//<!--

function changeValues()
{
	if(document.getElementById("ship_same").checked == true)
	{
		if(document.getElementById("ship_fname").value == "")
		{
			document.getElementById("ship_fname").value = document.getElementById("bill_fname").value;
			document.getElementById("ship_lname").value = document.getElementById("bill_lname").value;
			document.getElementById("ship_address1").value = document.getElementById("bill_address1").value;
			document.getElementById("ship_address2").value = document.getElementById("bill_address2").value;
			document.getElementById("ship_city").value = document.getElementById("bill_city").value;
			document.getElementById("ship_state").value = document.getElementById("bill_state").value;
			document.getElementById("ship_zip").value = document.getElementById("bill_zip").value;
			document.getElementById("ship_country").value = document.getElementById("bill_country").value;
		}
		document.getElementById("ship_info").style.display = "none";	
	}
	if(document.getElementById("ship_same").checked == false)
	{
		if(document.getElementById("ship_fname").value == "")
		{
			document.getElementById("ship_fname").value = document.getElementById("bill_fname").value;
			document.getElementById("ship_lname").value = document.getElementById("bill_lname").value;
			document.getElementById("ship_address1").value = document.getElementById("bill_address1").value;
			document.getElementById("ship_address2").value = document.getElementById("bill_address2").value;
			document.getElementById("ship_city").value = document.getElementById("bill_city").value;
			document.getElementById("ship_state").value = document.getElementById("bill_state").value;
			document.getElementById("ship_zip").value = document.getElementById("bill_zip").value;
			document.getElementById("ship_country").value = document.getElementById("bill_country").value;
		}
		document.getElementById("ship_info").style.display = "block";
	}
}

function changefname()
{
	if(document.getElementById("ship_same").checked == true)
	{
		document.getElementById("ship_fname").value = document.getElementById("bill_fname").value;
	}
}

function changelname()
{
	if(document.getElementById("ship_same").checked == true)
	{
		document.getElementById("ship_lname").value = document.getElementById("bill_lname").value;
	}
}

function changeaddress1()
{
	if(document.getElementById("ship_same").checked == true)
	{
		document.getElementById("ship_address1").value = document.getElementById("bill_address1").value;
	}
}

function changeaddress2()
{
	if(document.getElementById("ship_same").checked == true)
	{
		document.getElementById("ship_address2").value = document.getElementById("bill_address2").value;
	}
}

function changecity()
{
	if(document.getElementById("ship_same").checked == true)
	{
		document.getElementById("ship_city").value = document.getElementById("bill_city").value;
	}
}

function changestate()
{
	if(document.getElementById("ship_same").checked == true)
	{
		document.getElementById("ship_state").value = document.getElementById("bill_state").value;
	}
}

function changezip()
{
	if(document.getElementById("ship_same").checked == true)
	{
		document.getElementById("ship_zip").value = document.getElementById("bill_zip").value;
	}
}

function changecountry()
{
	if(document.getElementById("ship_same").checked == true)
	{
		document.getElementById("ship_country").value = document.getElementById("bill_country").value;
	}
}

function checkThenMove(x,y,z){
        if(x){var c = x.value.length;
        if(c >= y){if(document.getElementById(z))
{document.getElementById(z).focus();}}}
}

function checkExtraPassword(this_element)
{
	this_element.value = lmescape(this_element.value);
	if(this_element.value == "" || this_element.length < 6)
	{
		this_element.focus();
		return "You need to enter in a password";
	}
}

function checkExtraQuestion(this_element)
{
	this_element.value = lmescape(this_element.value);
	if(this_element.value == "")
	{
		this_element.focus();
		return "You need to select a security password";
	}
}

function checkExtraAnswer(this_element)
{
	this_element.value = lmescape(this_element.value);
	if(this_element.value == "")
	{
		this_element.focus();
		return "You need to enter in a security answer";
	}
}

function checkFName(this_element)
{
	this_element.value = lmescape(this_element.value);
	if(this_element.value == "")
	{
		this_element.focus(); 
		return "You need to enter in a First Name";
	}
}

