﻿//W3Presence and its suppliers own all intellectual property in the Manage.My.Content solution; W3Presence permits you to use this software 
//solution including any of it components, methods or methodologies or in whole or part only in accordance with all our terms and conditions. 
//
//
//This solution is supplied without guarantee and all modifications must be approved unless otherwise stated

//
//
//define managemycontent solution variables
var mmcValidSecurity=false;
var mmcRemoteFunctionsFolder="/mmc/services/removefunctions/"
var mmcUserLogin="/mmc/login.asp"
var mmcBrowser="/mmc/browser.asp"
var mmcConstant_AllEditors="alleditors", mmcConstant_AllAssetLists="allassetlists";



//define the dialogue types
var mmcDialogueType_Alert="dialogeAlert", mmcDialogueType_Confirmation="dialogeConfirmation"; 



//associate external scripts
private_IncludeJavascript ("/mmc/support.js");
private_IncludeJavascript ("/mmc/services/jquery/jquery-1.4.1.min.js");
private_IncludeJavascript ("/mmc/services/jquery/jquery-ui-1.8rc3.custom.min.js");
private_IncludeJavascript ("/mmc/services/uploadify/swfobject.js");
private_IncludeJavascript ("/mmc/services/uploadify/jquery.uploadify.v2.1.0.min.js");
private_IncludeJavascript ("/mmc/services/tinymce/jscripts/tiny_mce/tiny_mce.js");

private_IncludeJavascript ("/mmc/services/popup/add-event.js");
private_IncludeJavascript ("/mmc/services/popup/popup.js");


private_IncludeCSS("/mmc/styles/managementbar.css");
private_IncludeCSS("/mmc/styles/jquery-ui.css");


//
//
//



