
function trim(str) {
	return str.replace(/^\s*|\s*$/g,"");
}

/*-----------------------------------------------------*/
function AllSelectsVisibility(status) {
	var allSelects = document.getElementsByTagName('select');
	if (allSelects.length > 0) {
		for (x=0;x<allSelects.length;x++) {
			allSelects[x].style.visibility = status;
		}
	}
}

/*-----------------------------------------------------*/
function styleShift(eleName,eleStyle,eleStyleValue) {
    eval("document.getElementById('" + eleName + "').style." + eleStyle + "='" + eleStyleValue + "';");
}

/*-----------------------------------------------------*/
function WS(message) 
{
    window.status = message;
}

/*-----------------------------------------------------*/
function IFrameOutputFormat(iFrameName,format) 
{
    if (format != "")
    {
        eval("window.frames." + iFrameName + ".OutputFormat('" + format + "');");
    }
}

/*-----------------------------------------------------*/
function ChildIFrameObject(iFrameName)
{
    //var doc = document;
    //var frm = document.frames ? parent.frames[iFrameName] : document.getElementById(iFrameName);
    //var ele = frm.document || frm.contentWindow.document;
    return eval("window.frames." + iFrameName + ".document");
}


/*----------------------------------
--------- Navigation -------------
----------------------------------*/

	var MenuCache = new Object();
		MenuCache.menu = null;
		MenuCache.button = null;
		MenuCache.submenu = null;
	
	function GEID(id) { return document.getElementById(id) };

	function Menu(id)
	{
	    if (!(document.readyState == "complete"))
	    {
	        return;
	    }
		CloseNav();
		var menu = GEID('M' + id);
		var button = GEID('B' + id);
		var mask = GEID("NavMask");
		
		MenuCache.button = button;
		MenuCache.menu = menu;
		
		button.className = "BH";
		
		var M = menu.style;
		var BO = new RecurseOffset(button);
			M.left = BO.GetOffsetLeft() + "px";
			M.top = (BO.GetOffsetTop() + button.offsetHeight) + "px";
			M.display = "block";
			
		var K = mask.style;
		var MO = new RecurseOffset(menu);
			K.width = (WindowInner.width - 20) + "px";
			//K.height = (WindowInner.height - MO.GetOffsetTop() - 20) + "px";
			K.height = "600px";
			K.display = "block";
			
		MenuSweepSelects(menu);
	}
	/*-----------------------------------------------------*/
	function SubMenu(id)
	{
		CloseSubMenu();
		var submenu = GEID('S' + id);
		var button = GEID('B' + id);
		var mask = GEID("NavMask");
		
		MenuCache.submenu = submenu;
		
		var M = submenu.style;
		var BO = new RecurseOffset(button);
			M.left = BO.GetOffsetLeft() + button.offsetWidth - 2 + "px";
			M.top = BO.GetOffsetTop() + "px";
			M.display = "block";
			
		MenuSweepSelects(submenu);
	}
	
	/*-----------------------------------------------------*/
	function CloseNav()
	{
	    if (MenuCache.button != null)
		{
			MenuCache.button.className = "BB";
		}
		if (MenuCache.menu != null)
		{
			MenuCache.menu.style.display = "none";
		}
		CloseSubMenu();
		document.getElementById("NavMask").style.display = "none";
		MenuRestoreSelects();
	}
	
	function CSM() { CloseSubMenu(); }

	/*-----------------------------------------------------*/
	function CloseSubMenu()
	{
		if (MenuCache.submenu != null)
		{
			MenuCache.submenu.style.display = "none";
		}
	}
	
	//========================================================
	//   RecurseOffset
	//   returns true offsetLeft and offsetTop
	//========================================================
	function RecurseOffset(obj)
	{
		this.ParentObj = null;
		this.CurrentObj = obj;
	    this.AbsoluteLeft = obj.offsetLeft;
	    this.AbsoluteTop = obj.offsetTop;
		RecurseOffset.prototype.Init = function()
		{
		    if (this.CurrentObj.offsetParent != null)
		    {
		        do
			    {
	                this.ParentObj = this.CurrentObj.offsetParent;
	                this.AbsoluteLeft += this.ParentObj.offsetLeft;
	                this.AbsoluteTop += this.ParentObj.offsetTop;
	                this.CurrentObj = this.ParentObj;
			    }
			    while (this.CurrentObj.offsetParent != null);
		    }
		}
		RecurseOffset.prototype.GetOffsetLeft = function() { return this.AbsoluteLeft; }
		RecurseOffset.prototype.GetOffsetTop = function() { return this.AbsoluteTop; }
		this.Init();
	}
	//========================================================
	//   MenuRestoreSelects
	//   Restores selects on page hidden by menu
	//========================================================
	function MenuRestoreSelects()
	{
	    var SelectCollection = document.getElementsByTagName("select");
	        for (var s=0;s<SelectCollection.length;s++)
	        {   
	            SelectCollection[s].style.visibility="visible";
	        }
	}
	//========================================================
	//   MenuSweepSelects(MenuObject)
	//   Hides selects in collision with MenuObject
	//========================================================
	function MenuSweepSelects(MenuObject)
	{
	    var RO = new RecurseOffset(MenuObject);
	    var MenuLeft = RO.GetOffsetLeft();
	    var MenuTop = RO.GetOffsetTop();
	    var MenuRight = MenuLeft + MenuObject.offsetWidth;
	    var MenuBottom = MenuTop + MenuObject.offsetHeight;
	    
	    var SelectCollection = document.getElementsByTagName("select");
	    
	    for (var s=0;s<SelectCollection.length;s++)
	    {
	        var SelectObject = SelectCollection[s];
	        var SO = new RecurseOffset(SelectObject);
    	    var SelectLeft = SO.GetOffsetLeft();
            var SelectTop = SO.GetOffsetTop();
            var SelectRight = SelectLeft + SelectObject.offsetWidth;
            var SelectBottom = SelectTop + SelectObject.offsetHeight;
            
            //====================== detect collision
           
            if (
                (SelectRight > MenuLeft) &&
                (SelectBottom > MenuTop) &&
                (SelectLeft < MenuRight) &&
                (SelectTop < MenuBottom)
                )
                {
                    SelectObject.style.visibility = "hidden";
                    //return;
                }
                
            //======================= if position of select is not detectible, hide to be sure
            if ((SelectLeft == 0) && (SelectTop == 0))
            {
                SelectObject.style.visibility = "hidden";
                //return;
            }
                
	    }
	    
	}
	
	//========================================================
	//   WindowInner
	//   captures window inner width and window inner height
	//	 fires on page load and page resize
	//========================================================
	var WindowInner = new Object();
		WindowInner.width = 0;
		WindowInner.height = 0;
		
	function GetWindowInner()
	{
		if (document.all) 
		{
		    WindowInner.width = document.body.clientWidth + document.body.scrollLeft;
		    WindowInner.height = document.body.clientHeight + document.body.scrollTop;
		} 
		else
		{
		    WindowInner.width = window.innerWidth+window.pageXOffset;
		    WindowInner.height = window.innerHeight+window.pageYOffset;
		}
		return;
	}