function checkLName(this_element)
{
	this_element.value = lmescape(this_element.value);
	if(this_element.value == "")
	{
		this_element.focus(); 
		return "You need to enter in a Last Name";
	}
}

function checkAddress(this_element)
{
	this_element.value = lmescape(this_element.value);
	if(this_element.value == "")
	{
		this_element.focus(); 
		return "You need to enter in an Address";
	}
	var address = this_element.value;
	if(address.length <= 3)
	{
		this_element.focus(); 
		return "You need to enter in a valid Street Address";
	}
	
	if( (this_element.value.toLowerCase() == "8950 SW 142 AVE #922".toLowerCase()) || 
		(this_element.value.toLowerCase() == "181 Church ST #101".toLowerCase()) || 
		(this_element.value.toLowerCase() == "181 Church ST UNIT 101".toLowerCase()) || 
		(this_element.value.toLowerCase() == "311 W 50th ST".toLowerCase()) || 
		(this_element.value.toLowerCase() == "220032 Box".toLowerCase()) || 
		(this_element.value.toLowerCase() == "PO Box 220032".toLowerCase())
	){
		this_element.focus(); 
		return "This Address is invalid";
	}
	
	if(document.getElementById("bill_address2"))
	{
		var addy2 = document.getElementById("bill_address2");
		addy2.value = lmescape(addy2.value);
	}
	
}

function checkCity(this_element)
{
	this_element.value = lmescape(this_element.value);
	if(this_element.value == "")
	{
		this_element.focus(); 
		return "You need to enter in an City";
	}
}

function checkState()
{
    var the_country = document.getElementById("bill_country").value;
    if(the_country == 'US' || the_country == 'CA'){
    	var str = document.getElementById("bill_state").value;
    	the_state = str.substr(3, 2);
    	if(the_country != the_state)
    	{
    		document.getElementById("bill_state").value = "0";
    	}
    }

    var the_country = document.getElementById("ship_country").value;
    if(the_country == 'US' || the_country == 'CA'){
	var str = document.getElementById("ship_state").value;
	the_state = str.substr(3, 2);
	if(the_country != the_state)
	{
		document.getElementById("ship_state").value = "0";
	}
    }
}


function checkState2(this_element)
{
	this_element.value = lmescape(this_element.value);
	if(this_element.value == 0)
	{
		this_element.focus();
		return "You need to enter in a State";
	}
}

function checkState3(this_element)
{
	this_element.value = lmescape(this_element.value);
	if(this_element.value == "" || this_element.value == 0)
	{
		this_element.focus();
		return "You need to enter in a State";
	}
}

function checkCounty(this_element)
{
	if(this_element.value == 0)
	{
		this_element.focus();
		return "You need to enter in County";
	}
}

function checkCountry()
{
	var str = document.getElementById("bill_state").value;
	the_country = str.substr(3, 2);
	if(the_country != document.getElementById("bill_country").value)
	{
		document.getElementById("bill_country").value = the_country;
	}

	var str = document.getElementById("ship_state").value;
	the_country = str.substr(3, 2);
	if(the_country != document.getElementById("ship_country").value)
	{
		document.getElementById("ship_country").value = the_country;
	}
}

function checkCountry2(this_element)
{
	if(this_element.value == 0)
	{
		this_element.focus();
		return "You need to enter in a Country";
	}
}

