//#############################
//#  Copyright 2004-2008 Kimball Jensen
//#  Kimball's eCommerce Software (KES_v4_0)
//#  Version 2.0 November 12, 2005
//#  Version 3.0 August 09, 2006
//#  Version 3.1 October 01, 2006
//#  Version 4.0 July 26, 2008
//#    significant changes in v4 include mushoo, improved ppbin, no double payments, helpdesk client, ctm
//#
//#############################
//# PATCHES / ENHANCEMENTS:
//#
//#
//#
//#############################
//#
//# USER REQUESTED CHANGES:
//#
//#
//#############################

  windowprops = "width=600,height=650,location=no,menubar=no,directories=no,toolbar=no,scrollbars=yes,resizable=yes,status=no";
  couponHelp = "Please enter your coupon, promotional, or discount code. Once you enter the code, click the 'Redeem' button to verify and apply your discount. The shopping cart page will reload with the discount applied.";
  var undefined;
  var tm;
  var sig;
  var vcount = 0;
  
  function openThis(file) {
    open(file,"aside",windowprops);    
  }

  function escapeText () {
    document.activity_form.note.value = escape (document.activity_form.note.value);
  }

  function escapeText2 () {
//    document.ccForm.note.value = escape (document.ccForm.note.value);
//    document.ccForm.instructions.value = escape (document.ccForm.instructions.value);
  }

  function updateShoppingCart_form (val,optionModifier) {
    toChange = eval ("document.getElementById('addToCart_form')."+optionModifier);
    toChange.value = val;
  }

  function formatCurrency(num) {
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num)) num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if (cents<10) cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
      num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
    return (((sign)?'':'-') + num + '.' + cents);
  }
  
  function calcTax () {
    var taxAmount = 0;
	if (taxRecip == 1) {
	    if (((document.getElementById('bstate')) && (taxState == document.getElementById('bstate').value)) || 
			((document.getElementById('sstate')) && (taxState == document.getElementById('sstate').value))) {
	      taxAmount = document.getElementById('cart_productSubtotal').value * taxRate;
		} else {
	      taxAmount = document.getElementById('cart_tax_ori').value * 1;
		}
	}
	taxAmount = formatCurrency(taxAmount);
	if (document.getElementById('cart_tax')) 
		document.getElementById('cart_tax').value = taxAmount;
	if (document.getElementById('taxAmount'))
		document.getElementById('taxAmount').innerHTML = taxAmount;

	subTotal_tmp = (document.getElementById('cart_tax').value * 1) + (document.getElementById('cart_shipping').value * 1) + (document.getElementById('cart_productSubtotal').value * 1) - (document.getElementById('cart_discount').value * 1);
	subTotal_tmp = formatCurrency(subTotal_tmp);
	document.getElementById('cart_grandTotal').value = subTotal_tmp;
    document.getElementById('grandTotal').innerHTML = subTotal_tmp;


  } //end.calcTax

  function newFocus (num) {
    document.getElementById('updateButton'+num).focus();
  }

  function dontForgetUpdate (num) {
    document.getElementById('updateButton'+num).className = 'active';
    document.getElementById('updateButton'+num).style.background = 'red';
    document.getElementById('updateButton'+num).style.color = 'white';
//    window.setTimeout('newFocus('+num+')', 50);
	document.getElementById('beginCheckoutButton').disabled = true;
	document.getElementById('beginCheckoutButton').className = 'inactive';
  }

  function showEnlargedPicture (obj) {
    document.getElementById('largeItem_layer').className = 'active';
    document.getElementById('smallItem_layer').className = 'inactive';
    eval ("document.getElementById('largeImage').src = '"+obj+"'");
  }

  function hideEnlargedPicture () {
    document.getElementById('largeItem_layer').className = 'inactive';
    document.getElementById('smallItem_layer').className = 'active';
  }

  function showCVM () {
    document.getElementById('cvmRow').className = 'active';
  }

  function hideCVM () {
    document.getElementById('cvmRow').className = 'inactive';
  }

  function disableSubmit (form) {
    if (document.getElementById('ccForm').submitted) return false;
    document.getElementById('ccForm').submitted = true;
//    document.getElementById('ccForm').disabled=true;
    return true;
  }

  function disableBeginCheckout (form) {
    if (document.getElementById('beginCheckout'))
      document.getElementById('beginCheckout').className = 'inactive';
//    if (document.getElementById('os'))
//      document.getElementById('os').className = 'inactive';
//    if (document.getElementById('pspm'))
//      document.getElementById('pspm').className = 'inactive';
//    if (document.getElementById('psyc'))
//      document.getElementById('psyc').className = 'inactive';
    if (document.getElementById('beginCheckoutForm'))
      document.getElementById('beginCheckoutForm').disabled = true;
    return true;
  }

  function validate_prexfer () {
    if ((document.getElementById("cart_pm_1").checked == true) && (!validRequired(document.getElementById("bcountry"), "Country"))) {
        return false;
    } else {
      if ((document.getElementById('beginCheckout')) && (document.getElementById('pleaseWait')))  {
        document.getElementById('beginCheckout').className = 'inactive';
        document.getElementById('pleaseWait').className = "active";
      }
    }
  }

  function pleaseWait (e) {
    if ((document.getElementById(e)) && (document.getElementById('pleaseWait')))  {
      document.getElementById(e).className = 'inactive';
	  document.getElementById('pleaseWait').className = "active";
	}
  }
      
  function submitIRForm (e) {
    document.getElementById('iRForm'+e).submit();
    return true;
  }

