var disappeardelay=150;  
var hidemenuAllGM_onclick="yes";
var hidemenuWW_onclick="yes";

function showhideAllGM(obj, e, visible, hidden){
	if (e.type=="click" && obj.display==hidden || e.type=="mouseover"){
		obj.display=visible;
		if ((navigator.appName=="Microsoft Internet Explorer")&&
			(navigator.appVersion.indexOf("MSIE 6")>-1)){
			document.getElementById('gAllGMSitesIFrame').style.display ='block';
		}

	}else{
		if (e.type=="click"){
			obj.display=hidden;
			if ((navigator.appName=="Microsoft Internet Explorer")&&
				(navigator.appVersion.indexOf("MSIE 6")>-1)){
				document.getElementById('gAllGMSitesIFrame').style.display ='none';
			}
		}
	}
};


function iecompattestAllGM(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
};


function dropdownmenuAllGM(obj, e){
	if (window.event) event.cancelBubble=true;
	else if (e.stopPropagation) e.stopPropagation();
	clearhidemenuAllGM();
	dropmenuobj=document.getElementById? document.getElementById("gmSitesCont") : gmSitesCont
	showhideAllGM(dropmenuobj.style, e, "block", "none");
	return clickreturnvalueAllGM()
};


function clickreturnvalueAllGM(){
	return false;
};

function contains_ns6AllGM(a, b) {
	while (b.parentNode)
		if ((b = b.parentNode) == a)
		return true;
	return false;
};

function dynamichideAllGM(e){
	if (e.currentTarget!= e.target)
	delayhidemenuAllGM()
};

function hidemenuAllGM(e){
	if (typeof dropmenuobj!="undefined"){
		if ((navigator.appName=="Microsoft Internet Explorer")&&
			(navigator.appVersion.indexOf("MSIE 6")>-1)){
			document.getElementById('gAllGMSitesIFrame').style.display ='none';
		}
		dropmenuobj.style.display="none";
	}
};


function hidemenuAllGM2(e){
	if ( (typeof dropmenuobj!="undefined") && (dropmenuobj.id == "gmSitesCont")){
		dropmenuobj.style.display="none";
		if (navigator.appName=="Microsoft Internet Explorer"){
				if(navigator.appVersion.indexOf("MSIE 6")>-1){
					document.getElementById('gAllGMSitesIFrame').style.display ='none';
				}
		}
	}
};

function delayhidemenuAllGM(){
	delayhideAllGM=setTimeout("hidemenuAllGM()",disappeardelay)
};

function clearhidemenuAllGM(){
	if (typeof delayhideAllGM!="undefined")
	clearTimeout(delayhideAllGM)
};

function showhideWW(obj, e, visible, hidden){
	cleanMenus();
	initializeDrag();
	if (e.type=="click" && obj.display==hidden || e.type=="mouseover"){
		obj.display=visible
		if (navigator.appName=="Microsoft Internet Explorer"){
				if(navigator.appVersion.indexOf("MSIE 6")>-1){
					document.getElementById('gAllGMSitesIFrame').style.display ='block';
					//document.getElementById('gGMWorldWideIFrame').style.display ='block';
				}
		}
	}else{ 
			if (e.type=="click"){
				obj.display=hidden;
				if (navigator.appName=="Microsoft Internet Explorer"){
					if(navigator.appVersion.indexOf("MSIE 6")>-1){
						document.getElementById('gGMWorldWideIFrame').style.display ='none';
					}
				}
			}
	}
};

function iecompattestWW(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
};


function dropdownmenuWW(obj, e){
	cleanMenus();
	initializeDrag();
	if (window.event) event.cancelBubble=true
	else if (e.stopPropagation) e.stopPropagation()
	clearhidemenuWW()
	dropmenuobj=document.getElementById? document.getElementById("cont") : cont
	showhideWW(dropmenuobj.style, e, "block", "none")
	return clickreturnvalueWW()
};

function clickreturnvalueWW(){
	return false;
};

function contains_ns6WW(a, b) {
	while (b.parentNode)
		if ((b = b.parentNode) == a)
		return true;
	return false;
};

function dynamichideWW(e){
	if (e.currentTarget!= e.target)
	delayhidemenuAllGM()
};

function hidemenuWW(e){

	if ( (typeof dropmenuobj!="undefined")){
		dropmenuobj.style.display="none";
		if (navigator.appName=="Microsoft Internet Explorer"){
				if(navigator.appVersion.indexOf("MSIE 6")>-1){
					document.getElementById('gGMWorldWideIFrame').style.display ='none';
				}
		}
	}
};

