		
	var strSCPMContentDivPrefix = 'SCPM';
	var strSCPMContentHomeURL = '/';
	var strSCPMContentViewURL = '/content/view/';
	var strSCPMContentEditURL = '/content/edit/';

	var strSCPMAdminContentDivPrefix = 'SCPMAdmin';
	var strSCPMAdminContentViewURL = '/admin/content/view/';
	var strSCPMAdminContentEditURL = '/admin/content/edit/';
	
	var strSCPMReportContentDivPrefix = 'SCPMReport';
	var strSCPMReportContentViewURL = '/report/content/view/';
	var strSCPMReportContentEditURL = '/report/content/edit/';
	
	function manageSCPM(strSection, strAction, strQueryString, intEntryID, customFunction)
	{
		strSection = (strSection) ? strSection : '';
		strQueryString = (strQueryString) ? strQueryString : '';
		intEntryID = (intEntryID) ? intEntryID : '';
		customFunction = (customFunction) ? customFunction : '';
		
		strQueryString = strQueryString + '&strSection=' + strSection;
		if (strAction == 'LOGIN')
			loadAJAXFloatingPage('', strSCPMContentEditURL + 'login.asp?strAction=EDIT' + strQueryString, '#F3F3F3', null, false, 20, 0, '');
		else if (strAction == 'LOGIN_DONE')
			document.location.href = '/?' + strQueryString;
		else if (strAction == 'EDIT_POPUP')
			loadAJAXFloatingPage('', strSCPMContentEditURL + strSection.toLowerCase() + '.asp?strAction=' + strAction + '&strSection=' + strSection + ((strQueryString && strQueryString != '') ? strQueryString : ''), '#f3f3f3', this, false, 0, 0, customFunction);
		else if (strAction == 'EDIT_PAGE')
			loadAJAXContent('div' + strSCPMContentDivPrefix + strSection, strSCPMContentEditURL + strSection.toLowerCase() + '.asp?strAction=' + strAction + strQueryString, customFunction);			
		else if (strAction == 'VIEW')
			loadAJAXContent('div' + strSCPMContentDivPrefix + strSection, strSCPMContentViewURL + strSection.toLowerCase() + '.asp?strAction=' + strAction + strQueryString, customFunction);			
		else if (strAction == 'DELETE_COMMENT')
		{
			executeAJAXPage(strSCPMContentEditURL + 'comment.asp?strAction=' + strAction + '&intCommentID=' + intEntryID);					
			objForm = document.getElementById('div' + strSCPMReportContentDivPrefix + strSection);			
			if (objForm)
				manageSCPMReport(strSection, 'LIST', strQueryString);
		}
	}
	
	function manageSCPMReport(strSection, strAction, strQueryString, intEntryID, customFunction)
	{
		strSection = (strSection) ? strSection : '';
		strQueryString = (strQueryString) ? strQueryString : '';
		intEntryID = (intEntryID) ? intEntryID : '';
		customFunction = (customFunction) ? customFunction : '';
				
		if (strQueryString == '' && strSection.indexOf('.asp') == -1)
		{
			objForm = document.getElementById('frm' + strSCPMReportContentDivPrefix + strSection);			
			if (objForm)
			{
				lstElements = objForm.elements;
				strQueryString = '';
				strQueryString = strQueryString + '&intEntryID=' + intEntryID;
				strQueryString = strQueryString + '&intTempFPID=' + lstElements['intTempFPID'].value;;
				strQueryString = strQueryString + '&strSection=' + lstElements['strSection'].value;
				strQueryString = strQueryString + '&strFilterType=' + lstElements['strFilterType'].value;
				strQueryString = strQueryString + '&strFilterTargetPage=' + ((lstElements['strNewFilterTargetPage'] != undefined) ? lstElements['strNewFilterTargetPage'].value : lstElements['strFilterTargetPage'].value);
				strQueryString = strQueryString + '&blnShowFilter=' + lstElements['blnShowFilter'].value;
				
				strQueryString = strQueryString + '&dteFilterStart=' + ((lstElements['dteNewFilterStart'] != undefined) ? lstElements['dteNewFilterStart'].value : lstElements['dteFilterStart'].value);
				strQueryString = strQueryString + '&dteFilterEnd=' + ((lstElements['dteNewFilterEnd'] != undefined) ? lstElements['dteNewFilterEnd'].value : lstElements['dteFilterEnd'].value);

				strQueryString = strQueryString + '&strFilterSortField=' + ((lstElements['strNewFilterSortField'] != undefined) ? lstElements['strNewFilterSortField'].value : lstElements['strFilterSortField'].value);
				strQueryString = strQueryString + '&strFilterSortDirection=' + ((lstElements['strNewFilterSortDirection'] != undefined) ? lstElements['strNewFilterSortDirection'].value : lstElements['strFilterSortDirection'].value);
				strQueryString = strQueryString + '&rpp=' + lstElements['rpp'].value;
				strQueryString = strQueryString + '&p=' + lstElements['p'].value;
			}
			else
				strQueryString = strQueryString + '&strSection=' + strSection;
		}
		else
			strQueryString = strQueryString + '&strSection=' + strSection;

		if (strAction == 'FILTER')
			loadAJAXFloatingPage('', strSCPMReportContentEditURL + 'scpmfilter.asp?strAction=' + strAction + strQueryString, '#FFFFFF', null, false, 0, 0, '');
		else if (strAction == 'LIST')
		{
			if (strSection.indexOf('.asp') != -1)
				document.location.href = strSection;
			else
				loadAJAXContent('div' + strSCPMReportContentDivPrefix + strSection, strSCPMReportContentViewURL + 'commentlist.asp?strAction=' + strQueryString);			
		}
	}	

	function navigateSCPMReport(strSection, strAction, rpp, p)
	{		
		objForm = document.getElementById('frm' + strSCPMReportContentDivPrefix + strSection);
		lstElements = objForm.elements;
		
		lstElements['rpp'].value = rpp;
		lstElements['p'].value = p;	

		manageSCPMReport(strSection, strAction);
	}		
	

	function loadSCPMAdminContent(strSection, strAction, strQueryString, customFunction)
	{
		loadAJAXContent('div' + strSCPMAdminContentDivPrefix + strSection, strSCPMAdminContentViewURL + strSection.toLowerCase() + '.asp?strAction=' + strAction + ((strQueryString && strQueryString != '') ? strQueryString : ''), customFunction);
	}
	
	function manageSCPMAdmin(strSection, strAction, strQueryString, strItem, intItemID, customFunction)
	{
		strQueryString = (strQueryString) ? strQueryString : '';
		strItem = (strItem) ? strItem : '';
		intItemID = (intItemID) ? intItemID : '';
		customFunction = (customFunction) ? customFunction : '';

		if (strAction.indexOf('DELETE') != -1)
			executeAJAXPage(strSCPMAdminContentEditURL + strSection.toLowerCase() + '.asp?strAction=' + strAction + ((strItem != '') ? '&' + strItem + '=' + intItemID : '') + ((strQueryString && strQueryString != '') ? strQueryString : ''), 'loadSCPMAdminContent(\'' + strSection + '\', \'VIEW\', \'' + strQueryString + '\', \'' + customFunction + '\');');					
		else if (strAction.indexOf('EDIT') != -1)
			loadAJAXFloatingPage('', strSCPMAdminContentEditURL + strSection.toLowerCase() + '.asp?strAction=' + strAction + '&strSection=' + strSection + ((strItem != '') ? '&' + strItem + '=' + intItemID : '') + ((strQueryString && strQueryString != '') ? strQueryString : ''), '#f3f3f3', this, false, 0, 0, customFunction);
		else if (strAction == 'VIEW')
			loadSCPMAdminContent(strSection, strAction, strQueryString, customFunction);
	}
	
	function getRadioValue(objForm, strField)
	{
		for (var i=0; i < objForm.elements[strField].length; i++)
		{
			if (objForm.elements[strField][i].checked)
				return objForm.elements[strField][i].value;
		}
		return -1;
	}
	
	function navigateCalendar(intYear, intMonth)
	{
		manageSCPM('Calendar', 'VIEW', '&y=' + intYear + '&m=' + intMonth + '');
		manageSCPM('Job', 'VIEW', '&intJobID=-1');		
	}

	function navigateJobs(strSection, intYear, intMonth, rpp, p, strQueryString)
	{		
		manageSCPM('Jobs', 'VIEW_JOBS', '&y=' + intYear + '&m=' + intMonth + '&rpp=' + rpp + '&p=' + p + strQueryString);	
	}	
	
	function toggleJobOverview(blnShow, intJobID)
	{
		lnkJobShow = document.getElementById('lnkJobShow' + intJobID);
		lnkJobHide = document.getElementById('lnkJobHide' + intJobID);
		tblJob = document.getElementById('tblJob' + intJobID);
		
		lnkJobShow.style.display = (blnShow) ? 'none' : 'block';
		tblJob.style.display = (blnShow) ? 'block' : 'none';	
		
		//objJobsNavTop.style.visibility = (objJobsDiv.scrollTop > 0) ? 'visible' : 'hidden';
		//objJobsNavBottom.style.visibility = (objJobsDiv.scrollTop <= objJobsDiv.scrollHeight - 310) ? 'visible' : 'hidden';
	}

	function toggleJobOverviewAll(blnShow)
	{
		var blnShowAll = false;
		var lnkJobShowAll;
		//return;
		lnkJobShowAll = document.getElementById('lnkJobShowAll');
		blnShowAll = (lnkJobShowAll.innerHTML == 'expand all') ? true : false;
		
		lnkJobShowAll.innerHTML = (blnShowAll) ? 'hide all' : 'expand all';
	
		var links = document.getElementsByTagName("a");	
		for (l = 0; l < links.length; l++) 
		{
			if (links[l].name[0] == 'E')
				toggleJobOverview(blnShowAll, links[l].name.substring(1, links[l].name.length));				
		}
		
		
		//objJobsNavTop.style.visibility = (objJobsDiv.scrollTop > 0) ? 'visible' : 'hidden';
		//objJobsNavBottom.style.visibility = (objJobsDiv.scrollTop <= objJobsDiv.scrollHeight - 310) ? 'visible' : 'hidden';
	}
	
	function updateJobsNav()
	{
		objJobsDiv = document.getElementById('divViewJobs');
		objJobsNavTop = document.getElementById('divJobsNavTop');
		objJobsNavBottom = document.getElementById('divJobsNavBottom');
		//objJobsNavTop.style.visibility = (objJobsDiv.scrollHeight > 300) ? 'visible' : 'hidden';
		objJobsNavBottom.style.visibility = (objJobsDiv.scrollHeight > 300) ? 'visible' : 'hidden';
	}

	function clearFieldHelp(objField, strHelp)
	{
		if (objField.value == strHelp) { objField.value = ''; objField.style.color = '#000000'; }
	}
	
	function setFieldHelp(objField, strHelp)
	{
		if (objField.value == '') { objField.value = strHelp; objField.style.color = '#999999'; }
	}	
	
	var t;
	function loadAJAXSearch(strAJAXSearchURL, strAJAXSearchType, strAJAXSearchField, strAJAXSearchFilterQuery, customFunction)
	{
		clearTimeout(t);
		t = setTimeout("manageAJAXSearch('" + strAJAXSearchURL + "', '" + strAJAXSearchType + "', '" + strAJAXSearchField + "', '" + strAJAXSearchFilterQuery + "', '" + customFunction + "');",500)
	}	
					
	function manageAJAXSearch(strAJAXSearchURL, strAJAXSearchType, strAJAXSearchField, strAJAXSearchFilterQuery, customFunction)
	{		
		customFunction = (customFunction) ? customFunction : '';
	
		strAJAXSearchURL = '/scpm/includes/ajaxsearch.asp'
		
		var strSearchString = document.getElementById('str' + strAJAXSearchField + 'Dummy').value;
		var objTargetList = document.getElementById('int' + strAJAXSearchField + 'IDDummy');
		if (strSearchString.length >= 1 && objTargetList)
		{		
			strSearchString = strSearchString.replace('\'', '\'\'');
			strSearchString = strSearchString.replace('&', '%26');
			strAJAXSearchFilterQuery = strAJAXSearchFilterQuery.replace('%SS%', strSearchString);
		
			objTargetList.options.length = 0;
			AjaxRequest.get(
				{
					'url':'' + strAJAXSearchURL + '?strAJAXSearchType=' + strAJAXSearchType + '&strAJAXSearchFilterQuery=' + strAJAXSearchFilterQuery
					,'onLoading':function() { }
					,'onSuccess':function(req) { populateAJAXSearch(req, strAJAXSearchField, customFunction); }
					,'onError':function(req) { showAJAXMessage(req); }
				}
			);	
		}
	}
	
	function populateAJAXSearch(objRequest, strAJAXSearchField, customFunction)
	{
		filterData = objRequest.responseText; //read response data 
		var objTargetList = document.getElementById('int' + strAJAXSearchField + 'IDDummy');
		var objTargetListClose = document.getElementById('imgClose' + strAJAXSearchField);
		if (!filterData)
		{
			document.getElementById('str' + strAJAXSearchField + 'Dummy').style.backgroundColor = '#ffcccc';
			return;
		}
		else
		{	
			document.getElementById('str' + strAJAXSearchField + 'Dummy').style.backgroundColor = '#ffffff';			
			objTargetList.disabled = false; 
		
			objTargetList.options.length = 0;
			var lstItems = filterData.split(String.fromCharCode(25)); 
			var intCount = 0;
			for(var i = 0; i < lstItems.length; i++)
			{
				var lstValues = lstItems[i].split(String.fromCharCode(26)); 
				objTargetList.options[i] = new Option(lstValues[1], lstValues[0]);
				if (i == 0)
					objTargetList.selectedIndex = i;
					
				intCount++;
			}
			
			if (intCount > 6)
				objTargetList.size = 6; 
			else if(intCount >= 1)
				objTargetList.size = intCount; 

			objTargetList.style.display = 'block';	
			objTargetListClose.style.display = 'inline';				
		}
		
		eval(customFunction);
	} 	
	
	function setAJAXSearch(strAJAXSearchType, strAJAXSearchField, customFunction)
	{
		customFunction = (customFunction) ? customFunction : '';
		
		var objSearchField = document.getElementById('str' + strAJAXSearchField + 'Dummy');
		var objTargetIDField = document.getElementById('int' + strAJAXSearchField + 'ID');
		var objTargetList = document.getElementById('int' + strAJAXSearchField + 'IDDummy');
		var objTargetListClose = document.getElementById('imgClose' + strAJAXSearchField);
		
		if (objSearchField.style.backgroundColor == '#ffcccc')
		{
			objTargetIDField.value = '';
			objTargetList.style.display = 'none';
			objTargetListClose.style.display = 'none';
		}
		else
		{
			objSearchField.style.color = '#000000'
			objSearchField.value = objTargetList.options[objTargetList.selectedIndex].text;
			objTargetIDField.value = objTargetList.options[objTargetList.selectedIndex].value;
			objTargetList.style.display = 'none';
			objTargetListClose.style.display = 'none';
			
			eval(customFunction);			
		}
	}
	
	function setNewAJAXSearch(strAJAXSearchField, strResponse)
	{
		var objSearchField = document.getElementById('str' + strAJAXSearchField + 'Dummy');
		var objTargetIDField = document.getElementById('int' + strAJAXSearchField + 'ID');
		var objTargetList = document.getElementById('int' + strAJAXSearchField + 'IDDummy');
		var objTargetListClose = document.getElementById('imgClose' + strAJAXSearchField);
		
		intNewID = getQueryStringValue(strResponse, 'intNewID');
		strNewText = getQueryStringValue(strResponse, 'strNewText');
		
		objSearchField.value = strNewText;
		objTargetIDField.value = intNewID;
		objSearchField.style.color = '#000000'
		objTargetList.style.display = 'none';
		objTargetListClose.style.display = 'none';
	}
	
	function clearAJAXSearch(strAJAXSearchField)
	{
		var objSearchField = document.getElementById('str' + strAJAXSearchField + 'Dummy');
		var objTargetIDField = document.getElementById('int' + strAJAXSearchField + 'ID');
		var objTargetList = document.getElementById('int' + strAJAXSearchField + 'IDDummy');
		var objTargetListClose = document.getElementById('imgClose' + strAJAXSearchField);
		objSearchField.value = '';
		objTargetIDField.value = '';		
		objTargetListClose.style.display = 'none';
		//objTargetList.style.display = 'none';
	}
	
	function hideAJAXSearch(strAJAXSearchField)
	{
		var objTargetList = document.getElementById('int' + strAJAXSearchField + 'IDDummy');
		var objTargetListClose = document.getElementById('imgClose' + strAJAXSearchField);
		objTargetList.style.display = 'none';
		objTargetListClose.style.display = 'none';
	}	
  
  function copyAddress()
  {
    document.getElementById('strBillingAddress').value = document.getElementById('strCustomerAddress').value;
    document.getElementById('strBillingCity').value = document.getElementById('strCustomerCity').value;
    document.getElementById('strBillingPostCode').value = document.getElementById('strCustomerPostCode').value;
    document.getElementById('strBillingState').value = document.getElementById('strCustomerState').value;
    document.getElementById('strBillingCountry').value = document.getElementById('strCustomerCountry').value;
  }

    function showJobAddress(blnChecked)
  {
    document.getElementById('tblJobAddress').style.display = (blnChecked) ? 'none' : 'block';
    
  }

