var t; //timeout
var blnJSDebug = (blnJSDebug) ? blnJSDebug : true;
var arrFPs = [];

var isMozilla;
var objCurrentFP = null;
var strCurrentFP = "";
var overFP = false;

var onAJAXFileUploadComplete = '';
var strAJAXFileUploadPID = '';
var objCurrentAJAXRequest;

//
//	Element Positioning
//
function getBodyHeight() { return getDimensionResult (false, document.body.offsetHeight ? document.body.offsetHeight : 0, document.body.scrollHeight ? document.body.scrollHeight : 0, 0); }
function getBodyWidth() { return getDimensionResult (false, document.body.offsetWidth ? document.body.offsetWidth : 0, document.body.scrollWidth ? document.body.scrollWidth : 0, 0); }
function getWindowWidth() { return getDimensionResult (true, window.innerWidth ? window.innerWidth : 0, document.documentElement ? document.documentElement.clientWidth : 0, document.body ? document.body.clientWidth : 0); }
function getWindowHeight() { return getDimensionResult (true, window.innerHeight ? window.innerHeight : 0, document.documentElement ? document.documentElement.clientHeight : 0, document.body ? document.body.clientHeight : 0); }
function getScrollLeft() { return getDimensionResult (true, window.pageXOffset ? window.pageXOffset : 0, document.documentElement ? document.documentElement.scrollLeft : 0, document.body ? document.body.scrollLeft : 0); }
function getScrollTop() { return getDimensionResult (true, window.pageYOffset ? window.pageYOffset : 0, document.documentElement ? document.documentElement.scrollTop : 0, document.body ? document.body.scrollTop : 0); }
function getElementTop(objE) { var intT = 0; while (objE.offsetParent)	{ intT += objE.offsetTop; objE = objE.offsetParent; } return intT; }
function getElementLeft(objE) { var intL = 0; while (objE.offsetParent) { intL += objE.offsetLeft; objE = objE.offsetParent;	} return intL; }

function getDimensionResult (blnLowest, intW, intE, intB) 
{
	var intR = intW ? intW : 0;
	if (intE && (!intR || ((!blnLowest & intR < intE) || (blnLowest & intR > intE)))) {	intR = intE; }
	return intB && (!intR || ((!blnLowest & intR < intB) || (blnLowest & intR > intB))) ? intB : intR;
}

function setCenterDiv(objDiv)
{
	objDiv.style.top = getScrollTop() + (getWindowHeight() / 2) - (objDiv.offsetHeight / 2) + 'px';
	objDiv.style.left = getScrollLeft() + (getWindowWidth() / 2) - (objDiv.offsetWidth / 2) + 'px';
}

function MouseDown(e) 
{
	if (overFP)
	{
		objCurrentFP = document.getElementById(strCurrentFP);
		if (objCurrentFP)
		{
			if (isMozilla) 
			{
				X = e.layerX;
				Y = e.layerY;
				return false;
			}
			else 
			{
				objCurrentFP = objCurrentFP.style;
				X = event.offsetX;
				Y = event.offsetY;
			}
		}
	}
}

function MouseMove(e) 
{
	if (objCurrentFP) 
	{
			if (isMozilla) 
			{
					objCurrentFP.style.top = (e.pageY-Y) + 'px';
					objCurrentFP.style.left = (e.pageX-X) + 'px';
					return false;
			}
			else 
			{
					objCurrentFP.pixelLeft = event.clientX-X + document.body.scrollLeft;
					objCurrentFP.pixelTop = event.clientY-Y + document.body.scrollTop;
					return false;
			}
	}
}

function MouseUp() { objCurrentFP = null; }

//create function, it expects 2 values.
function insertAfter(objNew, objSource) 
{
	var objParent = objSource.parentNode;	//target is what you want it to go after. Look for this elements parent.
	if(objParent.lastchild == objSource)		
		objParent.appendChild(objNew); //add the newElement after the target element.
	else
		objParent.insertBefore(objNew, objSource.nextSibling); // else the target has siblings, insert the new element between the target and it's next sibling.
}

//
//	AJAX
//

