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(){
    var 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 (!(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((a[i]!='props_survey_field_99')||(!formu.props_survey_field_66.checked && a[i]=='props_survey_field_99')) //Lide:: para que compruebe el campo de establecimiento solo si la casilla de experiencia no esta activada
                 		if (eval("formu."+a[i]+".value==''")) {
                       		alert(a[a.length-2]+": "+a[i+2]);
                       		return false;
                 		}
                }
                
                if (a[i+1]=="SELECT menu"){
                	if(((a[i]!='props_survey_field_95')&&
                		 (a[i]!='props_survey_field_96')&&
                		 (a[i]!='props_survey_field_100'))||
                	   ((!formu.props_survey_field_66.checked)&&
                	    ((a[i]=='props_survey_field_95')||
                		  (a[i]=='props_survey_field_96')||
                		  (a[i]=='props_survey_field_100')))){ //lide:: para que compruebe los desplegables de mes, año y puesto de la primera fila solo si la casilla de experiencia no esta activada
                	 	if (e.selectedIndex<0 
                	 		 /*lide*/ || e.value=='0') {
                	       	alert(a[a.length-2]+": "+a[i+2]);
                	       	return false;
                	   }
                	}
                }
                
                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 mostrarcapa(etik) {
  obj = document.getElementById(etik);
  obj.style.display = 'block';
  //enla.innerHTML = (enla.innerHTML == '[-]') ? '[+]' : '[-]';
}

function ocultarcapa(etik) {
  obj = document.getElementById(etik);
  obj.style.display = 'none';
  //enla.innerHTML = (enla.innerHTML == '[-]') ? '[+]' : '[-]';
} 

function subircapa(etik) {
  obj = document.getElementById(etik);
  obj.style.posTop = -500;
}



function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

function fadeOut(objId,opacity, n) {
  b = eval ("fadeDirUp"+n);
  if( !b ){
    if (document.getElementById) {
      obj = document.getElementById (objId);
      if (opacity >= 0) {
        setOpacity(obj, opacity);
        opacity -= 10;
        window.setTimeout("fadeOut('"+objId+"',"+opacity+", '"+n+"')", 30);
      }else{
        obj.style.visibility = 'hidden';
      }
    }
  }
}

function fadeIn(objId,opacity, n) {
  b = eval("fadeDirUp"+n);
  if( b ){
    if (document.getElementById) {
      obj = document.getElementById(objId);
      obj.style.visibility = 'visible';
      if (opacity <= 100) {
        setOpacity(obj, opacity);
        opacity += 10;
        window.setTimeout("fadeIn('"+objId+"',"+opacity+", '"+n+"')", 100);
      }
    }
  }
}

function fadeImage(imageId, inoout, n) {
  eval("fadeDirUp"+n+" = "+inoout);
  if( inoout ){
    fadeIn(imageId,0,n);
  }else{
    fadeOut(imageId,100,n);
  }
}
