// dynafn javascript support functions
// the system uses a number of common constants to increase the module nature of the system - cJSXConfiguration_LabelColumn, cJSXConfiguration_IDColumn


//
//
//system constants

var cDiagnostic_EnableDynaFnPostDataDump=false //this displays dynafunction post data

var cDynaMode_AlphaNumeric=1, cDynaMode_Alpha=2, cDynaMode_Numeric=3, cDynaMode_Email=4, cDynaMode_Phone=5, cDynaMode_Password=6, cDynaMode_UKDate=7, cDynaMode_USDate=8; //these have to match the ASP versions
var cDynaFNFunction='/myjaxos/include/dynafunction/';

var cDynaFNLiterals_ElementColour='dynaSenseElementColour', cDynaFNLiterals_ElementValid='dynaSenseElementValid', cDynaFNLiterals_ExecutePostFormValidation='dynaSenseExecutingPostFormValidation', cDynaFNLiterals_AutoValidation='dynaSenseAutoValidation';
var cDynaFNLiterals_AutoHTMLUniqueId='dynaSenseAutoHTMLUniqueId', cDynaFNLiterals_AutoUniqueHTMLImageId='dynaSenseAutoUniqueHTMLImageId' ,cDynaFNLiterals_AutoUniqueDynaFunctionURL='dynaSenseAutoUniqueDynaFunctionURL';
var cDynaFNLiterals_AutoUniqueDynaFunctionImageURL1='dynaSenseAutoUniqueHTMLImageURL1', cDynaFNLiterals_AutoUniqueDynaFunctionImageURL2='dynaSenseAutoUniqueHTMLImageURL2', cDynaFNLiterals_AutoUniqueDynaFunctionImageURL3='dynaSenseAutoUniqueHTMLImageURL3'
var cDynaFNLiterals_AutoLookupHelperElementId="dynaSenseLookupHelperElementId", cDynaFNLiterals_AutoLookupHelperParentId="dynaSenseLookupHelperParentId", cDynaFNLiterals_AutoLookupHelperDynaFunctionURL="dynaSenseLookupHelperDynaFunctionURL";

var cDynaFNLiterals_AutoLeft='dynaSenseAutoLeft', cDynaFNLiterals_AutoTop='dynaSenseAutoTop';


var cDynaFNStyle_WarningColour='#ff3333';


//
//
//support function
function dnyaFNproperty_Warning(sHexColour) { cDynaFNStyle_WarningColour=sHexColour; } //this function remaps the warning colour



//
//
//-------------------------------------------------------------------------------------------------------------
// validation services and support functions
//-------------------------------------------------------------------------------------------------------------
function dynaFNProperty_GetElementValid(oElement) { var bValid=false; switch(cs_getObjectVariable(oElement.id, cDynaFNLiterals_ElementValid)) { case cs_convertBooleanBit(false): bValid=false; break; default: bValid=true; break; } return(bValid); } //this function returns true/false depending on whether the specified element is marked as valid
function dynaFNproperty_SetBGColour(oObject, sBackgroundHexColour) { oObject.style.backgroundColor=sBackgroundHexColour; } //this function sets the objects colour
function dynaFNproperty_GetBGColour(oObject) { var sBGColour=oObject.style.backgroundColor; if(sBGColour==null) { sBGColour=''; } 	return(sBGColour); } //this function return the objects colour

function dynaFNProperty_SetFormValidation(sForm, bActive) { cs_setObjectVariable(sForm, cDynaFNLiterals_ExecutePostFormValidation, cs_convertBooleanBit(bActive)); } //set the form validation flag
function dynaFNProperty_GetFormValidation(sForm) { return(cs_convertBitBoolean(cs_getObjectVariable(sForm, cDynaFNLiterals_ExecutePostFormValidation))); } //set the form validation flag