var strFloatingPageTitle = '';
strFloatingPageTitle = strFloatingPageTitle + '	<table id="tblFloatingPageTitle-%FloatingPageID%" class="FloatingPageTitle" style="height: 13px; text-transform: uppercase; color: #006080; background-color: #bcd5ea; padding: 0px 0px 0px 0px;">'
strFloatingPageTitle = strFloatingPageTitle + '		<tr>'
strFloatingPageTitle = strFloatingPageTitle + '			<td onmouseover="this.style.cursor = \'move\'; overFP = true;" onmouseout="this.style.cursor = \'default\'; overFP = false;" style=" padding: 0px 0px 0px 0px;">&nbsp;%FloatingPageTitle%</td>'
strFloatingPageTitle = strFloatingPageTitle + '			<td class="FloatingPageClose" align="right" style="width: 20px; padding: 2px 0px 0px 0px;">'
strFloatingPageTitle = strFloatingPageTitle + '				<a href="javascript: hideAJAXFloatingPage(\'%FloatingPageID%\');"><img src="/di_common/images/common/close.jpg" alt="Close" height="13px" border="0" style="padding: 0px 0px 0px 0px;"></a>&nbsp;'
strFloatingPageTitle = strFloatingPageTitle + '			</td>'
strFloatingPageTitle = strFloatingPageTitle + '		</tr>'
strFloatingPageTitle = strFloatingPageTitle + '	</table>'

function loadAJAXSpecialFilter(strFilterURL, strFilterType, strFilterQuery, customFunction)
{
	AjaxRequest.get(
		{
			'url':'' + strFilterURL + '?strFilterType=' + strFilterType + '&strFilterQuery=' + strFilterQuery
			,'onLoading':function() { showLoadingDiv(); }
			,'onSuccess':function(req) { eval(customFunction) }
			,'onError':function(req) { hideLoadingDiv(); showAJAXMessage(req); }
		}
	);	

}

function loadAJAXFilter(strFilterURL, strFilterType, strSourceList, strTargetList, strDefaultItemID, strFilterQuery, intDefaultItemCount, customFunction)
{
	var objSource = document.getElementById(strSourceList);
	var objTarget = document.getElementById(strTargetList);
	strDefaultItemID = (strDefaultItemID) ? strDefaultItemID : '-99';
		
	if (objTarget && objSource)
	{		
		intSourceID = objSource.value;
		strFilterQuery = (strFilterQuery) ? strFilterQuery : '';
		if (strTargetList.indexOf('ID') != -1 && objTarget.options)
			objTarget.options.length = (intDefaultItemCount) ? intDefaultItemCount : 1;	
		
		if 	(intSourceID == '' && strFilterQuery == '' && objTarget != objSource)
			objTarget.disabled = true; 
		else
		{ 
			AjaxRequest.get(
				{
					'url':'' + strFilterURL + '?strFilterType=' + strFilterType + '&strFilterQuery=' + strFilterQuery + '&intFilterID=' + intSourceID
					,'onLoading':function() { showLoadingDiv(); }
					,'onSuccess':function(req) { populateAJAXFilter(req, strTargetList, strDefaultItemID, customFunction); hideLoadingDiv(); }
					,'onError':function(req) { hideLoadingDiv(); showAJAXMessage(req); }
				}
			);	
		} 
	}
}
		
function populateAJAXFilter(objRequest, strTargetList, strDefaultItemID, customFunction)
{
	filterData = objRequest.responseText; //read response data 
	var objTarget = document.getElementById(strTargetList);
	if (!filterData || !objTarget) return;

	objTarget.disabled = false; 

	var intCount = (strTargetList.indexOf('ID') != -1) ? objTarget.options.length : 0;
	var lstItems = filterData.split(String.fromCharCode(25)); 
	for(var i = 0; i < lstItems.length; i++)
	{
		var lstValues = lstItems[i].split(String.fromCharCode(26)); 
		if (strTargetList.indexOf('ID') == -1)
		{
			objTarget.value = lstValues[1];
		}
		else
		{
			objTarget.options[intCount] = new Option(lstValues[1], lstValues[0]);
			if (lstValues[0].toString() == strDefaultItemID || (strDefaultItemID == '-100'))
				objTarget.selectedIndex = intCount;
		}
		intCount++;
	}
	
	eval(customFunction);
} 	

