//<!--
//===========================================================
//call the function with the onsubmit event handler
//and indicate the fields to validate as well
//as the text to appear in the alert box if
//it is left blank.
//
//The validate property should be set to true to validate
//an item. The msg property should be set to a string value
//enclosed in single quotes.
//
//Radio buttons should be referenced by their 0 index.
//
//Example:
//onsubmit="
//this.first_name.validate = true;
//this.first_name.msg = 'First Name';
//this.radiobutton[0].validate = true;
//this.radiobutton[0].msg = 'Radio Choice';
//return validate(this)";
//===========================================================
function isBlank(s) {
	for(var i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
	return true;
}
//--------------------------------------------------
function validate(f,msg) {
	var errors = 0;
	var message = "Please correct the following and re-submit:\n\n"
	var bolVal;
	var type;

	for (i = 0; i < f.elements.length; i++) {
		//alert("entering validate()");
		if(f.elements[i].validate) {
			type = f.elements[i].type;
			//alert("type = " + type);
			if (type == "text" || type == "password" || type == "file") {
				if(isBlank(f.elements[i].value)) {
					message += "Please supply a value for " + f.elements[i].msg + "\n";
					errors++;
				}
			}
			else if (type == "textarea") {
				if(isBlank(f.elements[i].value)) {
					message += "Please supply a value for " + f.elements[i].msg + "\n";
					errors++;
				}
			}
			else if (type == "select-one") {
				if(f.elements[i].selectedIndex == 0) {
					message += "Please supply a value for " + f.elements[i].msg + "\n";
					errors++;
				}
			}
			else if (type == "select-multiple") {
				var radioName = f.elements[i].name;
				chk = 0;
				for (j = 0; j < eval("f." + radioName).length; j++) {
					if(eval("f." + radioName)[j].selected) {
						chk++;
					}
				}
				if(chk == 0) {
					message += "Please supply a value for " + f.elements[i].msg + "\n";
					errors++;
				}
			}
			else if (type == "radio") {
				var radioName = f.elements[i].name;
				chk = 0;
				for (j = 0; j < eval("f." + radioName).length; j++) {
					if(eval("f." + radioName)[j].checked) {
						chk++;
					}
				}
				if(chk == 0) {
					message += "Please supply a value for " + f.elements[i].msg + "\n";
					errors++;
				}
			}
			else if (type == "checkbox") {
				var checkName = f.elements[i].name;
				chk = 0;
				for (j = 0; j < eval("f." + checkName).length; j++) {
					if(eval("f." + checkName)[j].checked) {
						chk++;
					}
				}
				if(chk == 0) {
					message += "Please supply a value for " + f.elements[i].msg + "\n";
					errors++;
				}
			}
			//else if (type == "checkbox") {
			//	if(!f.elements[i].checked) {
			//		message += "Please supply a value for " + f.elements[i].msg + "\n";
			//		errors++;
			//	}
			//}
		}
	}

	//if (msg != "undefined") {
	//	message += msg;
	//	errors++;
	//}

	if (errors > 0) {
		alert(message);
		return false;
	}
	return true;
	//return false;
}
//--------------------------------------------------
function submitPage(val) {
	document.form.action = val;
	document.form.method = "post";
	document.form.submit();
}
//--------------------------------------------------
function changeStoreState(val) {
	document.form.store_state_id1.value = document.form.state.value;
	document.form.store_state_id2.value = document.form.state.value;
	document.form.action = val;
	document.form.method = 'post';
	document.form.submit();
}
//--------------------------------------------------
function parseMenuSearchOption(val) {
	var arrParts;
	arrParts = val.split("#");
	document.form.search_menu_id.value = arrParts[0];
	document.form.search_menu_item.value = arrParts[1];
	//alert("document.form.search_menu_id.value = " + document.form.search_menu_id.value);
	//alert("document.form.search_menu_item.value = " + document.form.search_menu_item.value);
}
//--------------------------------------------------
function productWin(val) {
	var n;
	if (document.form.menu_id.value != '') {
		arrParts = document.form.menu_id.value.split("#");
		document.form.search_menu_id.value = arrParts[0];
		document.form.search_menu_item.value = arrParts[1];
		n = window.open('menu_item_dates.asp?menu_id=' + document.form.search_menu_id.value + '&store_id=' + val + '&state=' + document.form.search_state.value + '&menu_item=' + document.form.search_menu_item.value,'','width=500,height=400,left=250,top=250');
	}
	/*
	if (document.form.menu_id.value != '') {
		n = window.open('menu_item_dates.asp?menu_id=' + document.form.search_menu_id.value + '&store_id=' + val,'','width=500,height=400,left=250,top=250');
	}
	if (document.form.search_state.value != '') {
		n = window.open('menu_item_dates.asp?menu_id=' + document.form.search_menu_id.value + '&store_id=' + val + '&state=' + document.form.search_state.value + '&menu_item=' + document.form.search_menu_item.value,'','width=500,height=400,left=250,top=250');
	}
	*/
}
//--------------------------------------------------
function imgOn(imgName) {
	if (document.images) {
		document[imgName].src = "../images/" + imgName + "_on.gif";
	}
}
//--------------------------------------------------
function imgOff(imgName) {
	if (document.images) {
		document[imgName].src = "../images/" + imgName + "_off.gif";
	}
}
//--------------------------------------------------