function initialiseManagementContainer(contentContainer, debugContainers) {
//load the content management editor
var oContainer, oObjects, sManagementEditors="", sManagementAssetLists="", oAssetListProperties, oAssetProperty, sProperty, sValue;
	try { oContainer=document.getElementById(contentContainer); } catch(Error) { }	
	if(oContainer) {

	
		setMMCManagementContainer(contentContainer);
		setMMCActive(true);


		//search for mmc management container: editor
		oObjects=getElementsByAttribute("mmc_container", "editor", oContainer.id);
		for(var lCount=0; lCount<oObjects.length; lCount++) {
			sManagementEditors=cs_appendString(sManagementEditors, oObjects[lCount].id, ",");
			setEditorVariable( oObjects[lCount].id, "ready" ); //this sets an editor variable using the element name=hidden			
		}


		//search for mmc management container: assetlist
		oObjects=getElementsByAttribute("mmc_container", "assetlist", oContainer.id);
		for(var lCount=0; lCount<oObjects.length; lCount++) {
			sManagementAssetLists=cs_appendString(sManagementAssetLists, oObjects[lCount].id, ",");
			
			//identify any properties associated with asset list object
			oAssetListProperties=cs_SplitString(cs_removeWhiteSpace(cs_getObjectVariable(oObjects[lCount].id, "mmc_properties")), ";");
			for(var lProperty=0; lProperty<=oAssetListProperties.elements; lProperty++) {
				if(cs_StringLength(oAssetListProperties.string[lProperty])>0) {	
					//define object properties
					oAssetProperty=cs_SplitString(oAssetListProperties.string[lProperty], ":");
					sProperty=oAssetProperty.string[0].toLowerCase(); sValue=oAssetProperty.string[1].toLowerCase();
					switch(sProperty) {
						case "extension":
							setEditorVariable( oObjects[lCount].id + "_extension", sValue); //this sets an editor variable objectid_extension
							break;
						case "download":
							setEditorVariable( oObjects[lCount].id + "_download", sValue); //this sets an editor variable objectid_download
							break;
						case "info":
							setEditorVariable( oObjects[lCount].id + "_info", sValue); //this sets an editor variable objectid_info
							break;
						case "class":
							setEditorVariable( oObjects[lCount].id + "_class", sValue); //this sets an editor variable objectid_class
							break;
						case "maxlength":
							setEditorVariable( oObjects[lCount].id + "_maxlength", sValue); //this sets an editor variable objectid_maxlength
							break;
						case "icons":
							setEditorVariable( oObjects[lCount].id + "_icons", sValue); //this sets an editor variable objectid_icons
							break;
					}

				}
			}

		}


		//set default management variables
		setEditorVariable(mmcConstant_AllEditors, sManagementEditors); //this sets an editor variable using the element name
		setEditorVariable(mmcConstant_AllAssetLists, sManagementAssetLists); //this sets an editor variable using the element name

		setEditorVariable("autosave", "ready");	

		$(document).ready(function() {
			$("#mmcbutton_upload").uploadify({
				'method'			: 'post',
				'uploader'			: '/mmc/services/uploadify/uploadify.swf',
				'script'				: '/mmc/services/removefunctions/remote_AssetUpload.asp',
				'cancelImg'		: '/mmc/services/images/icons/16/cancel.png',
				'buttonImg'		: '/mmc/services/images/buttons/addassets.png',
				'width'				: '56',
				'height'				: '56',
				'rollover'			: true,
				'wmode'			: 'transparent',
				'folder'				: '/mmc/assets',
				'queueID'			: 'mmccontainer_uploadqueue',
				'multi'				: true,
				'auto'				: true,
				'fileDesc'			: 'Microsoft Word (*.docx), Microsoft Excel (*.xlsx), Microsoft PowerPoint (*.pptx),.Adobe PDF (*.pdf), WinZip (*.zip), PNG Image (*.png), JPG Image Files (*.jpg), GIF (*.gif)',
				'fileExt'				: '*.doc;*.docx;*.xls;*.xlsx;*.ppt;*.pptx;*.pdf;*.zip;*.png;*.gif;*.jpg',
				'sizeLimit'		: '1048576',
				'displayData'	: 'percentage',

				onComplete: function(event, queueID, fileObj, response, data) {
					//reload asset containers
					support_loadAssetListContainers();
				}
			});
		});
	}	
	
	//debug - display active containers
	if(debugContainers) {
		support_displayDialogueMessage('debugContainers - ' + mmcConstant_AllEditors + ': ' + sManagementEditors, mmcDialogueType_Alert);
		support_displayDialogueMessage('debugContainers - ' + mmcConstant_AllAssetLists + ': ' + sManagementAssetLists, mmcDialogueType_Alert);
	}
	
	support_loadAssetListContainers();
	
}



//
//
//global variables - IE issue fix relating to html element custom attbutes being wipes after initalising jQuery dialogue services
function isMMCActive() { return convertBitBoolean(cs_getJQueryBodyVariable('mmcActive')); }
function setMMCActive(bActive) { var lBit=0; if(bActive) { lBit=1; } cs_setJQueryBodyVariable('mmcActive', lBit); }
function setMMCManagementContainer(contentContainer) { cs_setJQueryBodyVariable('mmcContainer', contentContainer); }
function getMMCManagementContainer() { return cs_getJQueryBodyVariable('mmcContainer'); }


//
//
//editor services
function setEditorVariable(sVariable, vValue) { if(isMMCActive) { cs_setObjectVariable(getMMCManagementContainer(), sVariable, vValue);}} //set an editor variable
function getEditorVariable(sVariable) { var vValue=''; if(isMMCActive) { vValue=cs_getObjectVariable(getMMCManagementContainer(), sVariable);} return vValue; } //get an editor variable
function getAllEditorContainerElements() { return getEditorVariable(mmcConstant_AllEditors);} //this function returns a list of all management containers
function getAllAssetListContainerElements() { return getEditorVariable(mmcConstant_AllAssetLists);} //this function returns a list of all management containers

function convertBitBoolean(lBit) { try{ lBit=parseInt(lBit, 10); } catch(err) { lBit=0; }; switch(lBit) { case 1: return(true); break; case -1: return(true); break; default: return(false); }} //this function converts a 1 or -1 into a javascript boolean true






