var theWin = "";
//Usado para cursillo 2003 Videoporordenador
function launchPage(url) {
 if(theWin && !theWin.closed) {
  theWin.focus();
  theWin.location.href = url;
 } else {
  theWin = window.open(url,'launchPage','width=640,height=480,resizable=yes,scrollbars=no,menubar=no,toolbar=no,directories=no,location=no,status=no');
 }     
}


function enf() {
	document.forms['fo'].nom.focus();
}

function enpu() {
	document.fo.titulo.focus();
}

function enfi() {
	document.forms['fo'].alias.focus();
}

function enfic() {
	document.fo.catenombre.focus();
}

function enfice() {
	document.fo.enlanombre.focus();
}


function clearForm(form) {
	//De: http://www.webmasterworld.com/forum91/3832.htm
	//Para que funcione bien la opcion "Limpiar" cuando el formulario contiene valores
	for (i=0;i<form.elements.length;i++) {
		var element = form.elements[i];
		if ((element.type == 'text') | (element.type == 'textarea') | (element.type == 'file')) {
			element.value = '';
		}
		else if (element.type == 'select-one') {
			element.selectedIndex = 0;
		}
		else if (element.type == 'radio') {
			var elementName = element.name;
			var radio = eval('form.' + elementName);
			for (r=0;r<radio.length;r++) {
				if (r == 0) {
					eval('form.'+elementName+'['+r+'].checked=true');
				}
				else {
					eval('form.'+elementName+'['+r+'].checked=false');
				}
			}
		}
	}
} 


function valeagen() {
	
	//Validacion de HORA correcta -Aleluya! Lo hice! Maldito javascript!
	resp = document.agen.hora.value.charAt(2);
	nuno = document.agen.hora.value.charAt(0);
	ndos = document.agen.hora.value.charAt(1);
	ntre = document.agen.hora.value.charAt(3);
	ncua = document.agen.hora.value.charAt(4);
	
	titu = document.agen.titulo.value;
	
	desc = document.agen.descripcion.value;
	
	vale = 0;
	if ((nuno == 0) | (nuno == 1) | (nuno == 2)) {
		if ((ndos == 0) | (ndos == 1) | (ndos == 2) | (ndos == 3) | (ndos == 4) | (ndos == 5) | (ndos == 6) | (ndos == 7) | (ndos == 8) | (ndos == 9)) {
			if ((ntre == 0) | (ntre == 1) | (ntre == 2) | (ntre == 3) | (ntre == 4) | (ntre == 5)) {
				if ((ncua == 0) | (ncua == 1) | (ncua == 2) | (ncua == 3) | (ncua == 4) | (ncua == 5) | (ncua == 6) | (ncua == 7) | (ncua == 8) | (ncua == 9)) {
					vale = 1;
				}
			}
		}
	}

	if (nuno == 2) {
		if (ndos > 3) {
			vale = 0;
		}	
	}
	mensaje = 0;
	if ((resp == ':') & (vale == 1)) {
		$devuelve = true;
	} else {
		mensaje = 1;
		alert('La hora introducida no es válida! '+titu);
		document.agen.hora.focus();
		devuelve = false;
	}
	
	if (titu == "") {
		devuelve = false;
		if (mensaje == 0) {
			mensaje = 1;
			alert('Debes introducir un título para el evento!');
			document.agen.titulo.focus();
		}
	}
	
	if (desc == "") {
		devuelve = false;
		if (mensaje == 0) {
			alert('Debes introducir la descripción del evento!');
			document.agen.descripcion.focus();
		}
	}
	
	return devuelve;
	
}
function validacua() {
	
	alerta = 0;
	devuelve = true;
	if ((document.fo.nom.value=="")||(document.fo.mensaje.value=="")||(document.fo.email.value=="")||(document.fo.asun.value==""))
	{
		
		alerta = 1;
		
		if (document.fo.mensaje.value=="") {
			document.fo.mensaje.focus();
		}		
		if (document.fo.asun.value=="") {
			document.fo.asun.focus();
		}
		if (document.fo.email.value=="") {
			document.fo.email.focus();
			alerta = 2;
		}
				
		if (document.fo.nom.value=="") {
			document.fo.nom.focus();
		}
		
		devuelve = false;
		
	}
	
	if (alerta < 2) {
		
		vemail = document.fo.email.value;
		
		resp = document.fo.email.value.indexOf('@');
		
		if (resp == -1) {
			alert('El campo email no es valido!');
			document.fo.email.focus();
			alerta = 0;
			devuelve = false;
		}
		
	}
	
	if (alerta > 0) {
		alert('Debes rellenar los cuatro campos, gracias');
	}
	
	return devuelve;
}

