// addLoadEvent from Simon Willison

addLoadEvent(openDescription);
addLoadEvent(openMenu);
addLoadEvent(openMenu2);
addLoadEvent(openMenu3);
addLoadEvent(descriptionCloser);
addLoadEvent(menuCloser);
addLoadEvent(externalLinks);


function addLoadEvent(func) { 
 var oldonload = window.onload;
 if (typeof window.onload != 'function') {
  window.onload = func;
 } else {
  window.onload = function() {
   oldonload();
   func();
  }
 }
}

// 1. creates link to DESCRIPTION showDiv function 

function openDescription() {
     var myLink = document.getElementById('descriptionlink');
	 if(myLink) {
		 myLink.onclick = function() {	 
			showDiv('description_two');
			return false;
		 }
	 }
}

// 2. creates link to MENU showDiv function 

function openMenu() {
     var myLinker = document.getElementById('menuLink');
	 if(myLinker) {
		 myLinker.onclick = function() {	 
			showDiv('section_change');
			return false;
		 }
	 }
}


// 3. closes description box

function descriptionCloser() {
     var myCloser = document.getElementById('dCloser');
	 if(myCloser) {
		 myCloser.onclick = function() {	 
			hideDiv('description_two');
			return false;
		 }
	 }
}

// 4. closes popup menu

function menuCloser() {
     var myCloser = document.getElementById('mCloser');
	 //myCloser.mouseover = function() {
	 //myCloser.style.backgroundColor ='000000';
	// }
	if(myCloser) {
		 myCloser.onclick = function() {	 
			hideDiv('section_change');
			return false;
		 }
	}
}

// 5. Show and hide functions

function doNuhn() {}
function getRefToDiv(divID,oDoc) {
	if( document.getElementById ) { return document.getElementById(divID); }
	if( document.all ) { return document.all[divID]; }
	if( !oDoc ) { oDoc = document; }
	if( document.layers ) {
		if( oDoc.layers[divID] ) {
			return oDoc.layers[divID];
		} else {
			for( var x = 0, y; !y && x < oDoc.layers.length; x++ ) {
				y = getRefToDiv(divID,oDoc.layers[x].document);
			}
			return y;
		}
	}
	return false;
}

function showDiv(divID_as_a_string) {
	var myReference = getRefToDiv(divID_as_a_string);
	if( myReference.style ) { myReference.style.visibility = 'visible'; } else {
		if( myReference.visibility ) { myReference.visibility = 'show'; } else {
			return; } }
}

function hideDiv(divID_as_a_string) {
	var myReference = getRefToDiv(divID_as_a_string);
	if( myReference.style ) { myReference.style.visibility = 'hidden'; } else {		
		if( myReference.visibility ) { myReference.visibility = 'hide'; } else {
			 return; } }
}


//  show / hide DIVS in Servicios section 

function openMenu2() {
     var myLinker = document.getElementById('openCr');
	 if(myLinker) {
		 myLinker.onclick = function() {
			var highlightColor = document.getElementById('openCr');
	        highlightColor.style.color = 'FD6C02';
			var highlightColor = document.getElementById('openId');
	        highlightColor.style.color = 'black';
			var highlightColor = document.getElementById('openTc');
	        highlightColor.style.color = 'black';
			sDiv('creatividad');
			hDiv('ideas');
			hDiv('techno');		
			return false;
		 }
	 }
	 
     myLinker = document.getElementById('openId');
	 if(myLinker) {
		 myLinker.onclick = function() {
			var highlightColor = document.getElementById('openCr');
	        highlightColor.style.color = 'black';
			var highlightColor = document.getElementById('openId');
	        highlightColor.style.color = 'FD6C02';
			var highlightColor = document.getElementById('openTc');
	        highlightColor.style.color = 'black';
			sDiv('ideas');
			hDiv('creatividad');
			hDiv('techno');		
			return false;
		 }
	 }	 
     myLinker = document.getElementById('openTc');
	 if(myLinker) {
		 myLinker.onclick = function() {	 
			sDiv('techno');
			hDiv('creatividad');
			hDiv('ideas');
			var highlightColor = document.getElementById('openCr');
	        highlightColor.style.color = 'black';
			var highlightColor = document.getElementById('openId');
	        highlightColor.style.color = 'black';
			var highlightColor = document.getElementById('openTc');
	        highlightColor.style.color = 'FD6C02';
			return false;
		 }
	 }	 	 
}

function sDiv(dId) {
	var tDiv = document.getElementById(dId);
	if(tDiv) {
		tDiv.style.display = 'block';
	}
}

function hDiv(dId) {
	var tDiv = document.getElementById(dId);
	if(tDiv) {
//		alert('h');		
		tDiv.style.display = 'none';	
	}
}


//  show / hide DIVS in Mujer Salud section 

function openMenu3() {
     var myLinker = document.getElementById('openTerra');
	 if(myLinker) {
		 myLinker.onclick = function() {
			var highlightColor = document.getElementById('openTerra');
	        highlightColor.style.color = 'red';
			var highlightColor = document.getElementById('openHola');
	        highlightColor.style.color = 'FD6C02';
			var highlightColor = document.getElementById('openMHmujer');
	        highlightColor.style.color = 'FD6C02';
			sDiv('terra');
			hDiv('mhmujer');
			hDiv('hola');		
			return false;
		 }
	 }
	 
     myLinker = document.getElementById('openHola');
	 if(myLinker) {
		 myLinker.onclick = function() {
			var highlightColor = document.getElementById('openTerra');
	        highlightColor.style.color = 'FD6C02';
			var highlightColor = document.getElementById('openHola');
	        highlightColor.style.color = 'red';
			var highlightColor = document.getElementById('openMHmujer');
	        highlightColor.style.color = 'FD6C02';
			sDiv('hola');
			hDiv('terra');
			hDiv('mhmujer');		
			return false;
		 }
	 }	 
     myLinker = document.getElementById('openMHmujer');
	 if(myLinker) {
		 myLinker.onclick = function() {	 
			sDiv('mhmujer');
			hDiv('hola');
			hDiv('terra');
			var highlightColor = document.getElementById('openTerra');
	        highlightColor.style.color = 'FD6C02';
			var highlightColor = document.getElementById('openHola');
	        highlightColor.style.color = 'FD6C02';
			var highlightColor = document.getElementById('openMHmujer');
	        highlightColor.style.color = 'red';
			return false;
		 }
	 }	 	 
}

// new window for legal info

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
	   anchor.onclick = function() {
			var owin = window.open(anchor.getAttribute("href"),'cock','width=300, height=200');
			owin.focus();
			return false;
	   }
   }
   
 }
}
