/* CONFIGURATION AREA */
/*
browsers:
IE - Microsoft Internet Explorer
FF - FireFox
Safari - Safari browser
Opera - Opera browser
all - includes IE, FF, Opera and Safari
		
parentId:
any existing Id attribute 
tagName:
any valid tag name
tagPosition:
all - all inner elements 
children - first level children only
className:
any valid class name
*/

var browsers = 'all';
var config = {
	hovers: new Array(
		{
			parentId: 'topmenu',
			tagName: 'li',
			tagPosition: 'all',
			className: 'hover'
		}
	)
};



/* CODE AREA */

/* hovers */

var initHovers = function()
{
	for (var index in config.hovers)
	{
		var conf = config.hovers[index];
		var topLevelElement = document.getElementById(conf.parentId);
		if (topLevelElement)
		{
			var subElements = topLevelElement.getElementsByTagName(conf.tagName);
			for (var i = 0; i < subElements.length; i++)
			{
				if (conf.tagPosition == 'all' || (conf.tagPosition == 'children' && subElements[i].parentNode.id == conf.parentId))
				{
					subElements[i].configIndex = index;
					subElements[i].onmouseover = function()
					{
						this.className += ' ' + config.hovers[this.configIndex].className;
					};
					subElements[i].onmouseout = function()
					{
						this.className = this.className.replace(config.hovers[this.configIndex].className, '');
					};
				}
			}
		}
	}
}

/* common */

var currentState = {};

var opera = window.opera;
var safari = navigator.appVersion.indexOf("Safari") != -1;
var ie = document.all && !window.opera;
var ff = navigator.userAgent.indexOf("Firefox") != -1;

var addEvent = function(browsers, event, initMethod)
{
	if (opera && (browsers.match(/Opera/) || browsers.match(/all/)))
	{
		window.addEventListener(event, initMethod, false);
	} else if (safari && (browsers.match(/Safari/) || browsers.match(/all/)))
	{
		window.addEventListener(event, initMethod, false);
	} else if (ie && (browsers.match(/IE/) || browsers.match(/all/)))
	{
		window.attachEvent("on" + event, initMethod);
	} else if (ff && (browsers.match(/FF/) || browsers.match(/all/)))
	{
		window.addEventListener(event, initMethod, false);
	} else if (!ie && !ff && !safari && !opera)
	{
		if (window.addEventListener)
		{
			window.addEventListener(event, initMethod, false);
		}
		else if (window.attachEvent)
		{
			window.attachEvent("on" + event, initMethod);
		}
	}
}

function goToPage(id)
{
	document.getElementById("htxtPage").value = id;
	if (document.getElementById("htxtPage").value != "")
	{
		if (fnisInteger(document.getElementById("htxtPage").value) == true)
		{
			try
			{
				__doPostBack("lnkPages", "");
			}
			catch (Exception)
				{ }
		}
	}
}

function fnisInteger(s)
{
	var i;
	for (i = 0; i < s.length; i++)
	{
		// Check that current character is number.
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
	}
	// All characters are numbers.
	return true;
}

function goSearch()
{
	var ctlSiteSearch = document.getElementById('txtSearch');
	var url = 'SiteSearch.aspx?txtSearch=' + ctlSiteSearch.value;
	document.location.href = url;
}

function submitPage(e, textbox)
{
	var key_enter = 13; // 13 = Enter
	var evt = (window.event == null) ? e : window.event;
	var code = evt.which ? evt.which : evt.keyCode

	if (key_enter == code)
	{
		location.href = 'SiteSearch.aspx?txtSearch=' + textbox.value;
		return false;
	}
}

function lostfocus(tbSiteSearch)
{
	if (tbSiteSearch.value == '')
		tbSiteSearch.value = '(Site Search)';
}

function getfocus(tbSiteSearch)
{
	if (tbSiteSearch.value == '(Site Search)')
		tbSiteSearch.value = '';
}

function openCentered(url, width, height, windowName, featureString)
{
	if (!windowName)
		windowName = '';
	if (!featureString)
		featureString = '';
	else
		featureString = ',' + featureString;
	var x = Math.round((screen.availWidth - width) / 2);
	var y = Math.round((screen.availHeight - height) / 2);
	featureString = 'left=' + x + ',top=' + y + ',width=' + width
				+ ',height=' + height + featureString;
	winname = open(url, windowName, featureString);

	if (!winname)
	{
		alert("The window could not be opened. Please check if you have a popup blocker installed that may be preventing the window from opening.");
	}
	else
	{
		winname.focus();
	}
}

function OpenWin(Agent, Relogin)
{
	var CompanyId = document.getElementById('txtCompanyID').value;

	if (Relogin)
	{
		eurl = "../Redirect.aspx?CompanyID=" + CompanyId;
	}
	else
	{
		var VacancyId = document.getElementById('txtVacancyID').value
		eurl = "../Redirect.aspx?CompanyID=" + CompanyId + "&VacancyId=" + VacancyId;
	}
	if (Agent)
	{
		eurl += "&Agent=1"
	}
	eurl += "&BusinessUnitID=" + 495
	awindow = openCentered(eurl, 795, 520, 'application', 'toolbar=yes,location=no,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes')
}

function DWMailwindow()
{

	strurl = "Email.aspx?CompanyID=" + document.getElementById("txtCompanyID").value + "&VacancyID=" + document.getElementById("txtVacancyID").value
	OpenWindow(strurl, "email", 'height=350,width=500,toolbar=no,location=no,status=no,scrollbars=yes,resizable=no');
}

function Proceed()
{
	if (document.getElementById("chkPolicy").checked)
		OpenWin(0, 0);
	else
		alert("To continue, please confirm that you have read the Privacy Policy");
}

function searchJobs(controlID)
{
	var division = document.getElementById(controlID + "_ddlDivision").value;
	var country = document.getElementById(controlID + "_ddlCountry").value;
	var url = "DPWVacancySearch.aspx?DivisionID=" + division + "&CountryID=" + country;
	window.location.href = url;
}

var i = 0;
var banner = "visual$"
var previousbanner;
function Timer()
{
	if (previousbanner)
		previousbanner.style.display = 'none';

	var objbanner;
	if (i <= 2)
	{
		i++;
	}
	else
	{
		i = 1;
	}
	objbanner = document.getElementById(banner.replace("$", i));
	$(objbanner).fadeIn(2000);
	previousbanner = objbanner;
	window.setTimeout("Timer()", 10000)
}

addEvent(browsers, 'load', initHovers);