/*-----------------------------------------------------*/
function openFolderView(url) 
{
	top.window.location.href = "../FolderView/Folders.aspx?page=" + url;
}

/*-----------------------------------------------------*/
function saveToFolder(url,tempname) 
{
    top.window.location.href = "../FolderView/Folders.aspx?tempname=" + escape(tempname) + "&action=save&page=" + url;
}

/*-----------------------------------------------------*/
function closeFolderView(url) 
{
	top.window.location.href = url;
}

/*-----------------------------------------------------*/
function ClearCache() 
{
    var myAnswer = window.confirm("This will clear all cached data.\n\nAre you sure you want to do this?");
    if (myAnswer) 
    {
        document.getElementById("hiddenTarget").src = '../Components/ClearCache.aspx';
    }
}
/*
----------------------------------
--------- Tab Panels -------------
----------------------------------
*/

function blurTabPanel(TabID)
{
    if (TabID.indexOf("TabDark") > -1)
    {
        document.getElementById("Tab"+TabID).className = 'tabPanelDarkTabDim';
    }
    else
    {
        document.getElementById("Tab"+TabID).className = 'tabPanelTabDim';
    }
    
    document.getElementById("TabPanel"+TabID).style.display = 'none';
}

function sweepTabPanels() {
	for (x=0;x<myPanels.length;x++) {
	    blurTabPanel(myPanels[x]);
	}
}

function TabPanel(TabID) {
	sweepTabPanels();
    document.getElementById("Tab"+TabID).className = 'tabPanelTab';
	document.getElementById("TabPanel"+TabID).style.display = 'block';
}