function loadAJAXMenu(strMenuURL, strMenuType, strSourceDiv, intTargetLevel, intFilterItemID, strFilterQuery, customFunction)
{
	intFilterItemID = (intFilterItemID) ? intFilterItemID : '';
	strFilterQuery = (strFilterQuery) ? strFilterQuery : '';
	customFunction = (customFunction) ? customFunction : '';
	
	var strTargetDiv = strMenuType + '' + intFilterItemID;
	var objSource = document.getElementById(strSourceDiv);
	var objTarget = document.getElementById(strTargetDiv);
	if (objTarget && objTarget.style.display == 'block')
	{		
		objTarget.innerHTML = ''; 
		objTarget.style.display = 'none'; 
		return;
	}
	else if (!objTarget)
	{
		var objNewMenu = document.createElement("div");
		objNewMenu.id = strTargetDiv;
		insertAfter(objNewMenu, objSource);
		objTarget = document.getElementById(strTargetDiv);
	}
	
	AjaxRequest.get(
			{
				'url':'' + strMenuURL + '?strMenuType=' + strMenuType + '&strFilterQuery=' + strFilterQuery + '&intFilterItemID=' + intFilterItemID
				,'onLoading':function() { }
				,'onSuccess':function(req) { populateAJAXMenu(req, objTarget, intTargetLevel, customFunction); }
				,'onError':function(req) { showAJAXMessage(req); }
			}
		);	
	
}
		
function populateAJAXMenu(objRequest, objTarget, intTargetLevel, customFunction)
{
	filterData = objRequest.responseText; //read response data 
	if (!filterData) return;

	var strMenu = '';
	var lstItems = filterData.split(String.fromCharCode(25)); 
	for(var i = 0; i < lstItems.length; i++)
	{
		var lstValues = lstItems[i].split(String.fromCharCode(26)); 
		strMenu = strMenu + '<div class="navlevel' + intTargetLevel + '" id="' + lstValues[0] + '"><a href="' + lstValues[1] + '">' + lstValues[2] + '</a></div>'
	}
	
	objTarget.innerHTML = strMenu;
	objTarget.style.display = 'block';
	
	eval(customFunction);
} 	

function loadAJAXFloatingPage(strContentTitle, strContentURL, strBackgroundColour, objSource, blnRelativePos, intPaddingTop, intPaddingLeft, customFunction)
{ 
	isMozilla = (document.all) ? 0 : 1;

	if (isMozilla) 
		document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);

	document.onmousedown = MouseDown;
	document.onmousemove = MouseMove;
	document.onmouseup = MouseUp;
	
	AjaxRequest.get(
		{
			'url':'' + strContentURL
			,'onLoading':function() { showLoadingDiv(); }
			,'onSuccess':function(req) { hideLoadingDiv(); populateAJAXFloatingPage('', req, strContentTitle, strBackgroundColour, objSource, true, blnRelativePos, intPaddingTop, intPaddingLeft, ''); eval(customFunction); }
			,'onError':function(req) { hideLoadingDiv(); showAJAXMessage(req); }
		}
	);	
	
} 

function loadAJAXSearch(strTargetFPID, strContentTitle, strContentURL, strBackgroundColour, objSource, blnRelativePos, intPaddingTop, intPaddingLeft, customFunction)
{ 
	isMozilla = (document.all) ? 0 : 1;

	if (isMozilla) 
		document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);

	document.onmousedown = MouseDown;
	document.onmousemove = MouseMove;
	document.onmouseup = MouseUp;

	AjaxRequest.get(
		{
			'url':'' + strContentURL
			,'onLoading':function() { }
			,'onSuccess':function(req) { populateAJAXFloatingPage(strTargetFPID, req, strContentTitle, strBackgroundColour, objSource, false, blnRelativePos, intPaddingTop, intPaddingLeft, ''); eval(customFunction); }
			,'onError':function(req) { showAJAXMessage(req); }
		}
	);	
	
} 

