function compruebaf4(telefono,email,form){
       var tel = telefono.value;
       var em = email.value;
       if(tel != null && tel != "" )
           form.submit();
       else
           if(em != null && em != "")
               form.submit();
           else
               alert("Debe introducir al menos una referencia de contacto:\n\t - Telefono\n\t - E-mail");
    }
function actualizaImporteTotal(idOferta,idAlojamiento,temporada){
    var iT;
    var eleImporteTotal = document.getElementById('importeParcialOriginal'+idAlojamiento+temporada);
    var tipoOferta = document.getElementById("tipoOferta"+idOferta).value;
    var valor;
    if(tipoOferta == "descuento"){
        valor = parseInt(document.getElementById("valor"+idOferta).value,10);
        iT = parseInt(eleImporteTotal.value,10);
        iT = (iT * valor)/100;
        document.getElementById('importeParcial'+idAlojamiento+temporada).value = eleImporteTotal.value - iT;
        document.getElementById('IATT'+idAlojamiento+temporada).style.visibility = "visible";
    }
    if(tipoOferta == "diasregalo"){
        iT = parseInt(eleImporteTotal.value,10);
        var diasRegalo = parseInt(document.getElementById('numDiasRegalo'+idOferta).value,10);
        var totalDias = parseInt(document.getElementById('numTotalDias'+idOferta).value,10);
        iT = (iT / totalDias)*(totalDias - diasRegalo);
        document.getElementById('importeParcial'+idAlojamiento+temporada).value = iT;
        document.getElementById('IATT'+idAlojamiento+temporada).style.visibility = "visible";
    }
    if(tipoOferta == "precio"){
        valor = parseInt(document.getElementById("valor"+idOferta).value,10);
        document.getElementById('importeParcial'+idAlojamiento+temporada).value = valor;
        document.getElementById('IATT'+idAlojamiento+temporada).style.visibility = "visible";
    }
    if( (tipoOferta == "regalo") || (tipoOferta == "descriptiva") ){
        document.getElementById('importeParcial'+idAlojamiento+temporada).value = document.getElementById('importeParcialOriginal'+idAlojamiento+temporada).value;
    }
    actulizaImporte();
}

function actulizaImporte(){
    var numAloj = alojamientos.length;
    var c;
    var total=0;
    for(c=0;c<numAloj;c++){
        total += parseFloat(document.getElementById('importeParcial'+alojamientos[c]).value);
    }
    //document.getElementById('importeTotal').value = redondeo2decimales(total);

    //var importe = redondeo2decimales(document.getElementById('importeTotal').value);
    //var ivaR = redondeo2decimales(importe * 0.08);
    var importe = redondeo2decimales(total);
    var totalR = redondeo2decimales(importe);
    //document.getElementById('ivaR').value = ivaR;
    document.getElementById('totalR').value = totalR;
}

function redondeo2decimales(numero)
{
	var original=parseFloat(numero);
	var result=Math.round(original*100)/100 ;
	return result;
}


/*function compruebaF2(){
        var errores = false;
        var numTs = document.getElementById('nT').value;
        var formu = document.getElementById('FR2');
        var ocupacionTotal = document.getElementById('numPer').value;
        var ocupacionNinos = document.getElementById('numNin').value;
        var ocupacionAdultos = document.getElementById('numAdul').value;
        //var cuevas = document.formReservas2.elements['cueva[]'];
        var ocupacionSelect;*/
        /*var supletorias;*/
        /*var numA;
        if(numTs > 1){*/
           /* supletorias = document.formReservas2.elements['supletorias[]'];*/
          /*  ocupacionSelect = document.formReservas2.elements['numApartamentosTipo[]'];
            numA = ocupacionSelect.length;
        }else{
            ocupacionSelect = document.formReservas2.elements['numApartamentosTipo'];
        }*/
        //var capacidades = document.formReservas2.elements['capacidad[]'];
        //var numA = cuevas.length;
        
        //alert(numA);
        //var c;
       // var ele;
        //var ocupacion = 0;
        //var ocu;
        
       /* if(numTs > 1){
           for(c=0;c<numA;c++){*/
               /*if(cuevas[c].checked){
                   ele = "ocu"+(cuevas[c].value);
                   ocu = document.getElementById(ele);
                   ocupacion += parseInt(ocu.value);
               }*/
                /*ocupacion += parseInt(ocupacionSelect[c].value,10)*parseInt(capacidades[c].value,10);
                if(parseInt(ocupacionSelect[c].value,10) > 0){
                    ocupacion += parseInt(document.getElementById('sup['+capacidades[c].value+']').value,10);
                }
            }
        }else{
           ocupacion += parseInt(ocupacionSelect.value,10)*parseInt(capacidades.value,10);
           ocupacion += parseInt(document.getElementById('sup['+capacidades.value+']').value,10);*/
            /*if(cuevas.checked){
                ele = "ocu"+(cuevas.value);
                ocu = document.getElementById(ele);
                ocupacion += parseInt(ocu.value);
            }*/
        /*}
       
        //alert(ocupacion);
        if(ocupacionTotal > ocupacion){alert("Las opciones seleccionadas no cubren el numero de personas");errores=true;}
        var suma = parseInt(ocupacionNinos) + parseInt(ocupacionAdultos);
        if(suma > ocupacionTotal){alert("La suma del numero de niņos y adultos es superior al numero de personas seleccionado");errores=true;}
        //if(!errores)alert("OK");
        if(!errores)formu.submit();

    }*/


