/* Blue River Digital API - Common **********************************
 *	
 *	This API contains all the common Javascript functions
 *	
 *********************************************************************/
 	
 	// Globals *************************************************
    var currentFocus    = "";
    var inchesTag       = "inches";
    var feetTag         = "feet";
    var centimetersTag  = "centimeters";
    var metersTag       = "meters";
    
    function windowScrollBarExists()
    {
        if (getHeight(getElement("mainContentContainer")) > getWindowHeight())
        {
            return true;
        }
        else
        {
            return false;
        }
    } 
    
    
 	// Broswer Detection ****************
 	var IE = document.all?true:false; // determine which browser 
	var thisBrowser = navigator.userAgent;
	var thisBrowserVersion = null;
	
	if (thisBrowser.indexOf("MSIE") != -1)
	{
		if (thisBrowser.indexOf("MSIE 8") != -1)
		{
			thisBrowserVersion = 8;	
		}
		
		thisBrowser = "IE";
		
	}
	else if (thisBrowser.indexOf("Firefox") != -1)
	{
		thisBrowser = "Firefox";	
	}
	else if (thisBrowser.indexOf("Safari") != -1)
	{
		thisBrowser = "Safari";	
	}
	else
	{
		thisBrowser = "Other";	
	}
	
	function getBrowserOffset(offsetDim)
	{
	    var xOffset = null;
	    var yOffset = null;
	    
	    if (IE)
        {
            if (thisBrowserVersion != 8) // IE7, Compatibility View and lower
            {
                if (windowScrollBarExists())
                {
                    xOffset = 0;
                    yOffset = 2;
                }
                else
                {
                    xOffset = 0;
                    yOffset = 2;
                }
            }
            else // IE8
            {
                if (windowScrollBarExists())
                {
                    
                    xOffset = 8;
                    yOffset = 0;
                }
                else
                {
                    xOffset = 0;
                    yOffset = 0;
                }
            }
        }
        else // Firefox
        {
            if (windowScrollBarExists())
            {
                xOffset = 8;
                yOffset = 0;
            }
            else
            {
                xOffset = 0;
                yOffset = 0;
            }
        }
        
        if (offsetDim.toLowerCase() == "x")
        {
            return xOffset;
        }
        else
        {
            return yOffset;
        }
	}
	
	function getBrowserOffsetX()
	{
	    return getBrowserOffset("x");
	}
	
	function getBrowserOffsetY()
	{
	    return getBrowserOffset("y");
	}
	
	
	var mousePositionX = "";
	var mousePositionY = "";
	
	
	// Current Date and Time *****************************
	var d = new Date();
	var yearValue = d.getYear();
	var hourValue = d.getHours();
	var amPmValue = "AM";
	
	if (!IE)
	{
		yearValue += 1900;	
	}
	
	if (hourValue > 11)
	{
		amPmValue = "PM";	
	}
	
	var now = (d.getMonth()+1) + "/" + d.getDate() + "/" + yearValue + " " + hourValue + ":" + d.getMinutes() + ":" + d.getSeconds() + " " + amPmValue;
			
	
/*  Get Mouse Position * *******************************************************
 *
 *	TAKES:		Event Object
 * 	RETURNS:	NOTHING
 *	NOTES:		IE by default does not calculate the page scrolling in the
 *				mouse postion, but the screen position.  Since FF and NS include
 *				page scroll in the mouse position, we're adding to IE as well.
 *
 *************************************************************************/
	
	function getMousePosition(e)
	{
		var posX = "";
		var posY = "";
		
		if (IE)
		{ 
			// grab the y pos.s if browser is IE
			posX = event.clientX - 2 + getPageXOffset();
			posY = event.clientY - 2 + getPageYOffset();
	  	}
		else
		{ 
			// grab the y pos.s if browser is NS
			posX = e.pageX;
			posY = e.pageY;
		}  
	  
	   // catch possible negative values in NS4
	   if ((posX < 0)||(posY < 0))
	   {
		  posX = 0;
		  posY = 0;
	   }  
	  
	 	mousePositionX = posX;
	 	mousePositionY = posY;
		
	}
	
 
 /* Is Array * *******************************************************
 *
 *	TAKES:		Array Object
 * 	RETURNS:	True if the array object is actually an array. False if the 
 *				array object is not an array.
 *	NOTES:		Usage: [Array Obj].isArray();
 *
 *************************************************************************/
 
 	Object.prototype.isArray = function()
	{
		return this.constructor == Array;
	}
	