function populateAJAXFloatingPage(strTargetFPID, objRequest, strContentTitle, strBackgroundColour, objSource, blnDisableSource, blnRelativePos, intPaddingTop, intPaddingLeft, customFunction)
{
	customFunction = (customFunction) ? customFunction : '';

	var strContentData = objRequest.responseText; //read response data 
	if (objRequest.status == '500')
	{
		var intErrorDetailsPos = strRequestContent.indexOf('<div style="width: 500px;" id="divErrorDetails">');
		if (intErrorDetailsPos != -1)
			strContentData = strRequestContent.substring(intErrorDetailsPos, strRequestContent.indexOf('</div>', intErrorDetailsPos) + 6);
	}
	
	if (strContentData)
	{
		if (strTargetFPID == '')
			intFPID = objRequest.parameters["AjaxRequestUniqueId"];
		else
			intFPID = strTargetFPID;

		eval(customFunction);	
					
		objDiv = document.getElementById('divFloatingPage-' + intFPID);
		if (!objDiv)
		{
			arrFPs.push(intFPID);
			
			if (blnDisableSource)
				showDisabledMask();	
			
			var objDiv = document.getElementById('divGenericFloatingPage').cloneNode(true);
			objDiv.setAttribute('id', 'divFloatingPage-' + intFPID);
			document.body.appendChild(objDiv);
		}
		else if (blnDisableSource)
			showDisabledMask();	
		
		
		strCurrentFP = objDiv.id;

		strContent = ((blnRelativePos) ? '' : strFloatingPageTitle.replace(/%FloatingPageTitle%/g, strContentTitle)) + '<div id="divFloatingPageContent-' + intFPID + '">' + strContentData + '</div>';
		strContent = strContent.replace(/%FloatingPageID%/g, intFPID);

		objDiv.innerHTML = strContent;

		updateAJAXFloatingPagePosition(intFPID, blnRelativePos, objSource, intPaddingTop, intPaddingLeft);
			
		objDiv.style.backgroundColor = (strBackgroundColour == '') ? '#f3f3f3' : strBackgroundColour;
		objDiv.style.visibility = 'visible';	
		objDiv.className = objDiv.className + ' Enabled';			
	}
} 	

function updateAJAXFloatingPagePosition(intFPID, blnRelativePos, objSource, intPaddingTop, intPaddingLeft)
{
	var objDiv = document.getElementById('divFloatingPage-' + intFPID);
	if (objDiv.offsetHeight > (getWindowHeight() - 100))
	{
		var objFPContentDiv = document.getElementById('divFloatingPageContent-' + intFPID);
		objFPContentDiv.style.width = objDiv.offsetWidth;
		objFPContentDiv.style.height = (getWindowHeight() - 100);
		objFPContentDiv.style.overflow = 'auto';
	}

	if (!blnRelativePos)
	{
		document.getElementById('tblFloatingPageTitle-' + intFPID).style.width = objDiv.offsetWidth;
	}
	
	if (objSource && blnRelativePos)
	{
		objDiv.style.top = getElementTop(objSource) + ((intPaddingTop) ? intPaddingTop : 0);
		objDiv.style.left = getElementLeft(objSource) + ((intPaddingLeft) ? intPaddingLeft : 0);
	}
	else
	{
		setCenterDiv(objDiv);
	}
}

function hideAJAXFloatingPage(intFPID)
{ 
	var objDiv = document.getElementById('divFloatingPage-' + intFPID);
	if (objDiv)
	{
		strCurrentFP = objDiv.id;
		hideLoadingDiv();
		document.body.removeChild(objDiv);
		arrFPs.pop();
		hideDisabledMask();
	}
	clearTimeout();
} 

function executeAJAXPage(strContentURL, customFunction)
{ 
	customFunction = (customFunction) ? customFunction : '';
	AjaxRequest.get(
		{
			'url':'' + strContentURL
			,'onLoading':function() { }
			,'onSuccess':function(req) { showAJAXMessage(req); eval(customFunction); return true; }
			,'onError':function(req) { showAJAXMessage(req); }
		}
	);	
} 

function loadAJAXContent(strContentDiv, strContentURL, customFunction)
{ 

	var objDiv = document.getElementById(strContentDiv);
	if (objDiv)
	{
		if (strContentURL != '')
		{
			AjaxRequest.get(
				{
					'url':'' + strContentURL
					,'onLoading':function() { showLoadingDiv(); }
					,'onSuccess':function(req) { populateAJAXContent(req, strContentDiv, customFunction); }
					,'onError':function(req) { hideLoadingDiv(); showAJAXMessage(req); }
				}
			);	
		}
		else
		{
			eval(customFunction);
		}
	}
} 

function populateAJAXContent(objRequest, strContentDiv, customFunction)
{
	
	var objDiv = document.getElementById(strContentDiv);
	var strContentData = objRequest.responseText; //read response data 
	if (strContentData && objDiv)
	{
		objDiv.innerHTML = strContentData;
		objDiv.style.display = 'block'; 

		eval(customFunction);
	}

	hideLoadingDiv();
} 	

