/*----------------------
      Producido en 2011 por Jos&eacute; Lessa
	This software is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
----- */
function Continuar(camp)
{
switch(camp)
{
case 'Verofit1':

		if(ValidarDatos1() == false){
                  document.miformulario.submit();
      		document.getElementById('miformulario').submit();
		}
break;
case 'Verofit2':

		if(ValidarDatos2() == false){
                  document.miformulario.submit();
      		document.getElementById('miformulario').submit();
		}
break;
case 'Verofit3':
		if(ValidarDatos3() == false){
                  document.miformulario.submit();
      		document.getElementById('miformulario').submit();
		}
break;
}	
}
/*------------------------------------------------*/
function ValidarDatos1(){

 TieneError = false;
 MiError = "";
if(trim(document.miformulario.nombreContacto.value) == ""){
	MiError = MiError + " *- El campo Nombre es obligatorio.\n";
	TieneError = true;
      document.getElementById('NombreC').innerHTML = '<span class="alerta">Nombre:</span>'; 
}
else
{
      document.getElementById('NombreC').innerHTML = 'Nombre:';
}
if(trim(document.miformulario.apellidos.value) == ""){
	MiError = MiError + " *- El campo Apellidos es obligatorio.\n";
	TieneError = true;
      document.getElementById('apellidoC').innerHTML = '<span class="alerta">Apellidos:</span>'; 
}
else
{
      document.getElementById('apellidoC').innerHTML = 'Apellidos:';
}
if(trim(document.miformulario.localidadContacto.value) == ""){
	MiError = MiError + " *- El campo Localidad es obligatorio.\n";
	TieneError = true;
      document.getElementById('localidad').innerHTML = '<span class="alerta">Localidad:</span>'; 
}
else
{
      document.getElementById('localidad').innerHTML = 'Localidad:';
}
if(trim(document.miformulario.cp.value) == ""){
	MiError = MiError + " *- El campo Codigo postal es obligatorio.\n";
	TieneError = true;
      document.getElementById('cpC').innerHTML = '<span class="alerta">CP:</span>'; 
}
else
{
      document.getElementById('cpC').innerHTML = 'CP:';
}
if(trim(document.miformulario.telefonoContacto.value) == ""){
	MiError = MiError + " *- El campo Tel&eacute;fono es obligatorio.\n";
	TieneError = true;
      document.getElementById('telefono').innerHTML = '<span class="alerta">Tel&eacute;fono:</span>'; 
}
else
{
      document.getElementById('telefono').innerHTML = 'Tel&eacute;fono:';
}
if(trim(document.miformulario.movil.value) == ""){
	MiError = MiError + " *- El campo M&oacute;vil es obligatorio.\n";
	TieneError = true;
      document.getElementById('movilC').innerHTML = '<span class="alerta">M&oacute;vil:</span>'; 
}
else
{
      document.getElementById('movilC').innerHTML = 'M&oacute;vil:';
}



if(!validarEmail(trim(document.miformulario.EmailContacto.value)))
{
	MiError = MiError + " *- El email es obligatorio.\n";
      TieneError = true;
      document.getElementById('Email').innerHTML = '<span class="alerta">e-Mail </span>';
}
      else
      {
           document.getElementById('Email').innerHTML = 'e-Mail:';
      }


if( document.miformulario.edad.value == "0"){

	MiError = MiError + " *- Debe indicar la edad";
	TieneError = true;
      document.getElementById('edadC').innerHTML = '<span class="alerta">Edad:</span>'; 
}

else
{
      document.getElementById('edadC').innerHTML = 'Edad:';
}


if(trim(document.miformulario.ocupacion.value) == ""){

	MiError = MiError + " *- El campo Ocupaci&oacute;n es obligatorio.\n";
	TieneError = true;
      document.getElementById('ocupacionC').innerHTML = '<span class="alerta">Ocupaci&oacute;n:</span>'; 
}

else
{
      document.getElementById('ocupacionC').innerHTML = 'Ocupaci&oacute;n:';
}

if(trim(document.miformulario.experiencias.value) == ""){

	MiError = MiError + " *- El campo experiencias es obligatorio.\n";
	TieneError = true;
      document.getElementById('experienciasC').innerHTML = '<span class="alerta">Experiencias profesionales previas:</span>'; 
}

else
{
      document.getElementById('experienciasC').innerHTML = 'Experiencias profesionales previas:';
}


if(trim(document.miformulario.objetivos.value) == ""){

	MiError = MiError + " *- El campo objetivos es obligatorio.\n";
	TieneError = true;
      document.getElementById('objetivosC').innerHTML = '<span class="alerta">Objetivos y comentarios:</span>'; 
}

else
{
      document.getElementById('objetivosC').innerHTML = 'Objetivos y comentarios:';
}


if((!document.miformulario.porEmail.checked)&& (!document.miformulario.porTelefono.checked ) )
{
	MiError = MiError + " *- Nos debe indicar forma de contactarnos: es obligatorio.\n";
	TieneError = true;
      document.getElementById('contactemos').innerHTML = '<span class="alerta">&iquest;Como prefieres que te contactemos?</span>'; 
}
else
{
      document.getElementById('contactemos').innerHTML = '&iquest;Como prefieres que te contactemos?';
}

if((!document.miformulario.opcion1.checked)&& (!document.miformulario.opcion2.checked ) && (!document.miformulario.opcion4.checked ) && (!document.miformulario.opcion5.checked ) )
{
	MiError = MiError + " *- &iquest;C&oacute;mo nos has conocido?: es obligatorio.\n";
	TieneError = true;
      document.getElementById('conocidoC').innerHTML = '<span class="alerta">&iquest;C&oacute;mo nos has conocido?</span>'; 
}
else
{
      document.getElementById('conocidoC').innerHTML = '&iquest;C&oacute;mo nos has conocido?';
}
if ((!document.miformulario.condiciones.checked )) 
{
	MiError = MiError + " *- Debe aceptar las condiciones para continuar.\n";
      TieneError = true;
      document.getElementById('condib').innerHTML = '<span class="align-lt"><input type="checkbox" name="condiciones" onClick="Privacidad2()" /></span><span class="alerta">S&iacute;, acepto la pol&iacute;tica de privacidad.</span>';
}
      else
      {
           document.getElementById('condib').innerHTML = '<span class="align-lt"><input type="checkbox" checked name="condiciones" onClick="Privacidad2Off()" /></span><p>S&iacute;, acepto la pol&iacute;tica de privacidad.</p>';
      }

if (TieneError ){
   document.getElementById('condi').innerHTML = '<span class="alerta"> &iexcl;Error! Uno o varios campos estan incompletos o vacios. Por favor, revise los campos marcados en rojo.</span>';
}
else
{
	document.miformulario.enviar.value ="Procesando";
}
return TieneError
}
/*----------------Solicitar Productos--------------------------------*/
function ComentarioPro1()
{
 document.getElementById('comentPro1').innerHTML = '<input type="checkbox" class="align-rt" name="opcion5" checked onClick="ComentarioPro1Off()" /><label for="formulario-texto">Amigo, conocido </label><br /><br /><input class="align-lt" value="" name="clienteCo" size="17" style="border-width: 1px; border-style: solid; border-color: rgb(204, 204, 204); font-size: 16px; float: left; margin: 0px 0px 0px 0px; padding: 3px 3px 3px 3px;" type="text" />';
}

