

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 (!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 -->



//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; 
} 
