
//------- Formulario Español
//--------------------------------------------------------------------------------------------------------------------
function validaformulario_es()
{

	if(document.getElementById('nombre').value=="") 
	{
		alert("Debe colocar sus nombres");
		document.getElementById('nombre').focus();
	}
	else if(document.getElementById('apellidos').value=="") 
	{
		alert("Debe colocar sus apellidos");
		document.getElementById('apellidos').focus();
	}
	else if(ValidarEmail(document.getElementById('cabecera').value)=="0")
	{
		alert("Debe colocar su e-mail y este debe ser válido");	  
		document.getElementById('cabecera').focus();
	}
	else if(document.getElementById('direccion').value=="") 
	{
		alert("Debe colocar su dirección");
		document.getElementById('direccion').focus();
	}
	else if(document.getElementById('pais').value=="") 
	{
		alert("Debe seleccionar su país de origen");
		document.getElementById('pais').focus();
	}
	else if(document.getElementById('departamento').value=="") 
	{
		alert("Debe colocar su departamento o provincia");
		document.getElementById('departamento').focus();
	}
	else if(document.getElementById('ciudad').value=="") 
	{
		alert("Debe colocar su ciudad");
		document.getElementById('ciudad').focus();
	}
	else if(ValidarNum(document.getElementById('telefono').value)=="1")
	{
		alert("Debe colocar su teléfono y este unicamente debe contener números");	  
		document.getElementById('telefono').focus();
	}
	else if(document.getElementById('ocupacion').value=="") 
	{
		alert("Debe colocar su ocupacion");
		document.getElementById('ocupacion').focus();
	}
	else if(document.getElementById('institucion').value=="") 
	{
		alert("Debe colocar su institucion");
		document.getElementById('institucion').focus();
	}
	else 
		sendRequestFormulario_es();
}

var httpFormulario_es=createRequestObject();
function sendRequestFormulario_es() {
    var aleatorio = Math.round(Math.random()*1000);
    httpFormulario_es.open('get', 'archivos/enviaformulario_es.php?oferta='+document.getElementById('oferta').value+'&nombre='+document.getElementById('nombre').value+'&apellidos='+document.getElementById('apellidos').value+'&cabecera='+document.getElementById('cabecera').value+'&direccion='+document.getElementById('direccion').value+'&ciudad='+document.getElementById('ciudad').value+'&departamento='+document.getElementById('departamento').value+'&pais='+document.getElementById('pais').value+'&telefono='+document.getElementById('telefono').value+'&celular='+document.getElementById('celular').value+'&ocupacion='+document.getElementById('ocupacion').value+'&institucion='+document.getElementById('institucion').value+'&mensaje='+document.getElementById('comentario').value+'&Capacitacion='+document.getElementById('Capacitacion').checked+'&Guias='+document.getElementById('Guias').checked+'&Donaciones='+document.getElementById('Donaciones').checked+'&Red='+document.getElementById('Red').checked+'&Otro='+document.getElementById('Otro').checked+'&cual='+document.getElementById('cual').value+'&aleatorio='+aleatorio);
    httpFormulario_es.onreadystatechange = handleResponseFormulario_es;
    httpFormulario_es.send(null);
}
function handleResponseFormulario_es() {
    if(httpFormulario_es.readyState == 4)
    {
      var Valor=new String(httpFormulario_es.responseText);
	  escribeCapa('contenidos',Valor);
    }
}