function dynaFNHelper(sHelperId, sParent, lLeft, lTop, sDynaFNURL) {
var sHelper, sHelpTitle, sHelperPanel, oHelper, oHelpTitle, oHelperPanel, lLayerId, lZIndex, sAdditionData='';

var lHeight=180, lWidth=210, lTitleHeight=24, lAdjustment=4;

	if(cs_getObjectVariable(sHelperId, 'HelperActive')!='active') {

		//create new helper
		lLayerId=raiseFrameCounter(); lZIndex=raiseZIndexCounter();
		sHelper=sHelperId+'_'+lLayerId; 
		sHelpTitle=sHelper+'_title'; 
		sHelperPanel=sHelper+'_panel'; 	
				
		cs_setObjectVariable(sHelperId, 'HelperLayer', lLayerId); 
	
		oHelper=createLayer(document.getElementById(sParent), sHelper, 'absolute', lLeft, lTop, lWidth, lHeight, 0, lZIndex, findRegisteredImage(cimgWinHelperBlock).src, 'scroll', 'repeat', false, false, false);
		if(oHelper) {
			// 	cimgPixelTransparent
			cs_setObjectVariable(sHelperId, 'HelperActive', 'active');
			oHelpTitle=createLayer(document.getElementById(oHelper), sHelpTitle, 'absolute', 0, 0, lWidth, lTitleHeight, 0, lZIndex, findRegisteredImage(cimgPixelTransparent).src, 'scroll', 'repeat', false, true, false);
			oHelperPanel=createLayer(document.getElementById(oHelper), sHelperPanel, 'absolute', lAdjustment, lTitleHeight, lWidth-(lAdjustment*2), (lHeight-lTitleHeight-lAdjustment), 0, lZIndex, findRegisteredImage(cimgPixelTransparent).src, 'scroll', 'repeat', true, true, false);

			createHTMLSegment(oHelpTitle, '<div style=\'background-color: #141414; text-align: right; padding-top: 0px; cursor: default\' title=\'Helper window: existing references are listed below\'><img onclick=\"private_dynaFNHelperClose(\'' + sHelperId + '\');\" src=\'/myjaxos/include/images/gui/winControlMini0.gif\' title=\'close helper window\' onmouseover=\"this.src=\'/myjaxos/include/images/gui/winControlMini1.gif\'; \" onmouseout=\"this.src=\'/myjaxos/include/images/gui/winControlMini0.gif\'; \" /></div>');
			
		}
	} else { 
		//create pointer to original helper
		sHelperPanel=sHelperId+'_'+cs_getObjectVariable(sHelperId, 'HelperLayer')+'_panel';
	}	 
	private_executeFunction_AutoUpdater(sHelperId, sDynaFNURL, sHelperPanel);

}

function private_dynaFNHelperClose(sHelperId) {
//this function closes the dynahelper window
var lLayerId, sHelper, sHelpTitle, sHelperPanel, oParent, oUpdate, oHelper, oTitle, oPanel;

	lLayerId=cs_getObjectVariable(sHelperId, 'HelperLayer', lLayerId); 	
	sHelper=sHelperId+'_'+lLayerId; sHelpTitle=sHelper+'_title'; sHelperPanel=sHelper+'_panel'; 	
	
	oUpdate=document.getElementById(sHelperId); oParent=oUpdate.parentNode;
	oHelper=document.getElementById(sHelper); oTitle=document.getElementById(sHelpTitle); oPanel=document.getElementById(sHelperPanel);
	
	oHelper.removeChild(oPanel); oHelper.removeChild(oTitle); oParent.removeChild(oHelper);
	cs_setObjectVariable(sHelperId, 'HelperActive', 'nonactive');
	
}

function private_dynaFNHelperUpdate(sHelperId, vValue) {
//this function updates the helper and closes
	document.getElementById(sHelperId).value=vValue;
	private_dynaFNHelperClose(sHelperId);
}


//
//event services
function dynaFNEventFocus(oObject) { try { if(oObject) {if(cs_getObjectVariable(oObject.id, cDynaFNLiterals_ElementColour)==null) {cs_setObjectVariable(oObject.id, cDynaFNLiterals_ElementColour, dynaFNproperty_GetBGColour(oObject));} if(!dynaFNProperty_GetFormValidation(cs_Form(oObject.id).name)) {if(!cs_getObjectProperty(oObject).readonly) { oObject.select(); };}}} catch(err) {}} //this function autoselects the value in the specified object
function dynaFNEventBlur(bMandatory, oObject) { var vValue=String(oObject.value); try { switch(bMandatory) { case true: if(vValue.blank()) { private_validationFailed(oObject); } break; default: break; }} catch(err) {}} //this function checks mandatory fields
function dynaFNEventClose(sWindowReference) { executeControlClose(sWindowReference); } //this function is a wrapper for the executeControlClose mjjaxos function


