/*
	UNIVERSIDAD DE ALCALA

	SCRIPTS

	Borja Delgado	- http://www.orangeside.org
	12 - 2006
*/

if(!window.EXTRAS) EXTRAS = {};

UAH = {

	preventExplorerFlicker : function() { 
			try {
				document.execCommand("BackgroundImageCache", false, true);
			} catch(err) {}
	},

	/*
		ADAPTED FROM:	Sergi Messeguer
									http://www.zigotica.com/
	*/

	popThisUp : function(obj) {
			obj.onclick = function() {
				window.open(obj.href, '');
				return false;
			}
	},

	autoPopup : function() {
			var pops = EXTRAS.getElementsByClass('popup',null , 0);
			for (var i = 0; i < pops.length; i++) {
					UAH.popThisUp(pops[i]);
			}
	},

	addStyles : function() {
		//alert("En la función");
        if(document.getElementById('cambio_estilos')) document.getElementById('cambio_estilos').innerHTML = '<a href="javascript:void(null);" id="texto_menor" tabindex="29" title="Tama&ntilde;o de letra por defecto" class="cambio_estilos"><span class="letra_peq">A</span></a> <a href="javascript:void(null);" id="texto_medio" tabindex="30" title="Tama&ntilde;o de letra medio" class="cambio_estilos"><span class="letra_med">A</span></a> <a href="javascript:void(null);" id="texto_mayor"  tabindex="31" title="Tama&ntilde;o de letra mayor" class="cambio_estilos"><span class="letra_gran">A</span></a>';
        var a = document.getElementById('texto_menor');
        var b = document.getElementById('texto_medio');
        var c = document.getElementById('texto_mayor');
		
        a.onclick = a.onkeypress = b.onclick = b.onkeypress = c.onclick = c.onkeypress = function (e) {
			//alert("entrando en la función" + this.id);
            if (!e) e = window.event;
            if(e.type == "keypress" && e.keyCode != 13) return;
            if(e.type == "click") this.blur();
            UAH.setActiveStyleSheet(this.id);
            return false;
        }
    },

	addPrinter : function() {
        if(document.getElementById('imprimir')) document.getElementById('imprimir').innerHTML = '<a href="#" title="Imprimir la p&aacute;gina" onclick=" window.print(); return false;" accesskey="4" title="Imprimir pagina ( alt + 4 )">Imprimir</a> |';
    },
	
	addStartPage : function() {
        if(document.getElementById('haz_pagina_inicio')) document.getElementById('haz_pagina_inicio').innerHTML = '<a href="../www.uah.es/scripts/default.htm" onclick="this.style.behavior=\'url(#default#homepage)\';this.setHomePage(\'default.htm\');return false;" style="cursor: hand">Haz de la UAH tu página de inicio</a>';
    },

	/*
		ADAPTED FROM:	A List Apart - Working With Alternate Style Sheets
									http://www.alistapart.com/stories/alternate/
	*/

	initiateStyles : function(e) {
		var cookie = UAH.readCookie("style");
		var title = cookie ? cookie : UAH.getPreferredStyleSheet();
		if ((title!="texto_menor") && (title!="texto_medio") && (title!="texto_mayor"))
		 { 
		    title = "texto_menor";
		 }
		UAH.setActiveStyleSheet(title);
	},

	setSheet : function(e) {
		var title = UAH.getActiveStyleSheet();
		UAH.createCookie("style", title, 365);
	},

	setActiveStyleSheet : function(title) {
		var i, a, main;
		for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
			if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
				a.disabled = true;
				if(a.getAttribute("title") == title) a.disabled = false;
			}
		}
	},

	getActiveStyleSheet : function() {
		var i, a;
		for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
			if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
		}
		return null;
	},

	getPreferredStyleSheet : function() {
		var i, a;
		for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
			if(a.getAttribute("rel").indexOf("style") != -1
				 && a.getAttribute("rel").indexOf("alt") == -1
				 && a.getAttribute("title")
				 ) return a.getAttribute("title");
		}
		return null;
	},

	createCookie : function(name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	},

	readCookie : function(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}

}

