function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function validateEmail(target){
	var emailID=target
	
	if ((emailID.value==null)||(emailID.value=="")){
		//alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }
 
function validZip(target) {
   var zip = target;
   var zipRegExp = /(^\d{5}$)|(^\D{1}\d{1}\D{1}\s\d{1}\D{1}\d{1}$)/;
   return zipRegExp.test(zip);
}

// 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;

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 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){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function ValidateNumber(target){
	var Phone=target
	
	if ((Phone.value==null)||(Phone.value=="")){
		//alert("Please Enter your Phone Number")
		Phone.focus()
		return false
	}
	if (checkInternationalPhone(Phone.value)==false){
		//alert("Please Enter a Valid Phone Number")
		Phone.value=""
		Phone.focus()
		return false
	}
	return true
 }

<!--
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: David Leppek :: https://www.azcode.com/Mod10

Basically, the alorithum takes each digit, from right to left and muliplies each second
digit by two. If the multiple is two-digits long (i.e.: 6 * 2 = 12) the two digits of
the multiple are then added together for a new number (1 + 2 = 3). You then add up the 
string of numbers, both unaltered and new values and get a total sum. This sum is then
divided by 10 and the remainder should be zero if it is a valid credit card. Hense the
name Mod 10 or Modulus 10. */
function Mod10(ccNumb) {  // v2.0
var valid = "0123456789"  // Valid digits in a credit card number
var len = ccNumb.length;  // The length of the submitted cc number
var iCCN = parseInt(ccNumb);  // integer of ccNumb
var sCCN = ccNumb.toString();  // string of ccNumb
sCCN = sCCN.replace (/^\s+|\s+$/g,'');  // strip spaces
var iTotal = 0;  // integer total set at zero
var bNum = true;  // by default assume it is a number
var bResult = false;  // by default assume it is NOT a valid cc
var temp;  // temp variable for parsing string
var calc;  // used for calculation of each digit

// Determine if the ccNumb is in fact all numbers
for (var j=0; j<len; j++) {
  temp = "" + sCCN.substring(j, j+1);
  if (valid.indexOf(temp) == "-1"){bNum = false;}
}

// if it is NOT a number, you can either alert to the fact, or just pass a failure
if(!bNum){
  /*alert("Not a Number");*/bResult = false;
}

// Determine if it is the proper length 
if((len == 0)&&(bResult)){  // nothing, field is blank AND passed above # check
  bResult = false;
} else{  // ccNumb is a number and the proper length - let's see if it is a valid card number
  if(len >= 15){  // 15 or 16 for Amex or V/MC
    for(var i=len;i>0;i--){  // LOOP throught the digits of the card
      calc = parseInt(iCCN) % 10;  // right most digit
      calc = parseInt(calc);  // assure it is an integer
      iTotal += calc;  // running total of the card number as we loop - Do Nothing to first digit
      i--;  // decrement the count - move to the next digit in the card
      iCCN = iCCN / 10;                               // subtracts right most digit from ccNumb
      calc = parseInt(iCCN) % 10 ;    // NEXT right most digit
      calc = calc *2;                                 // multiply the digit by two
      // Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7,
      // I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple.
      switch(calc){
        case 10: calc = 1; break;       //5*2=10 & 1+0 = 1
        case 12: calc = 3; break;       //6*2=12 & 1+2 = 3
        case 14: calc = 5; break;       //7*2=14 & 1+4 = 5
        case 16: calc = 7; break;       //8*2=16 & 1+6 = 7
        case 18: calc = 9; break;       //9*2=18 & 1+8 = 9
        default: calc = calc;           //4*2= 8 &   8 = 8  -same for all lower numbers
      }                                               
    iCCN = iCCN / 10;  // subtracts right most digit from ccNum
    iTotal += calc;  // running total of the card number as we loop
  }  // END OF LOOP
  if ((iTotal%10)==0){  // check to see if the sum Mod 10 is zero
    bResult = true;  // This IS (or could be) a valid credit card number.
  } else {
    bResult = false;  // This could NOT be a valid credit card number
    }
  }
}
// change alert to on-page display or other indication as needed.
if(bResult) {
  //alert("This IS a valid Credit Card Number!");
  document.getElementById('checkoutFormid').submit();
  //return true;
}
if(!bResult){
  alert("Please enter a valid credit card number.");
  return false;
}
  //return bResult; // Return the results
}


function validatecard () {
	if (document.validate.firstname.value == "")
	{
		alert("Please enter your first name.");
		document.validate.firstname.focus();
		return (false);
	}

	if (document.validate.lastname.value == "")
	{
		alert("Please enter your last name.");
		document.validate.lastname.focus();
		return (false);
	}

	if (document.validate.address1.value == "")
	{
		alert("Please enter your address.");
		document.validate.address1.focus();
		return (false);
	}

	if (document.validate.city.value == "")
	{
		alert("Please enter your city.");
		document.validate.city.focus();
		return (false);
	}

	if (document.validate.state.value == "")
	{
		alert("Please enter your state.");
		document.validate.state.focus();
		return (false);
	}

	if (document.validate.zip.value == "")
	{
		alert("Please enter your zip code.");
		document.validate.zip.focus();
		return (false);
	}

	checkZip = validZip(document.validate.zip.value);
	
	if (!checkZip) {
		alert("Please enter a valid zip code.");
		document.validate.zip.focus();
		return (false);
	}

	if (document.validate.email.value == "")
	{
		alert("Please enter your email address.");
		document.validate.email.focus();
		return (false);
	}

	checkEmail = validateEmail(document.validate.email);

	if (!checkEmail) {
		alert("Please enter a valid email address.");
		document.validate.email.focus();
		return (false);
	}

	if (document.validate.phone.value == "")
	{
		alert("Please enter your phone number.");
		document.validate.phone.focus();
		return (false);
	}
	
	phoneTest = ValidateNumber(document.validate.phone);
	
	if (!phoneTest) {
		alert("The phone number you entered is not valid.");
		document.validate.phone.focus();
		return (false);
	}
	
	if (!document.validate.sameasbilling.checked) {
		if (document.validate.shipfirstname.value == "")
		{
			alert("Please enter your shipping first name.");
			document.validate.shipfirstname.focus();
			return (false);
		}
	
		if (document.validate.shiplastname.value == "")
		{
			alert("Please enter your shipping last name.");
			document.validate.shiplastname.focus();
			return (false);
		}
	
		if (document.validate.shipaddress1.value == "")
		{
			alert("Please enter your shipping address.");
			document.validate.shipaddress1.focus();
			return (false);
		}
	
		if (document.validate.shipcity.value == "")
		{
			alert("Please enter your shipping city.");
			document.validate.shipcity.focus();
			return (false);
		}
	
		if (document.validate.shipstate.value == "")
		{
			alert("Please enter your shipping state.");
			document.validate.shipstate.focus();
			return (false);
		}
	
		if (document.validate.shipzip.value == "")
		{
			alert("Please enter your shipping zip code.");
			document.validate.shipzip.focus();
			return (false);
		}

		checkZipShip = validZip(document.validate.shipzip.value);
		
		if (!checkZipShip) {
			alert("Please enter a valid shipping zip code.");
			document.validate.shipzip.focus();
			return (false);
		}
	
		if (document.validate.shipemail.value == "")
		{
			alert("Please enter your shipping email address.");
			document.validate.shipemail.focus();
			return (false);
		}

		checkEmailShip = validateEmail(document.validate.shipemail);
	
		if (!checkEmailShip) {
			alert("Please enter a valid shipping email address.");
			document.validate.shipemail.focus();
			return (false);
		}

		if (document.validate.shipphone.value == "")
		{
			alert("Please enter your shipping phone number.");
			document.validate.shipphone.focus();
			return (false);
		}
			
		phoneTestShip = ValidateNumber(document.validate.shipphone);
		
		if (!phoneTestShip) {
			alert("The shipping phone number you entered is not valid.");
			document.validate.shipphone.focus();
			return (false);
		}
	
	}

	if (document.validate.cc_name.value == "") {
		alert("Please enter the name as it appears on the credit card.");
		document.validate.cc_name.focus();
		return (false);
	}

	if (document.validate.accountnumber.value == "") {
		alert("Please enter your credit card number.");
		document.validate.accountnumber.focus();
		return (false);
	}

	if (document.validate.accountnumber.value.length != 15 && document.validate.accountnumber.value.length != 16) {
		alert("Please enter a valid credit card number.");
		document.validate.accountnumber.focus();
		return (false);
	}

	if (document.validate.cc_cvv.value == "") {
		alert("Please enter the cards CVV number.");
		document.validate.cc_cvv.focus();
		return (false);
	}

	ccResult = Mod10(document.validate.accountnumber.value);
	if (!ccResult) {
		return false;	
	}
}

// function to hide or show divs based on clicks
function toggleLayer( whichLayer ) {
	var elem, vis;
	if( document.getElementById ) // this is the way the standards work
		elem = document.getElementById( whichLayer );
	else if( document.all ) // this is the way old msie versions work
		elem = document.all[whichLayer];
	else if( document.layers ) // this is the way nn4 works
		elem = document.layers[whichLayer];
	
	vis = elem.style;
	// if the style.display value is blank we try to figure it out here
	if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
		vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
		vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

var newwindow;

function openWindow() {
	newwindow=window.open('cvv.html','cvv','height=250,width=600,left=100,top=100,resizable=no,scrollbars=no,toolbar=no,status=no');
	if (window.focus) {newwindow.focus()}
}

function copyBillingInfo() {
	if (document.getElementById('sameasbillingid').checked == true) {
		document.getElementById('shipfirstnameid').value = document.getElementById('firstnameid').value;
		document.getElementById('shiplastnameid').value = document.getElementById('lastnameid').value;
		document.getElementById('shipaddress1id').value = document.getElementById('address1id').value;
		document.getElementById('shipaddress2id').value = document.getElementById('address2id').value;
		document.getElementById('shipcityid').value = document.getElementById('cityid').value;
		document.getElementById('shipstateid').value = document.getElementById('stateid').value;
		document.getElementById('shipzipid').value = document.getElementById('zipid').value;
		document.getElementById('shipcountryid').value = document.getElementById('countryid').value;
		document.getElementById('shipemailid').value = document.getElementById('emailid').value;
		document.getElementById('shipphoneid').value = document.getElementById('phoneid').value;
	} else {
		document.getElementById('shipfirstnameid').value = '';
		document.getElementById('shiplastnameid').value = '';
		document.getElementById('shipaddress1id').value = '';
		document.getElementById('shipaddress2id').value = '';
		document.getElementById('shipcityid').value = '';
		document.getElementById('shipstateid').value = '';
		document.getElementById('shipzipid').value = '';
		document.getElementById('shipcountryid').value = '';
		document.getElementById('shipemailid').value = '';
		document.getElementById('shipphoneid').value = '';
		document.getElementById('shipfirstnameid').focus();
	}
	checkShippingStateShip();
	checkShipping(); 
}

function unCheck() {
	if (document.getElementById('sameasbillingid').checked == true) {
		document.getElementById('sameasbillingid').checked = false;	
	}
}

function checkShippingState() {
	if (document.getElementById('stateid').value == "AK" || document.getElementById('stateid').value == "HI") {
		if (document.getElementById('shipping_ak_hi').style.display = 'none') {
			document.getElementById('shipping_us').style.display = 'none';
			document.getElementById('shipping_cn').style.display = 'none';
			document.getElementById('shipping_ak_hi').style.display = 'block';
			document.getElementById('shipping_methodakhiidstandard').checked = true;
		}
	} else {
		if (document.getElementById('countryid').value == "CN") {
			document.getElementById('shipping_ak_hi').style.display = 'none';
			document.getElementById('shipping_us').style.display = 'none';
			document.getElementById('shipping_cn').style.display = 'block';
			document.getElementById('shipping_methodcnidstandard').checked = true;
		} else {
			document.getElementById('shipping_ak_hi').style.display = 'none';
			document.getElementById('shipping_cn').style.display = 'none';
			document.getElementById('shipping_us').style.display = 'block';
			document.getElementById('shipping_methodidstandard').checked = true;
		}
	}
}

function checkShippingStateShip() {
	if (document.getElementById('shipstateid').value == "AK" || document.getElementById('shipstateid').value == "HI") {
		if (document.getElementById('shipping_ak_hi').style.display = 'none') {
			document.getElementById('shipping_us').style.display = 'none';
			document.getElementById('shipping_cn').style.display = 'none';
			document.getElementById('shipping_ak_hi').style.display = 'block';
			document.getElementById('shipping_methodakhiidstandard').checked = true;
		}
	} else {
		if (document.getElementById('shipcountryid').value == "CN") {
			document.getElementById('shipping_ak_hi').style.display = 'none';
			document.getElementById('shipping_us').style.display = 'none';
			document.getElementById('shipping_cn').style.display = 'block';
			document.getElementById('shipping_methodcnidstandard').checked = true;
		} else {
			document.getElementById('shipping_ak_hi').style.display = 'none';
			document.getElementById('shipping_cn').style.display = 'none';
			document.getElementById('shipping_us').style.display = 'block';
			document.getElementById('shipping_methodidstandard').checked = true;
		}
	}
}

function checkShipping() {
		if (document.getElementById('shipcountryid').value == "US") {
			if (document.getElementById('shipstateid').value == "AK" || document.getElementById('shipstateid').value == "HI") {
				checkShippingState;
			} else {
				if (document.getElementById('shipping_us').style.display = 'none') {
					document.getElementById('shipping_ak_hi').style.display = 'none';
					document.getElementById('shipping_cn').style.display = 'none';
					document.getElementById('shipping_us').style.display = 'block';
					document.getElementById('shipping_methodidstandard').checked = true;
				}
			}
		} else if (document.getElementById('shipcountryid').value == "CN") {
			if (document.getElementById('shipstateid').value == "AK" || document.getElementById('shipstateid').value == "HI") {
				checkShippingStateShip;
			} else {
				if (document.getElementById('shipping_cn').style.display = 'none') {
					document.getElementById('shipping_ak_hi').style.display = 'none';
					document.getElementById('shipping_us').style.display = 'none';
					document.getElementById('shipping_cn').style.display = 'block';
					document.getElementById('shipping_methodcnidstandard').checked = true;
				}
			}
		}
}

function checkForm(theForm)
{
  if (theForm.first_name.value.length < 2)
  {
    alert("Please enter your first name.");
    theForm.first_name.focus();
    return (false);
  }

  if (theForm.last_name.value.length < 2)
  {
    alert("Please enter your last name.");
    theForm.last_name.focus();
    return (false);
  }
  if (theForm.address1.value.length < 5)
  {
    alert("Please enter your address.");
    theForm.address1.focus();
    return (false);
  }
  if (theForm.city.value.length < 2)
  {
    alert("Please enter your city.");
    theForm.city.focus();
    return (false);
  }
  if (theForm.state.value == "")
  {
    alert("Please select your state");
    theForm.state.focus();
    return (false);
  }
  if (theForm.zip.value.length < 5)
  {
    alert("Please enter your zip code.");
    theForm.zip.focus();
    return (false);
  }
  if (theForm.email.value.length < 7)
  {
    alert("Please enter your email address.");
    theForm.email.focus();
    return (false);
  }
  if (theForm.area_code.value.length < 3)
  {
    alert("Please enter your area code.");
    theForm.area_code.focus();
    return (false);
  }
  if (theForm.prefix.value.length < 3)
  {
    alert("Please enter your phone number prefix.");
    theForm.prefix.focus();
    return (false);
  }
  if (theForm.suffix.value.length < 4)
  {
    alert("Please enter your phone number suffix.");
    theForm.suffix.focus();
    return (false);
  }
  return true;
}

function checkCS(theForm)
{
  if (theForm.realname.value.length < 2)
  {
    alert("Please enter your name.");
    theForm.realname.focus();
    return (false);
  }

  if (theForm.email.value.length < 2)
  {
    alert("Please enter your email address.");
    theForm.email.focus();
    return (false);
  }
  document.getElementById('CustomerService_id').submit();
}
