function ValidaFormularios(controles)
{
	for ( i = 0, n = controles.length; i < n; i++ )
 	{
	var iControl = controles[i];
  	var e = document.getElementById(iControl[0]);
  		if (e)
  		{
   			if ( e.value.length == 0 )
   			{
    			alert("El campo " + iControl[1] + " está vacío.");
    			e.focus();
    			return 0;
   			}
  		}
 	}
}

function ValidaMails(mails)
{
	var filtro = /^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/;
	
	for ( i = 0, n = mails.length; i < n; i++ )
 	{
		var iMail = mails[i];
  		var e = document.getElementById(iMail[0]);
		if (e)
  		{
   			if ( e.value.length > 0 )
   			{
				var s = e.value;
				if (!filtro.test(s))
				{
					alert("El campo " + iMail[1] + " no es válido.");
    				e.focus();
    				return 0;
				}
			}			
   		}
  	}	
}

function ValidaURL(url) {
var re=/^(http:|https:|ftp:)\/\/\w+(\.\w+)*(\-\w+)?\.\w{2,3}(\:\d{2,6})?(\/{1,2}(\:|\-|\w|\.|\?|\/|\=|\&|\%|\@|\\|\,)*)?$/;
return re.test(url);
}


function Numeros(e)
{
	var key = (document.all) ? e.keyCode : e.which;
	if (key < 48 || key > 57)
	{
		return false;
	}
	else
	{
		return true;	
	}
}

function PaginacionSubmit(i,por,order)
{
	document.paginar.page.value=i;
	document.paginar.por.value=por;
	document.paginar.order.value=order;
	document.paginar.submit();
	
}

function SubmitID(id, command)
{
	var myForm = document.getElementById('formid');	
	myForm.command.value = command;
	myForm.id.value = id;
	myForm.submit();
}

/* DIVS DESPLEGABLE */

function mostrar(blo,off,on)
{
	OCULTO="none";
	VISIBLE="block";
	if(blo != "")
	{
		document.getElementById(blo).style.display=VISIBLE;

	}
	if(on != "")
	{
		document.getElementById(on).style.display=OCULTO;
	}
	if(off != "")
	{
		document.getElementById(off).style.display=VISIBLE;
	}
}
function ocultar(blo,off,on)
{
	OCULTO="none";
	VISIBLE="block";
	if(blo != "")
	{
		document.getElementById(blo).style.display=OCULTO;
	}
	if(off != "")
	{
		document.getElementById(off).style.display=OCULTO;
	}
	if(on != "")
	{
		document.getElementById(on).style.display=VISIBLE;
	}
}


/////////////////Login/////////////////////////////
function ValidaLogin()
{
	var obj = document.getElementById('autentificacion');
	
	var controles = Array(
  	Array("usuario",   	"Usuario"),
  	Array("password",	"Contraseña")
	);
	
	var respuesta = ValidaFormularios(controles);
 	
	if(respuesta == 0)
	{
		return false;
	}

	return true
}


function ValidaEmail()
{
	var obj = document.getElementById('forgotp');
	
	var controles = Array(
  	Array("user",   	"Usuario"),
  	Array("mail",		"E-mail")
	);
	
	var mails = Array(
  	Array("mail",		"E-mail")
	);
	
	var respuesta = ValidaFormularios(controles);
 	if(respuesta == 0)
	{
		return false;
	}
	
	var respuesta = ValidaMails(mails);
 	if(respuesta == 0)
	{
		return false;
	}
	return true
}

function popUp(URL) 
{
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=660,height=420,left = 262,top = 259');");
}