function validados() {
	
	alerta = 0;
	devuelve = true;
	if ((document.fo.nom.value=="")||(document.fo.mensaje.value=="")||(document.fo.email.value=="")||(document.fo.asun.value==""))
	{
		
		alerta = 1;
		
		if (document.fo.mensaje.value=="") {
			document.fo.mensaje.focus();
		}		
		if (document.fo.asun.value=="") {
			document.fo.asun.focus();
		}
		if (document.fo.email.value=="") {
			document.fo.email.focus();
			alerta = 2;
		}
				
		if (document.fo.nom.value=="") {
			document.fo.nom.focus();
		}
		
		devuelve = false;
		
	}
	
	if (alerta < 2) {
		
		vemail = document.fo.email.value;
		
		resp = document.fo.email.value.indexOf('@');
		
		if (resp == -1) {
			alert('El campo email no es valido!');
			document.fo.email.focus();
			alerta = 0;
			devuelve = false;
		}
		
	}
	
	if (alerta > 0) {
		alert('Todos los campos son obligatorios, excepto Adjunto.');
	}
	
	return devuelve;
			
}



function validatres() {
	if ((document.fo.alias.value=="")||(document.fo.clave.value=="")||(document.fo.checkcod.value==""))
	{
		
		if (document.fo.checkcod.value=="") {
			document.fo.checkcod.focus();
		}
		
		
		if (document.fo.clave.value=="") {
			document.fo.clave.focus();
		}
		
		
		if (document.fo.alias.value=="") {
			document.fo.alias.focus();
		}
		
		return false;
		
	}
}

function valien() {
	if ((document.fo.enlanombre.value=="")||(document.fo.enlaceURL.value==""))
	{
		
		if (document.fo.enlaceURL.value=="") {
			document.fo.enlaceURL.focus();
		}
		
		
		if (document.fo.enlanombre.value=="") {
			document.fo.enlanombre.focus();
		}
		
		return false;
		
	}
}

	

function valienmo() {
	if (((document.fo.enlanombre.value=="")||(document.fo.enlaceURL.value=="")) && (document.fo.eliminar.value != "on"))
	{
		
		if (document.fo.enlaceURL.value=="") {
			document.fo.enlaceURL.focus();
		}
		
		
		if (document.fo.enlanombre.value=="") {
			document.fo.enlanombre.focus();
		}
		
		return false;
		
	}
}


//Función traida con nostalgia de Sincalma 2.0
function f_UrlTarget(UrlTarget)	{
	
	var str= UrlTarget;
	var pos=str.indexOf('@@@@');
	var vlen = str.length;
	var vUrl = str.substr(0,pos);
	var vTarget = str.substr(pos + 4,vlen - pos - 4);
	if  (vTarget.indexOf('_top') > -1 || vTarget.indexOf('_parent') > -1 ) 
	window.top.location = vUrl;
	else
		if (vTarget.indexOf('_blank') > -1) 
			window.open(vUrl);
	return;
}
		

function abre(objeto,este) {
	
	var scr_w = screen.availWidth;
	var scr_h = screen.availHeight;
	var browseWidth, browseHeight;

	if (document.layers) {
		browseWidth=window.outerWidth;
   		browseHeight=window.outerHeight;
	}
	
	if (document.all) {
		browseWidth=document.body.clientWidth;
		browseHeight=document.body.clientHeight;
	}

	if (window.event) {
	  	lalY = browseHeight - event.clientY - 20;
  		limite = browseHeight - 250;

		if (document.getElementById) {
			if (lalY > limite) {
				document.getElementById(objeto).style.bottom =  lalY-100;
		  
	  		} else {
		  		document.getElementById(objeto).style.bottom =  lalY;
	  		}
	
    		document.getElementById(objeto).style.visibility = 'visible';
  		} else if (document.layers && document.layers[objeto]) {
	
	  		if (lalY > limite) {
		  		document.layers[objeto].style.bottom =  lalY-100;
		  
	  		} else {
		  		document.layers[objeto].style.bottom =  lalY;
	  		}
	  	
    		document.layers[objeto].visibility = 'visible';
  		} else if (document.all) {
	  		if (lalY > limite) {
		  		document.all[objeto].style.bottom =  lalY-100;
	  		} else {
		  		document.all[objeto].style.bottom =  lalY;
	  		}
	  
    		document.all[objeto].style.visibility = 'visible';
  		}
  		
  		
  	} else {
			
		laalY = este.pageY;
		lallY = window.pageYOffset;
		laoY = window.outerHeight;
		layY = window.innerHeight;
	   
		coar = lallY;
		coab = lallY + layY;
		disu = coab - laalY; 

		//alert(lallY+' '+laalY+' dif:'+disu);
		if (document.getElementById) {
		
			if (disu > 150) {
				document.getElementById(objeto).style.top = laalY;
	  		} else {
				document.getElementById(objeto).style.top = laalY-160;
			}
			document.getElementById(objeto).style.visibility = 'visible';
		}
	}

}
 
function cierra(objeto) {
	if (document.getElementById) {
		document.getElementById(objeto).style.visibility = 'hidden';
	} else if (document.layers && document.layers[objeto]) {
		document.layers[objeto].visibility = 'hidden';
	} else if (document.all) {
		document.all[objeto].style.visibility = 'hidden';
	}
}

