var mouseX=0, mouseY=0;
var Browser='IE';
if (document.all) Browser='IE';
else
{ if (document.layers)	Browser='NS';
	else	Browser='7'; }


function getMousePos(e)
{
	if (!e)
	var e = window.event||window.Event;

	if('undefined'!=typeof e.pageX)
	{
		mouseX = e.pageX;
		mouseY = e.pageY+10;
	}
	else
	{
		mouseX = e.clientX + document.body.scrollLeft;
		mouseY = e.clientY + document.body.scrollTop+10;
	}
}


if(Browser=='IE')
{
  document.onmousemove=Mouse_IE;
}
else
{
	document.onmousemove = getMousePos;
}


function Mouse_IE(evnt)
{
	mouseX = event.y+10;
	mouseY = event.x+10;
}

function muestra(campo)
{
	var tipob1;
	tipob1=document.all;
	if (tipob1)
		this.Browser='IE';
	else
	{
		tipob1=document.layers;
		if (tipob1)
			this.Browser='NS';
		else
			this.Browser='7';
	}
	switch(this.Browser)
	{
		case 'IE':
			eval(campo+'.style.visibility = "visible"');
			break;
		case 'NS':
			eval('document.'+campo+'.visibility = "visible"');
			break;
		case '7':
			if(document.getElementById(campo)) document.getElementById(campo).style.visibility = 'visible';
			break;
	}
}

function oculta(campo)
{
	var tipob1;
	tipob1=document.all;
	if (tipob1)
		this.Browser='IE';
	else
	{
		tipob1=document.layers;
		if (tipob1)
			this.Browser='NS';
		else
			this.Browser='7';
	}
	switch(this.Browser)
	{
		case 'IE':
			eval(campo+'.style.visibility = "hidden"');
			break;
		case 'NS':
			eval('document.'+campo+'.visibility = "hide"');
			break;
		case '7':
			document.getElementById(campo).style.visibility = 'hidden';
			break;
	}

}


function validaemail(dato)
{
	var enc1=0;
	var enc2=0;

	for(i=0;i<dato.value.length;i++)
	{
		if( dato.value[i]=='@') enc1=1;
	}
	if (dato.value.indexOf('.')!=-1)
	{
		enc2=1;
	}
	if (enc1==0)
	{
		alert('Debe escribir una dirección de correo electrónico válida, hace falta @');
		dato.focus();
	}
	if (enc2==0)
	{
		alert('Debe escribir una dirección de correo electrónico válida, hace falta .');
		dato.focus();
	}
}

function adicionames(fecha,cantidad)
{
	nfecha=fecha.replace(/-/g,'');
	ano=nfecha.substr(0,4)*1;
	mes=nfecha.substr(4,2)*1;
	dia=nfecha.substr(6,2)*1;
	mes+=cantidad;
	while(mes>12) { mes-=12; ano++; }
	if(mes==2 && dia>28) dia=28;
	if( ((mes==4) || (mes==6) || (mes==9) || (mes==11)) & (dia>30)) dia=30;
	resultado=ano+'-'+mes+'-'+dia;
	return resultado;
}

function adicionadia(fecha,cantidad)
{
	nfecha=fecha.replace(/-/g,'');
	ano=nfecha.substr(0,4)*1;
	mes=nfecha.substr(4,2)*1;
	dia=nfecha.substr(6,2)*1;
	dia+=cantidad;
	while(dia>31) { dia-=31; mes++;}
	while(mes>12) {mes-=12; ano++; }
	if(mes==2 && dia >28) {dia-=28; mes++}
	if(((mes==4) || (mes==6) || (mes==9) || (mes==11)) && (dia>30)) {dia=30; mes++; }
	resultado=ano+'-'+mes+'-'+dia;
	return resultado;
}

function rtrim( str )
{
	var resultStr = "";
	var i = 0;
	if (str+"" == "undefined" || str == null)	return null;
	str += "";
	if (str.length == 0) resultStr = "";
	else
	{
  		i = str.length - 1;
  		while ((i >= 0) && (str.charAt(i) == " ")) i--;
  		resultStr = str.substring(0, i + 1);
  	}
  	return resultStr;
}

