function aboEnvironment() 
{
	this.dateFormat = "MM/DD/YYYY";
	this.today = new Date();
	this.integer = /^([0-9]||[-]||[+])*$/;
	this.hour = /^([0-9])*$/;
	this.minute = /^([0-9])*$/;
	this.decimal = /^([0-9]||[.]||[-]||[+])*$/;
	this.zip = /^[0-9]{5}$/;
	this.zipFormated = /^[0-9]{5}[-]{1}[0-9]{4}$/;
	this.zipUnformated = /^[0-9]{9}$/;
	this.phoneUnformated = /^[0-9]{10}$/; 
	this.phoneFormated = /^[(][0-9]{3}[)][ ][0-9]{3}[-][0-9]{4}$/;
	this.phoneFormat = /^([0-9]|[-]|[+]|[.]|[(]|[)]|[ ]|[\/])*$/;
	this.emailFormat = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	this.baseURL = document.location.protocol + "//" + document.location.hostname + ":" + document.location.port;
	this.debug = false;
	this.trustedSite = null;
	this.classXML = "Microsoft.XMLDOM";
	this.classXMLHTTP = "Microsoft.XMLHTTP";
	this.checkboxChecked = false;	
	this.culture = null;
	this.modalWindow = null;
	this.modalEventHandler = null;
	this.modalInterval = null;
	this.executeMethodID = "ExecuteMethod";
	this.baseURL = "/Library";
}

aboEnvironment.prototype.initialize = function() 
{
	document.body.onMouseUp = "document.abo.tabClear(this);";
	this.tables = document.all.tags("TABLE");
	this.rows = document.all.tags("TR");
}
aboEnvironment.prototype.getDateString = function(theDate) 
{
	if (theDate.getMonth() < 9) theMonth = "0" + (theDate.getMonth() + 1);
	else theMonth = (theDate.getMonth() + 1);
	if (theDate.getDate() < 10) theDay = "0" + theDate.getDate();
	else theDay = theDate.getDate();
	theYear = theDate.getFullYear();
	if (this.dateFormat == "DD/MM/YYYY") theString = theDay + "/" + theMonth + "/" + theYear;
	else theString = theMonth + "/" + theDay + "/" + theYear;
	return theString;
}

aboEnvironment.prototype.getDate = function(dateString)
{
	var datePart = dateString.split("/");
	if (this.dateFormat == "DD/MM/YYYY")
	{
		return (new Date(datePart[2] + "/" + datePart[1] + "/" + datePart[0]))
	}
	else
	{
		return (new Date(datePart[2] + "/" + datePart[0] + "/" + datePart[1]));
	}
}

aboEnvironment.prototype.isDate = function(theValue) 
{
	var theDate;
	var theYear;
	var theMonth;
	var theDay;
	
	if (theValue != "") 
	{
		if (theValue == ".") 
		{
			theDate = new Date();
			
			return (this.getDateString(theDate, this.dateFormat));
		} 
		else if ((theValue.length == 6) && (theValue.indexOf("/") == -1) && (theValue.indexOf("-") == -1)) 
		{
			theString = new String(theValue);
			if (this.dateFormat == "DD/MM/YYYY") 
			{
				theDay = theString.substring(0, 2);
				theMonth = theString.substring(2, 4);
				theYear = new Number(theString.substring(4, 6));
			} 
			else 
			{
				theDay = theString.substring(2, 4);
				theMonth = theString.substring(0, 2);
				theYear = new Number(theString.substring(4, 6));
			}
		} 
		else 
		{
			theString = theValue.replace(/-/g, "/");
			if (this.dateFormat == "DD/MM/YYYY") 
			{
				theDay = theString.substring(0, theString.indexOf("/"));
				theString = theString.substring(theString.indexOf("/") + 1, theString.length);
				theMonth = theString.substring(0, theString.indexOf("/"));
			} 
			else 
			{
				theMonth = theString.substring(0, theString.indexOf("/"));
				theString = theString.substring(theString.indexOf("/") + 1, theString.length);
				theDay = theString.substring(0, theString.indexOf("/"));
			}
			theYear = new Number(theString.substring(theString.indexOf("/") + 1, theString.length));
		}
		
		if (theYear <= 50) theYear += 2000;
		
		if (theYear < 1753 || theYear > 9999)
		{
			return (null);	
		}
		
		theDate = new Date(theMonth + "/" + theDay + "/" + theYear);
		
		var dateString = this.getDateString(theDate, this.dateFormat);
		var datePart = dateString.split("/");
	
		if ( this.dateFormat == "DD/MM/YYYY"
			&& datePart[0] == theDay
			&& datePart[1] == theMonth
			&& datePart[2] == theYear )
		{
			return (dateString);
		}
		else if ( this.dateFormat != "DD/MM/YYYY"
			&& datePart[1] == theDay
			&& datePart[0] == theMonth
			&& datePart[2] == theYear )
		{
			return (dateString);
		}
		else
		{
			return (null);
		}
	}
	return ("");
}

aboEnvironment.prototype.isEmail = function (value)
{
    return this.emailFormat.test(value);
}

aboEnvironment.prototype.elementIsEmail = function (control)
{
    if (control.value.length > 0 && !this.isEmail(control.value))
    {
        alert(control.value + " is not a valid email address. Please enter a valid email address.");
        control.value = "";
        control.focus();
    }
}

