  var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function check_value(ele, e){
  // var e = document.getElementById('text');
  var keycode = (isNN) ? e.which : e.keyCode;  // e=event

  //alert ('keycode='+keycode)
  //if (ele.value=='') return // allow empty
  if (!keycode) return;  // allow backspace
  if ( (keycode==8) || (keycode==46)) {
    // on backspace or delete key... check the value and put a zero if its null
   // if (ele.value == '') ele.value=0;   // disabled
    //alert('check_value(): val='+ele.value);
    return;  // allow backspace
  }
  if (keycode==9) return;  // allow tabs
  if (keycode==13) return;  // allow enter
  if (keycode==16) return;  // allow right/left shift
  if (keycode==17) return;  // allow ctrl 
  if (keycode==18) return;  // allow alt
  if (keycode==27) return;  // allow esc
  if (keycode==33) return;  // allow pg-up
  if (keycode==34) return;  // allow pg-down
  if (keycode==35) return;  // allow end
  if (keycode==36) return;  // allow home
  if (keycode==37) return;  // allow left arrow
  if (keycode==38) return;  // allow up arrow
  if (keycode==39) return;  // allow right arrow
  if (keycode==40) return;  // allow down arrow
  if (keycode==45) return;  // allow insert
   
  if (!/^[0-9\.\-]+$/.test(ele.value)) { 
    //if (ele.value == '') return;
    alert("Please enter only a number.");
    ele.value = ele.value.substring(0,ele.value.length-1);
  }
  //alert('check_value(): val='+ele.value);
}   
/*
//New phone function end

var sec = 00;   // set the seconds
var min = 5;   // set the minutes

function countDown() {
  sec--;
  if (sec == -01) {
    sec = 59;
    min = min - 1;
  } else {
   min = min;
  }
if (sec<=9) { sec = "0" + sec; }
  time = (min<=9 ? "0" + min : min) + ":" + sec + "";
if (document.getElementById) { theTime.innerHTML = time; }
  SD=window.setTimeout("countDown();", 1000);
if (min == '00' && sec == '00') { sec = "00"; window.clearTimeout(SD); }
}

*/



/*
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function() {
  countDown();
});
*/
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function check_form_landing(form) {
    var first_initial=form.first_initial.value;
    var last_name=form.last_name.value;
    var tnc=form.tnc;
    var email=form.email_id.value;
    var areacode=form.phone_1.value;
    var phonedir=form.phone_2.value;
    var phone=form.phone_3.value;
	var emailRegEx = null;
    
    errors = 0;
    var msg='';
    //if (first_initial == '') 
    emailRegEx = /^[a-zA-Z]{1}$/i;
    if( first_initial.search(emailRegEx) == -1 )
    { 
    	msg=msg+"Initial of first name is invalid.\n"; 
    	errors++; 
    }
    //if (last_name == '') 
    emailRegEx = /^[a-zA-Z]+$/i;
    if( last_name.search(emailRegEx) == -1 )
    {
    	msg=msg+"Last name invalid.\n"; 
    	errors++; 
    }
    
    
    /*validate email format*/  
	emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
    if( email.search(emailRegEx) == -1 ) 
    {
          msg = msg + "Please enter a valid email address.\n"; 
          errors++;
    }
     
     
	
    
    
    if (areacode == '') {
      msg=msg+"Area code is required.\n"; errors++;
    } else {
      if (areacode.length != 3) {
        msg=msg+"Area code must be three digits.\n"; errors++;
      }
      if (areacode.match('^[01]')) {
        msg=msg+"Area code does not start with a zero or a one.\n"; errors++;
      }
    }
    if (phonedir == '') {
      msg=msg+"Phone prefix is required.\n"; errors++;
    } else {
      if (phonedir.length != 3) {
        msg=msg+"Phone prefix must be three digits.\n"; errors++;
      }
      if (phonedir.match('^[01]')) {
        msg=msg+"Phone prefix does not start with a zero or a one.\n"; errors++;
      }
    }

    if (phone == '') {
      msg=msg+"Phone number is required.\n"; errors++;
    } else {
      if (phone.length != 4) {
        msg=msg+"Phone number must be four digits.\n"; errors++;
      }
    }

    if (tnc && (tnc.checked == false)) {
      msg=msg+"Terms and Conditions acceptance is required.\n"; errors++;
    } 

    if (errors > 0) {
      msg=msg+"\nThere were "+errors+" error(s) found.  Please fix.";
      alert(msg);
      return false;
    }
    //alert('first_initial='+first_initial+', last_name='+last_name+', street_address='+street_address+', city='+city+', '+
    //      'state='+state+', zip='+zip+', email='+email+', areacode='+areacode+', phonedir='+phonedir+', phone='+phone+', msg='+msg);
    return true;
}


