/*

	Please keep the following lines visible, in recognition of my work...

	************************	
	Author: Max Holman <max@blueroo.net>
	Date  : Sun, 21 Jan 2001
	************************

	This functions lets users type in letters to select an option in your SELECT form fields.

	Usually the browser only takes notice of single keystrokes and switches to the first Option that
	begins with that letter.

	This scripts buffers the users input and compares it against the OPTIONs in the SELECT field, 
	choosing the closest match as you type


	Cut and Paste this text into your HTML file or into a separate .js file for inclusion on your site.

	Usage:	<SELECT onKeyPress = "return shiftHighlight(event.keyCode, this);">	

	Platform: Only tested on IE5 (Win) - will not work on Netscape


*/

var timerid     = null;
var matchString = "";
var mseconds    = 1500;	// Length of time before search string is reset
// H. Stechl 06/05/2006
var utilitystring = ""; // maybe used as a temporary variable...
//

var DialogWindow = null;
var nOriginalWidth = 0;
var nOriginalHeight = 0;

function expandDropDownList(e)
{
	// H. Stechl 10/30/2007
	// IE 6, causes a postback as soon as the user clicks on the dropdown
	if (navigator.userAgent.indexOf("MSIE")>-1 && parseFloat(navigator.appVersion.split("MSIE")[1])>=7)
	{
		if (e != null && e.tagName == "SELECT")
		{
			var w = e.offsetWidth;
			var z = e.style.zIndex;
			e.setAttribute("_position", e.style.position);
			e.style.position = "absolute";
			e.style.width = "";
			if (e.offsetWidth <= w)
			{
				e.style.width = w + "px";
				e.style.position = e.attributes["_position"].value.toString();
				e.setAttribute("_position", "");
			}
			else
			{
				e.setAttribute("_width", w + "px");
				e.style.zIndex = 100000;
				e.setAttribute("_zindex", z);
			}
		}
    }
    return true;
}

function collapseDropDownList(e)
{
	// H. Stechl 10/30/2007
	// IE 6, causes a postback as soon as the user clicks on the dropdown
	if (navigator.userAgent.indexOf("MSIE")>-1 && parseFloat(navigator.appVersion.split("MSIE")[1])>=7)
	{
		if (e != null && e.tagName == "SELECT" && e.attributes["_width"] != null)
		{
			e.style.width = e.attributes["_width"].value.toString();
			e.style.zIndex = e.attributes["_zindex"].value.toString();
			e.style.position = e.attributes["_position"].value.toString();
			e.setAttribute("_width", "");
			e.setAttribute("_zindex", "");
			e.setAttribute("_position", "");
		}
    }
    return true;
}


function shiftHighlight(keyCode,targ)
{
    // navid 11/07/06: return if tab or enter key
    if (keyCode==9 || keyCode==13) { return true; }
    
    keyVal      = String.fromCharCode(keyCode); // Convert ASCII Code to a string
    matchString = matchString + keyVal; // Add to previously typed characters

    elementCnt  = targ.length - 1;	// Calculate length of array -1

    for (i = elementCnt; i > 0; i--)
    {
	    selectText = targ.options[i].text.toLowerCase(); // convert text in SELECT to lower case
	    if (selectText.substr(0,matchString.length) == 	matchString.toLowerCase())
	    {
		    targ.options[i].selected = true; // Make the relevant OPTION selected
	    }
    }
    clearTimeout(timerid); // Clear the timeout
    timerid = setTimeout('matchString = ""',mseconds); // Set a new timeout to reset the key press string
	
    return false; // to prevent IE from doing its own highlight switching
}

function FormFocusFirst(oForm, szName)
{
	if (oForm)
		{
		var oElement=null;
		
		if (szName!=null && szName!="")
		{
			oElement = oForm.elements[szName];
		}
		else
		{
			for (i = 0; i < oForm.elements.length; i++)
			{
				oElement = oForm.elements[i] ;
				if (!oElement.isDisabled) //ajs 12/9/02
				{
					if (oElement.type == 'text' || oElement.type == 'textarea' || oElement.type == 'select-one' || oElement.type == 'checkbox' || oElement.type == 'select-multiple' || oElement.type == 'radio')
					{
						break;
					}
				}
			}
		}
		if (oElement!=null && oElement.type != 'hidden' && !oElement.isDisabled && oElement.style.display != 'none') // ajs 12/9/02
		{
			oElement.focus();
		}
	}
}

function TabStrip_Next(oTS)
{
	if (oTS.selectedIndex < oTS.numTabs)
		oTS.selectedIndex++;
}

function TabStrip_Previous(oTS)
{
	if (oTS.selectedIndex > 0)
		oTS.selectedIndex--;
}