function cs_InitialiseCallbackEvent(milliSeconds) { setTimeout(cs_eventCallback, milliSeconds); }
function cs_eventCallback() {}



//
//
//editor controls
function useEditor(elementid) {
//this function closes any editor windows then opens the specified frame
var elements, ignore=false, activeElement="";

	if(support_ConfirmValidSecurity()) {	
		//allow only when an active securiity session is available
		elements=getAllEditorContainerElements().split(",");	
		for(var lCount=0; lCount<elements.length; lCount++) {	
			switch(getEditorVariable(elements[lCount])) { 
				case "visible": ignore=true; activeElement=elements[lCount]; break; 
			}
		}
		if(!ignore) {
			for(var lCount=0; lCount<elements.length; lCount++) {	
				switch(getEditorVariable(elements[lCount])) { 
					case "ready": if(elementid==elements[lCount]) { loadEditor(elements[lCount]); }; break;
					case "hidden": if(elementid==elements[lCount]) { showEditor(elements[lCount]); }; break; 
				}
			}
			setEditorVariable("autosave", "nothing");
		} else { 
			support_displayDialogueMessage("Close the Active Editor (" + activeElement + ") before continuing", mmcDialogueType_Alert);
		}
		
	} else {
		support_dialogueLoginService();
	}
}

// content_css : "/services/tinymce/jscripts/tiny_mce/themes/advanced/skins/default/content.css, /default.css",

function showEditor(elementid) { if(getEditorVariable(elementid)=="hidden") { setEditorVariable(elementid, "visible"); setEditorVariable("autosave", elementid); tinyMCE.get(elementid).show(); }} //this function closes the editor
function closeEditor(elementid) { if(getEditorVariable(elementid)=="visible") { setEditorVariable(elementid, "hidden"); tinyMCE.get(elementid).hide(); }} //this function closes the editor
function loadEditor(elementid) {
//initialise editor
var editorMode;

	switch(getEditorVariable(elementid)) {
		case "ready": 
			//load the editor for the first time
			tinyMCE.init({
				// general options
				mode : "exact",
				theme : "advanced",
				plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",

				file_browser_callback : "launchBrowser",

				content_css : "/services/tinymce/jscripts/tiny_mce/themes/advanced/skins/default/content.css, /hhvdefault.css",
				body_class : "editorEdit",

				// theme options
	 			theme_advanced_buttons1: "save,newdocument,|,forecolor,|,justifyleft,justifycenter,justifyright,|,bullist,numlist,|,styleselect, link,unlink, image,code", 				
				theme_advanced_buttons2 : "",
				theme_advanced_buttons3 : "",
				theme_advanced_buttons4 : "",
				theme_advanced_toolbar_location : "bottom",
				theme_advanced_layout_manager : "SimpleLayout",
				theme_advanced_styles : "Heading=mmcHeading; SubHeading=mmcSubHeading; ClipArt=mmcClipArt; Link=mmcLink, RightAd=mmcMainBodyAd_FloatRight",
				
				elements: elementid,
				
				setup: function(ed) {
					ed.onSaveContent.add(function(ed, o) {
						saveEditor(tinyMCE.activeEditor.id); //execute autosave
					});
				}

			});
			
			setEditorVariable(elementid, "visible");
			break;
	}
}


//
//
//attribute services
function cs_setObjectVariable(sObject, sVariable, vValue) { var oObject=document.getElementById(sObject); if(oObject) { oObject.setAttribute(private_supportFilterAttributeName(sVariable), vValue); }} //this function sets the object variable/attribute
function cs_getObjectVariable(sObject, sVariable) { var oObject, vValue=""; if(cs_StringLength(sObject)>0) { try { oObject=document.getElementById(sObject); } catch(err) {} if(oObject) { vValue=oObject.getAttribute(private_supportFilterAttributeName(sVariable));}} return vValue; } //this function gets the object variable/attribute

