var objEseminarWindow;

function getLanguagePhrase(strLanguagePhase){
	if (eval("typeof " + strLanguagePhase)!="undefined"){
		var strText = eval(strLanguagePhase);
		return strText;
	}else{
		return "";
	}
}

function popWindow(url) {
	//SetCookie('disclaimer', 'yes');
	objEseminarWindow = window.open(url,'ESeminar','resizable=1;location=0,status=0,scrollbars=1,toolbar=1,width=800,height=600');
	if(!objEseminarWindow)
	{
		myAshurst_Popup(getLanguagePhrase("strPopupBlockerTitle"),getLanguagePhrase("strPopupBlockerMessage"),getLanguagePhrase("strInterfaceOK"),"","");
		return;
	}else{
		try{
			AnalyticsTrack("/Events/ViewEseminar");	
		}
		catch(er){
			// tracking failed
		}
	}
}

function myAshurst_OpenLocationLink(strOffice)
{
    // The general office landing page...
    var strContentId = 14;

    // Otherwise goto specific office if known
    switch(strOffice.toLowerCase())
    {
    case "new york":
      strContentId = 114;
      break;
    case "washington dc":
      strContentId = 4302;
      break;
    case "brussels":
      strContentId = 19;
      break;
    case "frankfurt":
      strContentId = 112;
      break;
    case "london":
      strContentId = 20;
      break;
    case "madrid":
      strContentId = 21;
      break;
    case "milan":
      strContentId = 92;
      break;
    case "munich":
      strContentId = 91;
      break;
    case "paris":
      strContentId = 1377;
      break;
    case "stockholm":
      strContentId = 2643;
      break;
    case "abu dhabi":
      strContentId = 3797;
      break;
    case "dubai":
      strContentId = 1942;
      break;
    case "hong kong":
      strContentId = 4035;
      break;
    case "singapore":
      strContentId = 116;
      break;
    case "tokyo":
      strContentId = 117;
      break;                         
    }
    var strmyAshurstUrl = "http://www.ashurst.com/page.aspx?id_Content=" + strContentId;
    window.open(strmyAshurstUrl,"_blank");
}

function myAshurst_Popup(strTitle,strMessage,strCancel,strOK,strOKFunction)
{
	// clear all elements from popup table
	// heading element
	var lobjHead = Object();
	lobjHead = document.getElementById('bkHead');
	lobjHead.innerHTML = strTitle;
	// mid text element
	var lobjTest = Object();
	lobjTest = document.getElementById('bktext');
	lobjTest.innerHTML = strMessage;
	var lobjCancel = Object();
	lobjCancel = document.getElementById('butCancel');
	if (strCancel.length!=0){
		//cancel button
		lobjCancel.value = strCancel;
		lobjCancel.style.display = "block";
	}else{
		// Hide cancel button	
		lobjCancel.style.display = "none";
	}
	// submit button
	var lobjSubmit = Object();
	lobjSubmit = document.getElementById('butSubmit');
	if (strOK.length!=0){
		lobjSubmit.value = strOK;
		lobjSubmit.style.display = "block";
	}else{
		// Hide cancel button	
		lobjSubmit.style.display = "none";
	}
	lobjSubmit.onclick = new Function(strOKFunction);
	
	    raisePopup();
}

function myAshurst_logOff(strLogOffLocation)
{
	myAshurst_clearPopupTable();

	// Show popup
	myAshurst_Popup(getLanguagePhrase("strLogoffTitle"),getLanguagePhrase("strLogoffMessage"),getLanguagePhrase("strInterfaceCancel"),getLanguagePhrase("strInterfaceConfirm"),"window.location='" + strLogOffLocation +"'");
}

function myAshurst_clearPopupTable()
{
	var lobjbkCnf	= new Object();
	lobjbkCnf = document.getElementById("bkCnf");
	var	table =	 document.getElementById("bookingsRec");
	if	(table.rows.length > 0)	
	{
		for (var i=table.rows.length; i>0; i--) {
			if (table.rows[i]!=null)
			{
				table.deleteRow(i); // delete table rows
			}
		}
	}
}