/* Data Is Valid **********************************************************
*
*	TAKES:		Data, Data Type
*	RETURNS:	True if the data is valid, False if the data is not valid
*				based on the data type. Data types include:
*
*					1. String	- Ex: "abc123"
*					2. Integer	- Ex: 123
*					3. Float	- Ex: 25.99
*					4. Email	- Ex: test@email.com
*					5. Password - Ex: *******
*					6. Phone	- Ex: 123-444-5555
*
*	NOTES:		This function genreally doesn't enforce the maximum number
*				of characters for given data, this should be handled with 
*				character limits using HTML forms.
*
**************************************************************************/

	function dataIsValid(data, dataType)
	{
		var regExp;
		var errorMessage
		data = String(data);
		
		switch(dataType)
		{
			case "string":
				
				regExp = /^(\w|\s)+$/;
				errorMessage = "Invalid characters were used. (Ex: <, >, %, \", ', #).";
				break;
				
			case "integer":
				
				regExp = /^\d+$/;
				errorMessage = "This field can only contain whole numbers (Ex: 1, 23, 675).";
				break;
				
			case "float":
			
				regExp = /^(-|)\d+(\.\d+|)$/;
				errorMessage = "This field can only contain decimal numbers (Ex: 51, 1.0, 23.5, 67.5).";
				break;
				
			case "fraction":
			
				regExp = /^(|[0-9]+ )[0-9]+\/[0-9]+$/;
				errorMessage = "This field can only contain fractions (Ex: 12 3/4, 1/2).";
				break;
				
			case "email":
			
				regExp = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
				errorMessage = "This field can only contain valid email addresses (Ex: johndoe@emailexample.com).";
				break;
				
			case "password":
			
				regExp = /^.{6}/
				errorMessage = "This field must be at least six characters long and not contain any invalid characters. (Ex: <, >, %, \", ', #)";
				break;
			
			case "phone":
			
				regExp = /^((\(\d{3}\)( |))|(\d{3}( |-|.|)))\d{3}( |-|.|)\d{4}(,| |x|e)*/;
				errorMessage = "This field can only contain phone numbers (Ex: 111-555-4444).";
				break;
			
			case "zip":
			
				regExp = /^\d{5}([\-]\d{4})?$/;
				errorMessage = "This field can only contain zip codes (Ex: 12345-5555).";
				break;
			
			case "text":
			
				regExp = /^.*$/;
				errorMessage = "Invalid characters were used. (Ex: <, >, %, \", ', #).";
				break;
			
			case "projectNo":
			
				regExp = /^P[A-Z][0-9]{4}-[A-Z]{2}$/;
				errorMessage = "Invalid Project No., please use the format: PA0000-AA";
				break;
				
			default:
				
				return false;
		}
		
		if (data.search(regExp) != -1)
		{
			return true;	
		}
		else
		{
			return errorMessage;	
		}
	}
	