function submitAJAXContent(objForm, strContentDiv, strContentURL, customFunction, blnSubmitAJAXFile, strItemID) 
{
	if (!validateFields(objForm))
		return false;

	blnSubmitAJAXFile = (blnSubmitAJAXFile == null) ? false : blnSubmitAJAXFile;
	
	var status = AjaxRequest.submit(
		objForm
		,{
			'onLoading':function() { showLoadingDiv(false); }
			,'onSuccess':function(req) { if (blnSubmitAJAXFile) { objCurrentAJAXRequest = req; onAJAXFileUploadComplete = customFunction; submitAJAXFile(objForm, strItemID, '', req.responseText); } else { if (strContentDiv != '') { populateAJAXContent(req, strContentDiv, ''); } else if (strContentURL != '') { loadAJAXContent(strContentDiv, strContentURL); } eval(customFunction); hideLoadingDiv(); showAJAXMessage(req); } }
			,'onError':function(req) { hideLoadingDiv(); showAJAXMessage(req); }
		}
	);
	return status;
}

function submitAJAXFile(objForm, strItemID, intItemID, strResponseText)
{		
	if (intItemID == '')
		intItemID = getQueryStringValue(strResponseText, strItemID);

	if (strItemID == 'intFileID')
	{
		intPosItem = strResponseText.indexOf(strItemID);
		if (intPosItem == -1)	return;	else intPosStart = intPosItem + strItemID.length + 1;
						
		intPosNextItem = strResponseText.indexOf('&', intPosItem);
		intPosEnd = (intPosNextItem != -1 ? intPosNextItem : strResponseText.length);
		
		intItemID = strResponseText.substring(intPosStart, intPosEnd);
	}
		
	objForm.encoding = 'multipart/form-data';
	if (objForm.elements['PID'])
		strAJAXFileUploadPID = objForm.elements['PID'].value;
		
	intPosItem = objForm.action.indexOf('?');
	if (intPosItem == -1)	
		objForm.action = objForm.action + '?strAction=UPLOAD&PID=' + strAJAXFileUploadPID;
	else 
		objForm.action = objForm.action + '&strAction=UPLOAD&PID=' + strAJAXFileUploadPID;

	objForm.elements['' + strItemID].value = intItemID;

	AIM.submit(objForm, {'onStart' : startAJAXUpload, 'onComplete' : finishAJAXUpload});
	objForm.submit();
}

function showAJAXFileUploadProgress()
{
	document.getElementById('divFileUploadStatus').style.display = 'block';
	document.getElementById('divFileUploadForm').style.display = 'none';
}

function startAJAXUpload() { showAJAXFileUploadProgress(); return true; }
function finishAJAXUpload(response) {	req = objCurrentAJAXRequest; eval(onAJAXFileUploadComplete); hideLoadingDiv(); showAJAXMessage(objCurrentAJAXRequest); objCurrentAJAXRequest = null; onAJAXFileUploadComplete = ''; return true; }

function showAJAXMessage(objRequest, strContent)
{
	strRequestContent = (objRequest == '') ? strContent : objRequest.responseText;
	strRequestStatus = (objRequest == '') ? '200' : objRequest.status;

	if (strRequestStatus == '500')
		populateAJAXFloatingPage('', objRequest, '', '#FFFFFF', null, true, false, 0, 0, '');
	else if (strRequestContent && strRequestContent.indexOf('strAction=MESSAGE') != -1)
		loadAJAXFloatingPage('', '/di_common/page/message.asp?' + strRequestContent, '#FFFFFF', null, false, 0, 0, 'document.getElementById(\'btnMessageClose\').focus(); fadeFloatingPageStart(intFPID, 150, 0, 3000);');		
		
}

//
//	Content Management
//


function confirmDelete(strType)
{
	return window.confirm('Are you sure you wish to delete this ' + strType + '?');
}	

function updateSelectList(strFormSelectListID, intTargetValue)
{
	objSelectList = document.getElementById(strFormSelectListID);
	if (objSelectList)
	{
		for (i=0; i < objSelectList.options.length; i++)
		{
			if (objSelectList.options[i].value == intTargetValue)
			{
				objSelectList.selectedIndex = i;
				break;
			}
		}
	}
}

