// JavaScript Document
//Abre las ventanas secundarias
function ventanaSecundaria (URL, ancho, alto, barra_desplazamiento){
//   window.open(URL,"ventana1","width=120,height=300,scrollbars=yes")
   window.open(URL,"ventana1","left=250, top=250, width="+ancho+",height="+alto+",scrollbars="+barra_desplazamiento)
}
function aviso_legal (){
//   window.open(URL,"ventana1","width=120,height=300,scrollbars=yes")
   window.open('http://www.ereza.es/aviso_legal.php','ventana1','left=250, top=250, width=500,height=300,scrollbars=yes');
}
function ver_mapa (url){
//   window.open(URL,"ventana1","width=120,height=300,scrollbars=yes")
   window.open(url,'ventana1','left=250, top=250, width=590,height=489,scrollbars=yes');
}

function cambiar_imagen(imagen) {
	document.images['id_imagen'].src = imagen;
}
//***********************
// Formulario Contacto
//***********************
var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/;
var xmlHttp;
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	 {
	 // Firefox, Opera 8.0+, Safari
	 xmlHttp=new XMLHttpRequest();
	 }
	catch (e)
	 {
	 //Internet Explorer
	 try
	  {
	  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	  }
	 catch (e)
	  {
	  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	 }
	return xmlHttp;
}

function validarCorreoContacto (formulario, lang)
{

	switch(lang)
	{
	case 'en':
	  txt_alerta = 'All the boxes have to be completed.';
	  text_email = 'Email, bad format.';
	  text_enviando = 'Sending email ...';
	  txt_correcto = 'The email has been sent successfully. If you would like to submit another form click <a href="contact.php?lang='+lang+'">here</a>.';
	  txt_error = 'Failed to send mail. Please try again later.';
	  break;		
	case 'es':
	  txt_alerta = 'Todos los campos son obligatorios.';
	  text_email = 'Email, formato no válido.';
	  text_enviando = 'Enviando email ...';	  
	  txt_correcto = 'El correo ha sido enviado correctamente. Si desea enviar otro formulario pinche <a href="contacto.php?lang='+lang+'">aqu&iacute;</a>.';
	  txt_error = 'No se ha podido enviar el correo. Por favor, int&eacute;ntelo m&aacute;s tarde.';	  
	  break;
	case 'de':
	  txt_alerta = 'Alle Felder müssen ausgefüllt werden.';
	  text_email = 'Email, bad format.';
	  text_enviando = 'Sending email ...';	  
	  txt_correcto = 'Die E-Mail wurde erfolgreich gesendet. Wenn Sie möchten, dass eine andere Form finden Sie <a href="contacto.php?lang='+lang+'">hier</a>.';
	  txt_error = 'Fehler beim E-Mails senden. Bitte versuchen Sie es sp&auml;ter erneut.';	  
	  break;
	default:
	  txt_alerta = 'All the boxes have to be completed.';
	  text_email = 'Email, bad format.';
	  text_enviando = 'Sending email ...';	  
	  txt_correcto = 'The email has been sent successfully. If you would like to submit another form click <a href="contacto.php?lang='+lang+'">here</a>.';
	  txt_error = 'Failed to send mail. Please try again later.';	  
	}	
	if (formulario.nombre.value== "")
	{
			     alert(txt_alerta);
				 formulario.nombre.select();
                 return false;
	}	
	if (formulario.email.value== "")
	{
			     alert(txt_alerta);
				 formulario.email.select();
                 return false;
	}
	var returnval=emailfilter.test(formulario.email.value)
	if (returnval==false)
	{
			alert(text_email);		
			formulario.email.select();
			return false;
	}
	if (formulario.telefono_fijo.value== "")
	{
			     alert(txt_alerta);
				 formulario.telefono_fijo.select();
                 return false;
	}	
	if (formulario.comentario.value== "")
	{
			     alert(txt_alerta);
				 formulario.comentario.select();
                 return false;
	}			
	document.getElementById("enviando_correo").innerHTML=text_enviando;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Lo sentimos, pero su navegador no soportar peticiones HTTP");
		return false;
	}		
	var url="acciones/envio_contacto.php";
	url=url+"?email="+formulario.email.value;	 
	url=url+"&nombre="+formulario.nombre.value;	 
	url=url+"&telefono_fijo="+formulario.telefono_fijo.value;	 
	url=url+"&comentario="+formulario.comentario.value;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=estadoEnvio;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	return false;
}