function checkZip(the_zip, the_country)
{
	the_zip.value = lmescape(the_zip.value);
	if(the_country.value == "US")
	{
		if(the_zip.value == "")
		{
			the_zip.focus();
			return "You need to enter in a Zip Code";
		}
		else
		{
			if(isNaN(the_zip.value))
			{
				the_zip.focus();
				return "Your Zip Code is not a valid Number";
			}
			else
			{
				if(the_zip.value.length != "5")
				{
					the_zip.focus();
					return "Your Zip Code is not 5 Digits";
				}
				
			}
		}
	}
	else if(the_country.value == "CA")
	{
		if(the_zip.value == "")
		{
			the_zip.focus();
			return "You need to enter in a Zip";
		}
		else
		{
			var CPC_response = isCanadianPostCode(the_zip.value);
			if(CPC_response.length > 7)
			{
				the_zip.focus();
				return CPC_response;
			}
			else
			{
				the_zip.value = CPC_response;
			}			
		}
	}
	else if(the_country.value == "AU")
	{
		if(the_zip.value == "")
		{
			the_zip.focus();
			return "You need to enter in a Zip Code";
		}
		else
		{
			if(isNaN(the_zip.value))
			{
				the_zip.focus();
				return "Your Zip Code is not a valid Number";
			}
			else
			{
				if(the_zip.value.length != "4")
				{
					the_zip.focus();
					return "Your Zip Code is not 4 Digits";
				}
			}
		}
        }
        else if(the_country.value == "UK")
	{
		if(the_zip.value == "")
		{
			the_zip.focus();
			return "You need to enter in a Post Code";
		}
		else
		{
                        if(the_zip.value.length < "6")
		        {
		              the_zip.focus();
		              return "Your Post Code is less than 6 digits";
                        }
		}
	}
}

function checkEmail(this_element)
{
	this_element.value = lmescape(this_element.value);
	if(this_element.value == "")
	{
		this_element.focus();
		return "You need to enter in your Email Address";
	}
	else
	{
		if(!isValidEmail(this_element.value))
		{
			this_element.focus();
			return "You need to enter in a valid Email Address";
		}
	}	
}

function checkPhone3(phone3)
{
     phone3.value = lmescape(phone3.value);
     if(phone3.value == "")
     {
        phone3.focus();
        return "You need to enter in your Mobile/Phone Number";
     }
}

function checkPhoneR(phone1, phone2, phone3)
{
	phone1.value = lmescape(phone1.value);
	phone2.value = lmescape(phone2.value);
	phone3.value = lmescape(phone3.value);

	if(phone1.value == "")
	{
		phone1.focus();
		return "You need to enter in your Area Code";
	}
	else
	{
		if(isNaN(phone1.value))
		{
			phone1.focus();
			return "Your Area Code is not a valid Number";
		}
		else
		{
			if(phone1.value.length != "3")
			{
				phone1.focus();
				return "Your Area Code is not 3 Digits long";
			}
		}
        if(phone1.value == "000")
        {
			phone1.focus();
			return "Please enter a valid Phone Number";
        }
	}

	if(phone2.value == "")
	{
		phone2.focus();
		return "You need to enter in your Phone Number Prefix";
	}
	else
	{
		if(isNaN(phone2.value))
		{
			phone2.focus();
			return "Your Phone Number Prefix is not a valid Number";
		}
		else
		{
			if(phone2.value.length != "3")
			{
				phone2.focus();
				return "Your Phone Number Prefix is not 3 Digits";
			}
		}
        if(phone2.value == "000")
        {
			phone2.focus();
			return "Please enter a valid Phone Number";
        }
	}

	if(phone3.value == "")
	{
		phone3.focus();
		return "You need to enter in your last 4 digits of your Phone Number";
	}
	else
	{
		if(isNaN(phone3.value))
		{
			phone3.focus();
			return "The last 4 digits of your Phone Number is not a valid Number";
		}
		else
		{
			if(phone3.value.length != "4")
			{
				phone3.focus();
				return "The last 4 digits of your Phone Number is not 4 Digits";
			}
		}
	}
}

