function CheckShiptoState(sstate)
{   
 
  if (sstate == 'MA')
      {
        st_msg = "We will now be redirecting you to Corporate Wines, a Massachusetts licensed retailer who can legally accept, fulfil and ship your order in the State of Massachusetts.";
        alert(st_msg);
      }
  if (sstate == 'CA')
      {
       st_msg = "We will now be redirecting you to Lionstone Sonoma Wine, a California licensed retailer who can legally accept, fulfil and ship your order in the State of California.";
       alert(st_msg);
      }
  if (sstate == 'NY')
      {
       st_msg = "We will now be redirecting you to Shermer Specialties Wine, a New York licensed retailer who can legally accept, fulfil and ship your order in the State of New York.";
       alert(st_msg);
      }
                          
      cookie_name = "state";
                                        
                                                           
     index = -1;
     if (index == -1)
        {
                                                          
          document.cookie=cookie_name+"="+sstate+"; expires=Monday, 04-Apr-2010 05:00:00 GMT";
        }
     
	 return true;
}

// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}
function copyFields() 
{

    if (document.getElementById("Chkout_same").checked) 
    {                                                                                                        
        
        document.getElementById("Chkout_shipping_first_name").value = document.getElementById("Chkout_first_name").value;
	    document.getElementById("Chkout_shipping_last_name").value = document.getElementById("Chkout_last_name").value;	
	    document.getElementById("Chkout_shipping_company_name").value = document.getElementById("Chkout_billing_company_name").value;	
	    document.getElementById("Chkout_shipping_address").value = document.getElementById("Chkout_address").value;
	    document.getElementById("Chkout_shipping_address2").value = document.getElementById("Chkout_address2").value;	
	    //document.getElementById("Chkout_city2").value = document.getElementById("Chkout_city").value;	
	    
        document.getElementById("Chkout_hdnShipCity").value = document.getElementById("Chkout_hdnBillCity").value;
        document.getElementById("Chkout_spnCity2").innerHTML = document.getElementById("Chkout_spnCity").innerHTML;	
        document.getElementById("Chkout_spnstate2").innerHTML = document.getElementById("Chkout_spnstate1").innerHTML;
        document.getElementById("Chkout_hdnstateid2").value = document.getElementById("Chkout_hdnstateid1").value;
	    document.getElementById("Chkout_shipping_zip").value = document.getElementById("Chkout_txtZipCode").value;
	    document.getElementById("Chkout_shipping_phone").value = document.getElementById("Chkout_txtPhone").value;	
	    ZipChange2();
	    
	    return true;													
    }
    else
    {
        return false;
    }

}
function copyEmail()
{
    document.getElementById("Chkout_txtUserName").value = document.getElementById("Chkout_email").value;
}
											  
											  
function ZipChange() 
{
	// added by jake to slide city/state down when focus on zip
	$('#city-field').slideDown("normal");
	$('#state-field').slideDown("normal");
	
    //document.getElementById("Chkout_spnCity").innerHTML = '<select name=city6 id=city6 ruanat=server><option>Please enter your postcode</option></select>';
    
    if (document.getElementById("Chkout_txtZipCode").value.length == 0) 
    {
        document.getElementById("Chkout_spnstate1").innerHTML = "Please re-enter your zip code";
        document.getElementById("Chkout_hdnBillCity").value = "";
        document.getElementById("Chkout_spnCity").innerHTML = "";
        return false;
    }

    var SuburbSelection = ajax_request('processing.aspx?Action=GetSuburbs&zip=' + document.getElementById("Chkout_txtZipCode").value);

    //alert(SuburbSelection);

    if (SuburbSelection == 'Not a valid Postcode') {
        //alert(SuburbSelection);
        document.getElementById("Chkout_spnstate1").innerHTML = "<span class='required'>Please enter a valid zip code</span>";
        document.getElementById("cityLabel").style.display = "none";
        document.getElementById("Chkout_hdnBillCity").value = "";
        document.getElementById("Chkout_txtZipCode").style.background = '#FFFFcc';
        document.getElementById("Chkout_txtZipCode").focus();
        return false;
    } else {
        //alert(SuburbSelection);
        var city = SuburbSelection.substr(SuburbSelection.indexOf('>')+1,SuburbSelection.length - SuburbSelection.indexOf('>') )
        document.getElementById("Chkout_hdnBillCity").value = city;
        //alert(city);
        document.getElementById("Chkout_spnCity").innerHTML = SuburbSelection;
        if (SuburbSelection.indexOf('select') == -1) {
            SelectState();
            //document.getElementById("Chkout_txtPhone").focus();
        } 
    }
    return true;
}