/*-----------------------------------------------------*/
var HTMLAreas = new Array();

function detectAndLoadHTMLArea(elementID) {
        
        try {
            var detect = document.getElementById('HTMLArea_' + elementID).style.width;
        } catch(e) {
            var HTMLAreaTimer = window.setTimeout(function(){
                HTMLArea.replace(elementID, config);
                HTMLAreas[elementID] = HTMLArea.getElementById("textarea", elementID);
                }, 100);
        }
 
    
    //here, a new IFRame was just loaded to the DOM
    //var ifr = document.getElementsByTagName('iframe');
    //for (x=0;x<ifr.length;x++) {
        //alert(ifr[x].getAttribute('id'));
   // }
}
/*
----------------------------------
--------- Fade Effect ------------
----------------------------------
*/

function opacity(id, opacStart, opacEnd, millisec) {
	var speed = Math.round(millisec / 101);
	var timer = 0;

	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 101);
	object.MozOpacity = (opacity / 101);
	object.KhtmlOpacity = (opacity / 101);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}


function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}

/*
----------------------------------
--------------- Help -------------
----------------------------------
*/

function getInnerWidth() {
	var theWidth;
	if (window.innerWidth) { 
		theWidth = window.innerWidth;
	} else if (document.documentElement && document.documentElement.clientWidth) {
		theWidth = document.documentElement.clientWidth;
	} else if (document.body) {
		theWidth = document.body.clientWidth;
	} else {
		theWidth = 800;
	}
	return theWidth;
}

function getInnerHeight() {
	var theHeight;
	if (window.innerHeight) {
		theHeight = window.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		theHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		theHeight = document.body.clientHeight;
	} else {
		theHeight = 800;
	}
	return theHeight;
}

/*-----------------------------------------------------*/
function drawHelpElements() {
		document.write("<DIV ID='checkerboard' STYLE='position:absolute;visibility:hidden;z-index:500;left:0;top:0;width:" + getInnerWidth() + "px;height:" + getInnerHeight() + "px;background-image:url(../images/checkerboard.gif);'>&nbsp;</DIV>");
		document.write("<IFRAME NAME='innerHelp' ID='innerHelp' FRAMEBORDER=0 BORDER=0 SRC=../Components/Blank.aspx STYLE='position:absolute;visibility:hidden;z-index:550;left:" + parseInt((getInnerWidth() - 600) / 2) + ";top:" + parseInt((getInnerHeight() - 400) / 2) + ";width:600px;height:400px;background-color:#ffffff;border:6px solid #000000;'></IFRAME>");
}
var myHelp = null;

function goHelp(helpPage) {
	var thisHelpPage = '../Help/default.aspx';
		if (helpPage=='' | helpPage==undefined) {
			thisHelpPage = '../Help/default.aspx?id=0';
		} else {
			thisHelpPage = '../Help/default.aspx?id=' + helpPage;
		}
		
        myHelp = window.open(thisHelpPage,'myHelpWindow','left=' + parseInt((screen.width - 600) / 2) + ',top=' + parseInt((screen.height - 400) / 2) + ',width=720,height=450,statusbar=no,resizable=yes');
	    myHelp.focus();

	return; 
}

/*-----------------------------------------------------*/
function supportTicket(thePage,theErrorText) {

    var myString = "\n\n\n\n=================================================\n";
        myString += "INFORMATION FOR SUPPORT PERSONNEL - DO NOT REMOVE\n";
        myString += "=================================================\n";
        myString += "PAGE: " + thePage + "\n\n" + theErrorText;
        
    thisHelpPage = '../Help/default.aspx?id=26&errorText=' + escape(myString);
    
    myHelp = window.open(thisHelpPage,'myHelpWindow','left=' + parseInt((screen.width - 600) / 2) + ',top=' + parseInt((screen.height - 400) / 2) + ',width=720,height=450,statusbar=no,resizable=yes');
	myHelp.focus();
}

/*-----------------------------------------------------*/
function getJobWebID() {
    var Today 	= new Date();
    var TYear 	= Today.getYear();
    var TMonth 	= Today.getMonth() + 1
    var TDay	= Today.getDate();
    var THour   = Today.getHour();
    var TMinute = Today.getMinute();
    var TSecond = Today.getSecond();
    var JobWebID = TYear + '' + TMonth + '' + TDay + '' + THour + '' + TMinute + '' + TSecond;
        alert(JobWebID);
}