// ############ MODAL POPUP FUNCTIONS #########

var _rulesAdded = false;
var _hideType = "iframe" //iframe,replace

function addDynamicContent()
{
    var objContent = getObj('WebPartWPQ1')
    getObj('modalWindow').innerHTML = objContent.innerHTML;
}
function getObj(id)
{
	return document.getElementById(id);
}

function setCollabIframeDisplay(strDisplayMode)
{
	var iFrames = document.getElementsByTagName("iframe");

	for (i=0;i<iFrames.length;i++)
	{
		var iFrame = iFrames[i]
		if (iFrame.src.toLowerCase().indexOf("extranet.")>=0)
		{
			iFrame.style.display = strDisplayMode;
			break;
		}
	} 
}

function raisePopup()
{
	// Bug: in the Projects area hummingbird iframe appears above popup, so we hide it.
	setCollabIframeDisplay('none');

    // Display the popup
	getObj('modalWindow').style.display = getObj('modalBackground').style.display = 'block';
 
	// special < IE7 -only processing for windowed elements, like select	
	if (window.XMLHttpRequest == null)
	{
		var type = _hideType;
		
		if (type == 'iframe')
			getObj('modalIframe').style.display = 'block';
		if (type == 'replace')
			ReplaceSelectsWithSpans();
	}
 
	// call once to center everything
	OnWindowResize();
	
	if (window.attachEvent)
		window.attachEvent('onresize', OnWindowResize);
	else if (window.addEventListener)
		window.addEventListener('resize', OnWindowResize, false);
	else
		window.onresize = OnWindowResize;
	
	// we won't bother with using javascript in CSS to take care
	//   keeping the window centered
	if (document.all)
		document.documentElement.onscroll = OnWindowResize;
}
 
function OnWindowResize()
{
	// we only need to move the dialog based on scroll position if
	//   we're using a browser that doesn't support position: fixed, like < IE 7
	var left = window.XMLHttpRequest == null ? document.documentElement.scrollLeft : 0;
	var top = window.XMLHttpRequest == null ? document.documentElement.scrollTop : 0;
	var div = getObj('modalWindow');
	
	div.style.left = Math.max((left + (GetWindowWidth() - div.offsetWidth) / 2), 0) + 'px';
	div.style.top = Math.max((top + (GetWindowHeight() - div.offsetHeight) / 2), 0) + 'px';
}
 
function hidePopup()
{
	getObj('modalWindow').style.display = getObj('modalBackground').style.display = 'none';
	
	// special IE-only processing for windowed elements, like select	
	if (document.all)
	{
		var type = _hideType;
		
		if (type == 'iframe')
			getObj('modalIframe').style.display = 'none';
		if (type == 'replace')
			RemoveSelectSpans();
	}
	
	setCollabIframeDisplay('block');	
	
	if (window.detachEvent)
		window.detachEvent('onresize', OnWindowResize);
	else if (window.removeEventListener)
		window.removeEventListener('resize', OnWindowResize, false);
	else
		window.onresize = null;
			
}
 
/* These functions deal with IE's retardedness in not allowing divs to 
 * cover select elements by replacing the select elements with spans. */
 
function RemoveSelectSpans()
{
	var selects = document.getElementsByTagName('select');
	
	for (var i = 0; i < selects.length; i++)
	{
		var select = selects[i];
		
		if (select.clientWidth == 0 || select.clientHeight == 0 || 
			select.nextSibling == null || select.nextSibling.className != 'selectReplacement')
		{
			continue;
		}
			
		select.parentNode.removeChild(select.nextSibling);
		select.style.display = select.cachedDisplay;
	}
}
 