function ComentarioPro1Off()
{
  document.getElementById('comentPro1').innerHTML = '<div class="align-rt"><input type="checkbox" name="opcion5" onClick="ComentarioPro1()" /><label for="formulario-texto">Amigo, conocido </label><br /></div>';
}

function ComentarioPro2()
{
 document.getElementById('comentPro2').innerHTML = '<input type="checkbox" class="align-rt" name="opcion4" checked onClick="ComentarioPro2Off()" /><label for="formulario-texto">Otros</label><br /><br /><input class="align-lt" value="" name="clienteOtros" size="17" style="border-width: 1px; border-style: solid; border-color: rgb(204, 204, 204); font-size: 16px; float: left; margin: 0px 0px 0px 0px; padding: 3px 3px 3px 3px;" type="text" />';
}

function ComentarioPro2Off()
{
  document.getElementById('comentPro2').innerHTML = '<div class="align-rt"><input type="checkbox"  name="opcion4" onClick="ComentarioPro2()" /><label for="formulario-texto">Otros</label><br /></div>';
}

function Privacidad2()
{

  document.getElementById('condib').innerHTML = ' <span class="align-lt"><input type="checkbox" checked name="condiciones" onClick="Privacidad2Off()" /></span><p>Si, acepto la pol&iacute;tica de privacidad.</p>';
}

