function cambio_idioma(nuevadir, idioma){
	//saveCookie('idioma',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=a[0];
    for(i=1; 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 ((eval("formu."+a[i]+".value")!="0")&&(!(parseInt(eval("formu."+a[i]+".value"))))){alert(a[a.length-1]+": "+nombre);return false;};
                    }
                    if (a[i+2]==2){
                        if (!(checkEmail(eval("formu."+a[i]+".value")))){alert(a[a.length-1]+": "+nombre);return false;};
                    }
                    if (a[i+2]==3){
                        if (!(checkPhone(eval("formu."+a[i]+".value")))){alert(a[a.length-1]+": "+nombre);return false;};
                    }
                }
                if ((a[i+1].indexOf("Extension")>=0)&&(a[i+2]!="")){
                    //COMPROBAR EXTENSIONES
                    nombre=a[i+1].substring(10,a[i+1].length);
                    valores=a[i+2].toLowerCase();
                    campos=valores.split(";");
                    var encontrado=false;
                    var valor=eval("formu."+a[i]+".value").toLowerCase();
                    if (valor==''){encontrado=true;}
                    else{
                      for (z=0;z<campos.length;z++){
                        if (valor.indexOf("."+campos[z])>=0){
                          encontrado=true;
                        }
                      }
                    }
                    if (!encontrado){alert(a[a.length-1]+": "+nombre);return false;}
                }
                if ((a[i+1]=="Text input")||(a[i+1]=="Text area")||(a[i+1]=="File")){
                    if (eval("formu."+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 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);
}

function abrirVentana(pag,anchura,altura) {
  var vent;
  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 recargar_lapagina(direccion,segundos){
  //ahora voy a generar un string para enviarlo por parámetro a esta misma página
//el parámetro lo pasaremos por URL. 
//No haremos nada con ese dato, pero como cada vez será distinto, nos asegura que el navegador siempre solocitará al servidor la página, en vez de mostrar otra vez la que tiene en caché
//utilizaremos la fecha y tiempo para generar el dato
miFecha = new Date();
dato_url = miFecha.getYear().toString() + miFecha.getMonth().toString() + miFecha.getDate().toString() + miFecha.getHours().toString() + miFecha.getMinutes().toString() + miFecha.getSeconds().toString();
//para recargar la página con un retardo utilizaremos la función setTimeout()
//recibe el primer parámetro la instrucción que se quiere ejecutar
//segundo parámetro es el tiempo en milisegundos que se quiere esperar
var tiempo=segundos * 1000;
var direccion2=direccion.split("&t=");
//alert(direccion2);
setTimeout("window.location='"+direccion2+ "&t="+dato_url+"'", tiempo);
}