function ltrim( str )
{
	var resultStr = "";
	var i = len = 0;
	if (str+"" == "undefined" || str == null)	return null;
	str += "";
	if (str.length == 0) resultStr = "";
	else
	{
		len = str.length;
  		while ((i <= len) && (str.charAt(i) == " "))	i++;
  		resultStr = str.substring(i, len);
  	}
  	return resultStr;
}

function alltrim( str )
{
	var resultStr = "";
	resultStr = ltrim(str);
	resultStr = rtrim(resultStr);
	return resultStr;
}


function modal(url,top,left,alto,ancho,destino)
{
	 if(!top) top=0;
	 if(!left) left=0;
	 if(!alto) alto=50;
	 if(!ancho) ancho=100;
	 if(!destino) destino='_blank';
	var caracteristicas = "height=50, width=100, channelmode=0, dependent=1, chrome=yes, location=0, toolbar=0, directories=0,status=0, statusbar=0, linemenubar=0, menubar=0, modal=1, left="+left+", top="+top+", resizable=1, scrollbars=1";

	var NuevaVentana = window.open(url,destino,caracteristicas);
	if(NuevaVentana==null) alert('SU NAVEGADOR ESTA BLOQUEANDO VENTANAS EMERGENTES');
	NuevaVentana.focus();
	if(destino!='destino')
	{
		var saltoalto=alto/5;
		var saltoancho=ancho/5;
		var nancho=10;
		var nalto=10;
		while(nancho<ancho && nalto<alto){
			nancho+=saltoancho;
			nalto+=saltoalto;
			NuevaVentana.resizeTo(nancho,nalto);
		} // while
		NuevaVentana.resizeTo(ancho,alto);
		if(mouseX+ancho>screen.availWidth) mouseX=screen.availWidth-ancho;
		if(mouseY+alto>screen.availHeight) mouseY=screen.availHeight-alto-100;
		NuevaVentana.moveTo(mouseX,mouseY);
	}

}

function modal2(url,top,left,alto,ancho,destino,mouse)
{
	var caracteristicas = "height=50, width=100, channelmode=0, dependent=0, chrome=yes, location=0, toolbar=0, directories=0,status=0,statusbar=0, linemenubar=0, menubar=1, modal=1, left="+left+", top="+top+", resizable=1, scrollbars=1";
	var NuevaVentana = window.open(url,destino,caracteristicas);
	if(NuevaVentana==null) alert('SU NAVEGADOR ESTA BLOQUEANDO VENTANAS EMERGENTES');
	NuevaVentana.focus();
	if(destino!='destino')
	{
		var saltoalto=alto/5;
		var saltoancho=ancho/5;
		var nancho=10;
		var nalto=10;
		while(nancho<ancho && nalto<alto)
		{
			nancho+=saltoancho;
			nalto+=saltoalto;
			NuevaVentana.resizeTo(nancho,nalto);
		} // while
		NuevaVentana.resizeTo(ancho,alto);
		if(mouse)
		{
			if(mouseX+ancho>screen.availWidth) mouseX=screen.availWidth-ancho;
			if(mouseY+alto>screen.availHeight) mouseY=screen.availHeight-alto-100;
			NuevaVentana.moveTo(mouseX,mouseY);
		}
	}
}


function s_alto(){
	return screen.availHeight;
}

function s_ancho(){
	return screen.availWidth;
}

function valida_entrada(usuario,clave,perfil,CP,MF)
{
	if(perfil)
	window.open('valida_entrada.php?IDuser='+usuario+'&clave='+clave+'&PerFil='+perfil+(CP?'&CAMBIA_PERFIL=1':'')+(MF?'&MODOFECHA='+MF:''),'destino');
	else
	window.open('valida_entrada.php?IDuser='+usuario+'&clave='+clave+'&PerFil='+perfil+(CP?'&CAMBIA_PERFIL=1':'')+(MF?'&MODOFECHA='+MF:''),'_self');
}

function crea_perfil(comando)
{
	modal('marcoindex.php?Acc=selecciona_perfil&SESION_PUBLICA=1&C='+comando,0,0,screen.availWidth,screen.availHeight,'destino');
}

function mata_perfil()
{
	window.open('marcoindex.php?Acc=mata_perfil&SESION_PUBLICA=1','_self');
}


