/*

	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

var DialogWindow = null;

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);
				if(element.value!=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;
				}
				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":
			{
			    var bI=false;
			    if(s.substring(0,1)!="+")
			    {
				    s=s.replace(/[^0-9]/g,"");
			        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);
				}
				else
				{
				    var n=s.length;
				    s="+"+s.replace(/[^0-9\s\-\(\)]/g,"");
				    bI=(n!=s.length);
				}
				if(n!=0 && (bI || n<7 || (n>10 && s.substring(0,1)!="+" && 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 shiftHighlight(keyCode,targ)
{
	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(id)
//{
//	var e = null;
//	if (id != null && id != "")
//		e = document.forms[0].elements[id];
//	else
//	{
//		for (i = 0; i < document.forms[0].elements.length; i++)
//		{
//			e = document.forms[0].elements[i];
//			if (!e.isDisabled) //ajs 12/9/02
//			{
//				if (e.type == 'text' || e.type == 'textarea' || e.type == 'select-one' || e.type == 'checkbox' || e.type == 'select-multiple' || e.type == 'radio')
//					break;
//			}
//		}
//	}
//	if (e != null && e.type != 'hidden' && !e.isDisabled && e.style.display != 'none') // ajs 12/9/02
//		e.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 = document.getElementById(divId);
	var img = document.getElementById(imageId);
	var 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; }
			SetCookie(divId,'1');
		}
		else
		{
			div.style.display = "none";		
			img.src = szExpand;	
			if (szExpandAlt != null) { img.alt = szExpandAlt; }
			SetCookie(divId,'0');
		}
		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
	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?"))
	{
		if (event)
			{event.returnValue = false;}
		return false;
	}
	return true;
}

function Confirm(msg)
{
	if (!confirm(msg))
	{
		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)
	{
		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)
{
	var oImage = null;
	if (event.srcElement.children[0] != null && event.srcElement[0].tagName == "IMG")
		oImage = event.srcElement[0];
	else if (event.srcElement.parentElement != null && event.srcElement.parentElement.children[0] != null && event.srcElement.parentElement.children[0].tagName == "IMG")
		oImage = event.srcElement.parentElement.children[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(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;
		DialogWindow.name = (new Date()).getSeconds().toString();
		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) - 50;
		if (DialogWindow.top < 0)
		    DialogWindow.top = 0;
		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()
{	
    try
    {
	    if (DialogWindow != null)
	    {
		    if (DialogWindow.win && !DialogWindow.win.closed)
		    {
			    DialogWindow.win.focus()	
		    }
	    }
	} catch (e) {}	
}

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.getElementById("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.getElementById("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 = (isNaN(parseInt(aOffsets[0])) ? 1 : nTopOffset);
				nLeftOffset = (isNaN(parseInt(aOffsets[1])) ? 1 : nLeftOffset);
				if(nTopOffset>0) nTopOffset=-30;
				if(nLeftOffset>0) nLeftOffset=-4;
			}
			var aCoordinates = szCoordinates.split(",");
			var nTop = parseInt(aCoordinates[0]); 
			var nLeft = parseInt(aCoordinates[1]);
			if(nTop < 0 || nTop > window.screen.availHeight) nTop=100;
			if(nLeft < 0 || nLeft > window.screen.availWidth) nLeft=100;
			var nHeight = parseInt(aCoordinates[2])-(nTopOffset*2);
			var nWidth = parseInt(aCoordinates[3])-(nLeftOffset*2);
			window.resizeTo(nWidth,nHeight);

            var adjustWidth, adjustHeight;
            if (navigator.appName == "Netscape")
            {
			    adjustWidth = parseInt(aCoordinates[3]) - parseInt(window.outerWidth) ;
			    adjustHeight = parseInt(aCoordinates[2]) - parseInt(window.outerHeight);
            }
            else
            {
			    adjustWidth = parseInt(aCoordinates[3]) - parseInt(document.body.offsetWidth);
			    adjustHeight = parseInt(aCoordinates[2]) - parseInt(document.body.offsetHeight);
			}
			//adjust to the exactly saved size
			window.resizeBy(adjustWidth, adjustHeight);

			window.moveTo(nLeft,nTop);
			// adjust to make sure the window is moved to the exact position saved in cookie
			var screenLeft = (window.screenLeft == undefined ? window.screenX : window.screenLeft);
			var screenTop = (window.screenTop == undefined ? window.screenY : window.screenTop);
			var adjustLeft = nLeft - parseInt(screenLeft);
			var adjustTop = nTop - parseInt(screenTop);
			window.moveBy(adjustLeft, adjustTop);
			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 != "")
	{
	    var szCookieValue;
	    if (navigator.appName == "Netscape")
	    	szCookieValue = window.screenY + "," + window.screenX + "," + window.outerHeight + "," + window.outerWidth;
	    else
	    	szCookieValue = window.screenTop + "," + window.screenLeft + "," + document.body.offsetHeight + "," + document.body.offsetWidth;

		SetCookie(szCookie,szCookieValue);
	}
}

function Report_Preview(szReportKey)
{
	openDialogAbsolute("ReportPreview.aspx?ReportKey="+szReportKey,900,700);
}

function Report_Run(szReportKey)
{
	openDialogAbsolute("ReportStart.aspx?ReportKey="+szReportKey+"&bReportCentral=true", 900, 700);
}

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.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);
}

function RegisterForEvent(siteCode, prdKey)
{
    if (opener != null && opener.opener != null && siteCode != null && prdKey != null)
    {
        opener.opener.document.location.href = 'Shopping/Shopping.aspx?Site='+siteCode+'&WebCode=Shopping&Cart=0&prd_key=' + prdKey;
        window.close();
        opener.close();
    }
    else { alert('Unable to redirect to online store. Please close open windows and use the navigation bar on the main page.'); }
}

function ShowMenu(szMenuID,szShowHide,szPosition)
{
	var nLinkHeight = 0;
	var nLinkWidth = 0;
	var nMenuHeight = 0;
	var nMenuWidth = 0;
	var oLink = document.getElementById(szMenuID);
	if (oLink)
	{
		nLinkHeight = oLink.offsetHeight;
		nLinkWidth = oLink.offsetWidth;
	}
	var oMenu = document.getElementById(szMenuID + "_menu");
	if (oMenu)
    {
        nMenuHeight = oMenu.offsetHeight;
		nMenuWidth = oMenu.offsetWidth;
		
		if (szShowHide == "hide")
			oMenu.style.display = "none";
		else
        {
            if (szPosition)
            {
                if (szPosition == "top")
                {
                    oMenu.style.top = "-5px";
                    oMenu.style.left = "5px";
                }
                else if (szPosition == "left")
                {
                    oMenu.style.top = (-nLinkHeight-5).toString() + "px";
                    oMenu.style.left = (nLinkWidth-5).toString() + "px";
                }
                else if (szPosition == "right")
                {
                    oMenu.style.top = (-nLinkHeight-5).toString() + "px";
                    oMenu.style.left = (-nMenuWidth+5).toString() + "px";
                }
                else if (szPosition == "bottom")
                {
                    oMenu.style.top = (-nMenuHeight-nLinkHeight+5).toString() + "px";
                    oMenu.style.left = "5px";
                }
            }
            oMenu.style.display = "block";
	    }
	}
}	


//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)
{
	var innText = new String();
	innText = textHtml;

	if (differenceUrlAnchor != '')
		while (innText.indexOf(differenceUrlAnchor,0)!=-1)
			innText = innText.replace(differenceUrlAnchor,'');
	if (differenceUrl4P != '')
		while (innText.indexOf(differenceUrl4P,0)!=-1)
			innText = innText.replace(differenceUrl4P,'../..');
	if (differenceUrl2P != '')
		while (innText.indexOf(differenceUrl2P,0)!=-1)
			innText = innText.replace(differenceUrl2P,'..');
    if (differenceUrl1P != '')
		while (innText.indexOf(differenceUrl1P,0)!=-1)
			innText = innText.replace(differenceUrl1P,'');
	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 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;
        }
    }
}

function goback()
{
history.go(-1);
}
var new_win;
function open_window(url,win_name,w,h,scroll)
{
var 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;
}