/*-----------------------------------------------------*/
function CacheImages(arrImageNames, arrImageStates, ImageRoot, ImageExtension)
{
    // uses syntax for common image naming on rollover states:
    // [name] _ [state] . [extension]
    
    ImageRoot = ((ImageRoot == undefined) ? "../images" : (ImageRoot == null) ? "../images" : ImageRoot);
    ImageExtension = ((ImageExtension == undefined) ? "gif" : (ImageExtension == null) ? "gif" : ImageExtension);

    for (var i = 0; i < arrImageNames.length; i++)
    {
        for (var s = 0; s < arrImageStates.length; s++)
        {
            eval(arrImageNames[i] + "_" + arrImageStates[s] + " = new Image();");
            eval(arrImageNames[i] + "_" + arrImageStates[s] + ".src = '" + ImageRoot + "/" + arrImageNames[i] + "_" + arrImageStates[s] + "." + ImageExtension + "';");
        }
    }
}



/*----------------------------------
------ Countdown session ---------
----------------------------------*/

function sessionCountdown(year, month, day, hour, minute) 
{
         //var myCountdown = null;
         Today = new Date();
         Todays_Year = Today.getYear();
         Todays_Month = Today.getMonth() + 1;                  
              
         Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();                                 
         Target_Date = (new Date(year, month, day, hour, minute, 00)).getTime();                  
                          
         Time_Left = Math.round((Target_Date - Todays_Date) / 1000);
         
         if (Time_Left > 0) 
         {
//		 	window.alert("Your Session Has expired.");
//		 	clearTimeout(myCountdown);
//            //top.window.location.href="../logout.aspx";
//		}
//		else
//		{
         
             days = Math.floor(Time_Left / (60 * 60 * 24));
             Time_Left %= (60 * 60 * 24);
             hours = Math.floor(Time_Left / (60 * 60));
             Time_Left %= (60 * 60);
             minutes = Math.floor(Time_Left / 60);
             Time_Left %= 60;
             seconds = Time_Left;
             
             dps = 's'; hps = 's'; mps = 's'; sps = 's';

             if(days == 1) dps ='';
             if(hours == 1) hps ='';
             if(minutes == 1) mps ='';
             if(seconds == 1) sps ='';
             
			 var timeString
			 	timeString = 'Session Expires in ';
             if (parseInt(hours) > 0) {
			 	timeString += hours + ' hr' + hps + ', ';
			}
             timeString += addLeadingZero(minutes) + ' min' + mps + ', ';
             timeString += addLeadingZero(seconds) + ' sec' + sps;
    		 
		     if (document.getElementById('countdown')) {
		        document.getElementById('countdown').innerHTML = timeString;
		     }
			
            myCountdown = setTimeout('sessionCountdown(' + year + ',' + month + ',' + day + ',' + hour + ',' + minute + ');', 1000);
        }
}
 

function addLeadingZero(str) {
    if (str.toString().length < 2) {
        str = "0" + str;
    }
    return str;
}
/*
----------------------------------
---------- Calculator ------------
----------------------------------
*/
function calculator(formEle,OnCloseEvent) {
		
		//AllSelectsVisibility('hidden');
	var myUrl = '../includes/calculator.aspx?formEle=' + formEle + '&OnCloseEvent=' + escape(OnCloseEvent);
	
	var IFStyle = document.getElementById('icalculator').style;
		IFStyle.visibility = 'visible';
		IFStyle.left = document.windowVals.MouseX.value + "px";
		IFStyle.top = document.windowVals.MouseY.value + "px";
		document.getElementById('icalculator').src = myUrl;
}

function closecalculator() {
		var IFStyle = document.getElementById('icalculator').style;
		IFStyle.visibility = 'hidden';
		IFStyle.left = '0px';
		IFStyle.top = '0px';
		//document.getElementById('icalculator').src = '../includes/blank.html';
		//AllSelectsVisibility('visible');
}

/*-----------------------------------------------------*/

// Global variables
var MousePosition = new Object();
    MousePosition.X = 0;
    MousePosition.Y = 0;

function captureMousePosition(e) 
{
    if (document.layers) 
    {
        MousePosition.X = e.pageX + 25;
        MousePosition.Y = e.pageY - 25;
    } 
    else if (document.all) 
    {
        MousePosition.X = window.event.x + document.body.scrollLeft + 25;
        MousePosition.Y = window.event.y + document.body.scrollTop - 25;
    } 
    else if (document.getElementById) 
    {
        MousePosition.X = e.pageX + 25;
        MousePosition.Y = e.pageY - 25;
    }
}

