// -------------------------------- //
// Funcions javascript per EBA 2007 //
// -------------------------------- //

// Funcio per obrir una finestra flotant
function obreFinestra(nom) {
		amplada = 760;
		alcada = 430;
		esquerra = (screen.width) ? (screen.width-amplada)/2 : 0;
		dalt = (screen.height) ? (screen.height-alcada)/2 : 0;
		props ='height='+alcada+',width='+amplada+',top='+dalt+',left='+esquerra+',scrollbars=yes,resizable=yes';
		window.open(nom,'',props)
	}
function obreComs(nom) {
		amplada = 800;
		alcada = 500;
		esquerra = (screen.width) ? (screen.width-amplada)/2 : 0;
		dalt = (screen.height) ? (screen.height-alcada)/2 : 0;
		props ='height='+alcada+',width='+amplada+',top='+dalt+',left='+esquerra+',scrollbars=yes,resizable=yes';
		window.open(nom,'',props)
	}

// Validació de formularis
function validar_esp(f) 
{
	if (f.nom.value.length <= 0)
	{
		alert("Por favor, introduce el nombre");
		f.nom.focus();
		return false;
	}
	else
	{
		if (f.cognoms.value.length <= 0)
		{
		alert("Por favor, introduce los apellidos");
		f.cognoms.focus();
		return false;
		}
		else
		{
			if (f.email.value.length <= 0)
			{
				alert("Por favor, introduce un email");
				f.email.focus();
				return false;
			}
			else
			{
				correu=f.email.value;
				if(correu.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1)
				{
					alert("Por favor, introduce un email válido");
					f.email.focus();
					return false;
				}
				else
				{
					tel=f.telefon.value;
					mob=f.mobil.value;
					if ((tel.length <= 0)&&(mob.length <= 0))
					{
						alert("Por favor, introduce un teléfono o móvil de contacto");
						f.telefon.focus();
						return false;
					}
					else
					{
						if (tel.length > 0)
						{	
							if (tel.search(/^\d+$/) == -1)
							{
							alert("Por favor, introduce sólo números en el teléfono\nPor ej. 0034937398986");
							f.telefon.focus();
							return false;
							}
						}
						if (mob.length > 0)
						{
							if (mob.search(/^\d+$/) == -1)
							{
							alert("Por favor, introduce sólo números en el móvil\nPor ej. 0034937398986");
							f.mobil.focus();
							return false;
							}
						}						
						if (f.empresa.value.length <= 0)
						{
							alert("Por favor, introduce el nombre de la empresa");
							f.empresa.focus();
							return false;
						}						
						else
						{
						document.forms[0].submit();
						}//else - empresa ple
					}//else - tel o mòbil ple					
				}//else - email vàlid
			}//else - email ple
		}//else - cognoms ple
	}//else - noms ple
	return false;
}

function validar_cat(f) 
{
	if (f.nom.value.length <= 0)
	{
		alert("Si us plau, introdueixi el nom!");
		f.nom.focus();
		return false;
	}
	else
	{
		if (f.cognoms.value.length <= 0)
		{
		alert("Si us plau, introdueixi els cognoms!");
		f.cognoms.focus();
		return false;
		}
		else
		{
			if (f.email.value.length <= 0)
			{
			alert("Si us plau, introdueixi el teu email!");
			f.email.focus();
			return false;
			}
			else
			{
				correu=f.email.value;
				if(correu.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1)
				{
					alert("Si us plau, introdueixi un email vàlid!");
					f.email.focus();
					return false;
				}
				else
				{
					tel=f.telefon.value;
					mob=f.mobil.value;
					if ((tel.length <= 0)&&(mob.length <= 0))
					{
						alert("Si us plau, introdueixi un telèfon o un mòbil de contacte!");
						f.telefon.focus();
						return false;
					}
					else
					{
						if (tel.length > 0)
						{
							if (tel.search(/^\d+$/) == -1)
							{
							alert("Si us plau, introdueixi només números al telèfon de contacte!\nPer ex. 0034937398986");
							f.telefon.focus();
							return false;
							}
						}
						if (mob.length > 0)
						{
							if (mob.search(/^\d+$/) == -1)
							{
							alert("Si us plau, introdueixi només números al mòbil de contacte!\nPer ex. 0034937398986");
							f.mobil.focus();
							return false;
							}
						}						
						if (f.empresa.value.length <= 0)
						{
							alert("Si us plau, introdueixi el nom de l'empresa!");
							f.empresa.focus();
							return false;
						}						
						else
						{
						document.forms[0].submit();
						}//else - empresa ple
					}//else - tel o mòbil ple
				} //else - email vàlid
			}//else - email ple
		}//else - cognoms ple
	}//else - nom ple
	return false;
}
