// JavaScript Document

function curTop(obj){
	//Regresa la posicion del cursor en y
	toreturn = 0;
	while(obj){
		toreturn += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return toreturn;
}

function curLeft(obj){
	//Regresa la posicion del cursor en x
	toreturn = 0;
	while(obj){
		toreturn += obj.offsetLeft;
		obj = obj.offsetParent;
	}
	return toreturn;
}

//Menus Desplegables

function jsDespliega(id,idPadre)
{
	Padre=document.getElementById(idPadre)
	document.getElementById(id).style.top=parseInt(curTop(Padre))+17;
	document.getElementById(id).style.left=curLeft(Padre);
	document.getElementById(id).style.visibility='visible';	
}
function jsDesespliega(id)
{
	document.getElementById(id).style.visibility='hidden';	
}


//Envio de contacto

function jsDirijeHome()
{
	jsLoadDirectorio('Home','directory.php');
}

function jsEnvioContact(NameContacto,Mail,Mensaje)
{
	var M=Mensaje.cloneNode(true);
	if(M.value!=""&&Mail.value!=""&&document.getElementById("txtNombWeb").value!=""&&document.getElementById("txtTelWeb").value!="")
	{
		M.value+= "|"+document.getElementById("txtNombWeb").value+"|"+document.getElementById("txtTelWeb").value+"|"+NameContacto;
		
	}
	else
	{
		alert("No deben quedar espacios en blanco");	
		
	}
	var aux=jsEnviarContactanos(2,Mail,M);
	if(aux!=false)
	{
		setTimeout("jsDirijeHome()",1000);
	}
}

//thickbox----------------

function jsWindowIt(Url,Titulo,W,H,Modal,CallBack){
	/* *******************************************************************************************
	 * Importancia: ALTA
	 Función que hace uso de un la funcion tb_show() del thickbox.js para mostrar una ventana flotante
	 Autor: FJRL
	 Fecha: 28 Enero 2009
	******************************************************************************************* **/
	tb_show(Titulo, Url + '&height='+H+'&width='+W+'&modal='+ Modal + '&callback=' + CallBack, null);
	//para cerrar
	//tb_remove();
}


function jsDialogIt(url, id, titulo, ancho, alto, bloquear, cerrar, arrastra, resize){
	// Abre un cuadro de dialogo con una carga dinámica (sustituto de jsWindowIt)
	//jsDialogIt('catalogos/activoFijo_tipode_modificar.php?id='+id, 'dlgModificaTipoDe', 'Modificar Tipo de Activo Fijo');

	var dlgId = id || 'ididid';
	ancho = ancho || 600;
	alto = alto || 130;
	titulo = titulo || '';
	bloquear = bloquear===undefined?true:bloquear;
	cerrar = cerrar===undefined?true:cerrar;
	arrastra = arrastra===undefined?true:arrastra;
	resize = resize===undefined?false:resize;
	if ($('#'+dlgId).length == 0) {
		var newDialog = document.createElement('DIV');
		newDialog.id = dlgId;
		$('body').prepend(newDialog);
		$('#'+newDialog.id).html('<div align="center" class="loading"><img src="img/loadingAnimation.gif"></div>');
		$('#'+newDialog.id).load(url);
		$('#'+newDialog.id).dialog({
			modal: bloquear,
			width: ancho,
			height: alto,
			closeOnEscape: cerrar,
			draggable: arrastra,
			resizable: resize,
			title: titulo,
			zIndex: 1000000,
			hide: 'fold',
			close: function(){
				$('#'+newDialog.id).remove();
				
			}
		});
	}
	else {
		$('#'+dlgId).effect('shake',{},50);
	}
}

function trim(cadena)
{
	//funcion que sirve para hacer trim
	for(i=0; i<cadena.length; )
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(i+1, cadena.length);
		else
			break;
	}

	for(i=cadena.length-1; i>=0; i=cadena.length-1)
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(0,i);
		else
			break;
	}
	
	return cadena
	//forma.caja2.value=cadena;
}

function jsEnsenaSlc(id,esta,value){
//muestra un objeto por medio de un combo que no se veia

	if (document.getElementById(esta).value==value) {
		$("#" + id).show();
	}
	else {
		$("#" + id).hide();
	}
}

function jsEnsenaSlcAgencia(id,esta,value1,value2){
//muestra un objeto por medio de un combo que no se veia para agencia especialmente

	if (document.getElementById(esta).value==value1||document.getElementById(esta).value==value2) {
		$("#" + id).show();
	}
	else {
		$("#" + id).hide();
	}
}

function jsEnsenachk(id, esta,demas){
	//muestra un objeto por medio de un chekbox que no se veia
	
	if(demas===undefined)demas="";
	esta=document.getElementById(esta);
	if (esta.checked) {
		$("#" + id).show();
	}
	else {
		$("#" + id).hide();
		if(demas!="")
		eval(demas);
	}
}

function jsEvaluaEmail(valor){
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(valor))
	{
		return (true)
	} 
	else 
	{
		alert("La direccion de email ("+valor+") es incorrecta.");
		return (false);
	}
}

function jsTextNumero(cadena, obj, e) {
	/*Funcion: Solo permite escribir numero en una caja de texto.
	Auto Hector de Leon
	Ejemplo: onkeypress='return jsTextNumero(event)'
	*/
	opc = false;
	tecla = (document.all) ? e.keyCode : e.which;

	if (cadena == "%d")
	if (tecla > 47 && tecla < 58)
	opc = true;
	if (cadena == "%f"){
	if ((tecla > 47 && tecla < 58)||tecla==8||tecla==9||tecla==0)
	opc = true;
	//para si se quiere punto---------------------------------------------
	//if (obj.value.search("[.*]") == -1 && obj.value.length != 0)
	//if (tecla == 46)
	//opc = true;
	//--------------------------------------------------------------------
	}

	return opc;

}

function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}

function jsRefreshTxt(obj,cadena)
{
	if(obj.value==cadena)
	{
		obj.style.color="#000";
		obj.value="";
	}
	else
	return false;
}

function jsReloadTxt(obj,cadena)
{
	if(trim(obj.value)=="")
	{
		obj.style.color="#666";
		obj.value=cadena;
	}
	else
	return false;
}

function jsShowObj(objeto)
{
	obj=document.getElementById(objeto);
	//alert(obj.style.display);
	
	
	if(obj.style.display=="none")
		$("#"+objeto).show();
	else
		$("#"+objeto).hide();
	
}