	//dialog vars
	var winModalWindow;
	var PromptText;
	var PromptTimeoutEnabled = false;
	
	//menu vars
	var objSpanCollection;							/* store a collecion of Menu */
	var objMenu;									/* the menu is clicked on */
	var onImages=new Array();
	
	function InitializeMenu(SelectedIndex) 
	{
		/* get a collection of menus */
		objSpanCollection = document.getElementById('MainMenu').getElementsByTagName("SPAN");

		for (var i = 0; i < objSpanCollection.length; i++)
		{
			var objSpan = objSpanCollection[i];
			
			/* assign the click event to every Menuheader */
			var div1 = objSpan.getElementsByTagName('div')[0];
			div1.onclick = ControlMenu;
			
			var div2 = objSpan.getElementsByTagName('div')[1];
			
			if(i != SelectedIndex)
			{	
				div2.style.display = "none";
			}
			else
			{
				div2.style.display = "block";
			}
		}
		initButtons();
	}
	
	function turnOn(img)
	{ 
		if(img.filters != null)
			img.filters[0].apply();
		img.offSrc = img.src;
		img.src = onImages[img.name].src;
		if(img.filters != null)
			img.filters[0].play();
	}

	function turnOff(img)
	{ 
		if(img.filters != null)
			img.filters[0].stop();
		img.src = img.offSrc;
	}

	
	function ControlMenu() 
	{
		objMenu = this.parentNode.getElementsByTagName('div')[1];
		
		if (objMenu.style.display == "none")
		{		
			for (var i = 0; i < objSpanCollection.length; i++)
			{
				if (this.parentNode != objSpanCollection[i])
				{
					objSpanCollection[i].getElementsByTagName('div')[1].style.display = "none";
				}
			}
			
			ShowMenu();
		}
		else
		{
			HideMenu();
		}
	}
	
	function ShowMenu()
	{		
		objMenu.style.display = "block"; 
	}
	
	function HideMenu()
	{	
		objMenu.style.display = "none";
	}
	
	function SwapImage(IMG,ImageSrc)
	{
		IMG.src = ImageSrc;
	}

	function initButtons() {
		var imgarr = document.getElementsByTagName('img');
		processElements(imgarr);
		
		imgarr = document.getElementsByTagName('input');
		processElements(imgarr);
	}

	function processElements(elements,reset)
	{
		for (var i = 0; i < elements.length; i++) 
		{
			if (elements[i].getAttribute('hsrc')) 
			{
				elements[i].onmouseout = function() {
					var imgOriginHsrc = this.getAttribute('hsrc');
					this.setAttribute('hsrc',this.getAttribute('src'));
					this.setAttribute('src',imgOriginHsrc);
				}
				
				elements[i].onmouseover = function() {
					var imgOriginSrc = this.getAttribute('src');
					this.setAttribute('src',this.getAttribute('hsrc'));
					this.setAttribute('hsrc',imgOriginSrc);
				}
			}
			
			if (elements[i].getAttribute('xsrc'))
			{
				if(!elements[i].name)
					elements[i].name = elements[i].tagName + i;
				
				onImages[elements[i].name] = new Image();
				onImages[elements[i].name].src = elements[i].getAttribute('xsrc');
				
				elements[i].className = 'Menu_Trans';
				
				elements[i].onmouseout = function() {
					if(this.isOn)
					{
						turnOff(this);
						this.isOn = false;
					}
				}
				elements[i].onmousedown = function() {
					if(this.isOn)
					{
						turnOff(this);
						this.isOn = false;
					}
				}
				elements[i].onmouseover = function() {
					turnOn(this);
					this.isOn = true;
				}
			}
		}
	}

	function SetOnChange()
	{
		_SetOnChange(document.getElementsByTagName('input'));
		_SetOnChange(document.getElementsByTagName('select'));
		_SetOnChange(document.getElementsByTagName('textarea'));
		_SetOnChange(document.getElementsByTagName('a'));
	}
	
	function _SetOnChange(controls)
	{
		var skipIsDirtyVal = false;

		if(controls == null) return;
		
		for(var xx = 0; xx < controls.length; xx++)
		{
			var control = controls[xx];

			if( control.getAttribute('SkipIsDirtyValidation') == "true" )
			{
				if((control.onchange == null && control.type != "image") || (control.onclick == null && control.type == "image"))
				{
					if(control.type == "image" || control.tagName == "A") // NK (11/3/06): Added A tag chk
					{
						control.onclick = function(){
							if(document.getElementById('IsDirty').value == 'true')
								document.getElementById('IsDirty').value = 'skip';
						}
					}
					else
					{
						control.onchange = function(){
							if(document.getElementById('IsDirty').value == 'true')
								document.getElementById('IsDirty').value = 'skip';
						};
					}
				}
				else
				{
					if (control.type == "image")
					{
					
						var ev = control.onclick.toString();
						ev = ev.substring(ev.indexOf("{") + 1, ev.lastIndexOf("}"));
						var func = new Function("if(document.getElementById('IsDirty').value == 'true')document.getElementById('IsDirty').value = 'skip'; " + ev);
						
						control.onclick = func;
					} 
					else 
					{     
						var ev = control.onchange.toString();
						ev = ev.substring(ev.indexOf("{") + 1, ev.lastIndexOf("}"));
						var func = new Function("if(document.getElementById('IsDirty').value == 'true')document.getElementById('IsDirty').value = 'skip'; " + ev);       
						
						control.onchange = func;
					}
				}
            }
            else
            {
				if((control.onchange == null && control.type != "image") || (control.onclick == null && control.type == "image"))
				{
					if(control.type == "image")
					{
						control.onclick = function(){
							document.getElementById('IsDirty').value = 'true';
						};
					}
					else
					{
						control.onchange = function(){
							document.getElementById('IsDirty').value = 'true';
						};
					}
				}
				else
				{
					if (control.type == "image")
					{
						var ev = control.onclick.toString();
						ev = ev.substring(ev.indexOf("{") + 1, ev.lastIndexOf("}"));
						var func = new Function("document.getElementById('IsDirty').value = 'true'; " + ev);
						
						control.onclick = func;
					} 
					else 
					{
						var ev = control.onchange.toString();
						ev = ev.substring(ev.indexOf("{") + 1, ev.lastIndexOf("}"));
						var func = new Function("document.getElementById('IsDirty').value = 'true'; " + ev);       
						
						control.onchange = func;
					}
				}
            }
		}
	}
	
	function beforeUnload()
	{
		if (document.getElementById('IsDirty').value != 'skip' && document.getElementById('IsDirty').value == 'true')
		{
			//% Firefox???: if ( event.preventDefault != null )
			//% Firefox???:		event.preventDefault();
			event.returnValue = "The data on this page has changed.\nNavigating away from this page will result in lost data.";
		}
	}

	function SkipDirtyFlag()
	{
		document.getElementById('IsDirty').value = 'skip';
	}
	
	function ResetDirtyFlag()
	{
		document.getElementById('IsDirty').value = '';
	}
	
	function HideWaitMessage()
	{
		document.getElementById('PleaseWait').style.visibility = "hidden";
		document.getElementById('PleaseWait').style.display = "none";
		document.getElementById('BodyContent').style.visibility = "visible";
		document.getElementById('BodyContent').style.display = "block";
		return true;
	}
	
	function ShowWaitMessage()
	{
		if (document.all)
		{
			//var top = 1*document.getElementById('PleaseWait').style.top.replace('px','');
		
			//document.getElementById('PleaseWait').style.visibility = "visible";
			//document.getElementById('PleaseWait').style.display = "block";
			//document.getElementById('PleaseWait').style.top = top + document.body.scrollTop;
			//document.getElementById('BodyContent').style.visibility = "hidden";
			//document.getElementById('BodyContent').style.display = "none";
			
			//document.getElementById('BodyContent').style.display = "none";		
			
			var element = document.getElementById('PleaseWait');
			element.style.visibility = "visible";
			element.style.display = "block";
			element.style.top = (element.offsetParent.clientHeight/2)-(element.clientHeight/2) + element.offsetParent.scrollTop;
			
			return true;
		}
		else
		{
			return true;
		}
	}
	
	function ShowWaitUploadingMessage()
	{
		if (document.all)
		{
			//var top = 1*document.getElementById('PleaseWaitUploading').style.top.replace('px','');
		
			//document.getElementById('PleaseWaitUploading').style.visibility = "visible";
			//document.getElementById('PleaseWaitUploading').style.display = "block";
			//document.getElementById('PleaseWaitUploading').style.top = top + document.body.scrollTop;
			//document.getElementById('BodyContent').style.visibility = "hidden";
			//document.getElementById('BodyContent').style.display = "none";
			
			document.getElementById('BodyContent').style.display = "none";		
			
			var element = document.getElementById('PleaseWaitUploading');
			element.style.visibility = "visible";
			element.style.display = "block";
			element.style.top = (element.offsetParent.clientHeight/2)-(element.clientHeight/2) + element.offsetParent.scrollTop;
			
			if(document.getElementById('imageedit'))
			{
				document.getElementById('imageedit').style.visibility = "hidden";
				document.getElementById('imageedit').style.display = "none";
			}
			return true;
		}
		else
		{
			return true;
		}
	}
	
	function OpenHelp(g,q)
	{
		var LeftPosition = (screen.width) ? (screen.width-780)/2 : 0;
		var TopPosition = (screen.height) ? (screen.height-600)/2 : 0;
		
		var features = "location=no,scrollbars=yes,menubar=no,resizable=no,status=no,titlebar=no,toolbar=no,top="+TopPosition+",left="+LeftPosition+",width=780,height=600";
		window.open("helpfaq.aspx?g="+g+"&q="+q,"_help",features);
	}
	
	function OpenFeedback()
	{		
		var features = "location=no,scrollbars=no,menubar=no,resizable=no,status=no,titlebar=no,toolbar=no,width=530,height=500";
		window.open("CustomerFeedback.aspx","", features);
	}

	function OpenCS(link)
	{
		window.open(link,"_support");
	}
	
	function OpenEULA()
	{
		var LeftPosition = (screen.width) ? (screen.width-700)/2 : 0;
		var TopPosition = (screen.height) ? (screen.height-700)/2 : 0;
		
		var features = "location=no,scrollbars=yes,menubar=no,resizable=no,status=no,titlebar=no,toolbar=no,top="+TopPosition+",left="+LeftPosition+",width=700,height=700";
		window.open("eula.aspx","_eula",features);
	}
	
	function StartTimer()
	{
		var ms = 240 * 60 * 1000; //min * sec * ms
		
		window.setTimeout('OpenPopup()',ms);
	}
	
	function OpenPopup()
	{
		var LeftPosition = (screen.width) ? (screen.width-300)/2 : 0;
		var TopPosition = (screen.height) ? (screen.height-120)/2 : 0;
		var msg = "Your session is about to expire. Click 'ok' to extend your online session.";
		var settings = 'dialogHeight:150px;dialogWidth:300px;dialogLeft:' + LeftPosition + 'px;dialogTop:' + TopPosition + 'px;scrollbars:no;status:no;resizable:no;help:no;';

		if(window.showModalDialog)
		{
			var args = new Array(msg,true);
			var newWindow = window.showModalDialog('popupdialog.aspx',args,settings);
			if(newWindow == 'timeout')
				document.forms[0].submit();
			StartTimer();
		}
		else
		{
			PromptText = msg;
			PromptTimeoutEnabled = true;
			ShowModalWindow('popupdialog.aspx',150,300,TopPosition,LeftPosition);
		}
	}
	
	function IgnoreEvents(e)
	{
		return false;
	}
	 
	function ShowModalWindow(page,h,w,t,l,args,addtlFeatures)
	{
		if (window.showModalDialog)
		{
			return window.showModalDialog(page,args,
				"dialogWidth="+w+"px;dialogHeight="+h+"px;dialogLeft:" + l + "px;dialogTop:" + t + "px;;status:no;resizable:no;help:no;")
		}
		else
		{
			window.top.captureEvents (Event.CLICK|Event.FOCUS);
			window.top.onclick=IgnoreEvents;
			window.top.onfocus=HandleFocus;
			winModalWindow = 
			window.open (page,"ModalChild",
			"dependent=yes,width="+w+",height="+h+",top="+t+",left="+l+"location=no,menubar=no,resizable=no,status=no,titlebar=no,toolbar=no" + (addtlFeatures ? ","+addtlFeatures : ""));
			winModalWindow.focus();
			return winModalWindow;
		}
	}
	
	function ShowModalWindowForParent(page,h,w,t,l,args,addtlFeatures)
	{
		if (!window.showModalDialog)
		{
			window.opener.PromptText = args[0];
			window.opener.PromptTimeoutEnabled = args[1];
			
			if(window.opener.winModalWindow && window.opener.winModalWindow.open && !window.opener.winModalWindow.closed)
				window.opener.winModalWindow.close();
			
			window.opener.ShowModalWindow(page,h,w,t,l,args,addtlFeatures);
		}
		else
		{
			return window.showModalDialog(page,args,
				"dialogWidth="+w+"px;dialogHeight="+h+"px;dialogLeft:" + l + "px;dialogTop:" + t + "px;;status:no;resizable:no;help:no;")
		}
	}
	
	function HandleFocus()
	{
		if (winModalWindow)
		{
			if (!winModalWindow.closed)
			{
				winModalWindow.focus();
			}
			else
			{
				window.top.releaseEvents (Event.CLICK|Event.FOCUS);
				window.top.onclick = "";
			}
		}
		return false
	}