// JavaScript Document


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){
		   return false;
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false;
		 }
 		 return true;
	}




function TrimString(sInString) {
  sInString = sInString.replace( /^\s+/g, "" );// strip leading
  return sInString.replace( /\s+$/g, "" );// strip trailing
}

function checkAddress()
{
 var a = document.getElementById('mailing_address').value;
 a = a.replace(".","","gi");
 a = a.replace(" ","","gi");
 a = a.toLowerCase();
 a = TrimString(a);
// alert("|" + a + "|");
 if (a.match("pobox"))
 {
  alert('Please note that we can only ship orders to PO Boxes via US Mail. If you choose to specify a mailing address with a PO Box, please make sure to select the USPS shipping option.');
 }
}

function orderAR()
{
 orderok = 1;
 var orderalert = "";
 if (!(echeck(document.getElementById('email').value)))
 {
	orderok = 0;
	orderalert = orderalert + " The email address entered is not valid. "
 }

 if (document.getElementById('shipping_service').value!="USPS")
 {
  if (document.getElementById('shipping_account_number').value=="")
  {
   orderok = 0;
   orderalert  = orderalert + " You must specify a shipping account number if you wish to receive your order through a service other than the US Postal Service.";
  }
 } 
 
 if ( (document.getElementById('payment_type').value=="check") && (document.getElementById('country').value!="USA") )
 {
  orderok = 0;
  orderalert  = orderalert + " If you are ordering from outside of the USA, then please select the Credit Card payment method. ";
 }


/*
if ( (document.getElementById('country').value!="USA") && (document.getElementById('shipping_service').value=="USPS") )
 {
  orderok = 0;
  orderalert  = orderalert + " If the reports will be shipped out of the US, you must choose a carrier OTHER than the US Postal Service. ";
 }
*/

 if (orderok==1)
 {
  document.form1.submit();
 }
 else
 {
  alert(orderalert);
 }

}


