// JavaScript Document

var mySlide;

window.addEvent('domready', function(){


	if($('FlashID')){
		swfobject.registerObject("FlashID");
	}
	SexyLightbox = new SexyLightBox({
		color:'blanco', emergefrom:'bottom',
		dir: '/_libreria/scripts/sexybox/sexyimages'
	});
	 
	
	if($('home')){
	SexyLightbox.display("/foto.html?TB_iframe=true&width=570&height=365", '', '');	
	}

/* FX.Slide */
/* toggle window for the login section */
/* Works with mootools-release-1.2 */
/* more info at http://demos.mootools.net/Fx.Slide */

	if($('login')){
		$('login').setStyle('height','auto');
		mySlide = new Fx.Slide('login').hide();  //starts the panel in closed state  
		if($('toggleLogin')){
			$('toggleLogin').addEvent('click', function(e){
			e = new Event(e);
			mySlide.toggle();
			e.stop();
			});
		}
		
		$('closeLogin').addEvent('click', function(e){
			e = new Event(e);
			mySlide.slideOut();
			e.stop();
		});
	}
	
	if($('enviar')){
		$('enviar').addEvent('click',function(e){								  
			$('formSistema').set('send',{
				onRequest: function() { $('proceso').set('html','verificando datos...'); },
				onSuccess:function(res){
					if(res=="OK"){
						document.location.href='/becarios';
					}else{
						$('proceso').set('html','Datos incorrectos, verifiquelos e intente de nuevo');	
					}
				}
				});
			$('formSistema').send();
		});
	}
	
	if(document.getElementById("imgBoletin")){
		document.getElementById("imgBoletin").onclick=function(){
		boletines('reg');
		}
	}
	
	if($('slide')){
		var V2 = new viewer($$('#slide img'),{
			mode: 'alpha',
			interval: 4500
		}).play(true);
	}
	
	$$("a").each(function(items){
				if($(items).get('title')!=null){
					$(items).tooltip ($(items).get('title'), { width: 300, style: 'alert' });
				}								
	});


});

function calendarioVer(dia,mes){
	c  = $('calendarioVer');
	var req = new Request({
    	    	    method: 'post',
        	    	url: '/llamada.php?im=0001',
	        	    data: { 'pr' : 'info', 'dia':dia,'mes':mes },
    	        	onRequest: function() { c.set('html','Cargando, un momento por favor'); },
               		update: c.set('html','Espere un momento por favor esta tardando mas de lo normal, si no carga, vuelva a intentarlo'),
 		       	    onComplete: function(response) { 
						c.set('html',response);
					}
	}).send();
}

function encuestaR(id,p){
	c  = $('encuesta');
	var req = new Request({
    	    	    method: 'post',
        	    	url: '/llamada.php?im=encuesta',
	        	    data: { 'pr' : 'info', 'id':id,'resp':p },
    	        	onRequest: function() { c.set('html','Cargando, un momento por favor'); },
               		update: c.set('html','Espere un momento por favor esta tardando mas de lo normal, si no carga, vuelva a intentarlo'),
 		       	    onComplete: function(response) { 
						c.set('html',response);
					}
	}).send();
}

function boletines(acto){
	c  = $('boletin');
	if(acto!="reg"){
		nombre= $('nombres');
		if(nombre.value==""){ nombre.focus(); return false; } 
		nombre= nombre.value;
		correo= $('correos');
		if(correo.value==""){ correo.focus(); return false; } 
		correo=correo.value;
	}else{
		nombre="";
		correo="";
	}
	var req = new Request({
    	    	    method: 'post',
        	    	url: '/llamada.php?im=boletin',
	        	    data: { 'pr' : acto, 'nombre':nombre,'correo':correo },
    	        	onRequest: function() { c.set('html','Cargando, un momento por favor'); },
               		update: c.set('html','Espere un momento por favor esta tardando mas de lo normal, si no carga, vuelva a intentarlo'),
 		       	    onComplete: function(response) { 
						c.set('html',response);
					}
	}).send();
}


function comprobarRE(id,p){
	formu=document.registroEmpresa;
	c  = document.getElementById('proceso');
	nombre=formu.nombre;
	contacto=formu.contacto;
	direccion=formu.direccion;
	telefono=formu.telefono;
	funcion= formu.funcion;
	correo=formu.correo;
	contrasenia=formu.contrasenia;
	cocontrasenia= formu.cocontrasenia;
	if(nombre.value==""){
		nombre.focus();
		return false;
	}
	if(contacto.value==""){
		contacto.focus();
		return false;
	}
	if(direccion.value==""){
		direccion.focus();
		return false;
	}
	if(telefono.value==""){
		telefono.focus();
		return false;
	}
	
	if(funcion.value==""){
		funcion.focus();
		return false;
	}
	if(correo.value==""){
		correo.focus();
		return false;
	}
	if(contrasenia.value==""){
		alert("La contrase\xf1a no debe estar en blanco");
		return false;
	}
	if(contrasenia.value!=cocontrasenia.value){
		alert("Las contrase\xf1as no coinciden");
		contrasenia.focus();
		return false;
	}
	informacion_enviar="registro=registro&nombre="+nombre.value+
	"&direccion="+direccion.value+"&contacto="+contacto.value+
	"&telefono="+telefono.value+"&funcion="+funcion.value+
	"&correo="+correo.value+"&contrasenia="+cocontrasenia.value;
	ajax=nuevoAjax();
	c.innerHTML = '<p style="text-align:center;"><span>Registrando, espere un momento por favor...<img src="_libreria/envio/esperando.gif"/></p>'; 
	ajax.open("POST", "llamada.php?id=empresa/0002&im=registro",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			c.innerHTML = ajax.responseText
		}
		
	}  //NO TOCAR
	
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send(informacion_enviar);
}