function expandCollapseDiv(divId, imageId, szExpand, szCollapse, szExpandAlt, szCollapseAlt)
{
	var div,img,oMultiChildAttributes
	
	if (document.all)
	{
		div = document.all[divId];
		img = document.all[imageId];
		oMultiChildAttributes = document.all["MultiChildAttributes"];
	}
	else if (document.getElementById)
	{
		div = document.getElementById(divId);
		img = document.getElementById(imageId); //BugFix by psherman (10-12-2006): replaced incorrect element ID
		oMultiChildAttributes = document.getElementById("MultiChildAttributes");
	}
		
	if (div != null && img != null)
	{
		if (div.style.display == "none") 
		{
			div.style.display = "inline";
			img.src = szCollapse;
			if (szCollapseAlt!=null)
			{img.alt = szCollapseAlt;}
		}
		else
		{
			div.style.display = "none";		
			img.src = szExpand;	
			if (szExpandAlt!=null)
			{img.alt = szExpandAlt;}
		}
		if (oMultiChildAttributes != null)
		{
			szAttribute = "["+divId+"]";
			szAttributes = oMultiChildAttributes.value;
			if (div.style.display == "inline")
			{
				if (szAttributes.indexOf(szAttribute) < 0)
					szAttributes += szAttribute;
			}
			else
			{
				if (szAttributes.indexOf(szAttribute) >= 0)
					szAttributes = szAttributes.replace(szAttribute,"");
			}
			oMultiChildAttributes.value = szAttributes;
		}
	}
}
function KeyPressMasked(szMaskType)
{
// Supported Mask Types:
//	Currency
//	Date
//	Phone
//	Integer
//	Float
//	Alpha

	// H. Stechl 11/16/2007
	// quick fix, make sure window.event exists
	if (typeof( window.event ) != "undefined")
	{
		if (szMaskType != "")
		{
			szChar = String.fromCharCode(window.event.keyCode)
			szMaskType = szMaskType.toLowerCase();
			if (szMaskType == "currency")
			{
				if ((szChar < "0" || szChar > "9") && "$,.-".indexOf(szChar) < 0)
					window.event.keyCode = 0;
			}
			else if (szMaskType == "date")
			{
				if ((szChar < "0" || szChar > "9") && szChar != "/")
					window.event.keyCode = 0;
			}
			else if (szMaskType == "phone")
			{
				if ((szChar < "0" || szChar > "9") && "()-/".indexOf(szChar) < 0)
					window.event.keyCode = 0;
			}
			else if (szMaskType == "integer")
			{
				if ((szChar < "0" || szChar > "9") && szChar != "-")
					window.event.keyCode = 0;
			}
			else if (szMaskType == "float")
			{
				if ((szChar < "0" || szChar > "9") && ".-".indexOf(szChar) < 0)
					window.event.keyCode = 0;
			}
			else if (szMaskType == "alpha")
			{
				if ((szChar < "a" || szChar > "z") && (szChar < "A" || szChar > "Z"))
					window.event.keyCode = 0;
			}
		}
	}
}

function ListGridRowClicked()
{
	szHref = event.srcRow.children[0].children[0].href;
	szHref = szHref.substr(szHref.indexOf("'")+1);
	szHref = szHref.substr(0,szHref.indexOf("'"));
	__doPostBack(szHref,'');
}

function ConfirmDelete()
{
	if (!confirm("Are you sure you want to delete?"))
	{
		// H. Stechl 11/16/2007
		// quick fix, make sure window.event exists
		if (typeof( event ) != "undefined")
		{
			if (event)
				{event.returnValue = false;}
		}
		return false;
	}
	return true;
}

function Confirm(msg)
{
	if (!confirm(msg))
	{
		// H. Stechl 11/16/2007
		// quick fix, make sure window.event exists
		if (typeof( window.event ) != "undefined")
		{
			if (event)
				{event.returnValue = false;}
		}
		return false;
	}
	return true;
}

function DeleteChildRow(szFormKey,szRowKey)
{
	if (ConfirmDelete())
	{
		if (document.forms[0].MultiChildAttributes != null)
		{
			document.forms[0].MultiChildAttributes.value += "DCKey["+szFormKey+"]DCRKey["+szRowKey+"]";
			document.forms[0].submit();
		}
		/*
		szURL = window.document.URL;
		if (szURL.indexOf("&DCKey=") > 0)
			szURL = szURL.substr(0,szURL.indexOf("&DCKey="));
		szURL += "&DCKey="+szFormKey+"&DCRKey="+szRowKey;
		window.document.URL = szURL;
		*/
	}
}

function ParentWindowRefresh(szURL)
{
	if (opener)
	{
	    // navid 11/07/06 - for some reason, this is still not working, maybe we need to make it work for future...
//	    if (opener.WebForm_PostBackOptions && opener.WebForm_DoPostBackWithOptions)
//	    {
//	        //function WebForm_PostBackOptions(eventTarget,eventArgument,validation,validationGroup,actionUrl,trackFocus,clientSubmit)
//	        var options = new opener.WebForm_PostBackOptions("XXXXXXXX","",null,null,null,false,true);
//	        opener.WebForm_DoPostBackWithOptions(options);
//	    }
        // navid 11/07/06 - this is working for now...
        if (navigator.userAgent.toLowerCase().indexOf("msie")<0)
        {
            if (opener.document.forms[0])
            {
                if (opener.document.getElementById("__EVENTTARGET") != null)
                    opener.document.getElementById("__EVENTTARGET").value = "XXXXXXXX";
                if (opener.document.getElementById("__EVENTARGUMENT") != null)
                    opener.document.getElementById("__EVENTARGUMENT").value = "";
	            opener.document.forms[0].submit();
	        }
	        else if (szURL != "")
			    opener.location.assign(szURL);
		    else
			    opener.location.reload(false);
	    }
	    else
	    {
		    if (window.opener.__doPostBack)
			    window.opener.__doPostBack("XXXXXXXX","");
		    else if (opener.document.forms[0])
			    opener.document.forms[0].submit();
		    else if (szURL != "")
			    opener.location.assign(szURL);
		    else
			    opener.location.reload(false);
		}
	}
}

function ImageSrcChange(szImageSrc,evt)
{

    var element =  null;
    
    if (evt != null)
         element = evt.target;
     else
         element = window.event.srcElement;
    

	var oImage = null;
	if (element.childNodes[0] != null && element[0].tagName == "IMG")
		oImage = element[0];
	else if (element.parentNode != null && element.parentNode.childNodes[0] != null && element.parentNode.childNodes[0].tagName == "IMG")
		oImage = element.parentNode.childNodes[0];
	if (oImage != null)
	{
		oImage.src = szImageSrc;	
	}
}

function TextLimit(field, maxlen)
{
	if (field.value.length > maxlen) 
	{
		field.value = field.value.substring(0, maxlen);
		alert('your input has been truncated!');
	}
}