function dynaFNEventKeyUp(sWindowReference, oObject, lKeyCode) {
//this function fires a number of definable events specified via attributes configured with the supplied object
var sObject1, sObject2, sObject3, sObject4, sPositionLeft, sPositionTop, sExternalGroup, sSource1, sSource2, sSource3, sURL, lId, bStatus=false, bLookup=false;
var cKey_F1=112, cKey_F12=123, cKey_CursorLeft=37, cKey_CursorRight=39, cKey_CursorUp=38, cKey_CursorDown=40;

	if(oObject) {
	
		switch(lKeyCode) {
			case cKey_F1:
				break;
			case cKey_F12:
				dynaFNContextHelp(oObject.id);
				break;
			case cKey_CursorLeft:
				break;
			case cKey_CursorRight:
				break;
			case cKey_CursorUp:
				break;
			case cKey_CursorDown:
				break;
			default:
				//process key strokes
				if(cs_StringLength(cs_getObjectValue(document.getElementById(oObject.id)))>0 ) { bLookup=true; }; 
				break;
		}
	
		//process the unique service 
		sObject1=oObject.id; //this is the actual object id (eg: blogreference)
		sObject2=cs_getObjectVariable(oObject.id, cDynaFNLiterals_AutoHTMLUniqueId); //this is the primary key used to identify the datarecord (eg: blogid etc)
		sObject3=cs_getObjectVariable(oObject.id, cDynaFNLiterals_AutoUniqueHTMLImageId); //this is the html element used to update the user (eg: blogreference_image )
		sURL=cs_getObjectVariable(oObject.id, cDynaFNLiterals_AutoUniqueDynaFunctionURL); //this returns the dynafunction (eg: dynafn_blogarticle_reference.asp )
		
		sSource1=cs_getObjectVariable(oObject.id, cDynaFNLiterals_AutoUniqueDynaFunctionImageURL1); //this returns the image URL
		sSource2=cs_getObjectVariable(oObject.id, cDynaFNLiterals_AutoUniqueDynaFunctionImageURL2); 
		sSource3=cs_getObjectVariable(oObject.id, cDynaFNLiterals_AutoUniqueDynaFunctionImageURL3); 
		
		//only execute this function if the element contains a unique id reference
		if(sObject2!=null) { 	
			if(cs_StringLength(cs_getObjectValue(document.getElementById(sObject1)))>0 ) { 
				//only execute if the object contains some value			
				switch(parseInt(private_executeFunction_PostDataPair(sObject1, sObject2, sURL, sWindowReference), 10)) {
					case -1: 
						cs_setObjectSourceAttribute(sObject3, sSource3, 'This field must be unique: It is'); //value available
						setWindowStatus(sWindowReference, 'Status: reference available'); 
						break;
					default: 
						cs_setObjectSourceAttribute(sObject3, sSource2, 'This field must be unique: Sorry, it isn\'t'); //value exists
						setWindowStatus(sWindowReference, 'Status: reference exists'); 
						break;
				}
			} else {
				//no values supplied
				cs_setObjectSourceAttribute(sObject3, sSource1, 'This field must be unique'); //value empty - no user imput
			}
		} //end verify unique function


		//process the helper services
		if(bLookup) {
			sObject2=cs_getObjectVariable(oObject.id, cDynaFNLiterals_AutoLookupHelperElementId); //this is the primary key used to identify the helper id (eg: blogid etc)	
			sObject3=cs_getObjectVariable(oObject.id, cDynaFNLiterals_AutoLookupHelperParentId); 
			
			sPositionLeft=cs_getObjectVariable(oObject.id, cDynaFNLiterals_AutoLeft); //get the display at position
			sPositionTop=cs_getObjectVariable(oObject.id, cDynaFNLiterals_AutoTop); 
			
			sURL=cs_getObjectVariable(oObject.id, cDynaFNLiterals_AutoLookupHelperDynaFunctionURL); //this returns the dynafunction (eg: dynafn_blogarticle_reference.asp )

			//only execute this function if the element contains a unique id reference
			if(sObject2!=null) { 	
				dynaFNHelper(sObject2, sObject3, sPositionLeft, sPositionTop, sURL)
			}
		}

	}
}


function dynaFNContextHelp(sObject) {
//this function is the context sensitive help
	alert('Context Help: ' + sObject + '\nthis services is not implemented');
}