aboEnvironment.prototype.elementIsDate = function(theElement) 
{
	theDateValue = this.isDate(theElement.value);
	if (theDateValue == null) {
		alert(theElement.value + " is an invalid date.");
		theElement.value = "";
		theElement.focus();
	} else theElement.value = theDateValue;
	/*if (theDateValue != "" && theDateValue < 01/01/1753 || theDateValue > 12/31/9999 ){
		alert(theElement.value + " Must be between 01/01/1753 12:00:00 AM and 12/31/9999 11:59:59 PM."); 
		theElement.value = "";
		theElement.focus();
	} else theElement.value = theDateValue;*/
}
aboEnvironment.prototype.isZip = function(theValue)
{
	return (this.zip.test(theValue) || this.zipFormated.test(theValue) || this.zipUnformated.test(theValue));
}
aboEnvironment.prototype.elementIsZip = function(theElement)
{
	this.culture = document.abo.culture;
	if (theElement.value > "")
	{
		
		if (this.culture == "en-US")
		{	
			if (!this.isZip(theElement.value))
			{	
				alert("'" + theElement.value + "' is an incorrect Zip Code format.\r\nEnter a 5-digit format (xxxxx) or 9-digit format (xxxxx-xxxx)\r\nAlternatively enter 9 digits (xxxxxxxxx) and it will be automatically formatted.");
				theElement.value = "";
				setTimeout("document.getElementById('" + theElement.id + "').focus();", 1);
			}
			else if (this.zipUnformated.test(theElement.value))
			{
				theElement.value = theElement.value.substring(0,5) + "-" + theElement.value.substring(5);
			}
		}
		else if (this.culture == "en-GB")
		{}
	}	
}

aboEnvironment.prototype.isPhone = function(theValue)
{
	return (this.phoneUnformated.test(theValue) || this.phoneFormated.test(theValue))
}

// Check if culture is british and if so validate and format accordingly
aboEnvironment.prototype.isPhoneGB = function(theValue)
{
	return (this.phoneUnformatedGB.test(theValue) || this.phoneFormatedGB.test(theValue))
}

aboEnvironment.prototype.elementIsPhone = function(theElement)
{
	this.culture = document.abo.culture;
	
	if (theElement.value > "")
	{
		
		if (this.culture == "en-US")
		{
			if (!this.isPhone(theElement.value))
				{
					alert("'" + theElement.value + "' is an invalid phone format.\r\nValid format is (xxx) xxx-xxxx\r\nAlternatively, Enter 10 digits and the system will format the number for you.");
					theElement.value = "";
					theElement.focus();
				}
			else if (this.phoneUnformated.test(theElement.value))
			{
				theElement.value = "(" + theElement.value.substring(0,3) + ") " + theElement.value.substring(3,6) + "-" + theElement.value.substring(6,10);
			}
		}
		else
		{
			if (!this.phoneFormat.test(theElement.value))
			{
				alert("'" + theElement.value + "' is an invalid phone format.");
				theElement.value = "";
				theElement.focus();
			}
		}		
	}	
}

aboEnvironment.prototype.isMoney = function(theValue) 
{
	var theResult = "";
	if (theValue > "") {
		theValue = theValue.replace(/\$/g, "");
		theValue = theValue.replace(/,/g, "");
		theMoney = new Number(theValue);
		if (isNaN(theMoney)) return (null);
		theResult = '' + Math.round(theMoney*100)/100;
		for (i=0; i<theResult.length; i++) {
			if (theResult.charAt(i) == '.') break;
		}
		if (i == theResult.length) theResult += ".00";
		else if (i == (theResult.length-1)) theResult += "00";
		else if (i == (theResult.length-2)) theResult += "0";
	} 
	return theResult;
}

aboEnvironment.prototype.elementIsMoney = function(theElement) 
{
	theMoneyValue = this.isMoney(theElement.value);
	if (theMoneyValue == null) {
		alert(theElement.value + " is an invalid monetary value.");
		theElement.value = "";
		theElement.focus();
	}
	else if (theElement.length >= 15) {
		alert(theElement.value + " is too large a monetary value.");
		theElement.value = "";
		theElement.focus();
	}
	 else {
		if (theElement.value < 0)
		{
			alert(theElement.value + " is an invalid monetary value.");
			theElement.value = "";
			theElement.focus();
		}
		else
		{
			theMoneyLeft = theMoneyValue.substring(0, theMoneyValue.indexOf("."));
			theCount = 0;
			theMoneyFormatted = "";
			for (var i=theMoneyLeft.length; i--; i==0) {
				theMoneyFormatted = theMoneyLeft.substring(i, i+1) + theMoneyFormatted;
				if ((++theCount == 3) && (i > 0)) {
					theMoneyFormatted = "," + theMoneyFormatted;
					theCount = 0;
				}
			}
			theElement.value = theMoneyFormatted + theMoneyValue.substring(theMoneyValue.indexOf("."), theMoneyValue.length);
			}
		}
}

aboEnvironment.prototype.isInteger = function(theValue)
{
	return (this.integer.test(theValue))
}

aboEnvironment.prototype.elementIsInteger = function(control, min, max)
{
	control.value = (control.value == "-") ? "" : control.value;
	if (!this.isInteger(control.value) || ((min != null && max != null) && (control.value < min || control.value > max)))
	{
		var message = (control.getAttribute("ValidationText") != null) ? control.getAttribute("ValidationText") : " is an invalid value."
		message += (min != null && !(min == 0 && max == 0)) ? "\r\nMinimum value allowed is " + min : "";
		message += (max != null && !(min == 0 && max == 0)) ? "\r\nMaximum value allowed is " + max : "";
		alert("'" + control.value + "' " + message);
		control.value = "";
		control.focus();
	}
}

