﻿
function ShowEmail(user, domain, anchor) {
	var OutText = '';
	OutText += '<a href="mailto:' + user + '@' + domain + '">';
	if (anchor != '') OutText += anchor;
	else OutText += user + '@' + domain;
	OutText  += '</a>';
	document.write(OutText);
}

var weekday = new Array ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');

function StartIt() {
    // Get local date and time
	var elem = document.getElementById('localdatetime');
	if (elem != null) {
	    var d = new Date();
	    elem.innerHTML = weekday[d.getDay()] + " " + d.toLocaleDateString().substr(0, d.toLocaleDateString().length-4);
	    elem.innerHTML += " <span>|</span> " + d.toLocaleTimeString().substr(0,5);
	}
	
    HighlightMenu();

	ExternalLinks();
}
window.onload = StartIt;

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.target = "_blank"; 
	 } 
} 

function HighlightMenu() {
    var whichLink;
    var current_location = window.parent.location.href;

    if (current_location.indexOf('default')!= -1)
        whichLink="home";
    else if (current_location.indexOf('about')!= -1)
        whichLink="about";   
    else if ((current_location.indexOf('contact')!= -1) && (current_location.indexOf('documents_')== -1))
        whichLink="contact_gi";           
    else if ((current_location.indexOf('global_offices')!= -1) || (current_location.indexOf('office_detail')!= -1))
        whichLink="offices";    
    else if (current_location.indexOf('client_services')!= -1)
        whichLink="services";     
    else if (current_location.indexOf('testimonial')!= -1)
        whichLink="testimonial";    
    else if (current_location.indexOf('case_')!= -1)
        whichLink="casestudies";    
    else if (current_location.indexOf('insights')!= -1)
        whichLink="insight";         
    else if (current_location.indexOf('news')!= -1)
        whichLink="gi_news";                          
    else if (current_location.indexOf('meetings')!= -1)
        whichLink="meeting";    
    else if (current_location.indexOf('business')!= -1)
        whichLink="business";                          
    else if (current_location.indexOf('country')!= -1)
        whichLink="country";                                                
    else if (current_location.indexOf('documents')!= -1)
        whichLink="documents"; 
    else if ((current_location.indexOf('edit_')!= -1) || (current_location.indexOf('email_partners')!= -1) || (current_location.indexOf('admin_settings')!= -1))
        whichLink="edit";  
                          
    if (whichLink != null)      
    {  
        if (document.getElementById(whichLink) != null)
        {                       
            document.getElementById(whichLink).style.backgroundColor = '#123067';   
            document.getElementById(whichLink).style.color = '#479ed5';     
        }
    }
    
    // Change active left menu color
    var splitValue = current_location.split("#");
    
    if (splitValue.length > 1)
    {
        if (document.getElementById(splitValue[1]) != null)
            document.getElementById(splitValue[1]).style.color = '#0061cc';  
    }
    else
    {
        var splitValue2 = current_location.split("id=");
        
        if (splitValue2.length == 1)
        {
            splitValue2 = current_location.split("/");
            splitValue2 = splitValue2[splitValue2.length-1].split(".");
            
            if (document.getElementById(splitValue2[0]) != null)
                document.getElementById(splitValue2[0]).style.color = '#0061cc';    
        }
        else
        {
            if (document.getElementById(splitValue2[1]) != null)
                document.getElementById(splitValue2[1]).style.color = '#0061cc';  
        }
    }
}

var jobTitleArray = new Array ('Chairman','FinanceDirector','MarketingDirector','BusinessDevelopmentDirector');

/* Show and hide director on about_director page */
function ShowHideDirectorDetails(theElement) {
    for (var i=0; i<jobTitleArray.length; i++)
    {
        if (jobTitleArray[i] == theElement)
        {
            if (document.getElementById(jobTitleArray[i]) != null)
                document.getElementById(jobTitleArray[i]).style.display = "";
            
            if (document.getElementById(jobTitleArray[i] + "2") != null)    
                document.getElementById(jobTitleArray[i] + "2").style.display = "";
            
            if (document.getElementById(jobTitleArray[i] + "Btn") != null) {
                if ((jobTitleArray[i] + "Btn") == "ChairmanBtn")
                    document.getElementById(jobTitleArray[i] + "Btn").style.backgroundPosition = 'bottom';
                else
                    document.getElementById(jobTitleArray[i] + "Btn").style.backgroundPosition = '0 -49px';
            }
        }
        else {
            if (document.getElementById(jobTitleArray[i]) != null)
                document.getElementById(jobTitleArray[i]).style.display = "none";
            
            if (document.getElementById(jobTitleArray[i] + "2") != null)                  
                document.getElementById(jobTitleArray[i] + "2").style.display = "none";
            
            
            if (document.getElementById(jobTitleArray[i] + "Btn") != null)
                document.getElementById(jobTitleArray[i] + "Btn").style.backgroundPosition = 'top';
        }
    }
}