function hidemenuWW2(e){
	if ( (typeof dropmenuobj!="undefined") && (dropmenuobj.id == "cont")){
		dropmenuobj.style.display="none";
		if (navigator.appName=="Microsoft Internet Explorer"){
				if(navigator.appVersion.indexOf("MSIE 6")>-1){
					document.getElementById('gGMWorldWideIFrame').style.display ='none';
				}
		}
	}
};


function delayhidemenuWW(){
	delayhideWW=setTimeout("hidemenuWW()",disappeardelay);
};

function clearhidemenuWW(){
	if (typeof delayhideWW!="undefined")
	clearTimeout(delayhideWW);
};

function createContinentsMenu()
{
	removeAllChilds("contnames");
	removeAllChilds("countries");
	removeAllChilds("brands");
	cleanMenus();
	for (var continent in worldwide){
		if(continent=="america"){
			for(var americaPart in worldwide[continent]){
				if(americaPart!="name"){
					createNode(americaPart, worldwide[continent][americaPart].name.value, "contnames", '');
					var element = document.getElementById(americaPart);
					var parent = element.parentNode;
					element.onclick = function(e){
										if(!e)e=window.event;
										if(!e.target)e.target=e.srcElement;
										var selectedContinent;
										selectedContinent=e.target.innerHTML;
										createCountriesMenu(e.target.id); 
										initializeDrag();
									   }	
					element.onmouseover = function(){
							this.className = "pHover";
						}	
					element.onmouseout = function(){
							this.className = "";
						}		
				}
			}
		}else{
			createNode(continent, worldwide[continent].name.value, "contnames", '');
			var element = document.getElementById(continent);
			var parent = element.parentNode;
			element.onclick = function(e){
								if(!e)e=window.event;
								if(!e.target)e.target=e.srcElement;
								var selectedContinent;
								selectedContinent=e.target.innerHTML;
								createCountriesMenu(e.target.id);
                                initializeDrag();
							   }
			element.onmouseover = function(){
									this.className = "pHover";
								}	
			element.onmouseout = function(){
									this.className = "";
								}				   
		}
	}
};

function createCountriesMenu(continent)
{
	cleanMenus();
	if((continent == "north_america") || (continent == "south_america") ){
		for(var countryCode in worldwide["america"][continent]){
			if(countryCode!= "name"){
				createNode(countryCode, worldwide["america"][continent][countryCode].name.value, "countries", '');
				var element = document.getElementById(countryCode);
				element.onclick = function(e){
										if(!e)e=window.event;
										if(!e.target)e.target=e.srcElement;
										var selectedCountry;
										selectedCountry=e.target.innerHTML;
										createBrandsMenu(e.target.id, continent);
									   }
				if ((navigator.appName=="Microsoft Internet Explorer") && (navigator.appVersion.indexOf("MSIE 6")>-1)){
					element.onmouseover = function(){
									this.className = "pHover1";
								}	
					element.onmouseout = function(){
									this.className = "";
								}
				}
			}

		}
	}else{
		for(var countryCode in worldwide[continent]){
			if(countryCode!= "name"){
				createNode(countryCode, worldwide[continent][countryCode].name.value, "countries", '');
				var element = document.getElementById(countryCode);
				element.onclick = function(e){
									if(!e)e=window.event;
									if(!e.target)e.target=e.srcElement;
									var selectedCountry;
									selectedCountry=e.target.innerHTML;
									createBrandsMenu(e.target.id, continent);
   								   }
				if ((navigator.appName=="Microsoft Internet Explorer") && (navigator.appVersion.indexOf("MSIE 6")>-1)){
					element.onmouseover = function(){
									this.className = "pHover1";
								}	
					element.onmouseout = function(){
									this.className = "";
								}				
				}
			}
		}
	}
	var lenghtCont =$('track1').offsetHeight;
	var scrollNoDisplay;
	var countriesNoDisplay;
	if(
	   (navigator.appName!="Microsoft Internet Explorer") && 
	   (navigator.appVersion.indexOf("Macintosh")>-1)
	   )
	{
		countriesNoDisplay = $('wn1');
		countriesNoDisplay.style.display="block";
		$('dragBar1').style.display="block";
		$('track1').style.display="block";
		$('dragBar1').style.visibility="visible";
		$('track1').style.visibility="visible";
	}else{
		countriesNoDisplay = $('wn1');
		countriesNoDisplay.style.display="block";
		if (navigator.appName!="Microsoft Internet Explorer"){
				scrollNoDisplay = $('scrollbar1');
				scrollNoDisplay.style.display = "block";
				$('dragBar1').style.display="block";
				$('track1').style.display="block";
				$('dragBar1').style.visibility="visible";
				$('track1').style.visibility="visible";
				$('dragBar1').style.top = "0px";
		}else{
			if (navigator.appVersion.indexOf("MSIE 6")>-1){
				$('underDiv').style.display='block';
				$('underDiv').style.visibility='visible';
			}
			$('dragBar1').style.top = "0px"; 
			$('dragBar1').style.display="block";
			$('track1').style.display="block";
		}
	}
};

