//#######################
//Copyright 2004-2005 Kimball Jensen
//
//changelog:
//    Version 2.0 November 12, 2005

//#############################
//# PATCHES / ENHANCEMENTS:
//#    PATCHED 20051122; added function inForbiddenCharSet, which had been unintentionally left out
//#    MODIFIED 20051204; added pw validation to function validateNewMember
//#    MODIFIED 20051205; added line to set focus to "update" button when changing shipping or intended recipient
//#    PATCHED 20051206; fixed previous modification; setfocus was not letting qty field update
//#    MODIFIED 20060607; signForm.cgi to validateNewsletterForm
//#    MODIFIED 20060607; added validation checking for inquirePage, companyPage and guestbookPage; each includes signForm.cgi support
//#    MODIFIED 20060920; added mailingList portal support
//#       SEE ALSO: getHtmlSkeleton.pl, gateway.pl, vars.pl, resources.js
//#
//#
//#
//#############################
//#
//# 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('dsws_productSubtotal').value * taxRate;
		} else {
	      taxAmount = document.getElementById('dsws_tax_ori').value * 1;
		}
	}
	taxAmount = formatCurrency(taxAmount);
	if (document.getElementById('dsws_tax')) 
		document.getElementById('dsws_tax').value = taxAmount;
	if (document.getElementById('taxAmount'))
		document.getElementById('taxAmount').innerHTML = taxAmount;

	subTotal_tmp = (document.getElementById('dsws_tax').value * 1) + (document.getElementById('dsws_shipping').value * 1) + (document.getElementById('dsws_productSubtotal').value * 1) - (document.getElementById('dsws_discount').value * 1);
	subTotal_tmp = formatCurrency(subTotal_tmp);
	document.getElementById('dsws_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).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 submitIRForm (e) {
    document.getElementById('iRForm'+e).submit();
    return true;
  }

  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;
	document.getElementById('expmonth').disabled = false;
	document.getElementById('expyear').disabled = false;
	document.getElementById('cardnumber').disabled = false;
	document.getElementById('cvm').disabled = false;
	document.getElementById('bname').disabled = false;
	document.getElementById('baddr1').disabled = false;
	document.getElementById('baddr2').disabled = false;
	document.getElementById('bcity').disabled = false;
	document.getElementById('bstate').disabled = false;
	document.getElementById('bzip').disabled = false;
	if (document.getElementById('ppInfo_tr'))
		document.getElementById('ppInfo_tr').className = 'inactive';
	document.getElementById('ccInfo_tr').className = 'active';
	document.getElementById('dsws_tmp').value = new_pp;
  }

  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 = false;
	if (document.getElementById('ccForm').cctype[3])
		document.getElementById('ccForm').cctype[3].disabled = false;
	document.getElementById('expmonth').disabled = true;
	document.getElementById('expyear').disabled = true;
	document.getElementById('cardnumber').disabled = true;
	document.getElementById('cvm').disabled = true;
	document.getElementById('bname').disabled = true;
	document.getElementById('baddr1').disabled = true;
	document.getElementById('baddr2').disabled = true;
	document.getElementById('bcity').disabled = true;
	document.getElementById('bstate').disabled = true;
	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';
	document.getElementById('dsws_tmp').value = new_pp;
  }

  function initializePage () {
	if (errorState == 0) {
	    calcTax();
	    if (
				(document.getElementById('dsws_tmp').value == "linkpoint") || 
				(document.getElementById('dsws_tmp').value == "securepay") || 
				(document.getElementById('dsws_tmp').value == "paypalpro_cc") || 
				(document.getElementById('dsws_tmp').value == "linkpointAPI")
		){
		  enableCC (document.getElementById('dsws_tmp').value);
	    } else {
		  disableCC (document.getElementById('dsws_tmp').value);
	    }
	  }
  }

  function demoAlert() {
    alert ("Sorry, this shopping cart is currently in Demonstration Mode. Your order cannot be processed.");
	return false;
  }
  
  function copyBillingAddr() {
  document.getElementById('sname').value = document.getElementById('bname').value;
  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('instructions').value = "";
  }

  function clearBI() {
  document.getElementById('bname').value = "";
  document.getElementById('baddr1').value = "";
  document.getElementById('baddr2').value = "";
  document.getElementById('bcity').value = "";
  document.getElementById('bstate').value = "";
  document.getElementById('bzip').value = "";
  document.getElementById('bcountry').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;
  }

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;

    alert (document.theForm.tm.value);
    return false;
}

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))
        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))
        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 validateGuestbook(theForm)
{
    if (!validRequired(theForm.full_name, "Name"))
      return false;
    if (!validEmail(theForm.email, "Email address", 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 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('dsws_tmp').value == "paypal") {
    } else if (document.getElementById('dsws_tmp').value == "linkpoint") {
      if (
        (theForm.cctype[0].checked == false) && 
        (theForm.cctype[1].checked == false)
        ) {
          alert('Please enter a value for the "Card Type" field.');
          return false;
      }
      if (!validRequired(theForm.expmonth, "Credit Card Expiration Month"))
        return false;
      if (!validRequired(theForm.expyear, "Credit Card Expiration Year"))
        return false;
      if (!validRequired(theForm.bname, "Cardholder Name"))
        return false;
      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.cardnumber, "Credit card number"))
        return false;
      if ((document.getElementById('dsws_cvmRequired_tmp').value=='1') && (!validRequired(theForm.cvm, "Credit card CVM code")))
        return false;
    }
    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.ph, "Phone number"))
        return false;
    if (!validEmail(theForm.emailaddy, "Email address", true))
        return false;

	escapeText2();

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

    return true;
}


  function validateMailingListEmail (o) {
    if (!validEmail(o.email, "Email address", true))
        return false;
	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 clickIE() {
    if (document.all) {
      return false;
    }
  } 

  function clickNS(e) {
    if (document.layers||(document.getElementById&&!document.all)) { 
      if (e.which==2||e.which==3) {
        return false;
      }
    }
  } 

  function copyProtect(e) {
    if (document.layers) {
      document.captureEvents(Event.MOUSEDOWN);
      document.onmousedown=clickNS;
    } else {
      document.onmouseup=clickNS;
      document.oncontextmenu=clickIE;
    } 
    document.oncontextmenu=new Function("return false");
  }

//-->

//<!--

  function ClientSnifferJr() { 
    this.ua = navigator.userAgent.toLowerCase(); 
    this.major = parseInt(navigator.appVersion); 
    this.minor = parseFloat(navigator.appVersion); 
    this.nav = ( (this.ua.indexOf('mozilla')!=-1) && ((this.ua.indexOf('spoofer')==-1) && (this.ua.indexOf('compatible') == -1)) ); 
    this.nav2 = (this.nav && (this.major == 2)); 
    this.nav3 = (this.nav && (this.major == 3)); 
    this.nav4 = (this.nav && (this.major == 4)); 
    this.nav4up = (this.nav && (this.major >= 4)); 
    this.nav5 = (this.nav && (this.major == 5)); 
    this.nav5up = (this.nav && (this.major >= 5)); 
    this.ie = (this.ua.indexOf("msie") != -1); 
    this.ie3 = (this.ie && (this.major == 2)); 
    this.ie4 = ( this.ie && (this.major == 4) && (this.ua.indexOf("msie 4.0")!=-1) ); 
    this.ie4up = (this.ie && (this.major >= 4)); 
    this.ie5 = ( this.ie && (this.major == 4) && (this.ua.indexOf("msie 5.0")!=-1) ); 
    this.ie5up = (this.ie && !this.ie3 && !this.ie4); 
    this.opera = (this.ua.indexOf("opera") != -1); 
    this.webtv = (this.ua.indexOf("webtv") != -1); 
  } 
  var is = new ClientSnifferJr();

  window.onload = function() { 
    if(is.nav5up) {
      document.addEventListener("mouseover",myMouseOver,false); 
    } 
  } 


  var oLastBtn=0;
  var previousId=0;

  function myMouseOver(e) { 
    if(is.nav5up) { 
      e.preventDefault(); 
      if (previousId && previousId != e.target.id) { 
		//mouseOff
        var btype = document.getElementById(previousId).getAttribute('buttonType');
		document.getElementById(previousId).className = btype + "Off";
        previousId = e.target.id;
      }
      if (e.target.nodeName == "SPAN") { 
		//mouseOn
        previousId = e.target.id;
        var btype = document.getElementById(previousId).getAttribute('buttonType');
		document.getElementById(e.target.id).className = btype + "Up";
      }
    } 
  } 

  document.unload = function() { 
    if(is.nav5up) {
      document.removeEventListener("mouseover",myMouseOver,false); 
    } 
  }

  var oLastBtn=0;
  function RaiseButton() {
  //mouseOver
    if (is.ie5up) {
      window.event.cancelBubble=true;
      oBtn = window.event.srcElement;
      var bChosen = false;
      if(oLastBtn && oLastBtn != oBtn) {
        HideButton();
      }
      if(oBtn.buttonType){
        oBtn.className = oBtn.buttonType + "Up";
        oLastBtn=oBtn;
      } else {
        oLastBtn = 0;
      }
	}
  } 

  function DepressButton() {
  //mouseDown
    if (is.ie5up) {
      window.event.cancelBubble=true;
      oBtn = window.event.srcElement;
      if(oBtn.buttonType){
        oBtn.className = oBtn.buttonType + "Down";
      }
	}
  }

  function HideButton() {
  //mouseUp
    if(is.nav5up) { 
    } else if (is.ie5up) {
      if ((oLastBtn.buttonType == "LeftNavChosen") || (oLastBtn.buttonType == "LeftNavSubChosen") || (oLastBtn.buttonType == "appNavChosen") || (oLastBtn.buttonType == "appNavSubChosen")) {
        oLastBtn.className = oLastBtn.buttonType;
      }  else {
        oLastBtn.className = oLastBtn.buttonType + "Off";
      }
	}
  }

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;
    for (var i=0;i<formField.value.length;i++)
        if (!(charset.indexOf(formField.value.substr(i,1))<0))
        {
            result = true;
			alert ('The "'+fieldLabel+'" field cannot contain the following character\n'+formField.value.substr(i,1));
		    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 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 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)))
		    return false;
    
	if (theForm.emailaddy2)
		if ((!validEmail(theForm.emailaddy2, "Secondary Email Address", false)))
		    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';
	}
	dontForgetUpdate(lcv);
}

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

//-->
