function loadDepartmentGrid(Department) {
  window.location.href = 'catalog.asp?s=1&v=grid&d=' + Department.options[Department.selectedIndex].value + '-' + Department.options[Department.selectedIndex].text + '&u=false';
}

function loadDepartmentList(Department) {
  window.location.href = 'catalog.asp?s=1&v=list&d=' + Department.options[Department.selectedIndex].value + '-' + Department.options[Department.selectedIndex].text + '&u=false';
}

function loadBrandGrid(Brand) {
  window.location.href = 'catalog.asp?s=1&v=grid&b=' + Brand.options[Brand.selectedIndex].value + '-' + Brand.options[Brand.selectedIndex].text + '&u=false';
}

function loadBrandList(Brand) {
  window.location.href = 'catalog.asp?s=1&v=list&b=' + Brand.options[Brand.selectedIndex].value + '-' + Brand.options[Brand.selectedIndex].text + '&u=false';
}

function loadCategoryGrid(Category) {
  window.location.href = 'catalog.asp?s=1&v=grid&a=' + Category.options[Category.selectedIndex].value + '-' + Category.options[Category.selectedIndex].text + '&u=false';
}

function loadCategoryList(Category) {
  window.location.href = 'catalog.asp?s=1&v=list&a=' + Category.options[Category.selectedIndex].value + '-' + Category.options[Category.selectedIndex].text + '&u=false';
}

function loadHealthHints(HealthHints) {
  window.location.href = HealthHints.options[HealthHints.selectedIndex].value;
}

function loadPrograms(Programs) {
  window.location.href = Programs.options[Programs.selectedIndex].value;
}

// Determine if parameter is empty ----------------------------------------------------------------
function isEmpty(msString) {
 return ((msString == null) || (msString.length == 0))
}

// Validate Postal Code in US Format, ##### or #####-#### -----------------------------------------
function isZipcode(msString) { 

 if (msString.length != 5 && msString.length != 10) {
   alert("Postal Code must be in a valid 5 or 10 digit U.S. Postal Code format");
   return false;
 }

 for (var i=0; i < msString.length; i++) {
   if ((msString.charAt(i) < '0' || msString.charAt(i) > '9') && msString.charAt(i) != '-') {
     alert("Postal Code must be in a valid 5 or 10 digit U.S. Postal Code format");
     return false;
   }
 }
 return true;
}

// Make sure that strGraphic has the extension .jpg or .gif ---------------------------------------
function isValidGraphic(strGraphic, strName) { 

 if (isEmpty(strGraphic)) return true;
 
 strGraphic = strGraphic.toLowerCase();
 
 if (strGraphic.indexOf(".jpg") == -1) {
   if (strGraphic.indexOf(".gif") == -1) {
     alert(strName + " must contain an extension of .jpg or .gif");
     return false;
   }
 }
 return true;
}

// Valid that strColor is in a valid hex color format ---------------------------------------------
function isValidHexColor(strColor) {
 
 if (isEmpty(strColor)) return true;

 strColor = strColor.toLowerCase();

 if (strColor.length != 6) {
   alert("Color must be 6 characters long");
   return false;
 }

 for (var i = 0; i < strColor.length; i++) {
   if ((strColor.charAt(i) < '0' || strColor.charAt(i) > '9')) {
     if ((strColor.charAt(i) < 'a' || strColor.charAt(i) > 'f')) {
       alert("Color must be a valid RGB Format");
       return false;
     }
   }
 }
 return true;
}

// Returns true if the string passed in is a valid number (no alpha characters), else it displays an error message
function ForceNumber(objField, FieldName) {

 var strField = new String(objField.value);
 var i = 0;

 if (isWhitespace(strField)) return true;
 for (i = 0; i < strField.length; i++) {
   if (strField.charAt(i) < '0' || strField.charAt(i) > '9') {
     alert(FieldName + " must be a valid numeric entry.\nPlease do not use commas or any non-numeric symbols.");
     objField.focus();
     return false;
   }
 }
 return true;
}

// Returns true if msString is empty or whitespace characters only --------------------------------

function isWhitespace(msString) {

 var i;
 var whitespace = " \t\n\r";
 
 if (isEmpty(msString)) return true;

 // Check that current character isn't whitespace.
 for (i = 0; i < msString.length; i++) {   
   var c = msString.charAt(i);
   if (whitespace.indexOf(c) == -1) return false;
 }
 return true;
}

