/*  
Site Name: ASECOR
Site URI: www.corazon12.org
Author: Desarrollo Creativo S.L.
*/

// =======================
// CONFIGURACION DE JQUERY
// =======================

// ABRE UNA VENTANA SECUNDARIA
function abrirVentana(url){
	window.open(url, "", "width=670,height=600,resizable=NO,scrollbars=YES");
}

// ========================================
// FUNCIONES PARA EL FORMULARIO DE CONTACTO
// ========================================

// FUNCIÓN QUE VALIDA EL FORMULARIO
function validarFormularioConsulta(){
	
	// Reseteo
	$('#frmContactaNombre').css("border-color", "Silver");
	$('#frmContactaMail').css("border-color", "Silver");
	$('#frmContactaTelefono').css("border-color", "Silver");	
	$('#frmContactaConsulta').css("border-color", "Silver");
	$('#frmContactaLegal').css("border-color", "Silver");

	// Valido el Nombre
	if($('#frmContactaNombre').val().length < 1){
		$('#frmContactaNombre').css("border-color", "#9c0808");
		$('#frmDifusor').css("background-color", "#9c0808");
		$("#frmDifusor").show();
		$("#frmContactaError").fadeIn("slow");
		return false;
	}
	
	// Valido el correo: Obligatorio
	if($('#frmContactaMail').val().length < 1){
		$('#frmContactaMail').css("border-color", "#9c0808");
		$('#frmDifusor').css("background-color", "#9c0808");
		$("#frmDifusor").show();
		$("#frmContactaError").fadeIn("slow");
		return false;		
	}	
	
	// Valido el correo: Formato
	var cadena = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890@._-"; 
	var arroba = ($('#frmContactaMail').val()).indexOf("@",0); 
	
	
	if ((($('#frmContactaMail').val()).lastIndexOf("@")) != arroba) 
		arroba = -1; 
	
	var punto = ($('#frmContactaMail').val()).lastIndexOf(".");
	
	
	for (var contador = 0 ; contador < ($('#frmContactaMail').val()).length ; contador++){ 
		if (cadena.indexOf(($('#frmContactaMail').val()).substr(contador, 1),0) == -1){ 
			$('#frmContactaMail').css("border-color", "#9c0808");
			$('#frmDifusor').css("background-color", "#9c0808");
			$("#frmDifusor").show();
			$("#frmMailError").fadeIn("slow");
			return false;
		}
	}
			
	if (!((arroba > 1) && (arroba + 1 < punto) && (punto + 1 < (($('#frmContactaMail').val()).length)) && (($('#frmContactaMail').val()).indexOf("..",0) == -1))){ 
		$('#frmContactaMail').css("border-color", "#9c0808");
		$('#frmDifusor').css("background-color", "#9c0808");
		$("#frmDifusor").show();
		$("#frmMailError").fadeIn("slow");
		return false;
	}
	
	
	// Valido el teléfono
	if($('#frmContactaTelefono').val().length < 1){
		$('#frmContactaTelefono').css("border-color", "#9c0808");
		$('#frmDifusor').css("background-color", "#9c0808");
		$("#frmDifusor").show();
		$("#frmContactaError").fadeIn("slow");
		return false;
	}
	else if(!(($('#frmContactaTelefono').val() > 99999999) && ($('#frmContactaTelefono').val() <= 999999999999))){
		$('#frmContactaTelefono').css("border-color", "#9c0808");
		$('#frmDifusor').css("background-color", "#9c0808");
		$("#frmDifusor").show();
		$("#frmTelefonoError").fadeIn("slow");
		return false;		
	}
	
	// Valido el contenido
	if($('#frmContactaConsulta').val().length < 1){
		$('#frmContactaConsulta').css("border-color", "#9c0808");
		$('#frmDifusor').css("background-color", "#9c0808");
		$("#frmDifusor").show();
		$("#frmContactaError").fadeIn("slow");
		return false;		
	}
	
	// Valido el Aviso Legal
	if(!( $('#frmContactaLegal').attr('checked'))){
		$("#frmContactaLegal").css("border-color", "#9c0808");
		$('#frmDifusor').css("background-color", "#9c0808");
		$("#frmDifusor").show();
		$("#frmAvisoError").fadeIn("slow");
		return false;
	}	
	
	return true;
}