//<no-double-payments>
  function enableCC(new_pp) {
	if (document.getElementById('ccForm').cctype[0])
		document.getElementById('ccForm').cctype[0].disabled = false;
	if (document.getElementById('ccForm').cctype[1])
		document.getElementById('ccForm').cctype[1].disabled = false;
	if (document.getElementById('ccForm').cctype[2])
		document.getElementById('ccForm').cctype[2].disabled = false;
	if (document.getElementById('ccForm').cctype[3])
		document.getElementById('ccForm').cctype[3].disabled = false;
	if (document.getElementById('expmonth'))
	    document.getElementById('expmonth').disabled = false;
	if (document.getElementById('expyear'))
	    document.getElementById('expyear').disabled = false;
	if (document.getElementById('cardnumber'))
	    document.getElementById('cardnumber').disabled = false;
	if (document.getElementById('cvm'))
	    document.getElementById('cvm').disabled = false;
	if (document.getElementById('bname'))
	    document.getElementById('bname').disabled = false;
	if (document.getElementById('bfname'))
	    document.getElementById('bfname').disabled = false;
	if (document.getElementById('blname'))
	    document.getElementById('blname').disabled = false;
	if (document.getElementById('baddr1'))
	    document.getElementById('baddr1').disabled = false;
	if (document.getElementById('baddr2'))
	    document.getElementById('baddr2').disabled = false;
	if (document.getElementById('bcity'))
	    document.getElementById('bcity').disabled = false;
	if (document.getElementById('bstate'))
	    document.getElementById('bstate').disabled = false;
	if (document.getElementById('bzip'))
	    document.getElementById('bzip').disabled = false;
	if (document.getElementById('ppInfo_tr'))
		document.getElementById('ppInfo_tr').className = 'inactive';
	if (document.getElementById('ccInfo_tr'))
	    document.getElementById('ccInfo_tr').className = 'active';
	if (document.getElementById('cart_tmp'))
	    document.getElementById('cart_tmp').value = new_pp;
	if (document.getElementById('continue'))
		document.getElementById('continue').className = 'active';
  }
//</no-double-payments>

//<no-double-payments>
  function disableCC(new_pp) {
/*	if (document.getElementById('ccForm').cctype[0])
		document.getElementById('ccForm').cctype[0].disabled = true;
	if (document.getElementById('ccForm').cctype[1])
		document.getElementById('ccForm').cctype[1].disabled = true;
	if (document.getElementById('ccForm').cctype[2])
		document.getElementById('ccForm').cctype[2].disabled = true;
	if (document.getElementById('ccForm').cctype[3])
		document.getElementById('ccForm').cctype[3].disabled = true;
	if (document.getElementById('expmonth'))
	    document.getElementById('expmonth').disabled = true;
	if (document.getElementById('expyear'))
	    document.getElementById('expyear').disabled = true;
	if (document.getElementById('cardnumber'))
	    document.getElementById('cardnumber').disabled = true;
	if (document.getElementById('cvm'))
	    document.getElementById('cvm').disabled = true;
	if (document.getElementById('bname'))
	    document.getElementById('bname').disabled = true;
	if (document.getElementById('bfname'))
	    document.getElementById('bfname').disabled = true;
	if (document.getElementById('blname'))
	    document.getElementById('blname').disabled = true;
	if (document.getElementById('baddr1'))
	    document.getElementById('baddr1').disabled = true;
	if (document.getElementById('baddr2'))
	    document.getElementById('baddr2').disabled = true;
	if (document.getElementById('bcity'))
	    document.getElementById('bcity').disabled = true;
	if (document.getElementById('bstate'))
	    document.getElementById('bstate').disabled = true;
	if (document.getElementById('bzip'))
	    document.getElementById('bzip').disabled = true;
	if (document.getElementById('ccInfo_tr'))
		document.getElementById('ccInfo_tr').className = 'inactive';
*/
	if ((new_pp == "paypalpro_pp") && (document.getElementById('ppInfo_tr')))
		document.getElementById('ppInfo_tr').className = 'active';
	if (document.getElementById('cart_tmp'))
	    document.getElementById('cart_tmp').value = new_pp;
	if (document.getElementById('continue'))
		document.getElementById('continue').className = 'active';
    }