// Returns true if the string passed in is a valid money (no alpha characters except a decimal place)
function ForceMoney(objField, FieldName) {

 var strField = new String(objField.value);
 var i = 0;

 if (isWhitespace(strField)) return true;

 for (i = 0; i < strField.length; i++) {
   if ((strField.charAt(i) < '0' || strField.charAt(i) > '9') && (strField.charAt(i) != '.') && (strField.charAt(i) != ',') && (strField.charAt(i) != '$')) {
     alert(FieldName + " must be a valid numeric entry.");
     objField.focus();
     return false;
   }
 }
 return true;
}

// isEmail (STRING s [, BOOLEAN emptyOK])
// 
// Email address must be of form a@b.c ... in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isEmail (s) {

  if (isEmpty(s)) 
  if (isEmail.arguments.length == 1) return true;
  else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) {
      alert("Format of Email is Invalid");
      return false;
    }
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@")) {
      i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) {
      alert("Format of Email is Invalid");
      return false;
    }
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != ".")) {
      i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) {
      alert("Format of Email is Invalid");
      return false;
    }
    else return true;
}
/****************************************************************/

// PURPOSE:  Check to see if the string passed in is a valid time.
//	A valid time is defined as a string which is postfixed with either
//  "PM" or "AM".  Next it checks to see if there is a colon in the
//  string.  If there is, it makes sure that at least one digit preceeds
//  it and two proceed it.

	function zIsTime(strTime)
	{
		var strTestTime = new String(strTime);
		strTestTime.toUpperCase();

		var bolTime = false;

		if (strTestTime.indexOf("PM",1) != -1 || strTestTime.indexOf("AM",1))
			bolTime = true;

		if (bolTime && strTestTime.indexOf(":",0) == 0)
			bolTime = false;

		var nColonPlace = strTestTime.indexOf(":",1);
		if (bolTime && ((parseInt(nColonPlace) + 5) < (strTestTime.length - 1) || (parseInt(nColonPlace) + 4) > (strTestTime.length - 1)))
			bolTime = false;


		return bolTime;
	}

/****************************************************************/

function zreplaceAll (s, fromStr, toStr)
{
	var new_s = s;
	for (i = 0; i < 100 && new_s.indexOf (fromStr) != -1; i++)
	{
		new_s = new_s.replace (fromStr, toStr);
	}
	return new_s;
}

/****************************************************************/

/* PURPOSE:  Since we are using the single tick mark as the
	string delimiter to construct our SQL queries, a string with
	a tick mark in it will cause a SQL error.  Therefore we replace
	all "'" with "''", which eliminates the possibility of a SQL error.
*/

function zsqlSafe (s)
{
	var new_s = s;
	new_s = replaceAll (new_s, "'", "|");
	new_s = replaceAll (new_s, "|", "''");
	new_s = replaceAll (new_s, "\"", "|");
	new_s = replaceAll (new_s, "|", "''");
	return new_s;
}

/****************************************************************/

function zmakeSafe (i)
{
	i.value = sqlSafe (i.value);
}

/****************************************************************/
// Checks to see if a required field is blank.  If it is, a warning
// message is displayed...

function zForceEntry(objField, FieldName)
{
	var strField = new String(objField.value);
	if (isWhitespace(strField)) {
		alert("You need to enter information for " + FieldName);
		objField.focus();
		objField.select();
		return false;
	}

	return true;
}
		
/****************************************************************/
// Right trims the string...  Useful for SQL datatypes of CHAR

function zRTrim(strTrim)
{
	var str = new String(strTrim);
	var i = 0;
	var c = "";
	var endpos = 0

	for (i = str.length; i >= 0 && endpos == 0; i = i - 1) {
		c = str.charAt(i);
		if (whitespace.indexOf(c) == -1)
			endpos = i;
	}

	return str.substring(0,endpos+1);
}

/****************************************************************/

/* PURPOSE:  Returns true if the string is a valid date number.
	A method is passed in (1 = month, 2 = day).  If the string is
	nonnumeric, false is passed back.  If the day in the date string
	is greater than 31, false is returned.  If the month is greater
	than 12, an error is returned.
*/

function zisDateNumber(strNum,method)
{
	var str = new String(strNum);
	var i = 0;

	if (isNaN(parseInt(str)) || parseInt(str) < 0) return false;

	if (method == 2)
		if (parseInt(str) > 31)
			return false;
	if (method == 1)
		if (parseInt(str) > 12)
			return false;

	for (i = 0; i < str.length; i++)
		if (str.charAt(i) < '0' || str.charAt(i) > '9')
			return false;


	return true;
}

