function insertFlash(movie,variables,ancho,alto){
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+ancho+'" height="'+alto+'" align="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain">');
	document.write('<param name="scale" value="noscale">');
	document.write('<param name="menu" value="false">');
	document.write('<param name="flashVars" value="'+variables+'">');
	document.write('<param name="bgcolor" value="#ffffff">');
	document.write('<param name="movie" value="'+movie+'">');
	document.write('<param name="quality" value="high">');
	document.write('<param name="wmode" value="transparent">');
	document.write('<embed src="'+movie+'" quality="high" scale="noscale" bgcolor="#ffffff" align="middle" allowScriptAccess="sameDomain" pluginspage="http://www.macromedia.com/go/getflashplayer" menu="false" flashVars="'+variables+'" wmode="transparent" type="application/x-shockwave-flash" width="'+ancho+'" height="'+alto+'"></embed>');
	document.write('</object>');
}
function validaMail(direccion){
    var mailres = true;            
    var cadena = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890@._-";    
    var arroba = direccion.indexOf("@",0);
    if ((direccion.lastIndexOf("@")) != arroba) arroba = -1;    
    var punto = direccion.lastIndexOf(".");                
     for (var contador = 0 ; contador < direccion.length ; contador++){
        if (cadena.indexOf(direccion.substr(contador, 1),0) == -1){
            mailres = false;
            break;
     	}
    }
    if ((arroba > 1) && (arroba + 1 < punto) && (punto + 2 < (direccion.length)) && (mailres == true) && (direccion.indexOf("..",0) == -1))
     mailres = true;
    else
     mailres = false;                
    return mailres;
}
function ErrorMade(texto){	
	alert(texto);	
}
var arrErrores = new Array();
function errores(valor){
	ultimaPos = arrErrores.length;
	arrErrores[ultimaPos] = valor;
}
function cargaRespuestas(lang){		
	if(lang == "esp"){		
		Resp = new Array();
		Resp[1] = "Escribe tu Nombre";
		Resp[2] = "Escribe tus Apellidos";
		Resp[3] = "Escribe tu E-mail";
		Resp[4] = "E-mail no válido";
		Resp[5] = "Introduce tu población";
		Resp[6] = "Introduce tu provincia";
		return Resp;	
	}else if(lang == "eng"){	
		Reng = new Array();
		Reng[1] = "Name";
		Reng[2] = "Surname";
		Reng[3] = "E-mail";
		Reng[4] = "E-mail no correct";
		Resp[5] = "Fill in your town";
		Resp[6] = "Fill in your city";
		return Reng;		
	}else{	
		Rcat = new Array();
		Rcat[1] = "Escriu el teu Nom";
		Rcat[2] = "Escriu els teus Cognoms";
		Rcat[3] = "Escriu el teu E-mail";
		Rcat[4] = "E-mail no vàlid";
		Resp[5] = "Escriu la teva població";
		Resp[6] = "Escriu la teva província";
		return Rcat;		
	}	
}
function validaFormContacto(lang){	
	respuestas = cargaRespuestas(lang);
	arrErrores = new Array();		
	if(document.contactar.nom.value == ""){															
		errores(respuestas[1]);
	}		
	if(document.contactar.cognoms.value == ""){															
		errores(respuestas[2]);
	}		
	if(document.contactar.email.value == ""){															
		errores(respuestas[3]);
	}		
	if(document.contactar.email.value != "" && !validaMail(document.contactar.email.value)){															
		errores(respuestas[4]);
	}	
	longitudErrores = arrErrores.length;	
	if(longitudErrores < 1){		
		document.contactar.submit(); 
		//return true;
	}else{		
		texto = "";		
		for(a=0;a<longitudErrores;a++){			
			texto += arrErrores[a];
			texto += "\n";
		}		
		ErrorMade(texto);
		//return false;
	}	
}
function validaCestaEnvio(lang){	
	respuestas = cargaRespuestas(lang);
	arrErrores = new Array();		
	if(document.enviar.nom.value == ""){															
		errores(respuestas[1]);
	}		
	if(document.enviar.cognoms.value == ""){															
		errores(respuestas[2]);
	}		
	if(document.enviar.poblacio.value == ""){															
		errores(respuestas[5]);
	}	
	if(document.enviar.provincia.value == ""){															
		errores(respuestas[6]);
	}		
	if(document.enviar.email.value == ""){															
		errores(respuestas[3]);
	}		
	if(document.enviar.email.value != "" && !validaMail(document.enviar.email.value)){															
		errores(respuestas[4]);
	}	
	longitudErrores = arrErrores.length;	
	if(longitudErrores < 1){		
		document.enviar.submit(); 		
	}else{		
		texto = "";		
		for(a=0;a<longitudErrores;a++){			
			texto += arrErrores[a];
			texto += "\n";
		}		
		ErrorMade(texto);
	}	
}
function cambia(etiqueta, imagen){
	document.getElementById(etiqueta).src = imagen;
}
////////////////////////////////////
//
//// TIENDA //
//
/////////////////////
function cantidadMenos(existe, id){
	cantidad = document.cantidades.cantidad.value;
	if(cantidad != 1) cantidad--;
	document.cantidades.cantidad.value = cantidad;	
	if(existe == 1){
		cargar_contenido ('anyadir_producto.php?id=' + id + '&q=' + cantidad, 'cpGenerator');
	}
}
function cantidadMas(existe, id){
	cantidad = document.cantidades.cantidad.value;
	cantidad++;
	document.cantidades.cantidad.value = cantidad;
	if(existe == 1){
		cargar_contenido ('anyadir_producto.php?id=' + id + '&q=' + cantidad, 'cpGenerator');
	}
}
function anyade(id){
	cantidad = document.cantidades.cantidad.value;
	document.getElementById('btafegir').src = 'img/icons/selecto.png';
	cargar_contenido ('anyadir_producto.php?id=' + id + '&q=' + cantidad, 'cpGenerator');
}
function eliminaProduct(pos){
	cargar_contenido ('eliminar_producto.php?pos=' + pos, 'cpCesta');
}
function iraCesta(lang, num, domain){	
	if(num != 0 || document.getElementById('btafegir').src == 'http://' + domain + '/img/icons/selecto.png'){		
		document.location.href = "cesta.php?lang=" + lang;	
	}else{
		resp = new Array();
		resp['esp'] = "No has añadido ningún producto a la cesta";
		resp['eng'] = "You have not added any products to cart";
		resp['cat'] = "No has afegit cap producte a la cistella";
		alert(resp[lang]);
	}
}
function cantidadMenosCesta(id, preu){
	cantidad = eval("document.cantidades.cantidad" + id).value;
	if(cantidad != 1){
		cantidad--;
		eval("document.cantidades.cantidad" + id).value = cantidad;	
		cargar_contenido ('anyadir_producto.php?id=' + id + '&q=' + cantidad, 'cpGenerator');
		document.getElementById('cpTotales').innerHTML -= 1;
		totalpreu = Number(document.getElementById('cpTotalPrice').innerHTML);
		document.getElementById('cpTotalPrice').innerHTML = totalpreu - Number(preu);
		totalLine = Number(document.getElementById('cpTotalLinePrice' + id).innerHTML);
		document.getElementById('cpTotalLinePrice' + id).innerHTML = totalLine - preu;
	}
}
function cantidadMasCesta(id, preu){
	cantidad = eval("document.cantidades.cantidad" + id).value;
	cantidad++;
	eval("document.cantidades.cantidad" + id).value = cantidad;
	cargar_contenido ('anyadir_producto.php?id=' + id + '&q=' + cantidad, 'cpGenerator');
	document.getElementById('cpTotales').innerHTML = Number(document.getElementById('cpTotales').innerHTML) + 1;
	totalpreu = Number(document.getElementById('cpTotalPrice').innerHTML);
	document.getElementById('cpTotalPrice').innerHTML = totalpreu + Number(preu);
	totalLine = Number(document.getElementById('cpTotalLinePrice' + id).innerHTML);
	document.getElementById('cpTotalLinePrice' + id).innerHTML = totalLine + preu;
}
//////

ventanas=new Array();
function abre(destino,name,ancho,alto){
	
	anchura="";
	altitud="";
	anchura+="width=";
	anchura+=ancho;
	altitud+="height=";
	altitud+=alto;
	tamany="";
	tamany=anchura;
	tamany+=",";
	tamany+=altitud;
	tamany+=",scrollbars=yes";
	
            if (ventanas[name]!=undefined) ventanas[name].close();{	
	ventanas[name]=window.open(destino,name,tamany);
			}			
	
	x = (screen.width - ancho) / 2;
    y = (screen.height - alto) / 2;
    ventanas[name].moveTo(x, y);
}

///////

function condiciones(lang){
	
	abre('condiciones.php?lang=' + lang, 'condis', 400, 500);
}