var disappeardelay=150;  
var hidemenuAll_onclick="yes";
var hidemenuWW_onclick="yes";

function showhideAll(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 ='none';
		}

	}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 iecompattestAll(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
};


function dropdownmenuAll(obj, e){
	if (window.event) event.cancelBubble=true;
	else if (e.stopPropagation) e.stopPropagation();
	clearhidemenuAll();
	dropmenuobj=document.getElementById? document.getElementById("gmSitesCont") : gmSitesCont
	showhideAll(dropmenuobj.style, e, "block", "none");
	return clickreturnvalueAll()
};


function clickreturnvalueAll(){
	return false;
};

function contains_ns6All(a, b) {
	while (b.parentNode)
		if ((b = b.parentNode) == a)
		return true;
	return false;
};

function dynamichideAll(e){
	if (e.currentTarget!= e.target)
	delayhidemenuAll()
};

function hidemenuAll(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 hidemenuAll2(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 delayhidemenuAll(){
	delayhide=setTimeout("hidemenuAll()",disappeardelay)
};

function clearhidemenuAll(){
	if (typeof delayhide!="undefined")
	clearTimeout(delayhide)
};

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('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)
	delayhidemenuAll()
};

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(){
	delayhide=setTimeout("hidemenuWW()",disappeardelay);
};

function clearhidemenuWW(){
	if (typeof delayhide!="undefined")
	clearTimeout(delayhide);
};

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 = document.getElementById("contbrands"); //$('contbrands');
	brandNoDisplay.style.display ="none";
	brandNoDisplay.style.visibility ="hidden";
	if(brandNoDisplay.style.display == 'block')
		alert('hum');
            document.getElementById("dragBar1").style.display="none";
            document.getElementById("track1").style.display="none";
            //document.getElementById("wn1").scrollTo(0, 0);
            document.getElementById("dragBar1").style.top = "0px"; 
	//$('dragBar1').style.display="none";
	//$('track1').style.display="none";
	//$('wn1').scrollTo(0, 0);
	//$('dragBar1').style.top = "0px"; 
	if(
	   (navigator.appName!="Microsoft Internet Explorer") && 
	   (navigator.appVersion.indexOf("Macintosh")>-1)
	   )
	{
		countriesNoDisplay = document.getElementById("wn1");
		countriesNoDisplay.style.display="none";
	}else{
		countriesNoDisplay = document.getElementById("wn1");
		countriesNoDisplay.style.display="none";
		if (navigator.appName!="Microsoft Internet Explorer"){
			scrollNoDisplay = document.getElementById("scrollbar1");
			scrollNoDisplay.style.display = "none";
		}else{
			if (navigator.appVersion.indexOf("MSIE 6")>-1){
				document.getElementById("underDiv").style.display='none';
                                document.getElementById("underDiv").style.visibility='hidden';
                                //$('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 = "";
	}
}