function cs_setObjectValue(sObject, vValue) { var oObject=document.getElementById(sObject); if(oObject) { oObject.value=vValue; }} //save the objects value
function cs_getObjectValue(sObject) { var oObject=document.getElementById(sObject); if(oObject) { return(oObject.value); }} //recover the objects value


function cs_setJQueryVariable(sObject, sVariable, vValue) { if(cs_ObjectExists(sObject)) { $('#'+sObject).data(private_supportFilterAttributeName(sVariable), vValue); } else { support_displayDialogueMessage("debug cs_setJQueryVariable - unable to identify object using ID '" + sObject + "'", mmcDialogueType_Alert); }}
function cs_getJQueryVariable(sObject, sVariable) { var vValue=""; if(cs_ObjectExists(sObject)) { vValue=$('#'+sObject).data(private_supportFilterAttributeName(sVariable)); } return vValue; } //this function returns the value


function cs_setJQueryBodyVariable(sVariable, vValue) { $('body').data(private_supportFilterAttributeName(sVariable), vValue); } //this function set the body variable value
function cs_getJQueryBodyVariable(sVariable) { return $('body').data(private_supportFilterAttributeName(sVariable)); } //this function returns the body variable value


function cs_removeWhiteSpace(vValue) { return vValue.replace( /\s/g, "" ); }
function cs_appendString(sOriginal, sAppend, sPrefix) { var sString=''; if(cs_IsAlphaNumeric(sOriginal)) { sString=sOriginal;} if(!cs_IsAlphaNumeric(sPrefix)) { sPrefix='';} if(cs_IsAlphaNumeric(sAppend)) { if(cs_stringLength(sAppend)>0) { if(cs_stringLength(sString)>0) { sString=sString + sPrefix; } sString=sString + sAppend; }}; return(sString); } //this function returns the appended string to the specified original
function cs_stringLength(vValue) { var sString; try { sString=String(vValue); } catch(err) { sString=''; }; return sString.length; } //this function returns the length of the specified string
function cs_SplitString(sString, sSeperator) { var rsSplitArray='', lElements=-1; if(cs_StringLength(sString)>0) { rsSplitArray=sString.split(sSeperator); lElements=rsSplitArray.length; if(lElements>0) { lElements--; }} return{ string: rsSplitArray, elements: lElements };}
function cs_StringLength(vValue) { var sString; try { sString=String(vValue); } catch(err) { sString=''; }; return sString.length; } //this function returns the length of the specified string
function cs_SetFocus(sObject) { document.getElementById(sObject).focus(); }
function cs_ObjectExists(sObject) { var bStatus=false; if($('#'+sObject).length>0) { bStatus=true; } return bStatus; } //this function return true/false 

//
//
//validation support functions
function cs_IsAlphaNumeric(vValue) { var regEx=/^[a-zA-Z_0-9\s\W]{0,}$/, bStatus=false; if(regEx.test(vValue)) { bStatus=true; } return bStatus; } //this function returns true/false depending on whether the vValue is alphanumeric
function cs_IsAlpha(vValue) { var regEx=/^[a-zA-Z\W]{0,}$/, bStatus=false; if(regEx.test(vValue)) { bStatus=true; } return bStatus; } //this function returns true/false depending on whether the vValue is alpha
function cs_IsNumeric(vValue) { var vValueX, regEx = /^-{0,1}\d*\.{0,1}\d+$/, bStatus=false; vValueX=vValue.replace(/\,/g, ''); if (regEx.test(vValueX)) { bStatus = true; } return bStatus;} //this function returns true/false depending on whether the vValue is numeric
function cs_IsEmail(vValue) { var regEx=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/, bStatus=false; if(regEx.test(vValue)) { bStatus=true; } return bStatus; } //this function returns true/false depending on whether the vValue is an email format
function cs_IsPhone(vValue) { var regEx= /^(\+\d{0,})*\s*(\(\d{0,}\)\s*)*\d{0,}(-{0,1}|\s{0,1})\d{0,}(-{0,1}|\s{0,1})\d{0,}$/, bStatus=false; if(regEx.test(vValue)) { bStatus=true; } return bStatus; } //this function returns true/false depending on whether the vValue is an phone format +XX (XX) XXX-XXXX etc.
function cs_IsUKDate(vValue) { var regEx=/^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/, bStatus=false; if(regEx.test(vValue)) { bStatus=true; } return bStatus; } //this function returns true/false depending on whether the vValue is ukdate dd/mm/yyyy
function cs_IsUSDate(vValue) { var regEx=/^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/, bStatus=false; if(regEx.test(vValue)) { bStatus=true; } return bStatus; } //this function returns true/false depending on whether the vValue is usdate mm/dd/yyyy
function cs_IsBlank(vValue) { var bStatus=false; if(cs_StringLength(vValue)==0) { bStatus=true;} return bStatus;} //this function returns true/false depending on whether the vValue is blank
function cs_IsNull(sValue) { var bStatus=true, vValue=''; if(cs_IsAlphaNumeric(sValue)) { try { vValue=sValue.toString().toLowerCase(); } catch(err) { vValue='null'; } switch (vValue) { case 'undefined': break; case 'null': break; default: bStatus=false; break; }}; return(bStatus); }

