// JavaScript Document

function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' debe contener una direccion de email valida.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' debe contener un numero de telefono valido.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' esta vacio o no es valido.\n'; }
    } if (errors) alert('Debe rellenar los siguientes campos:\n'+errors);
    document.MM_returnValue = (errors == '');
} }

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}





/*menu deplegable*/
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"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


function categorias2(){
	
	
	var capa = document.getElementById("categorias3").appendChild(subcat);

	if (capa.style.display == "none") {
	 capa.style.display = "block"; 
	} else {
	 capa.style.display = "none"; 
	}
}




/****************************************************************************
Menú desplegable accesible. 05-10-06
Autor: tunait http://javascript.tunait.com/ tunait@yahoo.com
Script de libre uso mientras se mantengan los créditos de autor intactos.
No permitida su re-distribución.
*****************************************************************************/
var retardoEnCerrar = 5000
var menuActivo = false
var zindex = 1000
var tiempoCierre
function nodoHijo(obj){
	if(obj.hasChildNodes){
		for(m=0; m<obj.childNodes.length; m++){
			if(obj.childNodes[m].nodeType == 1 && obj.childNodes[m].tagName.toLowerCase() == 'ul') {
				return obj.childNodes[m]
				break
			}
		}
	}
}
function recorre(elems, obj){
	for(s=0; s<elems-1; s++){
		if(obj.childNodes[s].nodeType == 1 && obj.childNodes[s].tagName.toLowerCase() == 'li'){
			alert(obj.childNodes[s].tagName + ": " + obj.childNodes[s].childNodes.length)
		}
	}
}
	H = document.documentElement.childNodes[0]
	tagLink = document.createElement('link')
	tagLink.type = "text/css"
	tagLink.rel = "stylesheet"
	tagLink.href = "css/estilo.css"
	H.appendChild(tagLink)
