$(document).ready(function() {
	var PasaFRMCorreo=false;
	var Direccion="";
	var urlFrmPrn='http://www.expo-capitalhumano.com/registro/Registro2012/index.php';
	var urlFrmPrn2='http://expo-capitalhumano.com/registro/Registro2012/index.php';
	var urlFrmPrn3='registro/Registro2012/index.php';
	//-----------------------------------------------------------------------------------
	//         Funcion que agrega una capa  html para marcar que esta en proceso 
	//-----------------------------------------------------------------------------------
	function MuestraCapa(bandera){
		try{
			if( !bandera){
				while(document.getElementById('DivModalBes')){	
					var elemento=document.getElementById('DivModalBes');
					elemento.parentNode.removeChild(elemento);			
				}
			}
			else{
		    var d = document.createElement('div');
			 document.body.appendChild(d);
			 d.setAttribute('id','DivModalBes');
		    d.style.position="fixed";
		    d.style.display="block";
		    d.style.height="100px";
		    d.style.width="300px";
		    d.style.top="45%";
		    d.style.left="40%";
		    d.style.color="#cbcbcb";
		    d.style.background="url(http://feriaejecutivadelempleo.com/registro/fondo.png)";
		    d.style.overflow="hidden";
		    d.innerHTML="<table width='100%' height='100%' ><tr><td align='center' valign='middle'><b>Espere un momento por favor.</b></td></tr></table>";
			}
		}
		catch(e){
			alert('Detalle creando la div');
		}
	}
	//-----------------------------------------------------------------------------------
	//    FIN     Funcion que agrega una capa  html para marcar que esta en proceso 
	//-----------------------------------------------------------------------------------

	//Envio de correo de contacto, de el menu contacto
	$('#ValCorreoAccs').submit(function() {		
		ValDatAjax($(this).serialize());
		return false;
	}); 
	$('#slcSectorJQ').change(function() {		
		var formenv="seleSector="+this.value;
		ValDatAjax(formenv);
		return false;
	}); 
	$('#slcPaisJQ').change(function() {		
		var formenv="selePais="+this.value;
		ValDatAjax(formenv);
		return false;
	}); 

	$('#CPSepomex').blur(function() {		
		var formenv="CPSepomex="+this.value;
		ValDatAjax(formenv);
		return false;
	}); 



	//-----------------------------------------------------------------------------------
	//                      validamos el formulario de envio de correo 
	//-----------------------------------------------------------------------------------
	function ValDatAjax(objeto){	
		var datosFrm=objeto;
		//--INICIO-----------PRIMERA direccion de validacion
		$.ajax({
			type: 'POST',
			url: urlFrmPrn,
			async: true, 
			cache: false, 
			data: datosFrm,
			error: function(request,status,error) { 
				MuestraCapa(false);
				//--INICIO-----------SEGUNDA direccion de validacion
				$.ajax({
					type: 'POST',
					url: urlFrmPrn2,
					async: true, 
					cache: false, 
					data: datosFrm,
					error: function(request,status,error) { 
						MuestraCapa(false);
						//--INICIO-----------TERCERA direccion de validacion
						$.ajax({
							type: 'POST',
							url: urlFrmPrn3,
							async: true, 
							cache: false, 
							data: datosFrm,
							error: function(request,status,error) { 
								MuestraCapa(false);
								alert('Tenemos problemas validando los formularios');				
							}, 
							success: function(data) {
								try{
									eval(data);
									if(PasaFRMCorreo){
										document.location.href=Direccion;
									}
								}
							   catch(e){
							   	alert('Error validando el formulario');
								}
								if(document.getElementById('BesDebug')){
									document.getElementById('BesDebug').innerHTML=data;
								}
								MuestraCapa(false);
							},
							beforeSend: function( ) {
								MuestraCapa(true);
							}	            
						})   
						//--FIN-----------TERCERA direccion de validacion		
				
					}, 
					success: function(data) {
						try{
							eval(data);
							if(PasaFRMCorreo){
								document.location.href=Direccion;
							}
						}
					   catch(e){
					   	alert('Error validando el formulario');
						}
						if(document.getElementById('BesDebug')){
							document.getElementById('BesDebug').innerHTML=data;
						}
						MuestraCapa(false);
					},
					beforeSend: function( ) {
						MuestraCapa(true);
					}	            
				})   
				//--FIN-----------SEGUNDA direccion de validacion
		
			}, 
			success: function(data) {
				try{
					eval(data);
					if(PasaFRMCorreo){
						document.location.href=Direccion;
					}
				}
			   catch(e){
			   	alert('Error validando el formulario');
				}
				if(document.getElementById('BesDebug')){
					document.getElementById('BesDebug').innerHTML=data;
				}
				MuestraCapa(false);
			},
			beforeSend: function( ) {
				MuestraCapa(true);
			}	            
		})   
		//--FIN-----------PRIMERA direccion de validacion	
	}
	//-----------------------------------------------------------------------------------
	//         FIN             validamos el formulario de envio de correo 
	//-----------------------------------------------------------------------------------
	
	//-----------------------------------------------------------------------------------
	//  parte segunda del formulario,  en la seleccion del que actividades se realizan
	//-----------------------------------------------------------------------------------
	$('#slcRealizaActividadesJQ').change(function() {
		var recursos=false;
		var otro=false;
		try{
			for (i=0; i<=this.length-1; i++) {
				if(this.options[i].selected){
					switch(this.options[i].value){
						case 'Relacionadas con Recursos Humanos': recursos=true; break;
						case 'Otro': otro=true; break;					
					}
				} 
			}
		}catch(e){
			alert(e);
		}
		if(recursos){
			document.getElementById('PrincipalActividades').style.display='block';		
		}
		else{
			document.getElementById('PrincipalActividades').style.display='none';		
		}
		if(otro){
			document.getElementById('slcRealizaActividadesOtro').style.display='block';		
		}
		else{
			document.getElementById('slcRealizaActividadesOtro').style.display='none';		
		}
			
	}); 	
	//-----------------------------------------------------------------------------------
	//		parte segunda del formulario,en la seleccion que servicios te interesan
	//-----------------------------------------------------------------------------------
	$('#slcServiciosInteresaSop').change(function() {
	
		var muestra=false;
		try{
			for (i=0; i<=this.length-1; i++) {
				if(this.options[i].selected){
					if(this.options[i].value=='Otro')
					muestra=true;
				} 
			}
		}catch(e){
			alert(e);
		}
		
		if(muestra){
			document.getElementById('slcServiciosInteresaOtro').style.display='block';		
		}
		else{
			document.getElementById('slcServiciosInteresaOtro').style.display='none';		
		}
			
	}); 	
	//-----------------------------------------------------------------------------------
	//    parte segunda del formulario,en la seleccion que capacitacion te interesan
	//-----------------------------------------------------------------------------------
	$('#slcCapacitacionInteresaSop').change(function() {
	
		var muestra=false;
		try{
			for (i=0; i<=this.length-1; i++) {
				if(this.options[i].selected){
					if(this.options[i].value=='Otro')
					muestra=true;
				} 
			}
		}catch(e){
			alert(e);
		}
		
		if(muestra){
			document.getElementById('slcCapacitacionInteresaOtro').style.display='block';		
		}
		else{
			document.getElementById('slcCapacitacionInteresaOtro').style.display='none';		
		}
			
	}); 	
	//-----------------------------------------------------------------------------------
	//parte primera del formulario,en la seleccion que servicios brinda tu empresa
	//-----------------------------------------------------------------------------------
	$('#SlcEmpDentIndsEsQueServicioJQ').change(function() {
	
		SelecMultiView ('SlcEmpDentIndsEsQueServicioOtroJQ','Otro',this);
		
	}); 	

	$('#SlcEmpDentIndsEsQueServicioJQAct').change(function() {
	
		SelecMultiView ('SlcEmpDentIndsEsQueServicioOtroJQAct','Otro',this);
		
	}); 	
	
	function SelecMultiView (oculta,valu,elemento){
		var muestra=false;
		try{
			for (i=0; i<=elemento.length-1; i++) {
				if(elemento.options[i].selected){
					if(elemento.options[i].value==valu)
					muestra=true;
				} 
			}
		}catch(e){
			alert(e);
		}		
		if(muestra){
			document.getElementById(oculta).style.display='block';		
		}
		else{
			document.getElementById(oculta).style.display='none';		
		}
		
	}
	    	
})