function estadoEnvio()
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{	 
     tmp_st=xmlHttp.responseText;
	 if (tmp_st.substring(0,2) == "ok") {	
	 	document.getElementById("enviando_correo").innerHTML=txt_correcto;
		return false;
	 }
	 else 
	 {	
		document.getElementById("enviando_correo").innerHTML=txt_error;
		return false;
	 }
	}
}
//***********************
// Formulario online1
//***********************
function validarOnline1 (formulario, lang)
{

	switch(lang)
	{
	case 'en':
	  txt_alerta = 'All the boxes have to be completed.';
	  text_email = 'Email, bad format.';
	  text_enviando = 'Sending email ...';
	  txt_correcto = 'The question has been sent successfully.';
	  txt_error = 'Failed to send question. Please try again later.';
	  break;		
	case 'es':
	  txt_alerta = 'Todos los campos son obligatorios.';
	  text_email = 'Email, formato no válido.';
	  text_enviando = 'Enviando email ...';	  
	  txt_correcto = 'La consulta ha sido enviado correctamente.';
	  txt_error = 'No se ha podido enviar la consulta. Por favor, int&eacute;ntelo m&aacute;s tarde.';	  
	  break;
	case 'de':
	  txt_alerta = 'Alle Felder müssen ausgefüllt werden.';
	  text_email = 'Email, bad format.';
	  text_enviando = 'Sending email ...';	  
	  txt_correcto = 'Die E-Mail wurde erfolgreich gesendet.';	  
	  break;
	default:
	  txt_alerta = 'All the boxes have to be completed.';
	  text_email = 'Email, bad format.';
	  text_enviando = 'Sending email ...';	  
	  txt_correcto = 'The question has been sent successfully.';
	  txt_error = 'Failed to send question. Please try again later.';	  
	}	
	if (formulario.nombre.value== "")
	{
			     alert(txt_alerta);
				 formulario.nombre.select();
                 return false;
	}	
	if (formulario.empresa.value== "")
	{
			     alert(txt_alerta);
				 formulario.empresa.select();
                 return false;
	}	
	if (formulario.email.value== "")
	{
			     alert(txt_alerta);
				 formulario.email.select();
                 return false;
	}
	var returnval=emailfilter.test(formulario.email.value)
	if (returnval==false)
	{
			alert(text_email);		
			formulario.email.select();
			return false;
	}
	if (formulario.telefono_fijo.value== "")
	{
			     alert(txt_alerta);
				 formulario.telefono_fijo.select();
                 return false;
	}	
	if (formulario.comentario.value== "")
	{
			     alert(txt_alerta);
				 formulario.comentario.select();
                 return false;
	}			
	document.getElementById("enviando_correo").innerHTML=text_enviando;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Lo sentimos, pero su navegador no soportar peticiones HTTP");
		return false;
	}		
	var url="acciones/envio_online1.php";
	url=url+"?email="+formulario.email.value;
	url=url+"&empresa="+formulario.empresa.value;
	url=url+"&nombre="+formulario.nombre.value;	 
	url=url+"&telefono_fijo="+formulario.telefono_fijo.value;	 
	url=url+"&comentario="+formulario.comentario.value;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=estadoEnvioOnline1;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	return false;
}