function checkField (objField, cInputMask) 
{
	InputMaskDelimiters = "/"
	bDelimiter = false;
	if( objField.value != "")
	{
		for (var i=0; i<objField.value.length; i++)
		{
			cChar = objField.value.charAt(i)
			if (InputMaskDelimiters.indexOf(cChar)>-1)
			{
				bDelimiter = true;
				break;
			}
		}

		if ( !bDelimiter )
		{
			objField.value = reformatInputMask(objField.value, cInputMask, InputMaskDelimiters)
		}
	}
	return true;
}

function reformat (s)
{   
	var arg;
    var sPos = 0;
    var resultString = "";
	var nStringLength = s.length
    for (var i = 1; i < reformat.arguments.length ; i++) {
		if (sPos <= nStringLength)
		{
			arg = reformat.arguments[i];
			if (i % 2 == 1) resultString += arg;
			else
			{
				resultString += s.substring(sPos, sPos + arg);
				sPos += arg;
			}
		}
    }

    return resultString;
}

function stripCharsInBag (s, bag)
{   var i;
    var returnString = "";

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}




function reformatInputMask (cValue,cInputMask, InputMaskDelimiters)
{   
	creformatFunction = "reformat (cValue, "
	nChar = 0
	for (i=0;i<cInputMask.length;i++)
	{
		if (InputMaskDelimiters.indexOf(cInputMask.charAt(i))==-1)
		{
			nChar=nChar+1
			if (i==0) //first character
				{creformatFunction = creformatFunction + "'', "}
			else
				{
				if (nConcatMask)
					{creformatFunction = creformatFunction + "', "}
				}				
			nConcatMask = false
		}	
		else
		{
			if (i==0)
				{creformatFunction = creformatFunction + "'"+cInputMask.charAt(i)}
			else
			{
				if (nChar==0)
				{
					if (nConcatMask)
						{creformatFunction = creformatFunction + cInputMask.charAt(i)}
					else
						{creformatFunction = creformatFunction + "'"+cInputMask.charAt(i)}
				}
				else
				{
					if (nConcatMask)
						{creformatFunction = creformatFunction + cInputMask.charAt(i)}
					else
						{creformatFunction = creformatFunction + " "+nChar+", '"+cInputMask.charAt(i)}
				}
			}
			nConcatMask = true
			nChar = 0
		}
	}
	if (nChar > 0)
	{
		creformatFunction = creformatFunction + " "+nChar+", "
	}
	//remove last two characters ", " and add close parenthesis at the end.
	creformatFunction = creformatFunction.substring(0,creformatFunction.length-2)
	creformatFunction = creformatFunction + ")"
	//alert(creformatFunction)
return ( eval(creformatFunction) )
}



function CheckCreditDebit()
{
	oSrcElement = event.srcElement;
	iIndex = oSrcElement.name.indexOf('JDG');
	iIndex = oSrcElement.name.indexOf('_', iIndex+1); 
	iIndex = oSrcElement.name.indexOf('_', iIndex+1); 
	oRowID = oSrcElement.name.substr(iIndex+1,1); 
	if ( oSrcElement.name.indexOf('JournalDataGrid') >= 0 &&
		oSrcElement.type == 'text' &&
		(oSrcElement.name.indexOf('Debit') >= 0 || oSrcElement.name.indexOf('Credit') >= 0) &&
		oSrcElement.value > 0 )
	{
		if (oSrcElement.name.indexOf('Debit') >= 0) Opposite = 'Credit';
		if (oSrcElement.name.indexOf('Credit') >= 0) Opposite = 'Debit';
		for (i = 0; i < document.forms[0].elements.length; i++)
		{
			oElement = document.forms[0].elements[i];
			if (oElement.type == 'text' &&
				oElement.name.indexOf('JournalDataGrid') >= 0 && 
				oElement.name.indexOf('JDG_'+Opposite+'_' + oRowID) >= 0 )
			{    
				document.forms[0].elements[i].disabled = true;
				if (Opposite == 'Credit')
					document.forms[0].elements[i+1].focus();
				if (Opposite == 'Debit')
					document.forms[0].elements[i+2].focus();
				break;
			}
		}
	}
}

function SetCookie(szName, szValue)
{
	document.cookie = szName + "=" + escape(szValue) + "; expires=Fri, 31 Dec 2099 23:59:59 GMT;";
	if (0==1){}
	var szDummy = GetCookie(szName);
	if (0==1){}
}

function GetCookie(szName)
{
	// cookies are separated by semicolons
	var szReturnValue = null;
	var aCookies = document.cookie.split("; ");
	for (var i=0; i < aCookies.length; i++)
	{
		// a name/value pair (a crumb) is separated by an equal sign
		var aCookie = aCookies[i].split("=");
		if (szName == aCookie[0]) 
			szReturnValue = unescape(aCookie[1]);
	}
	return szReturnValue;
}

function DelCookie(szName)
{
	date = new Date();
	document.cookie = szName + "=" + "; expires=" + date.toGMTString();
}

function OpenNewWindow_WithClose(szURL)
{
	close();
	openDialog(szURL,50,50);
}

function OpenNewWindow(szURL)
{
	//window.onfocus = "reload();";
	//openDialog(szURL,screen.width/2,screen.height/2);
	//debugger
	openDialog(szURL,50,50);
}

function OpenNewWindowAlert(szURL, szAlert)
{
	if (szAlert != "")
		AlertDialog(szAlert);
	openDialog(szURL,50,50);
}

function CloseWindow()
{
	close();
}

