

function validRequired(formField,fieldLabel)
{
    var result = true;
    
    if (formField.value == "")
    {
         alert('Oops, you forgot to enter a value for "' + fieldLabel +'.');

         formField.focus();
         result = false;
    }
    
    return result;
}

//Validate the Select
function hasSelection(strFieldName,strMsg)     {
     var objFormField = document.forms[0].elements[strFieldName];
     if(objFormField.selectedIndex ==0)     {
         alert("Oops, you forgot to enter a value for " + strMsg +".");
         formField.focus();         
           return false;
           }
     return true;
}

function checkRadioControl(strFormField,strMessage) 
{
  var objFormField = document.forms[0].elements[strFormField]
  intControlLength = objFormField.length
  bolSelected = false;
  for (i=0;i<intControlLength;i++){
       if(objFormField[i].checked){
                 bolSelected = true;
                 break;
       }
  }     
  if(!bolSelected){
       alert("Oops, you forgot to select your " + strMessage + "!\nWe need to know where to ship your order.");
       return false;
  }else{
       return true;
  }
   return result;
}



var submitcount=0;

function validateForm(theForm)

{

    // Active the checks for the required fields and radio buttons

    // Start ------->
    if (!validRequired(theForm.b_first," Customer Information: First Name"))
         return false;

    if (!validRequired(theForm.b_last," Customer Information: Last Name"))
         return false;

    if (!validRequired(theForm.b_addr," Customer Information: Address"))
         return false;

    if (!validRequired(theForm.b_city," Customer Information: City"))
         return false;

    if (!validRequired(theForm.b_state," Customer Information: State"))
         return false;

    if (!validRequired(theForm.b_zip," Customer Information: ZipCode"))
         return false;

    if (!validRequired(theForm.b_email," Customer Information: E-mail"))
         return false;
    if (CCCheckout) {
    if (!validRequired(theForm.CardName," Payment Information: Credit Card Type"))
         return false;

    if (!validRequired(theForm.CardNumber1," Payment Information: Credit Card Number"))
         return false;
    
    if (!validRequired(theForm.CardNumber2," Payment Information: Credit Card Number"))
         return false;
    
    if (!validRequired(theForm.CardNumber3," Payment Information: Credit Card Number"))
         return false;
    
    if (!validRequired(theForm.CardNumber4," Payment Information: Credit Card Number"))
         return false;
      
    if (!validRequired(theForm.ExpMon," Payment Information: Expiry Month"))
         return false;
	  
    if (!validRequired(theForm.ExpYear," Payment Information: Expiry Year"))
         return false;
	  }
	  
         if (submitcount == 0)
      {
      submitcount++;
document.checkout.b_first.value = document.orderform.b_first.value; 
document.checkout.b_last.value  = document.orderform.b_last.value;
document.checkout.b_addr.value  = document.orderform.b_addr.value; 
document.checkout.b_addr2.value = document.orderform.b_addr2.value;
document.checkout.b_city.value  = document.orderform.b_city.value; 
document.checkout.b_state.value = document.orderform.b_state.value;
document.checkout.b_zip.value   = document.orderform.b_zip.value; 
document.checkout.b_phone.value = document.orderform.b_phone.value;
document.checkout.b_fax.value   = document.orderform.b_fax.value; 
document.checkout.b_email.value = document.orderform.b_email.value; 
document.checkout.comment.value = document.orderform.comment.value;
document.checkout.b_cctype.value = document.orderform.CardName.value;
document.checkout.b_ccnum1.value   = document.orderform.CardNumber1.value; 
document.checkout.b_ccnum2.value   = document.orderform.CardNumber2.value; 
document.checkout.b_ccnum3.value   = document.orderform.CardNumber3.value; 
document.checkout.b_ccnum4.value   = document.orderform.CardNumber4.value; 
document.checkout.b_ccexpmon.value = document.orderform.ExpMon.value; 
document.checkout.b_ccexpyear.value = document.orderform.ExpYear.value;
document.checkout.b_cccvn.value = document.orderform.CVN.value;

		//		SendIt();
    document.checkout.submit(this);
           return false;
      }
   else 
      {
      alert("This form has already been submitted,\nand we are now processing your order.\n\nThanks!");
      return false;      }
         // <--------- End

}
    

function SendIt() {
    document.checkout.submit(this);		// contents of shopping cart 
}

//  End -->



<!-- Begin

// Cookie Functions -=#=-=#=-=#=-

  function setCookie(name, value, expires) {
    var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "");
    document.cookie = curCookie;
  }


  function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
      begin = dc.indexOf(prefix);
      if (begin != 0) return null;
    } else
      begin += 2;
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
      end = dc.length;
    return unescape(dc.substring(begin + prefix.length, end));
  }

  function deleteCookie(name) {
    if (getCookie(name)) {
      document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
  }


  var cc = new Object(); // creating our übercool object
  var now = new Date();
  var expBill = "";
  now.setTime(now.getTime() + (expBill * 24 * 60 * 60 * 1000)); // set cookie xpiration date to almost never :)
  
  cc.form = 'orderform'; // string for holding title of form, for which we want to do autosave
  cc.fields = new Array('b_first', 'b_last', 'b_addr', 'b_addr2', 'b_city', 'b_state', 'b_zip', 'b_phone', 'b_fax', 'b_email'); // array for holding form elements names
  cc.values = new Array(); // array for holding values
  cc.interval = false; // explicitly define, that no timer is set
  cc.timer = 1000; // how often autosave (1000 == 1 sec)
  
  // function loads data from cookie
  cc.load = function () {
    for (x in this.fields) {
      this.values[this.fields[x]] = getCookie(this.form+'_'+x);
      if (this.values[this.fields[x]] == null || this.values[this.fields[x]] == 'null') {
        this.values[this.fields[x]] = '';
      }
      document.forms[this.form][this.fields[x]].value = this.values[this.fields[x]];
    }
  }
  
  // function saves data to cookie
  cc.save = function () {
    for (x in this.fields) {
      setCookie(this.form+'_'+x, document.forms[this.form][this.fields[x]].value, now);
    }
  }
  
  // function deletes cookie
  cc.clear = function () {
    for (x in this.fields) {
      deleteCookie(this.form+'_'+x);
    }
  }

  // function starts timer
  cc.start = function () {
    if (!this.interval)
      this.interval = setInterval('cc.save()', this.timer); 
  }
  
  // function stops timer
  cc.stop = function () {
    clearInterval(this.interval); 
    interval = false;
  }
//AutoTab
var isNN = ( navigator.appName.indexOf( "Netscape" ) != -1 ); 
 
function autoTab( input,len, e ) { 
	var keyCode	= ( isNN ) ? e.which : e.keyCode; 
	var filter	= ( isNN ) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46]; 
	if( input.value.length >= len && !containsElement( filter, keyCode )) { 
	input.value = input.value.slice( 0, len ); 
	input.form[( getIndex( input ) + 1 ) % input.form.length].focus(); 
	} 
	return true; 
} 
 
function containsElement( arr, ele ) { 
	var found = false, index = 0; 
	while( !found && index < arr.length ) 
	if( arr[index] == ele ) { 
		found = true; 
	} else { 
		index++; 
	} 
	return found; 
} 
 
function getIndex( input ) { 
	var index = -1, i = 0, found = false; 
	while ( i < input.form.length && index == -1 ) 
	if ( input.form[i] == input ) { 
		index = i; 
	} else { 
		i++; 
	} 
	return index; 
} 
