//
// PopUp by MajestiC
// v1.05
//
// IE,Mozilla,Opera,FireFox compatible
//

isIE=document.all;
isNN=!document.all&&document.getElementById;

var CurrentLayer;
var iframeLayer;
var majActive;

function SetCurrentLayer(Layer1) {
	CurrentLayer = document.getElementById(Layer1);
	if(document.getElementById('ie6Iframe')) {
		iframeLayer = document.getElementById('ie6Iframe');
	}
}

function majMouseDown(e) {
	if (CurrentLayer != null) {
		majActive = true;
		if (isNN) {
			offsetx = e.clientX;
			offsety = e.clientY;
		}
		else {
			offsetx = event.clientX;
			offsety = event.clientY;
		}
      	nowX = parseInt(CurrentLayer.style.left);
		nowY = parseInt(CurrentLayer.style.top);
		document.onmousemove = MouseMoveHandler;
	}
}

function MouseMoveHandler(e) {
	if (!majActive) return;
	if (isNN) {
		CurrentLayer.style.left = eval(nowX + e.clientX - offsetx) + 'px';
		CurrentLayer.style.top = eval(nowY + e.clientY - offsety) + 'px';
		if(document.getElementById('ie6Iframe')) {
			iframeLayer.style.left = eval(nowX + e.clientX - offsetx) + 'px';
			iframeLayer.style.top = eval(nowY + e.clientY - offsety) + 'px';
		}
	}
	else {
		CurrentLayer.style.left = eval(nowX + event.clientX - offsetx) + 'px';
		CurrentLayer.style.top = eval(nowY + event.clientY - offsety) + 'px';
		if(document.getElementById('ie6Iframe')) {
			iframeLayer.style.left = eval(nowX + event.clientX - offsetx) + 'px';
			iframeLayer.style.top = eval(nowY + event.clientY - offsety) + 'px';
		}
	}
}


function hideMe(layerid){
	if(document.getElementById('iframe' + layerid)) {
		document.getElementById('iframe' + layerid).style.visibility = 'hidden';
		document.getElementById('iframe' + layerid).style.display = 'none';
	}
	if(document.getElementById(layerid)) {
		document.getElementById(layerid).style.visibility = 'hidden';
		document.getElementById(layerid).style.display = 'none';
	}
	if(document.getElementById('ie6Iframe')) {
		document.getElementById('ie6Iframe').style.display = 'none'; 
		try {
			var d = document.body;
			var olddiv = document.getElementById(layerid);
			d.removeChild(olddiv);
		}
		catch(ex) {
			return false;	
		}	
	}
}

function destroyMe(layerid){
	try {
		var nodeToRemove;
		if(document.getElementById('iframe' + layerid)) {
			nodeToRemove = document.getElementById('iframe' + layerid);
			nodeToRemove.parentNode.removeChild(nodeToRemove);
		}
		if(document.getElementById(layerid)) {
			nodeToRemove = document.getElementById(layerid);
			nodeToRemove.parentNode.removeChild(nodeToRemove);
		}
		showCallCenterUserSchedulePopupVisible = false;
	}
	catch(e) {
		
	}
}

function showMe(layerid, evt){
	if(document.getElementById(layerid)) {
		document.getElementById(layerid).style.visibility = 'visible';
		document.getElementById(layerid).style.display = 'block';
	}
	if(evt != null && evt != "") {
		//alert(document.getElementById(layerid).style.width.toString().replace('px','') + '\n' + document.getElementById(layerid).style.height.toString().replace('px',''));
		setElementPositionInRelationToMouseClick(evt, layerid, document.getElementById(layerid).style.width.toString().replace('px',''), document.getElementById(layerid).style.height.toString().replace('px',''));
	}
}

// insertAdjacentHTML(), insertAdjacentText() and insertAdjacentElement()
// for Netscape 6/Mozilla by Thor Larholm me@jscript.dk
// Usage: include this code segment at the beginning of your document
// before any other Javascript contents.

if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement)
{
	HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode)
	{
		switch (where)
		{
			case 'beforeBegin':
				this.parentNode.insertBefore(parsedNode,this)
				break;
			case 'afterBegin':
				this.insertBefore(parsedNode,this.firstChild);
				break;
			case 'beforeEnd':
				this.appendChild(parsedNode);
				break;
			case 'afterEnd':
				if (this.nextSibling) 
				{
					this.parentNode.insertBefore(parsedNode,this.nextSibling);
				}
				else 
				{
					this.parentNode.appendChild(parsedNode);
				}
				break;
		}
	}

	HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr)
	{
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where,parsedHTML)
	}


	HTMLElement.prototype.insertAdjacentText = function(where,txtStr)
	{
		var parsedText = document.createTextNode(txtStr)
		this.insertAdjacentElement(where,parsedText)
	}
}

function addToolbarLinks() {
	var loc = location.href;
	var parentLoc = window.parent.location.href;
	var searchedText = '';
	if(loc.indexOf('/app/') > 0 && loc.indexOf('language_tools') == -1 && parentLoc == loc) {
		if(document.getElementById('hiddenSearchedText')) {
			searchedText = document.getElementById('hiddenSearchedText').value;
		}
		//&& (loc.indexOf('W=WorkOrder') > 0 || loc.indexOf('W=CompanyViewInvoice') > 0 || loc.indexOf('W=EditInvoice') > 0 || loc.indexOf('W=ViewInvoice') > 0)) {
		//alert(document.getElementById('mainBodyTD'));
		if(document.getElementById('mainBodyTD')) {
			var toolbarHTML = '';
			var toolbarWidth;
			var quickSearchBoxPosition;
			disableGoogleTranslate ? toolbarWidth = 250 : toolbarWidth = 380;
			disableGoogleTranslate ? quickSearchBoxPosition = 0 : quickSearchBoxPosition = 152;
			document.getElementById('mainBodyTD').insertAdjacentHTML('afterBegin', '<div id="toolBarLayer" style="position:absolute;top:107px;right:0px;width:' + toolbarWidth + 'px;height:23px;background: url(/app/images/toolbarLinksBg2.gif) no-repeat top left;padding-left:4px;padding-top:2px;z-index:598;"></div>');
			toolbarHTML = '<form id="quickSearchForm" name="quickSearchForm" action="/app/default.asp?W=QuickSearchPost" method="post" onSubmit="if(checkForm(\'quickSearchForm\')){return true}else{return false}">';
			if(! disableGoogleTranslate) {
				toolbarHTML += 'Translate into <select id="ddTranslate" onchange="showTranslatePage(this.value)" style="vertical-align:middle;">' + 
					'<option value=""></option>' + 
					'<option value="fr">French</option>' + 
					'<option value="es">Spanish</option>' + 
					'<option value="ru">Russian</option>' + 
					'</select>' +
					'&nbsp;<img src="/app/images/toolBarLinksDivider.gif" width="2" height="17" style="vertical-align:middle" alt="" />&nbsp;'
			}
			toolbarHTML += '<div id="callCenterUserStatusSpan" style="width:0px;display:none;"></div>' +
				 '<a href="#" onclick="toggleQuickSearchToolbar();return false;"><img id="quickSearchTitleImage" src="/app/images/plus_sign.gif" alt="Quick Search" style="vertical-align:middle;" />Quick Search:</a>' + 
				 '<div id="quickSearchToolbarDiv" style="display:none;background-color:#FFFFFF;padding:2px;border-left:1px solid #BEBEBE;border-right:1px solid #BEBEBE;border-bottom:1px solid #BEBEBE;background-color:#F1F1F1;width:154px;position:relative;left:' + quickSearchBoxPosition + 'px;top:2px;">' + 
				 'Search Text:<br />' +
				 '<input type="text" id="searchText" name="searchText" value="'+searchedText+'" class="req_text" style="width: 140px;" /><br />' +
				 'Search Scope:<br />' +
				 '<span id="searchScopeSpan" style="width:140px;">' +
				 '<select id="searchScope" name="searchScope" class="req" style="width: 140px;" onchange="if(this.value != \'\'){GetAJAXResult(\'searchColumnsSpan\', \'default.asp?W=\'+this.value+\'ColumnSearchDD&Z=1\')}">' +
				 '<option value=""></option>' +
				 '</select>' +
				 '</span><br />' +
				 'Search Columns:<br />' +
				 '<span id="searchColumnsSpan" style="width:140px;">' +
				 '<select id="searchColumns" name="searchColumns" style="width:140px;" disabled>' +
				 '<option value=""></option>' +
				 '</select>' +
				 '</span>' +
				 '<input type="submit" id="btnSubmit" name="btnSubmit" value="Search" disabled="disabled" />  ' +
				 '</div>' +
				 '</form>';
			document.getElementById('toolBarLayer').innerHTML = toolbarHTML;
			GetAJAXResult('searchScopeSpan', '/app/default.asp?W=GetSearchScopeDD&X=1', 'group1');
			if(document.getElementById('getCallCenterStatusIconYN')) {
				if(document.getElementById('getCallCenterStatusIconYN').value == '1') {
					GetAJAXResult('callCenterUserStatusSpan', '/app/default.asp?W=GetCallCenterStatusIcon&X=1', 'group1');
				}
			}
			else {
				GetAJAXResult('callCenterUserStatusSpan', '/app/default.asp?W=GetCallCenterStatusIcon&X=1', 'group1');
			}
			document.getElementById('btnSubmit').disabled = true;
		}
	}
}
function showTranslatePage(e) {
	var userGuid = '';
	if(document.getElementById('UserSessionGuid')) {
		userGuid = document.getElementById('UserSessionGuid').value;
	}
	if(e != '') {
		var url1 = 'http://translate.google.com/translate?u=';
		var url2 = escape(location.href.replace('#','') + '&guid=' + userGuid);
		var url3 = '&langpair=en%7C' + e + '&hl=en&newwindow=1&ie=UTF-8&oe=UTF-8&prev=%2Flanguage_tools';
		var translateWindow = window.open(url1 + url2 + url3);
	}
}
if (document.addEventListener) {    
	document.addEventListener("DOMContentLoaded", addToolbarLinks, false);
}
else {
	document.onload = addToolbarLinks();
}

function toggleQuickSearchToolbar() {
	if(document.getElementById('quickSearchToolbarDiv').style.display == 'block') {
		document.getElementById('quickSearchTitleImage').src = 'images/plus_sign.gif';
		document.getElementById('quickSearchToolbarDiv').style.display = 'none';
	}
	else {
		document.getElementById('quickSearchTitleImage').src = 'images/minus_sign.gif';
		document.getElementById('quickSearchToolbarDiv').style.display = 'block';
	}
}