function CaptureMouseXY() {
	// Set Netscape up to run the "captureMousePosition" function whenever
	// the mouse is moved. For Internet Explorer and Netscape 6, you can capture
	// the movement a little easier.
	if (document.layers) { // Netscape
	    document.captureEvents(Event.MOUSEMOVE);
	    document.onmousemove = captureMousePosition;
	} else if (document.all) { // Internet Explorer
	    document.onmousemove = captureMousePosition;
	} else if (document.getElementById) { // Netcsape 6
	    document.onmousemove = captureMousePosition;
	}
}


/*-----------------------------------------------------*/
function ToExcel(){ 
		if (window.ActiveXObject){ 
		
		var  xlApp = new ActiveXObject("Excel.Application"); 
		var xlBook = xlApp.Workbooks.Add(); 
		
		
		xlBook.worksheets("Sheet1").activate; 
		var XlSheet = xlBook.activeSheet; 
		xlApp.visible = true; 
		
		for(var P = 1; P<= obj.getRowProperty("count"); P++){ 
		
		      for(var Q = 1; Q <= obj.getColumnProperty("count"); Q++){ 
		      if (P==1){ 
		      XlSheet.cells(P ,Q).value = obj.getColumnProperty("text",Q-1) 
		      } 
		       
		             XlSheet.cells(P +1,Q).value = obj.getDataText(P-1,Q-1); 
		} 
		} 
		XlSheet.columns.autofit; 
	} 
}//end function 


/*----------------------------------
--- Remove duplicates in array ---
----------------------------------*/

function removeDuplicates(array) { 
    //var temp = field.value; 
    //var array = temp.split(" "); 
    var orig = array; 
    array.sort(); 
    temp = array.join(" "); 
    do { 
        var newTemp = temp; 
        var temp = newTemp.replace(/\s(\w+\s)\1/, " $1"); 
    } while (temp.length != newTemp.length); 
    temp = temp.replace(/^(\w+\s)\1/, "$1"); 
    temp = temp.replace(/(\s\w+)\1$/, "$1"); 
    
    var finalStr = ""; 
    for (var i=0; i<orig.length; i++) { 
        if (temp.indexOf(orig[i] + " ") != -1) { 
            finalStr += orig[i] + " "; 
            temp = temp.split(orig[i] + " ").join(" "); 
        } else if (temp.indexOf(" " + orig[i]) != -1) { 
        finalStr += orig[i] + " "; 
        temp = temp.split(" " + orig[i]).join(" "); 
        } 
    } 
    if (finalStr.substring(finalStr.length-1, finalStr.length) == " ") { 
        finalStr = finalStr.substring(0, finalStr.length-1); 
    } 
    return finalStr.split(" ");
} 

/*========================================================\
|   inArray  
|   requires [Array] [String:value]
|---------------------------------------------------------:
|   returns True if found, False if not
|   uses "===" for exact match, not just similar
`========================================================*/
function inArray(targetArray, value)
{
    var i;
    for (i=0;i<targetArray.length;i++) 
    {
        if (trim(targetArray[i]+" ") === trim(value+" ")) // make sure both are strings for comparison
        {
            return true;
        }
    }
    return false;
}

/*-----------------------------------------------------*/
/* fix PNGs */
function fixPNG(myImage) 
{
    var arVersion = navigator.appVersion.split("MSIE");
    var version = parseFloat(arVersion[1]);
        if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
        {
           var imgID = (myImage.id) ? "id='" + myImage.id + "' " : "";
           var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : "";
           var imgTitle = (myImage.title) ? "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' ";
           var imgStyle = "display:inline-block;" + myImage.style.cssText;
           var strNewHTML = "<span " + imgID + imgClass + imgTitle
                      + " style=\"" + "width:" + myImage.width 
                      + "px; height:" + myImage.height 
                      + "px;" + imgStyle + ";"
                      + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                      + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>";
           myImage.outerHTML = strNewHTML;
        }
}

/*========================================================\
|   FormatInteger  
|   [Expression:num]     = if not a number, returns "NaN"
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|   Returns string formatted as rounded integer
`========================================================*/

function FormatInteger(num)
{   
    return FormatNumber(parseInt(num,10),0,false);
}