function cs_initialiseVariable(vValue, vDefault) { var vResult=vDefault; if(!cs_IsNull(vValue)) { if(cs_stringLength(vValue)>0) { vResult=vValue; }} return vResult;} //this function initialises a variable


function cs_MyDomain() { return document.domain; }
function cs_Form(sObject) { var oObject, sName, sId; oObject=document.getElementById(sObject); if(oObject) { try { sName=oObject.form.name; } catch(err) { sName=''; } try { sId=oObject.form.id; } catch(err) { sId=''; }} return { name: sName, id: sId };} //this function returns multiple values - you must select the appropriate return code or assign the function to a variable
function cs_GetFormAction(sForm) { var oForm, oActionURL, sTemp="", sActionURL="", sMyDomain="", bFixURL=false; oForm=document.getElementById(sForm); if(oForm) { oActionURL=cs_SplitString(oForm.action, '/'); sMyDomain=cs_MyDomain(); for(var lCount=0; lCount<=oActionURL.elements; lCount++) { sTemp=oActionURL.string[lCount].toLowerCase(); switch (sTemp) { case "http:": break; case "https:": break; case sMyDomain: bFixURL=true; break; default: if(cs_stringLength(sTemp)>0) { sActionURL=sActionURL+sTemp; if(lCount<oActionURL.elements) { sActionURL=sActionURL+"/"; }}; break; }}; if(bFixURL) { sActionURL="/" + sActionURL; }} return { url: sActionURL, page: oActionURL.string[oActionURL.elements]  }; } //this function returns the specified form action, included are fixes for various browsers
function cs_ReloadPage() { window.location.href=window.location.href; }
function cs_Refresh() { window.location.reload( false ); }



function getElementsByAttribute(sAttribute, sValue, sContainer) {
//this function returns all the elements in the specified container (or the body) - an example call: oObject=getElementsByClassName('shape',''); for(var i=0; i<oObject.length; i++) { alert('xx: ' + oObject[i].id); }
var oContainer, rsElements=[], sAttributeValue, oObjects;
	oContainer=document.getElementById(sContainer);
	if(!oContainer) { oContainer=document.getElementsByTagName("body")[0];} //use body - if no container specified    
	oObjects=oContainer.getElementsByTagName('*');	
	for(var lCount=0; lCount<oObjects.length; lCount++) {
		sAttributeValue=cs_getObjectVariable(oObjects[lCount].id, sAttribute);
		if(cs_IsAlphaNumeric(sAttributeValue)) { if(sAttributeValue==sValue) { rsElements.push(oObjects[lCount]);}}
	}
	return rsElements;
}


