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 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
}

// Delete the cookie with the specified name.
function DelCookie(sName) {
	document.cookie = sName + "=" + escape(sValue) + "; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}

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);
	myAshurst_setPopupStyle(); // set popup style properties
}

function myAshurst_generatePopupDiv()
{
	// generate popup div
	document.write("<div id=\"bkCnf\" class=\"bkCnf\" style=\"display:none;\">");
	document.write("<TABLE id=\"popup\" cellSpacing=\"0\" cellPadding=\"1\" border=\"0\">");
	document.write("\r\n");
	document.write("<TR>");
	document.write("<TD class=\"imageCell\" width=\"14px\" height=\"14px\" valign=\"top\" align=\"left\"><img src=\"/_layouts/1033/images/Ashurst/top_left.gif\" border=\"0\"></TD>");
	document.write("\r\n");
	document.write("<TD height=\"14px\" class=\"topBorder\" valign=\"top\" width=\"100%\"><img src=\"/_layouts/1033/images/Ashurst/spacer.gif\" border=\"0\" height=\"1px\" width=\"1px\"></TD>");
	document.write("\r\n");
	document.write("<TD class=\"imageCell\" width=\"14px\" height=\"14px\" valign=\"top\" align=\"right\"><img src=\"/_layouts/1033/images/Ashurst/top_right.gif\"></TD>");
	document.write("\r\n");
	document.write("</TR>");
	document.write("\r\n");
	document.write("<TR>");
	document.write("\r\n");
	document.write("<TD width=\"14px\" class=\"leftBorder\" align=\"left\"><img src=\"/_layouts/1033/images/Ashurst/spacer.gif\" border=\"0\" height=\"1px\" width=\"1px\"></TD>");
	document.write("\r\n");
	document.write("<TD>");
	document.write("\r\n");

	document.write("<h1 id=\"bkHead\" class=\"popup-title\"></h1>");
	document.write("<p id=\"bktext\"></p>");
	document.write("<table width=\"100%\" border=\"0\" cellspacing=\"0\">"); 
	document.write("<tr><td class=\"tabbkCnf\">");
	document.write("<table width=\"100%\" border=\"0\" cellspacing=\"2\" class=\"spsma-eventgridtable\" id=\"bookingsRec\"><tr><td></td><td></td></tr></table>");
	document.write("</td></tr><tr><td>");
	document.write("<table align=\"right\" border=\"0\" cellspacing=\"4\"><tr><td align=\"right\"><input id=\"butCancel\" type=\"button\" value=\"" + getLanguagePhrase("strInterfaceCancel") + "\" class=\"spssma-cancel-input\" onClick=\"myAshurst_hideConfirm();\"></td><td align=\"right\"><input id=\"butSubmit\" type=\"button\" value=\"" + getLanguagePhrase("strInterfaceConfirm") + "\" class=\"spssma-submit-input\" onClick=\"return false;\"></td></tr></table>");
	document.write("</td></tr></table>");

	document.write("</TD>");
	document.write("\r\n");
	document.write("<TD width=\"14px\" class=\"rightBorder\"><img src=\"/_layouts/1033/images/Ashurst/spacer.gif\" border=\"0\" height=\"1px\" width=\"1px\"></TD>");
	document.write("\r\n");
	document.write("</TR>");
	document.write("\r\n");
	document.write("<TR>");
	document.write("\r\n");
	document.write("<TD class=\"imageCell\" width=\"14px\" height=\"14px\" valign=\"bottom\" align=\"left\"><img src=\"/_layouts/1033/images/Ashurst/bottom_left.gif\" border=\"0\"></TD>");
	document.write("\r\n");
	document.write("<TD height=\"14px\" class=\"bottomBorder\" valign=\"bottom\" width=\"100%\"><img src=\"/_layouts/1033/images/Ashurst/spacer.gif\" border=\"0\" height=\"1px\" width=\"1px\"></TD>");
	document.write("\r\n");
	document.write("<TD class=\"imageCell\" width=\"14px\" height=\"14px\" valign=\"bottom\" align=\"right\"><img src=\"/_layouts/1033/images/Ashurst/bottom_right.gif\"></TD>");
	document.write("\r\n");
	document.write("</TR>");
	document.write("\r\n");
	document.write("</TABLE>");
	document.write("</div>");
			
}

function myAshurst_hideConfirm() 
{
	var lobjbkCnf = new Object();
	lobjbkCnf = document.getElementById("bkCnf");
	lobjbkCnf.style.display = "none";
	SetAllDDLDisplay("block"); // display back all drop down lists
}

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
			}
		}
	}
}

function myAshurst_setPopupStyle()
{
	SetAllDDLDisplay("none"); // hide all drop down lists

	var lobjbkCnf	= new Object(); 
	lobjbkCnf = document.getElementById("bkCnf");
	lobjbkCnf.style.position = "absolute";
	lobjbkCnf.style.display = "Block";
	lobjbkCnf.style.zindex = 10; 
	lobjbkCnf.style.width = "500px"; 
	
	// Default positions
    var winW = 250;
    var winH = 250;

	// Get the height/width of the window space
 	if (navigator.appName=="Netscape") {
  		winW = window.innerWidth;
  		winH = window.innerHeight;
	}
 	if (navigator.appName.indexOf("Microsoft")!=-1) {
		winW = document.body.offsetWidth;
		winH = document.body.offsetHeight;	
    	}

	// Get the height/width of the pop-up
	var height = 155;
	var width = lobjbkCnf.style.width.substring(0,lobjbkCnf.style.width.length-2);

	// Set the left position of the popup
	var intXPos = (winW - width) / 2;
	lobjbkCnf.style.left = intXPos + "px";

	// Set the top position of the popup
	var intYPos = ((winH - height) / 2) + document.body.scrollTop;
	intYPos = (intYPos<height)?height:intYPos;
	lobjbkCnf.style.top = intYPos + "px";
}



function SetAllDDLDisplay(strDisplay) // hide or display all drop down lists
{
	var lobjDDL;
	if (document.all) { 
		lobjDDL = document.all.tags("SELECT");
	}
	else if (document.getElementsByTagName) { 
		lobjDDL = document.getElementsByTagName("SELECT");
	}
	
	for (var i=0; i<lobjDDL.length; i++) {
//		alert(lobjDDL[i].id);
		if (lobjDDL[i].id.indexOf("ddlLanguageList")<0)
			lobjDDL[i].style.display = strDisplay;
	}

	if (document.all) { 
		lobjDDL = document.all.tags("IFRAME");
	}
	else if (document.getElementsByTagName) { 
		lobjDDL = document.getElementsByTagName("IFRAME");
	}
	
	for (var i=0; i<lobjDDL.length; i++) {
		lobjDDL[i].style.display = strDisplay;
	}

}

// write popup div
myAshurst_generatePopupDiv();



// ############ HELPER FUNCTIONS ##############
// 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 ##############