function ReplaceSelectsWithSpans()
{
	var selects = document.getElementsByTagName('select');
	
	for (var i = 0; i < selects.length; i++)
	{
		var select = selects[i];
		
		if (select.clientWidth == 0 || select.clientHeight == 0 || 
			select.nextSibling == null || select.nextSibling.className == 'selectReplacement')
		{
			continue;
		}
			
		var span = document.createElement('span');
		
		// this would be "- 3", but for that appears to shift the block that contains the span 
		//   one pixel down; instead we tolerate the span being 1px shorter than the select
		span.style.height = (select.clientHeight - 4) + 'px';
		span.style.width = (select.clientWidth - 6) + 'px';
		span.style.display = 'inline-block';
		span.style.border = '1px solid rgb(200, 210, 230)';
		span.style.padding = '1px 0 0 4px';
		span.style.fontFamily = 'Arial';
		span.style.fontSize = 'smaller';
		span.style.position = 'relative';
		span.style.top = '1px';
		span.className = 'selectReplacement';
		
		span.innerHTML = select.options[select.selectedIndex].innerHTML + 
			'<img src="custom_drop.gif" alt="drop down" style="position: absolute; right: 1px; top: 1px;" />';
		
		select.cachedDisplay = select.style.display;
		select.style.display = 'none';
		select.parentNode.insertBefore(span, select.nextSibling);
	}
}
 
/* utiltiy functions */
 
function GetWindowWidth()
{
	var width =
		document.documentElement && document.documentElement.clientWidth ||
		document.body && document.body.clientWidth ||
		document.body && document.body.parentNode && document.body.parentNode.clientWidth ||
		0;
		
	return width;
}
 
function GetWindowHeight()
{
    var height =
		document.documentElement && document.documentElement.clientHeight ||
		document.body && document.body.clientHeight ||
  		document.body && document.body.parentNode && document.body.parentNode.clientHeight ||
  		0;
  		
  	return height;
}
 
// ############ HELPER FUNCTIONS ##############

function SetCookie(sName, sValue) {
	document.cookie = sName + "=" + escape(sValue) + "; expires=Fri, 31 Dec 2099 23:59:59 GMT;";
}


function GetCookie(sName) {
	var aCookie = document.cookie.split("; "); // cookies are separated by semicolons
	for (var i=0; i < aCookie.length; i++) {
		// a name/value pair (a crumb) is separated by an equal sign
		var aCrumb = aCookie[i].split("=");
		if (sName == aCrumb[0]) 
			return unescape(aCrumb[1]);
		}
	return null; // a cookie with the requested name does not exist
}

function DelCookie(sName) {
	document.cookie = sName + "=" + escape(sValue) + "; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}


// Detect which browser return true if IE
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		return this.browser;
	},
	bowserName: function() {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
				return data[i].identity;
			}
		else if (dataProp)
			return data[i].identity;
		}
	},
	dataBrowser: [ {string: navigator.vendor, subString: "Apple", identity: "Safari"},
		{prop: window.opera, identity: "Opera"},
		{string: navigator.vendor, subString: "iCab", identity: "iCab"},
		{string: navigator.vendor, subString: "KDE", identity: "Konqueror"},
		{string: navigator.userAgent, subString: "Firefox", identity: "Firefox"},
		{string: navigator.userAgent, subString: "Netscape", identity: "Netscape"}, // for newer Netscapes (6+)
		{string: navigator.userAgent, subString: "MSIE", identity: "Explorer", versionSearch: "MSIE"},
		{string: navigator.userAgent, subString: "Gecko", identity: "Mozilla", versionSearch: "rv"},
		{string: navigator.userAgent, subString: "Mozilla", identity: "Netscape", versionSearch: "Mozilla"} // for older Netscapes (4-)
	]
};

function AnalyticsTrack(strURL){ //
	try{
		// Google Analytics 
		urchinTracker(strURL);
	}
	catch(er){
		// tracking failed
	}
}

// ############ HELPER FUNCTIONS ##############





