var tabControl=0; 
function parentForm(control){
  padre=control;
  while(padre.nodeName!="FORM"){
   padre=padre.parentNode;
  }
  return padre;
 }

function validText(filtro,control){
  filtros=new Array();
  cont=-1;
  while(filtro.indexOf("|")!=-1)
  {
   cont++;
   filtros[cont]=filtro.substring(0,filtro.indexOf("|"));
   filtro=filtro.substring(filtro.indexOf("|")+1,filtro.length);
  }
  filtros[cont+1]=filtro;
  for(f=0;f<filtros.length;f++){
   switch(filtros[f]){
    case "nodata":
     if(control.value==""){
      control.parentNode.getElementsByTagName("B")[0].innerHTML="&nbsp;&nbsp;El campo debe tener un valor";
      tabControl++;
      return false;
     }
    break;
    case "numerico":
     var filter=new RegExp("^(?:\\+|-)?\\d+\(.\\d*$)?");
     if(!filter.test(control.value))
     {
      control.parentNode.getElementsByTagName("B")[0].innerHTML="&nbsp;&nbsp;El campo debe ser numerico";
      tabControl++;
      return false;
     }
    break;
    case "entero":
     var filter=new RegExp("^(?:\\+|-)?\\d+$");
     if(!filter.test(control.value))
     {
      control.parentNode.getElementsByTagName("B")[0].innerHTML="&nbsp;&nbsp;El campo debe ser entero";
      tabControl++;
      return false;
     }
    break;
    case "email":
     var filter=/^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
     if(!filter.test(control.value))
     {
      control.parentNode.getElementsByTagName("B")[0].innerHTML="&nbsp;&nbsp;Email invalido";
      tabControl++;
      return false;
     }
    break;
    case "cadena":
    break;
   }
  }
  control.parentNode.getElementsByTagName("B")[0].innerHTML="";
  return true;
 }
function validar(obj){
 formulario=parentForm(obj);
 inputs=formulario.getElementsByTagName("INPUT");
 validos=true;
 for(i=0;i<inputs.length;i++){
  if(inputs[i].getAttribute("type")=="text"){
   if(inputs[i].getAttribute("filter")){ 
    bold=document.createElement("B");
    bold.setAttribute("style","color:red;font-size:11px;");
    div=document.createElement("div");
    div.setAttribute("align","center");
    div.setAttribute("style","width:auto;height:auto;float:left;");
    div.appendChild(bold);
    inputs[i].parentNode.appendChild(div);
    validos=validText(inputs[i].getAttribute("filter"),inputs[i]);
    if(validos==false)
    {
     if(tabControl==0){
      inputs[i].focus();
     }  // fin si
    } // Fin si
   }
  }
 } 
 if(validos==true){
  formulario.submit();
 }
}
window.onload=function(){
 titulo="Fundación del Río";
 h1=document.getElementById("centro").getElementsByTagName("H1");
 for(h=0;h<h1.length;h++)
 {
  if(h1[h].parentNode.className=="noticia")
   titulo+=" / "+h1[h].innerHTML;
 }
 document.title=titulo;
 var principales=document.getElementsByName("menue");
 for(m=0;m<principales.length;m++)
 {
  principales[m].onmouseover=function(){
  if(!document.getElementById("m"+this.getAttribute("id")))
  {
   id=this.getAttribute("id");
   var xml = $.ajax({
     type: "POST",
     url: "/submenu.php",
     dataType: "xml",
     data: "idmenu="+id,
     async: false
   }).responseXML;
   items=xml.getElementsByTagName("ITEM");
   div=document.createElement("DIV");
   div.setAttribute("style","z-index:1;clip: rect( );visibility:hidden;");
   div.style.position="absolute";
   menu=document.createElement("UL");
   menu.setAttribute("style","list-style-type:none;width:141px;font-size:12px;background-color:#558756;text-align:left;padding-left:10px;");
   div.setAttribute("id","m"+this.getAttribute("id"));
   for(i=0;i<items.length;i++)
   {
    item=document.createElement("LI");
    link=document.createElement("A");
    if(items[i].getAttribute("url") && items[i].getAttribute("url")!="")
    {
     link.setAttribute("href",items[i].getAttribute("url"));
    }
    else
    {
     link.setAttribute("href","#");
    }
    nodo=document.createTextNode(items[i].firstChild.data);
    link.setAttribute("style","color:white;");
    link.appendChild(nodo);
    item.appendChild(link);
    menu.appendChild(item);
   }
   div.appendChild(menu);
   this.appendChild(div);
   menu.style.left=$("#"+this.getAttribute("id")).position().left+"px";
   menu.style.top=($("#"+this.getAttribute("id")).position().top+$("#"+this.getAttribute("id")).height())+"px";
   div.onmouseover=function(){
    this.style.visibility="visible";
   };
   div.onmouseout=function(){
    this.style.visibility="hidden";
   };
  }
  document.getElementById("m"+this.getAttribute("id")).style.visibility="visible";
  };
  principales[m].onmouseout=function(){
   if(document.getElementById("m"+this.getAttribute("id"))){
    //this.removeChild(document.getElementById("m"+id));
    document.getElementById("m"+this.getAttribute("id")).style.visibility="hidden";
   }  
  };
 }
}

