﻿/* ===========================================================
	 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
	$j(element).css("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 = $j(elm);
	
//	if(elm.hasClassName(oldClass)) {
//		elm.removeClassName(oldClass);
//	}
	if(elm.hasClass(oldClass)) {
		elm.removeClass(oldClass);
	}
	
	elm.addClass(newClass);
}

// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 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 = newContent.replace(re, '"');

        return newContent;
    }
}

function radEditorLoad(editor) {
	var customFilter = new RadEditorCustomFilter();
	editor.FiltersManager.Add(customFilter);
	
	var style = editor.GetContentArea().style;
	style.backgroundColor = "white";
	style.fontFamily = "Arial";
}