function saveEditor(elementid) {
//this function executes an ajax post to save the content
var oAJAX, myContent, urlAddress, dataBuffer;

	if(getEditorVariable("autosave")!=elementid) {
		setEditorVariable("autosave", elementid);
		myContent=tinyMCE.get(elementid).getContent(); //load the content from the editor

		oAJAX=cs_AJAXPost({ objectid: elementid, urlAddress: "remote_ContentUpdate.asp", dataBuffer: "content=" + private_filterHTMLString(myContent), async: false, debug: false });
		if(oAJAX.ajaxstatus) { 
			closeEditor(elementid); cs_InitialiseCallbackEvent(100, elementid);
		} else { support_displayDialogueMessage("Save content update failed", mmcDialogueType_Alert); } //close the editor
		
	}
}





function launchBrowser(field_name, url, type, win) {
//field_name  - is the name (and ID) of the dialogue window's input field which needs to be filled with the value your file browser is about to provide. 
//url  - carries the existing link URL if you modify a link (or image URL if you edit an image). 
//type - is a string value which is either 'image', 'media' or 'file' (called respectively from image plugin, media plugin and link plugin insert/edit dialogs). With this value you can determine whether your file browser is called from a window that inserts images ("insert/edit image" dialogue), multimedia files (media plugin window) or a window that inserts hyperlinks ("insert/edit links" dialogue). 
//win - is a reference to the dialogue window itself which is extremely important when it comes to writing back the retrieved value. You will need a combination of win and field_name to fill the required fields in the editor's dialogue window! 

var urlAddress;

	urlAddress=mmcBrowser + "?type=" + type
    tinyMCE.activeEditor.windowManager.open({
        file : urlAddress,
        title : 'Browser',
        width : 620,  
        height : 400,
        resizable : false,
        popup_css: '/mmc/styles/popup.css', 
        inline : "yes",  
		close_previous : "no"
    }, {
        window : win,
        input : field_name
    });
    return false;
 
}


function cs_BrowserPostback(URL, Title, Description) {
// based on the function - launchBrowser(field_name, url, type, win)
// tinyMCEPopup.getWindowArg("input"); = field_name
// tinyMCEPopup.getWindowArg("window"); = win
var myPopup=tinyMCEPopup.getWindowArg("window");


	//filter postbacks
	URL=cs_initialiseVariable(URL, "");
	Title=cs_initialiseVariable(Title, "");
	Description=cs_initialiseVariable(Description, ""); 


	// send the information back to the parent container
	myPopup.document.getElementById(tinyMCEPopup.getWindowArg("input")).value=URL;
	
	// are we an image browser
	if (typeof(myPopup.ImageDialog) != "undefined")
	{
		switch(tinyMCEPopup.getWindowArg("input").toLowerCase())
		{
			case "src":
				// we are updating a primary image - update image dimensions and preview if necessary
				if (myPopup.ImageDialog.getImageData) myPopup.ImageDialog.getImageData();
				if (myPopup.ImageDialog.showPreviewImage) myPopup.ImageDialog.showPreviewImage(URL);
				
				myPopup.document.getElementById('title').value=Title;
				myPopup.document.getElementById('alt').value=Description;
				
				break;
			default:
				//although we are using images we are not updating a primary (mostlikely a mouserollover etc)
				break;
		}
	}

	tinyMCEPopup.close();

}


function cs_LoadDIVContainer(sURLAddress, sDIVContainer) {
//this function posts the specified form to the specified url and posts the fragment back to the container

	$('#' +sDIVContainer).load(sURLAddress);

}


