jQuery(document).ready(function($){
   //alert('<%=CookieClaveExp%>');
   // Funcionalidad de 'auto-sugerencia' de los campos del formulario Login
   if (CookieClaveExp == "")
   {
	   $InputPwd = $(document.forms['FrmLogin']).find('input[name=txt_pwd]');
	   if ( ! $InputPwd.size() ) return;

	   var InputHtml = $InputPwd.wrapAll('<span id="fake-wrapper"/>').parents('#fake-wrapper').html();
	   InputHtml = InputHtml.replace(/type[^\w]+password[^\s>]*/i, 'type="text"');

	   $InputMask = $(InputHtml).val('Clave')
	   .attr({ readOnly: true, name: $InputPwd.attr('name')+'-mask', id: '' });

	   $InputPwd.blur(function(evt){
		   if ( ! this.value )
		   {
			  $InputPwd.hide(0);
			  $InputMask.show(0).blur();
		   }
	   });
	   $InputMask.focus(function(evt){
					   $InputMask.hide(0);
					   $InputPwd.show(0).focus();
	   });

	   $InputPwd.after($InputMask).hide(0);
   }
});


function fnMenu(item) {
   obj = document.getElementById(item);
   if(obj != null)
   {
       visible = (obj.style.display!="none")
       if (visible)
       {
         obj.style.display="none";
        }
        else {
          obj.style.display="block";
         }
    }
}
function ActivarNube(nomId)
		{
		var varId;
		varId = document.getElementById(nomId);
			if (varId.style.display == 'none')
			{
			 varId.style.display = 'block';
			}
			
		}
		
	function DesactivarNube(nomId)
		{
		var varId;
		varId = document.getElementById(nomId);
			if (varId.style.display == 'block')
			{
			varId.style.display = 'none';
			}
	   
		}

function clear_textbox()
{
	if (document.FrmLogin.txt_usuario.value == "Usuario")
		document.FrmLogin.txt_usuario.value = "";
}

function usuario_textbox()
{
	if (document.FrmLogin.txt_usuario.value == "")
		document.FrmLogin.txt_usuario.value = "Usuario";
}

function clear_textbox1()
{
	if (document.FrmLogin.txt_pwd.value == "Clave")
	{
		document.FrmLogin.txt_pwd.value = "";
		var input=document.getElementById('txt_pwd');
		var input2= input.cloneNode(false);
		input2.type='password';
		input.parentNode.replaceChild(input2,input);
		document.FrmLogin.txt_pwd.focus;
	}
}

function CambioPais ()
{
 self.parent.location.href= document.FrmLogin.Pais.value;
}
function CambioPaisAbajo()
{
 document.location.href=RutaPaisA+"Redireccionamiento.asp?Id_pais=" + document.FrmPais.Pais.value;
 //document.location.href="" + Ruta + "Redireccionamiento.asp?Id_pais=" + pais;
}


function Login(Ruta)
{
    var usuario = document.FrmLogin.txt_usuario;
    var Clave2 = document.FrmLogin.txt_pwd;
    var Recordar = document.FrmLogin.recordar;
    var strRecordar
    strRecordar = "";
    if (Recordar.checked)
    {
        strRecordar="ON";
    }

    var Ruta2 = Ruta + "?usuario=" + usuario.value + "&Clave2=" + Clave2.value + "&recordar=" + strRecordar;
    Mostrar(Ruta2,'600','600');
}
function redirect(pageToReload)
{
	document.location.href=pageToReload;
}
/* ----------------------- */

/* Scripts dentro del Body */

var LoadHandler = {
  handlers:[],
  add:function(fn){
    if(window.onload!=LoadHandler.theHandler) LoadHandler._push(window.onload);
    LoadHandler._push(fn);
    window.onload=LoadHandler.theHandler;
  },
  _push:function(fn){
    if(typeof(fn)!='function') return;
    LoadHandler.handlers[LoadHandler.handlers.length]=fn;
  },
  theHandler:function(){
    var handlers=LoadHandler.handlers,i=-1,fn;
    while(fn=handlers[++i]) fn();
  }
}