function SelectState()
{
    //alert(document.getElementById("Chkout_txtZipCode").value);
    
    var StateState = ajax_request('processing.aspx?Action=GetState&zip=' + document.getElementById("Chkout_txtZipCode").value);
    var StateId = StateState.split(",");    
//    alert(StateId[0]);
//    alert(StateId[1]);
    if (StateId[1] == 'NA')
    {
        alert('State is not available for the given zipcode. Please enter any other zipcode.');
        document.getElementById( "Chkout_hdnCitycheck1").value = "False"
        document.getElementById( "Chkout_spnCity").innerHTML = '<span class="required">The zip code which you entered is invalid. Please try a different zip code.</span>';
        document.getElementById("cityLabel").style.display = "none";
        document.getElementById("Chkout_txtZipCode").style.background = '#FFFFcc';
        document.getElementById("Chkout_txtZipCode").focus();
        return false;
    }
    else
    {
        document.getElementById("cityLabel").style.display = "block";
        document.getElementById( "Chkout_hdnCitycheck1").value = "";
        //document.getElementById( "Chkout_spnCity").innerHTML =;
        document.getElementById("Chkout_spnstate1").innerHTML= StateId[0];        
        document.getElementById("Chkout_hdnstateid1").value = StateId[1];
        //document.getElementById("Chkout_ddlState").value = SuburbSelection;        
        document.getElementById("Chkout_txtPhone").focus();
        return true;    
    }
}											  
 function ZipChange2() 
{
	// added by jake to slide city/state down when focus on zip
	$('#city-field2').slideDown('slow');
	$('#state-field2').slideDown('slow');
	
    //document.getElementById("Chkout_spnCity2").innerHTML = '<span class='required'>Not a valid zip code. Please re-enter your zip code.</span>';
    if (document.getElementById("Chkout_shipping_zip").value.length == 0) 
    {    
    	document.getElementById("Chkout_spnstate2").innerHTML = "<span class='required'>Not a valid zip code. Please re-enter your zip code.</span>"
    	document.getElementById("Chkout_hdnShipCity").value = "";
        document.getElementById("Chkout_spnCity2").innerHTML = "";
    	return false;
    }
    var SuburbSelection = ajax_request('processing.aspx?Action=GetSuburbs&zip=' + document.getElementById("Chkout_shipping_zip").value);

    if (SuburbSelection == 'Not a valid Postcode') {
        //alert(SuburbSelection);
        document.getElementById("Chkout_spnstate2").innerHTML = "<span class='required'>Not a valid zip code. Please re-enter your zip code.</span>"
        document.getElementById("cityLabel2").style.display = "none";
        document.getElementById("Chkout_hdnShipCity").value = "";
        document.getElementById("Chkout_shipping_zip").style.background = '#FFFFcc';
        document.getElementById("Chkout_shipping_phone").focus();
        return false;
    } else {
        //SuburbSelection                                                    
        var suburb = SuburbSelection.replace('city','city2');   
        var city = suburb.substr(suburb.indexOf('>')+1,suburb.length - suburb.indexOf('>') )
        //alert(city);
        document.getElementById("Chkout_hdnShipCity").value = city;
        document.getElementById("Chkout_spnCity2").innerHTML = suburb;
        //var=SuburbSelection
        if (suburb.indexOf('select') == -1) {
            SelectState2();
            //document.getElementById("Chkout_shipping_phone").focus();
        } 
    }
    return true;
}

