if (document.images) {

	img1 = new Image();
	img2 = new Image();
	img3 = new Image();

	img1.src = "img/menu/menu_mig_hover.gif";
	img2.src = "img/menu/menu_dreta_hover.gif";
	img3.src = "img/menu/menu_esquerra_hover.gif";

}


function borrar_cistella(id){
	if(confirm("Estás seguro de quitar este producto de la cesta de la compra?")){
		location.href="cesta-compra.php?accio=borrar&id="+id;
	}
}


function canvi_cistella(id,unitats){
	location.href="cesta-compra.php?accio=actualitzar&id="+id+"&unitats="+unitats;
}


function cl_butlleti(){
	f=document.formbutlleti;
	if(f.butlleti_m.value.length==0)f.butlleti_m.value="Introduce tu e-mail";
}

function bl_butlleti(){
	f=document.formbutlleti;
	if(f.butlleti_m.value=="Introduce tu e-mail")f.butlleti_m.value="";
}

function isValidEmail(str) {
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function alta_butlleti(){
	f=document.formbutlleti;
	if(f.butlleti_m.value.length=="0") alert("Introduce tu email");
	else if(!isValidEmail(f.butlleti_m.value)) alert("El email introducido no es correcto");
	else {
		//envia_formulari_ajax(f,'alta_boletin.php','ajax_butlleti',false,false);
		f.submit();
	}
	
	return false;
}

function recuperar_pass(){
	f=document.form_recuperar;
	if(f.g_email.value.length=="0") alert("Introduce tu email");
	else if(!isValidEmail(f.g_email.value)) alert("El email introducido no es correcto");
	else {
		f.submit();
	}
	
	return false;
}


function login(){
	f=document.formlogin;
	if(f.login_u.value.length==0) alert("Introduce tu e-mail");
	else if(!isValidEmail(f.login_u.value)) alert("El e-mail introducido no es correcto");
	else if(f.login_p.value.length==0) alert("Introduce tu contraseña");
	else f.submit();
}

function guardar_dades_enviament(){
	f=document.form_envio;
	if(f.g_nom.value.length=="0") alert("Introduce tu nombre");
	else if(f.g_cognom1.value.length=="0") alert("Introduce tu primer apellido");
	else if(f.g_cognom2.value.length=="0") alert("Introduce tu segundo apellido");
	else if(f.g_email.value.length=="0") alert("Introduce tu e-mail de contacto");
	else if(!isValidEmail(f.g_email.value)) alert("El e-mail introducido no es correcto");
	else if(f.g_telefon1.value.length=="0") alert("Introduce tu teléfono de contacto");
	else if(f.g_direccio.value.length=="0") alert("Introduce la dirección de envio");
	else if(f.g_numero.value.length=="0") alert("Introduce el número de bloque o casa");
	else if(f.g_codi_postal.value.length<5) alert("Introduce el código postal");
	else if(f.g_poblacio.value.length=="0") alert("Introduce la población");
	else if(!f.condicions.checked) alert("Para continuar debes leer y aceptar las condiciones generales");
	else f.submit();
}

function guardar_dades_enviament_min(){
	f=document.form_envio;
	if(!f.condicions.checked) alert("Para continuar debes leer y aceptar las condiciones generales");
	else f.submit();
}

function alta_usuario(){
	f=document.form_envio;
	if(f.g_nom.value.length=="0") alert("Introduce tu nombre");
	else if(f.g_cognom1.value.length=="0") alert("Introduce tu primer apellido");
	else if(f.g_cognom2.value.length=="0") alert("Introduce tu segundo apellido");
	else if(f.g_email.value.length=="0") alert("Introduce tu e-mail de contacto");
	else if(!isValidEmail(f.g_email.value)) alert("El e-mail introducido no es correcto");
	else if(f.g_telefon.value.length=="0") alert("Introduce tu teléfono de contacto");
	else if(f.g_direccio.value.length=="0") alert("Introduce la dirección de envio");
	else if(f.g_numero.value.length=="0") alert("Introduce el número de bloque o casa");
	else if(f.g_codi_postal.value.length<5) alert("Introduce el código postal");
	else if(f.g_poblacio.value.length=="0") alert("Introduce la población");
	else if(f.g_contrasenya.value.length<3) alert("Introduce la contraseña de acceso");
	else if(f.contrasenya2.value.length<3) alert("Repite la contraseña de acceso");
	else if(f.g_contrasenya.value != f.contrasenya2.value) alert("Las contraseñas indicadas no coinciden");
	else if(!f.condicions.checked) alert("Para continuar debes leer y aceptar las condiciones generales");
	else f.submit();
}



function guardar_datos_personales(){
	f=document.form_envio;
	if(f.g_nom.value.length=="0") alert("Introduce tu nombre");
	else if(f.g_cognom1.value.length=="0") alert("Introduce tu primer apellido");
	else if(f.g_cognom2.value.length=="0") alert("Introduce tu segundo apellido");
	else if(f.g_email.value.length=="0") alert("Introduce tu e-mail de contacto");
	else if(!isValidEmail(f.g_email.value)) alert("El e-mail introducido no es correcto");
	else if(f.g_telefon.value.length=="0") alert("Introduce tu teléfono de contacto");
	else if(f.g_direccio.value.length=="0") alert("Introduce la dirección de envio");
	else if(f.g_numero.value.length=="0") alert("Introduce el número de bloque o casa");
	else if(f.g_codi_postal.value.length<5) alert("Introduce el código postal");
	else if(f.g_poblacio.value.length=="0") alert("Introduce la población");
	else if(f.g_contrasenya.value.length>=3 && (f.g_contrasenya.value != f.contrasenya2.value) ) alert("Las contraseñas indicadas no coinciden");
	else f.submit();
}

function afegir_direccio(){
	f=document.form_envio;
	if (f.g_nom_direccio.value.length=="0") alert("Introduce un nombre descriptivo para la dirección");
	else if(f.g_direccio.value.length=="0") alert("Introduce la dirección de envio");
	else if(f.g_numero.value.length=="0") alert("Introduce el número de bloque o casa");
	else if(f.g_codi_postal.value.length<5) alert("Introduce el código postal");
	else if(f.g_poblacio.value.length=="0") alert("Introduce la población");
	else f.submit();
}

function selecciona_pagament(n,tr,to){
	document.getElementById("pagament1").className="tipo_pagament";
	document.getElementById("pagament2").className="tipo_pagament";
	document.getElementById("pagament3").className="tipo_pagament";
	
	HideContent("pagament1_text");
	HideContent("pagament2_text");
	HideContent("pagament3_text");
	
	document.getElementById("pagament"+n).className="tipo_pagament_seleccionat";
	ShowContent("pagament"+n+"_text");
	
	document.getElementById("p_transport").innerHTML="<b>"+tr+" &euro;</b>";
	document.getElementById("p_total").innerHTML="<b>"+to+" &euro;</b>";
	
	if(n=="3"){
		document.getElementById("p_frase_transport").innerHTML='<span class="text">Gastos de envío (</span><a href="tarifas_transporte.php"><u>Tabla de precios de transporte</u></a><span class="text">) + Recargo por contra reembolso</span>';
	}else{
		document.getElementById("p_frase_transport").innerHTML='<span class="text">Gastos de envío (</span><a href="tarifas_transporte.php"><u>Tabla de precios de transporte</u></a><span class="text">)</span>';
	}
	
	
}

function ver_ingredientes(){
	ShowContent("ingredients");
}
function cerrar(){
	HideContent("ingredients");
}

function mostra_menu(num){
	var estat = document.getElementById('menu_extra'+num).style.display;
	if(estat=="block")HideContent('menu_extra'+num);
	else ShowContent('menu_extra'+num);
}

function HideContent(d) {
	if(d.length < 1) { return; }
	document.getElementById(d).style.display = "none";
	
	if(d=="ingredients"){
		ShowContent('form_unitats');
	}
}

function ShowContent(d) {
	if(d.length < 1) { return; }
	document.getElementById(d).style.display = "block";
	
	if(d=="ingredients"){
		HideContent('form_unitats');
		var pageSize	= this.getPageSize();
		document.getElementById(d).style.height = pageSize[1] + "px";

	}
}




function getPageSize(){
		var x,y;
		if (self.innerHeight) // all except Explorer
		{
			x = self.innerWidth;
			y = self.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight)
			// Explorer 6 Strict Mode
		{
			x = document.documentElement.clientWidth;
			y = document.documentElement.clientHeight;
		}
		else if (document.body) // other Explorers
		{
			x = document.body.clientWidth;
			y = document.body.clientHeight;
		}


		var x1,y1;
		var test1 = document.body.scrollHeight;
		var test2 = document.body.offsetHeight
		if (test1 > test2) // all but Explorer Mac
		{
			x1 = document.body.scrollWidth;
			y1 = document.body.scrollHeight;
		}
		else // Explorer Mac;
			 //would also work in Explorer 6 Strict, Mozilla and Safari
		{
			x1 = document.body.offsetWidth;
			y1 = document.body.offsetHeight;
		}

		arrayPageSize = new Array(x,y,x1,y1) 
		return arrayPageSize;

}


function isValidEmail(str) {
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str))
		testresults=true
	else{
		testresults=false
	}
	return (testresults) 
}