// FUNCIÓN QUE ENVÍA EL CORREO CON LA CONSULTA
function enviarConsulta(){
	
	// Valido el Formulario
	if(validarFormularioConsulta()){
		
		// Hago la petición por Ajax: Mail
		$.ajax({
			url: 'http://www.corazon12.org/php/ajaxContacta.php',
			type: "POST",
			data: "frmContactaNombre=" + $('#frmContactaNombre').val() +
				"&frmContactaMail=" + $('#frmContactaMail').val() +
				"&frmContactaTelefono=" + $('#frmContactaTelefono').val() +
				"&frmContactaConsulta=" + $('#frmContactaConsulta').val(),
			
			// SI NO SE PRODUCE UN ERROR EN LA LLAMADA AJAX
			success: function(data){
				$("#frmDifusor").css("background-color","White");
				$("#frmDifusor").show();
				$("#frmEnvioExito").fadeIn("slow");
			},
			
			// SI SE PRODUCE UN ERROR EN LA LLAMADA AJAX
			error: function(XMLHttpRequest,textStatus,errorThrown){
				$('#frmDifusor').css("background-color", "#9c0808");
				$("#frmDifusor").show();
				$("#frmEnvioError").fadeIn("slow");
			}			
		});
	}
	
}

function vaciarNombre(){
	$('#frmContactaNombre').css("background-color", "White");
	$('#frmContactaNombre').val('');
}

function vaciarTelefono(){
	$('#frmContactaTelefono').css("background-color", "White");
	$('#frmContactaTelefono').val('');
}

function vaciarConsulta(){
	$('#frmContactaConsulta').css("background-color", "White");
	$('#frmContactaConsulta').val('');
}

function cerrarPopUp(){
	$("#frmContactaError").hide();
	$("#frmMailError").hide();
	$("#frmTelefonoError").hide();
	$("#frmAvisoError").hide();
	$("#frmDifusor").hide();
}

function recargarFormulario(){
	$('#frmContactaNombre').val('');
	$('#frmContactaMail').val('');
	$('#frmContactaTelefono').val('');	
	$('#frmContactaConsulta').val('');
	$('#frmContactaLegal').attr('checked',false);
	
	$("#frmEnvioError").hide();	
	$("#frmEnvioExito").hide();
	$("#frmDifusor").hide();
}

function faseCaptacion(){
	document.getElementById('faseCaptacion').className= "load";
	document.getElementById('tituloCaptacion').className= "listaEncendido";
	document.getElementById('faseFormacion').className= "preload";
	document.getElementById('tituloFormacion').className= "listaApagado";
	document.getElementById('faseAplicacion').className= "preload";
	document.getElementById('tituloAplicacion').className= "listaApagado";
	document.getElementById('faseSeguimiento').className= "preload";
	document.getElementById('tituloSeguimiento').className= "listaApagado";
}

function faseFormacion(){
	document.getElementById('faseCaptacion').className= "preload";
	document.getElementById('tituloCaptacion').className= "listaApagado";
	document.getElementById('faseFormacion').className= "load";
	document.getElementById('tituloFormacion').className= "listaEncendido";
	document.getElementById('faseAplicacion').className= "preload";
	document.getElementById('tituloAplicacion').className= "listaApagado";
	document.getElementById('faseSeguimiento').className= "preload";
	document.getElementById('tituloSeguimiento').className= "listaApagado";
}

function faseAplicacion(){
	document.getElementById('faseCaptacion').className= "preload";
	document.getElementById('tituloCaptacion').className= "listaApagado";
	document.getElementById('faseFormacion').className= "preload";
	document.getElementById('tituloFormacion').className= "listaApagado";
	document.getElementById('faseAplicacion').className= "load";
	document.getElementById('tituloAplicacion').className= "listaEncendido";
	document.getElementById('faseSeguimiento').className= "preload";
	document.getElementById('tituloSeguimiento').className= "listaApagado";
}

function faseSeguimiento(){
	document.getElementById('faseCaptacion').className= "preload";
	document.getElementById('tituloCaptacion').className= "listaApagado";
	document.getElementById('faseFormacion').className= "preload";
	document.getElementById('tituloFormacion').className= "listaApagado";
	document.getElementById('faseAplicacion').className= "preload";
	document.getElementById('tituloAplicacion').className= "listaApagado";
	document.getElementById('faseSeguimiento').className= "load";
	document.getElementById('tituloSeguimiento').className= "listaEncendido";
}


function tratamientoRecepcion(){
	document.getElementById('tratamientoRecepcion').className= "load";
	document.getElementById('tituloRecepcion').className= "listaEncendido";
	document.getElementById('tratamientoEvaluacion').className= "preload";
	document.getElementById('tituloEvaluacion').className= "listaApagado";
	document.getElementById('tratamientoIntervencion').className= "preload";
	document.getElementById('tituloIntervencion').className= "listaApagado";
	document.getElementById('tratamientoObjetivos').className= "preload";
	document.getElementById('tituloObjetivos').className= "listaApagado";
}