function SelectState2()
{
    var StateState = ajax_request('processing.aspx?Action=GetState&zip=' + document.getElementById("Chkout_shipping_zip").value);
    var StateId = StateState.split(","); 
    
    if (StateId[1] == 'NA')
    {
        alert('State is not available for the given zip code. Please try another zip code.');
         document.getElementById( "Chkout_hdnCitycheck2").value = "False"
        document.getElementById( "Chkout_spnCity2").innerHTML = '<span class="required">Not a valid zip code. Please re-enter your zip code.</span>';
        document.getElementById("Chkout_shipping_zip").style.background = '#FFFFcc';
        document.getElementById("Chkout_shipping_zip").focus();
        document.getElementById("cityLabel2").style.display = "none";
        return false;
    }
    else
    {
        if (StateId[1] == 'CA')
        {
            alert("We will now be redirecting you to Lionstone Sonoma Wine, a California licensed retailer who can legally accept, fulfil and ship your order in the State of California.");
        }
        else if(StateId[1] == 'NY')
        {
            alert("We will now be redirecting you to Shermer Specialties Wine, a New York licensed retailer who can legally accept, fulfil and ship your order in the State of New York.");
        }
        else if(StateId[1] == 'MA')
        {
            alert("We will now be redirecting you to Corporate Wines, a Massachusetts licensed retailer who can legally accept, fulfil and ship your order in the State of Massachusetts.");
        }
        document.getElementById( "Chkout_hdnCitycheck2").value = "";
        document.getElementById("cityLabel2").style.display = "block";
        document.getElementById("Chkout_spnstate2").innerHTML= StateId[0];        
        document.getElementById("Chkout_hdnstateid2").value = StateId[1];
        //document.getElementById("Chkout_ddlstate2").value = SuburbSelection;  
        if (StateId[1] != 'NA' && StateId[1] != '')
        {
            CheckShippingState(StateId[1]);
        }
        //document.getElementById("Chkout_shipping_phone").focus();
        return true;    
    }
    
}
function CheckShippingState(State)
{
    //alert(State);
    var blnShipToState = ajax_request('processing.aspx?Action=CheckShippingState&State=' + State);
    //alert(blnShipToState);
    if (blnShipToState == 'False')
    {
//        var oDDL = document.getElementById(MasterpageID + "ddlState");
//        var curText = oDDL.options[oDDL.selectedIndex].text;

        document.getElementById("Chkout_spnCity2").innerHTML = "";
        document.getElementById("Chkout_spnstate2").innerHTML= "";
        var message = "Sorry, we will not be able to ship to " + State;
        //alert(message);
        document.getElementById("cityLabel2").style.display = "none";
        document.getElementById("Chkout_spnstate2").innerHTML = "<span class='required'>Sorry, we will not be able to ship to " + State + "</span>";
        document.getElementById("Chkout_shipping_zip").style.background = '#FFFFcc';
        document.getElementById("Chkout_shipping_zip").value = "";
        document.getElementById("Chkout_shipping_zip").focus();
        return false;
    }
    else
    {
        document.getElementById("Chkout_txtPassword").focus();
        return true;    
    }
}

function isValidCardNumber (strNum) 
{
 var nCheck = 0;
var nDigit = 0;
//var bEven = false;
var checksum = 0;
var nDigitCheck = strNum.substring(0,6);

if(trim(strNum)=="")
{
    alert("Please enter the credit card");
    document.getElementById('Chkout_ccnumber').focus();
    return false;
}

if (((300000 <= nDigitCheck) && (309999 >= nDigitCheck)))
{
 alert("Sorry, you cannot use this credit card");
 return false;
} 
else
{										   


        for (var n=(2-(strNum.length % 2)); n<=strNum.length; n+=2)
        {
            checksum += parseInt(strNum.charAt(n-1));
        }
        for (n =(strNum.length % 2) + 1; n<strNum.length; n+=2) 
        {
            var cDigit = strNum.charAt(n);
            if (isDigit(cDigit))
           {
                cDigit = parseInt(strNum.charAt(n-1)) * 2;
                if (cDigit < 10) 
                {
                 checksum += cDigit; 
                 } 
                 else 
                 { checksum += (cDigit-9); 
                 }
           }
            else if (cDigit != ' ' && cDigit != '.' && cDigit != '-') 
            {
                return false;
            }
        }
        return (checksum % 10) == 0;
}
}	
	
function isDigit (c)
{
	var strAllowed = "1234567890";
	return (strAllowed.indexOf (c) != -1);
}
												