function checkPhoneNR(phone1, phone2, phone3)
{
//	if(phone1.value != "" || phone2.value != "" || phone3.value != "")
//	{
	phone1.value = lmescape(phone1.value);
	phone2.value = lmescape(phone2.value);
	phone3.value = lmescape(phone3.value);

		if(phone1.value == "")
		{
			phone1.focus();
			return "You need to enter in your Area Code";
		}
		else
		{
			if(isNaN(phone1.value))
			{
				phone1.focus();
				return "Your Area Code is not a valid Number";
			}
			else
			{
				if(phone1.value.length != "3")
				{
					document.getElementById("bill_phone1").focus();
					return "Your Area Code is not 3 Digits long";
				}
			}
		}
	
		if(phone2.value == "")
		{
			phone2.focus();
			return "You need to enter in your Phone Number Prefix";
		}
		else
		{
			if(isNaN(phone2.value))
			{
				phone2.focus();
				return "Your Phone Number Prefix is not a valid Number";
			}
			else
			{
				if(phone2.value.length != "3")
				{
					phone2.focus();
					return "Your Phone Number Prefix is not 3 Digits";
				}
			}
		}
	
		if(phone3.value == "")
		{
			phone3.focus();
			return "You need to enter in your last 4 digits of your Phone Number";
		}
		else
		{
			if(isNaN(phone3.value))
			{
				phone3.focus();
				return "The last 4 digits of your Phone Number is not a valid Number";
			}
			else
			{
				if(phone3.value.length != "4")
				{
					phone3.focus();
					return "The last 4 digits of your Phone Number is not 4 Digits";
				}
			}
		}
//	}	
}


function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
	// Declaring required variables
	var digits = "0123456789";
	// non-digit characters which are allowed in phone numbers
	var phoneNumberDelimiters = "()- ";
	// characters which are allowed in international phone numbers
	// (a leading + is OK)
	var validWorldPhoneChars = phoneNumberDelimiters + "+";
	// Minimum no of digits in an international phone no.
	var minDigitsInIPhoneNumber = 10;
	var bracket=3
	
	strPhone=trim(strPhone)
	if(strPhone.indexOf("+")>1) return false
	if(strPhone.indexOf("-")!=-1)bracket=bracket+1
	if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
	var brchr=strPhone.indexOf("(")
	if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
	if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
	s=stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function checkPhoneNew(phone1, phone2, phone3, country)
{
     if(country.value == "US" || country.value == "CA")
     {

		if(phone1.value == "")
		{
			phone1.focus();
			return "You need to enter in your Area Code";
		}
		else
		{
			if(isNaN(phone1.value) || isInteger(phone1.value) === FALSE)
			{
				phone1.focus();
				return "Your Area Code is not a valid Number";
			}
			else
			{
				if(phone1.value.length != "3")
				{
					document.getElementById("bill_phone1").focus();
					return "Your Area Code is not 3 Digits long";
				}
			}
		}

		if(phone2.value == "")
		{
			phone2.focus();
			return "You need to enter in your Phone Number Prefix";
		}
		else
		{
			if(isNaN(phone2.value) || isInteger(phone2.value) === FALSE)
			{
				phone2.focus();
				return "Your Phone Number Prefix is not a valid Number";
			}
			else
			{
				if(phone2.value.length != "3")
				{
					phone2.focus();
					return "Your Phone Number Prefix is not 3 Digits";
				}
			}
		}

		if(phone3.value == "")
		{
			phone3.focus();
			return "You need to enter in your last 4 digits of your Phone Number";
		}
		else
		{
			if(isNaN(phone3.value) || isInteger(phone3.value) === FALSE)
			{
				phone3.focus();
				return "The last 4 digits of your Phone Number are not valid";
			}
			else
			{
				if(phone3.value.length != "4")
				{
					phone3.focus();
					return "The last 4 digits of your Phone Number is not 4 Digits";
				}
			}
		}

     } else {
           if(phone3.value == "")
	       {
                phone3.focus();
                if(country.value == "MX") {
                     return "Por favor ponga su numero de telefono";
                } else {
                     return "Please enter in your phone number";
                }
	       }
	       if(checkInternationalPhone(phone3.value) == FALSE)
	       {
	       		phone3.focus();
	       		return "Your Phone Number is not valid.  Please try again";
	       }
     }
}

