todayDate = new Date();
todayYear = todayDate.getFullYear();

function checkpwd(WholeForm) {

  if (WholeForm.Email.value == "")
  {
    alert("Please enter a valid email address in the \"Email Address\" field.");
    WholeForm.Email.focus();
    return (false);
  }
  if (!isEmailAddr(WholeForm.Email.value))
  {
    alert("Please enter a complete email address in the form: yourname@yourdomain.com");
    WholeForm.Email.focus();
    return (false);
  }
  if (WholeForm.Email.value.length < 3)
  {
    alert("Please enter a valid email address in the \"Email Address\" field.");
    WholeForm.Email.focus();
    return (false);
  }

  if (WholeForm.OldPassword.value == "")
  {
    alert("Please enter a value for the \"Current Password\" field.");
    WholeForm.OldPassword.focus();
    return (false);
  }

  if (WholeForm.NewPassword.value == "")
  {
    alert("Please enter a value for the \"New Password\" field.");
    WholeForm.NewPassword.focus();
    return (false);
  }

	if(WholeForm.NewPassword.value != WholeForm.NewPassword2.value){
		alert('Your new password and new password confirmation values do not match. Please enter them again.');
		WholeForm.NewPassword.value = "";
		WholeForm.NewPassword2.value= "";
		WholeForm.NewPassword.focus();
		return false;
	}
	else {
		return true;
	}
}

function printthis(){
 	if (NS) {
		 window.print() ;
 	} else {
 		var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
 		document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
 		WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box WebBrowser1.outerHTML = "";
 	}
 }

function ValidateMe(txtbox)
  {
     if(txtbox.value != "")
      {
       var sval;
       if(txtbox.name == 'CardExpiryMonth')
        {
         sval =txtbox.value
         if((sval < 1) || (sval > 12))
           {
            alert("Please enter a valid expiration month");
            txtbox.focus();
            return false;
           }
         if(sval < 10 && sval.length == 1 )
           {
             txtbox.value = "0" + sval;
           }
      }
     if(txtbox.name == 'CardExpiryYear')
      {
        var d = new Date();
        var yy = (d.getFullYear());
        var mm = (d.getMonth() +1);
        sval = txtbox.value
        if(document.frmVerify.CardExpiryMonth.value == "")
          {
           document.frmVerify.CardExpiryMonth.focus();
           return false;
          }
        if(txtbox.length < 4)
         {
          alert("Enter a valid 4 Digit Date ");
          txtbox.focus();
          return false;
         }
        if(sval < yy)
         {
          alert("Date is not Valid");
          txtbox.focus();
          return false;
         }
	// iws : CCExpiryDateDropDowns
	if((sval == yy) && (mm > document.frmVerify.CardExpiryMonth.options[frmVerify.CardExpiryMonth.selectedIndex].value))
		alert("Expiration Date is not Valid");
	// txtbox.focus();
	// ene iws
           return false;
      }
   }
       return true;
}

function clearShipping(form)
 {
for (var i=0; i < form.length; i++)
   {
	 e = form.elements[i];
	 if (e.name.indexOf("Ship") == 0)
	 {
			e.value = "";
	 }
   }
}

function validate_Me(frm)
{
 var bmain_is_good = sfCheck(frm);
 if(bmain_is_good == true)
   {
    var bshipping_is_good = sfCheckPlus(frm);
    return bshipping_is_good;
   }
 else
  {
  return false;
  }
}

function reCalc()
 {
  var doCalc = document.frmQty.recalc.value;
  if(doCalc != "no")
    {
     document.frmQty.recalc.value ="1";
    }
 }

function reCalcNew(f) {
    var doCalc = document.getElementById(f).value;
    if(doCalc != "no"){
     document.getElementById(f).value ="1";
    }
}

function OpenPopUp(filename,windowname,properties) {
    mywindow = window.open(filename,windowname,properties);
    mywindow.focus();
}

function OpenCertDetails()
  {
  thewindow = window.open('https://www.thawte.com/cgi/server/certdetails.exe?code=USWISH12','anew',config='height=400,width=450,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,directories=no,status=yes');
  }

function CheckForm1 () {
  if (document.frmSiteSearch1.txtsearchParamTxt.value==""){
    alert("Please enter at least one keyword to search");
    document.frmSiteSearch1.txtsearchParamTxt.focus();
    return false;
    }
  return true
  }