//
//validation services
function dnyaFNEventAutoValidation(sWindowReference, oObject, bMandatory, cMode, lMinChars, lMaxChars, dMinValue, dMaxValue, lLowerChars, lUpperChars, lNumericChars) {
//this is an automatically fired event executed by the fJAXOS_CreateValidationRules services
var bStatus=false, sMessage='', lMode=0, oCtrlApplyButton=document.getElementById('apply_' + sWindowReference), vValue=String(oObject.value), validatePassword, lLength=cs_StringLength(vValue); 
	try {
			switch(parseInt(cMode, 10)) {
				case cDynaMode_Alpha:		if(bMandatory) { if(cs_IsAlpha(vValue)) { if((parseInt(lLength)>=lMinChars && parseInt(lLength)<=lMaxChars) || (lMinChars<=0) || (lMaxChars<=0)) { bStatus=true; }}} else {if(cs_IsBlank(vValue)) { bStatus=true;} else { if(cs_IsAlpha(vValue)) { if((parseInt(lLength)>=lMinChars && parseInt(lLength)<=lMaxChars) || (lMinChars<=0) || (lMaxChars<=0)) { bStatus=true;}}}}; sMessage='Alpha - min: ' + lMinChars + ', max: ' + lMaxChars; break;
				case cDynaMode_Numeric:	if(bMandatory) { if(cs_IsNumeric(vValue)) { if((parseFloat(vValue)>=dMinValue && parseFloat(vValue)<=dMaxValue)) { bStatus=true;}}} else { if(cs_IsBlank(vValue)) { bStatus=true; } else { if(cs_IsNumeric(vValue)) { if((parseFloat(vValue)>=dMinValue && parseFloat(vValue)<=dMaxValue)) { bStatus=true;}}}}; sMessage='Numeric - min: ' + dMinValue + ', max: ' + dMaxValue; break;
				case cDynaMode_Email:		if(bMandatory) { bStatus=cs_IsEmail(vValue);} else { if(cs_IsBlank(vValue)) { bStatus=true; } else {bStatus=cs_IsEmail(vValue);}	}; sMessage='Email'; break;
				case cDynaMode_Phone:		if(bMandatory) { bStatus=cs_IsPhone(vValue);} else {if(cs_IsBlank(vValue)) {bStatus=true;} else {bStatus=cs_IsPhone(vValue);}}; sMessage='Phone'; break;
				case cDynaMode_Password:	if(bMandatory) { validatePassword=cs_ValidatePassword(vValue, lMinChars, lMaxChars, lLowerChars, lUpperChars, lNumericChars); bStatus=validatePassword.status; sMessage=validatePassword.message; lMode=validatePassword.mode; } else { if(cs_IsBlank(vValue)) { bStatus=true; sMessage='password not supplied'; lMode=0; } else { validatePassword=cs_ValidatePassword(vValue, lMinChars, lMaxChars, lLowerChars, lUpperChars, lNumericChars); bStatus=validatePassword.status; sMessage=validatePassword.message; lMode=validatePassword.mode; }}; break;
				case cDynaMode_UKDate:		if(bMandatory) { bStatus=cs_IsUKDate(vValue);} else {if(cs_IsBlank(vValue)) {bStatus=true;} else {bStatus=cs_IsUKDate(vValue);}} sMessage='UKDate'; break;
				case cDynaMode_USDate:		if(bMandatory) { bStatus=cs_IsUSDate(vValue);} else {if(cs_IsBlank(vValue)) {bStatus=true;} else {bStatus=cs_IsUSDate(vValue);}} sMessage='USDate'; break;
					
				default:	//cDynaMode_AlphaNumeric:
					if(cs_IsAlphaNumeric(vValue)) { if((parseInt(lLength)>=lMinChars && parseInt(lLength)<=lMaxChars) || (lMinChars<=0) || (lMaxChars<=0)) { bStatus=true; }} sMessage='AlphaNumeric - min: ' + lMinChars + ', max: ' + lMaxChars; break;
			}
	} catch(err) { bStatus=false; }
	//process the results
	if(bStatus) { //handle the successful outcome	
		if(oCtrlApplyButton) { 
			if(!dynaFNProperty_GetFormValidation(cs_Form(oObject.id).name)) { //prevent the apply button being released if the form validator is running
				oCtrlApplyButton.disabled=false; } //enable the auro apply restore button
			}
		cs_setObjectVariable(oObject.id, cDynaFNLiterals_ElementValid, cs_convertBooleanBit(true)); //set the validation status		
		dynaFNproperty_SetBGColour(oObject, cs_getObjectVariable(oObject.id, cDynaFNLiterals_ElementColour)); //return the background colour to the default
	} else { //handle the failed outcome
		try { private_validationFailed(oObject); } catch(err) {}
	}	
	return {status: bStatus, message: sMessage, mode: lMode};
}


//
//media asset services
function dynaFNAssetMediaBatchUpdate(oControlButton, sWindowReference) {
//this function uses the control button to update the media assets
var oForm=document.getElementById(cs_Form(oControlButton.id).name), oDynaCall, lUpdates=0; 

	//process custom functions
	try { eval(cs_getObjectVariable(oForm.id, "oscommonfunction")) } catch(err) {};
	oDynaCall=private_executeFunction_SSI(oForm, "dynafn_mediaassets_batchupdate.asp", "", false);
	switch (oDynaCall.status) {
		case true: lUpdates=oDynaCall.autoid; alert('Update Manager Complete: ' + lUpdates + ' assets updated.'); break;
		default: break;
	}
}