aboEnvironment.prototype.isDecimal = function(theValue)
{
	return (this.decimal.test(theValue));
}

aboEnvironment.prototype.elementIsDecimal = function(theElement)
{
	theElement.value = (theElement.value == "-1") ? "" : theElement.value;
	if (!this.isDecimal(theElement.value))
	{
		alert(theElement.value + " is an invalid decimal number.");
		theElement.value = "";
		theElement.focus();
	}
	else
	{
		if (theElement.value.indexOf(".") == 0)
			theElement.value = "0" + theElement.value;
		
	}
}


aboEnvironment.prototype.isHour = function(theValue)
{
	return (this.hour.test(theValue))
}

aboEnvironment.prototype.elementIsHour = function(control, maxValue)
{
	
	if (!this.isHour(control.value) || control.value > maxValue)
	{

		var message = (control.getAttribute("ValidationText") != null) ? control.getAttribute("ValidationText") : " is an invalid hour. \r\nEnter a value between 0 and " + maxValue + ".";
		alert("'" + control.value + "' " + message);
		control.value = "";
		control.focus();
	}
	else 
	{
		if ((control.value >= 0 && control.value <= 9) && control.value.length < 2 && control.value.length != 0)
		{
			control.value = "0" + control.value;
		}
	}
}

aboEnvironment.prototype.isMinute = function(theValue)
{
	return (this.minute.test(theValue))
}

aboEnvironment.prototype.elementIsMinute = function(control)
{
	if (!this.isMinute(control.value) || control.value > 59)
	{
		var message = (control.getAttribute("ValidationText") != null) ? control.getAttribute("ValidationText") : " is an invalid minute. \r\nEnter a value between 0 and 59.";
		alert("'" + control.value + "' " + message);
		control.value = "";
		control.focus();
	}
	else 
	{
		if ((control.value >= 0 && control.value <= 9) && control.value.length < 2 && control.value.length != 0)
		{
			control.value = "0" + control.value;
		}
	}
}

aboEnvironment.prototype.tabClear = function() {
	if (window.self.tabFocus) {
		window.self.tabFocus.onblur = null;
		window.self.tabFocus = null;
	}
}

aboEnvironment.prototype.tabCapture = function(obj) {
	if (!window.self.workingObj) window.self.workingObj  = new Object();
	if (!window.self.workingId) window.self.workingId  = new Object();
	if (!window.self.tabMode) window.self.tabMode = new Object();

	if (new String(tabMode[event.srcElement.id]) == 'undefined') tabMode[event.srcElement.id] = false;
	status = 'TabMode = ' + tabMode[event.srcElement.id]
	window.self.theRange = document.selection.createRange();
	window.self.workingObj[obj.id] = obj;
	window.self.workingId[obj.id] = obj.id;
	
	if (event.keyCode == 9 && tabMode[event.srcElement.id]) {
		workingObj[event.srcElement.id].onblur = function anonymous () {
			this.focus();
			theRange.select();
		}
		theRange.text = "\t";
	}
	if (! tabMode[event.srcElement.id]) {
		if (workingObj[event.srcElement.id]) workingObj[event.srcElement.id].onblur = null;
	}
	if (event.keyCode == 84 && event.ctrlKey) {
		tabMode[event.srcElement.id] = !tabMode[event.srcElement.id];
		status = 'TabMode = ' + tabMode[event.srcElement.id];
	}
}

aboEnvironment.prototype.getFolderLocal = function(theRootFolder) {
	if (!this.isTrustedSite()) {
		this.errorHandler("This site is not trusted.  This page is attempting to access a folder on your local machine.");
		return (null);
	}
	try {
		osShell = new ActiveXObject("Shell.Application");
		if (theRootFolder != null) this.rootFolder = theRootFolder;
		var theFolder = osShell.BrowseForFolder(0, "Select folder", (32 | 64), this.rootFolder);
		return (theFolder);
	} catch (e) {
		alert(e.description);
		this.errorHandle("abo.getFolderLocal: " + e.description);
	}
}

aboEnvironment.prototype.getFolderNameLocal = function(theRootFolder) {
	theFolder = this.getFolderLocal(theRootFolder);
	theResult = "";
	while (theFolder != null) {
		alert(theResult);
		theResult = theFolder + "\\" + theResult;
		theFolder = theFolder.ParentFolder;
	}
	alert(theResult);
	return (theResult);
}

aboEnvironment.prototype.fileFolderName = function(theFileSpec) {
	var theResult = new String(theFileSpec);
	theResult = theResult.replace(/\\/g, "/");
	var theResultArray = theResult.split("/");
	theResult = theResultArray[0];
	for (var i=1; i<theResultArray.length-1; i++) theResult += "/" + theResultArray[i];
	return (theResult);
	
}

aboEnvironment.prototype.isTrustedSite = function() 
{
	if (this.trustedSite == null) {
		try {
			var theFileSystem = new ActiveXObject("Scripting.FileSystemObject");
			this.trustedSite = true;
			var theFileSystem = null;
		} catch (e) {
			this.trustedSite = false;
		}	
	}
	return (this.trustedSite);
}

aboEnvironment.prototype.errorHandle = function(theError) 
{
	try {
		alert("aboError: " + theError.description);
	} catch (e) {
		alert("aboError: " + theError);
	}
}