function iniciaMenu(){
	for(s in document.getElementsByTagName('link')){
		hoja = document.getElementsByTagName('link')[s]
		if(hoja.title == 'estilosMenusinjs') hoja.disabled = true
		if(hoja.title == 'estilosMenujs') hoja.disabled = false

	}
	/*if(document.styleSheets && document.styleSheets.length > 0){*/
	for(s in document.styleSheets){
		hoja = document.styleSheets[s]
		if(hoja.title == 'estilosMenusinjs') hoja.disabled = true
		if(hoja.title == 'estilosMenujs') hoja.disabled = false
	}
	Menu = document.getElementById('menu')
	as = document.getElementById('menu').getElementsByTagName('a')
	for(var m in as){
		as[m].className = 'menuSecundario'
	}
	li = document.getElementById('menu').getElementsByTagName('li')
	for(m in li){
		if(li[m].parentNode == Menu){
			li[m].firstChild.className = 'menuSecundario'
			li[m].style.cssFloat  = 'left'
			li[m].style.styleFloat  = 'left'
			}
	}
	uls = document.getElementById('menu').getElementsByTagName('ul').length
	for(m=0; m < uls ; m++){
		ul = document.getElementById('menu').getElementsByTagName('ul')[m]
		if(ul.parentNode.parentNode == Menu){
			ul.parentNode.style.cssFloat  = 'left'
			ul.parentNode.style.styleFloat  = 'left'
			ul.parentNode.firstChild.className = 'menuPrincipal'
			ul.parentNode.firstChild.style.cursor = 'pointer'
			if(ul.parentNode.firstChild.nodeName.toLowerCase() != 'a'){
				txt = ul.parentNode.firstChild.firstChild.nodeValue
				lin = document.createElement('a')
				lin.href = '#menu'
				lin.className = 'menuPrincipal'
				lin.title ="Haga click para abrir más opciones";
				lin.appendChild(document.createTextNode(txt))
				ul.parentNode.replaceChild(lin,ul.parentNode.firstChild)
			}
		}
		else{
			if(ul.parentNode.firstChild.nodeName.toLowerCase() != 'a'){
				txt = ul.parentNode.firstChild.firstChild.nodeValue
				lin = document.createElement('a')
				lin.href = '#menu'
				lin.className = 'menuSecundario'
				lin.title ="Haga click para abrir más opciones";
				lin.appendChild(document.createTextNode(txt))
				ul.parentNode.replaceChild(lin,ul.parentNode.firstChild)
			}
		}
		ul.style.visibility = 'hidden'
		ul.style.position = 'absolute'
		ul.className = 'cajaMenuDesp'
		ul.parentNode.firstChild.style.display = 'block'
		ul.parentNode.style.zIndex = zindex--
		ul.parentNode.firstChild.title ="Haga click para abrir más opciones"
		ul.parentNode.firstChild.setAttribute('visible','off') //atributo en A
		if(ul.offsetParent && ul.parentNode.parentNode != Menu){
			posIzq = 0
			derecha = 0
			ul2 = ul
			while(ul2 = ul2.offsetParent){
				posIzq += ul2.offsetLeft
			}
			anchoDoc = document.body.offsetWidth
			derecha = anchoDoc - (posIzq + ul.offsetWidth)
			if(derecha < 0) ul.style.marginLeft = derecha + "px"
		}
		ul.parentNode.firstChild.onclick = function(){ //click en el A
			hijo = nodoHijo(this.parentNode) //devuelve el UL del LI
			if(this.parentNode.parentNode == Menu){
				actMenus(this, hijo)
			}
			else{
				actSubMenus(this, hijo)
			}
			return false
		}
	}
		Menu.onmouseover = function(){
			menuActivo = true
		}
		Menu.onmouseout = function(){
			menuActivo = false
			clearTimeout(tiempoCierre)
			tiempoCierre = setTimeout('cierraMenu()',retardoEnCerrar)
		}

	/*}*/
}
function actMenus(obj,hijo){
	var uls = document.getElementById('menu').getElementsByTagName('ul').length
	for(var m=0; m < uls ; m++){
		var ul = document.getElementById('menu').getElementsByTagName('ul')[m]
		ul.style.visibility = 'hidden'
		ul.parentNode.firstChild.className = 'menuPrincipal'
		ul.parentNode.firstChild.title="Haga click para mostrar más opciones"
		if(ul.parentNode.firstChild == obj) continue
		ul.parentNode.firstChild.setAttribute('visible','off')
	}
	if(obj.getAttribute('visible') == 'off'){
				hijo.style.visibility = 'visible'
				obj.setAttribute('visible','on')
				obj.className = 'menuSeleccionado'
				obj.title = "Haga click para ocultar las opciones"
			}
	else{
		hijo.style.visibility = 'hidden'
		obj.setAttribute('visible','off')
		obj.className = 'menuPrincipal'
		obj.title = "Haga click para mostrar más opciones"
	}
	obj.focus()
}


function actSubMenus(obj, hijo){
	ulspadre = obj.parentNode.parentNode
	var uls = ulspadre.getElementsByTagName('ul').length
	for(var m=0; m < uls ; m++){
		var ul = ulspadre.getElementsByTagName('ul')[m]
		ul.style.visibility = 'hidden'
		ul.parentNode.firstChild.className = 'menuPrincipal'
		ul.parentNode.firstChild.title="Haga click para mostrar más opciones"
		if(ul.parentNode.firstChild == obj) continue
		ul.parentNode.firstChild.setAttribute('visible','off')
	}
	if(obj.getAttribute('visible') == 'off'){
				hijo.style.visibility = 'visible'
				obj.setAttribute('visible','on')
				obj.className = 'menuSeleccionado'
				obj.title = "Haga click para ocultar las opciones"
			}
	else{
		hijo.style.visibility = 'hidden'
		obj.setAttribute('visible','off')
		obj.className = 'menuPrincipal'
		obj.title = "Haga click para mostrar más opciones"
	}
	obj.focus()
}
function cierraMenu(){
	if(!menuActivo){
		var uls = document.getElementById('menu').getElementsByTagName('ul').length
		for(var m=0; m < uls ; m++){
			var ul = document.getElementById('menu').getElementsByTagName('ul')[m]
			ul.style.visibility = 'hidden'
			ul.parentNode.firstChild.className = 'menuPrincipal'
			ul.parentNode.firstChild.title="Haga click para mostrar más opciones"
			ul.parentNode.firstChild.setAttribute('visible','off')
		}
	}
}
