/**** FUNCIONES JAVASCRIPT PARA TIENDA VIRTUAL ****/

/* ------------------------------------------------------------------------- */
function muestraComp(){
    document.getElementById('comp').style.display = '';
}

/* ------------------------------------------------------------------------- */
function ocultaComp(){
    document.getElementById('comp').style.display = 'none';
    document.getElementById('inputComp').value = '';
}

/* ------------------------------------------------------------------------- */
function compruebaTipoCliente() {
    if (!document.purchaseForm.clientType[1].checked) {
        ocultaComp();
    }
}

/* ------------------------------------------------------------------------- */
function show(id, state) {
    document.getElementById(id).style.display= state ? '' : 'none';
    document.getElementById(id).style.visibility= state ? 'visible' : 'hidden';
}

function setFocus(id) {
    
    document.getElementById(id).focus();
}

/* ------------------------------------------------------------------------- */
function miError(quien){
    
    if(quien == 'invoicingData.address2' || quien == 'shippingData.address2'){
        document.getElementById(quien).style.background="#FBA09B";
    } else {
    document.getElementById(quien).style.background="#FBA09B";
}
setFocus(quien);
}

/* ------------------------------------------------------------------------- */

function countryError(quien, msg) {
    if(msg!='')
        alert(msg);
    document.getElementById(quien).style.background="#FBA09B";
    setFocus(quien);
}

function phoneError(quien, msg) {
    if(msg!='')
        alert(msg);
    document.getElementById(quien).style.background="#FBA09B";
    setFocus(quien);
}

function stateError(code, quien, idCountry, msg) {
    
    
    if (idCountry=="US" || idCountry=="ES" || idCountry=="CA") {
        document.purchaseForm.state_combo.style.background="#FBA09B";
        document.purchaseForm.state_combo.focus();
    }
    else {
        document.purchaseForm.state.style.background="#FBA09B";
        document.purchaseForm.state.focus();
    }
    
    if(code == 'COD_NOT_ALLOWED' || code == 'ONLY_SPAIN')
        alert(msg);
}

/* ------------------------------------------------------------------------- */
function doProperSubmit(){
    if(document.getElementById("check_PP") && document.getElementById("check_PP").checked) {
        document.paypalForm.submit();
    } else {
        document.paymentForm.submit();
    }
}

/* ------------------------------------------------------------------------- */
function checkPaypal(payment) {
    if (payment=="PP") {
        document.getElementById("check_PP").checked;
        document.paymentForm.submit();
    }
}

/* ------------------------------------------------------------------------- */
function checkPaypalCorrectCurrency(alertText, paypalRedirection) {
    alert(alertText);
    window.location=paypalRedirection;
}


/* ------------------------------------------------------------------------- */

function setShippingState(invoicingState, shippingState) {
    if(shippingState==null || shippingState=='') {
        document.purchaseForm.state.value=invoicingState;
    } else {
    document.purchaseForm.state.value=shippingState;
}
}

function showStates(idCountry,ent) {
    
    if (idCountry=="US" || idCountry=="ES" || idCountry=="CA") {
        insertStates(idCountry);
        show('state',false);
        show('state_combo',true);
        copyState(document.purchaseForm.state_combo[document.purchaseForm.state_combo.selectedIndex].text);
    } else {
    show('state',true);
    show('state_combo',false);
    if(ent==1) {
        copyState("");
    }
    
}

}

/* ------------------------------------------------------------------------- */
function insertStates(idCountry) {
    
    var sel = false;
    
    for(var i=0; i < document.purchaseForm.state_combo.length; i++) document.purchaseForm.state_combo.options[i]=null;
    
    if (idCountry=="US") {
        for(var i=0; i < EEUU_states.length; i++){
            if(EEUU_states[i]!=null) {
                var newOption = new Option(EEUU_states[i]);
                document.purchaseForm.state_combo.options[i] = newOption;
                if(document.purchaseForm.state.value!='' && document.purchaseForm.state.value==EEUU_states[i]) {
                    document.purchaseForm.state_combo.selectedIndex=i;
                    sel = true;
                }
            }
        }
    }
    else if (idCountry=="CA") {
        for(var i=0 ; i < Canada_states.length; i++){
            if(Canada_states[i]!=null) {
                var newOption = new Option(Canada_states[i]);
                document.purchaseForm.state_combo.options[i] = newOption;
                if(document.purchaseForm.state.value!='' && document.purchaseForm.state.value==Canada_states[i]) {
                    document.purchaseForm.state_combo.selectedIndex=i;
                    sel = true;
                }
            }
        }
    }
    else if (idCountry=="ES") {
        for(var i=0; i < Spain_states.length; i++){
            if(Spain_states[i]!=null) {
                var newOption = new Option(Spain_states[i]);
                document.purchaseForm.state_combo.options[i] = newOption;
                if(document.purchaseForm.state.value!='' && document.purchaseForm.state.value==Spain_states[i]) {
                    document.purchaseForm.state_combo.selectedIndex=i;
                    sel = true;
                }
            }
        }
    }
    
    if(sel==false) document.purchaseForm.state_combo.selectedIndex=0;
}

/* ------------------------------------------------------------------------- */
function copyState(stateName) {
    document.purchaseForm.state.value=stateName;
}