//</no-double-payments>

  function initializeViewCart () {
  }

/*<no-double-payments>*/
  function initializePage () {
	if (errorState == 0) {
	    calcTax();
	    if (
				(document.getElementById('cart_tmp').value == "linkpointConnect") || 
				(document.getElementById('cart_tmp').value == "securepay") || 
				(document.getElementById('cart_tmp').value == "paypalpro_cc") || 
				(document.getElementById('cart_tmp').value == "linkpointAPI") || 
				(document.getElementById('cart_tmp').value == "authorizeNetAIM")
		){
		  enableCC (document.getElementById('cart_tmp').value);
	    } else {
		  disableCC (document.getElementById('cart_tmp').value);
	    }
	  }
  }
/*</no-double-payments>*/

  function demoAlert() {
    alert ("Sorry, this shopping cart is currently in Demonstration Mode. Your order cannot be processed.");
	return false;
  }
  
  function copyBillingAddr() {
//<no-double-payments>
    if (document.getElementById('bname'))
        document.getElementById('sname').value = document.getElementById('bname');
    if (document.getElementById('bfname'))
        document.getElementById('sname').value = document.getElementById('bfname') + document.getElementById('blname');
//</no-double-payments>

  document.getElementById('saddr1').value = document.getElementById('baddr1').value;
  document.getElementById('saddr2').value = document.getElementById('baddr2').value;
  document.getElementById('scity').value = document.getElementById('bcity').value;
  document.getElementById('sstate').value = document.getElementById('bstate').value;
  document.getElementById('szip').value = document.getElementById('bzip').value;
  document.getElementById('scountry').value = document.getElementById('bcountry').value;
  calcTax();
  }

  function clearShippingAddr() {
  document.getElementById('sname').value = "";
  document.getElementById('saddr1').value = "";
  document.getElementById('saddr2').value = "";
  document.getElementById('scity').value = "";
  document.getElementById('sstate').value = "";
  document.getElementById('szip').value = "";
  document.getElementById('note').value = "";
  document.getElementById('ccForm').needsShipping[1].checked=true;
  }

  function clearAI() {
  document.getElementById('cname').value = "";
  document.getElementById('ph').value = "";
  document.getElementById('emailaddy').value = "";
  document.getElementById('emailaddy2').value = "";
  if (document.getElementById('instructions').disabled == false)
    document.getElementById('instructions').value = "";
  }

  function clearBI() {
//<no-double-payments>
  if (document.getElementById('bname'))
      document.getElementById('bname').value = "";
  if (document.getElementById('bfname'))
      document.getElementById('bfname').value = "";
  if (document.getElementById('blname'))
      document.getElementById('blname').value = "";
//</no-double-payments>
  document.getElementById('baddr1').value = "";
  document.getElementById('baddr2').value = "";
  document.getElementById('bcity').value = "";
  document.getElementById('bstate').value = "";
  document.getElementById('bzip').value = "";
  document.getElementById('cardnumber').value = "";
  document.getElementById('cvm').value = "";
  document.getElementById('cctype').value = "";
  document.getElementById('expmonth').value = "";
  document.getElementById('expyear').value = "";
	if (document.getElementById('ccForm').cctype[0])
		document.getElementById('ccForm').cctype[0].checked = false;
	if (document.getElementById('ccForm').cctype[1])
		document.getElementById('ccForm').cctype[1].checked = false;
	if (document.getElementById('ccForm').cctype[2])
		document.getElementById('ccForm').cctype[2].checked = false;
	if (document.getElementById('ccForm').cctype[3])
		document.getElementById('ccForm').cctype[3].checked = false;
  }

