var ymouse=0; var xmouse=0;
var mouseX, mouseY;
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_capa(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_capa(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 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=yes, chrome=yes, location=0, toolbar=0, directories=0,status=0, statusbar=0, linemenubar=0, menubar=0, modal=yes, left="+left+", top="+top+", resizable, scrollbars";

	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/20;
		var saltoancho=ancho/20;
		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=no, chrome=yes, location=0, toolbar=0, directories=0,status=0,statusbar=0, linemenubar=0, menubar=1, modal=yes, left="+left+", top="+top+", resizable, scrollbars";
	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/20;
		var saltoancho=ancho/20;
		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_campos(forma,campos)
{

	if(campos.length>0)
	{
		var fallos=false;
		var fallon=false;
		Arreglo_campos = campos.split(",");
		for(i=0;i<Arreglo_campos.length;i++)
		{
			Arreglo_campo= Arreglo_campos[i].split(':');
			if(Arreglo_campo[1]!='n')
			{
				var campo= "if(document."+forma+"."+Arreglo_campo[0]+".value=='') {document."+forma+"."+Arreglo_campo[0]+".style.backgroundColor='#ffbbbb';fallos=true;}";
				eval(campo);
			}
			if(Arreglo_campo[1]=='n')
			{
				var campo= "if(isNaN(document."+forma+"."+Arreglo_campo[0]+".value) || document."+forma+"."+Arreglo_campo[0]+".value=='') {document."+forma+"."+Arreglo_campo[0]+".style.backgroundColor='#bbffbb';fallon=true;}";
				eval(campo);
			}
		}
		if(fallos) {alert('Debe diligenciar la información correspondiente a los campos rosados.');  }
		if(fallon) {alert('Debe diligenciar la información NUMERICA (sin comas) correspondiente a los campos verdes.');  }
		if(!fallon && !fallos) eval("document."+forma+".submit();");
	}
	else
	eval("document."+forma+".submit();");
}


function pickcolor(Formulario,Campo,Dato)
{
	alto=400;left=0;
	ancho=400;top=0;
	destino='colores';
	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=yes, innerleft="+left+", innertop="+top+", dialog=yes,resizable, scrollbars";
		var NuevaVentana = window.open(url, destino, caracteristicas);
		if(xmouse+ancho>screen.availWidth) xmouse=screen.availWidth-ancho;
		if(ymouse+alto>screen.availHeight) ymouse=screen.availHeight-alto-100;
		NuevaVentana.moveTo(xmouse,ymouse);
	}
	else
	{
		var caracteristicas = "height="+alto+", width="+ancho+", channelmode=0, location=0, toolbar=0, directories=0,status=0, linemenubar=0, menubar=0, modal=yes, innerleft="+left+", innertop="+top+", dialog=yes,resizable, scrollbars";
		var NuevaVentana = window.open(url,destino,caracteristicas);
		xmouse=mouseX; ymouse=mouseY;
		if(xmouse+ancho>screen.availWidth) xmouse=screen.availWidth-ancho;
		if(ymouse+alto>screen.availHeight) ymouse=screen.availHeight-alto-100;
		NuevaVentana.moveTo(xmouse,ymouse);
		NuevaVentana.focus();
	}
}

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 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;
}