function estadoEnvioOnline1()
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{	 
     tmp_st=xmlHttp.responseText;
	 if (tmp_st.substring(0,2) == "ok") {	
	 	document.getElementById("enviando_correo").innerHTML=txt_correcto;
		return false;
	 }
	 else 
	 {	
		document.getElementById("enviando_correo").innerHTML=txt_error;
		return false;
	 }
	}
}
//***********************
// Formulario online2
//***********************
function validarOnline2 (formulario, lang)
{

	switch(lang)
	{
	case 'en':
	  txt_alerta = 'All the boxes have to be completed.';
	  text_email = 'Email, bad format.';
	  text_enviando = 'Sending email ...';
	  txt_correcto = 'The question has been sent successfully.';
	  txt_error = 'Failed to send question. Please try again later.';
	  break;		
	case 'es':
	  txt_alerta = 'Todos los campos son obligatorios.';
	  text_email = 'Email, formato no válido.';
	  text_enviando = 'Enviando email ...';	  
	  txt_correcto = 'La consulta ha sido enviado correctamente.';
	  txt_error = 'No se ha podido enviar la consulta. Por favor, int&eacute;ntelo m&aacute;s tarde.';	  
	  break;
	case 'de':
	  txt_alerta = 'Alle Felder müssen ausgefüllt werden.';
	  text_email = 'Email, bad format.';
	  text_enviando = 'Sending email ...';	  
	  txt_correcto = 'Die E-Mail wurde erfolgreich gesendet.';	  
	  break;
	default:
	  txt_alerta = 'All the boxes have to be completed.';
	  text_email = 'Email, bad format.';
	  text_enviando = 'Sending email ...';	  
	  txt_correcto = 'The question has been sent successfully.';
	  txt_error = 'Failed to send question. Please try again later.';	  
	}	
	if (formulario.nombre.value== "")
	{
			     alert(txt_alerta);
				 formulario.nombre.select();
                 return false;
	}	
	if (formulario.empresa.value== "")
	{
			     alert(txt_alerta);
				 formulario.empresa.select();
                 return false;
	}	
	if (formulario.email.value== "")
	{
			     alert(txt_alerta);
				 formulario.email.select();
                 return false;
	}
	var returnval=emailfilter.test(formulario.email.value)
	if (returnval==false)
	{
			alert(text_email);		
			formulario.email.select();
			return false;
	}
	if (formulario.telefono_fijo.value== "")
	{
			     alert(txt_alerta);
				 formulario.telefono_fijo.select();
                 return false;
	}	
	if (formulario.comentario.value== "")
	{
			     alert(txt_alerta);
				 formulario.comentario.select();
                 return false;
	}			
	document.getElementById("enviando_correo").innerHTML=text_enviando;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Lo sentimos, pero su navegador no soportar peticiones HTTP");
		return false;
	}		
	var url="acciones/envio_online2.php";
	url=url+"?email="+formulario.email.value;
	url=url+"&empresa="+formulario.empresa.value;
	url=url+"&nombre="+formulario.nombre.value;	 
	url=url+"&telefono_fijo="+formulario.telefono_fijo.value;	 
	url=url+"&comentario="+formulario.comentario.value;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=estadoEnvioOnline2;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	return false;
}

function estadoEnvioOnline2()
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{	 
     tmp_st=xmlHttp.responseText;
	 if (tmp_st.substring(0,2) == "ok") {	
	 	document.getElementById("enviando_correo").innerHTML=txt_correcto;
		return false;
	 }
	 else 
	 {	
		document.getElementById("enviando_correo").innerHTML=txt_error;
		return false;
	 }
	}
}
//***********************
// Formulario online3
//***********************
function validarOnline3 (formulario, lang)
{

	switch(lang)
	{
	case 'en':
	  txt_alerta = 'All the boxes have to be completed.';
	  text_email = 'Email, bad format.';
	  text_enviando = 'Sending email ...';
	  txt_correcto = 'The question has been sent successfully.';
	  txt_error = 'Failed to send question. Please try again later.';
	  break;		
	case 'es':
	  txt_alerta = 'Todos los campos son obligatorios.';
	  text_email = 'Email, formato no válido.';
	  text_enviando = 'Enviando email ...';	  
	  txt_correcto = 'La consulta ha sido enviado correctamente.';
	  txt_error = 'No se ha podido enviar la consulta. Por favor, int&eacute;ntelo m&aacute;s tarde.';	  
	  break;
	case 'de':
	  txt_alerta = 'Alle Felder müssen ausgefüllt werden.';
	  text_email = 'Email, bad format.';
	  text_enviando = 'Sending email ...';	  
	  txt_correcto = 'Die E-Mail wurde erfolgreich gesendet.';	  
	  break;
	default:
	  txt_alerta = 'All the boxes have to be completed.';
	  text_email = 'Email, bad format.';
	  text_enviando = 'Sending email ...';	  
	  txt_correcto = 'The question has been sent successfully.';
	  txt_error = 'Failed to send question. Please try again later.';	  
	}	
	if (formulario.nombre.value== "")
	{
			     alert(txt_alerta);
				 formulario.nombre.select();
                 return false;
	}	
	if (formulario.empresa.value== "")
	{
			     alert(txt_alerta);
				 formulario.empresa.select();
                 return false;
	}	
	if (formulario.email.value== "")
	{
			     alert(txt_alerta);
				 formulario.email.select();
                 return false;
	}
	var returnval=emailfilter.test(formulario.email.value)
	if (returnval==false)
	{
			alert(text_email);		
			formulario.email.select();
			return false;
	}
	if (formulario.telefono_fijo.value== "")
	{
			     alert(txt_alerta);
				 formulario.telefono_fijo.select();
                 return false;
	}	
	if (formulario.comentario.value== "")
	{
			     alert(txt_alerta);
				 formulario.comentario.select();
                 return false;
	}			
	document.getElementById("enviando_correo").innerHTML=text_enviando;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Lo sentimos, pero su navegador no soportar peticiones HTTP");
		return false;
	}		
	var url="acciones/envio_online3.php";
	url=url+"?email="+formulario.email.value;
	url=url+"&empresa="+formulario.empresa.value;
	url=url+"&nombre="+formulario.nombre.value;	 
	url=url+"&telefono_fijo="+formulario.telefono_fijo.value;	 
	url=url+"&comentario="+formulario.comentario.value;
	url=url+"&nombre_sociedad1="+formulario.nombre_sociedad1.value;
	url=url+"&nombre_sociedad2="+formulario.nombre_sociedad2.value;
	url=url+"&nombre_sociedad3="+formulario.nombre_sociedad3.value;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=estadoEnvioOnline3;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	return false;
}

