/***************************************

CambiaIdioma(IdiomaOut)

IdiomaOut = Idioma al que queremos cambiar.

Funcion para el cambio de idioma. Intentaremos hacer dinamicamente el cambio de idioma

mirando lo que pone en el top.location y cambiando de es a cat y de cat a es correspondientemente



***************************************/



function CambiaIdioma(IdiomaOut){

	var myString = new String(document.location); 

	var myArray1 = myString.split('?'); 
	
	var myArray2 = myArray1[0].split('/'); 
	

	if(myArray1.length!=1){
		window.top.location='../'+IdiomaOut+'/'+myArray2[eval(myArray2.length-1)]+'?'+myArray1[1];
		//alert('../'+IdiomaOut+'/'+myArray2[eval(myArray2.length-1)]+'?'+myArray1[1])
	}
	else{
		window.top.location='../'+IdiomaOut+'/'+myArray2[eval(myArray2.length-1)]+'';
		//alert('../'+IdiomaOut+'/'+myArray2[eval(myArray2.length-1)])
	}
	

}

/***************************************

CargaPagina(Pagina)

Pagina= Pagina a la que se queire redireccionar en relativo



***************************************/

function CargaPagina(Pagina){
	location.href=Pagina;
}

/***************************************

PintaFecha()

Funcion para pintar la fecha.

	getDate() - Devuelve el d�a del mes de 1 a 31

	getDay() - Devuelve el d�a de la semana de 0 a 6

	getMonth() - Devuelve el mes actual de 0 a 11, si queremos mostrar la fecha en formato dd/mm/yyy, tendremos que sumar uno a este valor.

	getFullYear() - Devuelve el a�o en formato YYYY

	getYear() - Devuelve el a�o en formato YY

	getHours() - Devuelve la hora de 0 a 23

	getMinutes() - Devuelve los minutos de 0 a 59

	getSeconds() - Devuelve los segundos de 0 a 59

	getMilliseconds() - Devuelve los milisegundos (0-999)

	getTime() - Devuelve la fecha unix (N�mero de milisegundos desde medianoche del 1 de enero de 1970)

	getTimezoneOffset() - Zona hor�ria del visitante

***************************************/



miFechaActual = new Date() 



diasemanahoy = miFechaActual.getDay();

diahoy = miFechaActual.getDate();

meshoy = miFechaActual.getMonth();

anohoy = miFechaActual.getFullYear();



function PintaFecha(){

	FechaActual="	"+DiaSemana[eval(diasemanahoy-1)]+", "+diahoy+" "+MesAno[meshoy]+" "+anohoy+"";

	document.write(FechaActual);

}

function PintaMes(){
var mes = MesAno[meshoy];
    return mes;
}

function PintaFechaCAT(){

	FechaActual="	"+DiaSemanaCAT[eval(diasemanahoy-1)]+", "+diahoy+" "+MesAnoCAT[meshoy]+" "+anohoy+"";

	document.write(FechaActual);

}

function PintaMesCAT(){
    return MesAnoCAT[meshoy];
}

/*Ejecuta el video dentro del popUp 'popUpContenido'*/
function EjecutaVideo(NombreVideo, idioma){
 ContenidoVideo='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="566" height="364">';
 ContenidoVideo+='<param name="movie" value="../../swf/'+NombreVideo+'.swf" />';
 ContenidoVideo+='<param name="quality" value="medium" />';
 ContenidoVideo+='<param NAME=wmode VALUE=opaque>';
 ContenidoVideo+='<embed src="../../swf/'+NombreVideo+'.swf" quality="medium" wmode=opaque pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="566" height="364"></embed>';
 ContenidoVideo+='</object>';
 document.getElementById('PopUpContenido').innerHTML=ContenidoVideo;
 popup_show('PopUpEnvio', 'PopUpDrag', 'PopUpExit', 'screen-center', 20,  20);	
 document.getElementById('PopUpEnvio').style.width="576px";  //mismo ancho que tiene el objeto de visualización más 10 para los bordes
}