function charAlert(e) {
	var maxlength = 150;
	if(e.value.length > maxlength) {
		e.value= e.value.substring(0,maxlength)
		e.blur()
		alert("Please limit your message to 150 characters or less.")
    }

}

  function validateSelection (e,optionModifier) {
    if (optionModifier != '') {
      toCheck = eval ("e."+optionModifier+".value");
      if (toCheck != "yes") {
        if ((e.qty) && (!validInt(e.qty, "Quantity", true)))
            return false;
    
        return true;
  
      } else {
        alert ("You must first make a selection");
        return false;
      }
    } else {
     if ((e.qty) && (!validInt(e.qty, "Quantity", true)))
       return false;

     return true;
    }

  }

function validateForm(theForm)
{
    if (!validRequired(theForm.recp, "Recipient Name"))
      return false;
    if (!validRequired(theForm.ad1, "Address"))
      return false;
    if (!validRequired(theForm.ci, "City"))
      return false;
    if (!validRequired(theForm.st, "State"))
      return false;
    if (!validRequired(theForm.z, "Zip code"))
      return false;
 
    if (!validRequired(theForm.ph, "Phone number"))
      return false;

    escapeText(); //required by printshipping form
    return true;
}

function validateNewsletterForm(theForm)
{
    if (!validRequired(theForm.first_name, "First Name"))
      return false;
    if (!validRequired(theForm.last_name, "Last Name"))
      return false;
    if ((!validEmail(theForm.email, "Email address", true)) || (inForbiddenCharSet(theForm.email, "Email address", "\'\"\$\% ")))
        return false;

    if (tm != undefined) {
        document.newsletterForm.tm.value = tm;
	} else {
        if (vcount == 1) {
            window.location = "/cgi-bin/gateway.cgi?verb=show&amp;page=submissionFailed";
            return false;
		}
        alert ("Unable to comply; required system variable 'TM' missing\n\nTry reloading this screen");
		vcount++;
        return false;
	}
    if (sig != undefined) {
        document.newsletterForm.sig.value = sig;
    } else {
        if (vcount == 1) {
            window.location = "/cgi-bin/gateway.cgi?verb=show&amp;page=submissionFailed";
            return false;
		}
        alert ("Unable to comply; required system variable 'SIG' missing\n\nTry reloading this screen");
		vcount++;
        return false;
    }
	return true;
}

function validateInquiry(theForm)
{
    if (!validRequired(theForm.first_name, "First Name"))
      return false;
    if (!validRequired(theForm.last_name, "Last Name"))
      return false;
    if ((!validEmail(theForm.email, "Email address", true)) || (inForbiddenCharSet(theForm.email, "Email address", "\'\"\$\% ")))
        return false;

    if (tm != undefined) {
        theForm.tm.value = tm;
	} else {
        if (vcount == 1) {
            window.location = "/cgi-bin/gateway.cgi?verb=show&amp;page=submissionFailed";
            return false;
		}
        alert ("Unable to comply; required system variable 'TM' missing\n\nTry reloading this screen");
		vcount++;
        return false;
	}
    if (sig != undefined) {
        theForm.sig.value = sig;
    } else {
        if (vcount == 1) {
            window.location = "/cgi-bin/gateway.cgi?verb=show&amp;page=submissionFailed";
            return false;
		}
        alert ("Unable to comply; required system variable 'SIG' missing\n\nTry reloading this screen");
		vcount++;
        return false;
    }
	return true;
}

function validateMakeAffiliate(theForm)
{
    if (!validRequired(theForm.txnid, "Transaction ID"))
      return false;
    if (!validRequired(theForm.key, "Key"))
      return false;
    if (tm != undefined) {
        theForm.tm.value = tm;
	} else {
        if (vcount == 1) {
            window.location = "/cgi-bin/gateway.cgi?verb=show&amp;page=submissionFailed";
            return false;
		}
        alert ("Unable to comply; required system variable 'TM' missing\n\nTry reloading this screen");
		vcount++;
        return false;
	}
    if (sig != undefined) {
        theForm.sig.value = sig;
    } else {
        if (vcount == 1) {
            window.location = "/cgi-bin/gateway.cgi?verb=show&amp;page=submissionFailed";
            return false;
		}
        alert ("Unable to comply; required system variable 'SIG' missing\n\nTry reloading this screen");
		vcount++;
        return false;
    }
	return true;
}