function Privacidad2Off()


{
  document.getElementById('condib').innerHTML = ' <span class="align-lt"><input type="checkbox" name="condiciones" onClick="Privacidad2()" /></span><span class="alerta">Si, acepto la pol&iacute;tica de privacidad..</span>';
}



/*......................................................................*/

function ValidarDatos2(){

 TieneError = false;
 MiError = "";

if(trim(document.miformulario.nombreContacto.value) == ""){

	MiError = MiError + " *- El campo Nombre es obligatorio.\n";
	TieneError = true;
      document.getElementById('NombreC').innerHTML = '<span class="alerta">Nombre:</span>'; 
}

else
{
      document.getElementById('NombreC').innerHTML = 'Nombre:';
}

if(trim(document.miformulario.telefono.value) == ""){
	MiError = MiError + " *- El campo Tel&eacute;fono es obligatorio.\n";
	TieneError = true;
      document.getElementById('telefonoC').innerHTML = '<span class="alerta">Tel&eacute;fono:</span>'; 
}
else
{
      document.getElementById('telefonoC').innerHTML = 'Tel&eacute;fono:';
}
if(trim(document.miformulario.CodigoPostal.value) == ""){
	MiError = MiError + " *- El C&oacute;digo postal: es obligatorio.\n";
	TieneError = true;
      document.getElementById('CodigoC').innerHTML = '<span class="alerta">C&oacute;digo postal:</span>'; 
}
else
{
      document.getElementById('CodigoC').innerHTML = 'C&oacute;digo postal:';
}


if(trim(document.miformulario.Localidad.value) == ""){
	MiError = MiError + " *- La localidad es obligatoria.\n";
	TieneError = true;
      document.getElementById('LocalidadC').innerHTML = '<span class="alerta">Localidad :</span>'; 
}
else
{
      document.getElementById('LocalidadC').innerHTML = 'Localidad :';
}


if(!validarEmail(trim(document.miformulario.EmailContacto.value)))
{
	MiError = MiError + " *- El email es obligatorio.\n";
      TieneError = true;
      document.getElementById('Email').innerHTML = '<span class="alerta">e-Mail:</span>';
}
      else
      {
           document.getElementById('Email').innerHTML = 'e-Mail:';
      }




if(trim(document.miformulario.comentario.value) == ""){
	MiError = MiError + " *- El comentario: es obligatorio.\n";
	TieneError = true;
      document.getElementById('comentarioC').innerHTML = '<span class="alerta">Comentario:</span>'; 
}
else
{
      document.getElementById('comentarioC').innerHTML = 'Comentario:';
}


if((!document.miformulario.control_peso.checked)&& (!document.miformulario.dermocosmetica.checked ) && (!document.miformulario.nutricion_deportiva.checked ) && (!document.miformulario.oportunidad_negocio.checked ) )
{
	MiError = MiError + " *- Su inter&eacute;s: es obligatorio.\n";
	TieneError = true;
      document.getElementById('interesC').innerHTML = '<span class="alerta">Me interesa...</span>'; 
}
else
{
      document.getElementById('interesC').innerHTML = 'Me interesa...';
}

if((!document.miformulario.opcion1.checked)&& (!document.miformulario.opcion2.checked ) && (!document.miformulario.opcion4.checked ) && (!document.miformulario.opcion5.checked ) )
{
	MiError = MiError + " *- &iquest;C&oacute;mo nos has conocido?: es obligatorio.\n";
	TieneError = true;
      document.getElementById('conocidoC').innerHTML = '<span class="alerta">&iquest;C&oacute;mo nos has conocido?</span>'; 
}
else
{
      document.getElementById('conocidoC').innerHTML = '&iquest;C&oacute;mo nos has conocido?';
}




if ((!document.miformulario.condiciones.checked )) 
{
	MiError = MiError + " *- Debe aceptar las condiciones para continuar.\n";
      TieneError = true;
      document.getElementById('condib').innerHTML = '<span class="align-lt"><input type="checkbox" name="condiciones" onClick="Privacidad2()" /></span><span class="alerta">S&iacute;, acepto la pol&iacute;tica de privacidad.</span>';
}
      else
      {
           document.getElementById('condib').innerHTML = '<span class="align-lt"><input type="checkbox" checked name="condiciones" onClick="Privacidad2Off()" /></span><p>S&iacute;, acepto la pol&iacute;tica de privacidad.</p>';
      }






if (TieneError ){
   document.getElementById('condi').innerHTML = '<span class="alerta"> &iexcl;Error! Uno o varios campos estan incompletos o vacios. Por favor, revise los campos marcados en rojo.</span>';
}
else
{
	document.miformulario.enviar.value ="Procesando";
}
return TieneError
}