/* ------------------------------------------------------------------------- */
function compruebaThai(country) {
    if (country=='TH') {
        alert('\u0E40\u0E23\u0E35\u0E22\u0E19\u0E17\u0E48\u0E32\u0E19\u0E1C\u0E39\u0E49\u0E21\u0E35\u0E2D\u0E38\u0E1B\u0E01\u0E32\u0E23\u0E04\u0E38\u0E13\n\u0E17\u0E32\u0E07\u0E1A\u0E23\u0E34\u0E29\u0E31\u0E17\u0E02\u0E2D\u0E41\u0E08\u0E49\u0E07\u0E43\u0E2B\u0E49\u0E17\u0E23\u0E32\u0E1A\u0E27\u0E48\u0E32\u0E02\u0E13\u0E30\u0E19\u0E35\u0E49\u0E40\u0E23\u0E32\u0E44\u0E21\u0E48\u0E2A\u0E32\u0E21\u0E32\u0E23\u0E16\u0E17\u0E33\u0E01\u0E32\u0E23\u0E15\u0E2D\u0E1A\u0E04\u0E33\u0E16\u0E32\u0E21\u0E2B\u0E23\u0E37\u0E2D\u0E15\u0E34\u0E14\u0E15\u0E48\u0E2D\u0E01\u0E31\u0E1A\u0E25\u0E39\u0E01\u0E04\u0E49\u0E32\u0E40\u0E1B\u0E47\u0E19\u0E20\u0E32\u0E29\u0E32\u0E44\u0E17\u0E22\u0E44\u0E14\u0E49\u0E40\u0E19\u0E37\u0E48\u0E2D\u0E07\u0E08\u0E32\u0E01\u0E44\u0E21\u0E48\u0E21\u0E35\u0E40\u0E08\u0E49\u0E32\u0E2B\u0E19\u0E49\u0E32\u0E23\u0E31\u0E1A\u0E1C\u0E34\u0E14\u0E0A\u0E2D\u0E1A\u0E14\u0E49\u0E32\u0E19\u0E20\u0E32\u0E29\u0E32\u0E44\u0E17\u0E22\n\u0E14\u0E31\u0E07\u0E19\u0E31\u0E49\u0E19\u0E40\u0E23\u0E32\u0E08\u0E36\u0E07\u0E02\u0E2D\u0E23\u0E1A\u0E01\u0E27\u0E19\u0E43\u0E2B\u0E49\u0E17\u0E48\u0E32\u0E19\u0E1C\u0E39\u0E49\u0E21\u0E35\u0E2D\u0E38\u0E1B\u0E01\u0E32\u0E23\u0E04\u0E38\u0E13\u0E17\u0E38\u0E01\u0E17\u0E48\u0E32\u0E19\u0E2A\u0E48\u0E07\u0E2D\u0E35\u0E40\u0E21\u0E25\u0E4C\u0E2B\u0E23\u0E37\u0E2D\u0E15\u0E34\u0E14\u0E15\u0E48\u0E2D\u0E01\u0E31\u0E1A\u0E40\u0E23\u0E32\u0E40\u0E1B\u0E47\u0E19\u0E20\u0E32\u0E29\u0E32\u0E2D\u0E31\u0E07\u0E01\u0E24\u0E29\u0E19\u0E31\u0E1A\u0E41\u0E15\u0E48\u0E19\u0E35\u0E49\u0E40\u0E1B\u0E47\u0E19\u0E15\u0E49\u0E19\u0E44\u0E1B\u0E08\u0E19\u0E01\u0E27\u0E48\u0E32\u0E17\u0E32\u0E07\u0E1A\u0E23\u0E34\u0E29\u0E31\u0E17\u0E08\u0E30\u0E2B\u0E32\u0E1C\u0E39\u0E49\u0E23\u0E31\u0E1A\u0E1C\u0E34\u0E14\u0E0A\u0E2D\u0E1A\u0E04\u0E19\u0E43\u0E2B\u0E21\u0E48\u0E44\u0E14\u0E49\n\n\u0E02\u0E2D\u0E2D\u0E20\u0E31\u0E22\u0E43\u0E19\u0E04\u0E27\u0E32\u0E21\u0E44\u0E21\u0E48\u0E2A\u0E30\u0E14\u0E27\u0E01\u0E21\u0E32 \u0E13 \u0E42\u0E2D\u0E01\u0E32\u0E2A\u0E19\u0E35\u0E49\u0E14\u0E49\u0E27\u0E22\n\n\u0E02\u0E2D\u0E41\u0E2A\u0E14\u0E07\u0E04\u0E27\u0E32\u0E21\u0E19\u0E31\u0E1A\u0E16\u0E37\u0E2D');
    }
}
/* ------------------------------------------------------------------------- */

function compruebaSoloDigitos(cadena) {
    for(var i=0; i<cadena.length; i++){
        if(cadena.charCodeAt(i) < 48 || cadena.charCodeAt(i) > 57) return false;
    }
    return true;
}

/* ------------------------------------------------------------------------- */

function checkCountry(msg) {
    /*  var idCountry = document.getElementById("invoicingData.country").value;
    
    if(idCountry=="KW" || idCountry=="AE")
        alert(msg);
    else
        document.purchaseForm.submit();
    */
    document.purchaseForm.submit();
    
}

/* ------------------------------------------------------------------------- */

function current(cual){
    document.getElementById(cual).className = "current";
}

/* ------------------------------------------------------------------------- */



/* PROCESO DE COMPRA */

function showHide(cual){
    if(cual == "ppal"){
        document.getElementById("ppal").style.display           = "block";
        document.getElementById("access").style.display         = "none";
        document.getElementById("submenu_ppal").style.display   = "block";
        document.getElementById("submenu_access").style.display = "none";
    }else{
    document.getElementById("access").style.display         = "block";
    document.getElementById("ppal").style.display           = "none";
    document.getElementById("submenu_ppal").style.display   = "none";
    document.getElementById("submenu_access").style.display = "block";
}
}

function ir(voy){
    if (valida()) document.location = voy;
}

function submitValidado(){
    document.productos.submit();
}


