﻿var logion_usuario = "Usuario";
var login_password = "Contraseña";
var archivoConfigVisor = "configsm";

$(document).ready(function(){
         $("#txtContrase").focus(function () {
            if($('#txtContrase')[0].value == login_password)
                $('#txtContrase')[0].value = '';
         });
         
         $("#txtContrase").blur(function () {
            if($('#txtContrase')[0].value == '') {
                $('#txtContrase')[0].value = login_password;
            }
            
            if ($('#txtContrase')[0].value == login_password){
                $('#txtContrase').hide();
                $('#txt1pwd')[0].value = login_password;
                $('#txt1pwd').show();
            }
         });
         
         $("#txt1pwd").focus(function () {
            if($('#txt1pwd')[0].value == login_password)
                $('#txt1pwd')[0].value = '';
         });
         
          $("#txt1pwd").blur(function () {
            if($('#txt1pwd')[0].value == '')
                $('#txt1pwd')[0].value = login_password;
         });

         $("#txtIdentificador").focus(function () {
            if($('#txtIdentificador')[0].value == logion_usuario)
                $('#txtIdentificador')[0].value = '';
         });
         
         $("#txtIdentificador").blur(function () {
            if($('#txtIdentificador')[0].value == '')
                $('#txtIdentificador')[0].value = logion_usuario;
         });
    
});


/*################################################ recordar pwd ######################################## */
function recordarPWD(){
    PageMethods.LIR_recordarXmail($('#txt_recordar_pwd_mail').val().trim(),idColegio,idServicioContacto, 'Datos de contacto para el acceso a www.encuentro-sm.com.mx', bien_recordarPWD, mal);
}

function bien_recordarPWD(res){
    if (res=='1'){
         alert(msg_inser_cod_revisemail); 
         cerrarPopup('dv_recordar_pwd');
    }else{
         recordarPWDMestres(); 
    }
}

function default_check_mail(){
    if((/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($('#txt_mail_usuario_new').val().trim()))){
        AJAXPro.PortalWeb.Frontal.getRecuperarDatosXcolegio($('#txt_mail_usuario_new').val().trim(),idPortal,idColegio, default_check_mail2);
    }else{
        alert(msg_mailMAL);
    }
}

function default_check_mail2(res){
    if (res.value==false){
        visiblePaso3();
        $('#tbl_tr_paso3_1').hide();
        $('#tbl_tr_paso3_2').show();
        $("#div_form_inscr").height($("#tbl_paso3").height());
        var mail = $('#txt_mail_usuario_new').val().trim();
        $('#txtEmail').val(mail);
        accionForm=2;
        $('.tooltipRegistro[title]').hovertip();
    }else{
        /*alert(msg_inser_cod_mailExistente);*/
        recordarPwdRegPaso2CruillaDigPopup();
    }
}

var dialogClose;
function abrirPopup(capa, width, height, opcionCierre, onOpenCallback){
     dialogClose = $('#' + capa).dialog({
     autoOpen: false,
     width: width, 
     height: height,
     modal:true,
     close: function(event, ui) {
        $('#sltCentro').css('visibility','visible');
        //Si viene opcionCierre a 1 vamos a mis libros
        if (opcionCierre==1) location.href ='/lir/misLibros.aspx';
        else eval(opcionCierre);
     },
     draggable: false,
     resizable: false,
     open: onOpenCallback
     });
     
     dialogClose.dialog('open'); 
}

function cerrarPopup(capa) {
     dialogClose.dialog('close');
     dialogClose.dialog('destroy');
     $('#sltCentro').css('visibility','visible');
}

function testEnter_pwd(event_key){
     if (event_key == null) {
        event_key = window.event;
     }

     if (event_key.keyCode == 13) {
        validarUsuarioWebLir();
     }
 } 
 
function mal(res){
    alert(msg_error);
}

function comprobarSaltoCarroAddCodProducto(id ,objEvento){
    if (objEvento.charCode>0){
        var s_txt1 = $('#txt_clv1').val();
        var s_txt2 = $('#txt_clv2').val();
        var s_txt3 = $('#txt_clv3').val();
        var txt4 = $('#txt_clv4');
        var txt4_1 = $('#txt_clv4_1');
        //a esta altura aun no ha insertado el valor en el input, cuando pase este evento lo hace ...
        //por eso contamos a 3 y no 4 los caracteres para pegar el salto a la siguiente caja
        
        if (id=='txt_clv1' && s_txt1.length==3)
            document.getElementById('txt_clv2').focus();
        if (id=='txt_clv2' && s_txt2.length==3)
            document.getElementById('txt_clv3').focus();
        if (id=='txt_clv3' && s_txt3.length==3){
            if (txt4.length>0) document.getElementById('txt_clv4').focus();
            if (txt4_1.length>0) document.getElementById('txt_clv4_1').focus();
        }
    }  
}

function recordarPwdHOMEpopup(){
    abrirPopup('dv_recordar_pwd_home',300,220);
}

var recordarPwdStart=0;
function recordarPWDHOMEfn(){
    if (recordarPwdStart==0){
        recordarPwdStart=1;
        var txtComprobar = $('#txt_recordar_pwd_mail_home').val().trim() 
        /*if (txtComprobar == ''){
            txtComprobar = '|' + $('#txt_recordar_pwd_login_home').val(); 
        }*/      
        PageMethods.LIR_recordarXmail(txtComprobar, idColegio,idServicioContacto, msg_recrodarpwd_titulo, bien_recordarPWDHOMEfn, mal);
    }
}

function bien_recordarPWDHOMEfn(res){
    cerrarPopup('dv_recordar_pwd_home');
    if (res=='1'){
         alert(msg_inser_cod_revisemail); 
    }else{
         alert(msg_recrodarpwd_usuarionoexistente); 
    }
    recordarPwdStart=0;   
}

function deshabilitarInput(oTh, txtId){
    if ($(oTh).val() != ''){
        $('#' + txtId).attr('disabled','disabled');
    }
    else{
        $('#' + txtId).removeAttr('disabled');
    }
}