//
//post data services
function dynaFNPostData(oControlButton, sWindowReference, bCloseOnSuccess, sAutoIdUpdateElement) {
//this function uses the control button to identify the parent form - then executes a full pre-post validation before using private_executeFunction_PostForm to packet and post the all form data
var lCount, oForm=document.getElementById(cs_Form(oControlButton.id).name), oElement, bValid=true;
	//execute dynasense events	
	
	dynaFNProperty_SetFormValidation(oForm.name, true); //set form validation - started		
	for(lCount=0;lCount<oForm.elements.length; lCount++) {
		try { oElement=document.getElementById(oForm.elements[lCount].id); } catch(err) {oElement=null;} //locate element
		if(oElement) {
			//confirm that the element is valid for this validation
			switch(cs_convertBitBoolean(cs_getObjectVariable(oElement.id, cDynaFNLiterals_AutoValidation))) {
				case true:
					cs_fireEvent(oElement, 'focus'); //execute focus event - this forces any validation routines to function
					cs_fireEvent(oElement, 'change'); //execute onchange event				
					switch(dynaFNProperty_GetElementValid(oElement)) { case false: bValid=false; break; }
					break;
				default: break;		
			}
		}
	}
	
	//process custom functions
	try { eval(cs_getObjectVariable(oForm.id, "oscommonfunction")) } catch(err) {};
	
	switch(bValid) {
		case true: private_executeFunction_PostForm(oControlButton, oForm.name, sWindowReference, bCloseOnSuccess, sAutoIdUpdateElement); break;
		default: setWindowStatus(sWindowReference, 'Warning: unable to process form, please check data'); alert('Warning: unable to process form, please check data'); break;
	}
	
}



//
//
//-------------------------------------------------------------------------------------------------------------
// asset catalogue - services and support functions
//-------------------------------------------------------------------------------------------------------------
function dynaFNMediaAssets_Sync(sWindowReference) {
//this function resyncs the existing catalogues
var lAssets;

	if(confirm('Sync Media Assets, Are you sure?\n\nSyncronising assets in registered catalogues can take several minutes.\nClick "Okay" to continue')) {
		lAssets=private_executeFunction_NoVariables('dynafn_mediaassets_sync.asp', sWindowReference)
		alert('Sync Complete: ' + lAssets + ' new assets found.');
	} else {
		alert('Request Cancelled');
	}

}


function dynaFNMediaAssets_CheckImport(sForm) {
//this function checks whether the specified file already exists
var sDynaFNURL='dynafn_mediaassets_checkimport.asp', dynaCall;

	dynaCall=private_executeFunction_SSI(sForm, sDynaFNURL, '', false);
	return dynaCall.autoid;

}


//
//
//-------------------------------------------------------------------------------------------------------------
// blog articles - services and support functions
//-------------------------------------------------------------------------------------------------------------
function dynaFNBlogArticle_optionsLookups(oMe, sUpdateObject, sDefaultValue, lGroupId) {
//this function executes a dynamic function - this is a custom re-write for the selectbox options to enable standard variables to be posted
var vValue, bridgeData, sDynaFNURL='blogarticle_selectoptions_lookup.asp';
	if(oMe) {
		vValue=oMe.options[oMe.selectedIndex].value;
		bridgeData=	'updateobject=' + escape(sUpdateObject) +
							'&defaultvalue=' + escape(sDefaultValue) +
							'&groupid=' + escape(lGroupId) +
							'&ignorepublish=' + escape(cs_convertBooleanBit(false)) +
							'&requestpage=' + escape(-1);
		private_executeFunction_CSJScript(sUpdateObject, bridgeData, sDynaFNURL);
	}
}







//
//
//-------------------------------------------------------------------------------------------------------------
// product catalogue - services and support functions
//-------------------------------------------------------------------------------------------------------------
function dynFNSelectOptions_ProductCatalogueSubcategories(oMe, sUpdateObject, sDefaultValue, lCategoryId, bIgnorePublish, bIncludeAll, lRequestPage) {
//this function executes a dynamic function - this is a custom re-write for the selectbox options to enable addition variables to be posted
var vValue, bridgeData, sDynaFNURL='dynafn_productcatalogue_selectoptions_subcategory.asp';
	if(oMe) {
		vValue=oMe.options[oMe.selectedIndex].value;
		bridgeData=	'updateobject=' + escape(sUpdateObject) +
							'&defaultvalue=' + escape(sDefaultValue) +
							'&categoryid=' + escape(lCategoryId) +
							'&ignorepublish=' + escape(cs_convertBooleanBit(bIgnorePublish)) + 
							'&includeall=' + escape(cs_convertBooleanBit(bIncludeAll)) + 
							'&requestpage=' + escape(lRequestPage);
		private_executeFunction_CSJScript(sUpdateObject, bridgeData, sDynaFNURL);
	}
}





