// Reset input field color when changed
function fldReset() {
  this.style.backgroundColor='';
  this.style.borderColor='#bbbbbb';
  if (this.type=='select-one') this.options[0].style.backgroundColor=''; 
}

// display error message, color error field, set 
function setErm(f,m) {
  alert(m);
  f.onchange = fldReset;
  f.style.backgroundColor="#ff9"; 
  f.style.borderColor="#f00";
  if (f.type=='select-one') f.options[0].style.backgroundColor="#ff9"; 
  else f.focus();
  return false;
}

// Check field(s) for required input, When a field is found with missing input,
// alert user, set field pink, and set focus to it.
function chkRqrd(s) {
  if (arguments.length<2) return true
  for ( var i = 1; i < arguments.length; i++ ) {
    fptr = s[arguments[i]];								// Get form field pointer
    if ( fptr.value=='' ) return setErm(fptr,'You must enter your name to continue.')	// Check field for content
  }
  return true;
}

// Check mailto form field(s) for required input, When a field is found with missing input,
// alert user, set field pink, and set focus to it.
function chkMailform(s) {
   if (s.name.value=='')		return setErm(s['name'],	'You must enter your name to continue.')
   if (s.dayphone.value=='')		return setErm(s['dayphone'],	'You must enter your daytime phone number to continue.')
   if (s.evephone.value=='')		return setErm(s['evephone'],	'You must enter your evening phone number to continue.')
   if (s.email.value=='')		return setErm(s['email'],	'You must enter your E-mail address to continue.');
   if (s.email.value.indexOf('@')==-1)	return setErm(s['email'],	'Your E-mail address appears to be invalid. Please check!');
   if (s.email.value.indexOf('.')==-1)	return setErm(s['email'],	'Your E-mail address appears to be invalid. Please check!');
   if (s.cemail.value=='')		return setErm(s['cemail'],	'You must enter your confirmation E-mail address to continue.');
   if (s.cemail.value.indexOf('@')==-1)	return setErm(s['cemail'],	'Your confirmation E-mail address appears to be invalid. Please check!');
   if (s.cemail.value.indexOf('.')==-1)	return setErm(s['cemail'],	'Your confirmation E-mail address appears to be invalid. Please check!');
   if (s.cemail.value!=s.cemail.value)	return setErm(s['cemail'],	'The E-mail address you have entered does not match the confirmation E-mail address. Please check');
   return true;
}

// Check cart form field(s) for required input, When a field is found with missing input,
// alert user, set field pink, and set focus to it.
function chkCartform(s) {
   if (s.customername.value=='')		return setErm(s['customername'],   'You must enter your contact name to continue.')
   if (s.customeremail.value=='')		return setErm(s['customeremail'],  'You must enter your email address to continue.')
   if (s.billingfname.value=='')		return setErm(s['billingfname'],   'You must enter the billing first name to continue.')
   if (s.billinglname.value=='')		return setErm(s['billinglname'],   'You must enter the billing last name to continue.')
   if (s.billingaddr1.value=='')		return setErm(s['billingaddr1'],   'You must enter the billing address to continue.')
   if (s.billingcity.value=='')			return setErm(s['billingcity'],	   'You must enter the billing city to continue.')
   if (s.billingstate.selectedIndex=='0')	return setErm(s['billingstate'],   'You must select the billing state to continue.')
   if (s.billingzip.value=='')			return setErm(s['billingzip'],	   'You must enter the billing zipcode to continue.')
   if (s.billingphone.value=='')		return setErm(s['billingphone'],   'You must enter the billing phone number to continue.')
   if (s.shippingfname.value=='')		return setErm(s['shippingfname'],  'You must enter the shipping first name to continue.')
   if (s.shippinglname.value=='')		return setErm(s['shippinglname'],  'You must enter the billing last name to continue.')
   if (s.shippingaddr1.value=='')		return setErm(s['shippingaddr1'],  'You must enter the shipping address to continue.')
   if (s.shippingcity.value=='')		return setErm(s['shippingcity'],   'You must enter the shipping city to continue.')
   if (s.shippingstate.selectedIndex=='0')	return setErm(s['shippingstate'],  'You must select the shipping state to continue.')
   if (s.shippingzip.value=='')			return setErm(s['shippingzip'],	   'You must enter the shipping zipcode to continue.')
   if (s.shippingphone.value=='')		return setErm(s['shippingphone'],  'You must enter the shipping phone number to continue.')
   if ((s.shippingstate[s.shippingstate.selectedIndex].value=="FL") && (s.shippingcounty.selectedIndex<1)) {
      return setErm(s['shippingcounty'],  'You must indicate the Florida county shipping destination to continue.')
   }
   return true;
}