function openDialog(url, width, height)
{
	DialogWindow = null;
	DialogWindow = new Object();
	if (!DialogWindow.win || (DialogWindow.win && DialogWindow.win.closed))
	{
		//DialogWindow.returnFunc = returnFunc;
		//DialogWindow.returnedValue = "";
		//DialogWindow.args = args;
		DialogWindow.url = url;
		DialogWindow.width = width;
		DialogWindow.height = height;
		// H. Stechl 08/14/2006
		// ensure unique window name
		// DialogWindow.name = (new Date()).getSeconds().toString();
		dDate = new Date();
		DialogWindow.name = dDate.getMinutes().toString() + dDate.getSeconds();
		//
		DialogWindow.left = 5000; //(screen.width - width) / 2;
		DialogWindow.top = 5000; // (screen.height - height) / 2;
		var attr = "left=" + DialogWindow.left + ",top=" + 
			DialogWindow.top + ",resizable=yes,status=yes,scrollbars=yes,width=" 
			+ DialogWindow.width + ",height=" + DialogWindow.height;
		DialogWindow.win = window.open(DialogWindow.url, DialogWindow.name, attr);
		var nLeftOffset = DialogWindow.left-DialogWindow.win.screenLeft;
		var nTopOffset = DialogWindow.top-DialogWindow.win.screenTop;
		SetCookie("WindowTopLeftOffset",nTopOffset+","+nLeftOffset);
		setTimeout("CheckWindowCoorinatesTimer()",3000);
	}
	DialogWindow.win.focus()
}

function openDialogAbsolute(url, width, height)
{
	DialogWindow = null;
	DialogWindow = new Object();
	if (!DialogWindow.win || (DialogWindow.win && DialogWindow.win.closed))
	{
		DialogWindow.url = url;
		DialogWindow.width = width;
		DialogWindow.height = height;
		DialogWindow.name = (new Date()).getSeconds().toString();
		DialogWindow.left = (screen.width - width) / 2;
		DialogWindow.top = (screen.height - height) / 2;
		var attr = "left=" + DialogWindow.left + ",top=" + 
			DialogWindow.top + ",resizable=yes,status=yes,scrollbars=yes,width=" 
			+ DialogWindow.width + ",height=" + DialogWindow.height;
		DialogWindow.win = window.open(DialogWindow.url, DialogWindow.name, attr);
	}
	DialogWindow.win.focus()
	setTimeout("CheckWindowCoorinatesTimer()",3000);
}

function CheckWindowCoorinatesTimer()
{
	//debugger
	try
	{
		if (DialogWindow && DialogWindow.win && DialogWindow.win.screenTop)
		{
			//nTop = Math.abs(DialogWindow.win.screenTop);
			//nLeft = Math.abs(DialogWindow.win.screenLeft);
			nTop = DialogWindow.win.screenTop;
			nLeft = DialogWindow.win.screenLeft;
			if (nTop > screen.height || nLeft > screen.width)
			{
				if (nTop > screen.height)
					nTop = 100;
				if (nLeft > screen.width)
					nLeft = 100;
				DialogWindow.win.moveTo(nLeft,nTop);
			}
		}
	}
	catch (e)
	{
		// window must have been closed by user before timer interval, do nothing
	}
}

function WindowBlockEvents()
{
	window.onfocus = WindowCheckModal
}

function WindowCheckModal()
{	
	if (DialogWindow != null)
	{
		if (DialogWindow.win!=null)
		{ 
			if (typeof DialogWindow.win.closed != 'unknown')
			{
				if (!DialogWindow.win.closed)
					{ DialogWindow.win.focus(); }
			}
		}
	}
}

function DialogBlockParent()
{
	if (opener) 
	{
		try
		{		
			opener.WindowBlockEvents();
		}
		catch (e)
		{
		}

	}
}

function SetWindowSize(bRemember)
{

	//debugger
	
	if (! bRemember || ! ResizeByCookie())
	{
		/*
		var nOffsetWidth = screen.width / 2;
		var nOffsetHeight = screen.height / 2;
		var oDesignedDiv = document.all["DesignedDiv"];
		if (document.forms[0] != null && document.forms[0].id == "WizardForm")
		{
			nOffsetWidth = screen.width-200;
			nOffsetHeight = screen.height-200;
		}
		else if (oDesignedDiv != null)
		{
			nOffsetWidth = oDesignedDiv.offsetWidth+50;
			nOffsetHeight = oDesignedDiv.offsetHeight+150;
		}
		else
		{
			var oDataFormTable = document.all["DataFormTable"];
			if (oDataFormTable != null)
			{
				nOffsetWidth = oDataFormTable.offsetWidth;
				nOffsetHeight = oDataFormTable.offsetHeight+75; // 75 to account for buttons..
			}
		}
		if (nOffsetWidth > screen.width)
			nOffsetWidth = screen.width;
		if (nOffsetHeight > screen.height)
			nOffsetHeight = screen.height;
		window.resizeTo(nOffsetWidth,nOffsetHeight);
		window.moveTo(((screen.width-nOffsetWidth) / 2),((screen.height-nOffsetHeight) / 2));
		window.scrollTo(0,0);
		*/
		//debugger
		w = (document.layers)?document.width:document.body.scrollWidth;
		h = (document.layers)?document.height:document.body.scrollHeight;
		w += 40;
		h += 60;
		if (w > screen.width-50)
		w = screen.width-50;
		if (h > screen.height-50)
		h = screen.height-50;
		window.resizeTo(w,h);
		window.moveTo(((screen.availWidth-w) / 2),((screen.availHeight-h) / 2));
		window.scrollTo(0,0);
	}
}