function editSection(strSection, strEditLink, strViewLink, strAction, intOptionalSubSection)
{
	var objLink = document.getElementById(strSection);
	strEditLink = (strEditLink == undefined || strEditLink == '') ? 'edit' : strEditLink;
	strViewLink = (strViewLink == undefined || strViewLink == '') ? 'view' : strViewLink;				
	if ((strAction == undefined || strAction == '') && objLink != null)
		strAction = objLink.innerHTML;

	document.getElementById(strSection + 'View').style.display = (strAction == strViewLink || strAction == 'View' || (strAction == 'Toggle' && document.getElementById(strSection + 'View').style.display == 'none')) ? 'block' : 'none';
	document.getElementById(strSection + 'Edit').style.display = (strAction == strViewLink || strAction == 'View' || (strAction == 'Toggle' && document.getElementById(strSection + 'Edit').style.display == 'block')) ? 'none' : 'block';
	
	if (objLink != null)	
	{
		objLinks = document.getElementsByTagName("a");
		for (i=0; i < objLinks.length; i++)
		{
			tmpLink = objLinks[i];
			if (tmpLink.id == strSection)
			{
			  if (strAction == 'Toggle' && tmpLink.innerHTML.indexOf('<IMG') != -1)
				{
					tmpLink.innerHTML = (tmpLink.innerHTML.indexOf(strViewLink) != -1) ? tmpLink.innerHTML.replace(strViewLink, strEditLink) : tmpLink.innerHTML.replace(strEditLink, strViewLink);
				}
				else
					tmpLink.innerHTML = (strAction == strViewLink || strAction == 'View') ? strEditLink : strViewLink;
			}
		}
	}
	
					
	var frm = document.getElementById('frm' + strSection);
	if (typeof frm != 'undefined' && frm != null)
	{
		var submitButton = frm.elements['btnSubmit'];
		if (submitButton)
		{
			var objID = frm.elements['int' + strSection.substring(7, strSection.length) + 'ID'];
			submitButton.value = (objID && objID.value == '') ? submitButton.value.replace('Update', 'Add') : submitButton.value.replace('Add', 'Update');
			if (submitButton.value.indexOf('Add') != -1)
				frm.reset();
		}
	}
		
	if (typeof intOptionalSubSection != 'undefined')
	{
		var arrDivs = document.getElementsByTagName('div');
		for (var i = arrDivs.length; i > 0; i--) // loop through the elements in reverse order for speed
		{
			var div = arrDivs[i - 1];
			var idLen = (strSection + 'Edit').length;
			if (div.id.indexOf(strSection + 'Edit') != -1 && (idLen < div.id.length))
			{
				strDivID = div.id.substring(idLen, div.id.length);
				div.style.display = (strDivID == intOptionalSubSection) ? 'block' : 'none';
			}
		}
	}				
		
}			

function setFrameHeight(strFrame, intHeight, intMaxHeight, intWidth, intMaxWidth)
{
	objFrame = document.getElementById(strFrame)
	intHeight = (intHeight > intMaxHeight) ? intMaxHeight : intHeight;
	if (intWidth != null)
		intWidth = (intWidth > intMaxWidth) ? intMaxWidth : intWidth;
	if (objFrame)
	{
		objFrame.style.height = intHeight + 'px';
		if (intWidth != null)
			objFrame.style.width = intWidth + 'px';
		objFrame.scrolling = (intHeight > intMaxHeight) ? 'yes' : 'no';
	}
}

//
//	DIVs
//

function showDisabledMask(blnNewFP)
{
	blnNewFP = (blnNewFP == undefined) ? true : blnNewFP;
	if (arrFPs.length > 1)
	{
		var objFPDiv = document.getElementById('divFloatingPage-' + arrFPs[arrFPs.length - (blnNewFP ? 2 : 1)]);
		var objFPDisabledDiv = document.getElementById('divPageDisabled-' + arrFPs[arrFPs.length - (blnNewFP ? 2 : 1)]);
		if (objFPDiv && !objFPDisabledDiv)
		{
			objFPDiv.className = objFPDiv.className.replace('Enabled', 'Disabled');
			
			var objDisabledDiv = document.getElementById('divPageDisabled').cloneNode(true);
			objDisabledDiv.id = 'divPageDisabled-' + arrFPs[arrFPs.length - (blnNewFP ? 2 : 1)];
			objDisabledDiv.style.top = objFPDiv.style.top;
			objDisabledDiv.style.left = objFPDiv.style.left;
			objDisabledDiv.style.width = objFPDiv.offsetWidth;
			objDisabledDiv.style.height = objFPDiv.offsetHeight;
			objDisabledDiv.style.display = 'block';
			document.body.appendChild(objDisabledDiv);
		}
	}
	else
	{
		var objDiv = document.getElementById('divPageDisabled');
		if (objDiv)
		{
			objDiv.style.width = getBodyWidth();
			objDiv.style.height = getBodyHeight();
			objDiv.style.display = 'block';
			document.body.className = 'Disabled';	
		}
	}
}