/*Muestra la imagen dentro del popUp*/
function MuestraImage(ArhivoImage, TextoPie){
        var contenidoPopUp = document.getElementById('PopUpContenido');

        //borramos todo lo que hubiera en el contenido del popUp
	while(contenidoPopUp.childNodes.length > 0){	       
		contenidoPopUp.removeChild(contenidoPopUp.firstChild);
        }             

	//añadimos la image
 	var imagen = document.createElement("img");
	imagen.setAttribute("src", "../../img/"+ArhivoImage);
	imagen.setAttribute("id", "imgPopUp");
	contenidoPopUp .appendChild(imagen );

        //si hay pide de página lo añadimos
        if(TextoPie != null){
        	var pieFoto = document.createElement("p");
                pieFoto.setAttribute("id", "pieFoto");
	        var pieFotoTxt = document.createTextNode(TextoPie);
	        pieFoto.appendChild(pieFotoTxt);
        	contenidoPopUp.appendChild(pieFoto);
        }




        //mostramos el popup
	popup_show('PopUpEnvio', 'PopUpDrag', 'PopUpExit', 'mouse', 0,  0);

        //esta nyapa es para que se muestre bien en explorer 6 y 7
        var width = ( (pieFoto != null) && (pieFoto.offsetWidth > imagen.offsetWidth)) ? (pieFoto.offsetWidth + 10) : (imagen.offsetWidth + 10); //10 del padding

        document.getElementById('PopUpEnvio').style.width=width+"px";         
}

/*Ejecuta el video dentro del popUp 'popUpContenido'*/
function EjecutaVideoNz(NombreVideo, idioma){
 ContenidoVideo='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="566" height="364">';
 ContenidoVideo+='<param name="movie" value="'+NombreVideo+'" />';
 ContenidoVideo+='<param name="quality" value="medium" />';
 ContenidoVideo+='<param NAME=wmode VALUE=opaque>';
 ContenidoVideo+='<embed src="'+NombreVideo+'" quality="medium" wmode=opaque pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="566" height="364"></embed>';
 ContenidoVideo+='</object>';
 document.getElementById('PopUpContenido').innerHTML=ContenidoVideo;
 popup_show('PopUpEnvio', 'PopUpDrag', 'PopUpExit', 'screen-center', 20,  20);	
 document.getElementById('PopUpEnvio').style.width="576px";  //mismo ancho que tiene el objeto de visualización más 10 para los bordes
}


/*Muestra la imagen dentro del popUp*/
function MuestraImageNz(ArhivoImage, TextoPie){
        var contenidoPopUp = document.getElementById('PopUpContenido');

        //borramos todo lo que hubiera en el contenido del popUp
	while(contenidoPopUp.childNodes.length > 0){	       
		contenidoPopUp.removeChild(contenidoPopUp.firstChild);
        }             

	//añadimos la image
 	var imagen = document.createElement("img");
	imagen.setAttribute("src", ArhivoImage);
	imagen.setAttribute("id", "imgPopUp");
	contenidoPopUp .appendChild(imagen );

        //si hay pide de página lo añadimos
        if(TextoPie != null){
        	var pieFoto = document.createElement("p");
                pieFoto.setAttribute("id", "pieFoto");
	        var pieFotoTxt = document.createTextNode(TextoPie);
	        pieFoto.appendChild(pieFotoTxt);
        	contenidoPopUp.appendChild(pieFoto);
        }




        //mostramos el popup
	popup_show('PopUpEnvio', 'PopUpDrag', 'PopUpExit', 'mouse', 0,  0);

        //esta nyapa es para que se muestre bien en explorer 6 y 7
        var width = ( (pieFoto != null) && (pieFoto.offsetWidth > imagen.offsetWidth)) ? (pieFoto.offsetWidth + 10) : (imagen.offsetWidth + 10); //10 del padding

        document.getElementById('PopUpEnvio').style.width=width+"px";         
}

function CierraVideo(){
 document.getElementById('PopUpContenido').innerHTML="";
}

function lanza_buscador(){
		document.formuBusca.submit();
	}
	function lanza_login(){
		document.formuLogin.submit();
	}


/***********************************************
function EnviaFormulario(Idioma)
Idioma= Idioma en el que se lanza el form

*******************************************/
mensajesES = new Array();
mensajesES[0] = "Gracias por suscribirte a nuestro e-newsletter";
mensajesES[1] = "El campo e-mail es obligatorio";
mensajesES[2] = "Error. El campo e-mail no contiene una dirección de correo electrónico válida";
mensajesES[3] = "Error. No introduzcas tu e-mail si eres usuario registrado.";
mensajesES[4] = "Error. El campo contraseña es obligatorio";
mensajesES[5] = "Error. La contraseña es incorrecta";
mensajesES[6] = "Error. Las contraseñas no coinciden";
mensajesES[7] = "Es obligatorio aceptar la política de privacidad";
mensajesES[8] = "Es oblitagorio aceptar las condiciones de uso";


