

function validateCreditCard(billingName,billingAddress,billingCity,billingStIndex,billingZipcode,billingCountry, CreditCardType,expMonthIndex,expYearIndex,cardNumber,cvvNumber) {

    var msg="";

        if(billingName.length==0 || checkLen(billingName, 4))
            msg+="Name on credit card is required and must contain at least 4 characters.\n";

        if(billingAddress.length==0 || checkLen(billingAddress, 5))
            msg+="Billing address is required and must contain at least 5 characters\n";

        if(billingCity.length==0 || checkLen(billingCity, 3))
            msg+="Billing city is required and must contain at least 3 characters\n";
			

       if(billingStIndex==0)
         msg+="Billing state is required. Please select it from the dropdown list\n";

        if(billingZipcode.length==0 || checkLen(billingZipcode, 1))
            msg+="Billing zip code is required and must contain at least 1 character\n";
    if(CreditCardType.selectedIndex==0)
        msg+="Credit card type is required. Please select it from the dropdown list\n";
	

    if(expMonthIndex==0)
        msg+="Expiration month is required. Please select it from the dropdown list\n";
		

    if(expYearIndex==0)
        msg+="Expiration year is required. Please select it from the dropdown list\n";

	if(cvvNumber.length==0 || checkLen(cvvNumber, 3) || !isNumber(cvvNumber))
            msg+="CVV/CVC is required and should not have spaces or dashes\n";
						
	if(checkLen(cvvNumber, 3) && CreditCardType.options[CreditCardType.selectedIndex].value.indexOf("AMEX") == -1 && CreditCardType.selectedIndex != 0)
            msg+="CVV/CVC number should be 3 numbers in length for this credit card type\n";
						
	if(checkLen(cvvNumber, 4) && CreditCardType.options[CreditCardType.selectedIndex].value.indexOf("AMEX") > -1 && CreditCardType.selectedIndex != 0)
            msg+="CVV/CVC number should be 4 numbers in length for this credit card type\n";
            
    if(cardNumber.length==0 || checkLen(cardNumber, 10) ||!isNumber(cardNumber))
            msg+="Credit card number is required and should not have spaces or dashes\n";

    if(!msg) {
        document.thisForm.Pay.disabled=true;
        document.thisForm.submit();
	/*var anchors = document.anchors;
	for(var i = 0;i < anchors.length;i++)
	{
	 var anchor = anchors.item(i);
	 if(anchor.name == "Pay")
	   anchor.href = "#";
        } */

    } else {
        alert(msg);
    }



}


function validateACH(billingName,abaRoutingNumber,bankAccountNumber,accountTypeIndex,billingAddress,billingCity,billingStIndex,billingZipcode,billingCountry) {

   var msg="";
   
        if(billingName.length==0 || checkLen(billingName, 3))
            msg+="Name on Bank Account is required.\n";

        if(abaRoutingNumber.length==0 || checkLen(abaRoutingNumber, 9) || !isNumber(abaRoutingNumber))
            msg+="ABA Routing Number is required and must contain 9 numeric digits\n";

        if(bankAccountNumber.length==0 || checkLen(bankAccountNumber, 1) || !isNumber(bankAccountNumber))
            msg+="Bank Account Number is required and must contain at least 1 numeric digit\n";

   if(accountTypeIndex==0)  {
        msg+= "Please, Select Bank Account Type\n";
    }
    
        if(billingAddress.length==0 || checkLen(billingAddress, 5))
            msg+="Billing address is required and must contain at least 5 characters\n";

        if(billingCity.length==0 || checkLen(billingCity, 3))
            msg+="Billing city is required and must contain at least 3 characters\n";
			

       if(billingStIndex==0)
         msg+="Billing state is required. Please select it from the dropdown list\n";

		if(billingZipcode.length==0 || checkLen(billingZipcode, 1))	
            msg+="Billing zip code is required and must contain at least 1 character\n";    

    if(!msg) {
        document.thisForm.Pay.disabled=true;
        document.thisForm.submit();
	/*var anchors = document.anchors;
	for(var i = 0;i < anchors.length;i++)
	{
	 var anchor = anchors.item(i);
	 if(anchor.name == "Pay")
	   anchor.href = "#";
     } */

    } else {
        alert(msg);
    }




}

function validateCreditCardESP(billingName,billingAddress,billingCity,billingStIndex,billingZipcode,billingCountry, CreditCardType,expMonthIndex,expYearIndex,cardNumber,cvvNumber) {

    var msg="";

        if(billingName.length==0 || checkLen(billingName, 4))
            msg+="El nombre para facturacion debe tener mas de tres letras.\n";

        if(billingAddress.length==0 || checkLen(billingAddress, 5))
            msg+="Se requiere un Proveedor para facturacion.\n";

        if(billingCity.length==0 || checkLen(billingCity, 3))
            msg+="La ciudad para facturacion debe tener mas de dos letras.\n";
			

       if(billingStIndex==0)
         msg+="Esatado de facturacion es requerido.\n";

        if(billingZipcode.length==0 || checkLen(billingZipcode, 5) || !isNumber(billingZipcode))
            msg+="El Codigo postal del domicilio de facturacion no es valido.\n";
    if(CreditCardType.selectedIndex==0)
        msg+="Se requiere el tipo de tarjeta de crédito.\n";
	

    if(expMonthIndex==0)
        msg+="Se requiere el mes de la fecha de vencimiento de la tarjeta de credito.\n";
		

    if(expYearIndex==0)
        msg+="Se requiere el año de la fecha de vencimiento de la tarjeta de credito.\n";

	if(cvvNumber.length==0 || checkLen(cvvNumber, 3) || !isNumber(cvvNumber))
            msg+="Se requiere el número de CVV/CVC y no debe contener espacios.\n";
						
	if(checkLen(cvvNumber, 3) && CreditCardType.options[CreditCardType.selectedIndex].value.indexOf("AMEX") == -1 && CreditCardType.selectedIndex != 0)
            msg+="El numero de CVV/CVC debe estar 3 dígitos en longitud para este tipo de tarjeta de crédito.\n";
						
	if(checkLen(cvvNumber, 4) && CreditCardType.options[CreditCardType.selectedIndex].value.indexOf("AMEX") > -1 && CreditCardType.selectedIndex != 0)
            msg+="El numero de CVV/CVC debe estar 4 dígitos en longitud para este tipo de tarjeta de crédito.\n";
    
    
        if(cardNumber.length==0 || checkLen(cardNumber, 10) ||!isNumber(cardNumber))
            msg+="El numero de la tarjeta de credito no es valido.\n";

    if(!msg) {
        document.thisForm.submit();
	var anchors = document.anchors;
	for(var i = 0;i < anchors.length;i++)
	{
	 var anchor = anchors.item(i);
	 if(anchor.name == "Pay")
	   anchor.href = "#";
        }

    } else {
        alert(msg);
    }



}

function checkLen(s,length)
{
	if(s == null || s.length < length)
		return true;
	return false;
}

function isNumber(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
       
        var c = s.charAt(i);
        if (((c < "0") || (c > "9")))
         return false;
    }
   
    return true;
}


