/*De: http://www.estadobeta.net/2006/10/10/prototype-ajax/*/
/* Javascript: se define un objeto con callbacks globales */
var globalCallbacks = {
		
		onCreate: function(){
			$('cargando').show();
                },
                onComplete: function() {			
                        if(Ajax.activeRequestCount == 0){
                                $('cargando').hide();
                        }
                }
        };
/* Se registran los callbacks en Ajax.Responders */
Ajax.Responders.register( globalCallbacks );
/*Fin Estado Beta//////////////////////////////////////////////////////////////////////////////////////////////////*/

/*aquí van las funciones javascript que se encargan de validar el formulario y gestionar las peticiones*/

function procesaRespuesta(resp){//esta es la función que presenta el resultado en la página objetivo
	$("content").innerHTML = resp.responseText;
}

function go(target){
	var ajax = new Ajax.Request( ''+target+'.html', {onComplete: procesaRespuesta	});
}

function goPhp(target){
	var ajax = new Ajax.Request( ''+target+'.php', {onComplete: procesaRespuesta	});
}
function enviaMail(){
	var asesor = $F('list_asesor');
	var nombre = $F('txt_nombre');
	var email = $F('txt_email');
	var mensaje = $F('textarea');
	var name = $F('name');

	if(name !='') exit;
	if(asesor == '0') {alert('Debe especificar un/a asesor/a a quien realizar la consulta');exit;}
	if(nombre == '') {alert('Debe indicar su nombre');exit;}
	if(email == '') {alert('Debe indicar su email para que le podamos contestar');exit;}
	if(mensaje == '') {alert('El texto de la consulta no puede estar vacío');exit}

	var url='mail.php';
	var parametros = Form.serialize($('formulario'));
	var ajax = new Ajax.Request( url, {
				parameters: parametros,
				method:"post",
				onComplete: procesaRespuesta
				});
}

function validaCom(){
	if(name !='') exit;
	var nom = $F('txt_nom');
	var ape = $F('txt_ape');
	var nif = $F('txt_nif');
	var ema = $F('txt_ema');
	var te1 = $F('txt_te1');
	var cen = $F('txt_cen');
	var niv = $F('list_niv');
	var tit = $F('txt_tit');
	var cep = $F('list_cep');
	var file = $F('myfile');

	if(nom == '') {alert('Debe indicar su nombre');exit;}
	if(ape == '') {alert('Debe indicar sus apellidos');exit;}
	if(nif == '') {alert('Debe indicar su NIF');exit;}
	if(ema == '') {alert('Debe indicar un email de contacto');exit;}
	if(te1 == '') {alert('Debe indicar un teléfono de contacto');exit;}
	if(cen == '') {alert('Debe indicar el Centro educativo donde trabaja');exit;}
	if(niv == '0') {alert('Debe indicar el nivel educativo que imparte');exit;}
	if(cep == '0') {alert('Debe indicar el CEP/CRAER de su zona');exit;}	
	if(file == '') {alert('Debe adjuntar el archivo de la Comunicación');exit;}

	document.formulario.submit();
}

function validaFoto(){
	if(name !='') exit;
	var nom = $F('txt_nom');
	var ape = $F('txt_ape');
	var nif = $F('txt_nif');
	var ema = $F('txt_ema');
	var te1 = $F('txt_te1');
	var cen = $F('txt_cen');
	var tit = $F('txt_tit');
	var mod = $F('list_mod');
	var file = $F('myfile');

	if(nom == '') {alert('Debe indicar su nombre');exit;}
	if(ape == '') {alert('Debe indicar sus apellidos');exit;}
	if(nif == '') {alert('Debe indicar su NIF');exit;}
	if(cen == '') {alert('Debe indicar el Centro educativo donde trabaja');exit;}
	if(ema == '') {alert('Debe indicar un email de contacto');exit;}
	if(te1 == '') {alert('Debe indicar un teléfono de contacto');exit;}
	if(tit == '') {alert('La fotografía debe tener un título');exit;}
	if(mod == '0') {alert('Debe indicar la modalidad de concurso');exit;}
	if(file == '') {alert('Debe adjuntar la fotografía');exit;}

	document.formulario.submit();
}


function validaIns(){
	if(name !='') exit;
        var cal = $F('list_cal');
	var nom = $F('txt_nom');
	var ape = $F('txt_ape');
	var nif = $F('txt_nif');
	var nrp = $F('txt_nrp');
	var ema = $F('txt_ema');
	var te1 = $F('txt_te1');
	var te2 = $F('txt_te2');
	var cen = $F('txt_cen');
	var esp = $F('txt_esp');
	var niv = $F('list_niv');
	var cep = $F('list_cep');
	var cj = $F('cb_cj');
	var ah = $F('cb_ah');
	var cv = $F('cb_cv');
	
        if(cal == '0') {alert('Debe indicar el tipo de participación');exit;}
	if(nom == '') {alert('Debe indicar su nombre');exit;}
	if(ape == '') {alert('Debe indicar sus apellidos');exit;}
	if(nif == '') {alert('Debe indicar su NIF');exit;}
	if(ema == '') {alert('Debe indicar un email de contacto');exit;}
	if(te1 == '') {alert('Debe indicar, al menos, un teléfono de contacto');exit;}
	if(cen == '') {alert('Debe indicar el Centro educativo donde trabaja');exit;}
	if(cep == '0') {alert('Debe indicar el CEP / CRAER de su zona');exit;}
	if(niv == '0') {alert('Debe indicar el nivel educativo que imparte');exit;}
	
	
	var url='inscrip.php';
	var parametros = Form.serialize($('f_ins'));
	var ajax = new Ajax.Request( url, {
				parameters: parametros,
				method:"post",
				onComplete: procesaRespuesta
				});
}


/*FUNCIONES ADMIN*/

function procesaRespuestaAdmin(resp){//esta es la función que presenta el resultado en la página objetivo
	$("resultado").innerHTML = resp.responseText;
}

function lista(item,url,valor){
	var url=""+url+".php";
	var parametros = "item="+item+"&valor="+valor+"";
	var ajax = new Ajax.Request( url, {
				parameters: parametros,
				method:"post",
				onComplete: procesaRespuestaAdmin
				});
}

function goAdmin(url){
	var url=""+url+".php";
	var ajax = new Ajax.Request( url, {
				onComplete: procesaRespuestaAdmin
				});
}

function fichaCom(id){
	var url="ficha_com.php";
	var parametros = "id="+id+"";
	var ajax = new Ajax.Request( url, {
				parameters: parametros,
				method:"post",
				onComplete: procesaRespuestaAdmin
				});
}