mensajesCAT = new Array();
mensajesCAT[0] = "Gràcies per subscriure't al nostre e-newsletter";
mensajesCAT[1] = "Error. El camp e-mail és obligatori";
mensajesCAT[2] = "Error. El camp e-mail no conté una adreça electrònica vàlida";
mensajesCAT[3] = "Error. No introdueixis el teu e-mail si ets usuari registrat.";
mensajesCAT[4] = "Error. El camp contrasenya és obligatori";
mensajesCAT[5] = "Error. La contrasenya és incorrecta";
mensajesCAT[6] = "Error. contrasenya no coincide con contrasenya 2";
mensajesCAT[7] = "Es obligatorio aceptar la política de privacidad";
mensajesCAT[8] = "Es oblitagorio aceptar las condiciones de uso";

function valEmail(valor){
    re=/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/
    if(!re.exec(valor))    {
        return false;
    }else{
        return true;
    }
}

function EnviaFormulario(Idioma){
	if(document.FormNew.email.value==''){
		alert(eval('mensajes'+Idioma)[1]);
		document.FormNew.email.focus();
		return;
	}
	else if(!valEmail(document.FormNew.email.value)){
		alert(eval('mensajes'+Idioma)[2]);
		document.FormNew.email.focus();
		return;
	}
	else if(document.FormNew.clave.value==''){
		alert(eval('mensajes'+Idioma)[4]);
		document.FormNew.clave.value='';
                document.FormNew.clave2.value='';
		document.FormNew.clave.focus();
		return;
	}
	else if(document.FormNew.clave2.value==''){
		alert(eval('mensajes'+Idioma)[4]);
		document.FormNew.clave.value='';
                document.FormNew.clave2.value='';
		document.FormNew.clave.focus();
		return;
	}
	else if(document.FormNew.clave.value.length<6 || document.FormNew.clave.value.length>10){
		alert(eval('mensajes'+Idioma)[5]);
		document.FormNew.clave.value='';
                document.FormNew.clave2.value='';
		document.FormNew.clave.focus();
		return;
	}
	else if(document.FormNew.clave.value!=document.FormNew.clave2.value){
		alert(eval('mensajes'+Idioma)[6]);
		document.FormNew.clave.value='';
                document.FormNew.clave2.value='';
		document.FormNew.clave.focus();
		return;
	}
	else if(!document.FormNew.condiciones.checked){
		alert(eval('mensajes'+Idioma)[8]);
		return;
	}
	else {
		document.FormNew.submit();
	}

}

function MuestraAlerta(Idioma,Alerta){
	alert(eval('mensajes'+Idioma)[Alerta]);
		

}

/**
* Función de validación formulario Atención al cliente 
* 17/05/09
*
*/

mensajesAtencionES = new Array();
mensajesAtencionES[0] = "Debes seleccionar un tipo de consulta";
mensajesAtencionES[1] = "Debes escribir tu comentario";

mensajesAtencionCAT = new Array();
mensajesAtencionCAT[0] = "Debes seleccionar un tipo de consulta";
mensajesAtencionCAT[1] = "Debes escribir tu comentario";

function EnviaFormularioAtencionCliente(Idioma){
	if(document.formAtencionCliente.tipo.value==''){
		alert(eval('mensajesAtencion'+Idioma)[0]);
		document.formAtencionCliente.tipo.focus();
		return;
	}
	else if(document.formAtencionCliente.comentarios.value==''){
		alert(eval('mensajesAtencion'+Idioma)[1]);
		document.formAtencionCliente.comentarios.focus();
		return;
	}
        else{
                document.formAtencionCliente.submit();
        }
}


function valEmail(valor){
    re=/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/
    if(!re.exec(valor))    {
        return false;
    }else{
        return true;
    }
}
	
	
function envia_form_ES(){
	if (document.FormEnviaAmigo.tunombre.value=="") { alert("Introduce tu nombre."); }
	else if (document.FormEnviaAmigo.sunombre.value=="") { alert("Introduce el nombre de tu amigo."); }
	else if (document.FormEnviaAmigo.suemail.value=="") { alert("Introduce el email de tu amigo."); }
	else if (!valEmail(document.FormEnviaAmigo.suemail.value)) { alert("El formato del email no es correcto."); }
	else { document.FormEnviaAmigo.submit(); }
}

function envia_form_CAT(){
	if (document.FormEnviaAmigo.tunombre.value=="") { alert("Introduce tu nombre."); }
	else if (document.FormEnviaAmigo.sunombre.value=="") { alert("Introduce el nombre de tu amigo."); }
	else if (document.FormEnviaAmigo.suemail.value=="") { alert("Introduce el email de tu amigo."); }
	else if (!valEmail(document.FormEnviaAmigo.suemail.value)) { alert("El formato del email no es correcto."); }
	else { document.FormEnviaAmigo.submit(); }
}

