// JavaScript Document


// ****************************************************************
// ******************* FUNCIONES DE FORMULARIOS *******************
// ****************************************************************

function Focus(elem,txt){
	if(elem.value == txt){
		elem.value = '';
	}	
}

function Blur(elem,txt){
	if(elem.value == ''){
		elem.value = txt;
	}	
}

function FocusEmail(elem){
	if(elem.value == 'Email'){
		elem.value = '';
		elem.style.backgroundColor = '#ebebeb';
	}	
}

function KeyUpEmail(elem){
	if(elem.value != ''){
		if(!valEmail(elem.value)){
			elem.style.backgroundColor = '#f7c3c3';			
		} else {
			elem.style.backgroundColor = '#cdf7c3';
		}
	} else {
		elem.style.backgroundColor = '#ebebeb';
	}
}
function BlurEmail(elem){
	if(elem.value == ''){
		elem.value = 'Email';
		elem.style.backgroundColor = '#ebebeb';
	}	
}

function valEmail(valor){
    re=/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]*(.[a-z0-9-]+)+(.[a-z]{2,3})$/
    if(!re.exec(valor))    {
        return false;
    }else{
        return true;
    }
}

// ****************************************************************
// ******************** FUNCIONES DE MENU *************************
// ****************************************************************



function irInscripcion(elem){
	if(elem.value != ''){
		if(valEmail(elem.value)){
			location.href='interna.php?m=9&email='+elem.value;
		} 
	}
}

function showAlert(){
	//Effect.toggle('alert','slide', { duration: 1 }); return false;	
	$(document).ready(function(){
		$("#alert").slideDown("slow")
	})
}

function closeAlert(){
	//Effect.toggle('alert','slide', { duration: 1 }); return false;	
	$(document).ready(function(){
		$("#alert").slideUp("slow")
	})
}


function sendEmail(){
	$(document).ready(function(){
		
		var dataString = $("#form_c").serialize();
		
		$("#form_contacto").html("<img src='../images/ajax-loader.gif'  alt='.' />");
		
		$.ajax({
			type: "GET",
			url: "contacto_form_send.php",
			data: dataString,
			cache: false,
			success: function(respuesta) {
				$("#form_contacto").html(respuesta);
			}
		});
		
	});
}


function loadForm(){
	$(document).ready(function(){
		
		$("#form_contacto").html("<img src='../images/ajax-loader.gif'  alt='.' />");
		
		$.ajax({
			type: "GET",
			url: "contacto_form.php",
			cache: false,
			success: function(respuesta) {
				$("#form_contacto").html(respuesta);
				var VanadiumRules = {
					email: ['required', 'email'],
					nom: ['accept'],
					msj: ['required']
				}
			}
		});
		
		
	});
}

function validar(){
	$(document).ready(function(){
		
		var complete = 0;
		
		if($("#nom").val() == ""){
			$("#nom_alert").html('(Campo obligatorio)');
		} else {
			$("#nom_alert").html('');
			complete++;
		}
		
		if($("#email").val() == ""){
			$("#email_alert").html('(Campo obligatorio)');
		} else {
			if (!valEmail($("#email").val())){
				$("#email_alert").html('(Debe ser el formato correcto: ejemplo@correo.com)');
			} else {
				$("#email_alert").html('');
				complete++;
			}
		}
		
		if($("#msj").val() == ""){
			$("#msj_alert").html('(Campo obligatorio)');
		} else {
			$("#msj_alert").html('');
			complete++;
		}
		
		if(complete ==3){
			sendEmail();
		}
		
		
	});
}


function validar_inscripcion(){
	$(document).ready(function(){
		
		var complete = 0;
		
		if($("#nom").val() == ""){
			$("#nom_alert").html('(Campo obligatorio)');
		} else {
			$("#nom_alert").html('');
			complete++;
		}
		
		if($("#ape").val() == ""){
			$("#ape_alert").html('(Campo obligatorio)');
		} else {
			$("#ape_alert").html('');
			complete++;
		}
		
		if($("#email").val() == ""){
			$("#email_alert").html('(Campo obligatorio)');
		} else {
			if (!valEmail($("#email").val())){
				$("#email_alert").html('(Debe ser el formato correcto: ejemplo@correo.com)');
			} else {
				$("#email_alert").html('');
				complete++;
			}
		}
		
		if($("#profesion").val() == ""){
			$("#profesion_alert").html('(Campo obligatorio)');
		} else {
			$("#profesion_alert").html('');
			complete++;
		}
		
		if($("#centro").val() == ""){
			$("#centro_alert").html('(Campo obligatorio)');
		} else {
			$("#centro_alert").html('');
			complete++;
		}
		
		
		
		if(complete ==5){
			sendInscripcion();
		}
		
		
	});
}


function sendInscripcion(){
	$(document).ready(function(){
		
		var dataString = $("#form_c").serialize();
		
		$("#form_contacto").html("<img src='../images/ajax-loader.gif'  alt='.' />");
		
		$.ajax({
			type: "GET",
			url: "inscripcion_form_send.php",
			data: dataString,
			cache: false,
			success: function(respuesta) {
				$("#form_contacto").html(respuesta);
			}
		});
		
	});
}


function loadInscripcion(){
	$(document).ready(function(){
		
		$("#form_contacto").html("<img src='../images/ajax-loader.gif'  alt='.' />");
		
		$.ajax({
			type: "GET",
			url: "inscripcion_form.php",
			cache: false,
			success: function(respuesta) {
				$("#form_contacto").html(respuesta);
				var VanadiumRules = {
					email: ['required', 'email'],
					nom: ['accept'],
					msj: ['required']
				}
			}
		});
		
		
	});
}



function anularSubmit(e) {
  // averiguamos el código de la tecla pulsada (keyCode para IE y which para Firefox)
  tecla = (document.all) ? e.keyCode :e.which;
  // si la tecla no es 13 devuelve verdadero,  si es 13 devuelve false y la pulsación no se ejecuta
  return (tecla!=13);
}