function hideDisabledMask(intFPID)
{
	if (arrFPs.length > 0)
	{
		
		var objFPDiv = document.getElementById('divFloatingPage-' + arrFPs[arrFPs.length - 1]);
		var objFPDisabledDiv = document.getElementById('divPageDisabled-' + arrFPs[arrFPs.length - 1]);
				
		if (objFPDisabledDiv)
			document.body.removeChild(objFPDisabledDiv);
			
		if (objFPDiv)
		{			
			objFPDiv.className = objFPDiv.className.replace('Disabled', 'Enabled');		
			strCurrentFP = objFPDiv.id;
		}		
	}
	else
	{
		var objDiv = document.getElementById('divPageDisabled');
		if (objDiv)
		{
			strCurrentFP = '';
			objDiv.style.display = 'none';
			document.body.className = '';		
		}
	}
}


function showLoadingDiv(blnNewFP) 
{	
	clearTimeout(t);
	var objDiv = document.getElementById('divLoading');
	if (objDiv && objDiv.style.visibility == 'hidden')
	{
		//t = setTimeout('hideLoadingDiv()',10000);	
		showDisabledMask(blnNewFP);
		
		objDiv.style.visibility = 'visible';		
		objDiv.innerHTML = '<img src="/di_common/images/common/loading.gif" />';		
		setCenterDiv(objDiv);				
	}
}		

function hideLoadingDiv() 
{
	clearTimeout(t);
	var objDiv = document.getElementById('divLoading');
	if (objDiv)
	{
		hideDisabledMask();
		objDiv.innerHTML = '';		
		objDiv.style.visibility = 'hidden';		
	}
}	

function fadeFloatingPageStart(intFPID, opacStart, opacEnd, millisec) 
{
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) 
	{
		for(i = opacStart; i >= opacEnd; i--) 
		{
			setTimeout("fadeFloatingPage(" + i + ", '" + intFPID + "', " + opacEnd + ")", (timer * speed));
			timer++;
		}
	}
	else if(opacStart < opacEnd) 
	{
		for(i = opacStart; i <= opacEnd; i++)
		{
			setTimeout("fadeFloatingPage(" + i + ", '" + intFPID + "', " + opacEnd + ")", (timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function fadeFloatingPage(opacity, intFPID, opacEnd) 
{
	var objPage = document.getElementById('divFloatingPage-' + intFPID); 
	if (objPage)
	{
		objPage.style.opacity = (opacity / 100);
		objPage.style.MozOpacity = (opacity / 100);
		objPage.style.KhtmlOpacity = (opacity / 100);
		objPage.style.filter = "alpha(opacity=" + opacity + ")";
	}
	
	if (opacity == opacEnd)
	{
		hideAJAXFloatingPage(intFPID);
	}
}

//
//	MISC
//

function getQueryStringValue(strQS, strID)
{
	var intPosItem = strQS.indexOf(strID);
	if (intPosItem == -1)	return ''; else var intPosStart = intPosItem + strID.length + 1;
					
	var intPosNextItem = strQS.indexOf('&', intPosItem);
	var intPosEnd = (intPosNextItem != -1 ? intPosNextItem : strQS.length);
	
	return strQS.substring(intPosStart, intPosEnd);
}

function padString(strInput, strChar, intLength, intPos)
{
	var strOutput = strInput;
	while (strOutput.length < intLength)
	{
		if (intPos == 0)
			strOutput = strChar + strOutput;
		else
			strOutput = strOutput + strChar;
	}
	return strOutput;
}

function updateMask(strField, blnChecked, intSelectedMask)
{
	var intMask = parseInt(document.getElementById(strField).value);
	document.getElementById(strField).value = (blnChecked) ? intMask + parseInt(intSelectedMask) : intMask - parseInt(intSelectedMask);		
}		
	