function checkPhoneNR2(phone1, phone2, phone3, country)
{
     if(country.value == "US" || country.value == "CA")
     {

//	if(phone1.value != "" || phone2.value != "" || phone3.value != "")
//	{
		if(phone1.value == "")
		{
			phone1.focus();
			return "You need to enter in your Area Code";
		}
		else
		{
			if(isNaN(phone1.value))
			{
				phone1.focus();
				return "Your Area Code is not a valid Number";
			}
			else
			{
				if(phone1.value.length != "3")
				{
					document.getElementById("bill_phone1").focus();
					return "Your Area Code is not 3 Digits long";
				}
			}
		}

		if(phone2.value == "")
		{
			phone2.focus();
			return "You need to enter in your Phone Number Prefix";
		}
		else
		{
			if(isNaN(phone2.value))
			{
				phone2.focus();
				return "Your Phone Number Prefix is not a valid Number";
			}
			else
			{
				if(phone2.value.length != "3")
				{
					phone2.focus();
					return "Your Phone Number Prefix is not 3 Digits";
				}
			}
		}

		if(phone3.value == "")
		{
			phone3.focus();
			return "You need to enter in your last 4 digits of your Phone Number";
		}
		else
		{
			if(isNaN(phone3.value))
			{
				phone3.focus();
				return "The last 4 digits of your Phone Number are not valid";
			}
			else
			{
				if(phone3.value.length != "4")
				{
					phone3.focus();
					return "The last 4 digits of your Phone Number is not 4 Digits";
				}
			}
		}
//	}
     } else {
           if(phone3.value == "")
	   {
                phone3.focus();
                if(country.value == "MX") {
                     return "Por favor ponga su numero de telefono";
                } else {
                     return "Please enter in your phone number";
                }
	   }
     }
}

function checkCC(cc_type, cc_date, cc_year, cc_num)
{
	cc_num.value = lmescape(cc_num.value);

	if(cc_type.value == "0")
	{
		cc_type.focus();
		return "You need to select your Credit Card Type";
	}

	if(cc_num.value == "")
	{
		cc_num.focus();
		return "You need to enter in your Credit Card Number";
	}
	else
	{
		if((cc_type.value == 1 && (cc_num.value.length != "13" && cc_num.value.length != "16")) ||
			(cc_type.value == 2 && cc_num.value.length != "16") ||
			(cc_type.value == 3 && cc_num.value.length != "15") ||
			(cc_type.value == 4 && cc_num.value.length != "16"))
		{
			cc_num.focus();
			return "Your Credit Card Number is not the proper length";
		}
		if (!checkCreditCard (cc_num.value, cc_type.value))
		{
			return "Your Credit Card Number is Invalid";
		}
	}
	
	var d = new Date()
	var the_month = (d.getMonth() + 1);
	var the_year = d.getFullYear();
	if((cc_date.value < the_month) && (cc_year.value == the_year))
	{
		cc_date.focus();
		return "Your Credit Card has Expired";
	}
}

function checkCCcvv(cc_type, cc_cvv)
{
	cc_cvv.value = lmescape(cc_cvv.value);

	if(cc_type.value == "0")
	{
		cc_type.focus();
		return "You need to select your Credit Card Type";
	}

	if(cc_cvv.value == "")
	{
		cc_cvv.focus();
		return "You need to enter in your Card Verification Number";
	}
	else
	{
		if((cc_type.value == 1 && cc_cvv.value.length != "3") ||
			(cc_type.value == 2 && cc_cvv.value.length != "3") ||
			(cc_type.value == 3 && cc_cvv.value.length != "4") ||
			(cc_type.value == 4 && cc_cvv.value.length != "3"))
		{
			cc_cvv.focus();
			return "Your Card Verification Number is not the proper length";
		}
	}
}

