var aDivResize;
var objDivResize;
var intResizeStep;
var intResizeSpeed;
var strResizeComplete;
var binResizeComplete = false;

function Execute(strCall, binWait, binShowError, strCallBack)
{
    // If the first parameter hasn't been provided then return without doing anything
    if (! strCall) return;
	var binDontWait = ! binWait;
	var xmlHttp=null;
	var binAJAXError = false;
    var strAJAXResponse = "";
    var strErrDesc = "";
    var strErrName = "";
    var strErrMessage = "";
	// Determine which object is being used
	try
	{
		xmlHttp = new XMLHttpRequest();
	}
	catch (e)
	{
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	if (xmlHttp)
	{
		// Internet Explorer caches responses to the AJAX calls.
		// This sets a time based parameter to avoid this.
		var tmpDate = new Date();
		var strDate = tmpDate.toGMTString() + "-" + tmpDate.getUTCMilliseconds();
		strCall += "&strNoCache=" + strDate;
        strCall += "&userAgent=" + HTTPEncode(navigator.userAgent);
        strCall += "&platform=" + HTTPEncode(navigator.platform);
        strCall += "&height=" + HTTPEncode("" + screen.height);
        strCall += "&width=" + HTTPEncode("" + screen.width);
        strCall += "&innerHeight=" + HTTPEncode("" + window.innerHeight);
        strCall += "&innerWidth=" + HTTPEncode("" + window.innerWidth);
		// If this is a synchronous call then the onreadystatechange function is irrelevant
		// Since the response will be processed later, and we don't want ir processed twice, ignore it here.
		if (binDontWait)
		{
			xmlHttp.onreadystatechange = function()
			{
				if (xmlHttp.readyState == 4)
				{
					try
					{
						if (xmlHttp.status == 200 && xmlHttp.responseText)
						{
                            eval(xmlHttp.responseText);
						}
					}
					catch (e)
					{
						binAJAXError = true;
                        //strAJAXResponse = xmlHttp.responseText;
                        strErrDesc = e.description;
                        strErrName = e.name;
                        strErrMessage = e.message;
                        // Send the error for a synchronous call
                        SendAJAXError(strCall, strAJAXResponse, strErrDesc, strErrName, strErrMessage, strCallBack);
                        if (binShowError)
                        {
						    alert("Error on AJAX call : " + e.description + "\nName: " + e.name + "\nMessage: " + e.message + "\n------\n" + strCall);
                        }
					}
				}
			}
		}
		if (!binAJAXError)
		{
			try
			{
				xmlHttp.open("POST","./",binDontWait);
                xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
                xmlHttp.setRequestHeader("Content-length",strCall.length);
                xmlHttp.setRequestHeader("Connection","close");
			}
			catch (e)
			{
				binAJAXError = true;
                //strAJAXResponse = xmlHttp.responseText;
                strErrDesc = e.description;
                strErrName = e.name;
                strErrMessage = e.message;
                if (binShowError)
                {
                    alert("Unable to set AJAX destination : " + e.description + "\nName: " + e.name + "\nMessage: " + e.message + "\n------\n" + strCall);
                }
			}
		}
		if (!binAJAXError)
		{
			try
			{
				xmlHttp.send(strCall);
			}
			catch (e)
			{
				binAJAXError = true;
                //strAJAXResponse = xmlHttp.responseText;
                strErrDesc = e.description;
                strErrName = e.name;
                strErrMessage = e.message;
                if (binShowError)
                {
                    alert("Error on AJAX call : " + e.description + "\nName: " + e.name + "\nMessage: " + e.message + "\n------\n" + strCall);
                }
			}
		}
		// If this is an asynchronous call, process the response text here.
		if (binWait && (!binAJAXError) && xmlHttp.status == 200 && xmlHttp.responseText)
		{
            try
            {
                eval(xmlHttp.responseText);
            }
            catch (e)
            {
                binAJAXError = true;
                //strAJAXResponse = xmlHttp.responseText;
                strErrDesc = e.description;
                strErrName = e.name;
                strErrMessage = e.message;
                if (binShowError)
                {
                    alert("Error on AJAX call : " + e.description + "\nName: " + e.name + "\nMessage: " + e.message + "\n------\n" + strCall);
                }
            }
		}
        if (binAJAXError)
        {
            //objErrorDiv = document.getElementById("divErrorContents");
            //objErrorDiv.innerHTML = strAJAXResponse;
            // Send the error for an asychronous call
            SendAJAXError(strCall, strAJAXResponse, strErrDesc, strErrName, strErrMessage, strCallBack);
        }
	}
}
function SendAJAXError(strCall, strAJAXResponse, strErrDesc, strErrName, strErrMessage, strCallBack)
{
    var strErrorCall;
    var xmlErrorHttp;
    strErrorCall  = "error=1";
    strErrorCall += "&desc=" + HTTPEncode(strErrDesc);
    strErrorCall += "&name=" + HTTPEncode(strErrName);
    strErrorCall += "&message=" + HTTPEncode(strErrMessage);
    strErrorCall += "&call=" + HTTPEncode(strCall);
    strErrorCall += "&response=" + HTTPEncode(strAJAXResponse);
    try
    {
        xmlErrorHttp = new XMLHttpRequest();
    }
    catch (e)
    {
        try
        {
            xmlErrorHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            xmlErrorHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    if (xmlErrorHttp)
    {
        try
        {
            xmlErrorHttp.open("POST","./",binDontWait);
            xmlErrorHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
            xmlErrorHttp.setRequestHeader("Content-length",strCall.length);
            xmlErrorHttp.setRequestHeader("Connection","close");
        }
        catch (e)
        {
            // Do Nothing
        }
        try
        {
            xmlErrorHttp.send(null);
        }
        catch (e)
        {
            // Do Nothing
        }
    }
    if (strCallBack)
    {
        try
        {
            eval(strCallBack);
        }
        catch (e)
        {
            // Do Nothing
        }
    }
}

String.prototype.ltrim = function()
{
	return this.replace(/^\s+/,"");
};
String.prototype.rtrim = function()
{
	return this.replace(/\s+$/,"");
};
function trim(strToTrim)
{
	return strToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(strToTrim)
{
	return strToTrim.replace(/^\s+/,"");
}
function rtrim(strToTrim)
{
	return strToTrim.replace(/\s+$/,"");
}

// Return whether or not the e-mail address is valid
// This leaves out some valid e-mail addesses like:
// -- anything with '
// -- "Paul Russell<>"@cloudworksconsulting.com
// -- prussell@[1.2.3.4]
function ValidEmail(strEmailAddress, binShowError)
{

	var binValid = true;
    var intChar;

	// Ensure that something has been filled in
	if (binValid &&
	    strEmailAddress == "")
	{
		if (binShowError)
		{
			alert("Error: No e-mail address was filled in.");
		}
		binValid = false;
	}

	// Check for a "@"
	//           and a "."
	//           and that there's only one "@"
	//           and that the "@" comes before the last "."
	if (binValid &&
	    (strEmailAddress.indexOf("@") == -1 ||
	     strEmailAddress.indexOf(".") == -1 ||
	     strEmailAddress.indexOf("@") != strEmailAddress.lastIndexOf("@") ||
	     strEmailAddress.lastIndexOf(".") < strEmailAddress.indexOf("@")))
	{
		if (binShowError)
		{
			alert("Error: Invalid e-mail address (1).");
		}
		binValid = false;
	}

	// Ensure that the local part of the address is valid (before the "@")
	if (binValid)
	{
		var strLocal = strEmailAddress.substring(0,strEmailAddress.indexOf("@"));
		//alert("local: " + strLocal);
		var strValidChars = strSpecialEmailChars + strNumbers + strUpperCase + strLowerCase;
		for (intChar = 0; intChar < strLocal.length-1; intChar++)
		{
			if (strValidChars.indexOf(strLocal.charAt(intChar)) == -1)
			{
				binValid = false;
			}
		}
		// Ensure that special checks are made for dots
		if (strLocal.indexOf(".") == 0 ||
		    strLocal.lastIndexOf(".") == strLocal.length-1 ||
		    strLocal.indexOf("..") != -1)
		{
			binValid = false;
		}
		if (binShowError && !binValid)
		{
			alert("Error: Invalid e-mail address (2).");
		}
	}

	// Ensure that the server part of the address is valid (between the "@" and the last ".")
	// A server can also have a "." in the name
	if (binValid)
	{
		var strServer = strEmailAddress.substr(strEmailAddress.lastIndexOf("@")+1);
		strServer = strServer.substring(0,strServer.lastIndexOf("."));
		//alert("server: " + strServer);
		strValidChars = strNumbers + strUpperCase + strLowerCase + ".";
		for (intChar = 0; intChar < strServer.length-1; intChar++)
		{
			if (strValidChars.indexOf(strServer.charAt(intChar)) == -1)
			{
				binValid = false;
			}
		}
		if (binShowError && !binValid)
		{
			alert("Error: Invalid e-mail address (3).");
		}
	}

	// Ensure that the TLD is valid (after the last ".")
	if (binValid)
	{
		var strTLD = strEmailAddress.substr(strEmailAddress.lastIndexOf(".")+1);
		//alert("tld: " + strTLD);
		strValidChars = strUpperCase + strLowerCase;
		for (intChar = 0; intChar < strTLD.length-1; intChar++)
		{
			if (strValidChars.indexOf(strTLD.charAt(intChar)) == -1)
			{
				binValid = false;
			}
		}
		if (binShowError && !binValid)
		{
			alert("Error: Invalid e-mail address (4).");
		}
	}

	return binValid;
}

// Determine whether or not the password is valid, based on the contents
function ValidPassword(strPassword, binShowError)
{

	var binValid = true;
    var strTestChar;

	strPassword = trim(strPassword);
	// Ensure that it's long enough
	if (binValid &&
	    strPassword.length < intMinPasswordLength)
	{
		binValid = false;
		if (binShowError)
		{
			alert("Error: Invalid password - it needs to be at least four characters long.");
	}
	}
	// Ensure that it has valid characters
	if (binValid)
	{
		var strValidChars = strSpecialPasswordChars + strNumbers + strUpperCase + strLowerCase;
		for (var intChar = 0; intChar < strPassword.length-1; intChar++)
		{
			strTestChar = strPassword.charAt(intChar);
			if (strValidChars.indexOf(strTestChar) == -1)
			{
				binValid = false;
			}
		}
		if (binShowError && !binValid)
		{
            if (strPassword.indexOf(" ") > -1)
            {
			    alert("Error: Invalid password - invalid characters.");
            }
            else
            {
                alert("Error: Invalid password - invalid characters.\r\rThe password cannot contain spaces.");
            }
		}
	}

	return binValid;

}

// Determine the strength of the password, based on a few calculations
// This returns a number from 0 to 8, indicating the strength
function PasswordStrength(strPassword)
{

	var intStrength = 0;
    var strTestChar;

	if (strPassword.length > 4) { intStrength += 1;	}
	if (strPassword.length > 6) { intStrength += 1; }

	var strLetters = strUpperCase + strLowerCase;
	var intLetters = 0;
	var intNumbers = 0;
	var intSpecialChars = 0;
	for (var intChar = 0; intChar < strPassword.length-1; intChar++)
	{
		strTestChar = strPassword.charAt(intChar);
		if (strLetters.indexOf(strTestChar) >= 0) { intLetters += 1; }
		if (strNumbers.indexOf(strTestChar) >= 0) { intNumbers += 1; }
		if (strSpecialPasswordChars.indexOf(strTestChar) >= 0) { intSpecialChars += 1; }
	}
	if (intLetters > 0) { intStrength += 1; }
	if (intLetters > 1) { intStrength += 1; }
	if (intNumbers > 0) { intStrength += 1; }
	if (intNumbers > 1) { intStrength += 1; }
	if (intSpecialChars > 0) { intStrength += 1; }
	if (intSpecialChars > 1) { intStrength += 1; }

	return intStrength;

}

// Determine whether or not the text entry is valid, based on the contents
function ValidInput(strInput, strFieldName, binShowError, binAllowCRLF)
{

	var binValid = true;
    var strTestChar;

	if (strInput)
	{
		strInput = trim(strInput);

		if (strFieldName == "")
		{
			strFieldName = "entry";
		}

		// Ensure that it does not have invalid characters (other criteria will be checked in the save routine)
		if (strInvalidChars.length > 0 && binValid)
		{
			for (var intChar = 0; intChar < strInput.length-1; intChar++)
			{
				strTestChar = strInput.charAt(intChar);
				if (strInvalidChars.indexOf(strTestChar) > 0)
				{
					binValid = false;
				}
			}
		}

		if (binShowError && !binValid)
		{
			alert("Error: Invalid " + strFieldName + " - invalid characters.");
		}
	}

	return binValid;

}

// If the passed parameter is MM/DD/YYYY then it formats it as YYYY-MM-DD
function DateEncode(strInput)
{

    var strReturn = "";
    var strNumbers = "0123456789";

    if (strInput && typeof strInput == "string")
    {
        strInput = trim(strInput);
        if (strInput.length = 10 && /* Check the basic characters */
            strNumbers.indexOf(strInput.substr(0,1)) > -1 &&
            strNumbers.indexOf(strInput.substr(1,1)) > -1 &&
            strInput.substr(2,1) == "/" &&
            strNumbers.indexOf(strInput.substr(3,1)) > -1 &&
            strNumbers.indexOf(strInput.substr(4,1)) > -1 &&
            strInput.substr(5,1) == "/" &&
            strNumbers.indexOf(strInput.substr(6,1)) > -1 &&
            strNumbers.indexOf(strInput.substr(7,1)) > -1 &&
            strNumbers.indexOf(strInput.substr(8,1)) > -1 &&
            strNumbers.indexOf(strInput.substr(9,1)) > -1)
        {
            var intMonth = strInput.substr(0,2);
            var intDay = strInput.substr(3,2);
            var intYear = strInput.substr(6,4);
            var aLastDays = new Array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
            if (intMonth == 2 && /* Adjust the highest day of the month for leap years */
                (intYear % 4 == 0 &&
                 (intYear % 100 != 0 || intYear % 400 == 0) &&
                 intDay <= 28))
            {
                aLastDays[2] = 29;
            }
            if (intYear > 1890 && intYear < 2050 && /* Check the numeric ranges */
                intMonth >= 1 && intMonth <= 12 &&
                intDay >= 1 && intDay <= aLastDays[intMonth])
            {
                // Format the return date
                strReturn = "" + intYear + "-" + intMonth + "-" + intDay;
            }
        }
    }

    return strReturn;
}

function ArrayCharacterRemoval(strInput)
{
    var strReturn = "";
    // ; will be a row delimiter
    // : will be a column delimiter
    // = will be a name/value pair delimiter
    var strArrayChars = ";:=";
    for (var intChar = 0; intChar < strInput.length; intChar++)
    {
        var strTestChar = strInput.charAt(intChar);
        if (strArrayChars.indexOf(strTestChar) == -1)
        {
            strReturn += strTestChar;
        }
    }
    return strReturn;
}
function HTTPEncode(strInput)
{
    var strReturn = "";
    if (strInput && typeof strInput == "string")
    {
        strReturn = strInput;
        strReturn = strReturn.replace(/%/g, '%25');
        strReturn = strReturn.replace(/!/g, '%21');
        strReturn = strReturn.replace(/"/g, '%22');
        strReturn = strReturn.replace(/&/g, '%26');
        strReturn = strReturn.replace(/'/g, '%27');
        strReturn = strReturn.replace(/\(/g, '%28');
        strReturn = strReturn.replace(/\)/g, '%29');
        strReturn = strReturn.replace(/\*/g, '%2A');
        strReturn = strReturn.replace(/\+/g, '%2B');
        strReturn = strReturn.replace(/:/g, '%3A');
        strReturn = strReturn.replace(/;/g, '%3B');
        strReturn = strReturn.replace(/</g, '%3C');
        strReturn = strReturn.replace(/>/g, '%3E');
        strReturn = strReturn.replace(/%20/g, '+');
    }
    return strReturn;
}
function HTTPDecode(strInput)
{
    var strReturn = "";
    if (strInput && typeof strInput == "string")
    {
        strReturn = strInput;
        strReturn = strReturn.replace(/\+/g, '%20');
        strReturn = strReturn.replace(/%3E/g, '\>');
        strReturn = strReturn.replace(/%3C/g, '\<');
        strReturn = strReturn.replace(/%3B/g, ';');
        strReturn = strReturn.replace(/%3A/g, ':');
        strReturn = strReturn.replace(/%2B/g, '+');
        strReturn = strReturn.replace(/%2A/g, '*');
        strReturn = strReturn.replace(/%29/g, ')');
        strReturn = strReturn.replace(/%28/g, '(');
        strReturn = strReturn.replace(/%27/g, '\'');
        strReturn = strReturn.replace(/%26/g, '&');
        strReturn = strReturn.replace(/%22/g, '"');
        strReturn = strReturn.replace(/%21/g, '!');
        strReturn = strReturn.replace(/%25/g, '%');
    }
    return strReturn;
}
function URLEncode(strInput)
{
	var strReturn = "";
	if (strInput && typeof strInput == "string")
	{
		strReturn = HTTPEncode(encodeURIComponent(strInput));
	}
	return strReturn;
}
function URLDecode(strInput)
{
	var strReturn = "";
	if (strInput && typeof strInput == "string")
	{
		strReturn = HTTPDecode(decodeURIComponent(strInput));
	}
	return strReturn;
}
function SQLEncode(strInput)
{
	var strReturn = "";
	if (strInput && typeof strInput == "string")
	{
		strReturn = strInput;
		strReturn = strReturn.replace(/%/g,'%25'); // This has to come first
		strReturn = strReturn.replace(/:/g,'%3A');
		strReturn = strReturn.replace(/</g,'%3C');
		strReturn = strReturn.replace(/>/g,'%3E');
		strReturn = strReturn.replace(/"/g,'%22');
		strReturn = strReturn.replace(/\n/g,'%0A');
		strReturn = strReturn.replace(/\r/g,'%0D');
	}
	return strReturn;
}
function SQLDecode(strInput)
{
	var strReturn = "";
	if (strInput && typeof strInput == "string")
	{
		strReturn = strInput;
		strReturn = strReturn.replace(/%0D/g,"\r");
		strReturn = strReturn.replace(/%0A/g,"\n");
		strReturn = strReturn.replace(/%22/g,'"');
		strReturn = strReturn.replace(/%3E/g,'>');
		strReturn = strReturn.replace(/%3C/g,'<');
		strReturn = strReturn.replace(/%3A/g,':');
		strReturn = strReturn.replace(/%25/g,'%'); // This has to come last
	}
	return strReturn;
}
function AnimateDivResize()
{
	if (!binResizeComplete)
	{
		if (intResizeStep < aDivResize.length)
		{
			//objDivResize.style.top = aDivResize[intResizeStep].top + "px";
			//objDivResize.style.left = aDivResize[intResizeStep].left + "px";
			objDivResize.style.height = aDivResize[intResizeStep].height + "px";
			objDivResize.style.width = aDivResize[intResizeStep].width + "px";
			intResizeStep += 1;
			setTimeout("AnimateDivResize()",intResizeSpeed);
		}
		else
		{
			//objDivResize.style.top = aDivResize[aDivResize.length-1].top + "px";
			//objDivResize.style.left = aDivResize[aDivResize.length-1].left + "px";
			objDivResize.style.height = aDivResize[aDivResize.length-1].height + "px";
			objDivResize.style.width = aDivResize[aDivResize.length-1].width + "px";
			// Now complete the process
			if (strResizeComplete)
			{
				eval(strResizeComplete);
			}
			// Clear the variables
			objDivResize = "";
			aDivResize = new Array();
			intResizeStep = 0;
			intResizeSpeed = 50;
			strResizeComplete = "";
		}
	}
}
function GetObjectValue(strObjectId)
{
    var varReturn;
    var objObject = document.getElementById(strObjectId);
    if (objObject)
    {
        try
        {
            varReturn = objObject.value;
        }
        catch (e)
        {

        }
    }
    return varReturn;
}
function SetObjectValue(strObjectId, varValue)
{
    var objObject = document.getElementById(strObjectId);
    if (objObject)
    {
        try
        {
            objObject.value = varValue;
        }
        catch (e)
        {

        }
    }
    return varValue;
}
function GetComponentValue(strObjectId)
{
    var varReturn;
    var objObject = Ext.getCmp(strObjectId);
    if (objObject)
    {
        try
        {
            varReturn = objObject.getValue();
            if (varReturn && typeof varReturn == 'object' && varReturn instanceof Date)
            {
                varReturn = '' + varReturn.getFullYear() + '-' + (varReturn.getMonth() + 1) + '-' + varReturn.getDate();
            }
        }
        catch (e)
        {
            alert("GetComponentValue: " + strObjectId + " error returning value");
        }
    }
    else
    {
        alert("GetComponentValue: " + strObjectId + " not found");
    }
    return "" + varReturn;
}
function SetComponentValue(strObjectId, varValue)
{
    var objObject = Ext.getCmp(strObjectId);
    if (objObject)
    {
        try
        {
            objObject.setValue(varValue);
        }
        catch (e)
        {

        }
    }
    return varValue;
}
function GetDivs(strDivList)
{
    if (typeof strDivList == "string" && strDivList.length > 0)
    {
        aRawObjects = strDivList.split(",");
        for (intObject = 0; intObject < aRawObjects.length; intObject++)
        {
            objDiv = document.getElementById(aRawObjects[intObject]);
            if (objDiv)
            {
                if (aPageDivs)
                {
                    binFound = false;
                    for (intCheck = 0; intCheck < aPageDivs.length; intCheck++)
                    {
                        if (aPageDivs[intCheck].divName == aRawObjects[intObject])
                        {
                            binFound = true;
                            aPageDivs[intCheck].div = document.getElementById(aRawObjects[intObject]);
                        }
                    }
                    if (! binFound)
                    {
                        aPageDivs[aPageDivs.length] = {'divName': aRawObjects[intObject], 'div': document.getElementById(aRawObjects[intObject])}
                    }
                }
                else
                {
                    aPageDivs = {'divName': aRawObjects[intObject], 'div': document.getElementById(aRawObjects[intObject])}
                }
            }
        }
    }
}
function ClickBreadCrumb(intNewPage)
{
    ZipHideHelp();
    if (intNewPage <= intProgress)
    {
        Execute(strProgress + intNewPage,false);
    }
}
function DrawBreadCrumbs(objContainer)
{
    objContainer.innerHTML = "The breadcrumbs will go here.";
    var strReturn = "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr>";
    for (var intBreadCrumbCount = 1; intBreadCrumbCount < aBreadCrumbs.length + 1; intBreadCrumbCount++)
    {
        strReturn += "<td id='divBreadCrumb" + intBreadCrumbCount + "' class='breadcrumb-inactive' onClick='ClickBreadCrumb(" + intBreadCrumbCount + ")'>&nbsp;" + (intBreadCrumbCount == 1 ? "&nbsp;" : "") + aBreadCrumbs[intBreadCrumbCount - 1].label + "</td>";
        if (intBreadCrumbCount < aBreadCrumbs.length)
        {
            strReturn += "<td id='divBreadCrumbSeparator" + intBreadCrumbCount + "' class='breadcrumb-separator-U2U'>" + "" + "</td>";
        }
        else
        {
            strReturn += "<td id='divBreadCrumbSeparator" + intBreadCrumbCount + "' class='breadcrumb-separator-UEnd'>" + "" + "</td>";
        }
    }
    strReturn += "</tr></table>";
    objContainer.innerHTML = strReturn;
}
// Highlight intBreadCrumb; Draw active until intMaxBreadCrumb
function DrawBreadCrumb(intBreadCrumb, intMaxBreadCrumb)
{
    for (var intBreadCrumbCount = 1; intBreadCrumbCount < aBreadCrumbs.length + 1; intBreadCrumbCount++)
    {
        if (intBreadCrumbCount == intBreadCrumb)
        {
            // Current Bread crumb
            document.getElementById("divBreadCrumb" + intBreadCrumbCount).className = "breadcrumb-current";
            if (intBreadCrumbCount < aBreadCrumbs.length)
            {
                document.getElementById("divBreadCrumbSeparator" + intBreadCrumbCount).className = "breadcrumb-separator-S2U";
            }
            else
            {
                document.getElementById("divBreadCrumbSeparator" + intBreadCrumbCount).className = "breadcrumb-separator-SEnd";
            }
        }
        else if (intBreadCrumbCount == intBreadCrumb - 1)
        {
            // Immediately to the left
            document.getElementById("divBreadCrumb" + intBreadCrumbCount).className = "breadcrumb-active";
            document.getElementById("divBreadCrumbSeparator" + intBreadCrumbCount).className = "breadcrumb-separator-U2S";
        }
        else if (intBreadCrumbCount <= intMaxBreadCrumb)
        {
            // All active ones
            document.getElementById("divBreadCrumb" + intBreadCrumbCount).className = "breadcrumb-active";
            if (intBreadCrumbCount < aBreadCrumbs.length)
            {
                document.getElementById("divBreadCrumbSeparator" + intBreadCrumbCount).className = "breadcrumb-separator-U2U";
            }
            else
            {
                document.getElementById("divBreadCrumbSeparator" + intBreadCrumbCount).className = "breadcrumb-separator-UEnd";
            }
        }
        else
        {
            // All inactive ones (these will be to the right)
            document.getElementById("divBreadCrumb" + intBreadCrumbCount).className = "breadcrumb-inactive";
            if (intBreadCrumbCount < aBreadCrumbs.length)
            {
                document.getElementById("divBreadCrumbSeparator" + intBreadCrumbCount).className = "breadcrumb-separator-U2U";
            }
            else
            {
                document.getElementById("divBreadCrumbSeparator" + intBreadCrumbCount).className = "breadcrumb-separator-UEnd";
            }
        }
    }
}
function FormatDate(objDate, strReturnFormat)
{
    var strReturn = "";
    var intDate = 0;
    var intMonth = 0;
    var intYear = 0;

    var aShortMonths = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    var aLongMonths = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

    // Try to parse the date
    if (typeof objDate == "string")
    {
        if (objDate.length == 10)
        {
            intYear  = parseInt(objDate.substr(0,4));
            intMonth = parseInt(objDate.substr(5,2));
            if (intMonth == 0)
            {
                intMonth = parseInt(objDate.substr(6,1));
            }
            intDate  = parseInt(objDate.substr(8,2));
            if (intDate == 0)
            {
                intDate  = parseInt(objDate.substr(9,1));
            }
        }
    }
    else if (typeof objDate == "date")
    {
        intYear  = objDate.getFullYear();
        intMonth = objDate.getMonth() + 1;
        intDate  = objDate.getDate();
    }

    // Format the return date
    if (intYear != 0 && intMonth != 0 && intDate != 0)
    {
        var strDate = "" + intDate;
        var str2DigitDate = "" + (intDate < 10 ? "0" : "") + intDate;
        var strMonth = "" + intMonth;
        var str2DigitMonth = "" + (intMonth < 10 ? "0" : "") + intMonth;
        var strShortMonth = aShortMonths[intMonth-1];
        var strLongMonth = aLongMonths[intMonth-1];
        // Default format: 31-Dec-2010
        strReturn = str2DigitDate + "-" + strShortMonth + "-" + intYear;
    }

    return strReturn;
}
function ParseJSError(err)
{
    var strReturn = "Error:";
    if (err.name) {strReturn += ";name:"+err.name;}
    if (err.message) {strReturn += ";message:"+err.message;}
    if (err.number) {strReturn += ";number:"+err.number;}
    if (err.description) {strReturn += ";description:"+err.description;}
}
function px(intDimension)
{
    var strReturn = "";
    intDimension = parseInt(intDimension);
    if (! isNaN(intDimension))
    {
        strReturn = "" + intDimension + (intDimension == 0 ? "" : "px");
    }
    return strReturn;
}