function ResizeByCookie()
{
	var bResized = false;
	var szCookie = GetCookieName(document.location.search);
	
	if (szCookie == "")
		szCookie = GetFileName(document.location.pathname);
	
	if (szCookie != "")
	{
		var szCoordinates = GetCookie(szCookie);
		if (szCoordinates != null)
		{
		
			var nTopOffset = 0;
			var nLeftOffset = 0;
			var szOffsetCookie = GetCookie("WindowTopLeftOffset");
			if (szOffsetCookie != null)
			{
				var aOffsets = szOffsetCookie.split(",");
				nTopOffset = parseInt(aOffsets[0]);
				nLeftOffset = parseInt(aOffsets[1]);
				
				// TJW, 11/14/2005, fix from OD team to make sure windows don't resize too small
                if(nTopOffset>0) nTopOffset=-30;
                if(nLeftOffset>0) nLeftOffset=-4;
                // TJW, 11/14/2005, END
			}
			
			var aCoordinates = szCoordinates.split(",");
			var nTop = parseInt(aCoordinates[0])+nTopOffset;
			var nLeft = parseInt(aCoordinates[1])+nLeftOffset;
			
			// TJW, 11/14/2005, fix from OD team to make sure windows don't resize too small
            if(nTop<0 || nTop>window.screen.availHeight) nTop=100;
            if(nLeft<0 || nLeft>window.screen.availWidth) nLeft=100;
            // TJW, 11/14/2005, END 
			
			// H. Stechl 07/31/2006
			// bug # 5862 hold on to previous size
			nOriginalHeight = parseInt(aCoordinates[2]);
			nOriginalWidth = parseInt(aCoordinates[3]);
			
			var nHeight = nOriginalHeight-(nTopOffset*2);
			var nWidth = nOriginalWidth-(nLeftOffset*2);


			window.resizeTo(nWidth,nHeight);
			window.moveTo(nLeft,nTop);
			window.scrollTo(0,0);
			bResized = true;
		}
	}
	return bResized;
}

function GetCookieName(szQueryString)
{
	var szCookie = "";
	if (szQueryString.indexOf("WizardKey=") >= 0)
		szCookie = szQueryString.substr(szQueryString.indexOf("WizardKey=")+10);
	else if (szQueryString.indexOf("FormKey") >= 0)
		szCookie = szQueryString.substr(szQueryString.indexOf("FormKey=")+8);
	if (szCookie != "")
	{
		if (szCookie.indexOf("&") >= 0)
			szCookie = szCookie.substring(0,szCookie.indexOf("&"));
	}
	return szCookie;
}

function GetFileName(szQueryString)
{
	var szCookie = "";
	if (szQueryString.indexOf(".") >= 0)
		szCookie = szQueryString.substr(0,szQueryString.indexOf("."));
	while (szCookie.indexOf("/") >= 0)
		szCookie = szCookie.substr(szCookie.indexOf("/")+1);
	if (szCookie != "")
		szCookie = "FORM_"+szCookie;
	return szCookie;
}

function BeforeUnloadWindow()
{
	//debugger
	var szCookie = GetCookieName(document.location.search);
	if (szCookie == "")
		szCookie = GetFileName(document.location.pathname);
	if (szCookie != "")
	{
		// H. Stechl 07/31/2006
		// bug # 5862 use original height if increased by less than 10 pixels
		// prevents ever-increasing browser height.
		var nWidth = document.body.offsetWidth;
		var nHeight = document.body.offsetHeight;
		if ( (nHeight > nOriginalHeight) && (nHeight - nOriginalHeight) < 11)
			nHeight = nOriginalHeight;
		var szCookieValue = window.screenTop+","+window.screenLeft+","+nHeight+","+nWidth;
		SetCookie(szCookie,szCookieValue);
	}
}

function Report_Preview(szReportKey)
{
	openDialogAbsolute("ReportPreview.aspx?ReportKey="+szReportKey,800,600);
}

/*
function Report_Run(szReportKey)
{
	openDialogAbsolute("ReportStart.aspx?ReportKey="+szReportKey,200,200);
}
*/

function Report_Run(szReportKey)
{
	Report_Run(szReportKey,null);
}

function Report_Run(szReportKey, szParam)
{
  Report_Run(szReportKey,szParam,null);
}

function Report_Run(szReportKey, szParam, szAParams)
{
  Report_Run(szReportKey,szParam,szAParams,null);
}

function Report_Run(szReportKey,szParam,szAdditionalParams,szDelivery)
{
   //debugger;
       
   //SB, 11/03/2005, MRS
   var szOutputFormat = "";
   var oDropDown = document.getElementById("DDL"+szReportKey);
    
   if (oDropDown != null)
   {
		szOutputFormat = oDropDown.options[oDropDown.selectedIndex].value;
		
		if (szDelivery==null)
		    szDelivery = "0";
		    
		if (szAdditionalParams==null)
		{
			//openDialogAbsolute("ReportStart.aspx?ReportKey="+szReportKey,200,200);
			
			//SB, 04/05/2006, Fixes Bug# 5294			
			if (szParam == "True")
			{
				openDialogAbsolute("ReportStart.aspx?ReportKey="+szReportKey+"&OutputFormat="+szOutputFormat+"&bReportCentral=true&ReportSubscription="+szDelivery, 200, 200);
			}
			else if (szParam == "False")
			{
			    openDialogAbsolute("ReportStart.aspx?ReportKey="+szReportKey+"&OutputFormat="+szOutputFormat+"&bReportCentral=true&ReportSubscription="+szDelivery, 800, 600);		
			}
			else
			{
			    openDialogAbsolute("ReportStart.aspx?ReportKey="+szReportKey+"&OutputFormat="+szOutputFormat+"&bReportCentral=true&ReportSubscription="+szDelivery, 200, 200);
			}
			//SB, 04/05/2006			    
		}
		else
		{
			//openDialogAbsolute("ReportStart.aspx?ReportKey="+szReportKey+szAdditonalParams,200,200);
			openDialogAbsolute("ReportStart.aspx?ReportKey="+szReportKey+szAdditionalParams+"&OutputFormat="+szOutputFormat+"&bReportCentral=true&ReportSubscription="+szDelivery, 200, 200);			
		}
   }   
   //SB, 11/03/2005, end
}

function ConfirmDialog(szMessage, szButtonID)
{
	if (window.confirm(szMessage))
	{
		if (document.forms[0].action)
			document.forms[0].action += "&Confirm=ByPass";

		if (szButtonID==null || szButtonID=='')
			szButtonID='ButtonSave';

		oButton = eval("document.getElementById('"+szButtonID+"')");
		
		if (!oButton)
			oButton = eval('document.forms[0].'+szButtonID);
		
		if (oButton)
			oButton.click();
	}
}