// Check credit card form field(s) for required input, When a field is found with missing input,
// alert user, set field pink, and set focus to it.
function chkCcardform(s) {
   if (s.cctype.selectedIndex==0)	return setErm(s['cctype'],	'You must indicate your Credit Card type continue.')
   if (s.x_Card_Num.value=='')		return setErm(s['x_Card_Num'],	'You must enter your Credit Card Number to continue.')
   if (s.x_Exp_Date.value=='')		return setErm(s['x_Exp_Date'],	'You must enter your Credit Card Expiration Date to continue.')
   if (s.x_Zip.value=='')		return setErm(s['x_Zip'],	'You must enter your Credit Card Billing Zip Code to continue.')
   if (s.x_Card_Code.value=='')		return setErm(s['x_Card_Code'],	'You must enter your Credit Card Identification Code to continue.')
   return true;
}

function checkScode(s) {
   switch(s.shippingcode.length) {
      case undefined:	{ if ( s.shippingcode.checked ) return true; }
      default:		{ for ( var i = 0; i<s.shippingcode.length; i++  ) { if ( s.shippingcode[i].checked ) return true; }}
   }
   alert("You must select a 'Shipping option' to continue.");
   return false;
}

function copyBilltoShip(s) {
   s.s_fname.value		= s.b_fname.value;
   s.s_lname.value		= s.b_lname.value;
   s.s_addr1.value		= s.b_addr1.value;
   s.s_addr2.value		= s.b_addr2.value;
   s.s_city.value		= s.b_city.value;
   s.s_province.value		= s.b_province.value;
   for ( var i=0; i<s.b_state.length; i++ )   s.s_state.options[i].selected   = s.b_state.options[i].selected 
   for ( var i=0; i<s.b_country.length; i++ ) s.s_country.options[i].selected = s.b_country.options[i].selected 
   s.s_zipcode.value		= s.b_zipcode.value;
   s.s_phone.value		= s.b_phone.value;
}

function checkShipping(s) {
  if (s.b_fname.length<2)		return setErm(s['b_fname'],	'You must enter the billing first name to continue.')
  if (s.b_lname.value=='')		return setErm(s['b_lname'],	'You must enter the billing last name to continue.')
  if (s.b_addr1.value=='')		return setErm(s['b_addr1'],	'You must enter a billing street address to continue.')
  if (s.b_city.value=='')		return setErm(s['b_city'],	'You must enter the billing city to continue.')
  if (s.b_zipcode.value=='')		return setErm(s['b_zipcode'],	'You must enter the billing zip code to continue.')
  if (s.b_country.selectedIndex==0)	return setErm(s['b_country'],	'You must indicate the billing country to continue.')
  if (s.b_country[s.b_country.selectedIndex].value=="US") {
     if (s.b_state.selectedIndex==0)	return setErm(s['b_state'],	'You must indicate the billing state to continue.')
  }
  if (s.b_phone.value=='')		return setErm(s['b_phone'],	'You must enter a billing phone number to continue.')
  if (s.b_email.value=='')		return setErm(s['b_email'],	'You must enter your email address to continue.')
  if ( (typeof s.s_pickup=="undefined") || (!s.s_pickup.checked) ) {
    if (s.s_fname.value=='')		return setErm(s['s_fname'],	'You must enter the shipping first name to continue.')
    if (s.s_lname.value=='')		return setErm(s['s_lname'],	'You must enter the shipping last name to continue.')
    if (s.s_addr1.value=='')		return setErm(s['s_addr1'],	'You must enter the shipping street address to continue.')
    if (s.s_city.value=='')		return setErm(s['s_city'],	'You must enter the shipping city to continue.')
    if (s.s_zipcode.value=='')	return setErm(s['s_zipcode'],	'You must enter the shipping zip code to continue.')
    if (s.s_country.selectedIndex==0)	return setErm(s['s_country'],	'You must indicate the shipping country to continue.')
    if (s.s_country[s.s_country.selectedIndex].value=="US") {
      if (s.s_state.selectedIndex==0)	return setErm(s['s_state'],	'You must indicate the shipping state to continue.','S')
      if (s.s_state[s.s_state.selectedIndex].value=="FL") {
        if (s.s_county.selectedIndex==0) return setErm(s['s_county'],	'You must indicate which county in Florida you are shipping to.','S')
      }
    }
    if (s.s_phone.value=='')		return setErm(s['s_phone'],	'You must enter the shipping phone number to continue.')
  }
  if ((s.payMethod.type!="hidden") && (s.payMethod.selectedIndex==0))
  					return setErm(s['payMethod'],	'You must indicate payment method to continue.');
  					
  s.conf.value = 'X1_mtLg133Py';
}