function isValidSecCode(strNum)
{
    var nCheck = 0;
    var nDigit = 0;
    var bEven = false;
    var result = false;
    for (n = strNum.length - 1; n >= 0; n--) 
    {
        var cDigit = strNum.charAt(n);
        if (isDigit(cDigit)) 
        {
            var nDigit = parseInt(cDigit, 10);
            nCheck += nDigit;
        }
        else 
        {
            return false;
        }
    }
    return true;
}
											
												
		  function validate() {
		  	  
		  	  //document.getElementById("Chkout_err").innerHTML = "";
		  	  document.getElementById("Chkout_first_name").style.background = '#efefef';
			  if (trim(document.getElementById("Chkout_first_name").value).length == '') 
			  { 
				alert('Please enter your billing first name.');
				document.getElementById("Chkout_first_name").style.background = '#FFFFcc';
				document.getElementById("Chkout_first_name").focus(); 
			  	return false; 
			  } 
			  
			  document.getElementById("Chkout_last_name").style.background = '#efefef';
			  if (trim(document.getElementById("Chkout_last_name").value).length == 0) 
			  { 
				alert('Please enter your billing last name.');
				document.getElementById("Chkout_last_name").style.background = '#FFFFcc';
				document.getElementById("Chkout_last_name").focus(); 
			  	return false; 
			  } 	  
			  
			  
			  
			  document.getElementById("Chkout_address").style.background = '#efefef';
			  if (trim(document.getElementById("Chkout_address").value).length == '') 
			  { 
				alert('Please enter your billing address.');
				document.getElementById("Chkout_address").style.background = '#FFFFcc';
				document.getElementById("Chkout_address").focus(); 
			  	return false; 
			  }
			  
//			  document.getElementById("Chkout_city").style.background = '#efefef';
//			  if (trim(document.getElementById("Chkout_hdnBillCity").value).length == 0)
//			  {
//					alert("Please enter your billing city");
////					document.getElementById("Chkout_city").focus();
////					document.getElementById("Chkout_city").style.background = '#FFFFcc';
//					return false;
//			  }
//			  
//			
//            var regExpression = /^[A-Za-z ]*$/ ;
//            if(!regExpression.test(document.getElementById("Chkout_city").value))
//            {
//                    alert("Please enter valid billing city name");
//					document.getElementById("Chkout_city").focus();
//					document.getElementById("Chkout_city").style.background = '#FFFFcc';
//					return false;
//            }
            
//												  document.getElementById("Chkout_billing_state.style.background = '#efefef';
//												  if (document.getElementById("Chkout_billing_state.value == '') 
//												  { 
//													alert('Please enter your billing state.');
//													document.getElementById("Chkout_billing_state.style.background = '#FFFFcc';
//													document.getElementById("Chkout_billing_state.focus(); 
//												  	return false; 
//												  }
//			  document.getElementById("Chkout_ddlState").style.background = '#efefef';
//            if (document.getElementById("Chkout_ddlState").value == 'Select')
//            {
//                alert('Please select your state');
//                document.getElementById("Chkout_ddlState").style.background = '#FFFFcc';
//                document.getElementById("Chkout_ddlState").focus();
//                return false;
//            }
			  
			  if (trim(document.getElementById("Chkout_txtZipCode").value).length == 0) 
			  {
					alert("Please enter your billing zip code.");
					document.getElementById("Chkout_txtZipCode").focus();
					document.getElementById("Chkout_txtZipCode").style.background = '#FFFFcc';
					return false;
			  }
			  
			  document.getElementById("Chkout_txtZipCode").style.background = '#efefef';
			  if (document.getElementById("Chkout_txtZipCode").value.length < 5) {
					alert("Please enter valid billing zip code.");
					document.getElementById("Chkout_txtZipCode").focus();
					document.getElementById("Chkout_txtZipCode").style.background = '#FFFFcc';
					return false;
			  }
			  else
                {
                    var e = document.getElementById("Chkout_txtZipCode").value;
                    var numericexp = /^[0-9]+$/;
                    if (!(e.match(numericexp)))
                    {
                        alert('Please enter valid billing zip code.');
                        document.getElementById("Chkout_txtZipCode").style.background = '#FFFFcc';
                        document.getElementById("Chkout_txtZipCode").focus();
                        return false;
                    }
                }
                
//												  if(document.getElementById( "hdnCitycheck1").value=="False")
//												  {
//												    alert("Please enter valid zip code.");
//												    document.getElementById("Chkout_txtZipCode").focus();
//												    document.getElementById("Chkout_txtZipCode").style.background = '#FFFFcc';
//												    return false;
//												  }
			  
			  document.getElementById("Chkout_email").style.background = '#efefef';
			  var e = document.getElementById("Chkout_email").value;
			  if(trim(document.getElementById("Chkout_email").value).length == 0)
			  {
			    alert('Please enter the email address');
			    document.getElementById("Chkout_email").style.background = '#FFFFcc';
			    document.getElementById("Chkout_email").focus();
			    return false;
			 }
			  
			  if(trim(document.getElementById("Chkout_email").value).length > 0)
			  {
			      var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
				  
			      if (!(filter.test(e))) 
			      {
			  	    alert('Invalid email address');
				    document.getElementById("Chkout_email").style.background = '#FFFFcc';
				    document.getElementById("Chkout_email").focus();
				    return false;
			      }
			  }	
			  
			  
			  document.getElementById("Chkout_txtPhone").style.background = '#efefef';
			  
			  if (trim(document.getElementById("Chkout_txtPhone").value).length == '') {
					alert("Please enter a phone number for the Billing address.");
					document.getElementById("Chkout_txtPhone").focus();
					document.getElementById("Chkout_txtPhone").style.background = '#FFFFcc';
					return false;
			  }
			  
			  document.getElementById("Chkout_txtPhone").style.background = '#efefef';
			  document.getElementById("Chkout_txtPhone").value = document.getElementById("Chkout_txtPhone").value.replace(/[\(\)\.\-\ ]/g, '');
			  var stripped = document.getElementById("Chkout_txtPhone").value.replace(/[\(\)\.\-\ ]/g, '');
			  //strip out acceptable non-numeric characters
			  
			  if (isNaN(parseInt(stripped))) {
				   	alert('The phone number contains bad characters or needs to be entered.');
				   	document.getElementById("Chkout_txtPhone").style.background = '#FFFFcc';
					document.getElementById("Chkout_txtPhone").focus(); 
					return false; 
			  }
			  var numericexp = /^[0-9]+$/;
			  if (!(stripped.match(numericexp)))
                    {
                    alert('The phone number contains bad characters or needs to be entered.');
				   	document.getElementById("Chkout_txtPhone").style.background = '#FFFFcc';
					document.getElementById("Chkout_txtPhone").focus(); 
					return false; 
					}
			  if (trim(document.getElementById("Chkout_txtPhone").value).length != 10) {
					alert('The phone number is the wrong length. Make sure you included an area code.');
					document.getElementById("Chkout_txtPhone").style.background = '#FFFFcc';
					document.getElementById("Chkout_txtPhone").focus(); 
					return false; 
			  }						  
			  	
			  								  
			  												  
			  document.getElementById("Chkout_shipping_first_name").style.background = '#efefef';
			  if (trim(document.getElementById("Chkout_shipping_first_name").value).length == 0) 
			  { 
				alert('Please enter your shipping first name.');
				document.getElementById("Chkout_shipping_first_name").style.background = '#FFFFcc';
				document.getElementById("Chkout_shipping_first_name").focus(); 
			  	return false; 
			  } 
			  
			  document.getElementById("Chkout_shipping_last_name").style.background = '#efefef';
			  if (trim(document.getElementById("Chkout_shipping_last_name").value).length == 0) 
			  { 
				alert('Please enter your shipping last name.');
				document.getElementById("Chkout_shipping_last_name").style.background = '#FFFFcc';
				document.getElementById("Chkout_shipping_last_name").focus(); 
			  	return false; 
			  } 
			  
			  document.getElementById("Chkout_shipping_address").style.background = '#efefef';
			  if (trim(document.getElementById("Chkout_shipping_address").value).length == 0) 
			  { 
				alert('Please enter your shipping address.');
				document.getElementById("Chkout_shipping_address").style.background = '#FFFFcc';
				document.getElementById("Chkout_shipping_address").focus(); 
			  	return false; 
			  }
			  
			  // check for PO Boxes
			  if ((document.getElementById("Chkout_shipping_address").value.toLowerCase().indexOf('box ') > -1) || (document.getElementById("Chkout_shipping_address").value.toLowerCase().indexOf('p.o.') > -1)) {
			  	alert('We\'re sorry, but we can\'t accept PO Boxes as a ship to address.');
				document.getElementById("Chkout_shipping_address").style.background = '#FFFFcc';
				document.getElementById("Chkout_shipping_address").focus(); 													
				return false;
			  }
			  
//			  document.getElementById("Chkout_city2").style.background = '#efefef';
//			  if (trim(document.getElementById("Chkout_hdnShipCity").value).length == 0) 
//			  { 
//				alert('Please enter your shipping city.');
////				document.getElementById("Chkout_city2").style.background = '#FFFFcc';
////				document.getElementById("Chkout_city2").focus(); 
//			  	return false; 
//			  }
//			  
//			  var regExpression = /^[A-Za-z ]*$/ ;
//            if(!regExpression.test(document.getElementById("Chkout_city2").value))
//            {
//                    alert("Please enter valid shipping city name");
//					document.getElementById("Chkout_city2").focus();
//					document.getElementById("Chkout_city2").style.background = '#FFFFcc';
//					return false;
//            }
            
//            document.getElementById("Chkout_ddlstate2").style.background = '#efefef';
//            if (document.getElementById("Chkout_ddlstate2").value == 'Select')
//            {
//                alert('Please select your shipping state');
//                document.getElementById("Chkout_ddlstate2").style.background = '#FFFFcc';
//                document.getElementById("Chkout_ddlstate2").focus();
//                return false;
//            }
            
//												  document.getElementById("Chkout_shipping_state.style.background = '#efefef';
//												  if (document.getElementById("Chkout_shipping_state.value == '') 
//												  { 
//													alert('Please enter your shipping state.');
//													document.getElementById("Chkout_shipping_state.style.background = '#FFFFcc';
//													document.getElementById("Chkout_shipping_state.focus(); 
//												  	return false; 
//												  } 
			  
			  //var state = document.getElementById("Chkout_ddlstate2.value;
			  
			  //alert(state);
			  
			  //document.getElementById("Chkout_city2").style.background = '#efefef';
			  //alert(document.getElementById("city2").value);
			  
			  document.getElementById("Chkout_shipping_zip").style.background = '#efefef';
			  
			  if (trim(document.getElementById("Chkout_shipping_zip").value).length == 0) 
			  {
					alert("Please enter your shipping zip code.");
					document.getElementById("Chkout_shipping_zip").focus();
					document.getElementById("Chkout_shipping_zip").style.background = '#FFFFcc';
					return false;
			  }
			  
			  if (document.getElementById("Chkout_shipping_zip").value.length < 5) 
			  {
					alert("Please enter valid shipping zip code.");
					document.getElementById("Chkout_shipping_zip").focus();
					document.getElementById("Chkout_shipping_zip").style.background = '#FFFFcc';
					return false;
			  }
			   else
             {
                    var e = document.getElementById("Chkout_shipping_zip").value;
                    var numericexp = /^[0-9]+$/;
                    if (!(e.match(numericexp)))
                    {
                        alert('Please enter valid shipping zip code.');
                        document.getElementById("Chkout_shipping_zip").style.background = '#FFFFcc';
                        document.getElementById("Chkout_shipping_zip").focus();
                        return false;
                    }
              }
              
//												 if(document.getElementById( "hdnCitycheck2").value=="False")
//												  {
//												    alert("Please enter valid zip code.");
//												    document.getElementById("Chkout_shipping_zip").style.background = '#FFFFcc';
//												    document.getElementById("Chkout_shipping_zip").focus();
//												    return false;
//												  }
//			 

//            alert(document.getElementById("city2").value);
//            alert(document.getElementById("txtstate2").value);

//			 if ( (document.getElementById("city2").value == "") || (document.getElementById("city2").value == "Please enter your post code") || (document.getElementById("city2").value == "Please enter your postcode"))
//			  { 
//				alert('Please enter valid zip code');
//				document.getElementById("Chkout_shipping_zip").focus();
//		        document.getElementById("Chkout_shipping_zip").style.background = '#FFFFcc';
//			  	return false; 
//			  }
//			  
//			  
//			  if ((document.getElementById("txtstate2").value == "Please enter your post code") || (document.getElementById("txtstate2").value == "Please enter your postcode"))
//			  { 
//				alert('Please enter valid zip code');
//				document.getElementById("Chkout_shipping_zip").focus();
//		        document.getElementById("Chkout_shipping_zip").style.background = '#FFFFcc';
//			  	return false; 
//			  }
			 
			 
			 //if (document.getElementById("hdnUserType").value.length == 0) 
				//{
				
				  if (trim(document.getElementById("Chkout_txtPassword").value).length == 0) 
				  {
					    alert("Please enter the Password");
					    document.getElementById("Chkout_txtPassword").focus();
					    document.getElementById("Chkout_txtPassword").style.background = '#FFFFcc';
					    return false;
			      }	
			      
			      if (trim(document.getElementById("Chkout_txtPassword").value).length < 6) 
			      {
					    alert("The Password must be atleast 6 characters length");
					    document.getElementById("Chkout_txtPassword").focus();
					    document.getElementById("Chkout_txtPassword").style.background = '#FFFFcc';
					    return false;
			      }	
    			  
    			  //document.getElementById("Chkout_txtConfirmPassword").style.background = '#efefef';
			      if(trim(document.getElementById("Chkout_txtConfirmPassword").value).length == 0) 
			      {
					    alert("Please confirm the Password");
					    document.getElementById("Chkout_txtConfirmPassword").focus();
					    document.getElementById("Chkout_txtConfirmPassword").style.background = '#FFFFcc';
					    return false;
			      }	
			      if (document.getElementById("Chkout_txtConfirmPassword").value != document.getElementById("Chkout_txtPassword").value) 
			      {
					    alert("The Passwords do not match. Please confirm the password");
					    document.getElementById("Chkout_txtConfirmPassword").focus();
					    document.getElementById("Chkout_txtConfirmPassword").style.background = '#FFFFcc';
					    return false;
			      }	
			  //}
			  
			  
			  document.getElementById("Chkout_shipping_phone").style.background = '#efefef';
			  if (trim(document.getElementById("Chkout_shipping_phone").value).length == 0) {
					alert("Please enter a phone number for the shipping address.");
					document.getElementById("Chkout_shipping_phone").focus();
					document.getElementById("Chkout_shipping_phone").style.background = '#FFFFcc';
					return false;
			  }
			  
			  
			  document.getElementById("Chkout_shipping_phone").style.background = '#efefef';
			  document.getElementById("Chkout_shipping_phone").value = document.getElementById("Chkout_shipping_phone").value.replace(/[\(\)\.\-\ ]/g, '');
			  var stripped = document.getElementById("Chkout_shipping_phone").value.replace(/[\(\)\.\-\ ]/g, '');
			 
			  //strip out acceptable non-numeric characters
			  if (isNaN(parseInt(stripped))) {
				   	alert('The shipping phone number contains bad characters.');
				   	document.getElementById("Chkout_shipping_phone").style.background = '#FFFFcc';
					document.getElementById("Chkout_shipping_phone").focus(); 
					return false; 
			  }
			  
			  if (!(stripped.length == 10)) {
					alert('The shipping phone number is the wrong length. Make sure you included an area code.');
					document.getElementById("Chkout_shipping_phone").style.background = '#FFFFcc';
					document.getElementById("Chkout_shipping_phone").focus(); 
					return false; 
			  }					
			  
			  	document.getElementById("Chkout_shipping_phone").style.background = '#efefef';
//												  if (trim(document.getElementById("Chkout_txtUserName").value).length == 0) 
//												  {
//														alert("Please enter the User Name");
//														document.getElementById("Chkout_txtUserName").focus();
//														document.getElementById("Chkout_txtUserName").style.background = '#FFFFcc';
//														return false;
//												  }						


              
			  
            
			  
//			
			  
			  	
			  
			   if (trim(document.getElementById("Chkout_ccnumEnter").value).length == 0) 
			   {
			    alert('Please enter the Credit Card.');
			    document.getElementById("Chkout_ccnumEnter").style.background = '#FFFFcc';
			    document.getElementById("Chkout_ccnumEnter").focus(); 
			    return false;
			   }
			   
			   //if (!isValidCardNumber(document.getElementById('Chkout_ccnum').value)) return false;
			  
			  document.getElementById("Chkout_ccmo").style.background = '#efefef';
			  if (document.getElementById("Chkout_ccmo").value == "MM") 
			  {
			    alert('Please select the month');
				document.getElementById("Chkout_ccmo").style.background = '#FFFFcc';
				document.getElementById("Chkout_ccmo").focus(); 
			  	return false; 	
			  }
			  
			  document.getElementById("Chkout_ccyr").style.background = '#efefef';
			  if (document.getElementById("Chkout_ccyr").value == "YYYY") 
			  {
			    alert('Please select the year');
				document.getElementById("Chkout_ccyr").style.background = '#FFFFcc';
				document.getElementById("Chkout_ccyr").focus(); 
			  	return false; 	
			  }
			  
               var currentTime = new Date(); 												  
			   var currMonth = currentTime.getMonth()+1;
			   var currYear = currentTime.getFullYear();
			   
			   if(document.getElementById("Chkout_ccyr").value < currYear)
			   {
			        alert("Your credit card has expired. Please enter a different card.");
                  return false;
                   }
			   if (document.getElementById("Chkout_ccyr").value==currYear)
			   {
			    if (document.getElementById("Chkout_ccmo").value < currMonth)
			        {
			            alert("Your credit card has expired. Please enter a different card.");
			            return false;
			            }
			    }
			  document.getElementById("Chkout_cvv").style.background = '#efefef';
			  if (trim(document.getElementById("Chkout_cvv").value).length == 0) {
			    alert('Please enter your credit card verfication number.');
				document.getElementById("Chkout_cvv").style.background = '#FFFFcc';
				document.getElementById("Chkout_cvv").focus(); 
				// document.getElementById("Chkout_submitBtn.disabled= false;
			  	return false; 	
			  }
			  
			  var seccode = document.getElementById("Chkout_cvv").value;
			  document.getElementById("Chkout_cvv").style.background = '#efefef';

//                                                if (seccode.length != 3)
//                                                {
//                                                    alert('Please enter valid sec code.');
//                                                    document.getElementById("Chkout_cvv").style.background = '#FFFFcc';
//                                                    document.getElementById("Chkout_cvv").focus();
//                                                    return false;
//                                                }
            
            if (!isValidSecCode(seccode)) 
            {
                alert('Please enter valid sec code.');
                document.getElementById("Chkout_cvv").style.background = '#FFFFcc';
                document.getElementById("Chkout_cvv").focus();
                return false;
            }
            
			  if (!document.getElementById("Chkout_chkAge").checked) {
					alert("Please certify that you are 21 years or older");
					document.getElementById("Chkout_chkAge").focus();
					document.getElementById("Chkout_chkAge").style.background = '#FFFFcc';
					return false;
			  }	
			
			CheckShiptoState(document.getElementById("Chkout_hdnstateid2").value);
			return true; 
			  
		  }
		  
