/*
	last updated: 09/04/2006

	(void)   function GetQueryString()
	
	(void)   function FCKeditor_OnComplete (editorInstance)
	(void)   function FCKeditor_OnBlur (editorInstance)
	(void)   function FCKeditor_OnFocus (editorInstance)

	(string) function PcmsEditing_GetElementValue (strElementId)
	(bool)   function PcmsEditing_SetElementValue (strElementId, strValue)
	(bool)   function PcmsEditing_SetElementInnerHtml (strElementId, strValue)

	(string) function PcmsEditing_HiddenElementId (strApp, strName)
	(obj)    function PcmsEditing_HiddenElement (strApp, strName)
	(void)   function PcmsEditing_HiddenElementCreateInline (strApp, strName)

	(string) function PcmsEditing_VisibleElementId (strApp, strName)
	(obj)    function PcmsEditing_VisibleElement (strApp, strName)
	(void)   function PcmsEditing_VisibleElementCreateInline (strApp, strName)

*/


//--------------------------------------------------------------------------------------------------
/*
	Build a QueryString collection (Object) for use on client-side - very handy!
*/

	var QueryString = new Object();
	GetQueryString();

	function GetQueryString ()
	{
		a_strParams = document.location.search.substr(1).split('&');
		for (var i = 0; i < a_strParams.length; i++)
		{
			a_strParamSplit = a_strParams[i].split('=');
			if (a_strParamSplit.length < 2)
			{
				strParamName = a_strParams[i];
				strParamValue = strParamName;
			}
			else
			{
				strParamName = a_strParamSplit[0];
				strParamValue = a_strParamSplit[1];
			}
			QueryString[strParamName] = strParamValue;
		}
	}

//--------------------------------------------------------------------------------------------------
/*
	FCKeditor collapsing
	This allows FCKeditors on the page to attach visibility code to their onBlur and onFocus events
*/

	function FCKeditor_OnComplete (editorInstance)
	{
		editorInstance.Events.AttachEvent('OnBlur', FCKeditor_OnBlur );
		editorInstance.Events.AttachEvent( 'OnFocus', FCKeditor_OnFocus );
		FCKeditor_OnBlur(editorInstance);
	}

	function FCKeditor_OnBlur (editorInstance)
	{
		//editorInstance.ToolbarSet.Collapse();
	}

	function FCKeditor_OnFocus (editorInstance)
	{
		//editorInstance.ToolbarSet.Expand();
	}

//--------------------------------------------------------------------------------------------------

/*
	For use by out-of-page editors (ie. those that open in a popup window).
	Suggested use is to launch your popup editor and pass it a unique identifier in the querystring.
	The editor will suffix this to derive (for instance) the "_edit" and "_view" elements.
	The following functions will be used to get the original content and set the edited content.
*/

	function PcmsEditing_GetElementValue (strElementId)
	{
		var result = "";
		if (document.getElementById)
		{
			var objElement = document.getElementById(strElementId);
			if (objElement && objElement.value != undefined)
			{
				result = objElement.value;
			}
		}
		return result;
	}

	function PcmsEditing_SetElementValue (strElementId, strValue)
	{
		var result = false;
		if (document.getElementById)
		{
			var objElement = document.getElementById(strElementId);
			if (objElement && objElement.value != undefined)
			{
				objElement.value = strValue;
				result = true;
			}
		}
		return result;
	}

	function PcmsEditing_SetElementInnerHtml (strElementId, strValue)
	{
		var result = false;
		if (document.getElementById)
		{
			var objElement = document.getElementById(strElementId);
			if (objElement && objElement.innerHTML != undefined)
			{
				objElement.innerHTML = strValue;
				result = true;
			}
		}
		return result;
	}

/*
	For ultra convenience, and consistency, these routines will help you:
	Generate a suitable ID, inline create (document.write) the element, and reference the element; for _HIDDEN and _VSIBLE variations.
*/

	function PcmsEditing_HiddenElementId (strApp, strName)
	{
		return (strApp + "_" + strName + "_HIDDEN");
	}
	
	function PcmsEditing_HiddenElement (strApp, strName)
	{
		var result = null;
		if (document.getElementById)
		{
			result = document.getElementById(PcmsEditing_ContentElementId(strApp, strName));
		}
		return result;
	}
	
	function PcmsEditing_HiddenElementCreateInline (strApp, strName)
	{
		var strId = PcmsEditing_ContentElementId(strApp, strName);
		document.write ("<input type=\"hidden\" id=\"" + strId + "\" name=\"" + strId + "\" value=\"\" />");
	}

	function PcmsEditing_VisibleElementId (strApp, strName)
	{
		return (strApp + "_" + strName + "_VISIBLE");
	}
	
	function PcmsEditing_VisibleElement (strApp, strName)
	{
		var result = null;
		if (document.getElementById)
		{
			result = document.getElementById(PcmsEditing_ContentElementId(strApp, strName));
		}
		return result;
	}
	
	function PcmsEditing_VisibleElementCreateInline (strApp, strName)
	{
		var strId = PcmsEditing_ContentElementId(strApp, strName);
		document.write ("<div id=\"" + strId + "\" name=\"" + strId + "\"></div>");
	}


	if (!getElementsByClass) {
		// Only create this function if not already done so.
		var getElementsByClass = function(FindClass, StartNode, TagName) {
			var result = [];
			if (FindClass != "") {
				if (StartNode == null) StartNode = document;
				if (TagName == null) TagName = '*';
				var MatchingTags = StartNode.getElementsByTagName(TagName);
				var ClassMatchPattern = new RegExp("(^|\\s)" + FindClass + "(\\s|$)");
				for (i = 0; i < MatchingTags.length; i++) {
					if (ClassMatchPattern.test(MatchingTags[i].className)) result.push(MatchingTags[i]);
				}
			}
			return result;
		};
	}

	function ToggleAdvancedPageProperties(setting) {
		elementsToToggle = getElementsByClass("advancedproperty", null, "TR");
		setdisplay = setting ? (document.all ? "block" : "table-row") : "none";
		for (i = 0; i < elementsToToggle.length; i++) {
			elementsToToggle[i].style.display = setdisplay;
		}
		createCookie("PcmsEditControlPanelAdvancedProperties", setting.toString(), 3);
	}

	var chkAdvancedPropertiesCookieSetting = readCookie("PcmsEditControlPanelAdvancedProperties");
	if (chkAdvancedPropertiesCookieSetting == "true" && document.getElementById("chkPcmsEditControlPanelAdvancedPropertiesToggle")) {
		document.getElementById("chkPcmsEditControlPanelAdvancedPropertiesToggle").click() = true;
	}



	// Cookie code. To cut corners I am using some code I found on the 'net
	// http://www.quirksmode.org/js/cookies.html

	function createCookie(name, value, days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
			var expires = "; expires=" + date.toGMTString();
		}
		else var expires = "";
		document.cookie = name + "=" + value + expires + "; path=/";
	}

	function readCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for (var i = 0; i < ca.length; i++) {
			var c = ca[i];
			while (c.charAt(0) == ' ') c = c.substring(1, c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
		}
		return null;
	}

	function eraseCookie(name) {
		createCookie(name, "", -1);
	}




//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------