//------- Formulario Ingles
//--------------------------------------------------------------------------------------------------------------------
function validaformulario_in()
{

	if(document.getElementById('nombre').value=="") 
	{
		alert("Please enter your First Name");
		document.getElementById('nombre').focus();
	}
	else if(document.getElementById('apellidos').value=="") 
	{
		alert("Please enter your Last Name");
		document.getElementById('apellidos').focus();
	}
	else if(ValidarEmail(document.getElementById('cabecera').value)=="0")
	{
		alert("Please enter a valid e-mail address");	  
		document.getElementById('cabecera').focus();
	}
	else if(document.getElementById('direccion').value=="") 
	{
		alert("Please enter your Address");
		document.getElementById('direccion').focus();
	}
	else if(document.getElementById('pais').value=="") 
	{
		alert("Please choose your Country");
		document.getElementById('pais').focus();
	}
	else if(document.getElementById('departamento').value=="") 
	{
		alert("Please enter your Departament or Province");
		document.getElementById('departamento').focus();
	}
	else if(document.getElementById('ciudad').value=="") 
	{
		alert("Please enter your City");
		document.getElementById('ciudad').focus();
	}
	else if(ValidarNum(document.getElementById('telefono').value)=="1")
	{
		alert("Please enter your Phone number");	  
		document.getElementById('telefono').focus();
	}
	else if(document.getElementById('ocupacion').value=="") 
	{
		alert("Please enter your Occupation");
		document.getElementById('ocupacion').focus();
	}
	else if(document.getElementById('institucion').value=="") 
	{
		alert("Please enter your Organization");
		document.getElementById('institucion').focus();
	}
	else 
		sendRequestFormulario_in();
}

var httpFormulario_in=createRequestObject();
function sendRequestFormulario_in() {
    var aleatorio = Math.round(Math.random()*1000);
    httpFormulario_in.open('get', 'archivos/enviaformulario_in.php?oferta='+document.getElementById('oferta').value+'&nombre='+document.getElementById('nombre').value+'&apellidos='+document.getElementById('apellidos').value+'&cabecera='+document.getElementById('cabecera').value+'&direccion='+document.getElementById('direccion').value+'&ciudad='+document.getElementById('ciudad').value+'&departamento='+document.getElementById('departamento').value+'&pais='+document.getElementById('pais').value+'&telefono='+document.getElementById('telefono').value+'&celular='+document.getElementById('celular').value+'&ocupacion='+document.getElementById('ocupacion').value+'&institucion='+document.getElementById('institucion').value+'&mensaje='+document.getElementById('comentario').value+'&Capacitacion='+document.getElementById('Capacitacion').checked+'&Guias='+document.getElementById('Guias').checked+'&Donaciones='+document.getElementById('Donaciones').checked+'&Red='+document.getElementById('Red').checked+'&Otro='+document.getElementById('Otro').checked+'&cual='+document.getElementById('cual').value+'&aleatorio='+aleatorio);
    httpFormulario_in.onreadystatechange = handleResponseFormulario_in;
    httpFormulario_in.send(null);
}
function handleResponseFormulario_in() {
    if(httpFormulario_in.readyState == 4)
    {
      var Valor=new String(httpFormulario_in.responseText);
	  escribeCapa('contenidos',Valor);
    }
}

//------- Generales
//--------------------------------------------------------------------------------------------------------------------
function ValidarEmail(Objeto)
{
	var s = Objeto;
	var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	if (s.length == 0 ) 
	{
	  return('0');
	}
	if (filter.test(s))
	{
	  return('1');
	}
	else
	{
	  return('0');
	}
}

function ValidarNum(Objeto)
{
	var Valor=new String(Objeto);
	NValor="";
	cont=0;
	i=0;
    if (Valor.length == 0 ) 
	{
	  return('1');
	}
	else
	{
		for(i=0;i<=Valor.length-1;i++)
		{
		  Codigo=Valor.charCodeAt(i);
		  if(Codigo>=48&&Codigo<=57)
		  {
			cont=cont;
			NValor = NValor + Valor.charAt(i);
		  }
		  else if(Codigo==32)
		  {
			cont=cont;
		  }
		  else
		  {
			cont=cont+1;
			NValor = NValor + Valor.charAt(i);
		  }
		}
		if(cont>0)
		{
		  return('1');
		}
		else
		{
		  return('0');
		}
	}
}