function validateLinkForm(theForm)
{
    if (!validRequired(theForm.website, "Website"))
      return false;
    if (!validRequired(theForm.website_desc, "Website Description"))
      return false;
    if ((!validEmail(theForm.email, "Email address", true)) || (inForbiddenCharSet(theForm.email, "Email address", "\'\"\$\% ")))
      return false;

    if (tm != undefined) {
        theForm.tm.value = tm;
	} else {
        if (vcount == 1) {
            window.location = "/cgi-bin/gateway.cgi?verb=show&amp;page=submissionFailed";
            return false;
		}
        alert ("Unable to comply; required system variable 'TM' missing\n\nTry reloading this screen");
		vcount++;
        return false;
	}
    if (sig != undefined) {
        theForm.sig.value = sig;
    } else {
        if (vcount == 1) {
            window.location = "/cgi-bin/gateway.cgi?verb=show&amp;page=submissionFailed";
            return false;
		}
        alert ("Unable to comply; required system variable 'SIG' missing\n\nTry reloading this screen");
		vcount++;
        return false;
    }
	return true;
}

function validateSig(theForm)
{
    if (tm != undefined) {
        theForm.tm.value = tm;
	} else {
        if (vcount == 1) {
            window.location = "/cgi-bin/gateway.cgi?verb=show&amp;page=siteErrorPage";
            return false;
		}
        alert ("Unable to comply; required system variable 'TM' missing\n\nTry reloading this screen");
		vcount++;
        return false;
	}
    if (sig != undefined) {
        theForm.sig.value = sig;
    } else {
        if (vcount == 1) {
            window.location = "/cgi-bin/gateway.cgi?verb=show&amp;page=siteErrorPage";
            return false;
		}
        alert ("Unable to comply; required system variable 'SIG' missing\n\nTry reloading this screen");
		vcount++;
        return false;
    }
	return true;
}

function validateCCForm(theForm)
{

    if (document.getElementById('cart_tmp').value == "paypal") {
    } 
	if (
		(document.getElementById('cart_tmp').value == "linkpointAPI") || 
		(document.getElementById('cart_tmp').value == "paypalpro_cc") || 
		(document.getElementById('cart_tmp').value == "authorizeNetAIM")
	) {
//<no-double-payments>
      if (theForm.bname)
        if (!validRequired(theForm.bname, "Cardholder Name"))
          return false;
      if (theForm.bfname)
        if (!validRequired(theForm.bfname, "Cardholder First Name"))
          return false;
      if (theForm.blname)
        if (!validRequired(theForm.blname, "Cardholder Last Name"))
          return false;
//</no-double-payments>
      if (!validRequired(theForm.baddr1, "Cardholder Address Line1"))
        return false;
      if (!validRequired(theForm.bcity, "Cardholder city"))
        return false;
      if (!validRequired(theForm.bstate, "Cardholder state"))
        return false;
      if (!validRequired(theForm.bzip, "Cardholder zip code"))
        return false;
//      if (!validNum(theForm.bzip, "Cardholder zip code", true, 5))
//        return false;
      if (!validRequired(theForm.cctype, "Credit Card Type"))
        return false;
      if (!validRequired(theForm.cardnumber, "Credit card number"))
        return false;
      if (!validCCNum(theForm.cardnumber, "Credit card number"))
        return false;
      if (!validRequired(theForm.expmonth, "Credit Card Expiration Month"))
        return false;
      if (!validRequired(theForm.expyear, "Credit Card Expiration Year"))
        return false;
      if ((document.getElementById('cart_cvmRequired_tmp').value=='1') && (!validRequired(theForm.cvm, "Credit card CVM code")))
        return false;
    }
	if (document.getElementById('cart_tmp').value == "paypalpro_pp") {
	}
    if (collectShipping == true) {
      if (!validRequired(theForm.sname, "Ship-to Name"))
        return false;
      if (!validRequired(theForm.saddr1, "Ship-to Address Line1"))
        return false;
      if (!validRequired(theForm.scity, "Ship-to city"))
        return false;
      if (!validRequired(theForm.sstate, "Ship-to state"))
        return false;
      if (!validRequired(theForm.szip, "Ship-to zip code"))
        return false;
//      if (!validNum(theForm.szip, "Ship-to zip code", true, 5))
//        return false;
    }

    if (!validRequired(theForm.cname, "Contact name"))
        return false;
    if (!validRequired(theForm.ph, "Phone number"))
        return false;
    if ((!validEmail(theForm.emailaddy, "Email address", true)) || (inForbiddenCharSet(theForm.emailaddy, "Email address", "\'\"\$\% ,")))
        return false;
    if (!validEmail_dupeCheck(theForm.emailaddy, "Email address", theForm.emailaddy2, "Second email address", true))
        return false;

	escapeText2();

	if (theForm.passed_js_validation)
		theForm.passed_js_validation.value = "1";

	pleaseWait('continue');

    if (document.getElementById('cancel1'))
		document.getElementById('cancel1').style.display = 'none';
    if (document.getElementById('cancel2'))
		document.getElementById('cancel2').style.display = 'none';
    if (document.getElementById('cancel3'))
		document.getElementById('cancel3').style.display = 'none';
    if (document.getElementById('cancel4'))
		document.getElementById('cancel4').style.display = 'none';
    if (document.getElementById('cancel5'))
		document.getElementById('cancel5').style.display = 'none';

    return true;
}


  function validateMailingListEmail (o) {
    if ((!validEmail(o.email, "Email address", true)) || (inForbiddenCharSet(o.email, "Email address", "\'\"\$\% ")))
        return false;
/*
    if (tm != undefined) {
        o.tm.value = tm;
	} else {
        if (vcount == 1) {
            window.location = "/cgi-bin/gateway.cgi?verb=show&amp;page=submissionFailed";
            return false;
		}
        alert ("Unable to comply; required system variable 'TM' missing\n\nTry reloading this screen");
		vcount++;
        return false;
	}
    if (sig != undefined) {
        o.sig.value = sig;
    } else {
        if (vcount == 1) {
            window.location = "/cgi-bin/gateway.cgi?verb=show&amp;page=submissionFailed";
            return false;
		}
        alert ("Unable to comply; required system variable 'SIG' missing\n\nTry reloading this screen");
		vcount++;
        return false;
    }
*/
	if (o.passed_js_validation)
		o.passed_js_validation.value = "1";
	return true;
  }

  function notFunctional () {
    alert ("We apologize - this feature is only available when the website is purchased by a customer");
  }
  
  function needShipping(e) {
    alert ("In order for us to give our customers the best possible service, it's very important that you include the recipients name, address and phone number with all orders.\n\nPlease review your order for shipping accuracy.\n\nThis information can be corrected by clicking the 'Add' or 'Edit' button accross from 'Recipient' or 'Note' for each item in your shopping cart.\n\nThank You");
    return false;
  }

  function needRequired(e) {
    alert ("One or more of the required fields (indicated by the right arrow) are empty.\n\nPlease review the page and make sure all required fields have values.\n\nThank You");
    return false;
  }


