<!-- hide from old browsers

/* prefill assumes the following:
   1 form is named "quantities"
   2 layer to reveal(if any) is named layer1
   3 cookie cinfo in format of "fn:eric|ln:jones"
   4 names in form are same as given in cinfo
*/
function prefill() {
  var form = document.quantities;
  if(!form) {
    return;
  }
  var cinfo = Get_Cookie('cinfo');
  // var country = "";
  if(cinfo == "") {
    return;
  }
  // document.write('https://www.urbannutritioninc.com/scripts/preorder.php?w=');
  showLayer('layer1');
  // alert(cinfo);
  var cinfo_array = cinfo.split("|");

  var temp_array; //  = New Array;
  var temp_var = "";
  // var name = "";
  var value = "";
  var elem;
  for(i=0;i<cinfo_array.length;i++) {
    temp_var = cinfo_array[i];
    // alert(temp_var);
    temp_array = temp_var.split(":");
    if(temp_array[0] != "") {
      // if(temp_array[0] == "ctry") {
      //        country = temp_array[1];
      // }
      elem = eval("form." + temp_array[0]);
      if(elem) {
        value = temp_array[1];
        // value.replace("+"," ");
        elem.value = value.replace(/\+/g," ");
      }
    }
  }
}

function showLayer(name) {
  layer = document.getElementById(name);
  if(layer) {
    layer.style.display='block';
  } else {
    // alert('layer ' + name + 'does not exist');
  }
}
function Get_Parm(name) {
   SCH = document.location.search;
   SCH = "?&" + SCH.substring(1,SCH.length);
   if(typeof(window['SEGET']) != "undefined") { SCH += '&' + window['SEGET']; }
   // alert('SCH = ' + SCH);
   var start = SCH.indexOf("&" + name+"=");
   var len = start+name.length+2;
   if ((!start) && (name != SCH.substring(0,name.length))) return("");
   if (start == -1) return "";
   var end = SCH.indexOf("&",len);
   if (end == -1) end = SCH.length;
   // alert('finished getting parm ' + name);
   return unescape(SCH.substring(len,end));
}
function Get_Cookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { // if the cookie exists
      offset += search.length
      end = document.cookie.indexOf(";", offset); // set the index of beginning value
      if (end == -1) // set the index of the end of cookie value
        end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
    }
  }
  return returnvalue;
}

function write_page_message() {
  var txt = Get_Parm('mssg');
  if(txt == null || txt == undefined || txt=="") {
     // noop
  } else {
     document.write('<p align=center><font color=red face=arial size=4>' + URLDecode(txt) + '</font></p>');
     // return(txt);
  }
 
}

function URLDecode(encoded )
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   // var encoded = document.URLForm.F2.value;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   // document.URLForm.F1.value = plaintext;
   return plaintext;
}
function checkFormSTD(form) {
  // setup error strings
  var error_preamble = "You are required to fill in the following information:      \n\n----------------------------------------\n\n";
  var error_postamble = "\n\n----------------------------------------\nPlease fill in the fields and try again.";
  var error_str = "";
  var error_email_match = "";
	
  // check fields for being empty
  if(form.status && form.status.value == ""){
    error_str += "   Status\n";
  }
  if(form.firstname && form.firstname.value == ""){
    error_str += "   First Name\n";
  }
  if(form.lastname && form.lastname.value == ""){
    error_str += "   Last Name\n";
  }
  if(form.email && form.email.value == ""){
    error_str += "   Email\n";
  }
  if(form.confirm_email && form.confirm_email.value == ""){
    error_str += "   Confirm Email\n";
  }

  if(form.email && form.email.value != "" &&
    form.confirm_email && form.confirm_email.value != ""){
    if(form.email.value != form.confirm_email.value){
      error_email_match = "Your email entries don't match.\n";
    }
  }
  if(!email_ok(form.email.value)) {
    error_str += "   Email does not appear valid";
  }

  /*  
  if(document.getElementById('status').value == "EC"){
    if(document.getElementById('subject').selectedIndex == 0){
      error_str += "   Subject\n";
    }
  } 
  */

  if(error_str == "" && error_email_match == "") {
    return true;
  } else {
    alert(error_preamble + error_str + error_email_match + error_postamble);
    return false;
  }

}

function email_ok(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   // alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   // alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    // alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    // alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    // alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    // alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    // alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}


//-->
