$(document).ready(function(){
    df= new Date();

    $("#cres_fecha1").datepicker({
        //dateformat: 'dd/mm/yy',
        onSelect: function(dateText, inst){
            a=$("#cres_fecha1").datepicker( "getDate" );
            f=$("#cres_fecha1").val().split("/");
            b=new Date(f[2],f[1], f[0]);
            b.setTime(b.getTime()+(1000*60*60*24));
            $("#cres_fecha2").datepicker("option","minDate",a);
        },
        firstDay: 1,
        minDate:new Date((1000*60*60*24)+parseInt(df.getTime()))
    });
    $("#cres_fecha2").datepicker({
        //dateformat: 'dd/mm/yy',
        firstDay: 1,
        minDate:new Date((1000*60*60*48)+parseInt(df.getTime()))
    });
    setInterval(hora_local, 1000);

});
function load_habitaciones(){
    $(document).ready(function(){
        $("#habitacionescol2").cycle({
            fx:'fade',
            spped:'fast',
            timeout:0,
            pager:'#conthabitaciones',
            pagerAnchorBuilder:function(idx,slide){
                src=$(slide).find(".itemhimg").attr("src");
                return '<a class="hitemmini" href="#"><img src="'+src.split("w=385&h=307").join("w=142&h=110")+'" /></a>';
            }
        });
        $(".hitemmini").click(function(){
            $(".hitemmini img").fadeTo(450, 0.3, function(){});
            $(".activeSlide img").fadeTo(450, 1, function(){
                fleXenv.fleXcrollMain('shdes1');
                fleXenv.fleXcrollMain('shdes2');
                fleXenv.fleXcrollMain('shdes3');
                fleXenv.fleXcrollMain('shdes4');

            });
        });
        $(".hitemmini:first").click();
        $(".hreserve").click(function(){
            $("#txthabitacion").val($(this).attr("title"));
            $("#frmhabit").submit();
        });
    });
}
function load_formtrabaja(){
    $(document).ready(function(){
        $("#linkalert").fancybox({
            overlayOpacity:0.8,
            overlayColor:"#000",
            showCloseButton:false
        });
        $("#frmreservacion").formValidator({
            onValidated:function(msg){
                if(msg){
                    $("#boxtexto").html(msg);
                    $("#linkalert").click();
                    return false;
                }
                else
                    return true;
            },
            txt4_validate:function(obj){
                ext=$(obj).val().substr(-3, 3);
                switch(ext){
                    case 'pdf':
                    case 'doc':
                    case 'ocx':
                        return false;
                        break;
                    default:
                        return "El formato del Curriculum Vitae no es válido.";
                }
            }
        });
    });
}