function validState(formField,fieldLabel)
{
    var result = true;
	if (formField.value == "")
	{
		alert ('Please select the appropriate state');
		formField.focus();
		result = false;
	}
	return result;
}

  function isEmailAddr(email)
  {
    var result = false;
    var theStr = new String(email);
    var index = theStr.indexOf("@");
    if (index > 0)
    {
      var pindex = theStr.indexOf(".",index);
      if ((pindex > index+1) && (theStr.length > pindex+1))
      result = true;
    }
    return result;
  }
  
  function validRequired(formField,fieldLabel)
  {
      var result = true;
      if (formField.value == "")
      {
          alert('Please enter a value for the "' + fieldLabel +'" field.');
          formField.focus();
          result = false;
      }
      
      return result;
  }
  
  function allDigits(str)
  {
      return inValidCharSet(str,"0123456789");
  }
  
  function inValidCharSet(str,charset)
  {
      var result = true;
  
      // Note: doesn't use regular expressions to avoid early Mac browser bugs    
      for (var i=0;i<str.length;i++)
          if (charset.indexOf(str.substr(i,1))<0)
          {
              result = false;
              break;
          }
      
      return result;
  }
  
  function inForbiddenCharSet(formField, fieldLabel, charset)
  {
	var result = false;
	var badChar = "";
    for (var i=0;i<formField.value.length;i++)
        if (!(charset.indexOf(formField.value.substr(i,1))<0))
        {
            result = true;
			badChar = formField.value.substr(i,1);
			if (badChar == " ")
				badChar = "space character";
			alert ('The "'+fieldLabel+'" field cannot contain the following character:  \n'+badChar);
		    formField.focus();
            break;
        }
	 return result;
  }

  function validEmail(formField,fieldLabel,required)
  {
      var result = true;
  	if (required && !validRequired(formField,fieldLabel))
          result = false;
  
      if (result && (formField.value.length > 0) && ((formField.value.length < 3) || !isEmailAddr(formField.value)) )
      {
          alert("Please enter a complete email address in the form: yourname\@yourdomain.com");
          formField.focus();
          result = false;
      }
     
    return result;
  }
  
  function validEmail_dupeCheck(formField,fieldLabel,formField2,fieldLabel2,required)
  {
      var result = true;
  	if (required && !validRequired(formField,fieldLabel))
          result = false;
  
      if (result && (formField.value != formField2.value) )
      {
          alert("The email addresses you supplied are not the same.\n\nPlease review the email addresses and fix the incorrect one.");
          formField.focus();
          result = false;
      }
     
    return result;
  }
  
  function validNum(formField,fieldLabel,required,digitCount)
  {
  	var result = true;
      if (required && !validRequired(formField,fieldLabel))
          result = false;
  
       if (result)
       {
           if ((!allDigits(formField.value)) || ((formField.value.length > 0) && !(formField.value.length == digitCount)))
           {
               alert('Please enter a valid number for the "' + fieldLabel +'" field.');
              formField.focus();        
              result = false;
          }
      } 
      
      return result;
  }

  function validInt(formField,fieldLabel,required)
  {
      var result = true;
  
      if (required && !validRequired(formField,fieldLabel))
          result = false;
    
       if (result)
       {
//           var num = parseInt(formField.value,10);
           var num = formField.value.toString();
           if ((isNaN(num)) || (!allDigits(formField.value)) || (formField.value < 1))
           {
               alert('Please enter a number for the "' + fieldLabel +'" field.');
              formField.focus();        
              result = false;
          }
      } 
      
      return result;
  }
  
  
  function validCCNum(formField,fieldLabel,required)
  {
      var result = true;
  
      if (required && !validRequired(formField,fieldLabel))
          result = false;
    
       if (result)
       {
//           var num = parseInt(formField.value,10);
           var num = formField.value.toString();
           if ((isNaN(num)) || (!allDigits(formField.value)) || (formField.value < 1))
           {
               alert('"' + fieldLabel +'" must be all numbers (no spaces or letters). Please correct.');
              formField.focus();        
              result = false;
          }
      } 
      
      return result;
  }
  
  
  function validDate(formField,fieldLabel,required)
  {
      var result = true;
  
      if (required && !validRequired(formField,fieldLabel))
          result = false;
    
       if (result)
       {
           var elems = formField.value.split("/");
           
           result = (elems.length == 3); // should be three components
           
           if (result)
           {
               var month = parseInt(elems[0],10);
               var day = parseInt(elems[1],10);
               var year = parseInt(elems[2],10);
               result = allDigits(elems[0]) && (month > 0) && (month < 13) &&
                       allDigits(elems[1]) && (day > 0) && (day < 32) &&
                       allDigits(elems[2]) && ((elems[2].length == 2) || (elems[2].length == 4));
           }
           
            if (!result)
           {
               alert('Please enter a date in the format MM/DD/YYYY for the "' + fieldLabel +'" field.');
              formField.focus();        
          }
      } 
      
      return result;
  }
  
  
  function validateQty(theForm)
  {
  
      if ((theForm.qty) && (!validInt(theForm.qty, "Quantity", true)))
          return false;
  
      return true;
  }