function enviar_es(){
	f=document.formul;
	if(f.nom.value.length<5) alert("Falta escribir el nombre y los apellidos");
	else if(!isValidEmail(f.email.value)) alert("Falta escribir el e-mail");
	else if(f.telefon.value.length<9) alert("Falta escribir el teléfono");
	else if(f.comentaris.value.length==0) alert("Falta escribir los comentarios");
	else {
		f.submit();
	}
}








////////////////////////////////////////////////////////////////////////////////////

//english


function alta_usuario_en(){
	f=document.form_envio;
	if(f.g_nom.value.length=="0") alert("Name is missing");
	else if(f.g_cognom1.value.length=="0") alert("Last name 1 is missing");
	else if(f.g_cognom2.value.length=="0") alert("Last name 2 is missing");
	else if(f.g_email.value.length=="0") alert("E-mail is missing");
	else if(!isValidEmail(f.g_email.value)) alert("E-mail not valid");
	else if(f.g_telefon.value.length=="0") alert("Phone number is missing");
	else if(f.g_direccio.value.length=="0") alert("Address is missing");
	else if(f.g_numero.value.length=="0") alert("Number is missing");
	else if(f.g_codi_postal.value.length<5) alert("Postal code is missing");
	else if(f.g_poblacio.value.length=="0") alert("City is missing");
	else if(f.g_contrasenya.value.length<3) alert("Password is missing");
	else if(f.contrasenya2.value.length<3) alert("Repeat the password");
	else if(f.g_contrasenya.value != f.contrasenya2.value) alert("Passwords don't match.");
	else if(!f.condicions.checked) alert("You have to accept the general conditions.");
	else f.submit();
}