function estadoEnvioOnline3()
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{	 
     tmp_st=xmlHttp.responseText;
	 if (tmp_st.substring(0,2) == "ok") {	
	 	document.getElementById("enviando_correo").innerHTML=txt_correcto;
		return false;
	 }
	 else 
	 {	
		document.getElementById("enviando_correo").innerHTML=txt_error;
		return false;
	 }
	}
}
//***********************
// Formulario registro
//***********************
function validarRegistro (formulario, lang)
{
	switch(lang)
	{
	case 'en':
	  txt_alerta = 'All the boxes have to be completed.';
	  text_email = 'Email, bad format.';
	  text_enviando = 'Sending email ...';
	  txt_correcto = 'The question has been sent successfully.';
	  txt_error = 'Failed to send question. Please try again later.';
	  break;		
	case 'es':
	  txt_alerta = 'Todos los campos son obligatorios.';
	  text_email = 'Email, formato no válido.';
	  text_enviando = 'Enviando email ...';	  
	  txt_correcto = 'La petición de registro se ha enviado correctamente. En la mayor brevedad, nos pondremos en contacto con ustedes para proporcionarles las claves de acceso.';
	  txt_error = 'No se ha podido enviar la consulta. Por favor, int&eacute;ntelo m&aacute;s tarde.';	  
	  break;
	case 'de':
	  txt_alerta = 'Alle Felder müssen ausgefüllt werden.';
	  text_email = 'Email, bad format.';
	  text_enviando = 'Sending email ...';	  
	  txt_correcto = 'Die E-Mail wurde erfolgreich gesendet.';	  
	  break;
	default:
	  txt_alerta = 'All the boxes have to be completed.';
	  text_email = 'Email, bad format.';
	  text_enviando = 'Sending email ...';	  
	  txt_correcto = 'The question has been sent successfully.';
	  txt_error = 'Failed to send question. Please try again later.';	  
	}		
	if (formulario.empresa.value== "")
	{
			     alert(txt_alerta);
				 formulario.empresa.select();
                 return false;
	}	
	if (formulario.email.value== "")
	{
			     alert(txt_alerta);
				 formulario.email.select();
                 return false;
	}
	var returnval=emailfilter.test(formulario.email.value)
	if (returnval==false)
	{
			alert(text_email);		
			formulario.email.select();
			return false;
	}
	if (formulario.telefono_fijo.value== "")
	{
			     alert(txt_alerta);
				 formulario.telefono_fijo.select();
                 return false;
	}	
	if (formulario.cif.value== "")
	{
			     alert(txt_alerta);
				 formulario.cif.select();
                 return false;
	}	
	if (formulario.pass.value== "")
	{
			     alert(txt_alerta);
				 formulario.pass.select();
                 return false;
	}	
	document.getElementById("enviando_correo").innerHTML=text_enviando;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Lo sentimos, pero su navegador no soportar peticiones HTTP");
		return false;
	}		
	var url="acciones/envio_registro.php";
	url=url+"?email="+formulario.email.value;
	url=url+"&empresa="+formulario.empresa.value; 
	url=url+"&telefono_fijo="+formulario.telefono_fijo.value;	 
	url=url+"&cif="+formulario.cif.value;
	url=url+"&pass="+formulario.pass.value;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=estadoRegistro;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	return false;
}

function estadoRegistro()
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{	 
     tmp_st=xmlHttp.responseText;
	 if (tmp_st.substring(0,2) == "ok") {	
	 	document.getElementById("enviando_correo").innerHTML=txt_correcto;
		return false;
	 }
	 else 
	 {	
		document.getElementById("enviando_correo").innerHTML=txt_error;
		return false;
	 }
	}
}