function compruebaF2(){
        var errores = false;
        var formu = document.getElementById('FR2');
        var ocupacionTotal = document.getElementById('numPer').value;
        var ocupacionNinos = document.getElementById('numNin').value;
        var ocupacionAdultos = document.getElementById('numAdul').value;
        var cuevas = document.formReservas2.elements['cueva[]'];
        var numA = cuevas.length;
        var c;
        var ele;
        var ocupacion = 0;
        var ocu;
        if(numA != null){
            for(c=0;c<numA;c++){
               if(cuevas[c].checked){
                   ele = "ocu"+(cuevas[c].value);
                   ocu = document.getElementById(ele);
                   ocupacion += parseInt(ocu.value,10);
                   ele = "sup["+(cuevas[c].value)+"]";
                   ocu = document.getElementById(ele);
                   ocupacion += parseInt(ocu.value,10);
               }
            }
        }else{
            if(cuevas.checked){
                ele = "ocu"+(cuevas.value);
                ocu = document.getElementById(ele);
                ocupacion += parseInt(ocu.value,10);
                ele = "sup["+(cuevas.value)+"]";
                ocu = document.getElementById(ele);
                ocupacion += parseInt(ocu.value,10);
            }
        }
        //alert(ocupacion);
        if(ocupacionTotal > ocupacion){alert("Las opciones seleccionadas no cubren el numero de personas");errores=true;}
        var suma = parseInt(ocupacionNinos) + parseInt(ocupacionAdultos);
        if(suma > ocupacionTotal){alert("La suma del numero de niņos y adultos es superior al numero de personas seleccionado");errores=true;}
        if(!errores)formu.submit();

    }
    function tieneValor(id){
        var tiene = false;
        var ele = document.getElementById(id);
        if(ele.value == "" || ele.value == null){
            tiene = true;
            alert("Valor nulo no permitido para el campo: "+ele.name)
        }
        return tiene;
    }

    function esEntero(id){
        var entero = true;
        var ele = document.getElementById(id);
        if(isNaN(parseInt(ele.value))){
            entero = false;
            alert("Valor no numerico para el campo: "+ele.name)
        }
        return entero;
    }
    function submita(id){
        var formu = document.getElementById(id);
        formu.submit();
    }
    function esMayor(id_dS,id_dE){
        var mayor;
        var dS = document.getElementById(id_dS);
        var fSalida = dS.value;
        var diaS = fSalida.substring(0,2);
        var mesS = fSalida.substring(3,5);
        var anoS = fSalida.substring(6,10);
        var totalFS = parseInt(diaS,10) + (parseInt(mesS,10) * 30) + (parseInt(anoS,10) * 365);
        var dE = document.getElementById(id_dE);
        var fEntrada = dE.value;
        var diaE = fEntrada.substring(0,2);
        var mesE = fEntrada.substring(3,5);
        var anoE = fEntrada.substring(6,10);
        var totalFE = parseInt(diaE,10) + (parseInt(mesE,10) * 30) + (parseInt(anoE,10) * 365);
        if(totalFS > totalFE)mayor = true;
        else{mayor = false;alert("La fecha de entrada: "+fEntrada+" no puede ser mayor que fecha de salida: "+fSalida);}

        return mayor;
    }
    function compruebaYsubmita(){
        var errores = false;
        errores = tieneValor('dE');
        if(!errores)errores = tieneValor('dS');
        if(!errores)errores = tieneValor('nP');
        if(!errores)errores = !esEntero('nP');
        if(!errores)errores = !esMayor('dS','dE');
        if(!errores)
            submita('formR');
    }

function submitar(id_form){
    var formu = document.getElementById(id_form);
    formu.submit();
}


