<!--
var digits;
digits = "0123456789";

function OpenCertDetails()
	{
	thewindow = window.open('https://www.thawte.com/cgi/server/certdetails.exe?code=USBARN15', 'anew', config='height=400,width=450,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,directories=no,status=yes');
	}

function OpenWindow(thisURL) {
	var myWin = window.open(thisURL,"pics",
     "toolbar=no,scrollbars=no,resizable=yes,width=400,height=480")};
	 

function OpenBedroomWindow(thisURL) {
	var myWin = window.open(thisURL,"pics",
     "toolbar=no,scrollbars=no,resizable=yes,width=700,height=400")};

function SubmitForm() {
	// Set the value of the first element of the first form on the page:
        // document.forms[0].elements[0].value = varValue;

        // Submit that form (Note: if you submit to the same page
        // this will loop, forever submitting your form):
        
	document.form1.submit();
}

function funcSignInValidator(theForm)
{
var strEmail=document.theForm.CustomerEmail.value
var filter=/^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i

//Please insure that "Existing Customer" is the second radio button
var strExistingCustomer=document.theForm.NewCustomer[1].checked


if (!(filter.test(strEmail)))
{
alert("Please enter a valid email address.");
document.theForm.CustomerEmail.value = "";
theForm.CustomerEmail.focus();
return (false);
}

if (strExistingCustomer)
{
if (theForm.CustomerPassword.value == "")
	{
	alert("Please enter your password.");
   	theForm.CustomerPassword.focus();
   	return (false);
	}
}

return (true);
}

function funcCheckCookieZip(theForm)
{
		if (theForm.ZipCodeCookie.value == "")
  			{ 
			alert("Please enter your zip code.");
    			theForm.ZipCodeCookie.focus();
    			return (false);
  			}
     
		for(i=0;i<5;i++)
			{
				if (digits.indexOf(theForm.ZipCodeCookie.value.charAt(i))<0)
					{
					alert("The zip code must be numeric");
					theForm.ZipCodeCookie.value = "";
					theForm.ZipCodeCookie.focus();
					return (false);
					}
			}

		if (theForm.ZipCodeCookie.value.length < 5)
			{
			alert("The zip code needs to be at least 5 characters long.");
			theForm.ZipCodeCookie.value = "";
  			theForm.ZipCodeCookie.focus();
			return (false);
			}
return (true);
}

function funcCheckoutShippingOptionsValidator(theForm)
{
	var Button1=document.theForm.accept_shipping_policy[0].checked
	var Button2=document.theForm.accept_shipping_policy[1].checked	
	if ((!(Button1)) && (!(Button2)))
		{
		alert("Please let us know if you accept the shipping policy");
		return (false);
		}
return (true);
}

