var url_fotos = "http://devel.adwod.com/barbadillo/fotos/";
var peso_max = 250;
var ventanaBusqueda = null;
var fotoAux1 = new Image();
var peso_foto = null;
var foto_original = null;
function verVideo (urlVideo)
{
	window.location.href = urlVideo;
}
function verAfoto (key, w_org, h_org, url_foto, peso)
{
	var w = screen.width - 50;
	var h = screen.height - 130;
	foto_original = url_foto;
	if (w_org > w || h_org > h)
	{
		verFoto ("genera_img.php?key=" + key + "&w=" + w + "&h=" + h);
		peso_foto = peso;
	}
	else
	if (peso > peso_max)
	{
		verFoto ("genera_img.php?key=" + key);
		peso_foto = null;
	}
	else
	{
		verFoto (url_foto);
		peso_foto = null;
	}
}
function verFoto (urlFoto)
{
	var cont = "<html><head><title>Ver Foto</title></head>\n";
	cont += "<table width=\"100%\" height=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
	cont += "<tr><td align=center><img src=img/reloj.gif border=0><p><font face=verdana size=1>Generando imagen...<br>Se esta generando la imagen a la medida de la resolucion de tu pantalla. Es posible que lleve algun tiempo, pero el peso de la fotografia final sera menor.</font></td>\n";
	cont += "</tr></table>\n";
	cont += "</body></html>";
	openWindow ("", "ventanaFoto", 200, 200, "no", "no");
	ventanaBusqueda.document.open();
	ventanaBusqueda.moveTo(10,10);
	ventanaBusqueda.document.write (cont);
	ventanaBusqueda.document.close();
	fotoAux1.onload = loadFoto;
	fotoAux1.src = urlFoto;
}
function loadFoto ()
{
	if (!ventanaBusqueda || ventanaBusqueda.closed)
		return (false);
	var w = fotoAux1.width + 10;
	var h = fotoAux1.height + 29 + 45;
	var max_w = screen.width;
	var max_h = screen.height;
	if (w > max_w)
	{
		var w_ini = w;
		w = max_w - 50;
		h = h * w / w_ini;
	}
	if (h > max_h)
	{
		var h_ini = h;
		h = max_h - 75;
		w = w * h / h_ini;
	}
	var foto = null;
	if (peso_foto)
		foto = fotoAux1.src;
	else
		foto = foto_original;
	var cont = "<html><head><title>Ver Foto</title>\n";
	cont += "<script language=\"JavaScript\" src=\"funciones.js\"></script>\n";
	cont += "<style type=\"text/css\">\n";
	cont += "<!--\n";
	cont += ".style1 {\n";
	cont += "font-family: Verdana, Arial, Helvetica, sans-serif;\n";
	cont += "font-size: 9pt;\n";
	cont += "}\n";
	cont += "-->\n";
	cont +="</style></head>\n";
	cont += "<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>\n";
	cont += "<img src=\"" + foto + "\" border=0 galleryimg=no";

if (peso_foto)
	{
		cont += " alt=\"Clic sobre la foto para ver en formato original\nPeso: " + peso_foto + " Kb\" ";
		cont += "style=\"cursor: hand;\" onClick=\"openWindow ('" + foto_original + "', '', " + w + ", " + h + ", 'yes', 'yes');\" ";
	}
	cont += ">\n";
	cont += "<form action=\"send_friend.php\" method=\"post\" name=\"sfriend\" target=\"_blank\">\n";
	cont += "<div align=\"center\"><a href=\"\" class=\"style1\" onClick=\"javascript:document.sfriend.submit();window.close();\">enviar a un amigo</a>\n";
	cont += "<input type=\"hidden\" name=\"afoto\" value=\"" + foto + "\"></div>\n";
	cont += "</form>";
	cont += "</body></html>";
	ventanaBusqueda.resizeTo (w, h);
	//ventanaBusqueda.moveTo (Math.round (screen.width / 2) - Math.round (w / 2), Math.round (screen.height / 2) - Math.round (h / 2));
	ventanaBusqueda.moveTo(10,10);
	//ventanaBusqueda.moveTo (10, 10);
	ventanaBusqueda.document.open();
	ventanaBusqueda.document.write (cont);
	ventanaBusqueda.document.close();
}
function abreVentanaModal (win, form, action, target)
{
	win.onLoad = enviaForm (form, action, target);
}
function enviaForm (form, action, target)
{
	form.submit();
	form.action = action;
	form.target = target;
}
function openWindow (url, name, w, h, scrollbars, resizable)
{
	if (ventanaBusqueda && !ventanaBusqueda.closed)
		ventanaBusqueda.close();
	var left = Math.round (screen.width / 2) - Math.round (w / 2);
	var top = Math.round (screen.height / 2) - Math.round (h / 2);
	ventanaBusqueda = window.open (url, name, "top=" + top + ", left=" + left + ", width=" + w + ", height=" + h + ", scrollbars=" + scrollbars + ", resizable=" + resizable);
	ventanaBusqueda.focus();
}

function correoValido(email)
{
	if(email.length < 6) return false; //la longitud mínima será de 6 caracteres
	if(email.indexOf('@') == -1) return false; //ha de llevar una arroba
	if(email.indexOf('.') == -1) return false; //ha de llevar un punto
	
	var usuario = email.substr(0,email.indexOf('@'));
	if(usuario.length == 0) return false; //ha de tener un nombre de usuario
	
	var host = email.substr(email.indexOf('@')+1,email.lastIndexOf('.')-email.indexOf('@')-1);
	if(host.length == 0) return false; //ha de tener un host
	
	var dominio = email.substr(email.lastIndexOf('.')+1,email.length-email.lastIndexOf('.')-1);
	if(dominio.length < 2 || dominio.length > 3) return false; //ha de tener un dominio (entre 2 y 3 caracteres)
	
	var expreg1 = new RegExp("[A-Za-z0-9]|.|_|-");
	var expreg2 = new RegExp("[A-Za-z]|.");

	//comprobamos que los caracteres sean válidos
	var i;
	for(var i = 0; i < usuario.length; i++)
		if(!expreg1.test(usuario.charAt(i))) return false;
	for(var i = 0; i < host.length; i++)
		if(!expreg1.test(host.charAt(i))) return false;
	for(var i = 0; i < dominio.length; i++)
		if(!expreg2.test(dominio.charAt(i))) return false;

	//si todo ha ido correcto devolvemos verdadero
	return true;
}