aboEnvironment.prototype.displayTab = function(theTab) {
	for (i=0; i<this.tables.length; i++) {
		if (this.tables[i].id.indexOf("Tab") >= 0) {
			if (this.tables[i].id == "Tab" + theTab) this.tables[i].style.display = "inline";
			else this.tables[i].style.display = "none";
		}
	}
}

aboEnvironment.prototype.urlAddParameter = function(theURL, theParameter, theValue) {
	var theResult = new String(theURL);
	theResult += (theResult.indexOf("?") > 0) ? "&" : "?";
	theResult += theParameter + "=";
	if (theValue != null) theResult += theValue;
	return (theResult);
}

aboEnvironment.prototype.xmlFromUrl = function(theURL, theConnectionString) {
	var xmlhttp = new ActiveXObject(this.classXMLHTTP);
	xmlhttp.Open("GET", this.urlAddParameter(theURL, "DTS", new Date().getTime()), false);
	if (theConnectionString != null) xmlhttp.setRequestHeader("ActionConnectionString", theConnectionString);
	xmlhttp.Send();

	var xmlDoc = new ActiveXObject(this.classXML);
	xmlDoc.async = false;
	xmlDoc.loadXML(xmlhttp.responseText);
	return (xmlDoc);
}

aboEnvironment.prototype.checkboxToggle = function(theName, theForm) {
	this.checkboxChecked = !this.checkboxChecked;
   	if (theForm == null) 
	{
		theForm = document.forms[0];
		if (document.forms.length > 0)
		{
			if (theForm.name == "PropertyLookUp")
				theForm = document.forms[1];
		}
	}
	with (theForm) for (i=0; i<elements.length; i++) {
		if (theName == null) {
			if (elements[i].type == "checkbox") elements[i].checked = this.checkboxChecked;
		} else  {
			if (elements[i].name == theName) elements[i].checked = this.checkboxChecked;
		}
	}
}

aboEnvironment.prototype.clearSelection = function() {
	var theTextRange = document.body.createTextRange();
	theTextRange.moveToPoint(0, 0);
	theTextRange.select();
}
aboEnvironment.prototype.formElementChecked = function(theElementName, theForm) {
   	if (theForm == null) 
	{
		theForm = document.forms[0];
		if (document.forms.length > 0)
		{
			if (theForm.name == "PropertyLookUp")
				theForm = document.forms[1];
		}
	}
	for (var i=0; i<theForm.elements.length; i++) {
		if ((theForm.elements[i].name == theElementName)
			&& (theForm.elements[i].type == "checkbox") 
			&& (theForm.elements[i].checked))
			return (true);
	}
	return (false);
}

aboEnvironment.prototype.getFileName = function(filePath) {
	filePath = filePath.replace(/\\/gi, "/");
	var fileArray = filePath.split("/");
	return (fileArray[fileArray.length-1]);
}

aboEnvironment.prototype.contactChooser = function(theElement) 
{
	theChooser = window.open(this.baseUrl + "/Contact/contactChooser.aspx", "ContactChooser", "toolbar=no,menubar=yes,scrollbars=yes,resizable=yes,width=600,height=500");
	theChooser.document.contactField = theElement;
	return (false);
}

aboEnvironment.prototype.windowPopUp = function(theURL, theWindowName)
{
	var win = window.open(theURL, theWindowName, "toolbar=no,menubar=yes,scrollbars=yes,resizable=yes,width=800,height=500");
	win.focus();
}

aboEnvironment.prototype.modalFocus = function()
{
	try
	{
		if (this.modalWindow.closed)
		{
			window.clearInterval(this.modalInterval);
			eval(this.modalEventHandler);
			this.modalWindow = null;
			return;
		}
		this.modalWindow.focus();
	}
	catch (e) {}
}
aboEnvironment.prototype.modalRemoveWatch = function()
{
	this.modalWindow = null;
	this.modalEventHandler = null;
}
aboEnvironment.prototype.modalShow = function(url, width, height, scrollbar, eventHandler, menubar)
{
	
	if (this.modalWindow != null && !this.modalWindow.closed)
	{
		this.modalWindow.close();
	}
		
	width = (width == null) ? 600 : width;
	height = (height == null) ? 200 : height;
	var top = Math.round((screen.height / 2) - (height / 2));
	var left = Math.round((screen.width / 2) - (width / 2));
	var settings = "width=" + width;
	settings += ", height=" + height;
	settings += ", top=" + top;
	settings += ", left=" + left;
	settings += ", resizable=no, status=no, toolbar=no, location=no";
	settings += ", menubar=" + ((menubar == null || menubar == 0) ? "no" : "yes");
	settings += ", scrollbars=" + ((scrollbar == null || scrollbar == 0) ? "no" : "yes");
	
	this.modalRemoveWatch();
	this.modalEventHandler = eventHandler;
	this.modalWindow = window.open(url, "", settings);
	this.modalWindow.focus();
	//this.modalInterval = window.setInterval("document.abo.modalFocus()", 1);
}

/// <summary>Gets the y position of the obj</summary>
function findY(obj)
{
	var y = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent) 
		{
			y += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
	{
		y += obj.y;
	}
	return (y);
}

/// <summary>Gets the x position of the obj</summary>
function findX(obj)
{
	var x = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			x += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x) 
	{
		x += obj.x;
	}
	return (x);
}