function check_form_1(form)
{
	var first_initial=form.first_initial.value;
    var last_name=form.last_name.value;
   
    errors = 0;
    var msg='';
    //if (first_initial == '') 
    emailRegEx = /^[a-zA-Z]{1}$/i;
    if( first_initial.search(emailRegEx) == -1 )
    { 
    	msg=msg+"Initial of first name is invalid.\n"; 
    	errors++; 
    }
    //if (last_name == '') 
    emailRegEx = /^[a-zA-Z]+$/i;
    if( last_name.search(emailRegEx) == -1 )
    {
    	msg=msg+"Last name invalid.\n"; 
    	errors++; 
    }
    
    
    
    if (errors > 0) {
      msg=msg+"\nThere were "+errors+" error(s) found.  Please fix.";
      alert(msg);
      return false;
    }
    //alert('first_initial='+first_initial+', last_name='+last_name+', street_address='+street_address+', city='+city+', '+
    //      'state='+state+', zip='+zip+', email='+email+', areacode='+areacode+', phonedir='+phonedir+', phone='+phone+', msg='+msg);
    return true;
}


function check_form_2(form)
{
	var tnc=form.tnc;
    var email=form.email_id.value;
    var areacode=form.phone_1.value;
    var phonedir=form.phone_2.value;
    var phone=form.phone_3.value;
	var emailRegEx = null;
    
    errors = 0;
    var msg='';
   
    
    
    /*validate email format*/  
	emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
    if( email.search(emailRegEx) == -1 ) 
    {
          msg = msg + "Please enter a valid email address.\n"; 
          errors++;
    }
     
     
	
    
    
    if (areacode == '') {
      msg=msg+"Area code is required.\n"; errors++;
    } else {
      if (areacode.length != 3) {
        msg=msg+"Area code must be three digits.\n"; errors++;
      }
      if (areacode.match('^[01]')) {
        msg=msg+"Area code does not start with a zero or a one.\n"; errors++;
      }
    }
    if (phonedir == '') {
      msg=msg+"Phone prefix is required.\n"; errors++;
    } else {
      if (phonedir.length != 3) {
        msg=msg+"Phone prefix must be three digits.\n"; errors++;
      }
      if (phonedir.match('^[01]')) {
        msg=msg+"Phone prefix does not start with a zero or a one.\n"; errors++;
      }
    }

    if (phone == '') {
      msg=msg+"Phone number is required.\n"; errors++;
    } else {
      if (phone.length != 4) {
        msg=msg+"Phone number must be four digits.\n"; errors++;
      }
    }

    if (tnc && (tnc.checked == false)) {
      msg=msg+"Terms and Conditions acceptance is required.\n"; errors++;
    } 

    if (errors > 0) {
      msg=msg+"\nThere were "+errors+" error(s) found.  Please fix.";
      alert(msg);
      return false;
    }
    //alert('first_initial='+first_initial+', last_name='+last_name+', street_address='+street_address+', city='+city+', '+
    //      'state='+state+', zip='+zip+', email='+email+', areacode='+areacode+', phonedir='+phonedir+', phone='+phone+', msg='+msg);
    return true;
}