function enviar_en(){
	f=document.formul;
	if(f.nom.value.length<5) alert("Name and last name are missing");
	else if(!isValidEmail(f.email.value)) alert("E-mail is missing");
	else if(f.telefon.value.length<9) alert("Phone is missing");
	else if(f.comentaris.value.length==0) alert("Comments are missing");
	else {
		f.submit();
	}
}


function cl_butlleti_en(){
	f=document.formbutlleti;
	if(f.butlleti_m.value.length==0)f.butlleti_m.value="Introduce your e-mail";
}

function bl_butlleti_en(){
	f=document.formbutlleti;
	if(f.butlleti_m.value=="Introduce your e-mail")f.butlleti_m.value="";
}

function alta_butlleti_en(){
	f=document.formbutlleti;
	if(f.butlleti_m.value.length=="0") alert("Introduce your e-mail");
	else if(!isValidEmail(f.butlleti_m.value)) alert("E-mail address is incorrect");
	else {
		//envia_formulari_ajax(f,'alta_boletin.php','ajax_butlleti',false,false);
		f.submit();
	}
	
	return false;
}


function borrar_cistella_en(id){
	if(confirm("Are you sure?")){
		location.href="shopping-cart.php?accio=borrar&id="+id;
	}
}

function canvi_cistella_en(id,unitats){
	location.href="shopping-cart.php?accio=actualitzar&id="+id+"&unitats="+unitats;
}