function checkBilling(s) {
  if ((s.shippingcost) && (s.shippingcost.value=='')) return setErm(s['shippingcost'],	'You must pick your shipping method to continue.')
  if (s.payMethod.value=="CC") {
    if (s.cctype.selectedIndex==0)	return setErm(s['cctype'],	'You must indicate the type of credit card you are using.')
    if (s.cc_cardnum.value=='')		return setErm(s['cc_cardnum'],	'You must enter the credit card number to continue.')
    var Tar = s.cctype[s.cctype.selectedIndex].value.split("|");
    if ((s.cc_cardcode.value=='') && (Tar[1]=="1")) {
      return setErm(s['cc_cardcode'],'You must enter your Credit Card Identification Code to continue.')
    }
    if (s.cc_expmo.selectedIndex==0)	return setErm(s['cc_expmo'],	'You must indicate the credit card date of expiration month.')
    if (s.cc_expyr.selectedIndex==0)	return setErm(s['cc_expyr'],	'You must indicate the credit card date of expiration year.')
  }
  if (s.payMethod.value=="PH") {
    if (s.ph_phone.value=='')	return setErm(s['ph_phone'],	'You must enter the Pay by Phone contact number to continue.')
    if (s.ph_time.value=='')	return setErm(s['ph_time'],	'You must specify the "best time to be contacted" to continue.')
    if (s.ph_date.value=='')	return setErm(s['ph_date'],	'You must specify the "best date to be contacted" to continue.')
  }
}

function itemUpdt(s) {	// Check item update input
   if (s.ITEMNAME.value=='')		 return setErm(s['ITEMNAME'],	'You must enter a product name to continue.')
   if (s['DEPTSELECT[]'].selectedIndex==-1) return setErm(s['DEPTSELECT[]'],	'You must selecte at least 1 department to continue.')
}

function deptUpdt(s) {	// Check department update input
   if (s.DEPARTMENTNAME.value=='')		return setErm(s['DEPARTMENTNAME'],'You must enter a department name to continue.')
   if (s.DEPARTMENTDESCRIPTION.value=='')	return setErm(s['DEPARTMENTDESCRIPTION'],'You must enter a department description to continue.')
}

function chkLogIn(s) {	// Check login input
   if (s.ACCOUNTID.value=='')	return setErm(s['ACCOUNTID'],'You must enter an account id to continue.')
   if (s.accountpw.value=='')	return setErm(s['accountpw'],'You must enter an account password to continue.')
}

function chkAcctEdit(s) {	        // Check account update input fields
   if (s.ACTION.value='add') {
     if (s.ACCOUNTID.value=='')	return setErm(s['ACCOUNTID'],'You must enter an account id to continue.')
     if (s.accountpw.value=='')	return setErm(s['accountpw'],'You must enter an account password to continue.')
   }
   if (s.b_fname.value=='')		return setErm(s['b_fname'],	'You must enter your first name to continue.')
   if (s.b_lname.value=='')		return setErm(s['b_lname'],	'You must enter your last name to continue.')
   if (s.b_addr1.value=='')		return setErm(s['b_addr1'],	'You must enter a street address to continue.')
   if (s.b_city.value=='')		return setErm(s['b_city'],	'You must enter the city to continue.')
   if (s.b_zipcode.value=='')		return setErm(s['b_zipcode'],	'You must enter the zip code to continue.')
   if (s.b_country.selectedIndex==0)	return setErm(s['b_country'],	'You must indicate the country to continue.')
   if (s.b_country[s.b_country.selectedIndex].value=="US") {
      if (s.b_state.selectedIndex==0)	return setErm(s['b_state'],	'You must indicate the a state to continue.')
   }
   if (s.b_phone.value=='')		return setErm(s['b_phone'],	'You must enter a phone number to continue.')
   if (s.b_email.value=='')		return setErm(s['b_email'],	'You must enter your email address to continue.')

   if (s.s_fname.value=='')		return setErm(s['s_fname'],	'You must enter your first name to continue.')
   if (s.s_lname.value=='')		return setErm(s['s_lname'],	'You must enter your last name to continue.')
   if (s.s_addr1.value=='')		return setErm(s['s_addr1'],	'You must enter a street address to continue.')
   if (s.s_city.value=='')		return setErm(s['s_city'],	'You must enter the city to continue.')
   if (s.s_zipcode.value=='')	return setErm(s['s_zipcode'],	'You must enter the zip code to continue.')
   if (s.s_country.selectedIndex==0)	return setErm(s['s_country'],	'You must indicate the country to continue.')
   if (s.s_country[s.s_country.selectedIndex].value=="US") {
      if (s.s_state.selectedIndex==0)	return setErm(s['s_state'],	'You must indicate the a state to continue.')
      if (s.s_state[s.s_state.selectedIndex].value=="FL") {
         if (s.s_county.selectedIndex==0) return setErm(s['s_county'],	'You must indicate which county in Florida county you are shipping to.')
      }
   }
   if (s.s_phone.value=='')		return setErm(s['s_phone'],	'You must enter a phone number to continue.')
}

function transDel() { return(confirm("Are you sure you want to delete this transaction?")); }