function funcCheckoutShippingValidator(theForm)
{
var strNewCustomer = document.theForm.NewCustomer.value
var blnCheckAddress = 0

	if ( strNewCustomer == "True")
	{
		
		//alert("New Customer");
		if (theForm.CustomerPassword.value == "")
			{ 
			alert("Please enter a password.");
			theForm.PasswordConfirm.value = "";
  			theForm.CustomerPassword.value = "";
			theForm.CustomerPassword.focus();
			return (false);
			}
		if (theForm.CustomerPassword.value.length < 6)
			{
			alert("The password needs to be at least 6 characters long.");
			theForm.PasswordConfirm.value = "";
  			theForm.CustomerPassword.value = "";
   			theForm.CustomerPassword.focus();
			return (false);
			}
		if (theForm.PasswordConfirm.value == "")
			{
			alert("Please re-enter your password.");
  			theForm.PasswordConfirm.focus();
  			return (false);
			}
		if (theForm.PasswordConfirm.value != theForm.CustomerPassword.value)
			{	
			alert("The passwords do not match.");
  			theForm.PasswordConfirm.value = "";
  			theForm.CustomerPassword.value = "";
  			theForm.CustomerPassword.focus();
  			return (false);
			}
		
		//since this is new customer then we need to set the flag
		blnCheckAddress = 1;
	}
	else
	{
		//alert("Not New Customer");
		var intRadioGroupLength;
		var blnIsChecked;
		var intNewAddress

		//determine the number of radio buttons
		intRadioGroupLength = theForm.ShippingAddressID.length;
		//alert(intRadioGroupLength);
		
		//determine the position of the create new address radio button
		intNewAddress = intRadioGroupLength - 1

		//determine whether it's been checked
		blnIsChecked = document.theForm.ShippingAddressID[intNewAddress].checked;
		//alert(blnIsChecked);
				
		//has the create new address button been checked?
		if(blnIsChecked)
			{
				//if it's been checked then set the flag
				blnCheckAddress = 1;
				
			}
			
	}

	//do we need to validate for a new address?
	if(blnCheckAddress)
	{
		if (theForm.CustomerFirstName.value == "")
			{ 
			alert("Please enter a your First Name.");
			theForm.CustomerFirstName.value = "";
  			theForm.CustomerFirstName.focus();
			return (false);
			}

		if (theForm.CustomerLastName.value == "")
  			{ 
			alert("Please enter your Last Name.");
    			theForm.CustomerLastName.focus();
    			return (false);
  			}
  
		for(i=0;i<3;i++)
			{
			if (digits.indexOf(theForm.AreaCode.value.charAt(i))<0)
				{
				alert("The phone number must be numeric");
				theForm.AreaCode.value = "";
				theForm.AreaCode.focus();
				return (false);
				}
			}

		if (theForm.AreaCode.value.length < 3)
			{
			alert("The area code needs to be at least 3 characters long.");
			theForm.AreaCode.value = "";
  			theForm.AreaCode.focus();
			return (false);
			}

		for(i=0;i<3;i++)
			{
			if (digits.indexOf(theForm.PhonePrefix.value.charAt(i))<0)
				{
				alert("The phone number must be numeric");
				theForm.PhonePrefix.value = "";
				theForm.PhonePrefix.focus();
				return (false);
				}
			}

		if (theForm.PhonePrefix.value.length < 3)
			{
			alert("The phone prefix needs to be at least 3 characters long.");
			theForm.PhonePrefix.value = "";
  			theForm.PhonePrefix.focus();
			return (false);
			}

		for(i=0;i<4;i++)
			{
			if (digits.indexOf(theForm.PhoneSufix.value.charAt(i))<0)
				{
				alert("The phone number must be numeric");
				theForm.PhoneSufix.value = "";
				theForm.PhoneSufix.focus();
				return (false);
				}
			}

		if (theForm.PhoneSufix.value.length < 4)
			{
			alert("The phone sufix needs to be at least 4 characters long.");
			theForm.PhoneSufix.value = "";
  			theForm.PhoneSufix.focus();
			return (false);
			}
		
		if (theForm.Address1.value == "")
  			{ 
			alert("Please enter your address.");
    			theForm.Address1.focus();
    			return (false);
  			}
  
		if (theForm.City.value == "")
  			{ 
			alert("Please enter your city.");
    			theForm.City.focus();
    			return (false);
  			}	
  
		if (theForm.State.options[theForm.State.selectedIndex].value == "-1")
     			{
			alert("Please select a state.");
     			theForm.State.focus();
     			return (false);
     			}

		if (theForm.ZipCode.value == "")
  			{ 
			alert("Please enter your zip code.");
    			theForm.ZipCode.focus();
    			return (false);
  			}
     
		for(i=0;i<5;i++)
			{
				if (digits.indexOf(theForm.ZipCode.value.charAt(i))<0)
					{
					alert("The zip code must be numeric");
					theForm.ZipCode.value = "";
					theForm.ZipCode.focus();
					return (false);
					}
			}

		if (theForm.ZipCode.value.length < 5)
			{
			alert("The zip code needs to be at least 5 characters long.");
			theForm.ZipCode.value = "";
  			theForm.ZipCode.focus();
			return (false);
			}
	}
return (true);
}