//
//
//-------------------------------------------------------------------------------------------------------------
// contact book - services and support functions
//-------------------------------------------------------------------------------------------------------------
function dynaFNSelectOptions_ContactBookLookups(oMe, sUpdateObject, sDefaultValue, lGroupId) {
//this function executes a dynamic function - this is a custom re-write for the selectbox options to enable standard variables to be posted
var vValue, bridgeData, sDynaFNURL='contactbook_selectoptions_lookup.asp';
	if(oMe) {
		vValue=oMe.options[oMe.selectedIndex].value;
		bridgeData=	'updateobject=' + escape(sUpdateObject) +
							'&defaultvalue=' + escape(sDefaultValue) +
							'&groupid=' + escape(lGroupId) +
							'&ignorepublish=' + escape(cs_convertBooleanBit(false)) +
							'&requestpage=' + escape(-1);
		private_executeFunction_CSJScript(sUpdateObject, bridgeData, sDynaFNURL);
	}
}

function dynaFNSelectOptions_ContactBookContacts(oMe, sUpdateObject, sDefaultValue, sContactRef, sFirstName, sMiddleName, sLastName, sEmail, sCompany, lContactTypeId, lLocationId, lOrganisationId, bIgnorePublish, bAlphabetic, bEnableWildCards, lRequestPage) {
//this function executes a dynamic function - this is a custom re-write for the selectbox options to enable addition variables to be posted
var vValue, bridgeData, sDynaFNURL='contactbook_selectoptions_contact.asp';
	if(oMe) {
		vValue=oMe.options[oMe.selectedIndex].value;
		bridgeData=	'updateobject=' + escape(sUpdateObject) +
							'&defaultvalue=' + escape(sDefaultValue) +
							'&contactref=' + escape(sContactRef) +
							'&firstname=' + escape(sFirstName) +
							'&middlename=' + escape(sMiddleName) +
							'&lastname=' + escape(sLastName) +
							'&email=' + escape(sEmail) +
							'&company=' + escape(sCompany) +
							'&contacttypeid=' + escape(lContactTypeId) +
							'&locationid=' + escape(lLocationId) +
							'&organisationid=' + escape(lOrganisationId) +
							'&ignorepublish=' + escape(cs_convertBooleanBit(bIgnorePublish)) + 
							'&alphabetic=' + escape(cs_convertBooleanBit(bAlphabetic)) + 	
							'&enablewildcards=' + escape(cs_convertBooleanBit(bEnableWildCards)) + 							
							'&requestpage=' + escape(lRequestPage);
		private_executeFunction_CSJScript(sUpdateObject, bridgeData, sDynaFNURL);
	}
}

function dynaFNSelectOptions_ContactBookLocations(oMe, sUpdateObject, sDefaultValue, sLocationRef, lOrganisationId, lLocationTypeId, sSummary, sAddress1, sAddress2, sTown, sCounty, sPostcode, sCountry, sRegion, bIgnoreActive, bIgnorePublish, lRequestPage) {
//this function executes a dynamic function - this is a custom re-write for the selectbox options to enable addition variables to be posted
var vValue, bridgeData, sDynaFNURL='contactbook_selectoptions_location.asp';
	if(oMe) {
		vValue=oMe.options[oMe.selectedIndex].value;
		bridgeData=	'updateobject=' + escape(sUpdateObject) +
							'&defaultvalue=' + escape(sDefaultValue) +
							'&locationref=' + escape(sLocationRef) +
							'&organisationid=' + escape(lOrganisationId) +
							'&locationtypeid=' + escape(lLocationTypeId) +
							'&summary=' + escape(sSummary) +
							'&address1=' + escape(sAddress1) +
							'&address2=' + escape(sAddress2) +
							'&town=' + escape(sTown) +
							'&county=' + escape(sCounty) +
							'&postcode=' + escape(sPostcode) +
							'&country=' + escape(sCountry) +
							'&region=' + escape(sRegion) +
							'&ignoreactive=' + escape(cs_convertBooleanBit(bIgnoreActive)) + 
							'&ignorepublish=' + escape(cs_convertBooleanBit(bIgnorePublish)) + 
							'&requestpage=' + escape(lRequestPage);
		private_executeFunction_CSJScript(sUpdateObject, bridgeData, sDynaFNURL);
	}
}

function dynaFNSelectOptions_ContactBookOrganisations(oMe, sUpdateObject, sDefaultValue, sOrganisationRef, sOrganisationPhrase, lOrganisationTypeId, sOrganisationName, bIgnorePublish, lRequestPage) {
//this function executes a dynamic function - this is a custom re-write for the selectbox options to enable addition variables to be posted
var vValue, bridgeData, sDynaFNURL='contactbook_selectoptions_organisation.asp';
	if(oMe) {
		vValue=oMe.options[oMe.selectedIndex].value;
		bridgeData=	'updateobject=' + escape(sUpdateObject) +
							'&defaultvalue=' + escape(sDefaultValue) +
							'&organisationref=' + escape(sOrganisationRef) +
							'&organisationphrase=' + escape(sOrganisationPhrase) +
							'&organisationtypeid=' + escape(lOrganisationTypeId) +
							'&organisationname=' + escape(sOrganisationName) +
							'&ignorepublish=' + escape(cs_convertBooleanBit(bIgnorePublish)) + 
							'&requestpage=' + escape(lRequestPage);
		private_executeFunction_CSJScript(sUpdateObject, bridgeData, sDynaFNURL);
	}
}