function load_formcontacto(){
    $(document).ready(function(){
        $("#linkalert").fancybox({
            overlayOpacity:0.8,
            overlayColor:"#000",
            showCloseButton:false
        });
        almsgrequired   =($("#txt10").val().toString().indexOf("spa")>-1?"El campo {campo} es requerido":"{campo} field is mandatory");
        almsginvalid    =($("#txt10").val().toString().indexOf("spa")>-1?"El campo {campo} no es válido":"{campo} field is not valid");
        $("#frmreservacion").formValidator({
            msgrequired   :almsgrequired,
            msginvalid    :almsginvalid,
            onValidated:function(msg){
                if(msg){
                    $("#boxtexto").html(msg);
                    $("#linkalert").click();
                }
                else{
                    datos='';
                    for(i=1;i<=10;i++){
                        x=$("#txt"+i);
                        if(x.length>0)
                            datos+='&'+x.attr("name")+"="+escape(x.val());
                    }
                    datos="validar=1"+datos;
                    $.ajax({
                        url:"../../mail_contacto.php",
                        type:"post",
                        data:datos,
                        success:function(data){
                            $("#boxtexto").html(data);
                            $("#frmreservacion input[name*=txt], textarea").val("");
                            $("#linkalert").click();
                        }
                    });
                }
                return false;
            }
        });
    });
}
function load_formreserva(){
    $(document).ready(function(){
        df=new Date();
        $("#txt5").datepicker({
            //dateformat: 'dd/mm/yy',
            onSelect: function(dateText, inst){
                a=$("#txt5").datepicker( "getDate" );
                f=$("#txt5").val().split("/");
                b=new Date(f[2],f[1], f[0]);
                b.setTime(b.getTime()+(1000*60*60*24));
                $("#txt6").datepicker("option","minDate",a);
            },
            firstDay: 1,
            minDate:new Date((1000*60*60*24)+parseInt(df.getTime()))
        });
        $("#txt6").datepicker({
            //dateformat: 'dd/mm/yy',
            firstDay: 1,
            minDate:new Date((1000*60*60*48)+parseInt(df.getTime()))
        });
        //validacion del formulario
        $("#linkalert").fancybox({
            overlayOpacity:0.8,
            overlayColor:"#000",
            showCloseButton:false
        });
        almsgrequired   =($("#txt10").val().toString().indexOf("spa")>-1?"El campo {campo} es requerido":"{campo} field is mandatory");
        almsginvalid    =($("#txt10").val().toString().indexOf("spa")>-1?"El campo {campo} no es válido":"{campo} field is not valid");
        $("#frmreservacion").formValidator({
            msgrequired   :almsgrequired,
            msginvalid    :almsginvalid,
            onValidated:function(msg){
                if(msg){
                    $("#boxtexto").html(msg);
                    $("#linkalert").click();
                }
                else{
                    datos='';
                    for(i=1;i<=11;i++){
                        x=$("#txt"+i);
                        if(x.length>0)
                            datos+='&'+x.attr("name")+"="+escape(x.val());
                    }
                    datos="validar=1"+datos;
                    $.ajax({
                        url:"../../mail_reservas.php",
                        type:"post",
                        data:datos,
                        async:false,
                        success:function(data){
                            $("#boxtexto").html(data);
                            $("#frmreservacion input[name*=txt]").val("");
                            $("#linkalert").click();
                        }
                    });
                }
                return false;
            }
        });
        calc_total=function(){
            total=0;
            nro=$("#txt7").val();
            if($("#txt8").val()=="Junior Suite" || $("#txt8").val()=="Suite Ejecutiva")
                total=nro*145;
            if($("#txt8").val()=="Classic Room" || $("#txt8").val()=="Habitación Matrimonial")
                total=nro*110;
            if($("#txt8").val()=="Twin Room" || $("#txt8").val()=="Habitación Doble")
                total=nro*140;
            if($("#txt8").val()=="Three bed Room" || $("#txt8").val()=="Habitación Triple")
                total=nro*210;
            $("#txt9").val("S/. "+total+".00");
        };
        $("#txt7").keyup(calc_total);
        $("#txt8").change(calc_total);
    });
}
function load_youtube(){
    $("#youtube").fancybox({
        width:640,
        height:390,
        overlayOpacity:0.8,
        overlayColor:"#000",
        type:"swf",
        titleShow:false,
        wmode: 'transparent'
    });
}
function hora_local(){
    seg=$("#segundos").text()*1+1;
    min=$("#minutos").text()*1;
    hor=$("#hora").text()*1;
    mer=$("#meridiano").text();
    if(seg==60){
        seg=0;
        min++;
        if(min==60){
            min=0;
            hor++;
            if(hor==12){
                if(mer=="pm")
                    mer="am";
                else
                    mer="pm";
            }
            if(hor==13){
                hor=1;
            }
        }
    }
    $("#segundos").html(seg);
    $("#minutos").html(min);
    $("#hora").html(hor);
}
function load_sliderhome(){
    $('#col2slidescont').cycle({
        fx:     'scrollHorz',
        speed:  'slow',
        timeout: 0,
        next:   '#col2der',
        prev:   '#col2izq'
    });
}