function funcCheckoutBillingValidator(theForm)
{
var blnCheckAddress = 0

	//alert("Not New Customer");
	var intRadioGroupLength;
	var blnIsChecked;
	var intNewAddress

	//determine the number of radio buttons
	intRadioGroupLength = theForm.BillingAddressID.length;
	//alert(intRadioGroupLength);
	
	//determine the position of the create new address radio button
	intNewAddress = intRadioGroupLength - 1

	//determine whether it's been checked
	blnIsChecked = document.theForm.BillingAddressID[intNewAddress].checked;
	//alert(blnIsChecked);
				
	//has the create new address button been checked?
	if(blnIsChecked)
		{
			//if it's been checked then set the flag
			blnCheckAddress = 1;
		}
			
	

	//do we need to validate for a new address?
	if(blnCheckAddress)
	{
		if (theForm.CustomerFirstName.value == "")
			{ 
			alert("Please enter a your First Name.");
			theForm.CustomerFirstName.value = "";
  			theForm.CustomerFirstName.focus();
			return (false);
			}

		if (theForm.CustomerLastName.value == "")
  			{ 
			alert("Please enter your Last Name.");
    			theForm.CustomerLastName.focus();
    			return (false);
  			}
  
		for(i=0;i<3;i++)
			{
			if (digits.indexOf(theForm.AreaCode.value.charAt(i))<0)
				{
				alert("The phone number must be numeric");
				theForm.AreaCode.value = "";
				theForm.AreaCode.focus();
				return (false);
				}
			}

		if (theForm.AreaCode.value.length < 3)
			{
			alert("The area code needs to be at least 3 characters long.");
			theForm.AreaCode.value = "";
  			theForm.AreaCode.focus();
			return (false);
			}

		for(i=0;i<3;i++)
			{
			if (digits.indexOf(theForm.PhonePrefix.value.charAt(i))<0)
				{
				alert("The phone number must be numeric");
				theForm.PhonePrefix.value = "";
				theForm.PhonePrefix.focus();
				return (false);
				}
			}

		if (theForm.PhonePrefix.value.length < 3)
			{
			alert("The phone prefix needs to be at least 3 characters long.");
			theForm.PhonePrefix.value = "";
  			theForm.PhonePrefix.focus();
			return (false);
			}

		for(i=0;i<4;i++)
			{
			if (digits.indexOf(theForm.PhoneSufix.value.charAt(i))<0)
				{
				alert("The phone number must be numeric");
				theForm.PhoneSufix.value = "";
				theForm.PhoneSufix.focus();
				return (false);
				}
			}

		if (theForm.PhoneSufix.value.length < 4)
			{
			alert("The phone sufix needs to be at least 4 characters long.");
			theForm.PhoneSufix.value = "";
  			theForm.PhoneSufix.focus();
			return (false);
			}
		
		if (theForm.Address1.value == "")
  			{ 
			alert("Please enter your address.");
    			theForm.Address1.focus();
    			return (false);
  			}
  
		if (theForm.City.value == "")
  			{ 
			alert("Please enter your city.");
    			theForm.City.focus();
    			return (false);
  			}	
  
		if (theForm.State.options[theForm.State.selectedIndex].value == "-1")
     			{
			alert("Please select a state.");
     			theForm.State.focus();
     			return (false);
     			}

		if (theForm.ZipCode.value == "")
  			{ 
			alert("Please enter your zip code.");
    			theForm.ZipCode.focus();
    			return (false);
  			}
     
		for(i=0;i<5;i++)
			{
				if (digits.indexOf(theForm.ZipCode.value.charAt(i))<0)
					{
					alert("The zip code must be numeric");
					theForm.ZipCode.value = "";
					theForm.ZipCode.focus();
					return (false);
					}
			}

		if (theForm.ZipCode.value.length < 5)
			{
			alert("The zip code needs to be at least 5 characters long.");
			theForm.ZipCode.value = "";
  			theForm.ZipCode.focus();
			return (false);
			}
	}
return (true);
}

