
function checkOrderFormFields(f) {
	var realBillNames = new Array();
		realBillNames["bill_firstname"] = 		'Billing: First Name';
		realBillNames["bill_lastname"] = 		'Billing: Last Name';
		realBillNames["bill_phone_number"] = 	'Billing: Phone No.';
		realBillNames["bill_email"] = 			'Billing: Email Address';
		realBillNames["bill_street_addr"] = 	'Billing: Street Address';
//		realBillNames["bill_apt"] = 			'Billing: Apt or Suite No.';
//		realBillNames["bill_pobox"] = 			'Billing: P.O. Box No.';
		realBillNames["bill_city"] = 			'Billing: City';
		realBillNames["bill_state"] = 			'Billing: State';
		realBillNames["bill_zip"] = 			'Billing: Zip/Postal Code';
		realBillNames["bill_country"] = 		'Billing: Country';

	var realCcNames = new Array();
		realCcNames["credit_card_no"] = 		'Credit Card Number';
		realCcNames["select_cc"] = 				'Type of Credit Card';
		realCcNames["expiration_date"] = 		'Credit Card Expir. Date';
		realCcNames["name_on_card"] = 			'Credit Card Holder\'s Name';
		realCcNames["card_zip"] = 				'Credit Card Billing Zip or Postal Code';

	var realShiptoNames = new Array();
		realShiptoNames["ship_firstname"] = 	'Shipping: First Name';
		realShiptoNames["ship_lastname"] = 		'Shipping: Last Name';
		realShiptoNames["ship_street_addr"] = 	'Shipping: Street Address';
		realShiptoNames["ship_city"] = 			'Shipping: City';
		realShiptoNames["ship_state"] = 		'Shipping: State';
		realShiptoNames["ship_zip"] = 			'Shipping: Zip/Postal Code';
		realShiptoNames["ship_country"] = 		'Shipping: Country';

	var realShippingMethodNames = new Array();
		realShippingMethodNames["shippingmethod"] = 'Shipping Method';

//pmtmethod   cc  paypal  check_mo

	var msg = "";
	var radiobCounter = 0;
	var checkedButton = 0;
	for(i = 0; i < f.pmtmethod.length; i++) {
		if(f.pmtmethod[i].checked) {
			checkedButton = f.pmtmethod[i].value;
			radiobCounter++;
		} // radiobCounter will be either 0 or 1
	}

	if(radiobCounter == 0) {
		msg += "\n   * Payment method (Credit card, Paypal, Check/MO)";
	}

	// Shipping method validation
	var radiobCounter2 = 0;
	var checkedButton2 = 0;
	for(i = 0; i < f.shippingmethod.length; i++) {
		if(f.shippingmethod[i].checked) {
			checkedButton2 = f.shippingmethod[i].value;
			radiobCounter2++;
		} // radiobCounter2 will be either 0 or 1
	}

	if(radiobCounter2 == 0) {
		msg += "\n   * Shipping method";
	}
	
	for(i = 0; i < f.elements.length; i++) {
		if (f.elements[i].type != "radio") {
			if (f.elements[i].type == "text" && realBillNames[f.elements[i].name] != null && f.elements[i].value == "") {
				msg += "\n   * " + realBillNames[f.elements[i].name];
			}
			if (checkedButton == "cc" && f.elements[i].type == "text" && realCcNames[f.elements[i].name] != null && f.elements[i].value == "") {
				msg += "\n   * " + realCcNames[f.elements[i].name];
			}
			if (f.shipto.checked && f.elements[i].type == "text" && realShiptoNames[f.elements[i].name] != null && f.elements[i].value == "") {
				msg += "\n   * " + realShiptoNames[f.elements[i].name];
			}
		}
	}

	if(msg != "") {
		alert("Please complete the following fields:\n(Use 'NA' instead of leaving item blank.)\n-------------------------------------------\n" + msg);
		return false;
	}
	return true;
}

function jumpto(form) {
	var myindex = form.elements[0].selectedIndex;
	if (form.elements[0].options[myindex].value != "none") {
		window.location = (form.elements[0].options[myindex].value);
	}
	else {
		alert("Please make a valid selection.");
	}
}

function validateMagForm(form) {
	if(form.title.selectedIndex == 0) {
		alert("Please specify a magazine title.");
		return false;
	}
	else{
		return true;
	}
}

function validateBookForm(form) {
	if(form.category.selectedIndex == 0) {
		alert("Please specify a book category. The other fields are optional.");
		return false;
	}
	else{
		return true;
	}
}

function help_window(url) {
	var NewWin = window.open(url,"NewWin","scrollbars=yes,toolbar=no,directories=no,menubar=no,status=no,resizable=yes,width=600,height=500")
}

function closewindow() {
	this.window.close();
}

function displayPaymentInfo(target) {
	document.getElementById(target).style.visibility = "visible";
	document.getElementById(target).style.zindex = 1;
}
function hidePaymentInfo(target) {
	document.getElementById(target).style.visibility = "hidden";
	document.getElementById(target).style.zindex = 10;
}	

function toggle_display_ckbox(target) {
	target_layer = (document.getElementById) ? document.getElementById(target).style : eval("document." + target);
	target_layer.display = (target_layer.display == "none") ? "" : "none";
}


function setSearchFormSortField(formName) {
	if(formName == 'categSearchForm') {
		var thisForm = document.forms['categSearchForm'];
		document.getElementById('order_by_categ').value='author,title';
		//document.write(document.getElementById('categorySrch').value); //produces extraneous query string parts: /index2.php?category=N&startpos=1&action=Books&rec_per_page=50
		//alert(document.getElementById('categorySrch').selectedIndex); // OK  produces index number
		thisForm.submit();
	}
/*	
	if(categValue.length > 0) {
		var categorySelected = document.forms.bookSearchForm.categorySrch.value;
		document.getElementById.orderBy.value 
	}
*/
	if(formName == 'bookSearchForm') {
		var thisForm = document.forms['bookSearchForm'];
		var auValue = document.getElementById('authorSearch').value;
		var tiValue = document.getElementById('titleSearch').value;
		if(auValue.length == 0 && tiValue.length == 0) {
			alert("Please specify a title and/or author.");
			return false;
		}
		else if(auValue.length > 0 && tiValue.length > 0) {
			document.getElementById('order_by_form').value='author,title';
			thisForm.submit();
		}
		else {
			if(auValue.length > 0) {
				document.getElementById('order_by_form').value='author,title';
			}
			if(tiValue.length > 0) {
				document.getElementById('order_by_form').value='title,author';
			}
			thisForm.submit();
		}
	}
}