function tratamientoEvaluacion(){
	document.getElementById('tratamientoRecepcion').className= "preload";
	document.getElementById('tituloRecepcion').className= "listaApagado";
	document.getElementById('tratamientoEvaluacion').className= "load";
	document.getElementById('tituloEvaluacion').className= "listaEncendido";
	document.getElementById('tratamientoIntervencion').className= "preload";
	document.getElementById('tituloIntervencion').className= "listaApagado";
	document.getElementById('tratamientoObjetivos').className= "preload";
	document.getElementById('tituloObjetivos').className= "listaApagado";
}

function tratamientoIntervencion(){
	document.getElementById('tratamientoRecepcion').className= "preload";
	document.getElementById('tituloRecepcion').className= "listaApagado";
	document.getElementById('tratamientoEvaluacion').className= "preload";
	document.getElementById('tituloEvaluacion').className= "listaApagado";
	document.getElementById('tratamientoIntervencion').className= "load";
	document.getElementById('tituloIntervencion').className= "listaEncendido";
	document.getElementById('tratamientoObjetivos').className= "preload";
	document.getElementById('tituloObjetivos').className= "listaApagado";
}

function tratamientoObjetivos(){
	document.getElementById('tratamientoRecepcion').className= "preload";
	document.getElementById('tituloRecepcion').className= "listaApagado";
	document.getElementById('tratamientoEvaluacion').className= "preload";
	document.getElementById('tituloEvaluacion').className= "listaApagado";
	document.getElementById('tratamientoIntervencion').className= "preload";
	document.getElementById('tituloIntervencion').className= "listaApagado";
	document.getElementById('tratamientoObjetivos').className= "load";
	document.getElementById('tituloObjetivos').className= "listaEncendido";
}

function verNoticia1(){
	document.getElementById('textoNoticias2').className= "preload";
	document.getElementById('textoNoticias3').className= "preload";
	document.getElementById('textoNoticias4').className= "preload";
	document.getElementById('textoNoticias1').className= "textoNoticias";
	
	document.getElementById('imagen1').src= "img/corazonblanconoticias.png";
	document.getElementById('imagen2').src= "img/corazonnoticias.png";
	document.getElementById('imagen3').src= "img/corazonnoticias.png";
	document.getElementById('imagen4').src= "img/corazonnoticias.png";
	
	cnt = 2;
	clearTimeout(reloj);
	setTimeout(carruselNoticias, 5000);
}
function verNoticia2(){
	document.getElementById('textoNoticias1').className= "preload";
	document.getElementById('textoNoticias3').className= "preload";
	document.getElementById('textoNoticias4').className= "preload";
	document.getElementById('textoNoticias2').className= "textoNoticias";
	
	document.getElementById('imagen2').src= "img/corazonblanconoticias.png";
	document.getElementById('imagen1').src= "img/corazonnoticias.png";
	document.getElementById('imagen3').src= "img/corazonnoticias.png";
	document.getElementById('imagen4').src= "img/corazonnoticias.png";
	
    cnt = 3;
    clearTimeout(reloj);
    setTimeout(carruselNoticias, 5000);
}
function verNoticia3(){
	document.getElementById('textoNoticias1').className= "preload";
	document.getElementById('textoNoticias2').className= "preload";
	document.getElementById('textoNoticias4').className= "preload";
	document.getElementById('textoNoticias3').className= "textoNoticias";
	
	document.getElementById('imagen3').src= "img/corazonblanconoticias.png";
	document.getElementById('imagen1').src= "img/corazonnoticias.png";
	document.getElementById('imagen2').src= "img/corazonnoticias.png";
	document.getElementById('imagen4').src= "img/corazonnoticias.png";

    cnt = 4;
    clearTimeout(reloj);
    setTimeout(carruselNoticias, 5000);
}
function verNoticia4(){
	document.getElementById('textoNoticias1').className= "preload";
	document.getElementById('textoNoticias2').className= "preload";
	document.getElementById('textoNoticias3').className= "preload";
	document.getElementById('textoNoticias4').className= "textoNoticias";
	
	document.getElementById('imagen4').src= "img/corazonblanconoticias.png";
	document.getElementById('imagen1').src= "img/corazonnoticias.png";
	document.getElementById('imagen2').src= "img/corazonnoticias.png";
	document.getElementById('imagen3').src= "img/corazonnoticias.png";

    cnt = 1;
    clearTimeout(reloj);
    setTimeout(carruselNoticias, 5000);
}

