function check_email(e) {
    var ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

    for(var i=0; i < e.length ;i++){
        if(ok.indexOf(e.charAt(i))<0){
            return (false);
        }
    }

    if (document.images) {
        var re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
        var re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
        if (!e.match(re) && e.match(re_two)) {
            return (-1);
        }
    }
}

function checkFirstName(){
    if ($("user.firstName").value == "")
        return false;

    return true;
}

function checkLastName(){
    if ($F("user.lastName").strip() == "")
        return false;

    return true;
}

function checkUserId(){
    if (($F("account.userID").strip() == "") || ($F("account.userID").length < 3))
        return false;
        
    return true;        
}

function checkUserIdForgot(){
    if (($F("account.userID").strip() == "") || ($F("account.userID").length < 3))
        return false;
    
    return true;
}

function checkAddress(){
    if (($F("user.address1").strip() == "") || ($F("user.address1").length < 3))
        return false;
        
    return true;
}

function checkCity(){
    if (($F("user.city").strip() == "") || ($F("user.city").length < 3))
        return false;

    return true;
}


function checkState(){
    if ($F("user.state").strip() == "")
        return false;

    return true;
}
function checkProvince(){
    if ($F("province").strip() == "")
        return false;

    return true;
}

function checkZipCode(){
    if ($F("user.zipCode").strip() == "")
        return false;
    
    return true;
}

function checkEmail(){
	if (($F("user.mail").strip() == "") || (!check_email($F("user.mail"))))
         return false;
    
    return true;
}

function checkPaypalUser(){
 	if (($F("user.paypalUser").strip() == "") || (!check_email($F("user.paypalUser"))))    
        return false;
    
	return true;
}

function checkPaypalUserConfirm(){
    $("user.paypalUser").value = $F("user.paypalUser").toLowerCase();
    $("user.paypalUserConfirm").value = $F("user.paypalUserConfirm").toLowerCase();
	if (($F("user.paypalUser") == $F("user.paypalUserConfirm")))
        return true;
    
    return false;
}

function checkConfirmEmail(){
    if ($('originalEmailAddress') != null && $F('originalEmailAddress').toLowerCase() == $F('user.mail').toLowerCase())
        return true;

    if (($F("email2Value").strip() == "") || ($F("email2Value").length < 3) || ($F("email2Value").toLowerCase() != $F("user.mail").toLowerCase()))
        return false;

    return true;
}

function checkPassword(){
    if (($F("account.password").strip() == "") || ($F("account.password").length < 6)||($F("account.password").length > 16))
        return false;
    
    return true;
}

function checkConfirmPassword(){
	var password2Value;
	
	if ($("account.password2Value"))
		password2Value = $F("account.password2Value");
	else if ($F("password2Value"))
		password2Value = $F("password2Value");
		
    if ((password2Value == "") || (password2Value.toLowerCase() != $F("account.password").toLowerCase()))
        return false;
   
    return true;
}

function checkSecurityQ(){
    if($F("question").strip() == "")
        return false;
    
	return true;
}

function checkAnswer(){
    if($F("answer").strip() == "")
        return false;
    
    return true;
}

function checkAnswerResponse(){
	var _maxLenghtAnswer = 26;
	
    switch($F("question")){
        case "What are the last 5 digits of your Social Security number?":  {
            if ( ($F("answer").length!=5) || (isNaN($F("answer"))) ){
                displayMessage("The answer to this question must be 5 numeric characters.");
                return false;
            }
            return true;
            break;
        }
        default: {
            if ($F("answer").length > _maxLenghtAnswer) {
                displayMessage("The answer to this question must be fewer than 26 characters long.");
                return false;
            }
            return true;
            break;
        }
    }
}


function checkAccountType() {
    if ($F("accounttypeRBW") == "")
        return false;
    
    return true;
}

function checkCreditCard() {
    if ($F("idCreditCard") == "")
        return false;
    
    $('user.creditCard').value = $('idCreditCard').options[$('idCreditCard').value-2].text;
    return true;
}

function checkSecurityCode() {
	if ($F('securityCode') == "" || isNaN($F('securityCode')))
		return false;
		
	return true;
}

function checkCreditCardNum(){
    if (($F("user.creditCardNumber") == "") || isNaN(($F("user.creditCardNumber"))))
        return false;
    
    if (((($F("user.creditCard") == "MasterCard") || $F("user.creditCard") == "Visa")) && ($F("user.creditCardNumber").length != 16))
        return false;
    
    if ($F("user.creditCard") == "MasterCard"){
    	var num = $F("user.creditCardNumber");
        return num.startsWith("5");
    }
    
    if ($F("user.creditCard") == "Visa"){
        var num = $F("user.creditCardNumber");
        return num.startsWith("4");                
    }
    
    return true;
}

function checkCreditCardId(){
    if (($F("user.creditCardId") == "") || isNaN(($F("user.creditCardId"))))
        return false;

    return true;
}

function checkPhone(phone){
    phone=phone.replace(/\(/gi,'');
    phone=phone.replace(/\)/gi,'');
    phone=phone.replace(/-/gi,'');
    phone=phone.replace(/\./gi,'');
    phone=phone.replace(/\ /gi,'');
    phone=phone.replace(/\+/gi,'');
    phone=phone.replace(/\*/gi,'');
    phone=phone.replace(/\#/gi,'');
	if ( (phone=="") || (phone.length<1) || isNaN(phone) ) 
		return false;
	
	return true;
}

function checkPaymentOption(){
    if ((!$("chkBSCreditCardValue").checked) && (!$("chkBSBankAccountValue").checked))
        return false;
    
    return true;
}

function checkBankName(){
    if ($F("user.bankName") == "")
        return false;
    
    return true;
}

function checkBankRouting(){
    if (($F("user.bankRouting") == "") || (isNaN($F("user.bankRouting"))))
        return false;
    
    return true;
}

function checkConfirmBankRouting(){
    return !($F("bankRoutingConfirm") != $F("user.bankRouting"));
}

function checkBankAccount(){
    if (($F("user.bankAccount") == "") || (isNaN($F("user.bankAccount"))))
        return false;
    
    return true;
}

function checkConfirmBankAccount(){
    return !($F("accountConfirm") != $F("user.bankAccount"));
}

function checkExpDate(){
    var d = new Date();
    var m = d.getMonth();
    var y = d.getFullYear();
	
	if ($('expYear').options[$('expYear').value].text < y)
        return false;
    	
    if ($('expYear').options[$('expYear').value].text == y)
        if($('expMonth').options[$('expMonth').value-1].text < m)
            return false;
    
	$('expDate1').value = $('expMonth').options[$('expMonth').value-1].text;
    $('expDate2').value = $('expYear').options[$('expYear').value].text;
    
    return true;
}

function check_name(country) {
    var ok = "qwertyuiopasdfghjklñzxcvbnm.QWERTYUIOPASDFGHJKLZXCVBNM'áéíóúÁÉÍÓÚäëïöüÄËÏÖÜàèìòù";

    for (var i=0; i < country.length ;i++)
        if (ok.indexOf(country.charAt(i))<0)
            return false;
    
    return true;
     
}
function check_question_name(country) {
    var ok = "qwertyuiopasdfghjklñzxcvbnm.QWERTYUIOPASDFGHJKLZXCVBNM'áéíóúÁÉÍÓÚäëïöüÄËÏÖÜàèìòù?¿";

    for(var i=0; i < country.length ;i++){
        if(ok.indexOf(country.charAt(i))<0){
            return (false);
        }
    }
    return(true);
}