// Documento JavaScript
// Esta función cargará los submenus
var numMenus = 8;
var W3CDOM = (document.createElement && document.getElementsByTagName);

function initFileUploads() {
	if (!W3CDOM) return;
	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = 'fakefile';
	fakeFileUpload.appendChild(document.createElement('input'));
	var image = document.createElement('img');
	image.src='images/browser.gif';
	fakeFileUpload.appendChild(image);
	var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++) {
		if (x[i].type != 'file') continue;
		if (x[i].parentNode.className != 'fileinputs') continue;
		x[i].className = 'file hidden';
		var clone = fakeFileUpload.cloneNode(true);
		x[i].parentNode.appendChild(clone);
		x[i].relatedElement = clone.getElementsByTagName('input')[0];
		x[i].onchange = x[i].onmouseout = function () {
			this.relatedElement.value = this.value;
		}
	}
}

function showSubMenu (index){
//alert("llamada a funcion show subMenu " + index);
hideAll();
eval ("document.getElementById('submenu" + index +"').style.visibility = 'visible';");
eval ("document.getElementById('submenu" + index +"').style.position = 'relative';");
//eval ("document.getElementById('submenu" + index +"').style.backgroundColor = '#000000';");
//alert("he mostrado el submenu " + index);

}

function hideAll (){ //funcion para ocultar todos los submenus
  for (i=1; i<= numMenus; i++){
	//alert("oculto el menu " + i);
  hideSubMenu (i);
  }	
}

function hideSubMenu (index){
eval ("document.getElementById('submenu" + index +"').style.visibility = 'hidden';");
eval ("document.getElementById('submenu" + index +"').style.position = 'absolute';");
//alert("he ocultado el submenu " + index);
}

function changeLink (link){
  changeAllLinks();
  link.className='linkActual';
}

function changeLinkById (name){
  var link = document.getElementById(name);
  changeLink(link);
}

function changeAllLinks (){
  //alert("acceso a " + document.getElementById('enlaces').getElementsByTagName('a'));
  var links = document.getElementById('sidebar').getElementsByTagName('a');
  for (i = 0; i< links.length; i++){
  //alert("Link: " + links[i].innerHTML);
  links[i].className = 'link';
  }
  links = document.getElementById('contacto').getElementsByTagName('a');
  for (i = 0; i< links.length; i++){
  //alert("Link: " + links[i].innerHTML);
  links[i].className = 'link';
  }
}

/*function goToAnchor(anchorId){
	//alert("llamada con " + anchorId);
      var anchor_node = document.getElementById(anchorId);
      //alert("anchor node: " + anchor_node);
      window.scrollTo(0, anchor_node.offsetTop);
      return false;
}*/