/*......................................................................*/
function trim(strText) { 
	// this will get rid of leading spaces 
	while (strText.substring(0,1) == ' ') 
		strText = strText.substring(1, strText.length);

	// this will get rid of trailing spaces 
	while (strText.substring(strText.length-1,strText.length) == ' ')
		strText = strText.substring(0, 4);

   return strText;
} 
/*......................................................................*/

function validarEmail(email) {

   var regexp=/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/;
   var resultado=email.match(regexp);
   if (resultado) return (resultado[0]==email)
   else return false;}
/*--------------------Hazte consultor----------------------------*/
//<input type="text"   name="g.clienteCo" value="Nombre:" />';

function Comentario1()
{
 document.getElementById('coment1').innerHTML = '<input type="checkbox" class="align-rt" name="opcion5" checked onClick="Comentario1Off()" /><label for="formulario-texto">Amigo, conocido</label><br /><br /><input class="align-lt" value="" name="clienteCo" size="17" style="border-width: 1px; border-style: solid; border-color: rgb(204, 204, 204); font-size: 16px; float: left; margin: 0px 0px 0px 0px; padding: 3px 3px 3px 3px;" type="text" />';
}

function Comentario1Off()
{
 document.getElementById('coment1').innerHTML = '<div class="align-rt"><input type="checkbox" name="opcion5" onClick="Comentario1()" /><label for="formulario-texto">Amigo, conocido</label><br /></div>';
}

function Comentario2()
{
 document.getElementById('coment2').innerHTML = '<input type="checkbox" class="align-rt" name="opcion4" checked onClick="Comentario2Off()" /><label for="formulario-texto">Otros</label><br /><br /><input class="align-lt" value="" name="clienteOtros" size="17" style="border-width: 1px; border-style: solid; border-color: rgb(204, 204, 204); font-size: 16px; float: left; margin: 0px 0px 0px 0px; padding: 3px 3px 3px 3px;" type="text" />';

}

function Comentario2Off()
{
  document.getElementById('coment2').innerHTML = '<div class="align-rt"><input type="checkbox"  name="opcion4" onClick="Comentario2()" />Otros<br /></div>';
}

function ComentarioHorarioTel()
{
 document.getElementById('horarioTel').innerHTML = '<input type="checkbox" class="align-rt" name="porTelefono" checked onClick="ComentarioHorarioTelOff()" /><label class="formulario-texto">Tel&eacute;fono</label><br /><br /><label class="formulario-texto">Horario preferido:</label> <select name="SelectHorarioTel" size="1" class="selecthorario"  ><option> 9 - 12 hrs</option><option>12 - 15 hrs</option><option>15 - 18 hrs</option><option>18 - 22 hrs</option></select>';
}

function ComentarioHorarioTelOff()
{
  document.getElementById('horarioTel').innerHTML = '<input type="checkbox" class="align-rt" name="porTelefono" onClick="ComentarioHorarioTel()" /><label class="formulario-texto">Tel&eacute;fono</label>';
}