/****************************************************************/

// Displays an alert box with the passed in string...

function zPromptErrorMsg(Field,strError)
{
	alert("You have entered an invalid date for " + strError + ".  Please make sure your date format is in M/D/Y format.");
	Field.focus();
}

/****************************************************************/

/* PURPOSE: Checks to see if the string is a valid date.  A valid
	date is defined as any of the following:

		MM/DD/YY, MM/DD/YYYY, M/D/YY, M/D/YYYY,
		MM-DD-YY, MM-DD-YYYY, M-D-YY, M-D-YYYY
*/

function zForceDate(strDate,strField, mbRequired)
{
	var str = new String(strDate.value);

  if (!mbRequired) { 
	  if (isWhitespace(str)) {
		  return true;
		}
	}

	var i = 0, count = str.length, j = 0;
	while ((str.charAt(i) != "/" && str.charAt(i) != "-") && i < count)
		i++;

	if (i == count || i > 2) {
		PromptErrorMsg(strDate,strField);
		return false;
	}

	var addOne = false;
	if (i == 2) addOne = true;

	if (!isDateNumber(str.substring(0,i),1)) {
		PromptErrorMsg(strDate,strField);
		return false;
	}

	j = i+1;
	i = 0;

	while ((str.charAt(i+j) != "/" && str.charAt(j+i) != "-") && i+j < count)
		i++;

	if (i+j == count || i > 2) {
		PromptErrorMsg(strDate,strField);
		return false;
	}

	if (!isDateNumber(str.substring(j,i+j),2)) {
		PromptErrorMsg(strDate,strField);
		return false;
	}

	j = i+3;
	i = 0;

	if (addOne) j++;

	while (i+j < count)
		i++;


	if (i != 2 && i != 4) {
		PromptErrorMsg(strDate,strField);
		return false;
	}

	if (!isDateNumber(str.substring(j,i+j),3)) {
		PromptErrorMsg(strDate,strField);
		return false;
	}

	return true;
}

/****************************************************************/



/****************************************************************/

// This function ensures that a field is less than or equal to the
// Length passed in.  You must call this function with the element
// name in your form (for example: "ForceLength(document.forms[0].txtElement)"
// as opposed to "ForceLength(document.forms[0].txtElement.value)"
// If the field's value is too large, an error message is displayed
// and false is returned, else true is returned.

function zForceLength(objField, nLength, strWarning)
{
	var strField = new String(objField.value);

	if (strField.length > nLength) {
		alert(strWarning);
		return false;
	} else
		return true;
}



function zInfoPopUp(strJump){
 var app = navigator.appName;
 //20000531 CPB and WWC allow for resizing with resizable feature
 if (app == "Microsoft Internet Explorer") {
  var InfoPopUp=window.open("http://www.cooking.com/guestassist/gashipping_slim.asp#" + strJump,"InfoPopUp","width=650,height=430,left=0,top=0,scrollbars=yes,resizable=yes");
 }
 else{
 	var InfoPopUp=window.open("http://www.cooking.com/guestassist/gashipping_slim.asp#" + strJump,"InfoPopUp","width=650,height=430,screenX=0,screenY=0,scrollbars=yes,resizable=yes");
 }
}				

function zOrderPopUp(strOrderNumber){
 var app = navigator.appName;
 //20000531 CPB and WWC allow for resizing with resizable feature
 if (app == "Microsoft Internet Explorer") {
   var OrderPopUp=window.open("adminorderview.asp?i=" + strOrderNumber,"OrderView","width=750,height=500,scrollbars=yes,resizable=no");
 }
 else{
  var OrderPopUp=window.open("adminorderview.asp?i=" + strOrderNumber,"OrderView","width=750,height=500,scrollbars=yes,resizable=no");
 }
}				

function xOrderPopUp(strOrderNumber){
 var app = navigator.appName;
 //20000531 CPB and WWC allow for resizing with resizable feature
 if (app == "Microsoft Internet Explorer") {
   var OrderPopUp=window.open("adminorderview.asp?i=" + strOrderNumber,"OrderNumber" + strOrderNumber,"width=750,height=500,scrollbars=yes,resizable=no");
 }
 else{
  var OrderPopUp=window.open("adminorderview.asp?i=" + strOrderNumber,"OrderNumber" + strOrderNumber,"width=750,height=500,scrollbars=yes,resizable=no");
 }
}				


