﻿/* ===========================================================
	 Initialisation code
   ========================================================== */

var needToConfirm = false;
window.onbeforeunload = confirmExit;

function confirmExit() {
	if (needToConfirm) {
		return "stuff and nonsense";
	}
}

function setPageTimeout (sessionTime) {
	window.setTimeout("window.location.href='_noSession.aspx'", sessionTime);
}

/* ===========================================================
	 General function library
   ========================================================== */

// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= QueryString related =-=-=

function getQuerystringParams() {
	// Uses prototype's toQueryParams()
	return location.toString().toQueryParams();
}


// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Event handling =-=-=

function addLoadEvent(func) {
	var oldonload = window.onload;
		
	if (typeof window.onload != 'function') 
	{		
		window.onload = function() { func; }
	} 
	else 
	{
		window.onload = function() 
		{
			if (oldonload) 
			{
				oldonload();
			}
			func();
		}		
	}
}



// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Page manipulation =-=-=

function addStylesheet(url, rel) {
	var link = document.createElement("link");
	link.setAttribute("href", url);
	
	if (rel != null) {
		link.setAttribute("rel", "stylesheet");
	}
	else {	
		link.setAttribute("rel", rel);
	}
	
	link.setAttribute("type", "text/css");
	
	var head = document.getElementsByTagName("head")[0];
	head.appendChild(link);
}



// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Element manipulation =-=-=

function hideElement(element) {
	// Uses prototype
	$(element).style.display = 'none';
}

function replaceClass(elm, oldClass, newClass) {
	/// <summary>
	/// Safely replaces the class attribute of an element
	/// </summary>
	/// <param name="elm" mayBeNull="false" optional="false" type="Element or ID">The element to be acted upon</param>
	/// <param name="oldClass" mayBeNull="false" optional="false" type="String">Class name to be removed from elm</param>
	/// <param name="newClass" mayBeNull="false" optional="false" type="String">Class name to be added to elm</param>
	elm = $(elm);
	
	if(elm.hasClassName(oldClass)) {
		elm.removeClassName(oldClass);
	}
	
	elm.addClassName(newClass);
}



function toggleLayer(whichLayer)
{
	
	if (document.getElementById)
	{
	// this is the way the standards work
		var element		= document.getElementById(whichLayer);

		var pnlMetaOpen = document.getElementById("ctl00_TopBar_pnlMetaOpen");
		var btnImage	= document.getElementById("ctl00_TopBar_btnMetaData");
		
		
		if (pnlMetaOpen.value.toLowerCase() == "false")
		{
			element.style.display	= "block";
			pnlMetaOpen.value		= "true";
			btnImage.src			= '_assets/images/_core/btnMetaDataHide.gif'
		}
		else
		{
			element.style.display	= "none";
			pnlMetaOpen.value		= "false";
			btnImage.src			= '_assets/images/_core/btnMetaDataShow.gif'
		}
	}
	else if (document.all)
	{
	// this is the way old msie versions work
		var style2			= document.all[whichLayer].style;
		var pnlMetaOpen		= document.all["ctl00_TopBar_pnlMetaOpen"];
		style2.display		= (style2.display == "block" || style2.display == "") ? "none"  : "block";
		pnlMetaOpen.value	= (style2.display == "block" || style2.display == "") ? "true"  : "false";
	}
	else if (document.layers)
	{
	// this is the way nn4 works
		var style2			= document.layers[whichLayer].style;
		var pnlMetaOpen		= document.layers["ctl00_TopBar_pnlMetaOpen"];
		style2.display		= (style2.display == "block" || style2.display == "") ? "none"  : "block";
		pnlMetaOpen.value	= (style2.display == "block" || style2.display == "") ? "true"  : "false";
	}
}

// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Telerik Code =-=-=

// Rad Editor
function RadEditorCustomFilter() {
	this.GetHtmlContent = function (content) {
		// Strip out Word auto-replacement of ' and "
		re = /[‘’]/gi
		newContent = content.replace(re, "'");
		
		re = /[“”]/gi
		newContent = content.replace(re, '"');
		
		return newContent;
	}
}

function radEditorLoad(editor) {
	var customFilter = new RadEditorCustomFilter();
	editor.FiltersManager.Add(customFilter);
}