//
//
//-------------------------------------------------------------------------------------------------------------
//this section is used to execute dynamic instructions on the server side
//-------------------------------------------------------------------------------------------------------------
function private_validationFailed(oObject) {
//this function executes a validation denied service call
	cs_setObjectVariable(oObject.id, cDynaFNLiterals_ElementValid, cs_convertBooleanBit(false)); //set the validation status
	dynaFNproperty_SetBGColour(oObject, cDynaFNStyle_WarningColour); 
	switch(dynaFNProperty_GetFormValidation(cs_Form(oObject.id).name)) { case true: break; case false: winFxPulseObject(oObject.id); break; } //enable highlight effects
}

function private_executeFunction_CSJScript(sUpdateObject, bridgeData, sDynaFNURL) {
//this function executes a AJAX post function and evaluates the server-side response as a javascript instruction
	cs_setObjectDisabled(sUpdateObject, true);
	new Ajax.Request(cDynaFNFunction + sDynaFNURL, {
		asynchronous: true,
		method: 'post',
		parameters: bridgeData,
		evalScripts: true,
			onSuccess: function(transport) {					
				eval(transport.responseText);
			}, 
			onFailure: function(transport) { alert('Warning: DynaFN CSJScript service ' + sURL + ' failed'); } //the application page call was unsuccessful
	} );	
	cs_setObjectDisabled(sUpdateObject, false);
}

function private_executeFunction_SSI(oForm, sURL, sAdditionData, bASYNC) {
//this function executes the specified form to the specified url, the follow defines an AJAX.response: eg: alert('Okay: '  + transport.status); alert(transport.responseText);
//response: status, statusText, readyState, responseText, responseXML, responseJSON, transport: the native xmlHttpRequest object, response. getHeader(name), getAllHeaders(), getResponseHeader(name), getAllResponseHeaders()
var postData=cDynaFNFunction + sURL, dataBuffer='', fnStatus=false, fnMessage="", fnAutoId=-1, fnForceClose=false, postResponse="", cUnitSeperator=String.fromCharCode(31);
var sFormName, sFormId;

	try { sFormName=oForm.name; } catch(err) { sFormName='N/A'; }
	try { sFormId=oForm.id; } catch(err) { sFormId='N/A'; }

	//create data buffer prior ajax post function
	try { dataBuffer=$(oForm).serialize(); } catch(err) { dataBuffer=''; } //compile form specific data
	dataBuffer=cs_appendString(dataBuffer, sAdditionData, '&'); //Add additional data


	//diagnostic post data dump
	if(cDiagnostic_EnableDynaFnPostDataDump) { alert('Form Name: ' + sFormName + ' (id: ' + sFormId + ') - action: ' + sURL + '\n\n' + dataBuffer); }


	new Ajax.Request(postData, {
		asynchronous: bASYNC,
		method: 'post',
		parameters: dataBuffer,
		onSuccess: function(transport) {
			postResponse=transport.responseText.split(cUnitSeperator);	 //the application page call was successful
			for(var i=0; i<postResponse.length; i++) {
				switch(i) {
					case 0: switch(postResponse[i].toLowerCase()) { case 'true': fnStatus=true; break; default: fnStatus=false; }; break; //process the first variable
					case 1: fnMessage=postResponse[i]; break; //process message
					case 2: fnAutoId=postResponse[i]; break; //process mode
					case 3: switch(postResponse[i].toLowerCase()) { case 'true': fnForceClose=true; break; default: fnForceClose=false; }; break; //process forceclose
				}
			}
		},
		onFailure: function(transport) { alert(transport.responseText); alert('Warning: DynaFN SSI service ' + sURL + ' failed'); } //the application page call was unsuccessful
	} );
		
	return{ status: fnStatus, message: fnMessage, autoid: fnAutoId, forceclose: fnForceClose };
}


function private_executeFunction_SimpleVariableTriplePair(sURL, sLabel1, vValue1, sLabel2, vValue2, sLabel3, vValue3, sWindowReference) {
	//this function is a wrapper for the function private_executeFunction_SSI - it is configured to pass two variables and only return an id
	var dynaCall, lId = -1, bridgeData;

	bridgeData = sLabel1 + '=' + escape(vValue1) + '&' +
						sLabel2 + '=' + escape(vValue2) + '&' +
						sLabel3 + '=' + escape(vValue3);

	dynaCall = private_executeFunction_SSI(null, sURL, bridgeData, false); //execute a syncronised function
	switch (dynaCall.status) {
		case true: //dynafunction completed okay
			setWindowStatus(sWindowReference, 'Status: MyJAXOS data-triple post successful; ' + dynaCall.message);
			try { lId = dynaCall.autoid; } catch (err) { }
			break;
		default: //dynafunction failed
			setWindowStatus(sWindowReference, 'Status: MyJAXOS data-triple post failed; ' + dynaCall.message);
			alert('MyJAXOS Unique function failed: ' + dynaCall.message + ', Id: ' + dynaCall.autoid);
			break;
	}
	return (lId);
}