function CheckForm2 () {
  if (document.frmSiteSearch2.txtsearchParamTxt.value==""){
    alert("Please enter at least one keyword to search");
    document.frmSiteSearch2.txtsearchParamTxt.focus();
    return false;
    }
  return true
  }

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 FormValidator(theForm)
{
  if (theForm.email.value == "")
  {
    alert("Please enter a valid email address in the \"email\" field.");
    theForm.email.focus();
    return (false);
  }
  if (!isEmailAddr(theForm.email.value))
  {
    alert("Please enter a complete email address in the form: yourname@yourdomain.com");
    theForm.email.focus();
    return (false);
  }
  if (theForm.email.value.length < 3)
  {
    alert("Please enter a valid email address in the \"email\" field.");
    theForm.email.focus();
    return (false);
  }
  return (true);
}

function drillmore(vId)
{
  if(vId != "Drill me")
  {
    document.drilMe.subcat.value =vId
    document.drilMe.submit()
  }
}

function convert_date(field1)
{
var fLength = field1.value.length; // Length of supplied field in characters.
var divider_values = new Array ('-','.','/',' ',':','_',','); // Array to hold permitted date seperators.  Add in '\' value
var array_elements = 7; // Number of elements in the array - divider_values.
var day1 = new String(null); // day value holder
var month1 = new String(null); // month value holder
var year1 = new String(null); // year value holder
var divider1 = null; // divider holder
var outdate1 = null; // formatted date to send back to calling field holder
var counter1 = 0; // counter for divider looping
var divider_holder = new Array ('0','0','0'); // array to hold positions of dividers in dates
var s = String(field1.value); // supplied date value variable
if ( fLength == 0 ) {
   return true;
}
if ( field1.value.toUpperCase() == 'NOW' || field1.value.toUpperCase() == 'TODAY' ) {
	var newDate1 = new Date();
  		if (navigator.appName == "Netscape") {
    		var myYear1 = newDate1.getYear() + 1900;
  		}
  		else {
  			var myYear1 =newDate1.getYear();
  		}
	var myMonth1 = newDate1.getMonth()+1;
	var myDay1 = newDate1.getDate();
	field1.value = myDay1 + "/" + myMonth1 + "/" + myYear1;
	fLength = field1.value.length;//re-evaluate string length.
	s = String(field1.value)//re-evaluate the string value.
}
if ( fLength != 0 && (fLength < 6 || fLength > 11) ) {
	invalid_date(field1);
	return false;
	}
for ( var i=0; i<3; i++ ) {
	for ( var x=0; x<array_elements; x++ ) {
		if ( s.indexOf(divider_values[x], counter1) != -1 ) {
			divider1 = divider_values[x];
			divider_holder[i] = s.indexOf(divider_values[x], counter1);
		   //alert(i + " divider1 = " + divider_holder[i]);
			counter1 = divider_holder[i] + 1;
			//alert(i + " counter1 = " + counter1);
			break;
		}
 	}
 }
if ( divider_holder[2] != 0 ) {
   invalid_date(field1);
	return false;
}
if ( divider_holder[0] == 0 && divider_holder[1] == 0 ) {
		if ( fLength == 6 ) {//ddmmyy
     	month1 = field1.value.substring(0,2);
     	day1 = field1.value.substring(2,4);
  			year1 = field1.value.substring(4,6);
  			if ( (year1 = validate_year(year1)) == false ) {
   			invalid_date(field1);
				return false;
				}
			}
		else if ( fLength == 7 ) {//mmmddy
  		 month1= field1.value.substring(0,3);
  			day1 = field1.value.substring(3,5);
  			year1 = field1.value.substring(5,7);
  			if ( (month1 = convert_month(month1)) == false ) {
   			invalid_date(field1);
				return false;
				}
  			if ( (year1 = validate_year(year1)) == false ) {
   			invalid_date(field1);
				return false;
				}
			}
		else if ( fLength == 8 ) {//mmddyyyy
  		 month1= field1.value.substring(0,2);
  			day1 = field1.value.substring(2,4);
  			year1 = field1.value.substring(4,8);
			}
		else if ( fLength == 9 ) {//mmmddyyyy
  		month1 = field1.value.substring(0,3);
  		day1 = field1.value.substring(3,5);
  			year1 = field1.value.substring(5,9);
  			if ( (month1 = convert_month(month1)) == false ) {
   			invalid_date(field1);
				return false;
				}
			}
		if ( (outdate1 = validate_date(day1,month1,year1)) == false ) {
   		alert("The value " + field1.value + " is not a vaild date.\n\r" +
			"Please enter a valid date in the format mm/dd/yyyy");
			field1.focus();
			field1.select();
			return false;
			}
		field1.value = outdate1;
		return true;// All OK
		}
if ( divider_holder[0] != 0 && divider_holder[1] != 0 ) {
  	 month1= field1.value.substring(0, divider_holder[0]);
  	day1 = field1.value.substring(divider_holder[0] + 1, divider_holder[1]);
  	year1 = field1.value.substring(divider_holder[1] + 1, field1.value.length);
	}
if ( isNaN(day1) && isNaN(year1) ) { // Check day and year are numeric
	invalid_date(field1);
	return false;
   }
if ( day1.length == 1 ) { //Make d day dd
   day1 = '0' + day1;
}
if ( month1.length == 1 ) {//Make m month mm
	month1 = '0' + month1;
}
if ( year1.length == 2 ) {//Make yy year yyyy
   if ( (year1 = validate_year(year1)) == false ) {
   	invalid_date(field1);
		return false;
		}
}
if ( month1.length == 3 || month1.length == 4 ) {//Make mmm month mm
   if ( (month1 = convert_month(month1)) == false) {
   	alert("month1" + month1);
   	invalid_date(field1);
   	return false;
   }
}
if ( (day1.length == 2 || month1.length == 2 || year1.length == 4) == false) {
   invalid_date(field1);
   return false;
}
if ( (outdate1 = validate_date(day1, month1, year1)) == false ) {
   alert("The value " + field1.value + " is not a vaild date.\n\r" +
	"Please enter a valid date in the format mm/dd/yyyy");

	field1.focus();
	field1.select();

	return false;
}
field1.value = outdate1;
return true;//All is well
}