function check_form_order(form) {
    var first_name=form.first_name.value;
    var last_name=form.last_name.value;
    var street_address=form.billing_address.value;
    var city=form.city.value;
    var state=form.state.value;
    var zip=form.zip.value;
    var email=form.email_id.value;
    var areacode=form.phone_1.value;
    var phonedir=form.phone_2.value;
    var phone=form.phone_3.value;
      var card_type=form.card_type.value;
    var card_no=form.card_no.value;
    var card_cvv=form.card_cvv.value;
    var expiry_month=form.expiry_month.value;
    var expiry_year=form.expiry_year.value;
    var tnc=form.tnc;
    
	var regExpr = null;
	
    errors = 0;
    var msg='';
    
    regExpr = /^[a-zA-Z]+$/i;
    if( first_name.search(regExpr) == -1 )
    { 
    	msg=msg+"First Name is invalid.\n"; 
    	errors++; 
    }
    
    regExpr = /^[a-zA-Z]+$/i;
    if( last_name.search(regExpr) == -1 )
    { 
    	msg=msg+"Last Name is invalid.\n"; 
    	errors++;
    }
    
    regExpr = /^.*/i;
    if( street_address.search(regExpr) == -1 )
    { 
    	msg=msg+"Street address is invalid.\n"; 
    	errors++; 
    }
    
    regExpr = /^([a-zA-Z]+|[a-zA-Z]+\s[a-zA-Z]+)$/i;
    if( city.search(regExpr) == -1 )
    { 
    	msg=msg+"City is invalid.\n"; 
    	errors++; 
    }
    
    regExpr = /^[A-Z]{2}$/i;
    if( state.search(regExpr) == -1 )
    { 
    	msg=msg+"State is required.\n"; 
    	errors++; 
    }
    
    regExpr = /^\d{5}([\-]\d{4})?$/i;
    if( zip.search(regExpr) == -1 )
    { 
      msg=msg+"Zipcode is invalid.\n"; 
      errors++; 
    } 
    
    
    /*validate email format*/  
	regExpr = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
    if( email.search(regExpr) == -1 ) 
    {
          msg = msg + "Please enter a valid email address.\n"; 
          errors++;
    }
    
    
    
    if (areacode == '') 
    { 
      	  msg=msg+"Area code is required.\n"; errors++; 
    } 
    else 
    {
	      if (areacode.length != 3) 
	      {
	        msg=msg+"Area code must be three digits.\n"; errors++;
	      }
	      if (areacode.match('^[01]')) 
	      {
	        msg=msg+"Area code does not start with a zero or a one.\n"; errors++;
	      }
    }
    
    
    
    if (phonedir == '') 
    { 
      	  msg=msg+"Phone prefix is required.\n"; errors++; 
    } 
    else 
    {
	      if (phonedir.length != 3) 
	      {
	        msg=msg+"Phone prefix must be three digits.\n"; errors++;
	      }
	      if (phonedir.match('^[01]')) 
	      {
	        msg=msg+"Phone prefix does not start with a zero or a one.\n"; errors++;
	      }
    }

    
    
    
	switch( card_type )
	{
		case 'Visa': regExpr = /^4[0-9]{12}(?:[0-9]{3})?$/i;
					 if( card_no.search(regExpr) == -1 ) 
					 	msg = msg + "Enter a valid Visa card number.\n";
					 break;
		case 'MasterCard':   regExpr = /^5[1-5][0-9]{14}$/i;
	    					 if( card_no.search(regExpr) == -1 ) 
	    					 	msg = msg + "Enter a valid Master card number.\n";
	    					 break;
	    case 'American Express':     regExpr = /^3[47][0-9]{13}$/i;
			    					 if( card_no.search(regExpr) == -1 ) 
			    					 	msg = msg + "Enter a valid America Express card number.\n";
			    					 break;
		case 'Discover':     regExpr = /^6(?:011|5[0-9]{2})[0-9]{12}$/i;
	    					 if( card_no.search(regExpr) == -1 ) 
	    					 	msg = msg + "Enter a valid Discover card number.\n";
	    					 break;
	    default: msg = msg + "Select a credit card type.\n"; 
	}
    
    
	    
    
    
    
    regExpr = /^[0-9]{3,4}$/i;
	if( card_cvv.search(regExpr) == -1 ) 
    {
      	msg=msg+"CVV number is invalid.\n"; 
      	errors++;
    } 
    
    
    
    if (expiry_month == '') {
      msg=msg+"Expiration month is required.\n"; errors++;
    } 
    if (expiry_year == '') {
      msg=msg+"Expiration year is required.\n"; errors++;
    } 

    if (phone == '') { 
      msg=msg+"Phone number is required.\n"; errors++; 
    } else {
      if (phone.length != 4) {
        msg=msg+"Phone number must be four digits.\n"; errors++;
      }
    }
    if (tnc && (tnc.checked == false)) {
      msg=msg+"Terms and Conditions acceptance is required.\n"; errors++;
    } 

    if (errors > 0) {
      msg=msg+"\nThere were "+errors+" error(s) found.  Please fix."; 
      alert(msg);
      return false;
    }
    //alert('first_name='+first_name+', last_name='+last_name+', street_address='+street_address+', city='+city+', '+
    //      'state='+state+', zip='+zip+', email='+email+', areacode='+areacode+', phonedir='+phonedir+', phone='+phone+', msg='+msg);
    return true;
}
