//**********************************************************************
//                             StaticCart                              *
// JavaScript Validate Checkout Module (Basic)       Copyright 2004-06 *
//                                                                     *
//**********************************************************************
//                                                                     *
// None of this script may be redistributed or sold without the        *
// authors express consent. Violations of this copyright will be       *
// prosecuted.  If you would like to use StaticCart, email us at       *
// carl@staticcart.com or visit http://www.staticcart.com              *
//                                                                     *
//**********************************************************************

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
//Validate the Select
function hasSelection(strFieldName,strMsg)     {
    var objFormField = document.forms[0].elements[strFieldName];
    if(objFormField.selectedIndex == 0)     {
         strAlertMsg += "- "+ strMsg +" is Required.\n";
          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 (theForm.b_state2.value == "") {
    if (!validRequired(theForm.b_state," Customer Information: State"))
         return false;
//    }

    if (!validRequired(theForm.b_zip," Customer Information: ZipCode"))
         return false;

//    if (!validRequired(theForm.b_country," Customer Information: Country"))
//         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++;


var database = GetCookie('GiftCoupon');
if ( database == null ){
      cTV = "Z0";
	PubName  = "";
	cCode  =  "";
	Redeemed = "";
}else{
	couponData = database.split("|");
	cTV = (couponData[0]);
	PubName  = (couponData[1]);
	cCode  =  (couponData[2]);
	Redeemed =  (couponData[3]);
}
Redeemed++;

document.checkout.cTV.value = cTV; 
document.checkout.PubName.value = PubName; 
document.checkout.cCode.value = cCode; 
document.checkout.Redeemed.value = Redeemed; 

 


document.checkout.b_first.value = document.orderform.b_first.value; 
document.checkout.b_last.value  = document.orderform.b_last.value;
document.checkout.b_name.value  = (document.orderform.b_first.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_address.value  =  (document.orderform.b_addr.value+' '+document.orderform.b_addr2.value+' '+document.orderform.b_city.value+' '+document.orderform.b_state.value+' '+document.orderform.b_zip.value); 
document.checkout.b_city.value  = document.orderform.b_city.value; 
document.checkout.b_state.value = document.orderform.b_state.value;
//document.checkout.b_state2.value = document.orderform.b_state2.value;
document.checkout.b_zip.value   = document.orderform.b_zip.value; 
document.checkout.b_country.value = document.orderform.b_country.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.s_first.value = document.orderform.s_first.value; 
document.checkout.s_last.value  = document.orderform.s_last.value;
document.checkout.s_addr.value  = document.orderform.s_addr.value; 
document.checkout.s_addr2.value = document.orderform.s_addr2.value;
document.checkout.s_address.value  = (document.orderform.s_addr.value+' '+document.orderform.s_addr2.value+' '+document.orderform.s_city.value+' '+document.orderform.s_state.value+' '+document.orderform.s_zip.value); 
document.checkout.s_city.value  = document.orderform.s_city.value; 
document.checkout.s_state.value = document.orderform.s_state.value;
//document.checkout.s_state2.value = document.orderform.b_state2.value;
document.checkout.s_zip.value   = document.orderform.s_zip.value; 
document.checkout.s_country.value = document.orderform.s_country.value;
document.checkout.s_phone.value = document.orderform.s_phone.value;
document.checkout.s_fax.value   = document.orderform.s_fax.value; 
document.checkout.s_email.value = document.orderform.s_email.value; 


document.checkout.comment.value = document.orderform.comment.value;

document.checkout.cctype.value = document.orderform.CardName.value;
document.checkout.ccnum1.value   = document.orderform.CardNumber1.value; 
document.checkout.ccnum2.value   = document.orderform.CardNumber2.value; 
document.checkout.ccnum3.value   = document.orderform.CardNumber3.value; 
document.checkout.ccnum4.value   = document.orderform.CardNumber4.value; 
document.checkout.cardnumber.value   = (document.orderform.CardNumber1.value+document.orderform.CardNumber2.value+document.orderform.CardNumber3.value+document.orderform.CardNumber4.value); 
document.checkout.expdate.value   = (document.orderform.ExpMon.value+document.orderform.ExpYear.value);
document.checkout.ccexpmon.value = document.orderform.ExpMon.value; 
document.checkout.ccexpyear.value = document.orderform.ExpYear.value;
document.checkout.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; 
} 







//----------------------------UPS-------------------------------//



function validateFormCK1(theForm)

{

    // Active the checks for the required fields and radio buttons

    // Start ------->
    if (!validRequired(theForm.c_first," Contact Information: First Name"))
         return false;

    if (!validRequired(theForm.c_last," Contact Information: Last Name"))
         return false;

    if (!validRequired(theForm.c_phone," Contact Information: Phone"))   
         return false;
 
    if (!validRequired(theForm.c_email," Contact Information: E-mail"))   
         return false;
 
    if (!validRequired(theForm.s_addr," Shipping Information: Address"))
         return false;

    if (!validRequired(theForm.s_city," Shipping Information: City"))
         return false;

    //if (theForm.s_state2.value == "") {
    if (!validRequired(theForm.s_state," Shipping Information: State"))
         return false;
    // }

    if (!validRequired(theForm.dest_zip," Shipping Information: ZipCode"))
         return false;



}

//  End -->


//=====================================================================||
//                    END Validate Checkout Module                     ||
//=====================================================================||
