var sent=0;
var currentForm;
var req;

function alertWin(x, err) 
{
    var lsError = "<font color=red size=2><b>Errors (The following fields are required):</b></font><hr><font size=2>";
    for (i = 0; i < x; i++){
        lsError += ((i+1) + ". " + err[i] + "<br>");
    }
    document.getElementById("errs").innerHTML = lsError + "</font>";
    document.getElementById("LandingPagePopupBox").style.display = "block";
    
    
}

function closeWin(x, err) 
{
    document.getElementById("LandingPagePopupBox").style.display = "none";
    
    
}

//this is for landing3 page.
function resetTextboxes_landing3(theForm) {
	theForm.shipFirst.style.backgroundColor = "#FFFFFF";
	theForm.shipFirst.style.borderColor = "#e2e2e2"; 
	theForm.shipLast.style.backgroundColor = "#FFFFFF";
	theForm.shipLast.style.borderColor = "#e2e2e2"; 
	
	theForm.shipadd1.style.backgroundColor = "#FFFFFF";
	theForm.shipadd1.style.borderColor = "#e2e2e2"; 
	theForm.shipzip1.style.backgroundColor = "#FFFFFF";
	theForm.shipzip1.style.borderColor = "#e2e2e2"; 
	theForm.shipcity.style.backgroundColor = "#FFFFFF";
	theForm.shipcity.style.borderColor = "#e2e2e2"; 
	theForm.shipphonearea.style.borderColor = "#e2e2e2"; 
	theForm.shipphonearea.style.backgroundColor = "#FFFFFF";
	theForm.shipphoneprefix.style.borderColor = "#e2e2e2"; 
	theForm.shipphoneprefix.style.backgroundColor = "#FFFFFF";
	theForm.shipphonepostfix.style.borderColor = "#e2e2e2"; 
	theForm.shipphonepostfix.style.backgroundColor = "#FFFFFF";
	theForm.email.style.backgroundColor = "#FFFFFF";
	theForm.email.style.borderColor = "#e2e2e2"; 
	
	theForm.ccnumber.style.backgroundColor = "#FFFFFF";
	theForm.ccnumber.style.borderColor = "#e2e2e2"; 
	theForm.cctype.style.backgroundColor = "#FFFFFF";
	theForm.cctype.style.borderColor = "#e2e2e2";   
	theForm.cccode.style.backgroundColor = "#FFFFFF";
	theForm.cccode.style.borderColor = "#e2e2e2";   
	theForm.ccname.style.backgroundColor = "#FFFFFF";
	theForm.ccname.style.borderColor = "#e2e2e2"; 

	theForm.ccMonth.style.backgroundColor = "#FFFFFF";
	theForm.ccMonth.style.borderColor = "#e2e2e2";   
	theForm.ccYear.style.backgroundColor = "#FFFFFF";
	theForm.ccYear.style.borderColor = "#e2e2e2";   

	theForm.billphonearea.style.backgroundColor = "#FFFFFF";
	theForm.billphonearea.style.borderColor = "#e2e2e2"; 
	theForm.shipphoneprefix.style.borderColor = "#e2e2e2"; 
	theForm.billphoneprefix.style.backgroundColor = "#FFFFFF";
	theForm.billphonepostfix.style.borderColor = "#e2e2e2"; 
	theForm.billphonepostfix.style.backgroundColor = "#FFFFFF";
	theForm.billadd1.style.backgroundColor = "#FFFFFF";
	theForm.billadd2.style.backgroundColor = "#FFFFFF";
	theForm.billzip1.style.backgroundColor = "#FFFFFF";
	theForm.billcity.style.backgroundColor = "#FFFFFF";
	theForm.billstate.style.backgroundColor = "#FFFFFF";
	theForm.billadd1.style.borderColor = "#e2e2e2"; 
	theForm.billadd2.style.borderColor = "#e2e2e2"; 
	theForm.billzip1.style.borderColor = "#e2e2e2"; 
	theForm.billcity.style.borderColor = "#e2e2e2"; 

	theForm.billstate.style.borderColor = "#e2e2e2"; 
		theForm.fname.style.backgroundColor = "#FFFFFF";
	theForm.fname.style.borderColor = "#e2e2e2"; 
	theForm.lname.style.backgroundColor = "#FFFFFF";
        theForm.lname.style.borderColor = "#e2e2e2"; 
}