//Busqueda de personal
function cargarVisual(valor1,valor2)
  {
	  var opciones="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=508,height=440,top=170,left=220";

      var titulo="";
      window.open("visualizar.asp@id1="+document.getElementById("idpersona1").value+"&id2="+document.getElementById("idpersona2").value,titulo,opciones);
  }
  
function mayus()
  {
	form13.Nomb.value=form13.Nomb.value.toUpperCase();
	form13.Nomb.value=acentos(form13.Nomb.value);
	form13.Ape1.value=form13.Ape1.value.toUpperCase();
	form13.Ape1.value=acentos(form13.Ape1.value);
	form13.Ape2.value=form13.Ape2.value.toUpperCase();
	form13.Ape2.value=acentos(form13.Ape2.value);
	form13.submit();
  }
  
function cambiarValor(i)
  {
	  switch (i)
	   {
	    case 1: document.getElementById("idpersona1").value="";break;
		case 2: document.getElementById("idpersona2").value="";break;
		case 3: document.getElementById("comboPuesto").value="";
				document.getElementById("Nomb").value="";
				document.getElementById("Ape1").value="";
				document.getElementById("Ape2").value=""; break;
		case 4: document.getElementById("comboCargo").value="";
				document.getElementById("Nomb").value="";
				document.getElementById("Ape1").value="";
				document.getElementById("Ape2").value=""; break;
		case 5: document.getElementById("comboPuesto").value="";
				document.getElementById("comboCargo").value="";break;
	   }
  }
function acentos(x) 
  {

	x = x.replace(/À/g,"A");    x = x.replace(/È/g,"E");	x = x.replace(/Ì/g,"I");
	x = x.replace(/Á/g,"A");    x = x.replace(/É/g,"E");	x = x.replace(/Í/g,"I");
	x = x.replace(/Â/g,"A");    x = x.replace(/Ê/g,"E");	x = x.replace(/Î/g,"I");
	x = x.replace(/Ä/g,"A");    x = x.replace(/Ë/g,"E");	x = x.replace(/Ï/g,"I");
	
	x = x.replace(/Ò/g,"O");	x = x.replace(/Ù/g,"U");
	x = x.replace(/Ó/g,"O");	x = x.replace(/Ú/g,"U");
	x = x.replace(/Ô/g,"O");	x = x.replace(/Û/g,"U");
	x = x.replace(/Ö/g,"O");	x = x.replace(/Ü/g,"U");
		
	return x
}

function esMail(Cadena) {

	Punto = Cadena.substring(Cadena.lastIndexOf('.') + 1, Cadena.length)			// Cadena del .com
	Dominio = Cadena.substring(Cadena.lastIndexOf('@') + 1, Cadena.lastIndexOf('.')) 	// Dominio @lala.com
	Usuario = Cadena.substring(0, Cadena.lastIndexOf('@'))					// Cadena lalala@
	Reserv = "_40/_25BA\"\'+*{}\\<>?¿[]áéíóú#·¡!^*;,:"						// Letras Reservadas
	
	// Añadida por El Codigo para poder emitir un alert en funcion de si email valido o no
	valido = true
	
	// verifica qie el Usuario no tenga un caracter especial
	for (var Cont=0; Cont<Usuario.length; Cont++) {
		X = Usuario.substring(Cont,Cont+1)
		if (Reserv.indexOf(X)!=-1)
                	valido = false
	}

	// verifica qie el Punto no tenga un caracter especial
	for (var Cont=0; Cont<Punto.length; Cont++) {
		X=Punto.substring(Cont,Cont+1)
		if (Reserv.indexOf(X)!=-1)
			valido = false
	}
                        
	// verifica qie el Dominio no tenga un caracter especial
	for (var Cont=0; Cont<Dominio.length; Cont++) {
		X=Dominio.substring(Cont,Cont+1)
		if (Reserv.indexOf(X)!=-1)
			valido = false
		}

	// Verifica la sintaxis básica.....
	if (Punto.length<2 || Dominio <1 || Cadena.lastIndexOf('.')<0 || Cadena.lastIndexOf('@')<0 || Usuario<1) {
		valido = false
	}

	return valido
}