function validateNewMember(theForm)
{
    if (theForm.userName)
	    if ((!validRequired(theForm.userName, "User Name")) || (inForbiddenCharSet(theForm.userName, "User Name", "\'\"\$\% ")))
		    return false;

	if (theForm.password) {
		if (theForm.password.value != '') {

			if (inForbiddenCharSet(theForm.password, "Password", "\'\"\$\%"))
			    return false;

			if ((!validRequired(theForm.newPassword, "New Password")) || (inForbiddenCharSet(theForm.newPassword, "New Password", "\'\"\$\%")))
			    return false;

			if ((!validRequired(theForm.newPassword2, "Retype New Password")) || (inForbiddenCharSet(theForm.newPassword2, "Retype New Password", "\'\"\$\%")))
			    return false;

			if (theForm.newPassword.value != theForm.newPassword2.value) {
				alert ("New Passwords do not match");
				return false;
			}
		}
	}

//	if (theForm.companyName)
//		if ((!validRequired(theForm.companyName, "Company Name")) || (inForbiddenCharSet(theForm.companyName, "Company Name", "\'\"\$\%")))
//		    return false;

//	if (theForm.lastName)
//		if ((!validRequired(theForm.lastName, "Last Name")) || (inForbiddenCharSet(theForm.lastName, "Last Name", "\'\"\$\%")))
//		    return false;
    
//	if (theForm.firstName)
//		if ((!validRequired(theForm.firstName, "First Name")) || (inForbiddenCharSet(theForm.firstName, "First Name", "\'\"\$\%")))
//		    return false;

//	if (theForm.contactNumber1Area)
//		if ((!validNum(theForm.contactNumber1Area, "Contact Number Area Code", true, 3)))
//		    return false;

//	if (theForm.contactNumber1Prefix)
//		if ((!validNum(theForm.contactNumber1Prefix, "Contact Number Prefix", true, 3)))
//		    return false;
    
//	if (theForm.contactNumber1Suffix)
//		if ((!validNum(theForm.contactNumber1Suffix, "Contact Number Suffix", true, 4)))
//		    return false;
    
//	if (theForm.contactNumber2Area)
//		if ((!validNum(theForm.contactNumber2Area, "Secondary Contact Number Area Code", false, 3)))
//		    return false;
    
//	if (theForm.contactNumber2Prefix)
//		if ((!validNum(theForm.contactNumber2Prefix, "Secondary Contact Number Prefix", false, 3)))
//		    return false;
    
//	if (theForm.contactNumber2Suffix)
//		if ((!validNum(theForm.contactNumber2Suffix, "Secondary Contact Number Suffix", false, 4)))
//		    return false;
    
//	if (theForm.url)
//		if ((!validRequired(theForm.url, "URL")) || (inForbiddenCharSet(theForm.url, "URL", "\'\"\$\% ")))
//		    return false;

//	if (theForm.emailaddy1)
//		if (((!validEmail(theForm.emailaddy1, "Email Address", true))) || (inForbiddenCharSet(theForm.emailaddy1, "Email Address", "\'\"\$\% ")))
//		    return false;
    
//	if (theForm.emailaddy2)
//		if (((!validEmail(theForm.emailaddy2, "Secondary Email Address", false))) || (inForbiddenCharSet(theForm.emailaddy2, "Secondary Email Address", "\'\"\$\% ")))
//		    return false;
    
//	if (theForm.address1)
//		if ((!validRequired(theForm.address1, "Address Line 1")) || (inForbiddenCharSet(theForm.address1, "Address Line 1", "\'\"\$\%")))
//		    return false;
    
//	if (theForm.address2)
//		if ((inForbiddenCharSet(theForm.address2, "Address Line 2", "\'\"\$\%")))
//		    return false;
    
//	if (theForm.city)
//		if ((!validRequired(theForm.city, "City")) || (inForbiddenCharSet(theForm.city, "City", "\'\"\$\%")))
//		    return false;
    
//	if (theForm.st)
//		if ((!validState(theForm.st, "State")))
//		    return false;
    
//	if (theForm.zip1)
//		if ((!validNum(theForm.zip1, "Zip code", true, 5)))
//		    return false;

//	if (theForm.zip2)
//		if ((!validNum(theForm.zip2, "Zip Code extension", false, 4)))
//		    return false;
    
//    if (!validDate(theForm.birthdate,"Birth Date",true))
//        return false;

    if (tm != undefined) {
        theForm.tm.value = tm;
	} else {
        if (vcount == 1) {
            window.location = "/cgi-bin/gateway.cgi?verb=show&amp;page=submissionFailed";
            return false;
		}
        alert ("Unable to comply; required system variable 'TM' missing\n\nTry reloading this screen");
		vcount++;
        return false;
	}
    if (sig != undefined) {
        theForm.sig.value = sig;
    } else {
        if (vcount == 1) {
            window.location = "/cgi-bin/gateway.cgi?verb=show&amp;page=submissionFailed";
            return false;
		}
        alert ("Unable to comply; required system variable 'SIG' missing\n\nTry reloading this screen");
		vcount++;
        return false;
    }

    return true;
}

