var Mw = window.screen.width;
var Mh = window.screen.height;

function muda(field){
    if (field.value != "PT"){
        document.getElementById('hww').style.display = 'block';
        document.getElementById('hpt').style.display = 'none';
        document.getElementById('hc').style.display = 'none';
        document.getElementById('c').style.display = 'none'; // RC

        for (var i=0; i < document.hww.pais.length; i++) {
            if (document.hww.pais[i].value == field.value) {
            document.hww.pais[i].selected = true;
            }
        }
    }
    if (field.value == "PT"){
        document.getElementById('hpt').style.display = 'block';
        document.getElementById('hww').style.display = 'none';

        for (var i=0; i < document.hpt.pais.length; i++) {
            if (document.hpt.pais[i].value == "PT") {
            document.hpt.pais[i].selected = true;
            }
        }
    }
}

function change(field){
    if (field == "hotel"){
        for (var i=0; i < document.hpt.pais.length; i++) {
            if (document.hpt.pais[i].value == "PT") {
            document.hpt.pais[i].selected = true;
            }
        }
        document.getElementById('c').style.display = 'none'; // RC
        document.getElementById('mcar').className = ''; // hotel main

        document.getElementById('hpt').style.display = 'block'; // hotel main
        document.getElementById('mhotel').className = 'labelm'; // hotel main

        document.getElementById('hc').style.display = 'none'; // hotel + RC
        document.getElementById('mhotelcar').className = ''; // hotel main
        document.getElementById('hww').style.display = 'none'; // hotel ww

    }
    else if (field == "hotelcar"){
        document.getElementById('c').style.display = 'none'; // RC
        document.getElementById('mcar').className = ''; // RC

        document.getElementById('hc').style.display = 'block'; // hotel + RC
        document.getElementById('mhotelcar').className = 'labeld'; // hotel + RC

        document.getElementById('hpt').style.display = 'none'; // hotel main
        document.getElementById('mhotel').className = ''; // hotel main
        document.getElementById('hww').style.display = 'none'; // hotel ww
    }
    else if (field == "car"){
        document.getElementById('hpt').style.display = 'none'; // hotel main
        document.getElementById('mhotel').className = ''; // hotel main

        document.getElementById('c').style.display = 'block'; // RC
        document.getElementById('mcar').className = 'labeld'; // hotel main

        document.getElementById('hc').style.display = 'none'; // hotel + RC
        document.getElementById('mhotelcar').className = ''; // hotel + RC
        document.getElementById('hww').style.display = 'none'; // hotel ww
    }
}

function addElement(qts, div){
var qtd = '';

if (qts != 0 && qts != 1 && qts != 2 && qts != 3 && qts != 4 && qts != 5 && qts != 6){
    if (qts == 's14'){
    var qtss = document.hww.s14.options[document.hww.s14.selectedIndex].value;
    if (qtss == 0){ qtd = 0; } else {  qtd = 1; }
    }
    else if (qts == 's15'){
    var qtss = document.hww.s15.options[document.hww.s15.selectedIndex].value;
    if (qtss == 0){ qtd = 0; } else {  qtd = 2; }
    }
}
else {
qtd = qts;
}
//alert(qtd);

    var value = 'theValue'+div;
    var ni = document.getElementById(div);
    var numi = document.getElementById(value);
    var num = document.getElementById(value).value;
    if (document.getElementById('my0Div'+div) != null){
    removeElement('my0Div'+div, div);
    }
    else {
    }

    numi.value = num; // set theValue
    var divIdName = "my0Div"+div;
    var newdiv = document.createElement('div');
    newdiv.setAttribute("id",divIdName);

    var inputs = '';

    for(var i=0;i<qtd;i++){
    inputs += '<input type=\"text\" name=\"idades[]\" value=\"\" size=\"1\" maxlength=\"2\" \/>';
    }

    newdiv.innerHTML = inputs;
    ni.appendChild(newdiv);

}

function removeElement(divNum, div){
    var d = document.getElementById(div);
    var olddiv = document.getElementById(divNum);
    d.removeChild(olddiv);
}


function validhpt(f, txt){

var error = 0;
    for (var i=0; i < f.elements.length; i++) {
        if (f.elements[i].name == "idades[]") {
            if (f.elements[i].value == "") {
            error++;
            }
        }
    }

//    if (f.localid.value == ""){
//    txt = 'Deve seleccionar a localidade do menu';
//    error++;
//    }

    if (error == 0){
    load();
    return true;
    }
    else {
    alert(txt);
    return false;
    }

}

function load() {
document.getElementById('loading').style.display = 'block';
document.getElementById('container').style.display = 'none';
}

function rooms(hotel, quarto, lang){
return window.open('pops/quarto.php?lang='+ lang +'&avidata='+ hotel+'&room='+ quarto, 'pop','width=450,height=400,top='+(Mh/2-55)+', left='+(Mw/2-275)+', toolbar=no,location=no,directories=no,status=no, menubar=no,scrollbars=yes,resizable=no') ;
}

function cardetails(lang){
    var urlcarro = document.c.carro.options[document.c.carro.selectedIndex].value;
    return window.open('pops/carro.php?lang='+ lang +'&carro='+ urlcarro, 'pop','width=450,height=290,top='+(Mh/2-55)+', left='+(Mw/2-275)+', toolbar=no,location=no,directories=no,status=no, menubar=no,scrollbars=no,resizable=no') ;
}

function paxCheck(qts, who, lang){
    if ((who == 'pax' && qts == 6) || (who == 'gf' && qts == 10)){
    window.location = "http://www.portimar.pt/pedido.php?lang=" + lang;
    }
}

function janela(url, w, h, yn){
return window.open(url, 'pop','width='+w+',height='+h+',top='+(Mh/2-55)+', left='+(Mw/2-275)+', toolbar=no,location=no,directories=no,status=no, menubar=no,scrollbars=yes,resizable='+yn) ;
}