function private_executeFunction_PostForm(oObject, sForm, sWindowReference, bCloseOnSuccess, sAutoIdUpdateElement) {
//this function is a wrapper for the function private_executeFunction_SSI - it is used to return an autoid
var dynaCall, oForm=document.getElementById(sForm), oActionURL, sAdditionData='', oAutoId, lAutoId=-1;
	if(oForm) {
		oActionURL=cs_splitString(oForm.action, '/'); //this is a firefox fix to avoid the addition of http://
		dynaCall=private_executeFunction_SSI(oForm, oActionURL.string[oActionURL.elements], sAdditionData, false); //execute a syncronised function
		switch(dynaCall.status) {
			case true: //dynafunction completed okay
				setWindowStatus(sWindowReference, 'Status: MyJAXOS post function successful; ' + dynaCall.message);
				try { oAutoId=document.getElementById(sAutoIdUpdateElement); } catch(err) {}
				try { if(oAutoId) { lAutoId=dynaCall.autoid; oAutoId.value=lAutoId; }} catch(err) {}
				if(bCloseOnSuccess) { dynaFNEventClose(sWindowReference);} else {if(dynaCall.forceclose) {dynaFNEventClose(sWindowReference);} else {oObject.disabled=true;}} //autoclose if update was successful
				break;
				
			default: //dynafunction failed
				setWindowStatus(sWindowReference, 'Status: MyJAXOS post function failed; ' + dynaCall.message);
				alert('MyJAXOS Post function failed: ' + dynaCall.message + ', AutoId: ' + dynaCall.autoid);				
				break;
		}
	}
	return(lAutoId);
}

function private_executeFunction_PostDataPair(sObject1, sObject2, sURL, sWindowReference) {
//this function is a wrapper for the function private_executeFunction_SSI - it is configured to post two elements and return an id
var dynaCall, lId=-1, bridgeData;

	bridgeData=	sObject1 + '=' + escape(document.getElementById(sObject1).value) + '&' +
						sObject2 + '=' + escape(document.getElementById(sObject2).value);

	dynaCall=private_executeFunction_SSI(null, sURL, bridgeData, false); //execute a syncronised function
	switch(dynaCall.status) {
		case true: //dynafunction completed okay
			setWindowStatus(sWindowReference, 'Status: MyJAXOS data-pair post successful; ' + dynaCall.message);
			try { lId=dynaCall.autoid; } catch(err) {}
			break;
		default: //dynafunction failed
			setWindowStatus(sWindowReference, 'Status: MyJAXOS data-pair post failed; ' + dynaCall.message);
			alert('MyJAXOS Unique function failed: ' + dynaCall.message + ', Id: ' + dynaCall.autoid);				
			break;
	}
	return(lId);
}


function private_executeFunction_NoVariables(sURL, sWindowReference) {
//this function is a wrapper for the function private_executeFunction_SSI - it is configured not to pass variables and only return an id
var dynaCall, lId=-1, bridgeData;

	bridgeData='';

	dynaCall=private_executeFunction_SSI(null, sURL, bridgeData, false); //execute a syncronised function
	switch(dynaCall.status) {
		case true: //dynafunction completed okay
			setWindowStatus(sWindowReference, 'Status: MyJAXOS post successful; ' + dynaCall.message);
			try { lId=dynaCall.autoid; } catch(err) {}
			break;
		default: //dynafunction failed
			setWindowStatus(sWindowReference, 'Status: MyJAXOS post failed; ' + dynaCall.message);
			alert('MyJAXOS Unique function failed: ' + dynaCall.message + ', Id: ' + dynaCall.autoid);				
			break;
	}
	return(lId);
}

function private_executeFunction_AutoUpdater(sElementId, sURL, sContainer) {
//this function posts the specified form to the specified url and posts the fragment back to the container
var postData=cDynaFNFunction + sURL, postBuffer, oForm;

	oForm=document.getElementById(cs_Form(sElementId).id)

	if(oForm) { postBuffer=$(oForm).serialize(); } else { postBuffer=''; }
	postBuffer=cs_appendString(postBuffer, 'postback='+sElementId, '&')

	new Ajax.Updater(sContainer, postData, {
		method: 'post',
		parameters: postBuffer,
		evalScripts: true, 
		asynchronous: true
	} );

}