/*========================================================\
|   FormatFloat 
|   [Expression:num]     = if not a number, returns "NaN"
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|   Returns string formatted as Float
`========================================================*/

function FormatFloat(num)
{   
    var DecimalCount = 0;
    num = new String(num);
    if (num.indexOf(".") > 0)
    {
        var numSplit = num.split(".");
        DecimalCount = numSplit[1].length;
    }
    return FormatNumber(parseFloat(num),DecimalCount,false);
}

/*========================================================\
|   FormatCurrency  
|   [Expression:num]     = if not a number, returns "NaN"
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|   Returns string formatted as currency
`========================================================*/

function FormatCurrency(num)
{   
    var newNum = FormatNumber(num,2,false);
    if (newNum != "NaN")
    {
        newNum = "$" + newNum;
    }
    return newNum;
}

/*========================================================\
|   FormatNumber  requires 
|   [Expression:num]     = if not a number, returns NaN
|   [Integer:decimalNum] = # of decimal places
|   [Boolean:LeadingZero]= return leading zero or not
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|   Returns string formatted as number
`========================================================*/

function FormatNumber(num,decimalNum,bolLeadingZero)
{ 
    if (isNaN(parseInt(num))) 
    {
        return "NaN";
    }
	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// positive or negative
	
	//-- Decimal palces
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;
	
	var tmpNumStr = new String(tmpNum); //-- number is a string

	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
	{
	    if (num > 0)
	    {
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
	    }
		else
		{
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
	    }
	}
		
	//--- Commas
	if ((num >= 1000 || num <= -1000)) 
	{
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
		{
			iStart = tmpNumStr.length;
		}
		iStart -= 3;
		while (iStart >= 1) 
		{
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length);
			iStart -= 3;
		}		
	}
	
	//--- add extra zeros at end if needed for currency
	
	if (decimalNum == 2)
	{
	    var iStart = tmpNumStr.indexOf(".");
	    if (iStart < 0)
	    {
	        tmpNumStr += ".00";
	        return tmpNumStr;
	    }
	    if (iStart < tmpNumStr.length)
	    {
	        var afterZero = tmpNumStr.substring(iStart+1);
	        if (afterZero.length == 1)
	        {
	            tmpNumStr += "0";
	            return tmpNumStr;
	        }
	    }

	}
	return tmpNumStr;
}