function ClearConfirmByPass()
{
	if (document.forms[0].action && document.forms[0].action.indexOf("&Confirm=ByPass") > 0)
		document.forms[0].action = document.forms[0].action.replace("&Confirm=ByPass","");
}

function AlertDialog(szMessage)
{
	window.alert(szMessage);
}

// H. Stechl - add options to dropdown from opener
function DropDownAddOption(oDropDown, szValue, szText)
{
	oDropDown.options[oDropDown.length] = new Option((szText==null)?szValue:szText, szValue);
}

//s sterian - in order to remove header added by internet explorer to innerHTML in iframe
//				(for RichTextBox control)
 
var differenceUrl2P ='',differenceUrl1P ='',differenceUrl='',differenceUrl4P='',differenceUrlAnchor='';


function ReplaceUrlHeaders(textHtml,checkbPres)
{
	var innText=new String();
	
	innText = textHtml;
	
	if (checkbPres != null && checkbPres.checked == true)
	{//replace only anchors
	    if (differenceUrlAnchor != '')
	    	while (innText.indexOf(differenceUrlAnchor+'#',0)!=-1)	    		
		        innText = innText.replace(differenceUrlAnchor+'#','#');	   
		     
		return innText;
    }

	if (differenceUrlAnchor != '')					 									
		while (innText.indexOf(differenceUrlAnchor,0)!=-1)
			innText = innText.replace(differenceUrlAnchor,'');	
	if (differenceUrl1P != '')
		while (innText.indexOf(differenceUrl1P,0)!=-1)
			innText = innText.replace(differenceUrl1P,'');
	if (differenceUrl2P != '')
		while (innText.indexOf(differenceUrl2P,0)!=-1)
			innText = innText.replace(differenceUrl2P,'..');
	if (differenceUrl4P != '')
		while (innText.indexOf(differenceUrl4P,0)!=-1)
			innText = innText.replace(differenceUrl4P,'../..');
	if (differenceUrl != '')										 									
		while (innText.indexOf(differenceUrl,0)!=-1)
			innText = innText.replace(differenceUrl,'');	

	return innText;	
}

function OnLoadGrabUrlDiff(iframeObj)
{
	var c=0;var testHtml=new String();	
	
	iframeObj.document.body.innerHTML ="<A href='/TxTTT.aspx'>Link</A>xxx0"+
	"<A href='UxUUU.aspx'>Link</A>yyy0<A href='../VxVVV.aspx'>Link</A>"+
	"zzz0<a href='../../WxWWW.aspx'>Link</a>www0<a href='#QxQQQ'>Link</a>";
	
	testHtml=iframeObj.document.body.innerHTML;
	
	c = testHtml.indexOf('/TxTTT.aspx');
	if (c>0)
		differenceUrl=testHtml.substr(9,c-9);		
	b  = testHtml.indexOf('xxx0');
	testHtml = testHtml.substr(b+4);	
		
	c = testHtml.indexOf('UxUUU.aspx');
	if (c>0)
		differenceUrl1P=testHtml.substr(9,c-9); 		
	b  = testHtml.indexOf('yyy0');
	testHtml = testHtml.substr(b+4);			
	c = testHtml.indexOf('/VxVVV.aspx');		
	if (c>0)
		differenceUrl2P=testHtml.substr(9,c-9); 		
	
	b  = testHtml.indexOf('zzz0');
	testHtml = testHtml.substr(b+4);		
	c = testHtml.indexOf('/WxWWW.aspx');
	if (c>0)
	 differenceUrl4P=testHtml.substr(9,c-9);	
	 
	b  = testHtml.indexOf('www0');	
	testHtml = testHtml.substr(b+4);		
	c = testHtml.indexOf('#QxQQQ');		
	if (c>0)
	 differenceUrlAnchor=testHtml.substr(9,c-9);	 
}


function goback()
{
	history.go(-1);
}

var new_win;

function open_window(url,win_name,w,h,scroll)
{
	settings = "";
	settings += 'toolbar=0, directories=0, menubar=0,';
	if(scroll!=null)
	{
		settings+=' scrollbars=yes, resizable=1,';
	}
	else
	{
		settings+=' scrollbars=0, resizable=0,';
	}
	settings += 'status=0, width='+w+', height='+h;
	close_window();
	var new_win = window.open(url, win_name, settings);
	new_win.focus();
}

function close_window()
{
	if(new_win  && !new_win.closed)
	{
		new_win.close();
	}
}

function arg_length(f,len,number)
{
	if(len!=number) {document.write("function "+f+"called with "+len+" arguments, but expected "+number+"!");return 0;} else {return 1;}
}

function not_empty(par)
{
	if ((par!=null)&&(par!="")) return 1;
	if ((par==null)||(par=="")) return 0;
}

function space(par1,par2)
{
	if(not_empty(par1)&&not_empty(par2)) return 1;
	if(!not_empty(par1)||!not_empty(par2)) return 0;
}

function StartProcess(id,s)
{
	var features;
	features = "toolbar=no,directories=no,menubar=no,scrollbars=no,resizable=no,height=100,width=200";
	window.open('ProgressBar.aspx?id=' + id +'&s=' + s, 'Progress', features);
}