function isValidForm3_landing3(theForm) 
{
	currentForm = theForm;
    //check zip and phone 1st.  If they pass, then call web service
    //if web service passes, then move on to the zip code and area code checker.
    resetTextboxes_landing3(theForm);
    
    //call service...
    //validateZipAreaCode(theForm.shipzip1.value,theForm.shipphonearea.value);
    finalizeValidation();
    return(false);
}

function removeSpaces(string) {
 return string.split(' ').join('');
}


function finalizeValidation() {
	document.getElementById("errs").innerHTML = "";
	        var err = new Array();
	    var x=0;
	    
	    if (currentForm.SamplesAggregate.value == "") {
	    	err[x] = 'Please select at least one swatch sample.';
	    	x=x+1;
	    }
	    
	    if (currentForm.shipFirst.value == "")
	    {
	        err[x] = 'Please enter a value for the \"first name\" field.';
	        currentForm.shipFirst.style.backgroundColor = "#FCB1B1";
	        currentForm.shipFirst.style.borderColor = "#7D1111";
	        currentForm.shipFirst.focus();
	        x=x+1;
	    }
	    if (currentForm.shipFirst.value.length < 2)
	    {
	        err[x] = 'Please enter at least 2 characters in the \"first name\" field.';
	        currentForm.shipFirst.style.backgroundColor = "#FCB1B1";
	        currentForm.shipFirst.style.borderColor = "#7D1111";
	        currentForm.shipFirst.focus();
	        x=x+1;
	    }
	    if (currentForm.shipFirst.value.length > 25)
	    {
	        err[x] = 'Please enter at most 25 characters in the \"first name\" field.';
	        currentForm.shipFirst.style.backgroundColor = "#FCB1B1";
	        currentForm.shipFirst.style.borderColor = "#7D1111";
	        currentForm.shipFirst.focus();
	        x=x+1;
	    }
	    if (currentForm.shipLast.value == "")
	    {
	        err[x] = 'Please enter a value for the \"last name\" field.';
	        currentForm.shipLast.style.backgroundColor = "#FCB1B1";
	        currentForm.shipLast.style.borderColor = "#7D1111";
	        currentForm.shipLast.focus();
	        x=x+1;
	    }
	    if (currentForm.shipLast.value.length < 2)
	    {
	        err[x] = 'Please enter at least 2 characters in the \"last name\" field.';
	        currentForm.shipLast.style.backgroundColor = "#FCB1B1";
	        currentForm.shipLast.style.borderColor = "#7D1111";
	        currentForm.shipLast.focus();
	        x=x+1;
	    }
	    if (currentForm.shipLast.value.length > 50)
	    {
	        err[x] = 'Please enter at most 50 characters in the \"last name\" field.';
	        currentForm.shipLast.style.backgroundColor = "#FCB1B1";
	        currentForm.shipLast.style.borderColor = "#7D1111";
	        currentForm.shipLast.focus();
	        x=x+1;
	    }
	    if (currentForm.email.value == "" || currentForm.email.value.indexOf('@', 0) == -1 || currentForm.email.value.indexOf('.', 0) == -1)
	    {
	        err[x] = 'Valid email address.';
	        currentForm.email.style.backgroundColor = "#FCB1B1";
	        currentForm.email.style.borderColor = "#7D1111";
	        x=x+1;
	    }
	
	    //shipping
	    currentForm.shipattn.value = currentForm.shipFirst.value + " " + currentForm.shipLast.value;
	    if (currentForm.shipadd1.value == "")
	    {
	        err[x] = 'Please enter a value for the \"ship address\" field.';
	        currentForm.shipadd1.style.backgroundColor = "#FCB1B1";
	        currentForm.shipadd1.style.borderColor = "#7D1111";
	        currentForm.shipadd1.focus();
	        x=x+1;
	    }
	    if (currentForm.shipadd1.value.length < 5)
	    {
	        err[x] = 'Please enter at least 5 characters in the \"ship address\" field.';
	        currentForm.shipadd1.style.backgroundColor = "#FCB1B1";
	        currentForm.shipadd1.style.borderColor = "#7D1111";
	        currentForm.shipadd1.focus();
	        x=x+1;
	    }
	    
	    var shipAddr = currentForm.shipadd1.value;
	    shipAddr = shipAddr.toLowerCase();
	    shipAddr = shipAddr.split('.').join('');
	    shipAddr = removeSpaces(shipAddr);

	    if (shipAddr.indexOf('pobox') >= 0)
	    {
	        err[x] = 'Unfortunately, UPS is unable to deliver to PO Boxes.  Please give us a real address to continue.';
	        currentForm.shipadd1.style.backgroundColor = "#FCB1B1";
	        currentForm.shipadd1.style.borderColor = "#7D1111";
	        currentForm.shipadd1.focus();
	        x=x+1;
	    }

	    if (currentForm.shipadd1.value.length > 50)
	    {
	        err[x] = 'Please enter at most 50 characters in the \"ship address\" field.';
	        currentForm.shipadd1.style.backgroundColor = "#FCB1B1";
	        currentForm.shipadd1.style.borderColor = "#7D1111";
	        currentForm.shipadd1.focus();
	        x=x+1;
	    }

	    //Does Shipping Address contain a PO Box?


	    if (currentForm.shipcity.value == "")
	    {
	        err[x] = 'Please enter a value for the \"ship city\" field.';
	        currentForm.shipcity.style.backgroundColor = "#FCB1B1";
	        currentForm.shipcity.style.borderColor = "#7D1111";
	        currentForm.shipcity.focus();
	        x=x+1;
	    }
	    if (currentForm.shipcity.value.length < 2)
	    {
	        err[x] = 'Please enter at least 2 characters in the \"ship city\" field.';
	        currentForm.shipcity.style.backgroundColor = "#FCB1B1";
	        currentForm.shipcity.style.borderColor = "#7D1111";
	        currentForm.shipcity.focus();
	        x=x+1;
	    }
	    if (currentForm.shipcity.value.length > 50)
	    {
	        err[x] = 'Please enter at most 50 characters in the \"ship city\" field.';
	        currentForm.shipcity.style.backgroundColor = "#FCB1B1";
	        currentForm.shipcity.style.borderColor = "#7D1111";
	        currentForm.shipcity.focus();
	        x=x+1;
	    }
	    if (document.getElementById("shipstate").selectedIndex == 0)
	    {
	            err[x] = 'Please enter a valid Shipping State.';
	            document.getElementById("shipstate").style.backgroundColor = "#FCB1B1";
	            document.getElementById("shipstate").style.borderColor = "#7D1111";
	            document.getElementById("shipstate").focus();
	            x=x+1;
	    
	    }
	    
	    
	    if (currentForm.shipzip1.value == "")
	    		    {
	    		        err[x] = 'Please enter a value for the \"shiping Postal Code\" field.';
	    		        currentForm.shipzip1.style.backgroundColor = "#FCB1B1";
	    		        currentForm.shipzip1.style.borderColor = "#7D1111";
	    		        currentForm.shipzip1.focus();
	    		        x=x+1;
	    		    }
	    		    if (currentForm.shipzip1.value.length < 4)
	    		    {
	    		        err[x] = 'Please enter at least 4 characters in the \"shiping Postal Code\" field.';
	    		        currentForm.shipzip1.style.backgroundColor = "#FCB1B1";
	    		        currentForm.shipzip1.style.borderColor = "#7D1111";
	    		        currentForm.shipzip1.focus();
	    		        x=x+1;
	    		    }
	    		    if (currentForm.shipzip1.value.length > 10)
	    		    {
	    		        err[x] = 'Please enter at most 10 characters in the \"ship zip\" field.';
	    		        currentForm.shipzip1.style.backgroundColor = "#FCB1B1";
	    		        currentForm.shipzip1.style.borderColor = "#7D1111";
	    		        currentForm.shipzip1.focus();
	    		        x=x+1;
	    		    }
	    		    
	    		    if (!numericOnly(currentForm.shipzip1.value))
	    			{
	    			    err[x] = 'Please enter a valid value in the \"shiping Zip Code\" field.';
	    			    currentForm.shipzip1.style.backgroundColor = "#FCB1B1";
	    			    currentForm.shipzip1.style.borderColor = "#7D1111";
	    			    currentForm.shipzip1.focus();
	    			    x=x+1;
	    			}
	    			
	    			
	    		     if (currentForm.shipphonearea.value == "")
	    		    {
	    		        err[x] = 'Please enter a value for the \"ship phone area code\" field.';
	    		        currentForm.shipphonearea.style.backgroundColor = "#FCB1B1";
	    		        currentForm.shipphonearea.style.borderColor = "#7D1111";
	    		        currentForm.shipphonearea.focus();
	    		        x=x+1;
	    		    }
	    		    if (currentForm.shipphonearea.value.length < 3)
	    		    {
	    		        err[x] = 'Please enter at least 3 characters in the \"ship phone area \" field.';
	    		        currentForm.shipphonearea.style.backgroundColor = "#FCB1B1";
	    		        currentForm.shipphonearea.style.borderColor = "#7D1111";
	    		        currentForm.shipphonearea.focus();
	    		        x=x+1;
	    		    }
	    		   
	    		        if (!numericOnly(currentForm.shipphonearea.value))
	    			{
	    				err[x] = 'Please enter a valid value in the \"ship Phone Area Code\" field.';
	    				currentForm.shipphonearea.style.backgroundColor = "#FCB1B1";
	    				currentForm.shipphonearea.style.borderColor = "#7D1111";
	    				currentForm.shipphonearea.focus();
	    				x=x+1;
			}
	    
	
		if (!numericOnly(currentForm.shipphoneprefix.value))
		{
			err[x] = 'Please enter a valid value in the \"Ship Phone Prefix\" field.';
			currentForm.shipphoneprefix.style.backgroundColor = "#FCB1B1";
			currentForm.shipphoneprefix.style.borderColor = "#7D1111";
			currentForm.shipphoneprefix.focus();
			x=x+1;
		}
	
		if (!numericOnly(currentForm.shipphonepostfix.value))
		{
			err[x] = 'Please enter a valid value in the \"Ship Phone Postfix\" field.';
			currentForm.shipphonepostfix.style.backgroundColor = "#FCB1B1";
			currentForm.shipphonepostfix.style.borderColor = "#7D1111";
			currentForm.shipphonepostfix.focus();
			x=x+1;
		}
	        
	        if (currentForm.shipphoneprefix.value == "")
	            {
	                err[x] = 'Please enter a value for the \"ship phone prefix\" field.';
	                currentForm.shipphoneprefix.style.backgroundColor = "#FCB1B1";
	                currentForm.shipphoneprefix.style.borderColor = "#7D1111";
	                currentForm.shipphoneprefix.focus();
	                x=x+1;
	            }
	            if (currentForm.shipphoneprefix.value.length < 3)
	            {
	                err[x] = 'Please enter at least 3 characters in the \"ship phone prefix \" field.';
	                currentForm.shipphoneprefix.style.backgroundColor = "#FCB1B1";
	                currentForm.shipphoneprefix.style.borderColor = "#7D1111";
	                currentForm.shipphoneprefix.focus();
	                x=x+1;
	        }
	        
	        if (currentForm.shipphonepostfix.value == "")
	            {
	                err[x] = 'Please enter a value for the \"ship phone s\" field.';
	                currentForm.shipphonepostfix.style.backgroundColor = "#FCB1B1";
	                currentForm.shipphonepostfix.style.borderColor = "#7D1111";
	                currentForm.shipphonepostfix.focus();
	                x=x+1;
	            }
	    if (currentForm.shipphonepostfix.value.length < 4)
	    {
		err[x] = 'Please enter at least 3 characters in the \"ship phone suffix \" field.';
		currentForm.shipphonepostfix.style.backgroundColor = "#FCB1B1";
		currentForm.shipphonepostfix.style.borderColor = "#7D1111";
		currentForm.shipphonepostfix.focus();
		x=x+1;
	    }
	    
	    currentForm.shipphone.value = currentForm.shipphonearea.value + currentForm.shipphoneprefix.value + currentForm.shipphonepostfix.value
	    
	    var theForm = currentForm;
	    
	    if (currentForm.PriorityShip.checked == true) {
	    	//validate the credit card fields
	    	if (theForm.cctype.value == "")
		{
		    err[x] = 'Please select the credit card type from the menu.';
		    theForm.cctype.style.backgroundColor = "#FCB1B1";
		    theForm.cctype.style.borderColor = "#7D1111";
		    theForm.cctype.focus();
		    x=x+1;
		}
		if (theForm.ccnumber.value == "")
		{
		    err[x] = 'Please enter a valid credit card number.';
		    theForm.ccnumber.style.backgroundColor = "#FCB1B1";
		    theForm.ccnumber.style.borderColor = "#7D1111";
		    theForm.ccnumber.focus();
		    x=x+1;
		}
		if (theForm.cctype.value == "AmericanExpress")
		{
		    if (theForm.ccnumber.value.length < 15)
		    {
			err[x] = 'American Express cards have 15 digits.  Please enter only 15 digits with no spaces or dashes.';
			theForm.ccnumber.style.backgroundColor = "#FCB1B1";
			theForm.ccnumber.style.borderColor = "#7D1111";
			theForm.ccnumber.focus();
			x=x+1;
		    }
		    if (theForm.ccnumber.value.length > 17)
		    {
			err[x] = 'American Express cards have 15 digits.  Please enter only 15 digits with no spaces or dashes.';
			theForm.ccnumber.style.backgroundColor = "#FCB1B1";
			theForm.ccnumber.style.borderColor = "#7D1111";
			theForm.ccnumber.focus();
			x=x+1;
		    }
		}
		if (theForm.cctype.selectedIndex > 1)
		{
		    if (theForm.ccnumber.value.length < 16)
		    {
			err[x] = 'Visa, Mastercard and Discover cards have 16 digits.  Please enter only 16 digits with no spaces or dashes.';
			theForm.ccnumber.style.backgroundColor = "#FCB1B1";
			theForm.ccnumber.style.borderColor = "#7D1111";
			theForm.ccnumber.focus();
			x=x+1;
		    }
		    if (theForm.ccnumber.value.length > 19)
		    {
			err[x] = 'Visa, Mastercard and Discover cards have 16 digits.  Please enter only 16 digits with no spaces or dashes.';
			theForm.ccnumber.style.backgroundColor = "#FCB1B1";
			theForm.ccnumber.style.borderColor = "#7D1111";
			theForm.ccnumber.focus();
			x=x+1;
		    }
		}
		if (theForm.cccode.value == "")
		{
		    err[x] = 'Please enter your credit card security code. This helps to prevent fraud.';
		    theForm.cccode.style.backgroundColor = "#FCB1B1";
		    theForm.cccode.style.borderColor = "#7D1111";
		    theForm.cccode.focus();
		    x=x+1;
		}
		if (theForm.ccname.value == "")
		{
		    err[x] = 'Please enter card holders full name.';
		    theForm.ccname.style.backgroundColor = "#FCB1B1";
		    theForm.ccname.style.borderColor = "#7D1111";
		    theForm.ccname.focus();
		    x=x+1;
		}
		
		if (theForm.ccMonth.selectedIndex < 1) {
		    	err[x] = 'Please select a valid credit card expiration month.';
			theForm.ccMonth.style.backgroundColor = "#FCB1B1";
			theForm.ccMonth.style.borderColor = "#7D1111";
			theForm.ccMonth.focus();
			x=x+1;
		}
			
		if (theForm.ccYear.selectedIndex < 1) {
			err[x] = 'Please select a valid credit card expiration year.';
			theForm.ccYear.style.backgroundColor = "#FCB1B1";
			theForm.ccYear.style.borderColor = "#7D1111";
			theForm.ccYear.focus();
			x=x+1;
    		}
	    }
	    
	   
	    if (currentForm.shipinfo.checked == true) {
	    	//validate the billing fields
	    	if (theForm.fname.value == "")
		    {
		        err[x] = 'Please enter a value for the \"first name\" field.';
		        theForm.fname.style.backgroundColor = "#FCB1B1";
		        theForm.fname.style.borderColor = "#7D1111";
		        theForm.fname.focus();
		        x=x+1;
		    }
		    if (theForm.fname.value.length < 2)
		    {
		        err[x] = 'Please enter at least 2 characters in the \"first name\" field.';
		        theForm.fname.style.backgroundColor = "#FCB1B1";
		        theForm.fname.style.borderColor = "#7D1111";
		        theForm.fname.focus();
		        x=x+1;
		    }
		    if (theForm.fname.value.length > 25)
		    {
		        err[x] = 'Please enter at most 25 characters in the \"first name\" field.';
		        theForm.fname.style.backgroundColor = "#FCB1B1";
		        theForm.fname.style.borderColor = "#7D1111";
		        theForm.fname.focus();
		        x=x+1;
		    }
		    if (theForm.lname.value == "")
		    {
		        err[x] = 'Please enter a value for the \"last name\" field.';
		        theForm.lname.style.backgroundColor = "#FCB1B1";
		        theForm.lname.style.borderColor = "#7D1111";
		        theForm.lname.focus();
		        x=x+1;
		    }
		    if (theForm.lname.value.length < 2)
		    {
		        err[x] = 'Please enter at least 2 characters in the \"last name\" field.';
		        theForm.lname.style.backgroundColor = "#FCB1B1";
		        theForm.lname.style.borderColor = "#7D1111";
		        theForm.lname.focus();
		        x=x+1;
		    }
		    if (theForm.lname.value.length > 50)
		    {
		        err[x] = 'Please enter at most 50 characters in the \"last name\" field.';
		        theForm.lname.style.backgroundColor = "#FCB1B1";
		        theForm.lname.style.borderColor = "#7D1111";
		        theForm.lname.focus();
		        x=x+1;
		    }
			
			if (theForm.billadd1.value == "")
		    {
		        err[x] = 'Please enter a value for the \"Bill Address\" field.';
		        theForm.billadd1.style.backgroundColor = "#FCB1B1";
		        theForm.billadd1.style.borderColor = "#7D1111";
		        theForm.billadd1.focus();
		        x=x+1;
		    }
		    if (theForm.billadd1.value.length < 5)
		    {
		        err[x] = 'Please enter at least 5 characters in the \"Bill Address\" field.';
		        theForm.billadd1.style.backgroundColor = "#FCB1B1";
		        theForm.billadd1.style.borderColor = "#7D1111";
		        theForm.billadd1.focus();
		        x=x+1;
		    }
		    if (theForm.billadd1.value.length > 50)
		    {
		        err[x] = 'Please enter at most 50 characters in the \"Bill Address\" field.';
		        theForm.billadd1.style.backgroundColor = "#FCB1B1";
		        theForm.billadd1.style.borderColor = "#7D1111";
		        theForm.billadd1.focus();
		        x=x+1;
		    }
		    if (theForm.billcity.value == "")
		    {
		        err[x] = 'Please enter a value for the \"bill city\" field.';
		        theForm.billcity.style.backgroundColor = "#FCB1B1";
		        theForm.billcity.style.borderColor = "#7D1111";
		        theForm.billcity.focus();
		        x=x+1;
		    }
		    if (theForm.billcity.value.length <= 1)
		    {
		        err[x] = 'Please enter at least 2 characters in the \"bill city\" field.';
		        theForm.billcity.style.backgroundColor = "#FCB1B1";
		        theForm.billcity.style.borderColor = "#7D1111";
		        theForm.billcity.focus();
		        x=x+1;
		    }
		    if (theForm.billcity.value.length >= 51)
		    {
		        err[x] = 'Please enter at most 50 characters in the \"bill city\" field.';
		        theForm.billcity.style.backgroundColor = "#FCB1B1";
		        theForm.billcity.style.borderColor = "#7D1111";
		        theForm.billcity.focus();
		        x=x+1;
		    }
		    if (theForm.billstate.selectedIndex == "0")
		    {
		        err[x] = 'Please enter a valid state or province field.';
			    theForm.billstate.style.backgroundColor = "#FCB1B1";
			    theForm.billstate.style.borderColor = "#7D1111";
			    theForm.billstate.focus();
			    x=x+1;
		        
		    }
		    
		    
		    if (theForm.billzip1.value == "")
		    {
		        err[x] = 'Please enter a value for the \"Billing Postal Code\" field.';
		        theForm.billzip1.style.backgroundColor = "#FCB1B1";
		        theForm.billzip1.style.borderColor = "#7D1111";
		        theForm.billzip1.focus();
		        x=x+1;
		    }
		    if (theForm.billzip1.value.length < 4)
		    {
		        err[x] = 'Please enter at least 4 characters in the \"Billing Postal Code\" field.';
		        theForm.billzip1.style.backgroundColor = "#FCB1B1";
		        theForm.billzip1.style.borderColor = "#7D1111";
		        theForm.billzip1.focus();
		        x=x+1;
		    }
		    if (theForm.billzip1.value.length > 10)
		    {
		        err[x] = 'Please enter at most 10 characters in the \"bill zip\" field.';
		        theForm.billzip1.style.backgroundColor = "#FCB1B1";
		        theForm.billzip1.style.borderColor = "#7D1111";
		        theForm.billzip1.focus();
		        x=x+1;
		    }
		    
		    if (!numericOnly(theForm.billzip1.value))
			{
			    err[x] = 'Please enter a valid value in the \"Billing Zip Code\" field.';
			    theForm.billzip1.style.backgroundColor = "#FCB1B1";
			    theForm.billzip1.style.borderColor = "#7D1111";
			    theForm.billzip1.focus();
			    x=x+1;
			}
			
			
		     if (theForm.billphonearea.value == "")
		    {
		        err[x] = 'Please enter a value for the \"bill phone area code\" field.';
		        theForm.billphonearea.style.backgroundColor = "#FCB1B1";
		        theForm.billphonearea.style.borderColor = "#7D1111";
		        theForm.billphonearea.focus();
		        x=x+1;
		    }
		    if (theForm.billphonearea.value.length < 3)
		    {
		        err[x] = 'Please enter at least 3 characters in the \"bill phone area \" field.';
		        theForm.billphonearea.style.backgroundColor = "#FCB1B1";
		        theForm.billphonearea.style.borderColor = "#7D1111";
		        theForm.billphonearea.focus();
		        x=x+1;
		    }
		   
		        if (!numericOnly(theForm.billphonearea.value))
			{
				err[x] = 'Please enter a valid value in the \"bill Phone Area Code\" field.';
				theForm.billphonearea.style.backgroundColor = "#FCB1B1";
				theForm.billphonearea.style.borderColor = "#7D1111";
				theForm.billphonearea.focus();
				x=x+1;
			}
			
			if (!numericOnly(theForm.billphoneprefix.value))
			{
				err[x] = 'Please enter a valid value in the \"bill Phone Prefix\" field.';
				theForm.billphoneprefix.style.backgroundColor = "#FCB1B1";
				theForm.billphoneprefix.style.borderColor = "#7D1111";
				theForm.billphoneprefix.focus();
				x=x+1;
			}
			
			if (!numericOnly(theForm.billphonepostfix.value))
			{
				err[x] = 'Please enter a valid value in the \"bill Phone Postfix\" field.';
				theForm.billphonepostfix.style.backgroundColor = "#FCB1B1";
				theForm.billphonepostfix.style.borderColor = "#7D1111";
				theForm.billphonepostfix.focus();
				x=x+1;
			}
			
		    if (theForm.billphoneprefix.value == "")
		        {
		            err[x] = 'Please enter a value for the \"bill phone prefix\" field.';
		            theForm.billphoneprefix.style.backgroundColor = "#FCB1B1";
		            theForm.billphoneprefix.style.borderColor = "#7D1111";
		            theForm.billphoneprefix.focus();
		            x=x+1;
		        }
		        if (theForm.billphoneprefix.value.length < 3)
		        {
		            err[x] = 'Please enter at least 3 characters in the \"bill phone prefix \" field.';
		            theForm.billphoneprefix.style.backgroundColor = "#FCB1B1";
		            theForm.billphoneprefix.style.borderColor = "#7D1111";
		            theForm.billphoneprefix.focus();
		            x=x+1;
		    }
		    
		    if (theForm.billphonepostfix.value == "")
		        {
		            err[x] = 'Please enter a value for the \"bill phone s\" field.';
		            theForm.billphonepostfix.style.backgroundColor = "#FCB1B1";
		            theForm.billphonepostfix.style.borderColor = "#7D1111";
		            theForm.billphonepostfix.focus();
		            x=x+1;
		        }
		        if (theForm.billphonepostfix.value.length < 4)
		        {
		            err[x] = 'Please enter at least 3 characters in the \"bill phone suffix \" field.';
		            theForm.billphonepostfix.style.backgroundColor = "#FCB1B1";
		            theForm.billphonepostfix.style.borderColor = "#7D1111";
		            theForm.billphonepostfix.focus();
		            x=x+1;
		    }
		    
    		    theForm.billphone.value = theForm.billphonearea.value + theForm.billphoneprefix.value + theForm.billphonepostfix.value;
	    	
	    }
	    else {
	    	currentForm.fname.value = currentForm.shipFirst.value;
		currentForm.lname.value = currentForm.shipLast.value;
		currentForm.billadd1.value = currentForm.shipadd1.value;
		currentForm.billadd2.value = currentForm.shipadd2.value;
		currentForm.billcity.value = currentForm.shipcity.value;
		
		var stateVal = getValueSelected(document.getElementById("shipstate"));
		currentForm.billstate.value = stateVal;
		currentForm.billzip1.value = currentForm.shipzip1.value;
		currentForm.billphonearea.value = currentForm.shipphonearea.value;
		currentForm.billphoneprefix.value = currentForm.shipphoneprefix.value;
		currentForm.billphonepostfix.value = currentForm.shipphonepostfix.value;
		currentForm.billphone.value = theForm.billphonearea.value + theForm.billphoneprefix.value + theForm.billphonepostfix.value;
	    }
	    
	    if (x > 0)
	    {
			alertWin(x, err);
			return(false);
	    }
	    else
	    {
	        if (sent==0)
	        {
				
		
		    document.getElementById("errs").innerHTML = "<BR><B><I>Processing Order, Please Be Patient...</I></B><BR>";
	            currentForm.submit();
	            sent=1;
	        }
    }
	
}