function createBrandsMenu(country, continent){
	removeAllChilds("brands");
	$('contbrands').style.display ="block";
	$('contbrands').style.visibility ="visible";
	if((continent == "north_america") || (continent == "south_america") ){
			for(var counter =0 ; counter < worldwide["america"][continent][country].sites.length; counter++){
				createNode(counter, worldwide["america"][continent][country].sites[counter].display , "brands", worldwide["america"][continent][country].sites[counter].url, country);
				var element = document.getElementById(counter);
				element.onclick=function(e){
					clickTrack({s_linkName:'GM | HOMEPAGE | TNAV | GM WORLDWIDE | ' + this.className.toUpperCase(), s_prop1:'GENERAL', s_prop2:'HOMEPAGE', s_prop3:'GENERAL | HOMEPAGE', s_prop5:'GM | HOMEPAGE | TNAV | GM WORLDWIDE | ' + this.className.toUpperCase()});
				  window.open(this.href, this.target); 
				  hidemenuWW(e);
				  return false;
				}
			}		
	}else{
			for(var counter =0 ; counter < worldwide[continent][country].sites.length; counter++){
				createNode(counter, worldwide[continent][country].sites[counter].display , "brands", worldwide[continent][country].sites[counter].url, country );
				var element = document.getElementById(counter);
				element.onclick=function(e){
					clickTrack({s_linkName:'GM | HOMEPAGE | TNAV | GM WORLDWIDE | ' + this.className.toUpperCase(), s_prop1:'GENERAL', s_prop2:'HOMEPAGE', s_prop3:'GENERAL | HOMEPAGE', s_prop5:'GM | HOMEPAGE | TNAV | GM WORLDWIDE | ' + this.className.toUpperCase()});
					window.open(this.href, this.target); 
					hidemenuWW(e);
					return false;
				}
			}
	}
};

function createNode(elementId, extension, containerId, url, country){

		var node = document.createElement("p");
		var linkItem = document.createElement("a");
		linkItem.id = elementId;
		if(url != ''){
			linkItem.setAttribute('href', url);
			linkItem.setAttribute('target', '_blank');
			linkItem.className = country;
		}
		var textNode = document.createTextNode(extension);
		linkItem.appendChild(textNode);
		node.appendChild(linkItem);
		var container = document.getElementById(containerId);
		container.appendChild(node);
};


function cleanMenus(){
	var brandNoDisplay ;
	var countriesNoDisplay;
	var scrollNoDisplay;
	brandNoDisplay = $('contbrands');
	if( typeof( brandNoDisplay.style ) != "undefined" ){
		brandNoDisplay.style.display ="none";
		brandNoDisplay.style.visibility ="hidden";
		if(brandNoDisplay.style.display == 'block')
			alert('hum');
	}
	if( typeof( $('dragBar1').style ) != "undefined" ){
		$('dragBar1').style.display="none";
		$('dragBar1').style.top = "0px"; 
	}
	if( typeof( $('track1').style ) != "undefined" )
		$('track1').style.display="none";
	if( typeof( $('wn1').style ) != "undefined" )
		$('wn1').scrollTo(0, 0);
	if(
		(navigator.appName!="Microsoft Internet Explorer") && 
		(navigator.appVersion.indexOf("Macintosh")>-1)
	){
		countriesNoDisplay = $('wn1');
		if( typeof( countriesNoDisplay.style ) != "undefined" )
			countriesNoDisplay.style.display="none";
	}else{
		countriesNoDisplay = $('wn1');
		if( typeof( countriesNoDisplay.style ) != "undefined" )
			countriesNoDisplay.style.display="none";
		if (navigator.appName!="Microsoft Internet Explorer"){
			scrollNoDisplay = $('scrollbar1');
			if( typeof( scrollNoDisplay.style ) != "undefined" )
				scrollNoDisplay.style.display = "none";
		}else{
			if (navigator.appVersion.indexOf("MSIE 6")>-1){
				$('underDiv').style.display='none';
				$('underDiv').style.visibility='hidden';
			}
		}
	}
	removeAllChilds("countries");
	removeAllChilds("brands");
};


function removeAllChilds(element)
{
    var node = document.getElementById(element);
	if ( node.hasChildNodes() )
	{
    	while ( node.childNodes.length >= 1 )
    	{
       		node.removeChild( node.firstChild );       
    	} 
	}	
};

function toggleUnderline(objref, opcion){
	if (opcion == 1) {	
		objref.className = "textUnderline";
	} else {
		objref.className = "";
	}
}

//AttachEvent(window, "load", createContinentsMenu);