/*......................................................................*/

function condic()
{
 if (!document.miformulario.condiciones.checked )
{
	MiError = MiError + " *- Debe aceptar las condiciones para continuar.\n";
      TieneError = true;
      document.getElementById('condib').innerHTML = '<span class="alerta">Antes de enviar este formulario debes leer y aceptar nuestra <a href="?politica_de_privacidad"> pol&iacute;tica de privacidad </a> de datos. </span><br />';
}
      else
      {
           document.getElementById('condib').innerHTML = 'Antes de enviar este formulario debes leer y aceptar nuestra <a href="?politica_de_privacidad"> pol&iacute;tica de privacidad </a>  de datos.<br />';
      }
}



/*-------------------------------------------*/


function ValidarDatos3(){

 TieneError = false;
 MiError = "";
if(trim(document.miformulario.nombreContacto.value) == ""){

	MiError = MiError + " *- El campo Nombre es obligatorio.\n";
	TieneError = true;
      document.getElementById('NombreC').innerHTML = '<span class="alerta">Nombre:</span>'; 
}
else
{
      document.getElementById('NombreC').innerHTML = 'Nombre:';
}
if(trim(document.miformulario.telefonoContacto.value) == ""){

	MiError = MiError + " *- El campo Tel&eacute;fono es obligatorio.\n";
	TieneError = true;
      document.getElementById('telefonoC').innerHTML = '<span class="alerta">Tel&eacute;fono:</span>'; 
}
else
{
      document.getElementById('telefonoC').innerHTML = 'Tel&eacute;fonol:';
}
if(trim(document.miformulario.cpContacto.value) == ""){

	MiError = MiError + " *- El C&oacute;digo postal: es obligatorio.\n";
	TieneError = true;
      document.getElementById('CodigoC').innerHTML = '<span class="alerta">C&oacute;digo postal:</span>'; 
}

else
{
      document.getElementById('CodigoC').innerHTML = 'C&oacute;digo postal:';
}



if(!validarEmail(trim(document.miformulario.EmailContacto.value)))
{
	MiError = MiError + " *- El email es obligatorio.\n";
      TieneError = true;
      document.getElementById('Email').innerHTML = '<span class="alerta">e-Mail</span>';
}
      else
      {
           document.getElementById('Email').innerHTML = 'e-Mail:';
      }



if(trim(document.miformulario.comentario.value) == ""){
	MiError = MiError + " *- El comentario: es obligatorio.\n";
	TieneError = true;
      document.getElementById('comentarioC').innerHTML = '<span class="alerta">Comentario:</span>'; 
}
else
{
      document.getElementById('comentarioC').innerHTML = 'Comentario:';
}



if ((!document.miformulario.condiciones.checked )) 
{
	MiError = MiError + " *- Debe aceptar las condiciones para continuar.\n";
      TieneError = true;
      document.getElementById('condib').innerHTML = '<span class="align-lt"><input type="checkbox" name="condiciones" onClick="Privacidad2()" /></span><span class="alerta">S&iacute;, acepto la pol&iacute;tica de privacidad.</span>';
}
      else
      {
           document.getElementById('condib').innerHTML = '<span class="align-lt"><input type="checkbox" checked name="condiciones" onClick="Privacidad2Off()" /></span><p>S&iacute;, acepto la pol&iacute;tica de privacidad.</p>';
      }






if (TieneError ){
   document.getElementById('condi').innerHTML = '<span class="alerta"> &iexcl;Error! Uno o varios campos estan incompletos o vacios. Por favor, revise los campos marcados en rojo.</span>';
}
else
{
	document.miformulario.enviar.value ="Procesando";
}
return TieneError
}

/*------------------------------------------------*/



function ValEmail()
 {
 if(!validarEmail(trim(document.miformulario.EmailContacto.value)))
       document.getElementById('Email').innerHTML = '<span class="alerta">e-Mail:</span>';    
else
  document.getElementById('Email').innerHTML = '<label for="EmailContacto" >e-Mail:</label>';
}
 /*...........................................................*/