// Example 2 (JS part 1)
function changeInputType(
  oldElm, // a reference to the input element
  iType, // value of the type property: 'text' or 'password'
  iValue, // the default value, set to 'password' in the demo
  blankValue, // true if the value should be empty, false otherwise
  noFocus) {  // set to true if the element should not be given focus
  if(!oldElm || !oldElm.parentNode || (iType.length<4) || 
    !document.getElementById || !document.createElement) return;
  var isMSIE=/*@cc_on!@*/false; //http://dean.edwards.name/weblog/2007/03/sniff/
  if(!isMSIE){
    var newElm=document.createElement('input');
    newElm.type=iType;
  } else {
    var newElm=document.createElement('span');
    newElm.innerHTML='<input type="'+iType+'" name="'+oldElm.name+'">';
    newElm=newElm.firstChild;
  }
  var props=['name','id','className','size','tabIndex','accessKey'];
  for(var i=0,l=props.length;i<l;i++){
    if(oldElm[props[i]]) newElm[props[i]]=oldElm[props[i]];
  }
  newElm.onfocus=function(){return function(){
    if(this.hasFocus) return;
    var newElm=changeInputType(this,'password',iValue,
      (this.value.toLowerCase()==iValue.toLowerCase())?true:false);
    if(newElm) newElm.hasFocus=true;
  }}();
  newElm.onblur=function(){return function(){
    if(this.hasFocus)
    if(this.value=='' || (this.value.toLowerCase()==iValue.toLowerCase())) {
      changeInputType(this,'text',iValue,false,true);
    }
  }}();
 // hasFocus is to prevent a loop where onfocus is triggered over and over again
  newElm.hasFocus=false;
  // some browsers need the value set before the element is added to the page
  // while others need it set after
  if(!blankValue) newElm.value=iValue;
  oldElm.parentNode.replaceChild(newElm,oldElm);
  if(!isMSIE && !blankValue) newElm.value=iValue;
  if(!noFocus || typeof(noFocus)=='undefined') {
    window.tempElm=newElm;
    setTimeout("tempElm.hasFocus=true;tempElm.focus();",1);
  }
  return newElm;
}


// Example 2 (JS part 2)
LoadHandler.add(function(){
  // Normally I use object detection, however, in this case since I need to 
  // detect Konqueror and Safari which don't have unique objects,
  // I will use the user agent string to detect them. Only use this type of 
  // detection as a last resort.
  // I'm doing this because example 2 crashes Konqueror 3.4 and Safari 1.0
return;
  var ua=navigator.userAgent.toLowerCase();
  if(!((ua.indexOf('konqueror')!=-1) && /khtml\/3\.[0-4]/.test(ua)) && 
    !(((ua.indexOf('safari')!=-1) && !window.print))) {

       // Set the third value to the text you want to appear in the field.
      if ('<%=CookieClaveExp%>' == 'Clave')
      {
        changeInputType(document.forms[0].clave2,'text','<%=CookieClaveExp%>',false,true);
      }
      else
      {
        changeInputType(document.forms[0].clave2,'password','<%=CookieClaveExp%>',false,true);
      }
  }
});
/* ]]> */
//-->

//Se crea funcion para que cuando se de enter haga lo mismo que el boton de entrar
    
    function entsub(e,myform) {
        if(myform!=null)
        {
         var keyCode=(document.all) ? e.keyCode : e.which;
            
         if (keyCode == 13)
            if (myform.name == "FrmLogin")
            {
                //Login('<%=Application("RutaHTTP")%>Login.asp');
                myform.submit();
            }
            else if (myform.name == "SE_CONTACTENOS_001")
            {
                submitform();
            }
            else if (myform.name == "FrmBuscar")
            {
                submitformbuscar();
            }
            else
            {
                myform.submit();
            }
            
        else
            return true;   
        }
        
    }
 
    ////Se agregaron funciones para validar el form buscar
    function submitformbuscar()
     {
        if(document.FrmBuscar.onsubmit())
         {//this check triggers the validations
            document.FrmBuscar.submit();
         }
     }
    function ValidarBuscar()
    {
        var Valor;
        Valor = trim(document.forms.FrmBuscar.Buscar.value);
        if(Valor==""){
            alert("Debe ingresar datos para la busqueda");
            return false;
            
        }
        else
        {
            if (Valor.length < 3)
            {
                alert("Debe ingresar por lo menos 3 caracteres para la busqueda");
                return false;
            }
        }
        return true;
    }