function funcCheckoutPaymentValidator(theForm)
{
var strAdjustedCardType;
var strNewCustomer = document.theForm.NewCustomer.value
var strCardNumber = document.theForm.cc_number.value
var strCardType = theForm.payment_method.options[theForm.payment_method.selectedIndex].value
var strExpMonth = theForm.cc_expiration_month.options[theForm.cc_expiration_month.selectedIndex].value
var strExpYear = theForm.cc_expiration_year.options[theForm.cc_expiration_year.selectedIndex].value
var blnCheckCard = 0

	if ( strNewCustomer == "True")
	{
				
		//since this is new customer then we need to set the flag
		blnCheckCard = 1;

	}
	else
	{
		//alert("Not New Customer");
		var intRadioGroupLength;
		var blnIsChecked;
		var intNewCard

		//determine the number of radio buttons
		intRadioGroupLength = theForm.CardID.length;
		//alert(intRadioGroupLength);
		
		//determine the position of the create new card radio button
		intNewCard = intRadioGroupLength - 1

		//determine whether it's been checked
		blnIsChecked = document.theForm.CardID[intNewCard].checked;
		//alert(blnIsChecked);
				
		//has the create new card button been checked?
		if(blnIsChecked)
			{
				//if it's been checked then set the flag
				blnCheckCard = 1;
				
			}
			
	}

	//do we need to validate for a new card?
	if(blnCheckCard)
	{
		if (theForm.payment_method.options[theForm.payment_method.selectedIndex].value == "-1")
     			{
			alert("Please select a Payment Method.");
     			theForm.payment_method.focus();
     			return (false);
     			}

		if (theForm.ccNameOnCard.value == "")
  			{ 
			alert("Please enter the name on the card.");
    			theForm.ccNameOnCard.focus();
    			return (false);
  			}	

		if (theForm.cc_number.value == "")
  			{ 
			alert("Please enter your credit card number.");
    			theForm.cc_number.focus();
    			return (false);
  			}	

		//for(i=0;i<20;i++)
		//	{
		//	if (digits.indexOf(theForm.cc_number.value.charAt(i))<0)
		//		{
		//		alert("The credit card must be numeric.");
		//		theForm.cc_number.value = "";
		//		theForm.cc_number.focus();
		//		return (false);
				//}
			//}

		if (theForm.cc_expiration_month.options[theForm.cc_expiration_month.selectedIndex].value == "-1")
     			{
			alert("Please select a credit card expiration month.");
     			theForm.cc_expiration_month.focus();
     			return (false);
     			}	

		if (theForm.cc_expiration_year.options[theForm.cc_expiration_year.selectedIndex].value == "-1")
     			{
			alert("Please select a credit card expiration year.");
     			theForm.cc_expiration_year.focus();
     			return (false);
     			}

		//do the advance credit card checks
		switch (strCardType)
			{
			case "Visa" : 
      				strAdjustedCardType = "v"; 
     				 break; 
			case "MasterCard" : 
      				strAdjustedCardType = "m"; 
     				 break; 
			case "Discover" : 
      				strAdjustedCardType = "d"; 
     				 break;
			case "American" : 
      				strAdjustedCardType = "a"; 
     				 break;  
   			default : 
      				strAdjustedCardType = "v"; 
			} 


		if( !validateCard(strCardNumber,strAdjustedCardType,strExpMonth,strExpYear) ) 
			{ 		// run the check digit algorithm
                        //alert("Sorry! this is not a valid credit card.");
                        return false;
			}
			
	}

return (true);
}