function login_en(){
	f=document.formlogin;
	if(f.login_u.value.length==0) alert("Login is missing");
	else if(!isValidEmail(f.login_u.value)) alert("Login is incorrect");
	else if(f.login_p.value.length==0) alert("Password is missing");
	else f.submit();
}


function guardar_datos_personales_en(){
	f=document.form_envio;

	if(f.g_nom.value.length=="0") alert("Name is missing");
	else if(f.g_cognom1.value.length=="0") alert("Last name 1 is missing");
	else if(f.g_cognom2.value.length=="0") alert("Last name 2 is missing");
	else if(f.g_email.value.length=="0") alert("E-mail is missing");
	else if(!isValidEmail(f.g_email.value)) alert("E-mail not valid");
	else if(f.g_telefon.value.length=="0") alert("Phone number is missing");
	else if(f.g_direccio.value.length=="0") alert("Address is missing");
	else if(f.g_numero.value.length=="0") alert("Number is missing");
	else if(f.g_codi_postal.value.length<5) alert("Postal code is missing");
	else if(f.g_poblacio.value.length=="0") alert("City is missing");
	
	else if(f.g_contrasenya.value.length>=3 && (f.g_contrasenya.value != f.contrasenya2.value) ) alert("Passwords don't match.");
	else f.submit();
}


function guardar_dades_enviament_min_en(){
	f=document.form_envio;
	if(!f.condicions.checked) alert("You have to accept the general conditions");
	else f.submit();
}


function afegir_direccio_en(){
	f=document.form_envio;
	if (f.g_nom_direccio.value.length=="0") alert("Description is missing");
	else if(f.g_direccio.value.length=="0") alert("Address is missing");
	else if(f.g_numero.value.length=="0") alert("Number is missing");
	else if(f.g_codi_postal.value.length<5) alert("Postal code is missing");
	else if(f.g_poblacio.value.length=="0") alert("City is missing");
	else f.submit();
}


function selecciona_pagament_en(n,tr,to){
	document.getElementById("pagament1").className="tipo_pagament";
	document.getElementById("pagament2").className="tipo_pagament";
	document.getElementById("pagament3").className="tipo_pagament";
	
	HideContent("pagament1_text");
	HideContent("pagament2_text");
	HideContent("pagament3_text");
	
	document.getElementById("pagament"+n).className="tipo_pagament_seleccionat";
	ShowContent("pagament"+n+"_text");
	
	document.getElementById("p_transport").innerHTML="<b>"+tr+" &euro;</b>";
	document.getElementById("p_total").innerHTML="<b>"+to+" &euro;</b>";
	
	if(n=="3"){
		document.getElementById("p_frase_transport").innerHTML='<span class="text">Postage and packing (</span><a href="carriage_table.php"><u>carriage charge table</u></a><span class="text">) + Extra charge</span>';
	}else{
		document.getElementById("p_frase_transport").innerHTML='<span class="text">Postage and packing (</span><a href="carriage_table.php"><u>carriage charge table</u></a><span class="text">)</span>';
	}
	
	
}