/**********************************************************************************/
/* Mostrar submenús en IE6 correctamente */


//SuckerTree Horizontal Menu (Sept 14th, 06)
//By Dynamic Drive: http://www.dynamicdrive.com/style/

var menuids=["nav"] //Enter id(s) of SuckerTree UL menus, separated by commas

function buildsubmenus_horizontal()
{
	for (var i=0; i<menuids.length; i++)
	{
		var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul");
		for (var t=0; t<ultags.length; t++)
		{
			ultags[t].parentNode.onmouseover=function()
			{
				this.getElementsByTagName("ul")[0].style.visibility="visible";
				this.className+=" sfhover";
			}
			ultags[t].parentNode.onmouseout=function()
			{
				this.getElementsByTagName("ul")[0].style.visibility="hidden";
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}

if (window.addEventListener)
window.addEventListener("load", buildsubmenus_horizontal, false)
else if (window.attachEvent)
window.attachEvent("onload", buildsubmenus_horizontal)


/*sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
		document.getElementById("nav").onmousemove=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}*/
		/*
		document.getElementById("body").onmousemove=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
		*/
	/*}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);*/


/**********************************************************************************/
/* Mostrar fecha actual */

function fecha()
{
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var dayarray=new Array("Domingo","Lunes","Martes","Mi&eacute;rcoles","Jueves","Viernes","S&aacute;bado")
var montharray=new Array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre")
document.write(""+dayarray[day]+" "+daym+" de "+montharray[month]+" de "+year)
}


/**********************************************************************************/
/* Mostrar y actualizar hora actual */

function show5(){
if (!document.layers&&!document.all&&!document.getElementById)
return

 var Digital=new Date()
 var hours=Digital.getHours()
 var minutes=Digital.getMinutes()
 var seconds=Digital.getSeconds()

 if (hours<=9)
 hours="0"+hours
 if (minutes<=9)
 minutes="0"+minutes
 if (seconds<=9)
 seconds="0"+seconds
//change font size here to your desire
myclock=""+hours+":"+minutes+""
if (document.layers){
document.layers.liveclock.document.write(myclock)
document.layers.liveclock.document.close()
}
else if (document.all)
liveclock.innerHTML=myclock
else if (document.getElementById)
document.getElementById("liveclock").innerHTML=myclock
setTimeout("show5()",1000)
 }
 
//window.onload=show5


/**********************************************************************************/
/* Quitar espacios sobrantes en cadena al principio y final */

function ltrim(s) {
	return s.replace(/^\s+/, "");
}

function rtrim(s) {
	return s.replace(/\s+$/, "");
}

function trim(s) {
	return rtrim(ltrim(s));
}



/**********************************************************************************/
/* Mostar años segun su fechas de nacimiento */
//calcular la edad de una persona 
//recibe la fecha como un string en formato español 
//devuelve un entero con la edad. Devuelve false en caso de que la fecha sea incorrecta o mayor que el dia actual 
function calcular_edad(fecha){ 

//calculo la fecha de hoy 
hoy=new Date() 
//alert(hoy) 

//calculo la fecha que recibo 
//La descompongo en un array 
var array_fecha = fecha.split("/") 
//si el array no tiene tres partes, la fecha es incorrecta 
if (array_fecha.length!=3) 
return false 

//compruebo que los ano, mes, dia son correctos 
var ano 
ano = parseInt(array_fecha[2]); 
if (isNaN(ano)) 
return false 

var mes 
mes = parseInt(array_fecha[1]); 
if (isNaN(mes)) 
return false 

var dia 
dia = parseInt(array_fecha[0]); 
if (isNaN(dia)) 
return false 


//si el año de la fecha que recibo solo tiene 2 cifras hay que cambiarlo a 4 
if (ano<=99) 
ano +=1900 

//resto los años de las dos fechas 
edad=hoy.getFullYear()- ano - 1; //-1 porque no se si ha cumplido años ya este año 

//si resto los meses y me da menor que 0 entonces no ha cumplido años. Si da mayor si ha cumplido 
if (hoy.getMonth() + 1 - mes < 0) //+ 1 porque los meses empiezan en 0 
return edad 
if (hoy.getMonth() + 1 - mes > 0) 
return edad+1 

//entonces es que eran iguales. miro los dias 
//si resto los dias y me da menor que 0 entonces no ha cumplido años. Si da mayor o igual si ha cumplido 
if (hoy.getUTCDate() - dia >= 0) 
return edad + 1 

return edad 
}



/**********************************************************************************/
/* Validar NIF NIE CIF */


function str_replace(search, replace, subject) { 
    var f = search, r = replace, s = subject;
    var ra = r instanceof Array, sa = s instanceof Array, f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;
 
    while (j = 0, i--) {
        if (s[i]) {
            while (s[i] = s[i].split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
        }
    };
 
    return sa ? s : s[0];
}

//Retorna: 1 = NIF ok, 2 = CIF ok, 3 = NIE ok, -1 = NIF error, -2 = CIF error, -3 = NIE error, 0 = ??? error
function valida_nif_cif_nie(a) 
{
	var temp=a.toUpperCase();
	var cadenadni="TRWAGMYFPDXBNJZSQVHLCKE";
 
	if (temp!==''){
		//si no tiene un formato valido devuelve error
		if ((!/^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$/.test(temp) && !/^[T]{1}[A-Z0-9]{8}$/.test(temp)) && !/^[0-9]{8}[A-Z]{1}$/.test(temp))
		{
			return 0;
		}
 
		//comprobacion de NIFs estandar
		if (/^[0-9]{8}[A-Z]{1}$/.test(temp))
		{
			posicion = a.substring(8,0) % 23;
			letra = cadenadni.charAt(posicion);
			var letradni=temp.charAt(8);
			if (letra == letradni)
			{
			   	return 1;
			}
			else
			{
				return -1;
			}
		}
 
		//algoritmo para comprobacion de codigos tipo CIF
		suma = parseInt(a.charAt(2))+parseInt(a.charAt(4))+parseInt(a.charAt(6));
		for (i = 1; i < 8; i += 2)
		{
			temp1 = 2 * parseInt(a.charAt(i));
			temp1 += '';
			temp1 = temp1.substring(0,1);
			temp2 = 2 * parseInt(a.charAt(i));
			temp2 += '';
			temp2 = temp2.substring(1,2);
			if (temp2 == '')
			{
				temp2 = '0';
			}
 
			suma += (parseInt(temp1) + parseInt(temp2));
		}
		suma += '';
		n = 10 - parseInt(suma.substring(suma.length-1, suma.length));
 
		//comprobacion de NIFs especiales (se calculan como CIFs)
		if (/^[KLM]{1}/.test(temp))
		{
			if (a.charAt(8) == String.fromCharCode(64 + n))
			{
				return 1;
			}
			else
			{
				return -1;
			}
		}
 
		//comprobacion de CIFs
		if (/^[ABCDEFGHJNPQRSUVW]{1}/.test(temp))
		{
			temp = n + '';
			if (a.charAt(8) == String.fromCharCode(64 + n) || a.charAt(8) == parseInt(temp.substring(temp.length-1, temp.length)))
			{
				return 2;
			}
			else
			{
				return -2;
			}
		}
 
		//comprobacion de NIEs
		//T
		if (/^[T]{1}/.test(temp))
		{
			if (a.charAt(8) == /^[T]{1}[A-Z0-9]{8}$/.test(temp))
			{
				return 3;
			}
			else
			{
				return -3;
			}
		}
 
		//XYZ
		if (/^[XYZ]{1}/.test(temp))
		{
			pos = str_replace(['X', 'Y', 'Z'], ['0','1','2'], temp).substring(0, 8) % 23;
			if (a.charAt(8) == cadenadni.substring(pos, pos + 1))
			{
				return 3;
			}
			else
			{
				return -3;
			}
		}
	}
 
	return 0;
}



/**********************************************************************************/