/// <summary>Hide all the select elements that overlap the item</summary>
function hideSelectElements(item)
{
	if (navigator.appName == "Microsoft Internet Explorer" && item != null)
	{
		var select = document.getElementsByTagName("SELECT");
		var itemX = findX(item);
		var itemY = findY(item);
		for (var index=0; index<select.length; index++)
		{
			var selectX = findX(select[index]);
			var selectY = findY(select[index]);
			if (!(selectX + select[index].offsetWidth <= itemX || itemX + item.offsetWidth <= selectX) && !(selectY + select[index].offsetHeight <= itemY || itemY + item.offsetHeight <= selectY))
			{
				select[index].style.visibility = "hidden";
			}
		}
	}
}

/// <summary>Show all the select elements</summary>
function showSelectElements()
{
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		var select = document.getElementsByTagName("SELECT");    
		for(var i = 0; i < select.length; i++)
		{   
			select[i].style.visibility = "visible"; 
		}
	}
}

// Standard event handler for all abo pages.  
// This can be overridden for any page; just make sure to call document.abo.initialize();
function loadPage() 
{
	document.abo.initialize();
}
// Function opens a popup windows displaying the select page of the lookup object.
// TheItem is the dropdown item.
// theLookupObject is the object been viewed in the dropdown.
// theURL is the url to the object select page.
function openLookupPopUp(theItem, theLookupObject, theURL)
{
	// Get the ID of the object selected.
	var theID;
	try
	{
		theID = document.getElementById(theItem).value;
	}
	catch (e)
	{
		theID = theItem;
	}
	// Dont open the windows if no id exists.
	if (theID != "" && theID != null)
	{
		// Open the popup
		var windowName = theLookupObject + theID.replace(/-/g, "_");
		var windowUrl = theURL + "?" + theLookupObject + "ID=" + theID
		var windowSettings = "toolbar=no,menubar=no,scrollbars=yes,resizable=yes,width=700,height=500";
		window.open(windowUrl, windowName, windowSettings);
	}
}