var phone_field_length=0;

function getValueSelected(obj){ 
	return(obj.options[obj.selectedIndex].value);
}

function TabNext(obj,event,len,next_field) {
	if (event == "down") {
		phone_field_length=obj.value.length;
		}
	else if (event == "up") {
		if (obj.value.length != phone_field_length) {
			phone_field_length=obj.value.length;
			if (phone_field_length == len) {
				next_field.focus();
			}
		}
	}
}

function numericOnly(strString) {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
	{
	strChar = strString.charAt(i);
	if (strValidChars.indexOf(strChar) == -1)
	 {
	 blnResult = false;
	 }
	}
	return blnResult;
}


//--------------THIS AREA CONTAINS WEB SERVICE CALLS-----------------------------

function validateZipAreaCode(zipcode,phone) {
      // branch for native XMLHttpRequest object
      var url = "backadmin/netfunctions.asmx/getCityStateAreaCode?zipCode=" + zipcode + "&phone=" + phone;
      
      if (window.ActiveXObject) {
          isIE = true;
          req = new ActiveXObject("Microsoft.XMLHTTP");
          if (req) {
            req.onreadystatechange = processWSResponse;
	    req.open("GET", url, true);
            req.send();
          }
      }
      
      else if (window.XMLHttpRequest) {
          req = new XMLHttpRequest();
          req.onreadystatechange = processWSResponse;
          req.open("GET", url, true);
          req.send(null);                  
      } 
      
      
  }
  
   //JL AJAX Billing postal lookup
    function processWSResponse() {
    
        if (req.readyState == 4) {
            if (req.status == 200) {
              response  = req.responseXML.documentElement;
              //if the elements exist then populate, otherwise, blank the values out 
              try 
              {
              	  
                  areacode = response.getElementsByTagName('areacode')[0].firstChild.data;
                  state = response.getElementsByTagName('state')[0].firstChild.data;                  
                  
                  
              }
              catch (error) {
                    alert("Either your zip code or your area code are invalid.  Please enter a valid zip code and area code before continuing.");
                    return(false);
              }
              
              finalizeValidation();  
                         
            } 
            else 
            {
                finalizeValidation();
            }
        }
  }
  
  //JL AJAX Coupon lookup
      function processCouponResponse() {
      
          if (req.readyState == 4) {
              if (req.status == 200) {
                response  = req.responseText;
                //if the elements exist then populate, otherwise, blank the values out 
                try 
                {
                    if (response == "") 
                    {alert('Sorry, the code you entered is not currently valid.');}
                    else {
                          document.getElementById("couponResult").innerHTML = "<b>Congratulations<br />Please select free ground<br />shipping below</b>";
                          
                          if (response.indexOf("FREE") > -1) {
                                document.getElementById("promo").value = "promo";
                          	var elSel = document.getElementById("shippingType");
                          	var elOptNew = document.createElement('option');
				elOptNew.text = 'Free Ground Delivery!';
				elOptNew.value = '141';
				var elOptOld = elSel.options[elSel.selectedIndex];  
				    try {
				      elSel.add(elOptNew, elOptOld); // standards compliant; doesn't work in IE
				    }
				    catch(ex) {
				      elSel.add(elOptNew, elSel.selectedIndex); // IE only
				    }
  			  }
                          
                    }
                }
                catch (error) {
                      alert("A problem occurred reaching our promo engine, sorry for the inconvenience." + error);
                      return(false);
                }
                
              } 
              else 
              {
                  alert("A problem occurred reaching our promo engine, sorry for the inconvenience.");
                  return(false);
              }
          }
  }