function toggleCBField(me,x,lcv) {
	var objstr = "DEL-CB-" + x;
	if (me.checked == true) {
		document.getElementById(objstr).value = "FALSE";
	} else {
		document.getElementById(objstr).value = "TRUE";
	}
	dontForgetUpdate(lcv);
}

function tickDelete(me,lcv) {
	var f = "Form" + lcv;
	if (me.checked == true)
//	{
		document.getElementById(f).verb.value = 'deleteItem';
//	} else {
//		document.getElementById(f).verb.value = 'updatebasket';
//	}
    document.getElementById(f).submit(true);
    document.getElementById('wmb').className = 'inactive';
    document.getElementById('pcc').className = 'inactive';
    document.getElementById('os').className = 'inactive';
    document.getElementById('pspm').className = 'inactive';
    document.getElementById('psyc').className = 'inactive';
    document.getElementById('filler').className = 'inactive';
    document.getElementById('filler2').className = 'active';
}

function updateCart (lcv) {
    document.getElementById('Form'+lcv).submit(true);
}

function initializeHomePage () {
  for (var i = 1; i <= 40; i++) {
    if (document.getElementById('t'+i)) {
  	  document.getElementById('t'+i).style.display='none';
    }
  }
}

function toggleTestimonial (n) {
	var target = document.getElementById("t"+n);
    if (target.style.display == "none") {
  	  target.style.display='';
	} else {
  	  target.style.display='none';
	}
}