function ajax_request(url) {  
	if (window.XMLHttpRequest) {
		AJAX=new XMLHttpRequest();                
	} else {                                      
		AJAX=new ActiveXObject("Microsoft.XMLHTTP");  
	}  
	if (AJAX) {     
		AJAX.open("GET", url, false);                                  
		AJAX.send(null);     
		return AJAX.responseText;                                           
	} else {
		alert('The browser you are using is not compatible. Please call 1-877-975-9463 to place your order.');
	}
}											

											  
                        function encryptcc()
                        {
	                        
	                        var ccnum = document.getElementById('Chkout_ccnumEnter').value;	                        
	                        document.getElementById('Chkout_ccnumber').value = document.getElementById('Chkout_ccnumEnter').value;
	                        ccnum = ccnum.replace(/ /g, '').replace(/-/g, '');
	                        if (ccnum.length != 0 && ccnum.substring(0, 1) != 'X') {												
		                        if(isValidCardNumber(ccnum) == 0) {
                        			
			                        alert('Please enter a valid credit card number.');
                                    document.getElementById("Chkout_ccnumEnter").value="";
                        			document.getElementById("Chkout_ccnumEnter").style.background = '#FFFFcc';
								    document.getElementById("Chkout_ccnumEnter").focus(); 									
			                        document.getElementById('Chkout_ccnum').value = '';
			                                             			
			                        
			                        return false;
		                        }
		                        document.getElementById('Chkout_ccnumEnter').value = 'XXXX XXXX XXXX ' + ccnum.substring(12, 16);
		                        //var encoded = ajax_request('Encrypt.aspx?ccnum=' + ccnum)
		                        document.getElementById('Chkout_ccnum').value = ccnum;
		                        return true;
                        		
	                        } else if (ccnum.substring(0, 1) != 'X'){
                        		
		                        alert('Please enter a valid credit card number.');
		                        document.getElementById('Chkout_ccnum').value = '';
		                        document.getElementById("Chkout_ccnumEnter").value="";
                        		document.getElementById("Chkout_ccnumEnter").style.background = '#FFFFcc';
								document.getElementById("Chkout_ccnumEnter").focus();
		                        return false;
	                        } else {return true;}
                        }											 
											  
 