function nuevoAjax(){
	var xmlhttp=false;
 	try {
 		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 	} catch (e) {
 		try {
 			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 		} catch (E) {
 			xmlhttp = false;
 		}
  	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}



function cargarContenido(){
	var t1, t2, contenedor;
	contenedor = document.getElementById('contenedor');
	t1 = document.getElementById('texto1').value;
	t2 = document.getElementById('texto2').value;

	ajax=nuevoAjax();
	ajax.open("POST", "ejemploajax2.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			contenedor.innerHTML = ajax.responseText
	 	}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("t1="+t1+"&t2="+t2)
}


function enviarFormulario(url, formid){
         var Formulario = document.getElementById('miformulario');
         var longitudFormulario = Formulario.elements.length;
         var cadenaFormulario = ""
         var sepCampos
         sepCampos = ""
         for (var i=0; i <= Formulario.elements.length-1;i++) {
         cadenaFormulario += sepCampos+Formulario.elements[i].name+'='+encodeURI(Formulario.elements[i].value);
         sepCampos="&";
}

	peticion=nuevoAjax  ();

  peticion.open("POST", url, true);
  peticion.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
  peticion.onreadystatechange = function () {
  if (peticion.readyState == 4) {
     document.getElementById('miformulario').innerHTML = "Los datos han sido enviados correctamente";
}
}
peticion.send(cadenaFormulario);
}


function Val(camp)
{
switch(camp)
{
case 'NombreContacto':
if(trim(document.miformulario.NombreContacto.value) == ""){
      document.getElementById('Nombre').innerHTML = '<span class="alerta">El campo Nombre es obligatorio </span>';
}

else
{
      document.getElementById('Nombre').innerHTML = '<label for="Nombre" >Nombre : </label>';
}
break;
case 'Apellido1Contacto':
if(trim(document.miformulario.Apellido1Contacto.value) == "" || trim(document.miformulario.Apellido2Contacto.value) == "")
{
      document.getElementById('Apellidos').innerHTML = '<span class="alerta">Ambos apellidos son obligatorios.\n</span>';
}
else
{
      document.getElementById('Apellidos').innerHTML = '<label for="Apellidos" >Apellidos : </label>';
}
break;
case 'Apellido2Contacto':
if(trim(document.miformulario.Apellido1Contacto.value) == "" || trim(document.miformulario.Apellido2Contacto.value) == "")
{
      document.getElementById('Apellidos').innerHTML = '<span class="alerta">Ambos apellidos son obligatorios.\n</span>';
}
else
{
      document.getElementById('Apellidos').innerHTML = '<label for="Apellidos" >Apellidos : </label>';
}
break;
case 'DireccionContacto':
if(trim(document.miformulario.DireccionContacto.value) == "")
{
      document.getElementById('DireccionContacto').innerHTML = '<span class="alerta">La direcci&oacute;n es obligatoria.\n</span>';
}
else
{
      document.getElementById('DireccionContacto').innerHTML = '<label for="DireccionContacto" >Direcci&oacute;n : </label>';
}
break;
case 'PoblacionContacto':

if(trim(document.miformulario.PoblacionContacto.value) == "")
{
      document.getElementById('Poblacion').innerHTML = '<span class="alerta">El campo de poblacion es obligatorio.\n</span>';
}
else
{
      document.getElementById('Poblacion').innerHTML = '<label for="PoblacionContacto" >Poblaci&oacute;n : </label>';
}

break;
case 'CodigoPostal':


if(trim(document.miformulario.CodigoPostal.value) == "")
{
      document.getElementById('CodigoP').innerHTML = '<span class="alerta">El c&oacute;digo postal es obligatorio.\n</span>';
}
else
{
      document.getElementById('CodigoP').innerHTML = '<label for="CodigoP" >CP : </label>';
}
break;
case 'EmailContacto':


 if(!validarEmail(trim(document.miformulario.EmailContacto.value)))
       document.getElementById('Email').innerHTML = '<span class="alerta">Debe ser un email v&aacute;lido.\n</span>';    
else
  document.getElementById('Email').innerHTML = '<label for="EmailContacto" >Email : </label>';
}

}

