var siteUrl = "http://"+document.domain+"/";
var origin = "";

if(siteUrl == "http://manhattangroup.asia/" || siteUrl == "http://www.manhattangroup.asia/")
{ origin = "&from=asia";}

if(siteUrl == "http://manhattangroup.com.au/" || siteUrl == "http://www.manhattangroup.com.au/")
{origin = "&from=au";}

if(siteUrl == "http://manhattangroup.eu/" || siteUrl == "http://www.manhattangroup.eu/")
{origin = "&from=eu";}	

if(siteUrl == "http://digital88.com.au/")
{
	var query = window.location.search.substring(1);
	var arr  = query.split("&");
	if(arr[1] == "from=asia")
	{	
		siteUrl = "http://manhattangroup.asia/";
		origin = "&from=asia";
	}
	
	if(arr[1] == "from=au")
	{
		siteUrl = "http://manhattangroup.com.au/";
		origin = "&from=au";
	}
	
	if(arr[1] == "from=eu")
    {
        siteUrl = "http://manhattangroup.eu/";
        origin = "&from=eu";
    }


	/*
	document.write('<script src="'+siteUrl+'jquery.js" type="text/javascript"></script>');
	document.write('<script type="text/javascript">');
	document.write('$(document).ready(function(){');
 	document.write('if($("#menu ul li:first a").attr("href") == "http://manhattangroup.com.au/")');
	document.write('{alert($("#menu ul li:first a").attr("href"));}');
	//document.write('{$("#menu ul li a:first").attr("href", "'+siteUrl+'");}');
	document.write('});');
	document.write('</script>');
	*/
}

var thirdPartyUrl = "http://digital88.com.au/mgo/candidate/";
//var thirdPartyUrl = "http://218.185.14.51/mgo/candidate/";

var opacity = 0.9;
var timerId = 0;
var menus = new Array("services","aboutMgo","researchAndInsight","yourCareer","contactUs");
var subMenu = new Array();
var subHTML = new Array();

//Services
subMenu[0] = new Array("Search & Selection", "Interim Management", "Human Capital Advisory");
subHTML[0] = new Array("services/search_and_selection.html", "services/interim_management.html", "services/human_capital_advisory.html");

//About MGO
subMenu[1] = new Array("Management Team", "Press Releases", "Privacy Statement");
subHTML[1] = new Array("about_mgo/management_team.html", "about_mgo/press_releases.html", "about_mgo/privacy_statement.html");

//Research and Insight
subMenu[2] = new Array("Research Library", "Salary Surveys", "Thought Leadership");
subHTML[2] = new Array("research_and_insight/research_library.html", "research_and_insight/salary_survey.html", "research_and_insight/thought_leadership.html");

//Your Career
subMenu[3] = new Array("Job Alert", "Job Search", "Career Management");
subHTML[3] = new Array("#", "search_job.php?jobsearch=1"+origin,"your_career/career_management.html");

//Contact Us
subMenu[4] = new Array("Melbourne Office", "Singapore Office", "Europe Office");
subHTML[4] = new Array("contact_us/melbourne_office.html", "contact_us/singapore_office.html", "contact_us/europe_office.html");

function whoAreyou(index)
{
	return 1;
}


function getMenu(menuNo)
{
	switch(menuNo)
	{
		case 0:
			showMenu(menuNo);
			
			break;
		case 1:
			showMenu(menuNo);
			break;
		case 2:
			showMenu(menuNo);
			break;
		case 3:
			showMenu(menuNo);
			break;
		case 4:
			showMenu(menuNo);
			break;
		default:
			break;
	}
}

function showMenu(menuNo, who)
{
	builtDivMenu(menuNo);
}

function builtDivMenu(menuNo)
{
	var sMenu = document.getElementById("subMenu");
  var path = thirdPartyUrl;
	
	if(menuNo != "3")
	{
    path = siteUrl;
	}
	else
	{
		path = thirdPartyUrl;
	}
	
	if(sMenu != null)
	{
		var mMenu = document.getElementById("subMenu").parentNode;
		if(timerId != 0)
		{
			clearInterval(timerId);
		}
		mMenu.removeChild(sMenu);
	}
	
	var menu = document.getElementById(menus[menuNo]);
	//var menu = document.getElementById("content");
	var subMenuElement = document.createElement("div");
	var subMenuTbl = document.createElement("table");
	var subMenuTr = document.createElement("tr");
	var subMenuTd = document.createElement("td");
	opacity = "0.9";
	var ul = document.createElement("ul");
	var subMenuArray = subMenu[menuNo];
	var subHTMLArray = subHTML[menuNo];
	for(var i=0; i < subMenuArray.length; ++i)
	{
		var li = document.createElement("li");
		var a = document.createElement("a");
		
		if(subMenuArray[i] != "Career Management")
		{
			a.setAttribute("href", path+subHTMLArray[i]);
		}
		else
		{
		
      path = siteUrl;
			a.setAttribute("href", path+subHTMLArray[i]);
		}
		
		if(subMenuArray[i] == "Job Alert")
		{
			a.setAttribute("href", "#");
			a.onclick = new Function ("popWindow();");
		}
		
		a.innerHTML = subMenuArray[i];
		li.appendChild(a);
		ul.appendChild(li);
	}
	subMenuElement.setAttribute("id", "subMenu");
	subMenuElement.onmouseover = new Function("stay();");
	subMenuElement.onmouseout = new Function("fadeOut();");
	subMenuElement.appendChild(ul);
	subMenuElement.style.top = "46px";
	subMenuElement.style.pixelLeft = menu.offsetLeft;
	menu.appendChild(subMenuElement);
}

function fadeOut()
{
	
	timerId = setInterval("clearOpacity();",80);
	//menuMain.removeChild(subMenu);
}

function stay()
{
	if(timerId != 0)
	{
		clearInterval(timerId);
	}
	var sMenu = document.getElementById("subMenu");
	sMenu.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=90)";
	sMenu.style.opacity = "0.9";
	
}

function clearOpacity()
{		
	var menuMain = document.getElementById("subMenu").parentNode;
	var subMenu = document.getElementById("subMenu");
	if(opacity <= 0)
	{
		if(timerId != 0)
		{
			clearInterval(timerId);	
		}
		menuMain.removeChild(subMenu);
	}
	else
	{
		opacity = opacity - 0.08;
		subMenu.style.opacity = opacity.toString();
		//for IE
		var opacityIE = opacity * 100;
		subMenu.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+opacityIE.toString()+")";
	}
}
	
function performSearch()
	{
	var url = thirdPartyUrl+"search_job.php?jobsearch=1";
  if (document.forms['searchform'].keyword.value != "")
		{
		url = url+"&keyword=" + escape(document.forms['searchform'].keyword.value);
		}
	url = url+"&daterange=" + escape(document.forms['searchform'].daterange.value);
	if ((document.forms['searchform'].industry.value != "") && (document.forms['searchform'].industry.value != "any"))
		{
		url = url+"&industry=" + escape(document.forms['searchform'].industry.value);
		}
	if (document.forms['searchform'].jobtype.value != "")
		{
		url = url+"&jobtype=" + escape(document.forms['searchform'].jobtype.value);
		}
	if (document.forms['searchform'].state.value != "")
		{
		url = url+"&state=" + escape(document.forms['searchform'].state.value);
		}
	if (document.forms['searchform'].region.value != "")
		{
		url = url+"&region=" + escape(document.forms['searchform'].region.value);
		}
	
	url = thirdPartyUrl+"search_job.php?jobsearch=1";
	location.href = url;
	
	}	

