function cambio_idioma(nuevadir, idioma)
	{
	saveCookie('lang',idioma,1);
	location.href=nuevadir
	}


function saveCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000))
		var expires = "; expires="+date.toGMTString()
	}
	else expires = ""
	document.cookie = name+"="+value+expires+"; path=/"
}
function readCookie(name) {
	var nameEQ = name + "="
	var ca = document.cookie.split(';')
	for(var i=0;i<ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length)
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length)
	}
	return null
}
function deleteCookie(name) {
	saveCookie(name,"",-1)
}

function comprobarFormularioContacto(){

		a=comprobarFormularioContacto.arguments;
		formu=encontrarObjeto("formulario");
		for(i=0; i<a.length-2; i=i+3){
				radioB=false;
				checkB=false;
				for (var j=0;j<formu.elements.length;j++) {
						var e = formu.elements[j];
						if (e.name.indexOf(a[i])>=0){
								if ((a[i+1].indexOf("Formato")>=0)&&(a[i+2]!=0)){
										nombre=a[i+1].substring(8,a[i+1].length);
										if (a[i+2]==1){
												if (!(parseInt(eval("formulario."+a[i]+".value")))){alert(a[a.length-1]+": "+nombre);return false;};
										}
										if (a[i+2]==2){
												if (!(checkEmail(eval("formulario."+a[i]+".value")))){alert(a[a.length-1]+": "+nombre);return false;};
										}
										if (a[i+2]==3){
												if (!(checkPhone(eval("formulario."+a[i]+".value")))){alert(a[a.length-1]+": "+nombre);return false;};
										}
								}
								if ((a[i+1]=="Text input")||(a[i+1]=="Text area")){
										if (eval("formulario."+a[i]+".value==''")) {
												alert(a[a.length-2]+": "+a[i+2]);
												return false;
										}
								}
								if (a[i+1]=="SELECT menu"){
										if (e.selectedIndex<0)
												alert(a[a.length-2]+": "+a[i+2]);
								}
								if (a[i+1]=="Radio buttons"){
										if (e.checked) {radioB=true;}
								}
								if (a[i+1]=="Checkbox(es)"){
										if (e.checked) {checkB=true;}
								}
						}
				}
				if ((a[i+1]=="Radio buttons")&&(!radioB)){alert(a[a.length-2]+": "+a[i+2]); return false;}
				if ((a[i+1]=="Checkbox(es)")&&(!checkB)){alert(a[a.length-2]+": "+a[i+2]); return false;}
		}
		
		return true;
}

function comprobarContacto(alerta1,alerta2,alerta3,alerta4,alerta5){
formu=encontrarObjeto("formulario");
	if (formu.nombre.value==""){
		alert(alerta1);
		return false;
	}
	if (formu.comentarios.value==""){
		alert(alerta2);
		return false;
	}
	if (!((formu.telefono.value!="")||(formu.correo.value!=""))){
		alert(alerta3);
		return false;
	}
	if ((!checkPhone(formu.telefono.value))&&(formu.telefono.value!="")){
		alert(alerta4);
		return false;
	}
	if ((!checkEmail(formu.correo.value))&&(formu.correo.value!="")){
		alert(alerta5);
		return false;
	}
	return true;
}

function comprobarContactoMulti(alerta1,alerta3,alerta4,alerta5,alerta6,alerta7){
formu=encontrarObjeto("formulario");
	if (formu.nombre.value==""){
		alert(alerta1);
		return false;
	}
	if (formu.ciudad.value==""){
		alert(alerta7);
		return false;
	}
	if (formu.provincia.value==""){
		alert(alerta6);
		return false;
	}
	if (!((formu.telefono.value!="")||(formu.correo.value!=""))){
		alert(alerta3);
		return false;
	}
	if ((!checkPhone(formu.telefono.value))&&(formu.telefono.value!="")){
		alert(alerta4);
		return false;
	}
	if ((!checkEmail(formu.correo.value))&&(formu.correo.value!="")){
		alert(alerta5);
		return false;
	}
	return true;
}

function checkPhone(text) {
	if (/[0-9]{9}/.test(text)){
		return (true);
	}
	else if (text==""){
		return (true)
	}
	return (false);
}
function checkEmail(text) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(text)){
		return (true);
	}
	else if (text==""){
		return (true)
	}
	return (false);
}

var vent;
function abrirVentana(pag,anchura,altura) {

l=(screen.width-anchura)/2;
t=(screen.height-altura)/2;
eval("vent=window.open('" +pag + "', 'prod','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=" + anchura + ",height=" + altura +",left=" + l + ",top=" + t +"')");
}

function encontrarObjeto(n, d) { 
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=encontrarObjeto(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); 
  return x;
}

function comprobar(f,alerta){
	if (f.texto.value=="") {alert(alerta);return false;}
	if (f.tipo.options[f.tipo.selectedIndex].value==0) {
		eval("window.open('http://www.google.com/search?q=" + f.texto.value + "&hl=es&lr=lang_es','','')");
		return false;
	}
	return true;
}