// Function opens a popup windows displaying the select page of the lookup object.
// TheItem is the dropdown item.
// theLookupObject is the object been viewed in the dropdown.
// theURL is the url to the object select page.
function openLookupPopUpSmall(theItem, theLookupObject, theURL)
{
	// Get the ID of the object selected.
	var theID;
	try
	{
		theID = document.getElementById(theItem).value;
	}
	catch (e)
	{
		theID = theItem;
	}
	// Dont open the windows if no id exists.
	if (theID != "" && theID != null)
	{
		// Open the popup
		var windowName = theLookupObject + theID.replace(/-/g, "_");
		var windowUrl = theURL + "?" + theLookupObject + "ID=" + theID
		var windowSettings = "toolbar=no,menubar=no,scrollbars=yes,resizable=yes,width=775,height=300";
		window.open(windowUrl, windowName, windowSettings);
	}
}
/// <summary>Open the specified url in a pop up window</summary>
/// <param name="windowName">A string containing the name of the window</param>
/// <param name="url">A string containing the url to open</param>
function openPopUp(windowName, url)
{
	var windowSettings = "toolbar=no,menubar=no,scrollbars=yes,resizable=yes,width=700,height=500";
	windowName = windowName.replace(/[ ]|[-]|[#]|[$]|[~]/g, "_");
	var popUp = window.open(url, windowName, windowSettings);
	popUp.focus();
	popUp = null;
}
/// <summary>Open the specified url in a pop up window and pass all the form elements to url.</summary>
/// <param name="exportMethod">A string containing the export method.</param>
/// <param name="objectName">A string containing the object name.</param>
/// <param name="url">A string containing the url to open.</param>
/// <param name="form">The form object to be used. This is an optional parameter and when not passed it will use the first form in the doucment.
/// <param name="param"></param>
/// </param>
function openExportPopUp(exportMethod, objectName, url, form, param)
{
	if (form == null)
	{
		form = document.forms[0];
		if (document.forms.length > 0)
		{
			if (form.name == "PropertyLookUp")
				form = document.forms[1];
		}
	}
	var windowSettings = "toolbar=no,menubar=yes,scrollbars=yes,resizable=yes,width=700,height=500";
	var windowUrl = url + "?ExportMethod=" + exportMethod;
	var windowName = objectName + "Export" + exportMethod;
	
	for (var index=0; index<form.elements.length; index++)
	{
		var element = form.elements[index];
		var elementName = null;
		if (exportMethod == "Search")
		{
			if (element.name.indexOf("_SearchString") > -1)
			{
				elementName = "SearchString";
			}
			else if (element.name.indexOf("_SearchBy") > -1)
			{
				elementName = "SearchBy";
			}
			else if (element.name.indexOf("_SortBy") > -1)
			{
				elementName = "SortBy";
			}
		}
		else if (element.name.indexOf("tbx") > -1 || element.name.indexOf("ddl") > -1)
		{
			elementName = element.name.substring(3);
		}
		else if (element.name.indexOf("rbn") > -1 && element.checked)
		{
			elementName = element.name.substring(3);
		}
		// If element is valid type add to the querystring
		if (elementName != null)
		{
			windowUrl += "&" + elementName + "=" + element.value;
		}
	}
	
	var location = new String(document.location);
	
	if (location.indexOf("?") > -1 && param)
	{
		windowUrl += (windowUrl.indexOf("?") > -1) ? "&" : "?";
		windowUrl += location.substring(location.indexOf("?") + 1);
	}
	window.open(windowUrl, windowName, windowSettings);
}

/// <summary>Open the specified url in a pop up window and pass all the form elements to url.</summary>
/// <param name="exportMethod">A string containing the export method.</param>
/// <param name="objectName">A string containing the object name.</param>
/// <param name="url">A string containing the url to open.</param>
/// <param name="form">The form object to be used. This is an optional parameter and when not passed it will use the first form in the doucment.
/// <param name="param"></param>
/// </param>
function openExportPopUpExcel(exportMethod, objectName, url, form, param)
{
	if (form == null)
	{
		form = document.forms[0];
		if (document.forms.length > 0)
		{
			if (form.name == "PropertyLookUp")
				form = document.forms[1];
		}
	}
	var windowSettings = "toolbar=no,menubar=yes,scrollbars=yes,resizable=yes,width=700,height=500";
	var windowUrl = url + "?ExportMethod=" + exportMethod;
	var windowName = objectName + "Export" + exportMethod;
	
	var iDs = " ";
	var idElementsName = "IDs";
	
	for (var index=0; index<form.elements.length; index++)
	{
		var element = form.elements[index];
		var elementName = null;
		if (exportMethod == "Search")
		{
			if (element.name.indexOf("_SearchString") > -1)
			{
				elementName = "SearchString";
			}
			else if (element.name.indexOf("_SearchBy") > -1)
			{
				elementName = "SearchBy";
			}
			else if (element.name.indexOf("_SortBy") > -1)
			{
				elementName = "SortBy";
			}
		}
		else if (element.name.indexOf("tbx") > -1 || element.name.indexOf("ddl") > -1)
		{
			elementName = element.name.substring(3);
		}
		else if (element.name.indexOf("rbn") > -1 && element.checked)
		{
			elementName = element.name.substring(3);
		}
		else if (element.name.indexOf("Expense") > -1)
		{
			if (element.checked == true)
			{
				iDs += element.value + ",";
			}
		}
		// If element is valid type add to the querystring
		if (elementName != null)
		{
			windowUrl += "&" + elementName + "=" + element.value;
		}
	}
	
	if (iDs != " ")
	{
		windowUrl += "&" + idElementsName + "=" + iDs;
	}
	
	var location = new String(document.location);
	
	if (location.indexOf("?") > -1 && param)
	{
		windowUrl += (windowUrl.indexOf("?") > -1) ? "&" : "?";
		windowUrl += location.substring(location.indexOf("?") + 1);
	}
	window.open(windowUrl, windowName, windowSettings);
}

/// <summary>Validate the form to check if items have been selected and confirms with the user if they want to execute the action</summary>
/// <param name="methodName">A string that identifies the action to be executed.</param>
/// <param name="methodLabel">A string containing the label of the action to be executed.</param>
/// <param name="objectName">A string containing the label of the module the action would be executed on.</param>
/// <param name="form">A form object. This is an optional parameter and when null it will use the first form in the document.</param>
/// <param name="checkSelection">A bool object. This is an optional parameter. When specified it omits the check to see if the object has been selected</param>
function executeAction(methodName, methodLabel, objectName, confirmAction, form, checkSelection)
{
	confirmAction = (confirmAction == null) ? true : confirmAction;
	checkSelection = (checkSelection == null) ? true : checkSelection;
	
	if (form == null && document.forms.length > -1)
	{
		form = document.forms[0];
		if (document.forms.length > 0)
		{
			if (form.name == "PropertyLookUp")
				form = document.forms[1];
		}
	}
	if (form != null)
	{
		if (checkSelection)
		{
			if 
			(
				(form.action.indexOf(objectName + "ID") == -1 && form.elements[objectName + "ID"] == null) 
				||	(form.elements[objectName + "ID"] != null && isChecked(objectName + "ID", form) == false)
			)
			{
				alert("You must select at least one item to " + methodLabel);
				return;
			}
		}
		
		// Ask for confirmation before executing the action if confirmAction is true
		var confirmResult = false;
		if (confirmAction)
		{
			var confirmMessage = "Are you sure you want to " + methodLabel;
			confirmMessage += (form.elements[objectName + "ID"] != null) ? " these items?" : " this " + objectName + "?";
			var confirmResult = confirm(confirmMessage);
		}
		// Execute Action
		if (confirmAction == false || confirmResult == true) 
		{
			var executeMethod = document.getElementById(document.abo.executeMethodID);
		    if (executeMethod != null) 
		    {
		    	executeMethod.value = methodName;
		    }			
			form.submit();
		}
	}
}

function ShowAll(strTag ,strAttribute)
{
    var elem = document.getElementsByTagName(strTag);
    
    for (var i =0;i<elem.length;i++)
	{
		if (elem[i].getAttribute(strAttribute)=="yes")
		{
			elem[i].style.display='table-row'; 
		}
		else if (elem[i].getAttribute(strAttribute)=="no")
		{
			elem[i].style.display='table-row'; 
		}
	}
}

function HideAll(strTag ,strAttribute)
{
    var elem = document.getElementsByTagName(strTag);
    
    for (var i =0;i<elem.length;i++)
	{
		if (elem[i].getAttribute(strAttribute)=="yes")
		{
			elem[i].style.display='none'; 
		}
		else if (elem[i].getAttribute(strAttribute)=="no")
		{
			elem[i].style.display='none'; 
		}
	}
}

function manifestElementControl(whichElement,whichFunction,whichProperty,whichValue)
{
	/* ----------------------------------------------------------------- //
	setCSS: Available list of CSS elements you can control:
	
	  TEXT PROPERTIES
	  ---------------
		textTransform: 			[capitalize,uppercase,lowercase,none]
		verticalAlign: 			[baseline,sub,super,top,text-top,middle,bottom,text-bottom]
		textAlign: 				[left,right,center,justify]
		textIndent:				[0px]
		lineHeight:				[0px]
		wordSpacing:			[0px]
		letterSpacing:			[0px]
		textDecoration:			[underline,overline,line-through,blink,none]
		
	  FONT PROPERTIES
	  ---------------
	  	fontFamily:				[verdana,arial,serif,sans-serif,cursive,fantasy,monospace]
		fontStyle:				[normal,italic,oblique]
		fontVariant:			[small-caps]
		fontWeight:				[lighter,normal,bold,bolder,100,200,300,400,500,600,700,800,900]
		fontSize:				[10px,150%,larger,smaller,xx-small,x-small,small,medium,large,x-large,xx-large]
		
	  COLOR AND BACKGROUND PROPERTIES
	  -------------------------------
	  	color:					[red,#FF0000,*rgb(R%, G%, B%),*rgb(R, G, B)]
		backgroundColor:		[red,#FF0000,*rgb(R%, G%, B%),*rgb(R, G, B)]
		backgroundImage:		[url(../images/myimage.gif)]
		backgroundRepeat:		[repeat,repeat-x,repeat-y,no-repeat]
		backgroundAttachment:	[scroll,fixed]
		backgroundPosition:		[vertical % horizontal %, center center (use: top,center,bottom,left,center,right)]
		
	  PLACEMENT PROPERTIES
	  --------------------
	  	marginTop:				[10px,auto]
		marginRight:			[10px,auto]
		marginBottom:			[10px,auto]
		marginLeft:				[10px,auto]
		paddingTop:				[10px,auto]
		paddingRight:			[10px,auto]
		paddingBottom:			[10px,auto]
		paddingLeft:			[10px,auto]
		borderWidth:			[thin,medium,thick,none]
		borderStyle:			[none,dotted,dashed,solid,double,groove,ridge,inset,outset]
		height:					[100px]
		width:					[100px]
		float:					[right,left,none]
		clear:					[right,left,both,none]
		top:					[10px]
		right:					[10px]
		bottom:					[10px]
		left:					[10px]
		zIndex:					[1]
		
	  CLASSIFICATION PROPERTIES
	  -------------------------
		display:				[none,block,inline,list-item]
		visibility:				[hidden,visible,collapse]
		whiteSpace:				[normal,pre,no-wrap]
		listStyleType:			[disc,circle,square,decimal,lower-roman,upper-roman,lower-alpha,upper-alpha]
		listStyleImage:			[url(../images/myimage.gif)]
		listStylePosition:		[inside,outside]
		
	  EXAMPLES
	  --------
	  	manifestElementControl("myElementID","setCSS","visibility","hidden");
		manifestElementControl("myElementID","setCSS","visibility","visible");
		manifestElementControl("myElementID","setCSS","left","100px");
		manifestElementControl("myElementID","setCSS","top","100px");
		manifestElementControl("myElementID","setCSS","backgroundColor","#466FC7");
		manifestElementControl("myElementID","setCSS","color","#FFFFFF");
		manifestElementControl("myElementID","setCSS","zIndex","1");
		
		manifestElementControl("leftBar,loader,Header","setCSS,setCSS,setCSS","visibility,visibility,backgroundColor","hidden,hidden,#466FC7");
		manifestElementControl("loader","setCSS","visibility","hidden");
	
	// ----------------------------------------------------------------- //
	setTEXT: Auto sets whichProperty to 'innerHTML'
	
	  EXAMPLES
	  --------
	  	manifestElementControl("myElementID","setTEXT","","<p>This is some text.</p>");
		manifestElementControl("myElementID","setTEXT","","<table><tr><td>This is some text.</td></tr></table>");
		
	// ----------------------------------------------------------------- */
	
	var ns6 = document.getElementById && !document.all;
	var ie = document.all;
	
	var whichElementArray = whichElement.split(",");
	var whichFunctionArray = whichFunction.split(",");
	var whichPropertyArray = whichProperty.split(",");
	var whichValueArray = whichValue.split(",");
	
	for(var i=0; i<whichElementArray.length; i++)
	{
		if (ie)
		{
			if (whichFunctionArray[i] == "setCSS"){ 	eval("document.all."+whichElementArray[i]+".style."+whichPropertyArray[i]+" = '"+whichValueArray[i]+"'");}
			if (whichFunctionArray[i] == "setTEXT"){	eval("document.all."+whichElementArray[i]).innerHTML = whichValueArray[i];}
		}
		else
		{
			if (whichFunctionArray[i] == "setCSS"){	eval("document.getElementById('"+whichElementArray[i]+"').style."+whichPropertyArray[i]+" = '"+whichValueArray[i]+"'");}
			if (whichFunctionArray[i] == "setTEXT"){	document.getElementById(whichElementArray[i]).innerHTML = whichValueArray[i];}
		}
	}
}

function ContextMenuSettings()
{
	//just disable the menu
	return false;
}

// standard form functions
function formExecuteMethod(theMethod, theForm, theItem) 
{
   	if (theForm == null) 
	{
		theForm = document.forms[0];
		if (document.forms.length > 0)
		{
			if (theForm.name == "PropertyLookUp")
				theForm = document.forms[1];
		}
	}

   	if (theItem != null) 
   	{
		if (!isChecked(theItem)) 
		{
			alert("You must select at least one item to " + theMethod + ".");
			return;
		}
   	}
	theForm.action = document.abo.urlAddParameter(theForm.action, "ExecuteMethod", theMethod);
	theForm.submit();
}
function formSubmit(recordStart, theForm) 
{
   	if (theForm == null) 
	{
		theForm = document.forms[0];
		if (document.forms.length > 0)
		{
			if (theForm.name == "PropertyLookUp")
				theForm = document.forms[1];
		}
	}
	with (theForm) 
	{
		RecordStart.value = recordStart;
		theForm.submit();
	}
}

function formSortBy(sortOrder, theForm) 
{
   	if (theForm == null) 
	{
		theForm = document.forms[0];
		if (document.forms.length > 0)
		{
			if (theForm.name == "PropertyLookUp")
				theForm = document.forms[1];
		}
	}
	with (theForm) 
	{
		SortBy.value = sortOrder;
		btnSearch.click();
	}
}

function aboTabOver(item)
{
	item.className = "tabBarOver";
}

function aboTabOut(item)
{
    item.className = "";
}

function toggleCheckbox(theElementName, theForm)
{
	if (theForm == null)
	{
		theForm = document.forms[0];
		if (document.forms.length > 0)
		{
			if (theForm.name == "PropertyLookUp")
				theForm = document.forms[1];
		}
	}

	var count = 0;
	
	with (theForm)
	{
	
		for (var i=0; i<theForm.elements.length; i++) 
		{
			if (theForm.elements[i].checked && theForm.elements[i].name==theElementName)
				count +=1;
		}
		
		if (count > 0)
		{
			for (var j=0; j<theForm.elements.length; j++) 
				if (theForm.elements[j].name==theElementName)
					theForm.elements[j].checked = false;
		}	
		else
		{
			for (var k=0; k<theForm.elements.length; k++)
				if (theForm.elements[k].name==theElementName)
					theForm.elements[k].checked = true;
		}
	}
}
			
function CheckedValues(elementName, form)
{
   	if (theForm == null) 
	{
		theForm = document.forms[0];
		if (document.forms.length > 0)
		{
			if (theForm.name == "PropertyLookUp")
				theForm = document.forms[1];
		}
	}
	var value = new Array();
	with (form)
	{
		if (elements[elementName] != null)
		{
			if (elements[elementName].length != null)
			{
				for (var index=0; index<elements[elementName].length; index++)
				{
					if (elements[elementName][index].checked)
					{
						value[value.length] = elements[elementName][index].value;
					}
				}
			}
			else if (elements[elementName].checked)
			{
				value[0] = elements[elementName].value;
			}
		}
	}
	return (value);
}

function isChecked(theElementName, theForm) 
{
   	if (theForm == null) 
	{
		theForm = document.forms[0];
		if (document.forms.length > 0)
		{
			if (theForm.name == "PropertyLookUp")
				theForm = document.forms[1];
		}
	}
	theElementList = theForm.elements;
	for (var i=0; i<theElementList.length; i++) 
	{
		if ((theElementList[i].name == theElementName) && (theElementList[i].checked)) return (true);
	}
	return (false);
}

function clearFormAction(theForm) 
{
   	if (theForm == null) 
	{
		theForm = document.forms[0];
		if (document.forms.length > 0)
		{
			if (theForm.name == "PropertyLookUp")
				theForm = document.forms[1];
		}
	}
	theForm.action = document.location.pathname;
}

// validation functions
function validateAction(theName, theForm)
{
   	if (theForm == null) 
	{
		theForm = document.forms[0];
		if (document.forms.length > 0)
		{
			if (theForm.name == "PropertyLookUp")
				theForm = document.forms[1];
		}
	}
	with (theForm)
	{
  		if (Action.selectedIndex == 0)
  		{
	   		alert("You must select an action before clicking Go!");
	   		return (false);
		}
		else 
		{
			theAction = Action.options[Action.selectedIndex].value;
		}
		isSelected = false;
		for (i=0; i<elements.length; i++)
		{
			if (elements[i].name == theName)
			{
				if (isSelected = elements[i].checked) break;
			}
		}
		if (!isSelected)
		{
			alert("You must check at least one checkbox before clicking Go!");
			return (false);
		}
	}
	return (confirm("Are you sure you want to " + theAction + " these items?"));
}

function submitAction(theParentElementName, theForm)
{
   	if (theForm == null) 
	{
		theForm = document.forms[0];
		if (document.forms.length > 0)
		{
			if (theForm.name == "PropertyLookUp")
				theForm = document.forms[1];
		}
	}
	if (validateAction(theParentElementName, theForm))
	{
		theForm.submit();
	}
}
function ValidatorCheckBoxDisableButton(chkId, mustBeChecked, btnId) {
    var button = document.getElementById(btnId);
    var chkbox = document.getElementById(chkId);

    if (button && chkbox) {
        button.disabled = (chkbox.checked != mustBeChecked);
    }
}

function ValidatorCheckBoxEvaluateIsValid(val) {
    var control = document.getElementById(val.controltovalidate);
    var mustBeChecked = Boolean(val.mustBeChecked == 'true');

    return control.checked == mustBeChecked;
}

function ValidatorCheckBoxListEvaluateIsValid(val) {
    var control = document.getElementById(val.controltovalidate);
    var minimumNumberOfSelectedCheckBoxes = parseInt(val.minimumNumberOfSelectedCheckBoxes);

    var selectedItemCount = 0;
    var liIndex = 0;
    var currentListItem = document.getElementById(control.id + '_' + liIndex.toString());
    while (currentListItem != null) {
        if (currentListItem.checked) selectedItemCount++;
        liIndex++;
        currentListItem = document.getElementById(control.id + '_' + liIndex.toString());
    }

    return selectedItemCount >= minimumNumberOfSelectedCheckBoxes;
}