function formatInput(element,format)
{
	if(element!=null && element.tagName=="INPUT" && element.type=="text" && format!=null)
	{
		var s=element.value;
		var f=format.toLowerCase();
		switch(f)
		{
			case "integer":
			{
				var n=s.length;
				s=s.replace(/[^0-9]/g,"");
				if(element.value!=s) element.value=s;
				if(s.length<n)
				{
					if(!confirm("The entered number contains invalid characters and they have been removed.\nPlease review the number and click OK to continue or Cancel to modify."))
					{
						try{element.focus();} catch(x){}
						return false;
					}
				}
				break;
			}
			case "float":
			{
				var n=s.length;
				s=s.replace(/[^0-9\.\,]/g,"");
				var m=s.length;
				s=s.replace(/[^0-9\.]/g,"");
				if(s!="")
				{
					if(s.indexOf(".")<0) s+=".00";
					var a=s.split(".");
					s=a[0]+".";
					for(var i=1; i<a.length; i++) s+=a[i];
					a=s.split("");
					if(a[0] && a[0]==".") a[0]="0.";
					else if(a[a.length-1] && a[a.length-1]==".") a[a.length-1]=".00";
					s=a.join("");
				}
				if(element.value!=s) element.value=s;
				if(m<n)
				{
					if(!confirm("The entered number contains invalid characters and they have been removed.\nPlease review the number and click OK to continue or Cancel to modify."))
					{
						try{element.focus();} catch(x){}
						return false;
					}
				}
				break;
			}
			case "currency":
			{
				var n=s.length;
				s=s.replace(/[^0-9\.\$\,]/g,"");
				var m=s.length;
				s=s.replace(/[^0-9\.]/g,"");
				if(s!="")
				{
					var a=s.split(".");
					s=a[0]+".";
					for(var i=1; i<a.length; i++) s+=a[i];
					s=""+(Math.round(parseFloat(s)*100)/100);
					a=s.split("");
					if(a[0] && a[0]==".") a[0]="0.";
					else if(a[a.length-1] && a[a.length-1]==".") a[a.length-1]=".00";
					s=a.join("");
					a=s.split(".");
					if(a[1])
					{
						if(a[1].length==0) a[1]="00";
						else if(a[1].length==1) a[1]+="0";
					}
					else a[1]="00";
					s=a.join(".");
					s="$"+s;
				}
				if(element.value!=s) element.value=s;
				if(m<n)
				{
					if(!confirm("The entered currency value contains invalid characters and they have been removed.\nPlease review the value and click OK to continue or Cancel to modify."))
					{
						try{element.focus();} catch(x){}
						return false;
					}
				}
				break;
			}
			case "time":
			{
				s=s.toLowerCase().replace(/[^0-9\:\a\p\m]/g,"");
				var t="";
				if(s.indexOf("am")>0) t="am";
				else if(s.indexOf("pm")>0) t="pm";
				s=s.replace(/[^0-9\:]/g,"");
				var a=s.split(":");
				if(a.length!=2)
				{
					if(s!="")
					{
						alert("The entered time is invalid and will be removed!\nPlease re-enter a valid time.");
						element.value="";
						try{element.focus();} catch(x){}
						return false;
					}
				}
				else
				{
					for(var i=0; i<a.length; i++)
					{
						if(a[i].length<2)
						{
							a[i]="00"+a[i];
							a[i]=a[i].substring(a[i].length-2);
						}
						else if(a[i].length>2) a[i]=a[i].substring(0,2);
					}
					if(t!="")
					{
						if(parseInt(a[0])>12) a[0]="12";
					}
					else if(t=="")
					{
						if(parseInt(a[0])>23) a[0]="00";
					}
					if(parseInt(a[1])>59) a[1]="00";
					s=a.join(":");
					if(t!="") s+=" "+t;
					if(element.value!=s) element.value=s;
				}
				break;
			}
			case "date":
			{
				s=s.replace(/[^0-9\/]/g,"");
				if(s.length>10) s=s.substring(0,10);
				var a=s.split("/");
				if(a.length!=3)
				{
					if(s!="")
					{
						alert("The entered date is invalid and will be removed!\nPlease re-enter a valid date.");
						element.value="";
						try{element.focus();} catch(x){}
						return false;
					}
				}
				else
				{
					for(var i=0; i<a.length; i++)
					{
						if(a[i].length<2)
						{
							a[i]="00"+a[i];
							a[i]=a[i].substring(a[i].length-2);
						}
						else if(i<2 && a[i].length>2) a[i]=a[i].substring(0,2);
						else if(i==2 && a[i].length>4) a[i]=a[i].substring(0,4);
					}
					if(parseInt(a[0])>12) a[0]="12";
					if(parseInt(a[1])>31) a[1]="31";
					s=a.join("/");
					if(element.value!=s) element.value=s;
				}
				break;
			}
			case "phone":
			{
				s=s.replace(/[^0-9]/g,"");
				var n=s.length;
				if(s.length==10 || (s.length==11 && s.substring(0,1)=="1"))
				{
					var b=false;
					if(s.substring(0,1)=="1")
					{
						b=true;
						s=s.substring(1);
					}
					var a=s.split("");
					var n=a.length;
					for(var i=0; i<n; i++)
					{
						switch(i)
						{
							case 0: a[i]="("+a[i]; break;
							case 2: if(a[i+1]!=null) a[i]+=") "; break;
							case 5: if(a[i+1]!=null) a[i]+="-"; break;
						}
					}
					s=a.join("");
					if(b) s="1 "+s;
				}
				if(s.length==7) s=s.substring(0,3)+"-"+s.substring(3);
				if(n!=0 && (n<7 || (n>11 && s.substring(0,1)=="1") || (n>10 && s.substring(0,1)!="1")))
				{
					if(!confirm("The entered phone number does not seem valid.\nPlease review the number and click OK to continue or Cancel to modify."))
					{
						try{element.focus();} catch(x){}
						return false;
					}
				}
				else if(element.value!=s) element.value=s;
				break;
			}
			case "alphanumeric":
			{
				var n=s.length;
				s=s.replace(/[^\w]/g,"");
				if(element.value!=s) element.value=s;
				if(n>s.length) alert("Invalid or special characters have been removed from your entry.\nOnly alpha-numeric characters and underscores \"_\" (no spaces) are allowed.");
				break;
			}
			case "initialuppercase":
			{
				var a=s.split("");
				var n=a.length;
				for(var i=0; i<n; i++)
				{
					if(i==0) a[i]=a[i].toUpperCase();
					else if(a[i]==" " && a[i+1]!=null) a[i+1]=a[i+1].toUpperCase();
				}
				s=a.join("");
				if(element.value!=s) element.value=s;
				break;
			}
			case "fulluppercase":
			{
				s=s.toUpperCase();
				if(element.value!=s) element.value=s;
				break;
			}
			case "fulllowercase":
			{
				s=s.toLowerCase();
				if(element.value!=s) element.value=s;
				break;
			}
		}
	}
}