/*
There are three functions in this set for credit card validation.
The main function is:
validateCard(cardNumber,cardType,cardMonth,cardYear)
	parameters:
		all paramaters are string values.
		Month & Year come from the select input fields in the form, so they are defined.
		cardType can be:
			'a' for American Express
			'd' for Discover
			'm' for MasterCard
			'v' for Visa
	description:
		this function will check string length, valid characters, specific credit card prefixes and test
		the Mod 10 (LUHN Formula) for validating possible credit card numbers. this function can only
		authorize that the given card data is potentially valid. You would still need to run actual
		card validation routines to verify the actual account.
	returns:
		this function returns true if the card number could be valid for the card type and expiration date.
		false otherwise.	
supporting functions:
mod10( cardNumber )
	parameters:
		this function takes the text string card number and runs the Mod 10 formula on its respective digits.
	description:
		Mod 10 is the check digit formula for the supported cards these functions attempt to validate.
	returns:
		this function returns true if the number passes the check digit test.
		false otherwise.
expired( cardMonth, cardYear )
	parameters:
		this function takes the text string values given by the html form.
	description:
		this function basically will check to make sure todays date is less than the expiration date the user inputs.
		this function is not locked into using 2 digit dates.
	returns:
		this fucntion returns true if the card is expired.
		false otherwise.
*/
function mod10( cardNumber ) { // LUHN Formula for validation of credit card numbers.
	var ar = new Array( cardNumber.length );
	var i = 0,sum = 0;


    	for( i = 0; i < cardNumber.length; ++i ) {
    		ar[i] = parseInt(cardNumber.charAt(i));
    	}
    	for( i = ar.length -2; i >= 0; i-=2 ) { // you have to start from the right, and work back.
    		ar[i] *= 2;							 // every second digit starting with the right most (check digit)
    		if( ar[i] > 9 ) ar[i]-=9;			 // will be doubled, and summed with the skipped digits.
    	}										 // if the double digit is > 9, ADD those individual digits together 


        	for( i = 0; i < ar.length; ++i ) {
        		sum += ar[i];						 // if the sum is divisible by 10 mod10 succeeds
        	}
        	return (((sum%10)==0)?true:false);	 	
    }


        function expired( month, year ) {
        	var now = new Date();							// this function is designed to be Y2K compliant.
        	var expiresIn = new Date(year,month,0,0,0);		// create an expired on date object with valid thru expiration date
        	expiresIn.setMonth(expiresIn.getMonth()+1);		// adjust the month, to first day, hour, minute & second of expired month
        	if( now.getTime() < expiresIn.getTime() ) return false;
        	return true;									// then we get the miliseconds, and do a long integer comparison
    }


        function validateCard(cardNumber,cardType,cardMonth,cardYear) {
        	if( cardNumber.length == 0 ) {						//most of these checks are self explanitory
        		alert("Please enter a valid card number.");
        		return false;				
        	}
        	for( var i = 0; i < cardNumber.length; ++i ) {		// make sure the number is all digits.. (by design)
        		var c = cardNumber.charAt(i);


            		if( c < '0' || c > '9' ) {
            			alert("Please enter a valid card number. Use only digits. do not use spaces or hyphens.");
            			return false;
            		}
            	}
            	var length = cardNumber.length;			//perform card specific length and prefix tests


                	switch( cardType ) {
                		case 'a':


                    			if( length != 15 ) {
                    				alert("Please enter a valid American Express Card number.");
                    				return;
                    			}
                    			var prefix = parseInt( cardNumber.substring(0,2));


                        			if( prefix != 34 && prefix != 37 ) {
                        				alert("Please enter a valid American Express Card number.");
                        				return;
                        			}
                        			break;
                        		case 'd':


                            			if( length != 16 ) {
                            				alert("Please enter a valid Discover Card number.");
                            				return;
                            			}
                            			var prefix = parseInt( cardNumber.substring(0,4));


                                			if( prefix != 6011 ) {
                                				alert("Please enter a valid Discover Card number.");
                                				return;
                                			}
                                			break;
                                		case 'm':


                                    			if( length != 16 ) {
                                    				alert("Please enter a valid MasterCard number.");
                                    				return;
                                    			}
                                    			var prefix = parseInt( cardNumber.substring(0,2));


                                        			if( prefix < 51 || prefix > 55) {
                                        				alert("Please enter a valid MasterCard Card number.");
                                        				return;
                                        			}
                                        			break;
                                        		case 'v':


                                            			if( length != 16 && length != 13 ) {
                                            				alert("Please enter a valid Visa Card number.");
                                            				return;
                                            			}
                                            			var prefix = parseInt( cardNumber.substring(0,1));


                                                			if( prefix != 4 ) {
                                                				alert("Please enter a valid Visa Card number.");
                                                				return;
                                                			}
                                                			break;
                                                	}
                                                	if( !mod10( cardNumber ) ) { 		// run the check digit algorithm
                                                		alert("Sorry! this is not a valid credit card number.");
                                                		return false;
                                                	}
                                                	if( expired( cardMonth, cardYear ) ) {							// check if entered date is already expired.
                                                		alert("Sorry! The expiration date you have entered would make this card invalid.");
                                                		return false;
                                                	}
                                                	
                                                	return true; // at this point card has not been proven to be invalid
                                            }


//-->