//-------------------------------------------------
//Muestra el campo otro 
//campo el input de donde se tomara el value
//valor la cadena que comparara con el input.value
//objetivo el id del campo que mostrara o ocultara
//-------------------------------------------------
function ActOtroCamp(campo, valor, objetivo){
	if(document.getElementById(objetivo).value){
		document.getElementById(objetivo).value='';		
	}
	if(campo.value==valor){
		document.getElementById(objetivo).style.display='block';
	}
	else{
		document.getElementById(objetivo).style.display='none';
	}
}

//Funcion inversa de la anterior
function ActOtroCampInver(campo, valor, objetivo){
	if(document.getElementById(objetivo).value){
		document.getElementById(objetivo).value='';		
	}
	if(campo.value==valor){
		document.getElementById(objetivo).style.display='none';
	}
	else{
		document.getElementById(objetivo).style.display='block';
	}
}
//------------------------------------------------------------------------
//Opcion especial para la parte 3, en el campo como se entero del evento 
//------------------------------------------------------------------------
function ComoEntero(campo){
	var tipo=0;
	switch(campo.value){
		case 'Banner' : tipo=1; break;
		case 'Internet' : tipo=1; break;
		case 'email' : tipo=1; break;
		case 'Radio' : tipo=2; break;
		case 'T.V.' : tipo=2; break;
		case 'Periodico' : tipo=2; break;
		case 'Revistas' : tipo=2; break;
		case 'Llamada telefonica' : tipo=2; break;
		case 'Correo postal' : tipo=2; break;
		case 'Recomendacion' : tipo=2; break;
		case 'Medios exteriores(Vallas y poster)' : tipo=2; break;
		case 'Volante' : tipo=2; break;
		case 'Otro' : tipo=2; break;
		case 'Redes Sociales' : tipo=3; break;
	}
	document.getElementById('slcMedioSitiosSop').selectedIndex='';
	document.getElementById('slcMediosRedesSocSop').selectedIndex='';
	document.getElementById('txtCualSop').value='';
	document.getElementById('slcMediosRedesSocOtro').value='';
	switch(tipo){
		case 1: 
			document.getElementById('MediosSitios').style.display='block';
			document.getElementById('TxtOtro').style.display='none';
			document.getElementById('MediosRedesSoc').style.display='none';
			break;
		case 2: 
			document.getElementById('MediosSitios').style.display='none';
			document.getElementById('TxtOtro').style.display='block';
			document.getElementById('MediosRedesSoc').style.display='none';
			break;	
		case 3: 
			document.getElementById('MediosSitios').style.display='none';
			document.getElementById('TxtOtro').style.display='none';
			document.getElementById('MediosRedesSoc').style.display='block';
			break;	
		default: 
			document.getElementById('MediosSitios').style.display='none';
			document.getElementById('TxtOtro').style.display='none';
			document.getElementById('MediosRedesSoc').style.display='none';
			return false; break;
	}
	return true;
}
//-------------------------------------------------------------------
//Opcion especial para la parte 2, en el campo el motivo de su visita 
//-------------------------------------------------------------------
function MotVisita(campo){
	var tipo=0;
	switch(campo.value){
		case 'Buscar soluciones de Recursos Humanos para mi empresa' : tipo=2; break;
		case 'Buscar soluciones de capacitación para mí' : tipo=1; break;
		case 'Conferencias y Talleres' : tipo=2; break;
		case 'Otro' : tipo=3; break;
	}
	
	var cadena = campo.value;
	if (cadena.indexOf('Buscar soluciones de capacitaci')!=-1) {
       tipo=1;
   }
	
	document.getElementById('slcServiciosInteresaSop').selectedIndex='';
	document.getElementById('slcServiciosInteresaOtro').value='';
	document.getElementById('slcCapacitacionInteresaSop').selectedIndex='';
	document.getElementById('slcCapacitacionInteresaOtro').value='';
	document.getElementById('slcMotivoVisitaOtro').value='';
	
	switch(tipo){
		case 1: 
			//capacitaci�n
			document.getElementById('CapacitacionInteresa').style.display='block';
			document.getElementById('slcCapacitacionInteresaOtro').style.display='none';
			document.getElementById('ServiciosInteresa').style.display='none';
			document.getElementById('slcServiciosInteresaOtro').style.display='none';
			document.getElementById('slcMotivoVisitaOtro').style.display='none';
			break;
		case 2: 
			//servicios
			document.getElementById('CapacitacionInteresa').style.display='none';
			document.getElementById('slcCapacitacionInteresaOtro').style.display='none';
			document.getElementById('ServiciosInteresa').style.display='block';
			document.getElementById('slcServiciosInteresaOtro').style.display='none';
			document.getElementById('slcMotivoVisitaOtro').style.display='none';
			break;	
		case 3: 
			//servicios y otro
			document.getElementById('CapacitacionInteresa').style.display='none';
			document.getElementById('slcCapacitacionInteresaOtro').style.display='none';
			document.getElementById('ServiciosInteresa').style.display='block';
			document.getElementById('slcServiciosInteresaOtro').style.display='none';
			document.getElementById('slcMotivoVisitaOtro').style.display='block';
			break;	
		default: 
			document.getElementById('CapacitacionInteresa').style.display='none';
			document.getElementById('slcCapacitacionInteresaOtro').style.display='none';
			document.getElementById('ServiciosInteresa').style.display='none';
			document.getElementById('slcServiciosInteresaOtro').style.display='none';
			document.getElementById('slcMotivoVisitaOtro').style.display='none';
			return false; break;
	}
	return true;
}