function fadeOpacity(id, opacStart, opacEnd, millisec) 
{ 
    if (millisec==null)
		millisec=200;
    var speed = Math.round(millisec / 100); 
    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, bDisappear) 
{ 
    var object = document.getElementById(id).style; 

	if (object != null)
	{
		if (opacity!=0 && object.display != 'block')
			object.display = 'block';

		object.filter = "alpha(opacity=" + opacity + ")"; 
		
		if (opacity==0 && object.display != 'none')
			object.display = 'none';

    }
} 

function fadeHeight(id, heightStart, heightEnd, millisec) 
{
    if (millisec==null)
		millisec=250;
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    if(heightStart > heightEnd) { 
        for(i = heightStart; i >= heightEnd; i--) { 
            setTimeout("changeHeight(" + i + ",'" + id + "')",(timer * speed)); 
            timer++;
        } 
    } else if(heightStart < heightEnd) { 
        for(i = heightStart; i <= heightEnd; i++) 
            { 
            setTimeout("changeHeight(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

function changeHeight(height, id) 
{ 
    var object = document.getElementById(id).style;
    if (object != null)
    {
		if (height!=0 && object.display != 'block')
			object.display = 'block';

		object.height = (height); 

		if (height==0 && object.display != 'none')
			object.display = 'none';
	}
} 



function fadeWidth(id, widthStart, widthEnd, millisec) 
{ 
    if (millisec==null)
		millisec=250;
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    if(widthStart > widthEnd) { 
        for(i = widthStart; i >= widthEnd; i--) { 
            setTimeout("changeWidth(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(widthStart < widthEnd) { 
        for(i = widthStart; i <= widthEnd; i++) 
            { 
            setTimeout("changeWidth(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

function changeWidth(width, id) { 
    var object = document.getElementById(id).style; 
    if (object != null)
    {
		if (width!=0 && object.display != 'block')
			object.display = 'block';

	    object.width = (width); 

		if (width==0 && object.display != 'none')
			object.display = 'none';

	}
} 

// H. Stechl 07/27/2006
// control which button/image is activated.
function CheckForEnter(szButtonOrImage)
{
	// H. Stechl - 10/17/2007
	// can add browser support as necessary...
	if (navigator.userAgent.indexOf("MSIE")!=-1)
	{
		if (event)
		{
			if (event.keyCode==13)
			{
				oButtonOrImage = document.getElementById(szButtonOrImage);
				if (oButtonOrImage != null)
				{
					event.keyCode = 0;
					event.returnValue = false;
					event.cancelBubble = true;
					oButtonOrImage.click();
				}
			}
		}
	}
	return true;
}

function RTBCleanupMSWord(szIframeId)
{
    if (szIframeId != null && szIframeId != "")
    {
        var oIframe = document.getElementById(szIframeId);
        if (oIframe != null)
        {
            var oDocument = oIframe.contentWindow.document;
            var aElements = oDocument.getElementsByTagName("*");
            for (var i = 0; i < aElements.length; i++)
            {
                var e = aElements[i];
                if (e.className.toLowerCase().indexOf("mso")>=0)
                    e.removeAttribute("className","",0);
                if (e.style.cssText.toLowerCase().indexOf("mso")>=0)
                {
                    var szCssText = "";
                    var aStyles = e.style.cssText.split(";");
                    for (var j = 0; j < aStyles.length; j++)
                    {
                        if (aStyles[j].toLowerCase().indexOf("mso")<0)
                            szCssText += aStyles[j] + ";";
                    }
                    e.style.cssText = szCssText;
                }
                e.removeAttribute("lang","",0);
                e.removeAttribute("stylw","",0);
            }
            var html = oDocument.body.innerHTML;
            html = html.replace(/\r/g,"");
            html = html.replace(/\n/g,"");
            html = html.replace(/\t/g," ");
            html = html.replace(/<\\?\??xml[^>]>/gi,"");
            html = html.replace(/(\&lt\;)?\\?\??|\W?|\w?xml[^(\&gt\;)](\&gt\;)?/gi,"");
            html = html.replace(/<\/?\w+:[^>]*>/gi,"");
            html = html.replace(/<p>&nbsp;<\/p>/gi,"<br/><br/>");
            html = html.replace(/[ ]+/g," ");
            html = html.replace(/<(\/)?strong>/ig,"<$1b> ");
            html = html.replace(/<(\/)?em>/ig,"<$1i> ");
            html = html.replace(/[”“]/gi,"\"")
	        html = html.replace(/[‘’]/gi,"'")
            html = html.replace(/^\s/i,"");
            html = html.replace(/\s$/i,"");
            html = html.replace(/<o:[pP]>&nbsp;<\/o:[pP]>/gi,"");
            html = html.replace(/<font>([^<>]+)<\/font>/gi,"$1");
            html = html.replace(/<span>([^<>]+)<\/span>/gi,"$1");
	        //html = html.replace(/<p([^>])*>(&nbsp;)*\s*<\/p>/gi,"")
	        //html = html.replace(/<span([^>])*>(&nbsp;)*\s*<\/span>/gi,"")
	        try { html = html.replace(/<st1:.*?>/gi,""); } 
            catch(ex) { html = html.replace(/<st1:.*>/gi,""); }
            oDocument.body.innerHTML = html;
        }
    }
}
