var DDSPEED = 10;
var DDTIMER = 15;

//controlo los eventos onmouseout y onmouseover //
function ddMenu(id,d){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearInterval(c.timer);
  if(d == 1){
    clearTimeout(h.timer);
    if(c.maxh && c.maxh <= c.offsetHeight){return}
    else if(!c.maxh){
      c.style.display = 'block';
      c.style.height = 'auto';
      c.maxh = c.offsetHeight;
      c.style.height = '0px';	
    }
    c.timer = setInterval(function(){ddSlide(c,1);document.getElementById("two-ddheader").style.cssText="background:url(../../../images/com/info_imgdistancia_bot.gif) no-repeat bottom;";},DDTIMER);
  }else{
    h.timer = setTimeout(function(){ddCollapse(c)},50);	
  }
}

// colapso el menu //
function ddCollapse(c){
  c.timer = setInterval(function(){ddSlide(c,-1)},DDTIMER);
  document.getElementById("two-ddheader").style.cssText="background:url(../../../images/com/info_imgdistancia.gif) no-repeat bottom;";
}

// cancela el dropdown //
function cancelHide(id){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearTimeout(h.timer);
  clearInterval(c.timer);
  if(c.offsetHeight < c.maxh){
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }
}

// expandir ocontraer el dropdown y bajar o subir la opacidad //
function ddSlide(c,d){
  
  var currh = c.offsetHeight;
  var dist;
  if(d == 1){
    dist = (Math.round((c.maxh - currh) / DDSPEED));
  }else{
    dist = (Math.round(currh / DDSPEED));	
  }
  if(dist <= 1 && d == 1){
    dist = 1;
  }
  if (currh < 45){
  
	c.style.height = currh + (dist * d) + 'px';
	c.style.opacity = currh / c.maxh;
	c.style.filter = 'alpha(opacity=' + (currh * 150 / c.maxh) + ')';
  }
  if((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)){
    clearInterval(c.timer);		
  }
  if(d==-1 && currh==4)	
	document.getElementById("one-ddcontent").style.height="0px";	
}

//log in para usuario distancia
function LoginDistEsp(es)
{
	var url;
	var ftnum;
	var pin;
	ajaxFunction();

	ftnum = document.form1.txtNumDist.value;
	pin = document.form1.txtPinDist.value;
	var params = "ftnum=" + ftnum + "&pin=" + pin;
	document.getElementById("txtPinDist").value="";

		url = "esp/dis/jli/jliloghp01.asp"
		document.getElementById("mensajeLogin").innerHTML="Procesando..."

	

	
	
	xmlHttp.onreadystatechange=function()
    {
		if(xmlHttp.readyState==4){
			document.getElementById("mensajeLogin").innerHTML="";
			var mjg=xmlHttp.responseText.split("|");
			if (mjg[0]=='true')
			{
				document.getElementById('dvBloqueLogin').style.display='none';
				document.getElementById("msgarea").innerHTML=mjg[1];
				
				document.getElementById('dvLogin').style.display = 'block';
				document.getElementById('dvLoginDistancia').style.display = 'none';
			}
			else
			{	
				document.getElementById('dvBloqueLogin').style.display='';
				if(mjg[0]=='false')
				{
					alertaGenerica(mjg[1]);
				}
				else
				{
			
						
						alertaGenerica("Usuario Invalido");
			
					
				}

			}
		}
    }	
	
	if(url != ""){	
		xmlHttp.open("POST",url,true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
	}
}

function UserIsLoginEsp(es)
{
	var url;

	ajaxFunction();
		
	url = "esp/dis/jli/jliloghp02.asp"
		
	
	xmlHttp.onreadystatechange=function()
    {
		if(xmlHttp.readyState==4){
			
			document.getElementById("mensajeLogin").innerHTML="";
			var mjg=xmlHttp.responseText.split("|");
			if (mjg[0]=='true')
			{
				document.getElementById("msgarea").innerHTML=mjg[1];
				if(mjg[2]=="0" || mjg[2]=="2")
				{
					document.getElementById('dvBloqueLogin').style.display='';
				}
				
			}
			else
			{
				document.getElementById('dvBloqueLogin').style.display='';
			}
		}
    }	
		
	if(url != ""){	
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);	
	}
}

function LogoutEsp(es)
{
	var url;

	ajaxFunction();
		
		url = "esp/dis/jli/jlilogouthp.asp"
		

	xmlHttp.onreadystatechange=function()
    {
		if(xmlHttp.readyState==4){
			var mjg=xmlHttp.responseText;
			if (mjg=='true')
			{
				UserIsLogin();
			}
		}
    }	
	
	if(url != ""){		
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);	
	}
}


function LoginDistEng()
{
	var url;
	var ftnum;
	var pin;
	ajaxFunction();

	ftnum = document.form1.txtNumDist.value;
	pin = document.form1.txtPinDist.value;
	var params = "ftnum=" + ftnum + "&pin=" + pin;
	document.getElementById("txtPinDist").value="";
	
		url = "eng/dis/jli/jliloghp01.asp"
		document.getElementById("mensajeLogin").innerHTML="Please Wait...";

	
	
	xmlHttp.onreadystatechange=function()
    {
		if(xmlHttp.readyState==4){
			document.getElementById("mensajeLogin").innerHTML="";
			var mjg=xmlHttp.responseText.split("|");
			if (mjg[0]=='true')
			{
				document.getElementById('dvBloqueLogin').style.display='none';
				document.getElementById("msgarea").innerHTML=mjg[1];
				
				document.getElementById('dvLogin').style.display = 'block';
				document.getElementById('dvLoginDistancia').style.display = 'none';
			}
			else
			{	
				document.getElementById('dvBloqueLogin').style.display='';
				if(mjg[0]=='false')
				{
					alertaGenerica(mjg[1]);
				}
				else
				{
						alertaGenerica("Invalid User");
				}

			}
		}
    }	
	
	if(url != ""){	
		xmlHttp.open("POST",url,true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
	}
}

function UserIsLoginEng()
{
	var url;

	ajaxFunction();

	url = "eng/dis/jli/jliloghp02.asp"
		
	
	
	xmlHttp.onreadystatechange=function()
    {
		if(xmlHttp.readyState==4){
			
			document.getElementById("mensajeLogin").innerHTML="";
			var mjg=xmlHttp.responseText.split("|");
			if (mjg[0]=='true')
			{
				document.getElementById("msgarea").innerHTML=mjg[1];
				if(mjg[2]=="0" || mjg[2]=="2")
				{
					document.getElementById('dvBloqueLogin').style.display='';
				}
				
			}
			else
			{
				document.getElementById('dvBloqueLogin').style.display='';
			}
		}
    }	
		
	if(url != ""){	
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);	
	}
}

function LogoutEng(es)
{
	var url;

	ajaxFunction();
		
	url = "eng/dis/jli/jlilogouthp.asp"
		
	xmlHttp.onreadystatechange=function()
    {
		if(xmlHttp.readyState==4){
			var mjg=xmlHttp.responseText;
			if (mjg=='true')
			{
				UserIsLogin();
			}
		}
    }	
	
	if(url != ""){		
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);	
	}
}


function ClkLog()
{
	login_onclick(); //funcion en libreria manejoDivs.
	document.getElementById("txtNumDist").focus();
}