function isValidEmail(str_to_test) 
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str_to_test))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function checkCreditCard (cardnumber, cardname)
{
	var ccErrorNo = 0;
	var ccErrors = new Array ()
	
	ccErrors [0] = "Unknown card type";
	ccErrors [1] = "No card number provided";
	ccErrors [2] = "Credit card number is in invalid format";
	ccErrors [3] = "Credit card number is invalid";
	ccErrors [4] = "Credit card number has an inappropriate number of digits";
     
  var cards = new Array();
  
  cards [0] = {name: "1", 
               length: "13,16", 
               prefixes: "4",
               checkdigit: true};
  cards [1] = {name: "2", 
               length: "16", 
               prefixes: "51,52,53,54,55",
               checkdigit: true};
  cards [2] = {name: "3", 
               length: "15", 
               prefixes: "34,37",
               checkdigit: true};
  cards [3] = {name: "4", 
               length: "16", 
               prefixes: "6011",
               checkdigit: true};
               
  var cardType = -1;
  for (var i=0; i<cards.length; i++) {

    if (cardname.toLowerCase () == cards[i].name.toLowerCase()) {
      cardType = i;
      break;
    }
  }
 
  if (cardType == -1) {
     ccErrorNo = 0;
     return false; 
  }
   
  if (cardnumber.length == 0)  {
     ccErrorNo = 1;
     return false; 
  }
  
  var cardNo = cardnumber
  var cardexp = /^([0-9]{4})\s?([0-9]{4})\s?([0-9]{4})\s?([0-9]{1,4})$/;
  if (!cardexp.exec(cardNo))  {
     ccErrorNo = 2;
     return false; 
  }
    
  cardexp.exec(cardNo);
  cardNo = RegExp.$1 + RegExp.$2 + RegExp.$3 + RegExp.$4;
       
  if (cards[cardType].checkdigit) {
    var checksum = 0;                                 
    var mychar = "";                                   
    var j = 1;                                         
  
    var calc;
    for (i = cardNo.length - 1; i >= 0; i--) {
    
      calc = Number(cardNo.charAt(i)) * j;
    
      if (calc > 9) {
        checksum = checksum + 1;
        calc = calc - 10;
      }
    
      checksum = checksum + calc;
    
      if (j ==1) {j = 2} else {j = 1};
    } 
  
    if (checksum % 10 != 0)  {
     ccErrorNo = 3;
     return false; 
    }
  }  
  
  var LengthValid = false;
  var PrefixValid = false; 
  var undefined; 

  var prefix = new Array ();
  var lengths = new Array ();
    
  prefix = cards[cardType].prefixes.split(",");
      
  for (i=0; i<prefix.length; i++) {
    var exp = new RegExp ("^" + prefix[i]);
    if (exp.test (cardNo)) PrefixValid = true;
  }
      
  if (!PrefixValid) {
     ccErrorNo = 3;
     return false; 
  }
    
  lengths = cards[cardType].length.split(",");
  for (j=0; j<lengths.length; j++) {
    if (cardNo.length == lengths[j]) LengthValid = true;
  }

  if (!LengthValid) {
     ccErrorNo = 4;
     return false; 
  };   
  
  return true;
}

is_this_being_used = false;
function checkQuantity()
{
	max_qty = (typeof max_qty == 'undefined') ? 0 : max_qty;
	is_this_being_used = true;
	if(isNaN(document.getElementById("quantity").value) || (document.getElementById("quantity").value <= 0))
	{
		alert("Please input a valid quantity");
		document.getElementById("quantity").value = 1;
		document.getElementById("quantity").focus();
		is_this_being_used = false;
		return false;
	}
	else if(document.getElementById("quantity").value > 20)
	{
		confirm_box = confirm("Are you sure you want to order " + document.getElementById("quantity").value + " of this item?");
		if(confirm_box == false)
		{
			document.getElementById("quantity").value = 1;
			document.getElementById("quantity").focus();
			is_this_being_used = false;
			return false;
		}
		return true;
	}
	
	is_this_being_used = false;
	return true;
}

