function displayInvoicing(){
    if ($('isinvoice').checked) {
        $('newAccount3').style.display = '';
    } else {
        $('newAccount3').style.display = 'none'; 
    }
}

function checkCreateAccount(){
    var isOk = true;

    $('btnSave').className = 'btnOff';
    $('btnSave').disabled = true;

    /* CHECKING FORM FROM BOTTOM TO TOP */
    /* 1. If invoicing address then check the City, place and street */
    if ($('isinvoice').checked) {
        if ($('icity').value.length < 2) {isOk = false;showError('icity');$('icity').focus()} else {hideError('icity');}
        if ($('izipcode').value.length < 4) {isOk = false;showError('izipcode');$('izipcode').focus()} else {hideError('izipcode');}
        if ($('istreet1').value.length < 5) {isOk = false;showError('istreet1');$('istreet1').focus()} else {hideError('istreet1');}
        if ($('icompany').value.length < 2) {isOk = false;showError('icompany');$('icompany').focus()} else {hideError('icompany');}
    }
    /* 2. Delivery address then check the City, place and street */
    if ($('dcity').value.length < 2) {isOk = false;showError('dcity');$('dcity').focus()} else {hideError('dcity');}
    if ($('dzipcode').value.length < 4) {isOk = false;showError('dzipcode');$('dzipcode').focus()} else {hideError('dzipcode');}
    if ($('dstreet1').value.length < 5) {isOk = false;showError('dstreet1');$('dstreet1').focus()} else {hideError('dstreet1');}
    if ($('dcompany').value.length < 2) {isOk = false;showError('dcompany');$('dcompany').focus()} else {hideError('dcompany');}

    /* 3. User information */
    if ($('phone').value.length < 10) {isOk = false;showError('phone');$('phone').focus()} else {hideError('phone')}
    if (checkPassword($('password').value) == false) {
        isOk = false;
        showError('password');
        $('password').focus();
    } else {
        hideError('password');
        if ($('passwordconfirm').value !== $('password').value) {
            isOk = false;
            showError('passwordconfirm');
            $('passwordconfirm').focus();
        } else {
            hideError('passwordconfirm');
        }
    } 
    if ($('username').value.length < 7 || !(checkEMail($('username').value))) {isOk = false;showError('username');$('username').focus()} else {hideError('username');}
    
    if ($('customernumber').value.length > 0 && $('customernumber').value.length != 6) {
        isOk = false;
        showError('customernumber');
        $('customernumber').focus();

    } else {
        hideError('customernumber');
    }
    if ($('firstname').value.length < 2) {isOk = false;showError('firstname');$('firstname').focus()} else {hideError('firstname');}
    if ($('lastname').value.length < 2) {isOk = false;showError('lastname');$('lastname').focus()} else {hideError('lastname');}

    if (!(isOk)) {
        $('btnSave').className = 'btnOon';
        $('btnSave').disabled = false;
    }
    return isOk;

}


function addCartSimple(pNo, pRef){
    var spid = $('pid-' + pNo).value;
    var sqty = $('qty-' + pNo).value;
    if (pRef) {
        document.location.href = '?pid=' + spid + '&qty=' + sqty + '&action=addCart&ref='+pRef;
    } else {
        document.location.href = '?pid=' + spid + '&qty=' + sqty + '&action=addCart';
    }

}

function deleteItem(pNo){
    var spid = $('pid-' + pNo).value;
    document.location.href = '?pid=' + spid + '&action=deleteProduct';

}

function editQty(){
    $('action').value = 'updateQtyCart';
    $('formCart').submit();
}


function deleteCart(){
    document.location.href = '?action=deleteCart';
}

function orderCart(){
    document.location.href = 'order-identification.asp';
}

var isOnForgot = false;

function forgotInfo(){
    if (!(isOnForgot)) {
        $('login-box').style.display = 'none';
        $('forgot-box').style.display = '';
        $('btnLogin').src='/images/shop/btn_submit_'+language+'.gif';
        $('action').value = 'forgot-check';
    } else {
        $('login-box').style.display = '';
        $('forgot-box').style.display = 'none';
        $('btnLogin').src='/images/shop/btn_login_'+language+'.gif';
        $('action').value = 'login-check';
    }
    isOnForgot = !(isOnForgot);
}

var returningurl = '';

function editDeliveryAddress(aid){
    document.location.href = '/' + language + '/clients/address-edit.asp?action=edit-address-delivery&addressid=' + aid + '&returningurl=' + returningurl  ;
}

function addDeliveryAddress(){
    document.location.href = '/' + language + '/clients/address-edit.asp?action=edit-address-delivery&addressid=0&returningurl=' + returningurl  ;
}

function editInvoicingAddress(aid){
    document.location.href = '/' + language + '/clients/address-edit.asp?action=edit-address-invoicing&addressid=' + aid + '&returningurl=' + returningurl  ;
}

function checkLoginBox(){
    
    var isOk = true;
    
    $('btnLogin').className = 'btnOff';
    $('btnLogin').disabled = true;

    if ($('action').value == 'login-check') {
        if ($('password').value.length < 5) {isOk = false; $('password').focus();$('password').className='loginError';} else {$('password').className='login';}
        if (!(checkEMail($('email').value))) {isOk = false; $('email').focus();$('email').className='loginError';} else {$('email').className='login';}
    } else if ($('action').value == 'forgot-check') {
        if (!(checkEMail($('email_forgot').value))) {isOk = false;$('email_forgot').focus();$('email_forgot').className='loginError';} else {$('email_forgot').className='login';}
    } else {
        isOk = false;
    }
    
    if (!(isOk)) {
        $('btnLogin').className = 'btnOn';
        $('btnLogin').disabled = false;
    }
    return isOk;
}

function processOrder(){
    var isOk = false;
    if ($('chkAccept').checked) {
        isOk = true;
    } else {
        alert('Vous devez accepter les conditions générales de ventes.')
    }
    return isOk;
}