function convert_month(monthIn) {
var month_values = new Array ("JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC");
monthIn = monthIn.toUpperCase();
if ( monthIn.length == 3 ) {
	for ( var i=0; i<12; i++ )
		{
   	if ( monthIn == month_values[i] )
   		{
			monthIn = i + 1;
			if ( i != 10 && i != 11 && i != 12 )
				{
   			monthIn = '0' + monthIn;
				}
			return monthIn;
			}
		}
	}
else if ( monthIn.length == 4 && monthIn == 'SEPT') {
   monthIn = '09';
   return monthIn;
	}
else {
	return false;
	}
}

function invalid_date(inField)
{
alert("The value " + inField.value + " is not in a vaild date format.\n\r" +
        "Please enter date in the format mm/dd/yyyy");
inField.focus();
inField.select();
return true
}

function validate_date(day2, month2, year2)
{
var DayArray = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var MonthArray = new Array("01","02","03","04","05","06","07","08","09","10","11","12");
var inpDate = month2 + day2 + year2;
var filter=/^[0-9]{2}[0-9]{2}[0-9]{4}$/;
if (! filter.test(inpDate))
  {
  return false;
  }
filter=/01|02|03|04|05|06|07|08|09|10|11|12/ ;
if (! filter.test(month2))
  {
  return false;
  }
var N = Number(year2);
if ( ( N%4==0 && N%100 !=0 ) || ( N%400==0 ) )
  	{
   DayArray[1]=29;
  	}
for(var ctr=0; ctr<=11; ctr++)
  	{
   if (MonthArray[ctr]==month2)
   	{
      if (day2<= DayArray[ctr] && day2 >0 )
        {
        inpDate = month2 + '/' + day2 + '/' + year2;
        return inpDate;
        }
      else
        {
        return false;
        }
   	}
   }
}

function validate_year(inYear)
{
if ( inYear < 10 )
	{
   inYear = "20" + inYear;
   return inYear;
	}
else if ( inYear >= 10 )
	{
   inYear = "19" + inYear;
   return inYear;
	}
else
	{
	return false;
	}
}

function returnToProcessOrder ()
{
alert ("Be sure to reselect your shipping option.");
}

function custAcct_FormValidator(theForm)
{
  if (theForm.custEmail.value == "")
  {
    alert("Please enter a valid email address in the \"email\" field.");
    theForm.custEmail.focus();
    return (false);
  }
  if (!isEmailAddr(theForm.custEmail.value))
  {
    alert("Please enter a valid email address in the format: username@yourdomain.com");
    theForm.custEmail.focus();
    return (false);
  }
  if (theForm.custPassword.value == "")
  {
    alert("You must enter a password.");
    theForm.custPassword.focus();
    return false;
  }
  return (true);
} 