function cs_AJAXPost(associativeArray) {
//this function executes an ajax function and saves the content data - objectid: 'null', urlAddress: 'xxx', dataBuffer: 'xxx', async: 'false'
var oForm, formId, formAction, formBuffer;
var objectid, urlAddress, dataBuffer, asyncMode, debugMode, parseMode;
var cAJAXStatus=0, cAJAXIdentificationId=1, cAJAXBuffer=2, cAJAXMessage=3, cAJAXOpMode=4;
var bAJAXStatus=false, lAJAXIdentificationId=-1, sAJAXBuffer="", sAJAXMessage="", lAJAXOpMode=-1;
var lElements, sHTMLSource;


	//objectid: 'null', urlAddress: 'myURL.asp', dataBuffer: '' - extract any associative array variables
	objectid=cs_initialiseVariable(associativeArray['objectid'], ""); 
	try { oForm=document.getElementById(cs_Form(objectid).id); } catch(err) { oForm=null; }
	if(oForm) { formId=oForm.id, formAction=cs_GetFormAction(formId).page; formBuffer=$(oForm).serialize(); } else { formId=""; formAction=""; formBuffer=""; }

	//indentify async mode - async: true (run as background) - async: false (run as dedicated thread)
	asyncMode=cs_initialiseVariable(associativeArray['async'], "false");
	try { asyncMode=asyncMode.toLowerCase(); } catch(err) {}
	switch(asyncMode) { case "true": asyncMode=true; break; case "false": asyncMode=false; break; case true: asyncMode=true; break; case false: asyncMode=false; break; default: asyncMode=false; break; }


	//identify debug mode - debug:  true (display post data) - debug: false (dont display post data)
	debugMode=cs_initialiseVariable(associativeArray['debug'], "false");
	try { debugMode=debugMode.toLowerCase(); } catch(err) {}
	switch(debugMode) { case "true": debugMode=true; break; case "false": debugMode=false; break; case true: debugMode=true; break; case false: debugMode=false; break; default: debugMode=false; break; }


	//identify parse mode - parse:  true (process html feedback response) - parse: false (dont parse response - raw html feedback)
	parseMode=cs_initialiseVariable(associativeArray['parse'], "true");
	try { parseMode=parseMode.toLowerCase(); } catch(err) {}
	switch(parseMode) { case "true": parseMode=true; break; case "false": parseMode=false; break; case true: parseMode=true; break; case false: parseMode=false; break; default: parseMode=false; break; }


	//compile the post information
	urlAddress=mmcRemoteFunctionsFolder + cs_initialiseVariable(associativeArray['urlAddress'], formAction);	
	dataBuffer=cs_appendString(formBuffer, cs_initialiseVariable(associativeArray['dataBuffer'], ""), "&");	
	dataBuffer=cs_appendString(dataBuffer, "mmc_sourcepage=" + private_SourcePage(), "&");
	dataBuffer=cs_appendString(dataBuffer, "mmc_objectid=" + objectid, "&");


	if(debugMode) {
		support_displayDialogueMessage('debug Post - URLAddress: ' + urlAddress, mmcDialogueType_Alert);
		support_displayDialogueMessage('debug Post - ObjectId: ' + objectid, mmcDialogueType_Alert);
		support_displayDialogueMessage('debug Post - FormId: ' + formId, mmcDialogueType_Alert);
		support_displayDialogueMessage('debug Post - Data Buffer: ' + dataBuffer, mmcDialogueType_Alert);
		support_displayDialogueMessage('debug Post - URLAddress: ' + urlAddress, mmcDialogueType_Alert);
		support_displayDialogueMessage('debug Post - Parse: ' + parseMode, mmcDialogueType_Alert);
	}

	$.ajax({
		async: asyncMode,
		type: "post",
		url: urlAddress,
		data: dataBuffer,
		success: function(remoteData) {
		
			//display debug successful status
			if(debugMode) { support_displayDialogueMessage('debug Post - Successful Request', mmcDialogueType_Alert);}
		
			sHTMLSource=remoteData; rsDataBuffer=private_extractValues(sHTMLSource);
			try { lElements=rsDataBuffer.length; } catch(err) { lElements=0; };
			
			for(var lCount=0; lCount<lElements; lCount++) {
				switch(lCount) {
					case cAJAXStatus: bAJAXStatus=convertBitBoolean(rsDataBuffer[lCount]); break;
					case cAJAXIdentificationId: lAJAXIdentificationId=rsDataBuffer[lCount]; break;
					case cAJAXBuffer: sAJAXBuffer=rsDataBuffer[lCount]; break;
					case cAJAXMessage: sAJAXMessage=rsDataBuffer[lCount]; break;
					case cAJAXOpMode: lAJAXOpMode=rsDataBuffer[lCount]; break;
				}
			}
		},
		error: function(remoteData) {
			support_displayDialogueMessage("AJAX Post - Failed: " + urlAddress, mmcDialogueType_Alert);
		}
	});
	
	if(debugMode) {
		support_displayDialogueMessage("debug Response - Status: " + bAJAXStatus, mmcDialogueType_Alert);
		support_displayDialogueMessage("debug Response - Identification: " + lAJAXIdentificationId, mmcDialogueType_Alert);
		support_displayDialogueMessage("debug Response - Buffer: " + sAJAXBuffer, mmcDialogueType_Alert);
		support_displayDialogueMessage("debug Response - Message: " + sAJAXMessage, mmcDialogueType_Alert);
		support_displayDialogueMessage("debug Response - OpMode: " + lAJAXOpMode, mmcDialogueType_Alert);
	}
	
	return { ajaxstatus: bAJAXStatus, ajaxidentification: lAJAXIdentificationId, ajaxbuffer: sAJAXBuffer, ajaxmessage: sAJAXMessage, ajaxopmode: lAJAXOpMode, ajaxurladdress: urlAddress, ajaxpostdata: dataBuffer, htmlsource: sHTMLSource };

}