var duplicateServicesAutoDispatchLayerVisible = false;
function showDuplicateSiteServicesForAutoDispatch(evt, SiteID) {	
	var layerName = 'duplicateSiteServicesForAutoDispatchLayer';
	var layerWidth = 450;
	var layerHeight = 150;
	if(! duplicateServicesAutoDispatchLayerVisible) {
		buildPopup(layerName);
		duplicateServicesAutoDispatchLayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=DuplicateSiteServicesForAutoDispatch&P=' + SiteID + '&X=1', 'group1');
}

var duplicateSiteWorkflowLayerVisible = false;
function showDuplicateSiteWorkflow(evt, SiteID) {
	var layerName = 'duplicateSiteWorkflowLayer';
	var layerWidth = 450;
	var layerHeight = 150;
	if(! duplicateSiteWorkflowLayerVisible) {
		buildPopup(layerName);
		duplicateSiteWorkflowLayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=DuplicateSiteWorkflowPopup&P=' + SiteID + '&X=1', 'group1');
}

var duplicateUserPermissionsLayerVisible = false;
function showDuplicateUserPermissions(evt, UserID) {
	var layerName = 'duplicateUserPermissionsLayer';
	var layerWidth = 450;
	var layerHeight = 300;
	if(! duplicateUserPermissionsLayerVisible) {
		buildPopup(layerName);
		duplicateUserPermissionsLayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=DuplicateUserPermissionsPopup&P=' + UserID + '&X=1', 'group1');
}

var duplicateServiceCatNTELayerVisible = false;
function duplicateServiceCatNTE(evt, serviceID) {
	var layerName = 'duplicateServiceCatNTELayer';
	var layerWidth = 450;
	var layerHeight = 200;
	if(! duplicateServiceCatNTELayerVisible) {
		buildPopup(layerName);
		duplicateServiceCatNTELayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=DuplicateServiceCatNTEPopup&P=' + serviceID + '&X=1', 'group1');
}

var duplicateServiceCatAcctCodeLayerVisible = false;
function duplicateServiceCatAcctCode(evt, serviceID) {
	var layerName = 'duplicateServiceCatAcctCodeLayer';
	var layerWidth = 450;
	var layerHeight = 200;
	if(! duplicateServiceCatAcctCodeLayerVisible) {
		buildPopup(layerName);
		duplicateServiceCatAcctCodeLayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=DuplicateServiceCatAccountCodePopup&P=' + serviceID + '&X=1', 'group1');
}

var duplicateServiceCatSLALayerVisible = false;
function duplicateServiceCatSLA(evt, serviceID) {
	var layerName = 'duplicateServiceCatSLALayer';
	var layerWidth = 450;
	var layerHeight = 200;
	if(! duplicateServiceCatSLALayerVisible) {
		buildPopup(layerName);
		duplicateServiceCatSLALayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=DuplicateServiceCatSLAPopup&P=' + serviceID + '&X=1', 'group1');
}

var thirdPartyManagementInfoLayerVisible = false;
function showThirdPartyManagementInfo(evt, userID, userType) {
	var layerName = 'thirdPartyManagementInfoPopup';
	var layerWidth = 400;
	var layerHeight = 520;
	if(! thirdPartyManagementInfoLayerVisible) {
		buildPopup(layerName);
		thirdPartyManagementInfoLayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ThirdPartyManagementInfoPopup&P=' + userID + '&P=' + userType + '&X=1');
}

var changeDispatcherLayerVisible = false;
function showChangeServiceRequestDispatcherPopup(evt, serviceRequestID, requestType, workOrderID) {
	var layerName = 'changeDispatcherPopup';
	var layerWidth = 400;
	var layerHeight = 120;
	if(! changeDispatcherLayerVisible) {
		buildPopup(layerName);
		changeDispatcherLayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ChangeServiceRequestDispatcherPopup&P=' + serviceRequestID + '&P=' + requestType + '&P=' + workOrderID + '&loc=' + escape(location.href) + '&X=1');
}

var editServiceRequestPriorityPopupLayerVisible = false;
function showEditServiceRequestPriorityPopup(evt, serviceRequestID) {
	var layerName = 'editServiceRequestPriorityPopupLayer';
	var layerWidth = 400;
	var layerHeight = 100;
	if(! editServiceRequestPriorityPopupLayerVisible) {
		buildPopup(layerName);
		editServiceRequestPriorityPopupLayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=EditServiceRequestPriorityPopup&P=' + serviceRequestID + '&X=1');
}

var supplierDocFormLayerVisible = false;
function showUploadSupDocForm(evt, DocType, SysDocID, InsType, SupplierID, returnLink) {
	var layerName = 'supplierDocFormLayer';
	var layerWidth = 450;
	var layerHeight = 100;
	if(! supplierDocFormLayerVisible) {
		buildPopup(layerName);
		supplierDocFormLayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=PopupUploadSupDocForm&P=' + DocType + '&P=' + SysDocID + '&P=' + returnLink + '&InsType=' + InsType + '&SupplierID=' + SupplierID + '&X=1');
}
var supplierUploadDBIFormLayerVisible = false;
function showUploadDBIForm(evt, SupplierID) {
	var layerName = 'supplierUploadDBIFormLayer';
	var layerWidth = 300;
	var layerHeight = 200;
	if(! supplierUploadDBIFormLayerVisible) {
		buildPopup(layerName);
		supplierUploadDBIFormLayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=PopupUploadDBIForm&P=' + SupplierID + '&X=1');
}
function uploadSupplierSysDoc(resultTarget) {
	if(checkForm('UploadSupDocForm')) {
		postUploadSupplierSysDoc(resultTarget);
	}
	return false;
}
function postUploadSupplierSysDoc(resultTarget) {
	GetAJAXPostResult(document.getElementById('UploadSupDocForm'), resultTarget);
	hideMe('supplierDocFormLayer');
	return false;
}
var editPatternLayerVisible = false;
function showCustomScheduleLayer(evt, serviceID) {
	var layerName = 'editPatternLayer';
	var layerWidth = 284;
	var layerHeight = 250;
	if(! editPatternLayerVisible && ! document.getElementById('editPatternLayer')) {
		if(document.getElementById('newScheduledServiceForm')) {
			buildPopupWithinForm(layerName, 'newScheduledServiceForm');
		}
		else {
			buildPopupWithinForm(layerName, 'editScheduledMaintenance');
		}
		editPatternLayerVisible = true;
	}
	showMe(layerName);
	if(evt != '') {
		setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	}
	else {
		// This was created and closed very quickly 
		editPatternLayerVisible = false;
	}
	GetAJAXResultWithScript(layerName, '/app/default.asp?W=ShowCustomSchedulePopup&P=' + serviceID + '&X=1');
}
var showSendServicExpressInvoiceLayerVisible = false;
function showSendServicExpressInvoiceToCustomerPopup(evt, consolidatedInvoiceID, sendOrResend) {
	var layerName = 'consolidatedInvoicePopupLayer';
	var layerWidth = 300;
	var layerHeight = 180;
	if(! showSendServicExpressInvoiceLayerVisible) {
		buildPopup(layerName);
		showSendServicExpressInvoiceLayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=SendServicExpressInvoiceToCustomerPopup&P=' + consolidatedInvoiceID + '&sendOrResend=' + sendOrResend + '&X=1');
}
var reassignToSubContractorLayerVisible = false;
function reassignToSubContractor(evt, workOrderID) {
	var layerName = 'reassignToSubContractorLayer';
	var layerWidth = 450;
	var layerHeight = 120;
	if(! reassignToSubContractorLayerVisible) {
		buildPopup(layerName);
		reassignToSubContractorLayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ReassignToSubContractorPopup&P=' + workOrderID + '&X=1');
}
var reassignVendorLayerVisible = false;
function showReassignVendorLayer(evt, siteID, supplierID, serviceID, equipmentID, taskID, procedureID, scheduledServiceID) {
	if(document.getElementById('originalSupplierID').value != supplierID) {
		var layerName = 'reassignVendorLayer';
		var layerWidth = 320;
		var layerHeight = 120;
		if(! reassignVendorLayerVisible) {
			buildPopup(layerName);
			reassignVendorLayerVisible = true;
		}
		showMe(layerName);
		setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
		GetAJAXResult(layerName, '/app/default.asp?W=ReassignVendorPopup&P=' + siteID + '&P=' + supplierID + '&P=' + serviceID + '&P=' + equipmentID + '&P=' + taskID + '&P=' + procedureID + '&P=' + scheduledServiceID + '&X=1');
	}
}
var assignContractorConfirmLayerVisible = false;
function showAssignContractorConfirmLayer(evt) {
	var layerName = 'assignContractorConfirmLayer';
	var layerWidth = 250;
	var layerHeight = 100;
	if(! assignContractorConfirmLayerVisible) {
		buildPopup(layerName);
		assignContractorConfirmLayerVisible = true;
	}
	showMe(layerName);
	document.getElementById(layerName).style.zIndex += 5;
	//currentZIndex += 5;
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowAssignContractorConfirmPopup&X=1');
}

/*var viewSupplierServicesLayerVisible = false;
function showSupplierServicesLayer(evt, SupplierID, SiteID) {
	var layerName = 'supplierServicesLayer';
	var layerWidth = 250;
	var layerHeight = 100;
	if(! viewSupplierServicesLayerVisible) {
		buildPopup(layerName);
		viewSupplierServicesLayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResultWithScript(layerName, '/app/default.asp?W=ViewSupplierServicesBySite&P=' + SupplierID + '&P=' + SiteID + '&X=1');
}*/

var viewAddWorkOrdersToInvoiceLayerVisible = false;
function addWorkOrdersToInvoice(evt, InvoiceID, CompanyID) {
	var layerName = 'addWorkOrdersToInvoiceLayer';
	var layerWidth = 500;
	var layerHeight = 150;
	if(! viewAddWorkOrdersToInvoiceLayerVisible) {
		buildPopup(layerName);
		viewAddWorkOrdersToInvoiceLayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowAddWorkOrdersToInvoiceLayerPopup&P=' + InvoiceID + '&P=' + CompanyID + '&X=1');
}

var viewChooseWorkOrderToViewLayerVisible = false;
function chooseWorkOrderToView(evt, InvoiceID) {
	var layerName = 'chooseWorkOrderToViewLayer';
	var layerWidth = 320;
	var layerHeight = 100;
	if(! viewChooseWorkOrderToViewLayerVisible) {
		buildPopup(layerName);
		viewChooseWorkOrderToViewLayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowChooseWorkOrdersToViewPopup&P=' + InvoiceID + '&X=1');
}

function callVerifyWorkOrderSubmission(evt, workOrderID, siteID, supplierID, serviceID, poNumber, taskID, showAlertWindow, showVendorJobCostYN) {
	var query = '&P=' + workOrderID + '&P=' + siteID + '&P=' + supplierID + '&P=' + serviceID + '&P=' + escape(poNumber) + '&P=' + taskID + '&X=1';
	var url = '/app/default.asp?W=VerifyWorkOrderSubmission' + query;
	var groupName = 'group1';
	AjaxRequest.get(
		{
			'url':url
			,'timeout':3000
			,'onTimeout':function() {
				return false;
				//callVerifyWorkOrderSubmission(evt, workOrderID, siteID, supplierID, serviceID, poNumber, taskID, showAlertWindow, showVendorJobCostYN);
			}
			,'onSuccess':function(req){ 
				if(req.responseText == '') {
					if(checkForm('neworder')) {
						//alert('Everything checks out ok');
						document.getElementById('neworder').submit();
						return true;
					}
					else {
						return false;	
					}
				}
				else {
					if(checkForm('neworder')) {
						if(req.responseText.indexOf('You must') != -1) {
							alert(req.responseText);
							return false;
						}
						else if(req.responseText != ''){
							if(confirm(req.responseText)){
								if(showAlertWindow) {
									if(confirm('The workflow has not been set up for this site yet.\nAre you sure you want to continue?')) {
										if(showVendorJobCostYN) {
											showVendorJobCost(evt, workOrderID, 'neworder');
										}
										else {
											document.getElementById('neworder').submit();
										}
									}
								}
								else if(showVendorJobCostYN) {
									showVendorJobCost(evt, workOrderID, 'neworder');
								}
								else {
									document.getElementById('neworder').submit();
									return true;
								}
								return false;	
							}
							else {
								return false;
							}
						}
						else {
							document.getElementById('neworder').submit();
							return true;
						}
					}
					else {
						return false;	
					}
				}
			}
			,'onError':function(){
				alert('An Error was returned by the web service.');
			}
			,'groupName':groupName
		}
	);
}

var viewWorkOrderETALayerVisible = false;
function showWorkOrderETA(evt, WorkOrderID, updateYN) {
	var loc = '';
	var layerName = 'etaLayer';
	var layerWidth = 400;
	var layerHeight = 300;
	if(! viewWorkOrderETALayerVisible) {
		buildPopup(layerName);
		viewWorkOrderETALayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	if(document.getElementById('loc')) {
		loc = escape(document.getElementById('loc').value);
	}
	GetAJAXResult(layerName, '/app/default.asp?W=ShowWorkOrderETAPopup&P=' + WorkOrderID + '&updateYN=' + updateYN + '&loc=' + loc + '&X=1');
}

var viewWorkOrderFollowUpLayerVisible = false;
function showWorkOrderFollowUp(evt, WorkOrderID) {
	var layerName = 'followUpLayer';
	var layerWidth = 400;
	var layerHeight = 300;
	if(! viewWorkOrderFollowUpLayerVisible) {
		buildPopup(layerName);
		viewWorkOrderFollowUpLayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowWorkOrderFollowUpPopup&P=' + WorkOrderID + '&X=1');
}

var viewWorkOrderCancelLayerVisible = false;
function showWorkOrderCancelLayer(evt, WorkOrderID) {
	var layerName = 'cancelLayer';
	var layerWidth = 400;
	var layerHeight = 150;
	if(! viewWorkOrderCancelLayerVisible) {
		buildPopup(layerName);
		viewWorkOrderCancelLayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowWorkOrderCancelLayerPopup&P=' + WorkOrderID + '&X=1');
}

var viewWorkOrderCompleteLayerVisible = false;
function showWorkOrderCompleteLayer(evt, WorkOrderID) {
	var layerName = 'completeLayer';
	var layerWidth = 460;
	var layerHeight = 200;
	if(! viewWorkOrderCompleteLayerVisible) {
		buildPopup(layerName);
		viewWorkOrderCompleteLayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowWorkOrderCompleteLayerPopup&P=' + WorkOrderID + '&X=1');
}

var viewWorkOrderAddNoteLayerVisible = false;
function showWorkOrderAddNoteLayer(evt, WorkOrderID) {
	var layerName = 'noteLayer';
	var layerWidth = 400;
	var layerHeight = 320;
	if(! viewWorkOrderAddNoteLayerVisible) {
		buildPopup(layerName);
		viewWorkOrderAddNoteLayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowWorkOrderNoteLayerPopup&P=' + WorkOrderID + '&X=1');
}

var viewWorkOrderRerouteLayerVisible = false;
function showWorkOrderRerouteLayerPopup(evt, WorkOrderID, SiteName, ServiceID, ServiceName) {
	var layerName = 'rerouteLayer';
	var layerWidth = 450;
	var layerHeight = 200;
	if(! viewWorkOrderRerouteLayerVisible) {
		buildPopup(layerName);
		viewWorkOrderRerouteLayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowWorkOrderRerouteLayerPopup&P=' + WorkOrderID + '&P=' + escape(SiteName) + '&P=' + ServiceID + '&P=' + escape(ServiceName) + '&X=1');
}

var viewWorkOrderRejectLayerVisible = false;
function showWorkOrderRejectLayerPopup(evt, WorkOrderID) {
	var layerName = 'rejectLayer';
	var layerWidth = 400;
	var layerHeight = 150;
	if(! viewWorkOrderRejectLayerVisible) {
		buildPopup(layerName);
		viewWorkOrderRejectLayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowWorkOrderRejectLayerPopup&P=' + WorkOrderID + '&X=1');
}

var viewInvoiceAddNoteLayerVisible = false;
function showInvoiceAddNoteLayerPopup(evt, InvoiceID, InvoiceContractorNote) {
	var layerName = 'invoiceNoteLayer';
	var layerWidth = 400;
	var layerHeight = 150;
	if(! viewInvoiceAddNoteLayerVisible) {
		buildPopup(layerName);
		viewInvoiceAddNoteLayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowInvoiceAddNoteLayerPopup&P=' + InvoiceID + '&P=' + InvoiceContractorNote + '&X=1');	
}

var viewSEInvoiceAddNoteLayerVisible = false;
function showSEInvoiceAddNoteLayerPopup(evt, InvoiceID, InvoiceNote) {
	var layerName = 'invoiceNoteLayer';
	var layerWidth = 400;
	var layerHeight = 150;
	if(! viewSEInvoiceAddNoteLayerVisible) {
		buildPopup(layerName);
		viewSEInvoiceAddNoteLayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowSEInvoiceAddNoteLayerPopup&P=' + InvoiceID + '&P=' + InvoiceNote + '&X=1');	
}

var viewInvoiceAddThirdPartyNoteLayerVisible = false;
function showInvoiceAddThirdPartyNoteLayerPopup(evt, InvoiceID, InvoiceContractorNote, Invoice3rdPartyNote) {
	var layerName = 'invoiceNoteLayer';
	var layerWidth = 400;
	var layerHeight = 150;
	if(! viewInvoiceAddThirdPartyNoteLayerVisible) {
		buildPopup(layerName);
		viewInvoiceAddThirdPartyNoteLayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowInvoiceAddThirdPartyNoteLayerPopup&P=' + InvoiceID + '&P=' + escape(InvoiceContractorNote) + '&P=' + escape(Invoice3rdPartyNote) + '&X=1');	
}

var showSendInvoiceStoreManagerPopupVisible = false;
function showSendInvoiceStoreManagerPopup(evt, InvoiceID) {
	var layerName = 'invoiceSendLayer';
	var layerWidth = 400;
	var layerHeight = 150;
	if(! showSendInvoiceStoreManagerPopupVisible) {
		buildPopup(layerName);
		showSendInvoiceStoreManagerPopupVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowSendInvoiceStoreManagerPopup&P=' + InvoiceID + '&X=1');	
}

var viewInvoiceSendLayerVisible = false;
function showInvoiceSendLayerPopup(evt, InvoiceID) {
	var layerName = 'invoiceSendLayer';
	var layerWidth = 400;
	var layerHeight = 150;
	if(! viewInvoiceSendLayerVisible) {
		buildPopup(layerName);
		viewInvoiceSendLayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowInvoiceSendLayerPopup&P=' + InvoiceID + '&X=1');	
}

var viewCcStatusPromptLayerVisible = false;
function showCallCenterStatusPrompt(evt) {
	var layerName = 'ccStatusPromptLayer';
	var layerWidth = 380;
	var layerHeight = 90;
	if(! viewCcStatusPromptLayerVisible) {
		buildPopup(layerName);
		viewCcStatusPromptLayerVisible = true;
	}
	showMe(layerName);
	if(evt != null) {
		setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	}
	else {
		setElementPositionInCenterOfScreen(layerName, layerWidth, layerHeight);
	}
	GetAJAXResult(layerName, '/app/default.asp?W=ShowCallCenterStatusPromptPopup&X=1');
}

function showCCStatusDiv() {
	document.getElementById('btnCCSubmit').disabled = false;
	if(document.getElementById('statusChange').value == 'Yes') {
		document.getElementById('formCCStatusDiv').style.display = 'block';
	}
	else {
		document.getElementById('formCCStatusDiv').style.display = 'none';
	}
}

var viewManageInternalNotesVisible = false;
function showManageInternalNotesPopup(evt, referenceType, referenceID, noteID) {
	if(noteID == '' || noteID == null) {
		noteID = 0;	
	}
	var layerName = 'manageInternalNotesLayer';
	var layerWidth = 588;
	var layerHeight = 480;
	if(! viewManageInternalNotesVisible) {
		buildPopup(layerName);
		viewManageInternalNotesVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ManageInternalNotesPopup&P=' + referenceType + '&P=' + referenceID + '&P=1&showNoteID=' + noteID + '&X=1');
}

var viewAdjustInvoiceDetailVisible = false;
function showAdjustInvoiceDetailPopup(evt, invoiceDetailID) {
	var layerName = 'adjustInvoiceDetailLayer';
	var layerWidth = 366;
	var layerHeight = 150;
	if(! viewAdjustInvoiceDetailVisible) {
		buildPopup(layerName);
		viewAdjustInvoiceDetailVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=AdjustInvoiceDetailForm&P=' + invoiceDetailID + '&X=1');
}

var viewPhotoViewerVisible = false;
function showPhotoViewerPopup(evt, siteSurveyID, photoType, photoReferenceID, id, equipmentID, newEquipmentYN, maintenanceCategoryID) {
	var newEquipment = '';
	if(newEquipmentYN) {
		newEquipment = '&newEquipment=1';
	}
	var url = '/app/default.asp?W=SiteSurveyPhotos&P=' + siteSurveyID + '&P=' + photoType + '&P=' + photoReferenceID + '&P=' + id + '&P=' + equipmentID + '&P=' + maintenanceCategoryID + newEquipment + '&X=1';
	var layerName = 'photoViewerPopup';
	var layerWidth = 550;
	var layerHeight = 250;
	if(! viewPhotoViewerVisible) {
		buildPopup(layerName);
		viewPhotoViewerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, url, 'group1');	
}

var viewSendSurveyOnDemandVisible = false;
function sendSurveyOnDemand(evt, surveyID, returnType) {
	var layerName = 'sendSurveyOnDemandPopup';
	var layerWidth = 530;
	var layerHeight = 210;
	if(! viewSendSurveyOnDemandVisible) {
		buildPopup(layerName);
		viewSendSurveyOnDemandVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=SendSurveyOnDemandPopup&P=' + surveyID + '&P=' + returnType + '&X=1');
}

var adjustContractorPopupVisible = false;
function showAdjustContractorPopup(evt, siteID) {
	var layerName = 'adjustContractorPopup';
	var layerWidth = 370;
	var layerHeight = 210;
	if(! adjustContractorPopupVisible) {
		buildPopup(layerName);
		adjustContractorPopupVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=AdjustContractor&P=' + siteID + '&X=1');
}

var viewContractorPerformanceViewLayer = false;
function showContractorPerformanceViewPopup(evt, supplierID) {
	var layerName = 'contractorPerformanceViewPopup';
	var layerWidth = 450;
	var layerHeight = 240;
	if(! viewContractorPerformanceViewLayer) {
		buildPopup(layerName);
		viewContractorPerformanceViewLayer = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ContractorPerformanceView&P=' + supplierID + '&X=1');
}

var viewWODocsLayer = false;
function showViewWODocsPopup(evt, workOrderID) {
	if(workOrderID != '') {
		var layerName = 'viewWODocsPopup';
		var layerWidth = 530;
		var layerHeight = 300;
		if(! viewWODocsLayer) {
			buildPopup(layerName);
			viewWODocsLayer = true;
		}
		showMe(layerName);
		setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
		GetAJAXResult(layerName, '/app/default.asp?W=ViewWODocs&P=' + workOrderID + '&X=1');
	}
	else {
		alert('No work order id was found.');	
	}
}

var viewRejectBidLayer = false;
function showRejectBidPopup(evt, workOrderID, fileID) {
	var layerName = 'viewRejectBidPopup';
	var layerWidth = 400;
	var layerHeight = 300;
	if(! viewRejectBidLayer) {
		buildPopup(layerName);
		viewRejectBidLayer = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowRejectBidPopup&P=' + workOrderID + '&P=' + fileID + '&X=1');
}

var viewVendorJobCostLayer = false;
function showVendorJobCost(evt, workOrderID, formName) {
	var useExistingForm;
	formName != '' ? useExistingForm = true : useExistingForm = false;
	var layerName = 'viewVendorJobCostPopup';
	var layerWidth = 275;
	var layerHeight = 150;
	if(! viewVendorJobCostLayer) {
		useExistingForm ? buildPopupWithinForm(layerName, formName) : buildPopup(layerName);
		viewVendorJobCostLayer = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowVendorJobCostPopup&P=' + workOrderID + '&P=' + useExistingForm + '&X=1');
}
//ShowServiceRequestNotesPopup

var showServiceRequestNotesLayerVisible = false;
function showServiceRequestNotesPopup(evt, serviceRequestID, serviceRequestsType) {
	var layerName = 'serviceRequestNotesPopup';
	var layerWidth = 400;
	var layerHeight = 150;
	if(! showServiceRequestNotesLayerVisible) {
		buildPopup(layerName);
		showServiceRequestNotesLayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowServiceRequestNotesPopup&P=' + serviceRequestID + '&P=' + serviceRequestsType + '&X=1');
}

function deleteServiceRequestNotes() {
	if(confirm('Are you sure you want to delete this note?')) {
		document.getElementById('formAction').value = 'delete';
		document.getElementById('serviceRequestNotesForm').submit();
	}
}

var showEquipmentWarrantyLayerVisible = false;
function showEquipmentWarrantyPopup(evt, equipmentID) {
	var layerName = 'showEquipmentWarranty';
	var layerWidth = 340;
	var layerHeight = 180;
	if(! showEquipmentWarrantyLayerVisible) {
		buildPopup(layerName);
		showEquipmentWarrantyLayerVisible = true;
	}
	showMe(layerName);
	//setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	setElementPositionInCenterOfScreen(layerName, layerWidth, layerHeight)
	GetAJAXResult(layerName, '/app/default.asp?W=ShowEquipmentWarrantyWindowPopup&P=' + equipmentID + '&X=1');
}

var showSafeSerialNumberLayerVisible = false;
function showSafeSerialNumberPopup(evt, serviceCat) {
	var obj = document.getElementById(serviceCat.id);
	var selIndex = obj.selectedIndex;
	var txt = obj.options[selIndex].text;
	if(txt == 'Safes') {
		var layerName = 'safeSerialNumberPopup';
		var layerWidth = 300;
		var layerHeight = 150;
		if(! showSafeSerialNumberLayerVisible) {
			buildPopup(layerName);
			showSafeSerialNumberLayerVisible = true;
		}
		showMe(layerName);
		setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
		GetAJAXResult(layerName, '/app/default.asp?W=ShowSafeSerialNumberPopup&X=1');
	}
}
function updateSafeSerialNumber() {
	var sn = document.getElementById('SerialNumber').value;
	var cm = document.getElementById('MBoxComments').value;
	if(sn != '') {
		document.getElementById('MBoxComments').value = 'Safe Serial #: ' + sn + '; ' + cm;
		hideMe('safeSerialNumberPopup');
	}
	else {
		alert('You must enter a serial number!');	
	}
	return false;
}

var showFixturesSRPopupLayerVisible = false;
function showFixturesSRPopup(evt, serviceCat) {
	if(0 == 1) {
		var obj = document.getElementById(serviceCat.id);
		var selIndex = obj.selectedIndex;
		var txt = obj.options[selIndex].text;
		if(txt == 'Fixture' || txt == 'Fixtures') {
			var layerName = 'fixturesSRPopup';
			var layerWidth = 300;
			var layerHeight = 150;
			if(! showFixturesSRPopupLayerVisible) {
				buildPopup(layerName);
				showFixturesSRPopupLayerVisible = true;
			}
			showMe(layerName);
			setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
			GetAJAXResult(layerName, '/app/default.asp?W=ShowFixturesSRPopup&X=1');
			document.getElementById('documentToUpload').className = 'text req';
			document.getElementById('documentOptionalSpan').innerHTML = '(Required)';
		}
		else {
			document.getElementById('documentToUpload').className = 'text';
			document.getElementById('documentOptionalSpan').innerHTML = '(Optional)';
		}
	}
}

var viewSupplierSummaryLayer = false;
function showSupplierSummary(evt, supplierID) {
	var layerName = 'viewSupplierSummaryPopup';
	var layerWidth = 380;
	var layerHeight = 250;
	if(! viewSupplierSummaryLayer) {
		buildPopup(layerName);
		viewSupplierSummaryLayer = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ViewSupplierSummary&P=' + supplierID + '&X=1');
}

var viewWODescLayer = false;
function editWorkOrderDescriptionPopup(evt, workOrderID) {
	var layerName = 'viewWODescPopup';
	var layerWidth = 500;
	var layerHeight = 220;
	if(! viewWODescLayer) {
		buildPopup(layerName);
		viewWODescLayer = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowWorkOrderDescriptionPopup&P=' + workOrderID + '&X=1');
}

var viewChangeWOServiceRequestorPopup = false;
function showChangeWorkOrderServiceRequestorPopup(evt, resultTarget, workOrderID) {
	var layerName = 'changeWorkOrderServiceRequestorPopup';
	var layerWidth = 400;
	var layerHeight = 100;
	if(! viewChangeWOServiceRequestorPopup) {
		buildPopup(layerName);
		viewChangeWOServiceRequestorPopup = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowChangeWorkOrderServiceRequestorPopup&P=' + resultTarget + '&P=' + workOrderID + '&X=1');
}

function postChangeWorkOrderServiceRequestorForm(resultTarget) {
	GetAJAXPostResult(document.getElementById('changeWorkOrderServiceRequestorForm'), resultTarget);
	hideMe('changeWorkOrderServiceRequestorPopup');
	return false;
}

function checkDocUploadFileType(e) {
	//This checks to see if the work order document to upload is a bid document or not
	var notifyElement = document.getElementById('sendEmailNotification');
	var bidAmountText = document.getElementById('bidAmountText');
	var bidAmountInput = document.getElementById('bidAmountInput');
	try {
		if(e == 'Bid' || e == 'True') {
			if(notifyElement.checked != 1) {
				notifyElement.checked = 1;
			}
			notifyElement.disabled = true;
			bidAmountText.style.display = 'block';
			bidAmountInput.style.display = 'block';
			if(document.getElementById('bidTypeText')) {
				document.getElementById('bidTypeText').style.display = 'block';
				document.getElementById('bidTypeValue').style.display = 'block';
			}
		}
		else {
			notifyElement.disabled = false;
			bidAmountText.style.display = 'none';
			bidAmountInput.style.display = 'none';
			if(document.getElementById('bidTypeText')) {
				document.getElementById('bidTypeText').style.display = 'none';
				document.getElementById('bidTypeValue').style.display = 'none';
			}
		}
	}
	catch(err) {
		
	}
}

var viewEquipDocsLayer = false;
function showViewEquipDocsPopup(evt, equipmentID, workOrderID) {
	var layerName = 'viewEquipDocsPopup';
	var layerWidth = 500;
	var layerHeight = 250;
	if(! viewEquipDocsLayer) {
		buildPopup(layerName);
		viewEquipDocsLayer = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ViewEquipDocs&P=' + equipmentID + '&P=' + workOrderID + '&X=1');
}

var viewCompanyDocsLayer = false;
function showViewCompanyDocs(evt, companyID, workOrderID) {
	var layerName = 'viewCompanyDocsPopup';
	var layerWidth = 300;
	var layerHeight = 200;
	if(! viewCompanyDocsLayer) {
		buildPopup(layerName);
		viewCompanyDocsLayer = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ViewCompanyDocs&P=' + companyID + '&P=' + workOrderID + '&X=1');
}

var viewWorkOrderOnHoldLayer = false;
function showWorkOrderOnHoldPopup(evt, workOrderID, pendingBid, pendingHomeOfficeApproval) {
	if(pendingBid == '' || pendingBid == null) {
		pendingBid = false;
	}
	if(pendingHomeOfficeApproval == '' || pendingHomeOfficeApproval == null) {
		pendingHomeOfficeApproval = false;
	}
	var layerName = 'workOrderOnHoldPopup';
	var layerWidth = 300;
	var layerHeight = 230;
	if(! viewWorkOrderOnHoldLayer) {
		buildPopup(layerName);
		viewWorkOrderOnHoldLayer = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=WorkOrderOnHoldPopup&P=' + workOrderID + '&P=' + pendingBid + '&P=' + pendingHomeOfficeApproval + '&X=1');
}

var viewWorkOrderOffHoldLayer = false;
function showWorkOrderOffHoldPopup(evt, workOrderID) {
	var layerName = 'workOrderOffHoldPopup';
	var layerWidth = 300;
	var layerHeight = 200;
	if(! viewWorkOrderOffHoldLayer) {
		buildPopup(layerName);
		viewWorkOrderOffHoldLayer = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=WorkOrderOffHoldPopup&P=' + workOrderID + '&X=1');
}

var viewRejectServiceRequestLayer = false;
function showRejectServiceRequestPopup(evt, serviceRequestID) {
	var layerName = 'rejectServiceRequestPopup';
	var layerWidth = 350;
	var layerHeight = 200;
	if(! viewRejectServiceRequestLayer) {
		buildPopup(layerName);
		viewRejectServiceRequestLayer = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowRejectServiceRequestPopup&P=' + serviceRequestID + '&X=1');
}

var viewWorkOrderSignoffLayer = false;
function showWorkOrderSignoffPopup(evt, workOrderID, dashboardTab) {
	var layerName = 'workOrderSignoffPopup';
	var layerWidth = 400;
	var layerHeight = 150;
	if(! viewWorkOrderSignoffLayer) {
		buildPopup(layerName);
		viewWorkOrderSignoffLayer = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=WorkOrderSignoffPopup&P=' + workOrderID + '&X=1&dashboardTab=' + dashboardTab);
}

var viewReopenWorkOrderLayer = false;
function showReopenWorkOrderPopup(evt, workOrderID) {
	if(confirm('Are you sure you want to re-open work order #' + workOrderID + '?')) {
		var layerName = 'reopenWorkOrderPopup';
		var layerWidth = 410;
		var layerHeight = 200;
		if(! viewReopenWorkOrderLayer) {
			buildPopup(layerName);
			viewReopenWorkOrderLayer = true;
		}
		showMe(layerName);
		setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
		GetAJAXResult(layerName, '/app/default.asp?W=ReopenWorkOrderPopup&P=' + workOrderID + '&X=1');
	}
}

function vendorSignInOrSignOut(workOrderID, hasOpenSignIn) {
	location.href = '/app/default.asp?W=VendorSignInSignOutPopupSubmit&workOrderID=' + workOrderID + '&hasOpenSignIn=' + hasOpenSignIn + '&X=1';
}

var viewVendorSignInSignOutLayer = false;
function showVendorSignInSignOutPopup(evt, workOrderID, hasOpenSignIn) {
	var layerName = 'vendorSignInSignOutPopup';
	var layerWidth = 400;
	var layerHeight = 200;
	if(! viewVendorSignInSignOutLayer) {
		buildPopup(layerName);
		viewVendorSignInSignOutLayer = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=VendorSignInSignOutPopup&P=' + workOrderID + '&P=' + hasOpenSignIn + '&X=1');
}

function exportInvoicesToQuickbooks(evt) {
	var selectedInvoices = '';
	var oCheckBoxes = document.getElementsByTagName('input');
	for(var i = 0; i < oCheckBoxes.length; i ++) {
		if(oCheckBoxes[i].getAttribute('type') == 'checkbox') {
			if(oCheckBoxes[i].checked && oCheckBoxes[i].id != 'cbSelectAll' && oCheckBoxes[i].id != 'DisablePaging') {
				var selectedId = oCheckBoxes[i].id.replace('cb','');
				if(selectedInvoices == '') {
					selectedInvoices = selectedId;
				}
				else {
					selectedInvoices += ',' + selectedId;
				}
			};
		}
	}
	//alert(selectedInvoices);
	showExportToQuickBooksPopup(evt, selectedInvoices, 'AP')
}
var viewShowExportToQuickBooksLayer = false;
function showExportToQuickBooksPopup(evt, invoiceID, invoiceType) {
	var layerName = 'exportToQuickBooksPopup';
	var layerWidth = 400;
	var layerHeight = 210;
	if(! viewShowExportToQuickBooksLayer) {
		buildPopup(layerName);
		viewShowExportToQuickBooksLayer = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=InvoiceExportToIIF&P=' + invoiceID + '&P=' + invoiceType + '&X=1');
}

var showEditBillToSiteForInvoiceLayer = false;
function editBillToSiteForInvoice(evt, invoiceID) {
	var layerName = 'editInvoiceBillToSiteLayer';
	var layerWidth = 420;
	var layerHeight = 210;
	if(! showEditBillToSiteForInvoiceLayer) {
		buildPopup(layerName);
		showEditBillToSiteForInvoiceLayer = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowEditInvoiceBillToSitePopup&P=' + invoiceID + '&X=1');
	//ShowEditInvoiceBillToSitePopup	
}

var viewShowEditServiceHistoryPopup = false;
function showEditServiceHistoryPopup(evt, workOrderID, historyID) {
	var layerName = 'editServiceHistoryPopup';
	var layerWidth = 390;
	var layerHeight = 250;
	if(! viewShowEditServiceHistoryPopup) {
		buildPopup(layerName);
		viewShowEditServiceHistoryPopup = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=EditServiceHistory&P=' + workOrderID + '&P=' + historyID + '&X=1');
}

function deleteServiceHistoryItem() {
	var workOrderID = document.getElementById('WorkOrderID').value;
	var historyID = document.getElementById('WorkOrderHistoryID').value;
	if(confirm('Are you sure you want to DELETE this service history item?\nThis action cannot be undone.')) {
		location.href = '/app/default.asp?W=DeleteServiceHistoryItem&P=' + workOrderID + '&P=' + historyID + '&X=1';
	}
	else {
		return false;	
	}
}

var viewSiteServiceMapLayer = false;
function showSiteServiceMapContainer(evt, siteID, serviceID) {
	var layerName = 'siteServiceMapLayer';
	var layerWidth = 715;
	var layerHeight = 440;
	serviceID = serviceID.replace('_ALL_', '');
//	var mapWin = window.open('/app/default.asp?W=GetSiteServiceMap&P=' + siteID + '&P=' + serviceID + '&X=1','mapWin','width=' + layerWidth + ',height=' + layerHeight + ',top=50px,left=50px,scrollbars=no,menubars=no');
//	mapWin.focus();
	if(! viewSiteServiceMapLayer) {
		buildPopup(layerName);
		viewSiteServiceMapLayer = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowSiteServiceMapContainer&P=' + siteID + '&P=' + serviceID + '&P=&P=False&X=1');
}

var viewSiteGroupSelectorPopup = false;
function showSiteGroupSelectorPopup(evt, supplierID, userID) {
	var layerName = 'siteGroupSelectorPopup';
	var layerWidth = 520;
	var layerHeight = 300;
	if(! viewSiteGroupSelectorPopup) {
		buildPopupWithinForm(layerName, 'FindContractors');
		viewSiteGroupSelectorPopup = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowSiteGroupSelectorPopup&P=' + supplierID + '&P=' + userID + '&X=1');
}

var viewCartersAfterHoursEmergencyAlertPopup = false;
function showCartersAfterHoursEmergencyAlertPopup(evt) {
	var layerName = 'cartersAfterHoursEmergenyAlertPopup';
	var layerWidth = 520;
	var layerHeight = 120;
	if(! viewCartersAfterHoursEmergencyAlertPopup) {
		buildPopup(layerName);
		viewCartersAfterHoursEmergencyAlertPopup = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowCartersAfterHoursEmergencyAlert&P=' + layerName + '&X=1');
}

var viewEditInvoiceContractorNumberPopup = false;
function showEditInvoiceContractorNumberPopup(evt, invoiceID, targetID) {
	var layerName = 'showEditInvoiceContractorNumberPopup';
	var layerWidth = 300;
	var layerHeight = 100;
	if(! viewEditInvoiceContractorNumberPopup) {
		buildPopup(layerName);
		viewEditInvoiceContractorNumberPopup = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowEditInvoiceContractorNumberPopup&P=' + invoiceID + '&P=' + targetID + '&X=1');
}

function saveEditInvoiceContractorNumberForm(targetName, formID) {
	GetAJAXPostResult(document.getElementById(formID), targetName);
	hideMe('showEditInvoiceContractorNumberPopup');
	return false;
}

var viewEditCostCenterNumberPopup = false;
function showEditCostCenterNumberPopup(evt, invoiceID, targetID) {
	var layerName = 'showEditCostCenterNumberPopup';
	var layerWidth = 300;
	var layerHeight = 100;
	if(! viewEditCostCenterNumberPopup) {
		buildPopup(layerName);
		viewEditCostCenterNumberPopup = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowEditCostCenterNumberPopup&P=' + invoiceID + '&P=' + targetID + '&X=1');
}

function saveEditCostCenterNumberForm(targetName, formID) {
	GetAJAXPostResult(document.getElementById(formID), targetName);
	hideMe('showEditCostCenterNumberPopup');
	return false;
}

var viewProjectDocumentPopupVisible = false;
function showProjectDocumentPopup(evt, projectID, taskID, documentID) {
	var layerName = 'projectDocumentsLayer';
	var layerWidth = 480;
	var layerHeight = 250;
	if(! viewProjectDocumentPopupVisible) {
		buildPopup(layerName);
		viewProjectDocumentPopupVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=UploadProjectDocument&P=' + projectID + '&P=' + taskID + '&P=' + documentID + '&X=1');
}

var viewProjectTaskActualCostPopupVisible = false;
function showProjectTaskActualCostFromInvoicePopup(evt, taskID) {
	var layerName = 'projectTaskActualCostLayer';
	var layerWidth = 450;
	var layerHeight = 150;
	if(! viewProjectTaskActualCostPopupVisible) {
		buildPopup(layerName);
		viewProjectTaskActualCostPopupVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowProjectTaskActualCostFromInvoicePopup&P=' + taskID + '&X=1');
}

var showReopenInvoicePopupVisible = false;
function showReopenInvoicePopup(evt, invoiceID) {
	var layerName = 'reopenInvoicePopup';
	var layerWidth = 400;
	var layerHeight = 200;
	if(! showReopenInvoicePopupVisible) {
		buildPopup(layerName);
		showReopenInvoicePopupVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ReopenInvoicePopup&P=' + invoiceID + '&X=1');
}

var taxElementIsActive = false;
var showBNATaxPopupVisible = false;
function showBNATaxPopup(e, siteID, detailID, invoiceID) {
	var targetObject = 'bnaTaxDiv';
	var url = '/app/default.asp?W=ShowBNATaxPopup&P=' + siteID + '&P=' + detailID + '&P=' + invoiceID + '&X=1';
	var groupName = 'group1';
	if(! showBNATaxPopupVisible) {		
		if(! document.getElementById(targetObject)) {
			document.body.insertAdjacentHTML('afterBegin', '<div id="' + targetObject + '" style="display:none;position:absolute;top:0px;left:0px;background-color:#FFFFFF;border:1px solid #000000;z-index:10000;" onmouseover="taxElementIsActive=true" onmouseout="taxElementIsActive=false"></div>');
		}
	}
	if(document.getElementById('btnSubmit')) {
		document.getElementById('btnSubmit').disabled = true;
	}
	if(! showBNATaxPopupVisible) {
		AjaxRequest.get(
			{
				'url':url
				,'onSuccess':function(req){ 
					ShowResult(targetObject, req.responseText);
					document.getElementById(targetObject).style.width = document.getElementById(e.id).style.width;
					document.getElementById(targetObject).style.left = findPosX(e) + 'px';
					document.getElementById(targetObject).style.top = (findPosY(e)+15) + 'px';
					document.getElementById(targetObject).style.display = 'block';
					showBNATaxPopupVisible = true;
				}
				,'groupName':groupName
				,'timeout':5000
				,'onTimeout':function() {
					ShowResult(targetObject, "Timeout connecting to the web service.");
					return false;
				}
			}
		);
	}
}
function hideBNATaxPopup(e) {
	if(showBNATaxPopupVisible && !taxElementIsActive) {
		document.getElementById('bnaTaxDiv').style.display = 'none';
		showBNATaxPopupVisible = false;
	}
}
function updateTaxLocationAddress(e, invoiceID) {
	GetAJAXResult('addressDiv', '/app/default.asp?W=GetTaxLocationAddress&P=' + e + '&P=' + invoiceID + '&X=1', 'group1');
	//document.getElementById('addressDiv').innerHTML = resultVal;
}
function setTaxPopupValues(invoiceID, invoiceDetailID) {
	var elem;
	if(invoiceDetailID == '0') { invoiceDetailID = ''; };
	var url = '/app/default.asp?W=SetTaxAmountFromZipCode&P=' + document.getElementById('ddTaxLocation').value + '&P=' + document.getElementById('ddTaxSalesOrUse').value + '&P=' + invoiceID + '&X=1';
	if(document.getElementById('InvoiceAdjustTax')) {
		elem = 'InvoiceAdjustTax';
	}
	else {
		elem = 'InvoiceDetailTax' + invoiceDetailID;
	}
	//GetAJAXResult(elem, url, 'group1');
	var returnVal, vals, taxAmount, county, state, city, zip;
	AjaxRequest.get(
		{
			'url':url
			,'timeout':3000
			,'onTimeout':function() {
				return false;
			}
			,'onSuccess':function(req){ 
				returnVal = req.responseText;
				if(returnVal.indexOf('|') != -1) {
					vals = returnVal.split('|');
					taxAmount = vals[0];
					county = vals[1];
					state = vals[2];
					city = vals[3];
					zip = vals[4];
					document.getElementById(elem).value = taxAmount;
					if(document.getElementById('detailCounty')) {
						document.getElementById('detailCounty').value = county;
						document.getElementById('detailState').value = state;
						document.getElementById('detailCity').value = city;
						document.getElementById('detailZip').value = zip;
						//alert(county + '\n' + state + '\n' + city + '\n' + zip);
					}
				}
				else {
					document.getElementById(elem).value = taxAmount;
				}
				//return returnVal;
			}
			,'onError':function(){
				returnVal = "Error connecting to the web service.";
				//return returnVal;
			}
			,'groupName':'group1'
		}
	);
	document.getElementById('bnaTaxDiv').style.display = 'none';
	showBNATaxPopupVisible = false;
	taxElementIsActive = false;
}
var showCallCenterUserSchedulePopupVisible = false;
function showCallCenterUserSchedulePopup(evt, userID, userType) {
	var layerName = 'ccUserSchedule';
	var layerWidth = 450;
	var layerHeight = 150;
	if(! showCallCenterUserSchedulePopupVisible) {
		buildPopup(layerName);
		showCallCenterUserSchedulePopupVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	var url = '/app/default.asp?W=ShowCallCenterUserSchedule&P=' + userID + '&P=' + userType + '&X=1';
	GetAJAXResult(layerName, url);
}
function saveCallCenterUserSchedule(theForm, layerName) {
	GetAJAXPostResult(theForm, layerName);
	hideMe(layerName);
}
function deleteCallCenterUserSchedule(formName, layerName, dateID) {
	var previousAction = document.getElementById(formName).action;
	document.getElementById(formName).action = '/app/default.asp?W=DeleteCallCenterUserSchedule&P=' + dateID + '&X=1';
	GetAJAXPostResult(document.getElementById(formName), layerName);
	document.getElementById(formName).action = previousAction;
	hideMe(layerName);
}

function getTaskActualAmountFromInvoice(taskID, layerName, targetName) {
	targetName == 'TaskActualCost' ? formatAsCurrency = 0 : formatAsCurrency = 1;
	GetAJAXResult(targetName, '/app/default.asp?W=GetProjectTaskActualCostFromInvoice&P=' + taskID + '&FormatAsCurrency=' + formatAsCurrency + '&X=1');
	hideMe(layerName);
}
function getProjectActualCostFromTaskInvoices(targetName, projectID) {
	GetAJAXResult(targetName, '/app/default.asp?W=GetProjectActualCostFromTaskInvoices&P=' + projectID + '&X=1');
}
function saveProjectTaskActualAmount(theForm, taskID, layerName) {
	GetAJAXPostResult(theForm, 'taskActualCost' + taskID);
	hideMe(layerName);
}
function updateProjectPercentCompleteFromTasks(targetName, projectID) {
	GetAJAXResult(targetName, '/app/default.asp?W=GetProjectPercentCompleteFromTasks&P=' + projectID + '&X=1');
}

function checkProjectDocumentForm() {
	if(checkForm('formPopup')){
		GetAJAXPostResult(document.getElementById('formPopup'), 'projectTaskDocumentsDiv');
		return false;
	}	
	else {
		return false;	
	}
}

function checkWorkOrderPriority(val) {
	var url = '/app/default.asp?W=GetWorkOrderPriorityDesc&P=' + val + '&X=1';
	GetAJAXResult('workOrderPriorityDescription', url, 'group1');
}
function checkServiceRequestPriority(val) {
	var url = '/app/default.asp?W=GetServiceRequestPriorityNotes&P=' + val + '&X=1';
	GetAJAXResult('serviceRequestOrderPriorityDescription', url, 'group1');
}
function validateAndClose() {
	if(checkForm('InvoiceExportToIIF')) {
		hideMe('exportToQuickBooksPopup');
		return true;
		//window.location.href = 'about:blank';
	}
	else {
		return false;
	}
}
function showMore() {
	if(document.getElementById('moreText').style.display == 'none') {
		document.getElementById('moreLink').innerText = 'Less';
		document.getElementById('moreText').style.display = 'block';
	}
	else {
		document.getElementById('moreLink').innerText = 'More';
		document.getElementById('moreText').style.display = 'none';
	}
}
		
function showHideFullDescription(evt, workOrderID, val) {
	if(val == 'more') {
		GetAJAXResultWithoutLoadingImage('woDesc' + workOrderID, '/app/default.asp?W=GetFullWorkOrderDescription&P=' + workOrderID + '&X=1', 'group1');
		document.getElementById('woDescLink' + workOrderID).innerHTML = 'less';	
	}
	else {
		GetAJAXResultWithoutLoadingImage('woDesc' + workOrderID, '/app/default.asp?W=GetShortenedWorkOrderDescription&P=' + workOrderID + '&X=1', 'group1');
		document.getElementById('woDescLink' + workOrderID).innerHTML = 'more';
	}
}
function postInternalNotesForm() {
	GetAJAXPostResult(document.getElementById('manageInternalNotesForm'), 'InternalNotesPopupDiv')
	return false;
}
function viewInternalNote(noteID) {
	GetAJAXResult('notesSectionDiv', '/app/default.asp?W=DisplayInternalNote&P=' + noteID + '&X=1', 'group1', false);
	//setTimeout("alert(document.getElementById('notesSectionDiv').innerHTML)", 1000);
}
function editInternalNote(noteID) {
	GetAJAXResult('notesEditSectionDiv', '/app/default.asp?W=EditInternalNote&P=' + noteID + '&X=1', 'group1', false);
}
function addLineToInternalNote(noteID) {
	GetAJAXResult('notesEditSectionDiv', '/app/default.asp?W=AddLineToInternalNote&P=' + noteID + '&X=1', 'group1', false);
}
function saveNoteStatusChange(noteID, noteStatusID, canEditNote) {
	DoAJAXNoteStatusChange('/app/default.asp?W=UpdateNoteStatusID&P=' + noteID + '&P=' + noteStatusID + '&X=1', 'group1', noteID, canEditNote);
}
function DoAJAXNoteStatusChange(url, groupName, noteID, canEditNote) {
	var returnVal;
	AjaxRequest.get(
		{
			'url':url
			,'timeout':3000
			,'onTimeout':function() {
				return false;
				//DoAJAXNoteStatusChange(url, groupName, noteID, canEditNote);
			}
			,'onSuccess':function(req){ 
				returnVal = req.responseText;
				canEditNote ? editInternalNote(noteID) : addLineToInternalNote(noteID);
				return returnVal;
			}
			,'onError':function(){
				returnVal = "Error connecting to the web service.";
				return returnVal;
			}
			,'groupName':groupName
		}
	);
}
function deleteInternalNote(noteID, referenceType, referenceID) {
	if(confirm('Are you sure you wish to delete this note?')) {
		//alert('/app/default.asp?W=ManageInternalNotes&P=' + referenceType.replace(' ','').toLowerCase() + '&P=' + referenceID + '&P=' + noteID + '&action=delete&X=1');
		document.getElementById('manageInternalNotesForm').action = '/app/default.asp?W=ManageInternalNotes&P=' + referenceType.replace(' ','').toLowerCase() + '&P=' + referenceID + '&P=' + noteID + '&action=delete&X=1';
		postInternalNotesForm();
	}
	else {
		return false;	
	}
}
function filterInternalNotes(noteType, referenceType, referenceID) {
	document.getElementById('manageInternalNotesForm').action = '/app/default.asp?W=ManageInternalNotes&P=' + referenceType.replace(' ','').toLowerCase() + '&P=' + referenceID + '&P=0&sfilter=' + noteType + '&X=1';
	postInternalNotesForm();
}
function goToNotesPrintView(typeID,referenceTypeID,referenceID,sensitivityLevelID,companyID,siteID,supplierID) {
	window.open('/app/default.asp?W=ViewInternalNotesList&P='+typeID+'&P='+referenceTypeID+'&P='+referenceID+'&P='+sensitivityLevelID+'&P='+companyID+'&P='+siteID+'&P='+supplierID+'&ShowPrintView=True&Z=1','','');
}
function displayInternalNotesNotifications(evt, noteID, referenceType, referenceID, sensitivityLevel, cc) {
	var toOrCc;
	showHideInternalNotesNotificationDiv(evt, cc);
	var sensitivityLevelID = document.getElementById('SensitivityLevel').value;
	var resultTarget = 'InternalNotesNotificationsDiv';
	if(cc != '') {
		toOrCc = 'Cc';
		var emailUserIds = document.getElementById('txtCcEmailUserIds').value;
		var emailTypeIds = document.getElementById('txtCcEmailTypeIds').value;
	}
	else {
		toOrCc = 'To';
		var emailUserIds = document.getElementById('txtEmailUserIds').value;
		var emailTypeIds = document.getElementById('txtEmailTypeIds').value;
	}
	var url = '/app/default.asp?W=InternalNotesNotifications&P=' + noteID + '&P=' + referenceType + '&P=' + referenceID + '&P=' + sensitivityLevelID + '&P=' + toOrCc + '&X=1';
	var group = 'group1';
	//document.getElementById(resultTarget).style.display = 'block';
	document.getElementById(resultTarget).innerHTML = '<img src="/app/images/timer_w.gif" width="16" height="16" style=""vertical-align:middle;"" /> Loading...';
	AjaxRequest.get(
		{
			'url':url
			,'onSuccess':function(req){ 
				if(document.getElementById(resultTarget)) {
					document.getElementById(resultTarget).innerHTML = req.responseText;
				}
				if(emailUserIds.indexOf(';') != -1) {
					var x = 1;
					var userIdArray = emailUserIds.split(';');
					var userTypeArray = emailTypeIds.split(';');
					while (document.getElementById('cb_' + x)) {
						for (var i = 0; i <= userIdArray.length; i ++) {
							//alert("document.getElementById('h1_' + x).value = " + document.getElementById('h1_' + x).value + "\nuserIdArray[i] = " + userIdArray[i]);
							if(document.getElementById('h1_' + x).value == userIdArray[i] && document.getElementById('h2_' + x).value == userTypeArray[i]) {
								document.getElementById('cb_' + x).checked = 1;
							}
						}
						x += 1;	
					}
				}
			}
			,'onError':function(req){
				document.getElementById(resultTarget).innerHTML = "Error connecting to the web service.";
			}
			,'groupName':group
		}
	);
}
function showHideInternalNotesNotificationDiv(evt, cc) {
	if(document.getElementById('InternalNotesNotificationsDiv').style.display == 'block') {
		document.getElementById('InternalNotesNotificationsDiv').style.display = 'none';
		if(document.getElementById('txtNoteDesc')) {
			document.getElementById('txtNoteDesc').focus();	
		}
	}
	else {
		document.getElementById('InternalNotesNotificationsDiv').style.display = 'block';
		//setElementPositionInRelationToMouseClick(evt, 'InternalNotesNotificationsDiv', 400, 150);
		if(cc != '') {
			setElementPositionInRelationToParentElement('InternalNotesNotificationsDiv', 'txtCcNotifications', 400, 150);
		}
		else {
			setElementPositionInRelationToParentElement('InternalNotesNotificationsDiv', 'txtNotifications', 400, 150);
		}
	}
}
function changeNotificationsVisibility(e) {
	if(e == '1') {
		document.getElementById('notifyButtonDiv').style.display = 'none';	
		document.getElementById('notifyValuesDiv').style.display = 'none';
		document.getElementById('notifyCcButtonDiv').style.display = 'none';	
		document.getElementById('notifyCcValuesDiv').style.display = 'none';
	}
	else {
		document.getElementById('notifyButtonDiv').style.display = 'block';	
		document.getElementById('notifyValuesDiv').style.display = 'block';
		document.getElementById('txtNotifications').value = '';
		document.getElementById('txtEmails').value = '';
		document.getElementById('txtEmailUserIds').value = '';
		document.getElementById('txtEmailTypeIds').value = '';
		document.getElementById('notifyCcButtonDiv').style.display = 'block';	
		document.getElementById('notifyCcValuesDiv').style.display = 'block';
		document.getElementById('txtCcNotifications').value = '';
		document.getElementById('txtCcEmails').value = '';
		document.getElementById('txtCcEmailUserIds').value = '';
		document.getElementById('txtCcEmailTypeIds').value = '';
	}
}
function hideInternalNotesNotificationDiv(evt) {
	document.getElementById('InternalNotesNotificationsDiv').style.display = 'none';
}
function validateManageInternalNotesForm() {
	 if(document.getElementById('NotifyUsersYN') && document.getElementById('txtNotifications').value.length > 0) {	
	 	if(confirm('Would you like to send a notification to the selected email addresses regarding this update?\nClick \'OK\' to send an email or click \'Cancel\' to continue without sending an email.')) {
			document.getElementById('NotifyUsersYN').value = 'yes';	
		}
		else {
			document.getElementById('NotifyUsersYN').value = 'no';
		}
	 }
	 return true;
}
function addSelectionToNotifications(evt, e, toOrCc) {
	var notifications;
	var emails;
	var emailUserIds;
	var emailUserTypes;
	if(toOrCc == 'To') {
		notifications = 'txtNotifications';
		emails = 'txtEmails';
		emailUserIds = 'txtEmailUserIds';
		emailTypeIds = 'txtEmailTypeIds';
	}
	else {
		notifications = 'txtCcNotifications';
		emails = 'txtCcEmails';
		emailUserIds = 'txtCcEmailUserIds';
		emailTypeIds = 'txtCcEmailTypeIds';
	}
	if(document.getElementById('cb_' + e).checked) {
		document.getElementById(notifications).value += document.getElementById('cb_' + e).value + '; ';
		document.getElementById(emails).value += document.getElementById('cb_' + e).value + '; ';
		document.getElementById(emailUserIds).value += document.getElementById('h1_' + e).value + ';';
		document.getElementById(emailTypeIds).value += document.getElementById('h2_' + e).value + ';';
	}
	else {
		var notificationsVal = document.getElementById(notifications).value;
		var userIdVal = document.getElementById(emailUserIds).value;
		var typeIdVal = document.getElementById(emailTypeIds).value;
		document.getElementById(notifications).value = notificationsVal.replace(document.getElementById('cb_' + e).value + '; ', '');
		document.getElementById(emails).value = notificationsVal.replace(document.getElementById('cb_' + e).value + '; ', '');
		document.getElementById(emailUserIds).value = userIdVal.replace(document.getElementById('h1_' + e).value + ';', '');
		document.getElementById(emailTypeIds).value = typeIdVal.replace(document.getElementById('h2_' + e).value + ';', '');
	}
}

var viewInvoicePayLayerVisible = false;
function showInvoicePayLayerPopup(evt, InvoiceID) {
	var layerName = 'invoicePayLayer';
	var layerWidth = 320;
	var layerHeight = 150;
	if(! viewInvoicePayLayerVisible) {
		buildPopup(layerName);
		viewInvoicePayLayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowInvoicePayLayerPopup&P=' + InvoiceID + '&X=1');
}

var viewInvoiceAcceptLayerVisible = false;
function showInvoiceAcceptLayerPopup(evt, InvoiceID, InvoicePONumber, dashboardLink) {
	var layerName = 'invoiceAcceptLayer';
	var layerWidth = 320;
	var layerHeight = 150;
	var invPONumAndLink = InvoicePONumber + dashboardLink;
	invPONumAndLink = escape(invPONumAndLink);
	if(! viewInvoiceAcceptLayerVisible) {
		buildPopup(layerName);
		viewInvoiceAcceptLayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowInvoiceAcceptLayerPopup&P=' + InvoiceID + '&P=' + invPONumAndLink + '&X=1');
}

var showBillToSiteInfoPopupVisible = false;
function showBillToSiteInfoPopup(evt, billToSiteID, siteID) {
	var layerName = 'billToSiteInfoLayer';
	var layerWidth = 440;
	var layerHeight = 150;
	if(! showBillToSiteInfoPopupVisible) {
		buildPopup(layerName);
		showBillToSiteInfoPopupVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowBillToSiteInfoPopup&P=' + billToSiteID + '&P=' + siteID + '&X=1');
}

var viewShowEditAcctNumberPopupVisible = false;
function showEditAcctNumberPopup(evt, invoiceID, methodName) {
	var layerName = 'editAcctNumberLayer';
	var layerWidth = 320;
	var layerHeight = 150;
	if(! viewShowEditAcctNumberPopupVisible) {
		buildPopup(layerName);
		viewShowEditAcctNumberPopupVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowEditAcctNumberPopup&P=' + invoiceID + '&P=' + methodName + '&X=1');
}

var viewShowEditVendorCheckNumberPopupVisible = false;
function showEditVendorCheckNumberPopup(evt, invoiceID, methodName) {
	var layerName = 'editVendorCheckNumberLayer';
	var layerWidth = 320;
	var layerHeight = 150;
	if(! viewShowEditVendorCheckNumberPopupVisible) {
		buildPopup(layerName);
		viewShowEditVendorCheckNumberPopupVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowEditVendorCheckNumberPopup&P=' + invoiceID + '&P=' + methodName + '&X=1');
}

var viewSaveCustomReportsQueryLayerVisible = false;
function showSaveCustomReportsQuery(evt, reportID) {
	var layerName = 'customReportsQueryLayer';
	var layerWidth = 400;
	var layerHeight = 250;
	if(! viewSaveCustomReportsQueryLayerVisible) {
		buildPopup(layerName);
		if(! isIE6orEalier) {
			viewSaveCustomReportsQueryLayerVisible = true;
		}
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowSaveCustomReportsQueryPopup&P=' + reportID + '&X=1');
}

var viewScheduledServicePopupLayerVisible = false;
function viewScheduledServicePopup(evt, scheduledServiceID) {
	var layerName = 'scheduledMaintenancePopupLayer';
	var layerWidth = 520;
	var layerHeight = 300;
	if(! viewScheduledServicePopupLayerVisible) {
		buildPopup(layerName);
		viewScheduledServicePopupLayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ViewScheduledServicePopup&P=' + scheduledServiceID + '&X=1');
}

var viewCloseOrReopenServiceRequestVisible = false;
function closeOrReopenServiceRequest(evt, serviceRequestID, closeOrReopen) {
	var layerName = 'serviceRequestPopupLayer';
	var layerWidth = 400;
	var layerHeight = 250;
	if(! viewCloseOrReopenServiceRequestVisible) {
		buildPopup(layerName);
		viewCloseOrReopenServiceRequestVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ViewCloseOrReopenServiceRequestPopup&P=' + serviceRequestID + '&P=' + closeOrReopen + '&X=1');
}

function getCustomReportsFormValues() {
	var selUsers = '';
	var selDispatchers = '';
	var selStatuses = '';
	var selectedServices = '';
	var selectedPriorities = '';
	var selectedWorkOrderTypes = '';
	if(document.getElementById('UserName')) {
		if(document.getElementById('UserName').value != '0') {
			var userElement = document.getElementById('UserName');
			for(var i = 0; i < userElement.options.length; i ++) {
				if(userElement.options[i].selected) {
					if(selUsers == '') {
						selUsers = userElement.options[i].value;	
					}
					else {
						selUsers += ',' + userElement.options[i].value;
					}
				}
			}
		}
		else {
			selUsers = '0';	
		}
	}
	else {
		selUsers = '0';	
	}
	if(document.getElementById('Dispatcher')) {
		if(document.getElementById('Dispatcher').value != '0') {
			var dispatcherElement = document.getElementById('Dispatcher');
			for(var i = 0; i < dispatcherElement.options.length; i ++) {
				if(dispatcherElement.options[i].selected) {
					if(selDispatchers == '') {
						selDispatchers = dispatcherElement.options[i].value;	
					}
					else {
						selDispatchers += ',' + dispatcherElement.options[i].value;
					}
				}
			}
		}
		else {
			selDispatchers = '0';	
		}
	}
	else {
		selDispatchers = '0';	
	}
	if(document.getElementById('SelectedPriorityID')) {
		if(document.getElementById('SelectedPriorityID').value != '0') {
			var priorityElement = document.getElementById('SelectedPriorityID');
			for(var i = 0; i < priorityElement.options.length; i ++) {
				if(priorityElement.options[i].selected) {
					if(selectedPriorities == '') {
						selectedPriorities = priorityElement.options[i].value;	
					}
					else {
						selectedPriorities += ',' + priorityElement.options[i].value;
					}
				}
			}
		}
		else {
			selectedPriorities = '0';	
		}
	}
	else {
		selectedPriorities = '0';	
	}
	if(document.getElementById('SelectedWorkOrderType')) {
		if(document.getElementById('SelectedWorkOrderType').value != '0') {
			var workOrderTypeElement = document.getElementById('SelectedWorkOrderType');
			for(var i = 0; i < workOrderTypeElement.options.length; i ++) {
				if(workOrderTypeElement.options[i].selected) {
					if(selectedWorkOrderTypes == '') {
						selectedWorkOrderTypes = workOrderTypeElement.options[i].value;	
					}
					else {
						selectedWorkOrderTypes += ',' + workOrderTypeElement.options[i].value;
					}
				}
			}
		}
		else {
			selectedWorkOrderTypes = '0';	
		}
	}
	else {
		selectedWorkOrderTypes = '0';	
	}
	if(document.getElementById('xServices')) {
		var servicesElement = document.getElementById('xServices');
		for(var i = 0; i < servicesElement.options.length; i ++) {
			if(servicesElement.options[i].selected) {
				if(selectedServices == '') {
					selectedServices = servicesElement.options[i].value;	
				}
				else {
					selectedServices += ',' + servicesElement.options[i].value;
				}
			}
		}
	}
	if(document.getElementById('StatusOfItems')) {
		var statusElement = document.getElementById('StatusOfItems');
		for(var i = 0; i < statusElement.options.length; i ++) {
			if(statusElement.options[i].selected) {
				if(selStatuses == '') {
					selStatuses = statusElement.options[i].value;	
				}
				else {
					selStatuses += ',' + statusElement.options[i].value;
				}
			}
		}
	}
	//alert('selUsers = ' + selUsers + '\nselectedServices = ' + selectedServices + '\nselStatuses = ' + selStatuses);
	document.getElementById('selectedOrderType').value = document.getElementById('Templates').value;
	document.getElementById('selectedSupplierID').value = document.getElementById('xSuppliers').value;
	document.getElementById('selectedServiceID').value = selectedServices;
	document.getElementById('selectedStartDate').value = document.getElementById('StartDate').value;
	document.getElementById('selectedEndDate').value = document.getElementById('EndDate').value;
	document.getElementById('selectedStatus').value = selStatuses;
	document.getElementById('selectedSites').value = document.getElementById('SelSites').value;
	document.getElementById('selectedUsers').value = selUsers;
	document.getElementById('selectedDispatchers').value = selDispatchers;
	document.getElementById('selectAllAvailableSites').value = document.getElementById('cbAllAvailableSites').value;
	document.getElementById('selectedSearchSiteNumber').value = document.getElementById('SearchSiteNumber').value;
	document.getElementById('selectedSearchSiteName').value = document.getElementById('SearchSiteName').value;
	document.getElementById('selectedSearchSiteCity').value = document.getElementById('SearchSiteCity').value;
	document.getElementById('selectedSearchSiteState').value = document.getElementById('SearchSiteState').value;
	document.getElementById('selectedSearchSiteEntityName').value = document.getElementById('SearchSiteEntityName').value;
	document.getElementById('selectedSearchSiteNumberRange1').value = document.getElementById('SearchSiteNumberRange1').value;
	document.getElementById('selectedSearchSiteNumberRange2').value = document.getElementById('SearchSiteNumberRange2').value;
	document.getElementById('selectedSearchPriorityID').value = selectedPriorities;
	document.getElementById('selectedSearchWorkOrderType').value = selectedWorkOrderTypes;
	document.getElementById('selectedSearchExportedToQbYN').value = document.getElementById('SearchExportedToQbYN').value;
	document.getElementById('selectedDefaultSortBy').value = document.getElementById('DefaultSortBy').value;
	document.getElementById('selectedDefaultSortBy2').value = document.getElementById('DefaultSortBy2').value;
	document.getElementById('selectedDefaultSortBy3').value = document.getElementById('DefaultSortBy3').value;
	document.getElementById('selectedApplyReportDatesTo').value = document.getElementById('ApplyReportDatesTo').value;
	if(document.getElementById('selectedSelectedRegionVPName') && document.getElementById('SelectedRegionVPName')) {
		document.getElementById('selectedSelectedRegionVPName').value = document.getElementById('SelectedRegionVPName').value;
	}
	if(document.getElementById('selectedSelectedDistrictManagerName') && document.getElementById('SelectedDistrictManagerName')) {
		document.getElementById('selectedSelectedDistrictManagerName').value = document.getElementById('SelectedDistrictManagerName').value;
	}
	for(var i = 1; i <= 23; i ++) {
		if(document.getElementById('column' + i)) {
			document.getElementById('selectedColumn' + i).value = document.getElementById('column' + i).value;
		}
		else {
			alert("document.getElementById('column" + i + "') does not exist!");	
		}
	}
	return true;
}

function selectAllSiteGroupSites(e) {
	var tags = document.getElementsByName('siteChk');
	for(var i = 0; i < tags.length; i ++) {
		if(e != '') {
			if(tags[i].id.indexOf('cbSite_' + e) != -1) {
				tags[i].checked = 1;
			}
		}
		else {
			tags[i].checked = 1;	
		}
	}
}

var viewInvoiceRejectLayerVisible = false;
function showInvoiceRejectLayerPopup(evt, InvoiceID, rejectInvoiceStatus) {
	var layerName = 'invoiceRejectLayer';
	var layerWidth = 320;
	var layerHeight = 150;
	var queryAdd = '';
	if(! viewInvoiceRejectLayerVisible) {
		buildPopup(layerName);
		viewInvoiceRejectLayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	//toContractorYN ? queryAdd = '&ToContractor=1' : queryAdd = '';
	GetAJAXResult(layerName, '/app/default.asp?W=ShowInvoiceRejectLayerPopup&P=' + InvoiceID + '&P=' + rejectInvoiceStatus + '&X=1');
}

var showAddOtherNTEPopupVisible = false;
function showAddOtherNTEPopup(evt, target, workOrderID) {
	var layerName = 'addOtherNTEPopup';
	var layerWidth = 360;
	var layerHeight = 100;
	if(! showAddOtherNTEPopupVisible) {
		buildPopup(layerName);
		showAddOtherNTEPopupVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowAddOtherNTEPopup&P=' + target + '&P=' + workOrderID + '&X=1');
}

function deleteNTEAmount(workOrderID) {
	var nteValue = document.getElementById('NotToExceed').value;
	var currentLoc = location.href;
	if(currentLoc.indexOf('&loc=') != -1) {
		// we need to strip out the "&loc=" section of the querystring
		var locStart = currentLoc.indexOf('&loc=');
		currentLoc = currentLoc.substring(0, locStart);
	}
	currentLoc = currentLoc.replace('?', '_ques_');
	while (currentLoc.indexOf('&') != -1) {
		currentLoc = currentLoc.replace('&', '_amp_');
	}
	while (currentLoc.indexOf('=') != -1) {
		currentLoc = currentLoc.replace('=', '_equal_');
	}
	
	if(confirm('Are you sure you want to delete the amount of $' + nteValue + '?')) {
		location.href = '/app/default.asp?W=DeleteNTEValue&P=' + nteValue + '&WorkOrderID=' + workOrderID + '&currentLoc=' + currentLoc + '&X=1'; 	
	}
}

var showChangeServiceCategoryPopupVisible = false;
function showChangeServiceCategoryPopup(evt, target, workOrderID, serviceRequestID) {
	if(serviceRequestID == 'undefined') {
		serviceRequestID = '';	
	}
	var layerName = 'changeServiceCatPopup';
	var layerWidth = 440;
	var layerHeight = 100;
	if(! showChangeServiceCategoryPopupVisible) {
		buildPopup(layerName);
		showChangeServiceCategoryPopupVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowChangeServiceCategoryPopup&P=' + target + '&P=' + workOrderID + '&serviceRequestID=' + serviceRequestID + '&X=1');
}
function allowServiceCatAssignmentToVendor() {
	document.getElementById('allowServiceCatAssignment').value = '1';
}
function postChangeServiceCatForm(resultTarget) {
	var selectedServiceID = document.getElementById('ServiceID').value;
	var allowServiceCatAssignment = document.getElementById('allowServiceCatAssignment').value;
	var refreshThePage = false;
	if((selectedServiceID.indexOf('NA') != -1 && allowServiceCatAssignment == '1') || selectedServiceID.indexOf('NA') == -1) {
		//alert(document.getElementById('ServiceID').selectedIndex);
		if(document.getElementById('ServiceID').options[document.getElementById('ServiceID').selectedIndex].innerText == undefined) {
			refreshThePage = true;
		}
		else {
			document.getElementById('ServiceName').value = document.getElementById('ServiceID').options[document.getElementById('ServiceID').selectedIndex].innerText;	
		}
	}
	GetAJAXPostResult(document.getElementById('changeServiceCatForm'), resultTarget);
	hideMe('changeServiceCatPopup');
	if(refreshThePage) {
		window.setTimeout('location.href = location.href', 500);
	}
	return false;
}

var showChangeWorkOrderTypePopupVisible = false;
function showChangeWorkOrderTypePopup(evt, target, workOrderID) {
	var layerName = 'changeWorkOrderTypePopup';
	var layerWidth = 300;
	var layerHeight = 100;
	if(! showChangeWorkOrderTypePopupVisible) {
		buildPopup(layerName);
		showChangeWorkOrderTypePopupVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowChangeWorkOrderTypePopup&P=' + target + '&P=' + workOrderID + '&X=1');
}

function postChangeWorkOrderTypeForm(resultTarget) {
	GetAJAXPostResult(document.getElementById('changeWorkOrderTypeForm'), resultTarget);
	hideMe('changeWorkOrderTypePopup');
	return false;
}

var showChangeWorkOrderPriorityPopupVisible = false;
function showChangeWorkOrderPriorityPopup(evt, target, workOrderID) {
	var layerName = 'changeWorkOrderPriorityPopup';
	var layerWidth = 300;
	var layerHeight = 100;
	if(! showChangeWorkOrderPriorityPopupVisible) {
		buildPopup(layerName);
		showChangeWorkOrderPriorityPopupVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowChangeWorkOrderPriorityPopup&P=' + target + '&P=' + workOrderID + '&X=1');
}

function postChangeWorkOrderPriorityForm(resultTarget) {
	GetAJAXPostResult(document.getElementById('changeWorkOrderPriorityForm'), resultTarget);
	hideMe('changeWorkOrderPriorityPopup');
	return false;
}

var showChangeEquipmentPopupVisible = false;
function showChangeEquipmentPopup(evt, target, workOrderID) {
	var layerName = 'changeEquipmentPopup';
	var layerWidth = 440;
	var layerHeight = 100;
	if(! showChangeEquipmentPopupVisible) {
		buildPopup(layerName);
		showChangeEquipmentPopupVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowChangeEquipmentPopup&P=' + target + '&P=' + workOrderID + '&X=1');
}
function postChangeEquipmentForm(resultTarget) {
	//document.getElementById('changeEquipmentForm').submit();
	GetAJAXPostResult(document.getElementById('changeEquipmentForm'), resultTarget);
	hideMe('changeEquipmentPopup');
	return false;
}

var showChangeCostCenterPopupVisible = false;
function showChangeCostCenterPopup(evt, workOrderID, serviceRequestID) {
	var layerName = 'changeCostCenterPopup';
	var layerWidth = 310;
	var layerHeight = 100;
	if(! showChangeCostCenterPopupVisible) {
		buildPopup(layerName);
		showChangeCostCenterPopupVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowChangeCostCenterPopup&P=' + workOrderID + '&P=' + serviceRequestID + '&X=1');
}

var showChangePONumberPopupVisible = false;
function showChangePONumberPopup(evt, workOrderID) {
	var layerName = 'addChangePONumberPopup';
	var layerWidth = 310;
	var layerHeight = 100;
	if(! showChangePONumberPopupVisible) {
		buildPopup(layerName);
		showChangePONumberPopupVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowChangePONumberPopup&P=' + workOrderID + '&X=1');
}

var showEditJobCostPopupVisible = false;
function showEditJobCostPopup(evt, target, workOrderID) {
	var layerName = 'editJobCostPopup';
	var layerWidth = 310;
	var layerHeight = 100;
	if(! showEditJobCostPopupVisible) {
		buildPopup(layerName);
		showEditJobCostPopupVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=EditJobCostPopup&P=' + target + '&P=' + workOrderID + '&X=1');
}

function saveEditJobCostForm(targetName) {
	GetAJAXPostResult(document.getElementById('editJobNumberForm'), targetName);
	hideMe('editJobNumberPopup');
	return false;
}

var showEditBatchNumberPopupVisible = false;
function showEditBatchNumberPopup(evt, target, workOrderID) {
	var layerName = 'editBatchNumberPopup';
	var layerWidth = 310;
	var layerHeight = 100;
	if(! showEditBatchNumberPopupVisible) {
		buildPopup(layerName);
		showEditBatchNumberPopupVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=EditBatchNumberPopup&P=' + target + '&P=' + workOrderID + '&X=1');
}

function saveEditBatchNumberForm(targetName) {
	GetAJAXPostResult(document.getElementById('editBatchNumberForm'), targetName);
	hideMe('editBatchNumberPopup');
	return false;
}

var showEditCertifiedMailReceiptPopupVisible = false;
function showEditCertifiedMailReceiptPopup(evt, target, workOrderID) {
	var layerName = 'editCertifiedMailReceiptPopup';
	var layerWidth = 310;
	var layerHeight = 100;
	if(! showEditCertifiedMailReceiptPopupVisible) {
		buildPopup(layerName);
		showEditCertifiedMailReceiptPopupVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=EditCertifiedMailReceiptPopup&P=' + target + '&P=' + workOrderID + '&X=1');
}

function saveEditCertifiedMailReceiptForm(targetName) {
	GetAJAXPostResult(document.getElementById('editCertifiedMailReceiptForm'), targetName);
	hideMe('editCertifiedMailReceiptPopup');
	return false;
}

var showEditJobNumberPopupVisible = false;
function showEditJobNumberPopup(evt, target, workOrderID) {
	var layerName = 'editJobNumberPopup';
	var layerWidth = 310;
	var layerHeight = 100;
	if(! showEditJobNumberPopupVisible) {
		buildPopup(layerName);
		showEditJobNumberPopupVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=EditJobNumberPopup&P=' + target + '&P=' + workOrderID + '&X=1');
}

function checkCurrentPassword(e, layerName, userID, userType, email) {
	var url = '/app/default.asp?W=AJAXCheckCurrentPassword&X=1&P=' + escape(e) + '&P=' + userID + '&P=' + userType + '&P=' + email;
	GetAJAXResult(layerName, url, 'group1');	
}
function checkPasswordStrength(e, layerName, userID, userType, email) {
	var url = '/app/default.asp?W=AJAXValidatePasswordStrength&X=1&P=' + escape(e) + '&P=' + userID + '&P=' + userType + '&P=' + email;
	GetAJAXResult(layerName, url, 'group1');	
}
function checkConfirmPassword(e, password, confirmPassword) {
	if(password != confirmPassword) {
		document.getElementById(e).innerHTML = '<span style="color:red;">Your passwords do not match.</span>';	
	}
	else {
		document.getElementById(e).innerHTML = '';
	}
}

var showEditClientNTEPopupVisible = false;
function showEditClientNTEPopup(evt, target, workOrderID) {
	var layerName = 'editClientNTEPopup';
	var layerWidth = 310;
	var layerHeight = 100;
	if(! showEditClientNTEPopupVisible) {
		buildPopup(layerName);
		showEditClientNTEPopupVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=EditClientNTEPopup&P=' + target + '&P=' + workOrderID + '&X=1');
}

function saveEditClientNTEForm(targetName) {
	GetAJAXPostResult(document.getElementById('editClientNTEForm'), targetName);
	hideMe('editClientNTEPopup');
	return false;
}

var showExportCustomReportPopupVisible = false;
function showExportCustomReportPopup(evt, customReportID, doNotSubmit) {
	var layerName = 'exportCustomReportPopup';
	var layerWidth = 310;
	var layerHeight = 100;
	if(! showExportCustomReportPopupVisible) {
		buildPopup(layerName);
		if(! isIE6orEalier) {
			showExportCustomReportPopupVisible = true;
		}
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ExportCustomReportPopup&P=' + customReportID + '&doNotSubmit=' + doNotSubmit + '&X=1');
}

var createdInvoiceAlertVisible = false;
function showCreatedInvoiceAlert(invoiceIDs) {
	var layerName = 'createdInvoiceAlertPopup';
	var layerWidth = 300;
	var layerHeight = 200;
	if(! createdInvoiceAlertVisible) {
		buildPopup(layerName);
		createdInvoiceAlertVisible = true;
	}
	showMe(layerName);
	setElementPositionInCenterOfScreen(layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowCreatedInvoiceAlert&P=' + invoiceIDs + '&X=1');
}
function closeCreatedInvoiceAlert() {
	// the alert for suppliers that they have a currently opened invoice should only appear once a day
	// so we will set a cookie that will expire after 1 day
	var name = 'CreatedInvoiceAlert';
	var value = '1';
	var days = 1;
	createCookie(name,value,days);
	hideMe('createdInvoiceAlertPopup');
}

function resetNotToExceed() {
	if(document.getElementById('NotToExceed')) {
		document.getElementById('NotToExceed').value = '';
	}
}
function postNTEForm(resultTarget) {
	GetAJAXPostResult(document.getElementById('otherNTEForm'), resultTarget);
	hideMe('addOtherNTEPopup');
	return false;
}

var currentZIndex = 1000;

function chooseVendorOrCustomerInvoice(evt, invoiceID, templateID, status, userType, showChoice, isCustomer) {
	var defaultLink;
	var linkVendor;
	var linkCustomer;
	switch (status) {
		case '1':
			linkVendor = 'EditInvoice&P=' + invoiceID;
			templateID == '' ? linkCustomer = 'CompanyViewInvoice&P=' + invoiceID : linkCustomer = 'EditInvoiceFromTemplate&P=' + templateID + '&P=' + invoiceID;
			break;
		case '2':
			linkVendor = 'ViewInvoice&P=' + invoiceID;
			templateID == '' ? linkCustomer = 'CompanyViewInvoice&P=' + invoiceID : linkCustomer = 'PreviewInvoiceTemplate&P=' + templateID + '&P=' + invoiceID;
			break;
		case '3':
			linkVendor = 'ViewInvoice&P=' + invoiceID;
			templateID == '' ? linkCustomer = 'CompanyViewInvoice&P=' + invoiceID : linkCustomer = 'PreviewInvoiceTemplate&P=' + templateID + '&P=' + invoiceID;
			break;
		case '4':
			linkVendor = 'EditInvoice&P=' + invoiceID;
			templateID == '' ? linkCustomer = 'CompanyViewInvoice&P=' + invoiceID : linkCustomer = 'PreviewInvoiceTemplate&P=' + templateID + '&P=' + invoiceID;
			break;
	}
	if(showChoice && ! isCustomer) {
		var popupName = 'chooseVendorOrCustomerInvoiceDiv';
		if(! document.getElementById(popupName)) {
			document.body.insertAdjacentHTML('afterBegin', '<div id="'+ popupName + '" style="position:absolute;left:0px;top:0px;display:none;visibility:hidden;background-color:#FFFFFF;border:1px solid #000000;z-index:' + eval(currentZIndex + 2) + ';"></div>');	
		}
		setElementPositionInRelationToMouseClick(evt, popupName, 150, 50);
		document.getElementById(popupName).innerHTML = '<table style="width:100%;"><tr><td>Choose a view:</td><td style="text-align:right;"><a href="#" onclick="hideMe(\'' + popupName + '\');return false;" title="Cancel">X</a>&nbsp;</td></tr>' +
			'<tr><td colspan="2">&bull; <a href="/app/default.asp?W=' + linkVendor + '">Contractor Invoice</a></td></tr>' + 
			'<tr><td colspan="2">&bull; <a href="/app/default.asp?W=' + linkCustomer + '">Customer Invoice</a></td></tr></table>';
		showMe(popupName);
	}
	else {
		// automatically take the user to the correct screen
		if(isCustomer) {
			defaultLink = '/app/default.asp?W=' + linkCustomer;	
		}
		else {
			switch(userType) {
				case '1': //vendor
					defaultLink = '/app/default.asp?W=' + linkVendor;
					break;
				case '2': //admin
					if(status == '1' || status == '4') {
						defaultLink = '/app/default.asp?W=' + linkVendor;
					}
					else {
						defaultLink = '/app/default.asp?W=' + linkCustomer;
					}
					break;
				case '3': //user
					if(status == '1' || status == '4') {
						defaultLink = '/app/default.asp?W=' + linkVendor;
					}
					else {
						defaultLink = '/app/default.asp?W=' + linkCustomer;
					}
					break;
			}
		}
		location.href = defaultLink;
	}
}
var ie6Iframe;
function buildPopup(popupName) {
	document.body.insertAdjacentHTML('afterBegin', '<div id="' + popupName + '" style="position:absolute;left:0px;top:0px;display:none;visibility:hidden;z-index:' + eval(currentZIndex + 2) + ';"></div>');
	currentZIndex += 2;
	
}
function setZIndex(layerName) {
	if(document.getElementById(layerName)) {
		document.getElementById(layerName).style.zIndex = eval(currentZIndex + 1);
		currentZIndex += 2;
	}
}
function resetCurrentZIndex(e) {
	currentZIndex = e;	
}

function buildPopupWithinForm(popupName, formName) {
	if(document.getElementById(formName)) {
		document.getElementById(formName).insertAdjacentHTML('afterBegin', '<div id="' + popupName + '" style="position:absolute;left:0px;top:0px;display:none;visibility:hidden;z-index:' + eval(currentZIndex + 2) + ';"></div>');
		currentZIndex += 2;
	}
}

function showCalendar(target, yearScroll, timeComp) {
	var nCal = new calendar2(target);
	nCal.year_scroll = yearScroll;
	nCal.time_comp = timeComp;
	nCal.popup();
}

function GetAJAXResultWithScript(resultTarget, url, groupName) {
	//myTimeout = setTimeout("document.getElementById('"+resultTarget+"').innerHTML='<img src=..//"images/loading.gif/" width=\"15\" height=\"15\" /> Loading...'",50);
	document.getElementById(resultTarget).style.display='block';
	document.getElementById(resultTarget).innerHTML='<img src="/app/images/timer_w.gif" width="16" height="16" style=""vertical-align:middle;"" /> Loading...';
	if(document.getElementById('btnSubmit')) {
		document.getElementById('btnSubmit').disabled = true;
	}
	AjaxRequest.get(
		{
			'url':url
			,'timeout':3000
			,'onTimeout':function() {
				return false;
				//clearTimeout(myTimeout);
				//GetAJAXResultWithScript(resultTarget, url, groupName);
			}
			,'onSuccess':function(req){ 
				document.getElementById(resultTarget).innerHTML=req.responseText; 	
				if(document.getElementById('btnSubmit')) {
					document.getElementById('btnSubmit').disabled = false;
				}
				var script = document.createElement('script');
				script.type = 'text/javascript';
				script.src = 'ScheduledServicesCal.js';
				document.getElementsByTagName('head')[0].appendChild(script);
				
				//clearTimeout(myTimeout);
			}
			,'onError':function(){
				document.getElementById(resultTarget).innerHTML="Error connecting to the web service.";
			}
			,'groupName':groupName
		}
	);
}

var deductLayerVisible = false;
function showDeductLayer(evt, invoiceID, siteID, supplierID) {
	var layerName = 'deductLayer';
	var layerWidth = 400;
	var layerHeight = 300;
	if(! deductLayerVisible) {
		buildPopup(layerName);
		deductLayerVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=ShowDeductLayer&P=' + invoiceID + '&P=' + siteID + '&P=' + supplierID + '&X=1');
}

var invoiceExportToExcelReportVisible = false;
function showInvoiceExportToExcelReport(evt) {
	var layerName = 'invoiceExportToExcelReport';
	var layerWidth = 300;
	var layerHeight = 120;
	if(! invoiceExportToExcelReportVisible) {
		//document.body.insertAdjacentHTML('afterBegin', '<div id="invoiceExportToExcelReport" style="position:absolute; left: 100; top:100;visibility:hidden; background-color:#D5DFF3; border: 1px solid #36415A;"></div>');
		buildPopup(layerName);
		invoiceExportToExcelReportVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, '/app/default.asp?W=InvoiceExportToExcelReport&X=1');
}

function checkUpdateMapAddressForm() {
	//var elem = document.getElementById;
	var addr = document.getElementById('addr').value;
	var addr2 = document.getElementById('addr2').value;
	var city = document.getElementById('city').value;
	var state = document.getElementById('state').value;
	var zip = document.getElementById('zip').value;
	var siteid = document.getElementById('SiteID').value;
	var supplierid = document.getElementById('SupplierID').value;
	var latitude;
	var longitude;
	if(document.getElementById('latitude')) {
		latitude = document.getElementById('latitude').value;
		longitude = document.getElementById('longitude').value;
	}
	updateMapCoordinates(siteid, supplierid, addr, addr2, city, state, zip, latitude, longitude);
	//return false;
}
var updateAddressPopupVisible = false;
function showUpdateAddressPopup(evt, siteID, supplierID) {
	var url = '/app/default.asp?W=ShowUpdateAddressPopup&P=' + siteID + '&P=' + supplierID + '&X=1';
	//alert(url);
	var layerName = 'updateAddressPopup';
	var layerWidth = 330;
	var layerHeight = 140;
	if(! updateAddressPopupVisible) {
		buildPopup(layerName);
		updateAddressPopupVisible = true;
	}
	showMe(layerName);
	setElementPositionInRelationToMouseClick(evt, layerName, layerWidth, layerHeight);
	GetAJAXResult(layerName, url, 'group1');
}
function updateMapCoordinates(siteID, supplierID, addr, addr2, city, state, zip, latitude, longitude) {
	var url = '/app/default.asp?W=CheckMapCoords&P=' + siteID + '&P=' + supplierID + '&P=' + escape(addr) + '&P=' + escape(addr2) + '&P=' + city + '&P=' + state + '&P=' + zip + '&latitude=' + latitude + '&longitude=' + longitude + '&X=1';
	var groupName = 'group1';
	AjaxRequest.get(
		{
			'url':url
			,'timeout':3000
			,'onTimeout':function() {
				return false;
			}
			,'onSuccess':function(req){
				if(req.responseText == '1') {
					location.reload();
				}
				else {
					alert('Address not found!');	
					//alert(req.responseText);
				}
				//clearTimeout(myTimeout);
			}
			,'onError':function(){
				alert('error');
				//document.getElementById(resultTarget).innerHTML="Error connecting to the web service.";
			}
			,'groupName':groupName
		}
	);
	//return false;
}
function wipeOutLatLong() {
	if(document.getElementById('latitude')) {
		document.getElementById('latitude').value = '';
		document.getElementById('longitude').value = '';
	}
}
function goToLatLongFinder() {
	var addr = document.getElementById('addr').value;
	var addr2 = document.getElementById('addr2').value;
	var city = document.getElementById('city').value;
	var state = document.getElementById('state').value;
	var zip = document.getElementById('zip').value;
	if(addr2 != '') {
		addr += ', ' + addr2;
	}
	var address = escape(addr + ', ' + city + ', ' + state + ' ' + zip);
	var url = 'http://www.batchgeocode.com/lookup/?q=' + address;
	var latLongWin = window.open(url, 'latLongWin', 'top=200,left=150,width=800,height=450,scrollbars=1,fullscreen=0,menubar=1,resizable=1,toolbar=0,location=0');
}

function getCitiesAndZipCodesByState(targetID, e, cityOrZip, supplierID) {
	var stateAbbr = '';
	var optionCount = 0;
	var vals = document.getElementById('geoOption' + e + 'State').options;
	for(i = 0; i < vals.length; i ++) {
		if(vals[i].selected) {
			//alert(vals[i].value);
			if(stateAbbr == '') {
				stateAbbr = vals[i].value.replace('SelState_', '').replace('SelProv_', '');
				optionCount += 1;
			}
			else {
				stateAbbr += ',' + vals[i].value.replace('SelState_', '').replace('SelProv_', '');
				optionCount += 1;
			}
		}
	}
	if(optionCount >= 5) {
		var locs;
		cityOrZip = 'city' ? locs = 'cities' : locs = 'zip codes';
		if(confirm('You have selected ' + optionCount + ' states.\nThis may take a several seconds to retrieve all of the ' + locs + '.\n\nAre you sure you wish to continue?')) {
			document.getElementById(targetID).innerHTML = '<option value="">Search in progress...</option><option value="">Please wait</option>';
			makeTheCall();
		}
		else {
			return false;	
		}
	}
	else {
		var selectBox = document.getElementById(targetID);
		selectBox.options.length = 0;
		selectBox.options[0] = new Option('Search in progress...', '');
		selectBox.options[1] = new Option('Please wait', '');
		//document.getElementById(targetID).innerHTML = '<option value="">Search in progress...</option><option value="">Please wait</option>';
		makeTheCall();
	}
	function makeTheCall() {
		var url = '/app/default.asp?W=AJAXGetCitiesAndZipCodesByState&P=' + stateAbbr + '&P=' + cityOrZip + '&P=' + supplierID + '&X=1';	
		var groupName = 'group1';
		AjaxRequest.get(
			{
				'url':url
				,'timeout':60000
				,'onTimeout':function() {
					alert('Request timed out');
					return false;
				}
				,'onSuccess':function(req){
					if(req.responseText == '') {
						document.getElementById(targetID).innerHTML = '<option value="">No Records Found</option>';
						document.getElementById(targetID).disabled = true;
					}
					else {
						var cities = req.responseText;
						document.getElementById(targetID).disabled = false;
						if(req.responseText.indexOf('<option') != -1) {
							document.getElementById(targetID).innerHTML = cities;
						}
						else {
							document.getElementById(targetID).options.length = 0;
							var optionVal = '';
							var optionText = '';
							var optionSelected = '0';
							var isSelected = false;
							var optionsArr = req.responseText.split('^');
							for(var i = 0; i <= optionsArr.length; i ++) {
								selectedText = '';
								var optionArr = optionsArr[i].split('|');
								if(optionArr[2] == '1') {
									isSelected = true;;	
								}
								optionText = optionArr[1];
								optionVal = optionArr[0];
								var selectBox = document.getElementById(targetID);
								selectBox.options[selectBox.length] = new Option(optionText, optionVal, false, isSelected);
							}
						}
					}
				}
				,'onError':function(){
					alert('error');
				}
				,'groupName':groupName
			}
		);
	}
}

function ShowInvoiceApprovedWarning() {
	if(confirm('Warning: This Deduction has already been Approved.\nIf you make a modification to it, the Deduction will need to be re-approved before it can be applied to a new invoice.\n\nAre you sure you wish to continue with your modifications?')) {
		return true;
	}
	else {
		return false;
	}
}
function ShowInvoiceDeductDeleteWarning() {
	if(confirm('Are you sure you want to delete this deduction?')) {
		return true;
	}
	else {
		return false;
	}
}
function checkInvoicePrintedYN(invoiceID) {
	var url = '/app/default.asp?W=CheckWhetherOrNotInvoiceWasPrinted&P=' + invoiceID + '&X=1';
	var groupName = 'group1';
	AjaxRequest.get(
		{
			'url':url
			,'timeout':30000
			,'onTimeout':function() {
				alert('Request timed out');
				return false;
			}
			,'onSuccess':function(req){
				if(req.responseText == '0') {
					markInvoiceAsPrinted();
					window.print();
					return true;
				}
				else {
					if(confirm('WARNING: This invoice has been flagged as having already been printed.\nAre you sure you wish to continue?')) {
						window.print();
						return true;
					}
					else {
						return false;
					}
				}
			}
			,'onError':function(){
				alert('error');
				return false;
			}
			,'groupName':groupName
		}
	);
	
	function markInvoiceAsPrinted() {
		url = '/app/default.asp?W=MarkInvoiceAsPrinted&P=' + invoiceID + '&X=1';
		AjaxRequest.get(
			{
				'url':url
				,'timeout':30000
				,'onTimeout':function() {
					alert('Request timed out.');
					return false;
				}
				,'onSuccess':function(req){
					return true;
				}
				,'onError':function(){
					alert('There was an error marking the invoice as "Printed".');
					return false;
				}
				,'groupName':groupName
			}
		);
	}
}

function setElementPositionInRelationToMouseClick(evt, elementID, elementWidth, elementHeight) {	
	// This function will position an element on the screen properly
	// based on the current position of the mouse.  This is especially
	// useful for placing a "popup" window next to the point where a 
	// mouse click takes place.
	//var curXPos = getCurrentXPosition(evt);
	//var curYPos = getCurrentYPosition(evt);
	var cursor = getPosition(evt);
	var curXPos = cursor.x;
	var curYPos = cursor.y;
	var winW;
	var winH;
	var styleTop;
	var styleLeft;
	if(window.innerWidth != undefined) {
		winW = window.innerWidth;
		winH = window.innerHeight;
	}
	else {
		winW = document.body.offsetWidth;
  		winH = document.body.offsetHeight;
	}
	if(elementHeight == null || elementHeight == '') {
		elementHeight = document.getElementById(elementID).style.height.toString().replace('px','');
		if(elementHeight == null || elementHeight == '') {
			elementHeight = 100;
		}
	}
	document.getElementById(elementID).style.width = elementWidth + 'px';
	document.getElementById(elementID).style.height = elementHeight + 'px';
	if(isNaN(curXPos) && isNaN(curYPos)) {
		setElementPositionInCenterOfScreen(elementID, elementWidth, elementHeight);
	}
	else {
		if((eval(curXPos) + eval(elementWidth)) > winW) {
			styleLeft = (eval(curXPos) - eval(elementWidth));
			if(styleLeft < 0) {
				styleLeft = 0;	
			}
			document.getElementById(elementID).style.left = styleLeft + 'px';
		}
		else {
			styleLeft = eval(curXPos);
			document.getElementById(elementID).style.left = styleLeft + 'px';
		}
		if((eval(curYPos) + eval(elementHeight)) > winH) {
			styleTop = (eval(curYPos) - eval(elementHeight));
			if(styleTop < 0) {
				styleTop = 0;	
			}
			document.getElementById(elementID).style.top = styleTop + 'px';
		}
		else {
			styleTop = eval(curYPos);
			document.getElementById(elementID).style.top = styleTop + 'px';
		}
	}
	
	
	if(isIE6orEalier) {
		var divPopup = document.getElementById(elementID);
		var iframeLeft = divPopup.offsetLeft + 'px';
		var iframeTop = divPopup.offsetTop + 'px';
		var iframeWidth = divPopup.offsetWidth + 'px';
		var iframeHeight = divPopup.offsetHeight + 'px';
		if (! document.getElementById('ie6Iframe')) {
			//alert('iframeLeft = ' + iframeLeft + '\niframeTop = ' + iframeTop + '\niframeWidth = ' + iframeWidth + '\niframeHeight = ' + iframeHeight);
			document.body.insertAdjacentHTML('afterBegin', '<iframe id="ie6Iframe" style="position:absolute;left:' + iframeLeft + ';top:' + iframeTop + ';width:' + iframeWidth + ';height:' + iframeHeight + ';filter:alpha(opacity=0);-moz-opacity: 0.80;" src="javascript:false;" frameborder="0" scrolling="no"></iframe>');
		}
		else {
			ie6Iframe = document.getElementById('ie6Iframe')
			ie6Iframe.style.left = iframeLeft;
			ie6Iframe.style.top = iframeTop;
			ie6Iframe.style.width = iframeWidth;
			ie6Iframe.style.height = iframeHeight;
			ie6Iframe.style.display = 'block';	
			
		}
	}
}
function setElementPositionInRelationToParentElement(elementID, parentElementID, elementWidth, elementHeight) {	
	// This function will position an element on the screen properly
	// based on the current position of the mouse.  This is especially
	// useful for placing a "popup" window next to the point where a 
	// mouse click takes place.
	var curXPos = DL_GetElementLeft(document.getElementById(parentElementID));
	var curYPos = DL_GetElementTop(document.getElementById(parentElementID));
	var winW;
	var winH;
	var isIE;
	if(document.getElementById && document.all) {
		isIE = true;	
	}
	if(window.innerWidth != undefined) {
		winW = window.innerWidth;
		winH = window.innerHeight;
	}
	else {
		winW = document.body.offsetWidth;
  		winH = document.body.offsetHeight;
	}
	if(elementHeight == null || elementHeight == '') {
		elementHeight = document.getElementById(elementID).style.height.toString().replace('px','');
		if(elementHeight == null || elementHeight == '') {
			elementHeight = 100;
		}
	}
	document.getElementById(elementID).style.width = elementWidth + 'px';
	document.getElementById(elementID).style.height = elementHeight + 'px';

	try {
		if((eval(curXPos) + eval(elementWidth)) > winW) {
			document.getElementById(elementID).style.left = (eval(curXPos) - eval(elementWidth)) + 'px';
		}
		else {
			//   alert(curXPos);
			document.getElementById(elementID).style.left = eval(curXPos) + 'px';
		}
		if((eval(curYPos) + eval(elementHeight)) > winH) {
			document.getElementById(elementID).style.top = (eval(curYPos) - eval(elementHeight)) + 'px';
		}
		else {
			document.getElementById(elementID).style.top = eval(curYPos) + 'px';
		}
	}
	catch(err) {
		alert('error');	
	}
}

function setElementPositionInCenterOfScreen(elementID, elementWidth, elementHeight) {	
	// This function will position an element on the screen properly
	// based on the current position of the mouse.  This is especially
	// useful for placing a "popup" window next to the point where a 
	// mouse click takes place.
	var curXPos = 0;
	var curYPos = 0;
	var winW;
	var winH;
	var styleTop;
	var styleLeft;
	if(window.innerWidth != undefined) {
		winW = window.innerWidth;
		winH = window.innerHeight;
	}
	else {
		winW = document.body.offsetWidth;
  		winH = document.body.offsetHeight;
	}
	if(elementHeight == null || elementHeight == '') {
		elementHeight = document.getElementById(elementID).style.height.toString().replace('px','');
		if(elementHeight == null || elementHeight == '') {
			elementHeight = 100;
		}
	}
	document.getElementById(elementID).style.width = elementWidth + 'px';
	document.getElementById(elementID).style.height = elementHeight + 'px';	
	document.getElementById(elementID).style.left = (winW / 2) - (elementWidth / 2) + 'px';
	document.getElementById(elementID).style.top = ((winH / 2) + document.documentElement.scrollTop) - (elementHeight / 2)  + 'px';

}

function DL_GetElementLeft(eElement)
{
    if (!eElement && this)                       // if argument is invalid
    {                                            // (not specified, is null or is 0)
        eElement = this;                         // and function is a method
    }                                            // identify the element as the method owner
    
    var nLeftPos = eElement.offsetLeft;          // initialize var to store calculations
    var eParElement = eElement.offsetParent;     // identify first offset parent element  
    while (eParElement != null)
    {                                            // move up through element hierarchy
        nLeftPos += eParElement.offsetLeft;      // appending left offset of each parent
        eParElement = eParElement.offsetParent;  // until no more offset parents exist
    }
    return nLeftPos;                             // return the number calculated
}


function DL_GetElementTop(eElement)
{
    if (!eElement && this)
    {
        eElement = this;
    }

    var nTopPos = eElement.offsetTop;
    var eParElement = eElement.offsetParent;
    while (eParElement != null)
    {
        nTopPos += eParElement.offsetTop;
        eParElement = eParElement.offsetParent;
    }
	
	if(document.getElementById && document.all) {
		// This is Internet Explorer
		nTopPos += 15;	
	}
    return nTopPos;
}



document.onmousedown=majMouseDown;
document.onmouseup=Function("majActive=false;CurrentLayer=null;");