/* Is Valid **********************************************************
*
*	TAKES:		Data
*	RETURNS:	True if the data is valid, False if the data is not valid
*				based on the data type. Data types include:
*
**************************************************************************/

	function isValid(data)
	{
		var regExp = /(<|>|"|%|'|#)/;
		
		if (data.search(regExp) != -1)
		{
			return false;	
		}
		else
		{
			return true;	
		}
		
	}
	
/*  Encode Query String * *******************************************************
 *
 *	TAKES:		Query String
 * 	RETURNS:	Encrypyed Query String
 *	NOTE:		Special characters that need to be encrypted:
 *
 *					- ;	%3B
 *					- ?	%3F
 *					- /	%2F
 *	 				- :	%3A
 *					- #	%23
 *					- &	%26
 *					- =	%3D
 * 					- +	%2B
 *					- $	%24
 *					- ,	%2C
 *					- <space>	%20
 *					- %	%25
 *					- <	%3C
 *					- >	%3E
 *					- ~	%7E
 *
 *************************************************************************/
 
	function encodeQueryString(queryString)
	{
		if (queryString != null)
		{
		    queryString = queryString.replace(/\n/g, "<br>");
		    queryString = queryString.replace(/%/g, "%25");
		    queryString = queryString.replace(/;/g, "%3B");
		    queryString = queryString.replace(/\?/g, "%3F");
		    //queryString = queryString.replace(/\//g, "%2F");
		    queryString = queryString.replace(/:/g, "%3A");
		    queryString = queryString.replace(/#/g, "%23");
		    queryString = queryString.replace(/ /g, "%20");
		    queryString = queryString.replace(/&/g, "%26");
		    queryString = queryString.replace(/=/g, "%3D");
		    queryString = queryString.replace(/\+/g, "%2B");
		    queryString = queryString.replace(/\$/g, "%24");
		    queryString = queryString.replace(/,/g, "%2C");
		    queryString = queryString.replace(/</g, "%3C");
		    queryString = queryString.replace(/>/g, "%3E");
		    queryString = queryString.replace(/~/g, "%7E");
		    
    	}
    		
		return queryString;

	}


/* Query String to Request Form Array **********************************************************
*
*	TAKES:		Query String in the format "&[param]=[value]"
*	RETURNS:	Multidimensional Array of the parameter-value pairs.
*
**************************************************************************/

	function queryStringToRequestFormArray(queryString)
	{
	    var paramValuePairsArray = new Array();
	    var temp = "";
	    if (queryString != undefined)
	    {
	        if (queryString.indexOf("&") != -1)
	        {
	            var pairStringArray = queryString.split("&");
    	        
	            for(var ctr=0; ctr<pairStringArray.length; ctr++)
	            {
	                var pairStringValue = pairStringArray[ctr];
    	            
	                if (pairStringValue.indexOf("=") != -1)
	                {
	                    var paramValueArray = pairStringArray[ctr].split("=");
	                    temp += paramValueArray[0] + ": " + paramValueArray[1] + "\n";
	                    paramValuePairsArray.push([paramValueArray[0], paramValueArray[1]]);
	                }
	            }
	        }
	    }
	   
	    return paramValuePairsArray; 
	}

/* Get Dimension Width **********************************************************
*
*	TAKES:		Dimension Data in the format W x H OR WWHH
*	RETURNS:	The width dimension from the dimension data
*
**************************************************************************/

	function getDimWidth(dimData)
	{
		var widthValue = "";
		var dimHolder = "";
		
		if (dimData.indexOf(" x ") != -1)
		{
			dimHolder = Left(dimData, dimData.indexOf(" x "));
			widthValue = Trim(dimHolder);
		}
		else
		{
			dimHolder = Right(dimData, dimData.length - 6);
			widthValue = Left(dimHolder, Math.floor(dimHolder.length/2));
		}
	
		return widthValue;
	
	}
	
/* Get Dimension Height **********************************************************
*
*	TAKES:		Dimension Data in the format W x H OR 5XXXXXWWHH
*	RETURNS:	The height dimension from the dimension data
*
**************************************************************************/

	function getDimHeight(dimData)
	{
		var heightValue = "";
		var dimHolder = "";
		
		if (dimData.indexOf(" x ") != -1)
		{
			dimHolder = Right(dimData, dimData.length - (dimData.indexOf(" x ")+3));
			heightValue = Trim(dimHolder);
		}
		else
		{
			dimHolder = Right(dimData, dimData.length - 6);
			heightValue = Right(dimHolder, Math.ceil(dimHolder.length/2));
		}
		return heightValue;
	
	}

/* Right **********************************************************
*
*	TAKES:		str - the string we are RIGHTing
*               n - the number of characters we want to return
*	RETURNS:	n characters from the right side of the string
*
**************************************************************************/

	function Right(str, n)
    {
		if (n <= 0)     // Invalid bound, return blank string
		{
			return "";
		}
		else if (n > String(str).length)   // Invalid bound, return
		{
			return str;                     // entire string
		}
		else
		{ 
		   // Valid bound, return appropriate substring
		   var iLen = String(str).length;
		   return String(str).substring(iLen, iLen - n);
		}
    }
	
/* Left **********************************************************
*
*	TAKES:		str - the string we are LEFTing
*               n - the number of characters we want to return
*	RETURNS:	n characters from the left side of the string
*
**************************************************************************/
		
	function Left(str, n)
	{
			if (n <= 0)     // Invalid bound, return blank string
			{
				return "";
			}
			else if (n > String(str).length)   // Invalid bound, return
			{
				return str;                // entire string
			}
			else // Valid bound, return appropriate substring
			{
				return String(str).substring(0,n);
			}
	}

	
/* Trim **********************************************************
*
*	TAKES:		String
*	RETURNS:	String with the whitespaces on the left and right sides trimmed.
*
**************************************************************************/

	function Trim(stringToTrim)
	{
		return stringToTrim.replace(/^\s+|\s+$/g,"");
	}
	

	
/* Fraction To Decimal **********************************************************
*
*	TAKES:		Fraction Data string
*	RETURNS:	Decimal representation of the fraction
*
**************************************************************************/

	function fractionToDecimal(data)
	{
		if (dataIsValid(data, "fraction") == true)
		{
			// Convert fractions to decimal
			var wholeNum 	= 0;
			var fraction	= 0;
			var numerator 	= 0;
			var denominator	= 0;
			var decimalValue = 0;
			
			var fractionValues = data.split(" ");
			
			if (fractionValues.length > 1)
			{
				wholeNum = fractionValues[0];
				fraction = fractionValues[1];
			}
			else
			{
				fraction = fractionValues[0];
			}
			
			if (fraction.search(/\//) != -1)
			{
				fractionValues 	= fraction.split("/");
				numerator  		= fractionValues[0];
				denominator  	= fractionValues[1];
				
				if (denominator > 0)
				{
					decimalValue = (numerator/denominator);
				}
				else
				{
					decimalValue = 0;
				}
			}
			
			data = Number(wholeNum) + Number(decimalValue);
		}
		
		return data;
	}

/* BRD Button Actions **********************************************************
*
*	TAKES:		NOTHING
*	RETURNS:	NOTHING
*	NOTES:		Sets the button actions for the BRD Buttons with tag: "brdButton"
*
*********************************************************************************/

	function setBrdButtonActions()
	{
		var buttonElements = getTagGroup("div", "brdButton");	
		
		if (buttonElements.length > 0)
		{
			var buttonElement;
			
			for(ctr=0; ctr<buttonElements.length; ctr++)
			{
				buttonElement = buttonElements[ctr];
				
				// Style Class --------------------------------
				buttonElement.className = "brdButton";
				
				// Mouse Over Actions -------------------------
				buttonElement.onmouseover = function()
				{
					this.className 		= "brdButtonHover";
					this.style.cursor	= "pointer";
				}
				
				// Mouse Over Actions -------------------------
				buttonElement.onmouseout = function()
				{
					this.className 		= "brdButton";
					this.style.cursor	= "";
				}
					
			}
			
		}
	}
	
/* Round Float **********************************************************
*
*	TAKES:		Float Value, Number of Significant Digits
*	RETURNS:	Truncated Float Value
*	NOTES:		
*
*********************************************************************************/

	function roundFloat(floatValue, numDigits)
	{
		if (numDigits == "")
		{
			numDigits = 0;	
		}
		
		var digitPosition;
		var multiplier = Math.pow(10, numDigits);
		
		floatValue = parseFloat(floatValue);
		floatValue = parseFloat(floatValue * multiplier);
		floatValue = Math.round(floatValue) / multiplier;
		
		if (String(floatValue).indexOf(".") > -1)
		{
			digitPosition = Right(String(floatValue), String(floatValue).length - (String(floatValue).indexOf(".") + 1));
			digitPosition = digitPosition.length;
		}
		else
		{
			digitPosition = 0;
			floatValue += ".";
		}
		
		if (digitPosition < numDigits)
		{
			for(var zeroCtr=digitPosition; zeroCtr<numDigits; zeroCtr++)
			{
				floatValue += "0";
			}
		}
		
		return floatValue;
	
	}

/* Pad Number **********************************************************
*
*	TAKES:		Number Value
*	RETURNS:	NOTHING
*	NOTES:		
*
*********************************************************************************/

	function padNumber(num)
	{
		if (num <= 9)
		{
			return "0" + num;
		}
	  
		return num;
	}


/* Set Department Cookie **********************************************************
*
*	TAKES:		Cookie Name, Cookie Value
*	RETURNS:	NOTHING
*	NOTES:		
*
*********************************************************************************/

	function setCookie(cookieName, cookieValue)
	{
		if (cookieName)
		{
			
			var expireDays 	= 365; // one year
			var expDate		= new Date();
			
			expDate.setDate(expDate.getDate() + expireDays);
			document.cookie = cookieName + "=" + escape(cookieValue) + ";expires=" + expDate.toGMTString();
			
		}
		
	}
	
/* Get Department Cookie **********************************************************
*
*	TAKES:		NOTHING
*	RETURNS:	Cookie Value
*	NOTES:		
*
*********************************************************************************/

	function getCookieValue(cookieName)
	{
		if (cookieName)
		{
			var cookieElements 	= document.cookie.split(";");
			var cookieElement 	= "";
			var cookieData		= "";
			var thisCookieName	= "";
			var thisCookieValue	= "";
			
			if (cookieElements.length > 0)
			{
				for(var ctr=0; ctr<cookieElements.length; ctr++)
				{
					cookieElement = cookieElements[ctr];
					
					cookieData = cookieElement.split("=");
					
					thisCookieName = cookieData[0];
					thisCookieValue = cookieData[1];
					
					if (thisCookieName == cookieName)
					{
						return (unescape(thisCookieValue));
					}
				}
			}
		}
		
		return false;
		
	}
	
 /* Email This Product Page ********************************************************
 *
 *	TAKES:		Product Name
 * 	RETURNS:	NOTHING
 *	NOTE:		
 *	
 ************************************************************************************/
 
	function emailThisProductPage(productName)
	{
		var graphicContainer 	= document.createElement("div");
		graphicContainer.style.backgroundImage = "url(/images/emailGraphic.jpg)";
		graphicContainer.style.backgroundRepeat = "no-repeat";
		graphicContainer.style.backgroundColor= "#FFFFFF";
		graphicContainer.style.marginTop = "0px";
		
		var productNameElement 		= document.createElement("input");
		productNameElement.type 	= "hidden";
		productNameElement.id 		= "productName";
		productNameElement.value 	= productName;
		
		graphicContainer.appendChild(productNameElement);
		
		var productLinkElement 		= document.createElement("input");
		productLinkElement.type 	= "hidden";
		productLinkElement.id 		= "productLink";
		productLinkElement.value 	= location.href;
		
		graphicContainer.appendChild(productLinkElement);
		
		var contentElement 		= document.createElement("div");
		contentElement.style.padding = "15px";
		
		var fieldContainer 	= document.createElement("div");
		var fieldTable		= document.createElement("table");
		var fieldTableBody	= document.createElement("tbody");
		
			var fieldToRow		= document.createElement("tr");
			fieldToRow.vAlign	= "top";
			
				var fieldToCol1		= document.createElement("td");
				var fieldToCol2		= document.createElement("td");
				
				fieldToCol1.innerHTML = "<b>To E-mail*: ";
				fieldToCol2.innerHTML = "<input type=\"text\" size=\"35\" id=\"emailTo\">";
				fieldToCol2.style.paddingLeft = "20px"; 
					
					// Error Pane *******************************
					var errorContainer			= document.createElement("div");
					errorContainer.id			= "emailToError";
					errorContainer.className 	= "errorContainer";
					errorContainer.style.display 	= "none";
					errorContainer.style.margin		= "0px";
					errorContainer.style.marginTop	= "5px";
					errorContainer.style.marginBottom = "10px";
					
					errorContainer.style.padding 	= "5px"; 
					
					fieldToCol2.appendChild(errorContainer);
				
				fieldToRow.appendChild(fieldToCol1);
				fieldToRow.appendChild(fieldToCol2);
			
			fieldTableBody.appendChild(fieldToRow);
			
			var fieldFromRow		= document.createElement("tr");
			fieldFromRow.vAlign		= "top";
			
				var fieldFromCol1		= document.createElement("td");
				var fieldFromCol2		= document.createElement("td");
				
				fieldFromCol1.innerHTML = "<b>From E-mail:</b><br><span style=\"#666666\">(optional)</span> ";
				fieldFromCol2.innerHTML = "<input type=\"text\" size=\"35\" id=\"emailFrom\">";
				fieldFromCol2.style.paddingLeft = "20px"; 
				
				// Error Pane *******************************
					var errorContainerAlt			= document.createElement("div");
					errorContainerAlt.id			= "emailFromError";
					errorContainerAlt.className 	= "errorContainer";
					errorContainerAlt.style.display = "none";
					errorContainerAlt.style.margin		= "0px";
					errorContainerAlt.style.marginTop	= "5px";
					errorContainerAlt.style.marginBottom = "10px";
					
					errorContainerAlt.style.padding 	= "5px"; 
					
					fieldFromCol2.appendChild(errorContainerAlt);
				
				fieldFromRow.appendChild(fieldFromCol1);
				fieldFromRow.appendChild(fieldFromCol2);
				
			fieldTableBody.appendChild(fieldFromRow);
		
		fieldTable.appendChild(fieldTableBody);
		contentElement.appendChild(fieldTable);
		
		var commentsContainer 	= document.createElement("div");
		commentsContainer.style.paddingTop = "20px";
		
		var commentsText		= document.createElement("div");
		commentsText.innerHTML	= "If you would like to include a message, please type it here:";
		
		var commentsField		= document.createElement("textarea")
		commentsField.id		= "commentsField";
		commentsField.cols		= 40;
		commentsField.rows		= 5;
		
		commentsContainer.appendChild(commentsText);
		commentsContainer.appendChild(commentsField);
		
		contentElement.appendChild(commentsContainer);
		
		var buttonContainer					= document.createElement("div");
		buttonContainer.style.paddingTop 	= "20px";
		buttonContainer.align				= "center";
		buttonContainer.innerHTML 			= "<input type=\"button\" id=\"sendBtn\" value=\"Send E-mail\" onclick=\"sendProductPageEmail()\">";
		buttonContainer.innerHTML		   += "<input type=\"button\" id=\"cancelBtn\" value=\"Cancel\" onclick=\"restorePageBackground()\">";
		
		contentElement.appendChild(buttonContainer);
		graphicContainer.appendChild(contentElement);
		
		contentElementPopup(productName + "<span style=\"color: #666666;\"> | Email this Product Page </span>",  graphicContainer);
	}

 /* Email This Product Page ********************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	NOTHING
 *	NOTE:		
 *	
 ************************************************************************************/
 
	function sendProductPageEmail()
	{
		var emailToValue 	= getElement("emailTo").value;
		var emailFromValue 	= getElement("emailFrom").value;
		var commentsValue	= getElement("commentsField").value;
		
		var errorMessage	= "";
		var result			= "";
		
		result = dataIsValid(emailToValue, "email");
		if (result != true)
		{
			getElement("emailToError").innerHTML = "Please enter a valid e-mail address.";
			showElement("emailToError");
			errorMessage += result;
		}
		else
		{
			hideElement("emailToError");	
		}
		
		result = dataIsValid(emailFromValue, "email");
		if ((emailFromValue != "") & (result != true))
		{
			getElement("emailFromError").innerHTML = "Please enter a valid e-mail address.";
			showElement("emailFromError");
			errorMessage += result;
		}
		else
		{
			hideElement("emailFromError");	
		}
		
		if (errorMessage == "")
		{
			var productName	= getElement("productName").value;
			var productLink	= getElement("productLink").value;
			
			// Disable Buttons ******************
			getElement("sendBtn").disabled = true;
			getElement("cancelBtn").disabled = true;
			
			commentsValue = encodeQueryString(commentsValue);
			
			setAjaxUrl("updateData", "/Includes/api/brdApiEmail.asp?action=sendProductPageEmail&productName=" + productName + "&productLink=" + productLink + "&emailTo=" + emailToValue + "&emailFrom=" + emailFromValue + "&comments=" + commentsValue, false, "alertShadedPopup('Email Product Page Status', 'E-mail Sent Successfully!');");
		}
		
	}
	
/*  Add Log Item  ********************************************************
 *
 *	TAKES:		Item Type, Item Id, Item Descr, Old Value, New Value
 * 	RETURNS:	NOTHING
 *	NOTE:		Log Action is determined based on the old and new values.
 *
 ********************************************************************************/
 
 	function addLogItem(itemType, itemId, itemDescr, oldValue, newValue, logUser)
	{
		var logAction = "";
		
		if (oldValue == " ")
		{
			oldValue = "";	
		}
		
		if (newValue == " ")
		{
			newValue = "";	
		}
		
		if ((oldValue != "") & (newValue != "") & (oldValue != newValue))
		{
			logAction = "CHANGED";	
		}
		else if ((oldValue != "") & (newValue == ""))
		{
			logAction = "REMOVED";	
		}
		else if ((oldValue == "") & (newValue != ""))
		{
			logAction = "ADDED";	
		}
		
		if ((logAction != "") & (logUser != ""))
		{
			var queryVars = "&itemType=" + encodeQueryString(itemType);
			queryVars += 	"&itemId=" + encodeQueryString(itemId);
			queryVars += 	"&itemDescr=" + encodeQueryString(itemDescr);
			queryVars += 	"&oldValue=" + encodeQueryString(oldValue);
			queryVars += 	"&newValue=" + encodeQueryString(newValue);
			queryVars += 	"&logAction=" + encodeQueryString(logAction);
			queryVars += 	"&logUser=" + encodeQueryString(logUser);
			
			setAjaxUrl("dataPane", "/Includes/api/brdApiQuery.asp?action=addLogItem" + queryVars, false, false);	
		}
	}
	
/*  Iterate Element List  ********************************************************
 *
 *	TAKES:		Element List, Iterate Action Function
 * 	RETURNS:	NOTHING
 *	NOTE:		The Element List produces an iterator object with two values:
 *					1. index 	[0]
 *					2. element	[1]
 *
 *				The Iterate Action Function must provide a definition for these values:
 *					EX: function(element, index)
 *
 *	EX CALL:	iterateElementList(exampleList, exampleFunc);
 *
 ********************************************************************************/
 
 	function iterateElementList(elementList, iterateAction)
	{
		if ((elementList != null) & (iterateAction != null))
		{
			if (thisBrowser != "Firefox")
			{
				// Manual Iteration ************************
				if (elementList.length > 0)
				{
					var element = "";
					
					for(var index=0; index<elementList.length; index++)
					{
						element = elementList[index];
						iterateAction(element, index);
					}
				}
				
			}
			else
			{
				// Javascript 1.7 Support ******************
				var iterator = Iterator(elementList);
				
				try
				{
					while(true)
					{
						var iteratorElement = iterator.next();
						var index 	= iteratorElement[0];
						var element = iteratorElement[1];
						
						iterateAction(element, index);
					}
				}
				catch (err)
				{
					if (!err instanceof StopIteration)
					{
						alert("ERROR: Iterate Element List\n\n" + err.description);	
					}
					else
					{
						// Iteration Complete
					}
				}
				
			} // IE
		}
	}
	
/*  Date Prototype Format  ********************************************************
 *
 *	TAKES:		Format String
 * 	RETURNS:	Formated String
 *	NOTE:		Mimics PHP's date format 
 *
 ********************************************************************************/
 
    Date.prototype.format = function(format) {
	    var returnStr = '';
	    var replace = Date.replaceChars;
	    for (var i = 0; i < format.length; i++) {
		    var curChar = format.charAt(i);
		    if (replace[curChar]) {
			    returnStr += replace[curChar].call(this);
		    } else {
			    returnStr += curChar;
		    }
	    }
	    return returnStr;
    };

    Date.replaceChars = {
	    shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
	    longMonths: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
	    shortDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
	    longDays: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
    	
	    // Day
	    d: function() { return (this.getDate() < 10 ? '0' : '') + this.getDate(); },
	    D: function() { return Date.replaceChars.shortDays[this.getDay()]; },
	    j: function() { return this.getDate(); },
	    l: function() { return Date.replaceChars.longDays[this.getDay()]; },
	    N: function() { return this.getDay() + 1; },
	    S: function() { return (this.getDate() % 10 == 1 && this.getDate() != 11 ? 'st' : (this.getDate() % 10 == 2 && this.getDate() != 12 ? 'nd' : (this.getDate() % 10 == 3 && this.getDate() != 13 ? 'rd' : 'th'))); },
	    w: function() { return this.getDay(); },
	    z: function() { return "Not Yet Supported"; },
	    // Week
	    W: function() { return "Not Yet Supported"; },
	    // Month
	    F: function() { return Date.replaceChars.longMonths[this.getMonth()]; },
	    m: function() { return (this.getMonth() < 9 ? '0' : '') + (this.getMonth() + 1); },
	    M: function() { return Date.replaceChars.shortMonths[this.getMonth()]; },
	    n: function() { return this.getMonth() + 1; },
	    t: function() { return "Not Yet Supported"; },
	    // Year
	    L: function() { return (((this.getFullYear()%4==0)&&(this.getFullYear()%100 != 0)) || (this.getFullYear()%400==0)) ? '1' : '0'; },
	    o: function() { return "Not Supported"; },
	    Y: function() { return this.getFullYear(); },
	    y: function() { return ('' + this.getFullYear()).substr(2); },
	    // Time
	    a: function() { return this.getHours() < 12 ? 'am' : 'pm'; },
	    A: function() { return this.getHours() < 12 ? 'AM' : 'PM'; },
	    B: function() { return "Not Yet Supported"; },
	    g: function() { return this.getHours() % 12 || 12; },
	    G: function() { return this.getHours(); },
	    h: function() { return ((this.getHours() % 12 || 12) < 10 ? '0' : '') + (this.getHours() % 12 || 12); },
	    H: function() { return (this.getHours() < 10 ? '0' : '') + this.getHours(); },
	    i: function() { return (this.getMinutes() < 10 ? '0' : '') + this.getMinutes(); },
	    s: function() { return (this.getSeconds() < 10 ? '0' : '') + this.getSeconds(); },
	    // Timezone
	    e: function() { return "Not Yet Supported"; },
	    I: function() { return "Not Supported"; },
	    O: function() { return (-this.getTimezoneOffset() < 0 ? '-' : '+') + (Math.abs(this.getTimezoneOffset() / 60) < 10 ? '0' : '') + (Math.abs(this.getTimezoneOffset() / 60)) + '00'; },
	    P: function() { return (-this.getTimezoneOffset() < 0 ? '-' : '+') + (Math.abs(this.getTimezoneOffset() / 60) < 10 ? '0' : '') + (Math.abs(this.getTimezoneOffset() / 60)) + ':' + (Math.abs(this.getTimezoneOffset() % 60) < 10 ? '0' : '') + (Math.abs(this.getTimezoneOffset() % 60)); },
	    T: function() { var m = this.getMonth(); this.setMonth(0); var result = this.toTimeString().replace(/^.+ \(?([^\)]+)\)?$/, '$1'); this.setMonth(m); return result;},
	    Z: function() { return -this.getTimezoneOffset() * 60; },
	    // Full Date/Time
	    c: function() { return this.format("Y-m-d") + "T" + this.format("H:i:sP"); },
	    r: function() { return this.toString(); },
	    U: function() { return this.getTime() / 1000; }
    };
    
/*  Convert to Inches ********************************************************
 *
 *	TAKES:	    Dimension Value, Units	
 * 	RETURNS:	Inches Value
 *	NOTE:		
 *
 ********************************************************************************/
 
 	function convertToInches(dimValue, currentUnits)
	{
	    var inchesValue = null;
	    
	    if (dataIsValid(dimValue, "integer") || dataIsValid(dimValue, "float"))
	    {
	        switch(currentUnits)
	        {
	            case inchesTag:
	                
	                inchesValue = dimValue;
	                break;
	                
	            case feetTag:
	            
	                inchesValue = dimValue * 12;
	                break;
	                
	            case centimetersTag:
	                
	                inchesValue = dimValue * 0.393700787;
	                break;
	                
	            case metersTag:
	                
	                inchesValue = dimValue * 39.3700787;
	                break;
	                
	            default:
	                
	                break;
	        }
	    }
	    
	    return inchesValue;
	}

/*  Convert to Feet ********************************************************
 *
 *	TAKES:	    Dimension Value, Units	
 * 	RETURNS:	Feet Value
 *	NOTE:		
 *
 ********************************************************************************/
 
 	function convertToFeet(dimValue, currentUnits)
	{
	    var feetValue = null;
	    var inchesValue = convertToInches(dimValue, currentUnits);
	    
	    if (inchesValue != null)
	    {
	        feetValue = roundFloat(inchesValue / 12, 3);
	    }
	    
	    return feetValue;
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

	
	
	
	
	