function pickcolor(Formulario,Campo,Dato)
{
	left=0;top=0;
	alto=350;
	ancho=400;
	destino='Recogecolor';
	Dato=Dato.replace(/#/,'');
	url='html/colorpicker/index.php?Forma='+Formulario+'&Campo='+Campo+'&Dato='+Dato;

	if(window.showModalDialog)
	{
		var caracteristicas="height="+alto+", width="+ancho+", channelmode=0, location=0, toolbar=0, directories=0,status=0, linemenubar=0, menubar=0, modal=1, innerleft="+left+", innertop="+top+", dialog=1,resizable=1, scrollbars=1";
		var NuevaVentana = window.open(url, destino, caracteristicas);
		if(mouseX+ancho>screen.availWidth) mouseX=screen.availWidth-ancho;
		if(mouseY+alto>screen.availHeight) mouseY=screen.availHeight-alto-100;
		NuevaVentana.moveTo(mouseX,mouseY);
	}
	else
	{
		var caracteristicas = "height="+alto+", width="+ancho+", channelmode=0, location=0, toolbar=0, directories=0,status=0, linemenubar=0, menubar=0, modal=1, innerleft="+left+", innertop="+top+", dialog=1,resizable=1, scrollbars=1";
		var NuevaVentana = window.open(url,destino,caracteristicas);
		if(mouseX+ancho>screen.availWidth) mouxeX=screen.availWidth-ancho;
		if(mouseY+alto>screen.availHeight) mouseY=screen.availHeight-alto-100;
		NuevaVentana.moveTo(mouseX,mouseY);
		NuevaVentana.focus();
	}
}

function cambiacolor(Color,Nombre_tabla,idcampo,ncampo)
{
	var WC=window.open('','CambioColor','width=100,height=100,toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,dependent=1,resizable=0,z-lock=1');
	var doc = WC.document;
	doc.open("text/html", "replace");
	doc.write("<HTML> <TITLE>Cambio de Color</TITLE><head><script src='inc/js/funciones.js'></script></head>");
	doc.write("<BODY onload=\"pickcolor('cambiocolor','Color','"+Color+"');\" onfocus='document.cambiocolor.submit();'>");
	doc.write("<form action='marcoindex.php' name='cambiocolor'>");
	doc.write("<input type='hidden' name='Acc' value='cambio_color' >");
	doc.write("<input type='hidden' name='Nombre_tabla' value='"+Nombre_tabla+"'>");
	doc.write("<input type='hidden' name='idcampo' value='"+idcampo+"'>");
	doc.write("<input type='hidden' name='ncampo' value='"+ncampo+"'>");
	doc.write("<input type='hidden' name='Color' value='"+Color+"'><input type='submit' value='Cambiar Color' ></form>");
	doc.write("</BODY></HTML>");
	doc.close();
}

function centrar(ancho,alto)
{
	if(!ancho) ancho=s_ancho()-10;
	if(!alto) alto=s_alto()-10;
	window.resizeTo(ancho,alto);
	window.moveTo((screen.availWidth-ancho)/2,(screen.availHeight-alto)/2);
}

function esquina(ancho,alto,esq)
{
	if(!esq) esq='supder';
	if(!ancho) ancho=s_ancho()/2;
	if(!alto) alto=s_alto()/2;
	window.resizeTo(ancho,alto);
	switch(esq)
	{
		case 'supder':	window.moveTo((screen.availWidth-ancho),1);break;
		case 'supizq':	window.moveTo(1,1);break;
		case 'infiz1':	window.moveTo(1,(screen.availHeight-alto));break;
		case 'infder':	window.moveTo((screen.availWidth-ancho),(screen.availHeight-alto));break;
	}
}

function modifica_registro(Num_Tabla,Id,Solover,Cerrar_ventana)
{
	V_ancho=screen.availWidth-60;V_alto=screen.availHeight-80;
	modal('marcoindex.php?Acc=mod_reg&Num_Tabla='+Num_Tabla+'&id='+Id+'&sV='+Solover+'&CERRAR_VENTANA='+Cerrar_ventana,5,10,V_alto,V_ancho,'Adicionar_modificar');
}


function abrir_tabla(Num_Tabla,destino,parametros)
{
	V_ancho=screen.availWidth-60;V_alto=screen.availHeight-80;
	modal('marcoindex.php?Acc=abre_tabla&Num_Tabla='+Num_Tabla+'&D_tag='+destino+'&'+parametros,5,10,V_alto,V_ancho,destino);
}

/**
 *
 * @access public
 * @return void
 **/
function vbuscando()
{
	var caracteristicas = "height=200, width=300, channelmode=0, location=0, toolbar=0, directories=0,status=0, linemenubar=0, menubar=0, modal=1, left="+((screen.availWidth-300)/2)+", top="+(screen.availHeight-100)/2+", dialog=1, scrollbars=1 ";
	var VVbuscando = window.open('','vbuscando',caracteristicas);
	var doc = VVbuscando.document;
	doc.open("text/html", "replace");
	doc.write("<HTML> <TITLE>BUSCANDO</TITLE>");
	doc.write("<BODY onload='window.focus();'>");
	doc.write("<H3>Buscando información...</H3><center><img src='gifs/buscando.gif' border=0>&nbsp;&nbsp;<img src='gifs/pc1.gif' border=0>&nbsp;&nbsp;<img src='gifs/buscando.gif' border=0></center>");
	doc.write("</BODY></HTML>");
	doc.close();
	VVbuscando.focus();
}

function cierrabuscando()
{
	var VVbuscando = window.open('','vbuscando');
	VVbuscando.close();
}

/**
 *
 * @access public
 * @return void
 **/
function menu_inicio()
{
	if(document.all)
	{
		Posicion='Relative';
		menu_pos=s_alto()-85;
	}
	else
	{
		borde=0;
		Posicion='Fixed';
		menu_pos=window.innerHeight-40;
		menu_alto=menu_pos-40;
		menu_ancho=170;
		Posicion_left=30;
		document.write("<iframe id='MEN_inicio' name='MEN_inicio' height='22' width='54' style='position:"+Posicion+";top:"+menu_pos+";left:0;border-style:solid;border-width:0px;background-color:transparent;z-index:100;' border=0 frameborder='no' scrolling='no' src='marcoindex.php?Acc=menu_inicio'></iframe>");
		document.write("<iframe id='MEN_1' name='MEN_1' height='"+menu_alto+"' width='"+(menu_ancho+50)+"' style='position:Fixed;top:40;left:30;border-style:solid;background-color:transparent;visibility:hidden;border-width:"+borde+"px;z-index:100;' border="+borde+" frameborder='no' scrolling='auto' ></iframe>");
		Posicion_left+=menu_ancho;
		document.write("<iframe id='MEN_2' name='MEN_2' height='"+menu_alto+"' width='"+(menu_ancho+50)+"' style='position:Fixed;top:40;left:"+Posicion_left+";border-style:solid;background-color:transparent;visibility:hidden;border-width:"+borde+"px;z-index:100;' border="+borde+" frameborder='no' scrolling='auto' ></iframe>");
		Posicion_left+=menu_ancho;
		document.write("<iframe id='MEN_3' name='MEN_3' height='"+menu_alto+"' width='"+(menu_ancho+50)+"' style='position:Fixed;top:40;left:"+Posicion_left+";border-style:solid;background-color:transparent;visibility:hidden;border-width:"+borde+"px;z-index:100;' border="+borde+" frameborder='no' scrolling='auto' ></iframe>");
		Posicion_left+=menu_ancho;
		document.write("<iframe id='MEN_4' name='MEN_4' height='"+menu_alto+"' width='"+(menu_ancho+50)+"' style='position:Fixed;top:40;left:"+Posicion_left+";border-style:solid;background-color:transparent;visibility:hidden;border-width:"+borde+"px;z-index:100;' border="+borde+" frameborder='no' scrolling='auto' ></iframe>");
		Posicion_left+=menu_ancho;
		document.write("<iframe id='MEN_5' name='MEN_5' height='"+menu_alto+"' width='"+(menu_ancho+50)+"' style='position:Fixed;top:40;left:"+Posicion_left+";border-style:solid;background-color:transparent;visibility:hidden;border-width:"+borde+"px;z-index:100;' border="+borde+" frameborder='no' scrolling='auto' ></iframe>");
	}
}

/**
 *
 * @access public
 * @return void
 **/
function cerrar_menu_inicio()
{
	if(document.getElementById('MEN_1'))
	{
		document.getElementById('MEN_1').style.visibility='hidden';
		document.getElementById('MEN_2').style.visibility='hidden';
		document.getElementById('MEN_3').style.visibility='hidden';
		document.getElementById('MEN_4').style.visibility='hidden';
		document.getElementById('MEN_5').style.visibility='hidden';
	}
}

function verificanumero(Evento,Nodo)
{
	var keynum;
	var Caracter;
	if(window.event) // IE
		keynum = Evento.keyCode;
	else if(Evento.which) // Netscape/Firefox/Opera
		keynum = Evento.which;
	if(keynum==8 || keynum==13  || keynum==110 || keynum==190 || keynum==37 || keynum==39 || keynum==46 || keynum==9 ||
		keynum==16 || keynum==17 || keynum==18 || keynum==27 || keynum==20 || keynum==144 ||
		(keynum>95 && keynum<106) || (keynum>=48 && keynum<=57))
	{
		return true;
	}
	else
	{
		alert('Caracer no permitido '+keynum);
		var Objc;
		var Texto;
		Objc=document.getElementById(Nodo);
		Texto=Objc.value.toUpperCase();
		Objc.value=Texto.replace(Caracter,'');
		Texto=solonumeros(Objc.value);
		Objc.value=Texto;
		Objc.style.backgroundColor='#ffddbb';
	}
}

function solonumeros(cadena)
{
	var Validos='0123456789.';
	var i;
	var j;
	var ok;

	do
	{
		ok=false;
		for(i=0;i<cadena.length;i++)
		{
			if(Validos.search(cadena[i])<0)
			{
				cadena=cadena.replace(cadena[i],'');
				ok=true;
			}
		}
	}
	while(ok && cadena.length>0)
	return cadena;
}

function activa_edicion(NT)
{
	var ventana=document.getElementById('Edicion_'+NT);
	if(window.innerHeight) ventana.height=window.innerHeight-50;
	else if((document.body) && (document.body.clientHeight)) ventana.height=document.body.clientHeight-50;
	if(window.innerWidth) ventana.width=window.innerWidth-60;
	else if((document.body) && (document.body.clientWidth)) ventana.width=document.body.clientWidth-60;
	ventana.style.visibility='visible';
	ventana.focus();
}

function oculta_edicion(NT,refrescando)
{

	if(!refrescando) refrescando=true; else refrescando=false;
	if(parent.document.getElementById('Edicion_'+NT))
	{
		var ventana=parent.document.getElementById('Edicion_'+NT);
		var refrescar=parent.document.location;
	}
	else
	{
		if(document.getElementById('Edicion_'+NT))
		{
			var ventana=document.getElementById('Edicion_'+NT);
			var refrescar=document.location;
		}
		else
		{
			window.close();
			void(null);
			opener.location.reload();
		}
	}
	if(ventana)
	{
	  ventana.src='marcoindex.php?Acc=cargando_informacion';
		ventana.style.visibility='hidden';
		ventana.height=0;
	}
	if(refrescando) parent.location=refrescar;
}

function leerCookie(nombre) 
{
	a = document.cookie.substring(document.cookie.indexOf(nombre + '=') + nombre.length + 1,document.cookie.length);
	if(a.indexOf(';') != -1)a = a.substring(0,a.indexOf(';'))
	return a; 	
} 

function setCookie(name, value, expires, path, domain, secure)
{
  document.cookie =
    name+"="+escape(value)+
    (expires ? "; expires="+expires.toGMTString() : "")+
    (path    ? "; path="   +path   : "")+
    (domain  ? "; domain=" +domain : "")+
    (secure  ? "; secure" : "");
}

function setCookieLT(name, value, lifetime, path, domain, secure)
{
  if (lifetime) lifetime = new Date(Date.parse(new Date())+lifetime*1000);
  setCookie(name, value, lifetime, path, domain, secure);
}

function getCookie(name)
{
  var cookie, offset, end;
  cookie  = " "+document.cookie;
  offset  = cookie.indexOf(" "+name+"=");
  if (offset == -1) return undefined;
  offset += name.length+2;
  end     = cookie.indexOf(";", offset)
  if (end    == -1) end = cookie.length;
  return unescape(cookie.substring(offset, end));
}

function delCookie(name, path, domain)
{
  if (getCookie(name))
    setCookie(name, "", new Date("January 01, 2000 00:00:01"), path, domain);
}


// *********************************************************************************************************************************


