/*-----------------------------------------------------*/
function CleanWordHTML( html, bIgnoreFont, bRemoveStyles, bRemoveMargins, bRemovePadding )
{
	html = html.replace(/<o:p>\s*<\/o:p>/g, "") ;
	html = html.replace(/<o:p>.*?<\/o:p>/g, "&nbsp;") ;
	
	// Remove mso-xxx styles.
	html = html.replace( /\s*mso-[^:]+:[^;"]+;?/gi, "" ) ;

	// Remove margin styles.
	html = html.replace( /\s*MARGIN: 0cm 0cm 0pt\s*;/gi, "" ) ;
	html = html.replace( /\s*MARGIN: 0cm 0cm 0pt\s*"/gi, "\"" ) ;
	html = html.replace( /\s*TEXT-INDENT: 0cm\s*;/gi, "" ) ;
	html = html.replace( /\s*TEXT-INDENT: 0cm\s*"/gi, "\"" ) ;
	html = html.replace( /\s*TEXT-ALIGN: [^\s;]+;?"/gi, "\"" ) ;
	html = html.replace( /\s*PAGE-BREAK-BEFORE: [^\s;]+;?"/gi, "\"" ) ;
	html = html.replace( /\s*FONT-VARIANT: [^\s;]+;?"/gi, "\"" ) ;
	html = html.replace( /\s*tab-stops:[^;"]*;?/gi, "" ) ;
	html = html.replace( /\s*tab-stops:[^"]*/gi, "" ) ;

	// Remove Class attributes
	html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;
    
    if ( bRemovePadding )
	{
        html = html.replace( /<(\w[^>]*) style="padding([^\"]*)"([^>]*)/gi, "<$1$3" ) ;
    }
    
    if ( bRemoveMargins )
	{
        html = html.replace( /<(\w[^>]*) style="margin([^\"]*)"([^>]*)/gi, "<$1$3" ) ;
    }
    
	// Remove FONT face attributes.
	if ( bIgnoreFont )
	{
		html = html.replace( /\s*face="[^"]*"/gi, "" ) ;
		html = html.replace( /\s*face=[^ >]*/gi, "" ) ;
		html = html.replace( /\s*FONT-FAMILY:[^;"]*;?/gi, "" ) ;
	}
	
	// Remove styles.
	if ( bRemoveStyles )
	{
		html = html.replace( /<(\w[^>]*) style="([^\"]*)"([^>]*)/gi, "<$1$3" ) ;
    }
    
	// Remove empty styles.
	html = html.replace( /\s*style="\s*"/gi, '' ) ;
	html = html.replace( /<SPAN\s*[^>]*>\s*&nbsp;\s*<\/SPAN>/gi, '&nbsp;' ) ;
	html = html.replace( /<SPAN\s*[^>]*><\/SPAN>/gi, '' ) ;
	
	// Remove Lang attributes
	html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;
	html = html.replace( /<SPAN\s*>(.*?)<\/SPAN>/gi, '$1' ) ;
	html = html.replace( /<FONT\s*>(.*?)<\/FONT>/gi, '$1' ) ;

	// Remove XML elements and declarations
	html = html.replace(/<\\?\?xml[^>]*>/gi, "") ;
	
	// Remove Tags with XML namespace declarations: <o:p><\/o:p>
	html = html.replace(/<\/?\w+:[^>]*>/gi, "") ;
	
	html = html.replace( /<H\d>\s*<\/H\d>/gi, '' ) ;

	html = html.replace( /<H1([^>]*)>/gi, '<div$1><b><font size="6">' ) ;
	html = html.replace( /<H2([^>]*)>/gi, '<div$1><b><font size="5">' ) ;
	html = html.replace( /<H3([^>]*)>/gi, '<div$1><b><font size="4">' ) ;
	html = html.replace( /<H4([^>]*)>/gi, '<div$1><b><font size="3">' ) ;
	html = html.replace( /<H5([^>]*)>/gi, '<div$1><b><font size="2">' ) ;
	html = html.replace( /<H6([^>]*)>/gi, '<div$1><b><font size="1">' ) ;
	html = html.replace( /<\/H\d>/gi, '<\/font><\/b><\/div>' ) ;
	html = html.replace( /<(U|I|STRIKE)>&nbsp;<\/\1>/g, '&nbsp;' ) ;

	// Remove empty tags (three times, just to be sure).
	html = html.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;
	html = html.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;
	html = html.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;

	// Transform <P> to <DIV>
	var re = new RegExp("(<P)([^>]*>.*?)(<\/P>)","gi") ;	// Different because of a IE 5.0 error
	html = html.replace( re, "<div$2<\/div>" ) ;

	return html ;
}

/*-----------------------------------------------------*/
function ColorSelector(FieldName)
{
    //alert(FieldName);
    var theDiv = document.getElementById("ColorSelector");
        theDiv.style.left = document.windowVals.MouseX.value;
        theDiv.style.top = document.windowVals.MouseY.value;
    var DefaultColor = document.getElementById(FieldName).value;
    var AJAX = new AJAXObject(ColorSelectorDisplay);
        AJAX.GetPage("../Components/ColorSelector.aspx?FieldName=" + FieldName + "&DefaultColor=" + DefaultColor);
}

/*-----------------------------------------------------*/
function ColorSelectorDisplay(AjaxResponse)
{
    var theDiv = document.getElementById("ColorSelector");
        theDiv.style.display = "block";
        theDiv.innerHTML = AjaxResponse;
}

function ColorSelectorClose()
{
    document.getElementById("ColorSelector").style.display = "none";
}

function SwapColor(color)
{
    document.getElementById("SelectedColor").style.backgroundColor = color;
    document.HiddenColorForm.ColorTxt.value = color;
}

function ChooseColor(FieldName)
{
    //alert(FieldName);
    var color = document.HiddenColorForm.ColorTxt.value;
    //alert(color);
    document.getElementById(FieldName).value = color;
    document.getElementById(FieldName + 'ColorDisplay').style.backgroundColor = color;
    ColorSelectorClose();
}

//======================================
//  Numeric Entry
//======================================

var NumericEntryCache = new Object();
	NumericEntryCache.src = null;
	NumericEntryCache.className = null;
	
function ShowNumericEntry(ele)
{
    if (NumericEntryCache.src != null)
    {
        CloseNumericEntry();
    }
    
    if (ele.value == "0.00" || ele.value == "0.0" || ele.value == "0")
    {
        ele.value = "";
    }
	    NumericEntryCache.src = ele.name;
	    NumericEntryCache.className = ele.className;
	    
	var Mask = document.getElementById("NumericEntryMask");
    
    var Mask1 = Mask.cloneNode(true);
        Mask1.id = "NumericEntryMask1";
        AttachCloseNumericEntryEvent(Mask1);
    var Mask2 = Mask.cloneNode(true);
        Mask2.id = "NumericEntryMask2";
        AttachCloseNumericEntryEvent(Mask2);
    var Mask3 = Mask.cloneNode(true);
        Mask3.id = "NumericEntryMask3";
        AttachCloseNumericEntryEvent(Mask3);
    var Mask4 = Mask.cloneNode(true);
        Mask4.id = "NumericEntryMask4";
        AttachCloseNumericEntryEvent(Mask4);
    document.body.appendChild(Mask1);
    document.body.appendChild(Mask2);
    document.body.appendChild(Mask3);
    document.body.appendChild(Mask4);

	var NEntry = document.getElementById("NumericEntry");
	
	var R = new RecurseOffset(ele);
	
	ele.className = "NumericEntryField";
	
	NEntry.style.zIndex = "5010";
	NEntry.style.width = "50px";
	NEntry.style.height = "100px";
	NEntry.style.left = R.GetOffsetLeft() + ele.offsetWidth + 5 + "px";
	NEntry.style.top = (R.GetOffsetTop() - 15) + "px";
	NEntry.style.display = "block";
	
	Mask1.style.zIndex = "5000";
	Mask1.style.width = ele.offsetWidth + 150;
	Mask1.style.height = "50px";
	Mask1.style.left = (R.GetOffsetLeft()-50) + "px";
	Mask1.style.top = (R.GetOffsetTop()-60) + "px";
	Mask1.style.display = "block";
	
	Mask2.style.zIndex = "5000";
	Mask2.style.width = ele.offsetWidth + 150;
	Mask2.style.height = "100px";
	Mask2.style.left = (R.GetOffsetLeft()-50) + "px";
	Mask2.style.top = R.GetOffsetTop() + ele.offsetHeight + 35 + "px";
	Mask2.style.display = "block";
	
	Mask3.style.zIndex = "5000";
	Mask3.style.width = ele.offsetWidth + 50;
	Mask3.style.height = "150px";
	Mask3.style.left = (R.GetOffsetLeft() + ele.offsetWidth) + 10 + "px";
	Mask3.style.top = R.GetOffsetTop() - 10 + "px";
	Mask3.style.display = "block";
	
	Mask4.style.zIndex = "5000";
	Mask4.style.width = "100px";
	Mask4.style.height = "100px";
	Mask4.style.left = R.GetOffsetLeft() - 100 + "px";
	Mask4.style.top = R.GetOffsetTop() - 10 + "px";
	Mask4.style.display = "block";
	
}

function CloseNumericEntry()
{
    if (NumericEntryCache.src != null)
    {
	    var ele = document.getElementById(NumericEntryCache.src);
	        ele.className = NumericEntryCache.className;
    }
	    
	if (document.getElementById("NumericEntryMask1")) { document.body.removeChild(document.getElementById("NumericEntryMask1")); }
	if (document.getElementById("NumericEntryMask2")) { document.body.removeChild(document.getElementById("NumericEntryMask2")); }
	if (document.getElementById("NumericEntryMask3")) { document.body.removeChild(document.getElementById("NumericEntryMask3")); }
	if (document.getElementById("NumericEntryMask4")) { document.body.removeChild(document.getElementById("NumericEntryMask4")); }
	
	var NEntry = document.getElementById("NumericEntry");
	
	NEntry.style.width = "1px";
	NEntry.style.height = "1px";
	NEntry.style.left = "1px";
	NEntry.style.top = "1px";
	NEntry.style.display = "none";
	
	NumericEntryCache.src = null;
	
}

function AttachCloseNumericEntryEvent(element)
{
	if (document.all)
	{
		element.attachEvent('onmouseover',function(){CloseNumericEntry();});
	}
	else
	{
		element.addEventListener('mouseover',function(){CloseNumericEntry();},false);
	}
}

function NE(num)
{
	var ele = document.getElementById(NumericEntryCache.src);
	if (num == null)
	{
		ele.value = "";
	}
	else
	{
		ele.value = ele.value + num;
	}
}