function isCanadianPostCode(entry)
{ // CANADIAN CODES ONLY
	
	strlen = entry.length;
	if(strlen != 6 && strlen != 7)
	{
		return "Your Zip Code is not a valid Canadian Postal Code";
	}
	entry = entry.toUpperCase();    // in case of lowercase characters
	// Check for legal characters in string - note index starts at zero
	if('ABCEGHJKLMNPRSTVXY'.indexOf(entry.charAt(0))<0)
	{
		return "Your Postal Code is not valid";
	}
	if('0123456789'.indexOf(entry.charAt(1))<0)
	{
		return "Your Postal Code is not valid";
	}
	if('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(entry.charAt(2))<0)
	{
		return "Your Postal Code is not valid";
	}
	if(entry.charAt(3) == " ")
	{
		if('0123456789'.indexOf(entry.charAt(4))<0)
		{
			return "Your Postal Code is not valid";
		}
		if('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(entry.charAt(5))<0)
		{
			return "Your Postal Code is not valid";
		}
		if('0123456789'.indexOf(entry.charAt(6))<0)
		{
			return "Your Postal Code is not valid";
		}
	}
	else
	{
		if('0123456789'.indexOf(entry.charAt(3))<0)
		{
			return "Your Postal Code is not valid";
		}
		if('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(entry.charAt(4))<0)
		{
			return "Your Postal Code is not valid";
		}
		if('0123456789'.indexOf(entry.charAt(5))<0)
		{
			return "Your Postal Code is not valid";
		}
	}
	return entry;
}


function checkDuplicateOrderNew()
{

	var ccno        = $('#cc_num').val();
	var test        = '';
	if (ccno == '5500000000000004' || ccno == '') { 
		test = '1'; 
	}
	else {
		test = '0'; 
	}
	response = $.ajax({
	 	type: "POST",
	 	url: "includes/validation/findExistingOrders.php",
	 	async: false,
	 	data: 
	 		"email="+$('#bill_email').val()+
	 		"&clientid="+$('#clientid').val()+
	 		"&cid="+$('#cid').val()+
	 		"&offerid="+$('#offerid').val()+
	 		"&test="+test
	}
	).responseText;
	
	if (response == "{code:0}") {
		var validate = checkInfo();
		if(validate != false) {
			$('#cust_info').submit();
		}
	}
	else if (response == "{code:1}") {
		var result = confirm("We've already received an order from you today. Are you sure you would like to place another?");
		if (result == true) {
			var validate = checkInfo();
			if(validate != false) {
				$('#cust_info').submit();
			}
		}
		else {
			$('#cust_info').reset();
			return false;
		}
	}
	else {
		// erroneous code somewhere...reset form and send for help!
		mail("domainadmin@livemercial.com", "new dupechecker", "the new dupechecker for offer "+$('#cid').val()+" is not processing correctly.");
		$('#cust_info').reset();
		return false;
	}
	/*testvar = true;*/
}

function checkStateVsZip(state, zip)
{
	
	/*$.get("js/checkZip.php?state="+state.value+"&zip="+zip.value,*/
	test = $.ajax({
	 	type: "POST",
	 	url: "js/checkZip.php",
	 	async: false,
	 	data: "state="+state.value+"&zip="+zip.value
	}
	).responseText;
	
	if (test == '1') {
		return "Your Zip Code Does Not Match Your State";
	}
	/*testvar = true;*/
	
}

// XSS Protection & PCI Compliance
function lmescape(value)
{
	//value = escape(value);

        value = str_replace("<script>",  "", value);
        value = str_replace("</script>",  "", value);

	value = str_replace("<",  "", value);
        value = str_replace(">",  "", value);
        value = str_replace("'",  "", value);
        value = str_replace("\"", "", value);
        value = str_replace(")",  "", value);
        value = str_replace("(",  "", value);

        //value = str_replace("<",  "&lt;", value);
        //value = str_replace(">",  "&gt;", value);
        //value = str_replace("'",  "&apos;", value);
        //value = str_replace("\"", "&#x22;", value);
        //value = str_replace(")",  "&#x29;", value);
        //value = str_replace("(",  "&#x28;", value);

	return value;

}


function str_replace(f, r, s){
	var ra = r instanceof Array, sa = s instanceof Array, l = (f = [].concat(f)).length, r = [].concat(r), i = (s = [].concat(s)).length;
	while(j = 0, i--)
		while(s[i] = s[i].split(f[j]).join(ra ? r[j] || "" : r[0]), ++j < l);
	return sa ? s : s[0];
}


//-->

