var es_firefox=(navigator.userAgent.indexOf("Firefox")!=-1)?true:false;

function aEntero(valor, valorNaN, valorNull)
{
	try
	{
		var n=parseInt(valor);
		if(isNaN(n)) n=valorNaN;
		return n;
	}
	catch(e){}
	return valorNull;
}

function IrA(destino)
{
	location.href=destino;
}

function IrAURL(destino)
{
	window.open(destino);	
}

function IrAVN(destino,parametros)
{
	IrAN2(destino,'',parametros);
}

function IrAVN2(destino,nombre,parametros)
{
	if(parametros.length==0)
		parametros='width=700,height=500,top=10,left=10,resizable=yes,scrollbars=yes';
	window.open(destino,nombre,parametros);
	return true;
}

function ControlTextArea(C,S,T)
{
	var t=T-T_CTArea(C);
	if(t<0)
	{
		C_CTArea(C,T);
		t=T-T_CTArea(C);
	}
	if(S!='')
		eval('window.document.forms.'+S+'.value='+(t));
}
function T_CTArea(C)
{
	var t=eval('window.document.forms.'+C+'.value'),D='\1\2\3',o='\n';
	if(es_firefox)
		D+='\4';
	while(t.search(o)>=0)
		t=t.replace(o,D);
	return t.length;
}
function C_CTArea(C,T)
{
	var t=eval('window.document.forms.'+C+'.value'),D='\1\2\3',o='\n';
	if(es_firefox)
		D+='\4';
	while(t.search(o)>=0)t=t.replace(o,D);if (t.charAt(t.length-3)=='\1' && t.length>T)
		t=t.substring(0,t.length-4);
	t=t.substring(0,T);
	while(t.search(D)>=0)
		t=t.replace(D,o);
	t=t.replace('\1','');
	t=t.replace('\2','');
	t=t.replace('\3','');
	if(es_firefox)
		t=t.replace('\4','');
	eval('window.document.forms.'+C+'.value=t');
}


// Validación
function EmailOk(dato)
{
	var arroba=0, punto=0;
	for(var i=0;i<dato.length;i++)
	{
		if(dato.charAt(i)==' ')return false;
		if(dato.charAt(i)=='@')arroba++;
		if(dato.charAt(i)=='.')punto++;
	}
	if(arroba!=1 || punto<1) return false;
	
	return true;
}

function FechaOk(d,m,a)
{
	var anyo=new Number(a),mes=new Number(m),dia=new Number(d);
	if (isNaN(anyo)||isNaN(mes)||isNaN(dia))
		return false;
	if (anyo<1||anyo>9999)
		return false;
	if (mes<1||mes>12)
		return false;
	if ((mes==1||mes==3||mes==5||mes==7||mes==8||mes==10||mes==12)&&(dia<1||dia>31))
		return false;
	if ((mes==4||mes==6||mes==9||mes==11)&&(dia<1||dia>30))
		return false;
	if (mes==2)
	{
		var df=(((anyo%4==0)&&((!(anyo%100==0))||(anyo%400==0)))?29:28);
		if (dia<1||dia>df)
			return false;
	}
	return true;
}

function fsubmenu(Q)
{
	obj=document.getElementById(Q);
	if(obj.style.display=="")obj.style.display="none"; else obj.style.display="";
}