//
//
//private support functions
function private_filterHTMLString(sHTMLString) { return encodeURIComponent(sHTMLString); }
function private_supportFilterAttributeName(sAttribute) { return(sAttribute); }
function private_IncludeJavascript(scriptFile) { document.write('<script type="text/javascript" src="' + scriptFile + '"></scr' + 'ipt>');} //this function includes an external script

function private_IncludeCSS(CSSFile) { document.write('<link rel="stylesheet" type="text/css" href="' + CSSFile + '" />');} //this function includes an external script


function loadjscssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", filename)
 }
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", filename)
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}



function private_SourcePage() { var myPath=window.location.pathname; var myPage = myPath.substring(myPath.lastIndexOf('/') + 1); return myPage;} //this function returns the source page of the executing page
function private_extractValues(sSerialisedValues) {
//this function returns an array element (base 0) containing all the variables serialised - the function filters nulls and undefined values
var rsExtractValues, vValue, cSOH=String.fromCharCode(1), cUnitSeperator=String.fromCharCode(31), cUndefined=String.fromCharCode(4), cObject=String.fromCharCode(24);
	if(sSerialisedValues.substr(0,1)==cSOH) {
		sSerialisedValues=sSerialisedValues.replace(cSOH,''); rsExtractValues=sSerialisedValues.split(cUnitSeperator);
		for(var lElement in rsExtractValues) { switch(rsExtractValues[lElement]) { case cUndefined: rsExtractValues[lElement]=undefined; break; case cObject: rsExtractValues[lElement]=null; break; default: rsExtractValues[lElement]=rsExtractValues[lElement]; break; }}
	}
	return(rsExtractValues);
}


//
//
//cookie services
function cs_deleteCookie(sName) { cs_deleteCookie(sName,"-1", -1); } //remove a cookie by setting its expiry date to the passed
function cs_setCookie(sName, vValue, lDays) { var dToday = new Date(), dExpire = new Date(); if (lDays==null || lDays==0) { lDays=1; } dExpire.setTime(dToday.getTime() + 3600000*24 * lDays); document.cookie = sName+"="+escape(vValue) + ";expires="+dExpire.toGMTString(); } //set a cookie that will expire in lDays
function cs_readCookie(sName) { var sCookie=""+document.cookie, ind=sCookie.indexOf(sName), ind1=sCookie.indexOf(';',ind); if (ind==-1 || sName=="") { return ""; } if (ind1==-1) { ind1=sCookie.length; } return unescape(sCookie.substring(ind+sName.length+1,ind1)); } //read a cookie
function cs_cookiesActive() { var lStatus=0; cs_setCookie('ActiveTest', 1); if(cs_readCookie('ActiveTest')==1) { lStatus=1; cs_deleteCookie('ActiveTest');} return lStatus; } //this tests whether cookies are active on the users browser, returns 0 if disabled
