//<![CDATA[

/// <reference name="MicrosoftAjax.js"/>

/// <summary>
/// Opens a webpage in a new browser window
/// </summary>
/// <param name="url">The URL of the page to open</param>
/// <param name="closeParent">Close the browser window which opens the new window?</param>
/// <param name="winWidth">The width of the new window</param>
/// <param name="winHeight">The height of the new window</param>
/// <param name="centerScreen">Center the window on the screen?</param>
/// <param name="hideBars">Hide all bars? (menubar, toolbar, statusbar, etc.)</param>
/// <returns>A reference to the window object</returns>
function OpenWindow(url, closeParent, winWidth, winHeight, centerScreen, hideBars, resizable)
{
	//Disable errorhandling
	window.onerror = errorHandler;

	//Set (default) window size (maximized)
	if (winWidth==null) { winWidth=screen.availWidth-10; }
	if (winHeight==null) { winHeight=screen.availHeight-28; }
	
	//Set window position
	var winLeft = 0;
	var winTop = 0;
	var extraTop = 0;
	if (!hideBars)
		extraTop = 150;
	if (centerScreen && winWidth!=screen.availWidth-10)
	{
		winLeft = (screen.availWidth-winWidth) / 2;
		if (winLeft<0) { winLeft=0; }
		winTop = (screen.availHeight-winHeight-extraTop) / 2;
		if (winTop<0) { winTop=0; }
	}
	
	//Set window bar properties
	var winBars;
	if (hideBars)
		winBars = "directories=no, scrollbars=no, status=no, menubar=no, toolbar=no";
	else
		winBars = "directories=yes, scrollbars=yes, status=yes, menubar=yes, toolbar=yes";
	if (typeof(resizable)=='undefined' || resizable==null || resizable==true)
		winBars += ", resizable=yes";
	else
		winBars += ", resizable=no";
	
	//Set all window properties
	var winFeatures = "width=" + winWidth + ", height=" + winHeight +
							", left=" + winLeft + ", top=" + winTop + ", " + winBars;

	//Open the window and return the object
	if (url!=null && url!="")
	{
		var winOpen = window.open(url, "", winFeatures);

		//Close the browser window which opens the new window	
		if (closeParent)
		{
			window.opener = window.self; 
			window.close(); 
		}
		
		//Return the reference to new window object
		return winOpen;
	}
}

/// <summary>
/// Opens a webpage in a new browser window
/// </summary>
/// <param name="url">The URL of the page to open</param>
/// <param name="closeParent">Close the browser window which opens the new window?</param>
/// <param name="winWidth">The width of the new window</param>
/// <param name="winHeight">The height of the new window</param>
/// <param name="centerScreen">Center the window on the screen?</param>
/// <param name="winFeatures">Specify your own featurs like hiding bars</param>
/// <returns>A reference to the window object</returns>
function OpenWindowWithFeatures(url, closeParent, winWidth, winHeight, centerScreen, winFeatures)
{
	//Disable errorhandling
	window.onerror = errorHandler;

	//Set (default) window size
	if (winWidth==null) { winWidth=screen.availWidth-10; }
	if (winHeight==null) { winHeight=screen.availHeight-28; }
	
	//Set window position
	var winLeft = 0;
	var winTop = 0;
	if (centerScreen && winWidth!=screen.availWidth-10)
	{
		winLeft = (screen.availWidth-winWidth) / 2;
		if (winLeft<0) { winLeft=0; }
		winTop = (screen.availHeight-winHeight) / 2;
		if (winTop<0) { winTop=0; }
	}
	
	//Set window bar properties
	var winBars;
	if (winFeatures==null)
	{
		winBars = "";
	}
	else
	{
		winBars = winFeatures;
	}
	
	//Set all window properties
	var winFeatures = "width=" + winWidth + ", height=" + winHeight +
							", left=" + winLeft + ", top=" + winTop + ", " + winBars;
	
	//Open the window and return the object
	var winOpen = window.open(url, "", winFeatures);

	//Close the browser window which opens the new window	
	if (closeParent)
	{
		window.opener = window.self; 
		window.close(); 
	}
	
	//Return the reference to new window object
	return winOpen;
}

/// <summary>
/// Opens a webpage in a new dialog window
/// </summary>
/// <param name="url">The URL of the page to open</param>
/// <param name="dialogArguments">Values to pass to the dialog window</param>
/// <param name="winWidth">The width of the new window</param>
/// <param name="winHeight">The height of the new window</param>
/// <param name="extraSettings">Extra settings to set for the dialog window</param>
/// <returns>A reference to the window object</returns>
function OpenDialogWindow(url, dialogArguments, winWidth, winHeight, extraSettings)
{
	//Disable errorhandling
	window.onerror = errorHandler;

	//Set (default) window size
	if (winWidth==null) { winWidth=300; }
	if (winHeight==null) { winHeight=300; }
	
	if (dialogArguments==null)
		dialogArguments = "";
	
	if (extraSettings==null)
		extraSettings = "";
		
	var dialogSettings = "dialogWidth:" + winWidth + "px ; dialogHeight:" + winHeight + "px ; " + extraSettings;

	if (window.showModalDialog)
	{
		//Open the window in a modal dialog and return the object
		return window.showModalDialog(url, dialogArguments, dialogSettings);
	}
	else
	{
		//Open the window as a normal window and return the object
		return OpenWindow(url, false, winWidth, winHeight, true, true, true);
	}
}

/// <summary>
/// Close a browser window. See the AskConfirmation() function for other details
/// </summary>
/// <param name="askConfirm">Ask the user for confirmation, before closing the window</param>
/// <param name="askMsg">The message to ask the user for</param>
/// <param name="submitOpener">Submit the window.document.form which opened this window?</param>
/// <returns>nothing</returns>
function CloseWindow(askConfirm, askMsg, submitOpener)
{
	//Disable errorhandling
	window.onerror = errorHandler;

	var bClose = true;
	
	//Ask the user for confirmation, to close the window
	if (askConfirm)
	{
		var message;
		//If specified use the message from the parameter askMsg
		if (askMsg!=null)
			message = askMsg;
		else
			message = "Are you sure you want to close this window?";
		
		var bConfirmed = AskConfirmation(message);
		bClose = bConfirmed;
	}
	
	if (bClose)
	{
		if (submitOpener)
		{
			var opener = getWindowOpener();
			if (opener!=null)
				opener.document.forms[0].submit();
		}
		//Close this window	
		try
		{
			window.close();
			self.close();
			document.close();
			top.close();
			parent.window.close();
		}
		catch (ex) {}
	}
}

/// <summary>
/// Try to return the window which opened this window
/// </summary>
function getWindowOpener()
{
	var opener = null;
	if(window.showModalDialog)
	{
		opener = window.dialogArguments;
		if (typeof(opener)=="undefined" || opener==null)
			opener = window.opener;
	}
	else
	{
		opener = window.opener;
	}
	return opener;
}


/// <summary>
/// Asks the user for confirmation: Yes/No (using either the askMsg or the controlMsg.value to ask)
/// </summary>
/// <param name="askMsg">The message to ask the user for</param>
/// <param name="controlMsg">Reference to the form control which contains the message (to ask the user for)</param>
/// <returns>True (when the user enters Yes); else False</returns>
function AskConfirmation(askMsg, controlMsg)
{
	var message;

	//Disable errorhandling
	window.onerror = errorHandler;

	//If specified use the message from the parameter askMsg
	if (askMsg!=null)
	{
		message = askMsg;
	}
	//else: if available, get the message (for confirmation) from the control send as parameter (controlMsg)
	else if (controlMsg!=null)
	{
		message = controlMsg.value;
	}
	//else: use an empty message
	else
	{
		message = "";
	}
		
	return confirm(message);
}


/// <summary>
/// Shows the user a message (using either the showMsg or the controlMsg.value to show)
/// </summary>
/// <param name="showMsg">The message to show the user</param>
/// <param name="controlMsg">Reference to the form control which contains the message (to show the user)</param>
/// <returns>nothing</returns>
function ShowMessage(showMsg, controlMsg)
{
	var message;

	//Disable errorhandling
	window.onerror = errorHandler;

	//If specified use the message from the parameter showMsg
	if (showMsg!=null)
	{
		message = showMsg;
	}
	//else: if available, get the message from the control send as parameter (controlMsg)
	else if (controlMsg!=null)
	{
		message = controlMsg.value;
	}
	//else: use an empty message
	else
	{
		message = "";
	}
		
	alert(message);
}


/// <summary>
/// Changes the mouse pointer to hourglass (or back to default) when moving over the specified control
/// </summary>
/// <param name="control">The control change the mousepointer for</param>
/// <param name="waitCursor">true for default and false for hourglass</param>
/// <returns>true, when the mousepointer successfully changes</returns>
function CursorWait(control, defaultCursor)
{
	//Disable errorhandling
	window.onerror = errorHandler;

	if (control!=null)
	{
		if (defaultCursor)
		{
			control.style.cursor = "auto";
		}
		else
		{
			control.style.cursor = "wait";
		}
		return true;
	}
}


/// <summary>
/// Changes the mouse pointer to hourglass (or back to default) for all controls on the page
/// </summary>
/// <param name="defaultCursor">true for default and false for hourglass</param>
/// <param name="loopAllControls">Loop through all controls to set the hourglass, or use a
///								  DIV tag on top of all controls</param>
/// <returns>true, when the mousepointer successfully changes</returns>
function PageCursorWait(defaultCursor, loopAllControls)
{
	//Disable errorhandling
	window.onerror = errorHandler;

	if (defaultCursor)
	{
		styleCursor = "auto";
	}
	else
	{
		styleCursor = "wait";
	}
	if (loopAllControls!=null && loopAllControls==true)
	{
		for (i=0; i<document.all.length; i++)
		{
			document.all(i).style.cursor = styleCursor;
		}
	}
	else
	{
		//Check if the DIV is already created
		var d = $get('thisPageCursor');
		if (d!='undefined' && d!=null)
		{
			d.style.cursor = styleCursor;
			d.style.display = "";
		}
		else
		{
			htmlText = "<div id=thisPageCursor style=\"cursor:" + styleCursor + "; z-index:999; position:absolute; left:0; top: 0; " + 
				"	width:" + (parseInt(document.body.clientWidth)) + "; height:100%\"></div>";
			document.body.insertAdjacentHTML("afterBegin", htmlText);
		}
	}
	document.body.style.cursor = styleCursor;

	return true;
}

function ClearPageCursorWait()
{
	var d = $get('thisPageCursor');
	if (d!='undefined' && d!=null)
	{
		d.style.cursor = "auto";
		d.style.display = "none";
	}
	document.body.style.cursor = "auto";
}

function DisableBodyPageWait()
{
	document.body.onbeforeunload = null;
	document.body.onunload = null;
}

/// <summary>
/// Navigates the current frame or window to the specified page
/// </summary>
/// <param name="url">URL to navigate to</param>
/// <param name="milliseconds">Time in milliseconds to wait before navigating (default=0)</param>
/// <param name="target">Frame name or when not specified the current window</param>
/// <returns>nothing</returns>
function Navigate(url, milliseconds, target)
{
	//Disable errorhandling
	window.onerror = errorHandler;

	if (milliseconds!=null && milliseconds>0)
	{
		if (target==null)
			window.setTimeout("DoNavigate('" + url + "',null)", milliseconds);
		else
			window.setTimeout("DoNavigate('" + url + "','" + target + "')", milliseconds);
	}
	else
	{
		DoNavigate(url,target);
	}
}
function DoNavigate(url, target)
{
	if (target==null)
		location.href = url;
	else if (target=="top")
		top.location.href = url;
	else
		loopFrames(url, target, top);
}
//Loop through all frames to to find the
//specified frame and navigate that frame
//to the specified URL
function loopFrames(url, frameName, frameObj)
{
	for (var i=0; i<frameObj.frames.length; i++)
	{
		if (frameObj.frames(i).name==frameName)
		{
			frameObj.frames(i).location.href = url;
			break;
		}
		if (frameObj.frames(i).frames.length>0)
		{
			loopFrames(url, frameName, frameObj.frames(i));
		}
	}
}

/// <summary>
/// Resizes te current window to the specified width and height.
/// </summary>
/// <param name="newWidth">New width of the window</param>
/// <param name="newHeight">New height of the window</param>
/// <returns>true</returns>
function ResizeWindow(newWidth, newHeight)
{
	top.resizeTo(newWidth, newHeight);
	return true;
}

/// <summary>
/// Handles the default button for a control on the current page (when the user types the Enter key)
/// </summary>
function HandleDefaultButton(btnID, event)
{
	btn = $get(btnID);
	var keyCode;
	if (document.all)
		keyCode = event.keyCode;
	else if (document.getElementById || document.layers)
		keyCode = event.which;

	if (keyCode==13)
	{
		event.returnValue=false;
		event.cancel = true;
		btn.focus();
		btn.click();
	}
}

/// <summary>
/// Shows the content of the specified object in an new window and prints the page
/// </summary>
/// <param name="objectName">Id of the control to print its content from</param>
/// <param name="closeWindowAfterPrint">Close the window automatically after printing is finished</param>
/// <param name="newWindowTitle">Window title of the pop-up window</param>
/// <param name="scriptToExecuteInPrintWindow">Client script which can be executed in the print window (after setting the HTML content)</param>
/// <param name="extraHeadTagHtml">Extra HTML content for in the HEAD tag</param>
function PrintContent(objectName, colseWindowAfterPrint, newWindowTitle, scriptToExecuteInPrintWindow, extraHeadTagHtml)
{
var popup_height=500;
var popup_width=700;

	//Open and center popup window
	var w=window.open('','','height='+popup_height+',width='+popup_width+',toolbar=yes,scrollbars=yes')
	var intwidth=parseInt(screen.availWidth);
	var intheight=parseInt(screen.availHeight);
	if(intwidth>0&&intheight>0){
		w.moveTo(((intwidth-popup_width) / 2), ((intheight - popup_height) / 2));
		w.focus();
	}

	var printarea = $get(objectName)
	if (printarea != null) 
	{
		w.document.open();
		w.document.write('<html>\n');
		w.document.write('<head>\n');
		if (extraHeadTagHtml!=null)
			w.document.write(extraHeadTagHtml + '\n');
		if (newWindowTitle!=null)
			w.document.write('	<title>' + newWindowTitle + '</title>');
		w.document.write('</head>\n');
		var extraScript = '';
		if (scriptToExecuteInPrintWindow!=null)
			extraScript = scriptToExecuteInPrintWindow;
		var timeOutHtml = '';
		if (colseWindowAfterPrint)
			timeOutHtml = "setTimeout(\'window.close()\', 5000);";
		w.document.write('<body onload="' + extraScript + '; window.print();' + timeOutHtml + '" >\n');
		w.document.write('  	<div style="position:relative;width:' + popup_width + '">' + printarea.innerHTML + '</div>\n');
		w.document.write('</body></html>\n');
		w.document.close();
	}
}

/// <summary>
/// Adds functionality to a page to:
/// - 'blur' the page 
/// - show a 'Processing window' within the page
/// For blurring the page a semi-transparent image will be used. To show a 'Processing
/// window' another html page will be used
/// Call the AddProcesspageToPage function at the end of the BODY and call the ProcessNextPage
/// function from (i.e.) a button or hyperlink to start blurring en show the 'Processing window'
/// </summary>
/// <param name="processpageUrl">url to the 'processing window' page</param>
/// <param name="blurImageUrl">url to the semi-transparent image</param>
/// <returns>nothing</returns>
function AddProcesspageToPage(processpageUrl, blurImageUrl)
{
	//Disable errorhandling
	window.onerror = errorHandler;

	htmlText = "<div id=thisProcessPage style=\"display:none; z-index:999; position:absolute; left:0; top: 0; " + 
		"	background-image: url(" + blurImageUrl + "); backgroud-repeat: repeat; width:" + (parseInt(document.body.clientWidth)) + "; height:100%\">\n" +
		"<table width=100% height=100%>" + 
		"<tr><td align=center valign=middle>" +
		"	<iframe width=250 height=120 scrolling=no frameborder=0 border=0 src=\"" + processpageUrl + "\"></iframe>" +
		"</td></tr>" +
		"</table>" +
		"</div>";
	document.body.insertAdjacentHTML("afterBegin", htmlText);
}

function AddProcesspageToPageWithDIV(processText, logoImageUrl, blurImageUrl)
{
	//Disable errorhandling
	window.onerror = errorHandler;

	htmlText = "<div id=thisProcessPage style=\"display:none; z-index:999; position:absolute; left:0; top: 0; " + 
		"	background-image: url(" + blurImageUrl + "); backgroud-repeat: repeat; width:" + (parseInt(document.body.clientWidth)) + "; height:100%\">\n" +
		"<table width=100% height=100%>" + 
		"<tr><td align=center valign=middle>" +
		"	<div style='BACKGROUND-COLOR:whitesmoke; BORDER:black 1px solid; POSITION:relative; WIDTH:250px; HEIGHT:120px' onmouseover=\"this.style.cursor='wait'\">" +
		"		<IMG align=left style='LEFT: -3px; POSITION: relative; TOP: 0px' src='" + logoImageUrl +  "'>" +
		"		<span style='TEXT-ALIGN:left; LEFT: 114px; POSITION: absolute; TOP: 30px; FONT-FAMILY:Arial; FONT-SIZE:18px; FONT-WEIGHT:bold'>" + processText + "</span>" +
		"	</div>" +
		"</td></tr>" +
		"</table>" +
		"</div>";
	document.body.insertAdjacentHTML("afterBegin", htmlText);
}
function ProcessNextPage()
{
	if (thisProcessPage!=null)
	{
		thisProcessPage.style.display = "";
	}
	return true;
}
function HideProcessNextPage()
{
	//Disable errorhandling
	window.onerror = errorHandler;

	thisProcessPage.style.display = "none";
	return true;
}

function AddModalWindowBackground()
{
	htmlText = "<div id=modalBack class=ModalBackground style='width:" + (parseInt(document.body.clientWidth)) + "; height:100%'><br><br>Test</div>";
	document.body.insertAdjacentHTML("afterBegin", htmlText);
}

/// <summary>
/// Add's link to Internet Explorer Favorites
/// </summary>
/// <param name="link">LinkUrl to add to favorites (when not specified the current page will be used</param>
/// <param name="linkName">Name of the link to add to favorites (when not specified the current page title will be used</param>
function AddFavorite(link, linkName)
{
	//Disable errorhandling
	window.onerror = errorHandler;

	if (link==null)
	{
		link = location.href;
	}
	if (linkName==null)
	{
		linkName = document.title;
	}
	
	window.external.addFavorite(link, linkName);
	return true;
}

/// <summary>
/// Checks a container control if there are any checkboxes selected
/// </summary>
/// <param name="container">ID of the container control</param>
/// <returns>Number of checkboxes selected</returns>
function CheckSelectedCheckboxesInContainer(container)
{
	var checkedCount = 0;
	var cont = $get(container);
	for (var i=0; i<cont.all.length; i++)
	{
		if(cont.all(i).checked!=null && cont.all(i).checked)
			checkedCount++;
	}
	return checkedCount;
}

/// <summary>
/// Set all checkboxes in a container control checked
/// </summary>
/// <param name="container">ID of the container control</param>
/// <param name="checked">Set checked or not</param>
function SetSelectedCheckboxesInContainer(container,checked)
{
	var cont = $get(container);
	for (var i=0; i<cont.all.length; i++)
	{
		if(cont.all(i).checked!=null)
			cont.all(i).checked=checked;
	}
}

/// <summary>
/// Checks a checkbox array (defined by using the same checkbox name) if there are any checkboxes selected
/// </summary>
/// <param name="checkboxName">Name of the checkboxes</param>
/// <returns>Number of checkboxes selected</returns>
function CheckSelectedCheckboxesInArray(checkboxName)
{
	var checkedCount = 0;
	var arrChk = $get(checkboxName);
	for (var i=0; i<arrChk.length; i++)
	{
		if(arrChk(i).checked!=null && arrChk(i).checked)
			checkedCount++;
	}
	return checkedCount;
}

/// <summary>
/// Sets all checkboxes in a checkbox array (defined by using the same checkbox name) checked
/// </summary>
/// <param name="checkboxName">Name of the checkboxes</param>
/// <returns>Number of checkboxes selected</returns>
function SetSelectedCheckboxesInArray(checkboxName,checked)
{
	var arrChk = $get(checkboxName);
	for (var i=0; i<arrChk.length; i++)
	{
		if(arrChk(i).checked!=null)
			arrChk(i).checked=checked;
	}
	return checkedCount;
}

/// <summary>
/// Loop through all frames from the specified window object and find the specified frame
/// </summary>
/// <param name="winObj">Window object</param>
/// <param name="frameName">name of the frame to find</param>
/// <returns>Frame object when found</returns>
function GetFrame(winObj, frameName)
{
	for (var i=0; i<winObj.frames.length; i++)
	{
		if (winObj.frames(i).name==frameName)
		{
			return winObj.frames(i);
			break;
		}
		if (winObj.frames(i).frames.length>0)
		{
			return GetFrame(winObj.frames(i), frameName);
		}
	}
}

/// <summary>
/// Finds the radiobutton with the sepcified value and checks the radio
/// </summary>
/// <param name="optionName">name of the radio group</param>
/// <param name="optionValue">value of the radio button</param>
function SetOptionValue(optionName, optionValue)
{
	if ($get(optionName)!=null)
	{
		for (var i=0; i<$get(optionName).length; i++)
		{
			if ($get(optionName)(i).value==optionValue)
				$get(optionName)(i).checked = true;
		}
	}
}

/// <summary>
/// Enables or disables controls within a container (i.e. a DIV)
/// </summary>
/// <param name="container">Container with controls</param>
/// <param name="enable">TRUE to enable; FALSE to disable</param>
function EnableControls(container, enable)
{
	if ($get(container)!=null)
	{
		var element = $get(container);
		for (i=0; i<element.all.length; i++)
		{
			element.all[i].disabled = (!enable);
		}
	}	
}

/// <summary>
/// Enables or disables radiobuttons with the specified group name
/// </summary>
/// <param name="groupName">Group name of the radio buttons</param>
/// <param name="enable">TRUE to enable; FALSE to disable</param>
/// <param name="alsoSetParent">Also enable/disable the parent element of the radio button</param>
function EnableRadios(groupName, enable, alsoSetParent)
{
	var ctrls = document.getElementsByName(groupName);
	if (ctrls!=null)
	{
		for (i=0; i<ctrls.length; i++)
		{
			ctrls[i].disabled = (!enable);
			if (alsoSetParent!=null && alsoSetParent && ctrls[i].parentElement!=null)
				ctrls[i].parentElement.disabled = (!enable);
		}
	}
}

/// <summary>
/// Resizes the specified image object (by setting its width/height attributes)
/// </summary>
/// <param name="imageObject">HTML Image object</param>
/// <param name="maxWidth">Max. width of the image (leave 0/null to allow all widths)</param>
/// <param name="maxHeight">Max. height of the image (leave 0/null to allow all widths)</param>
function ResizeImage(imageObject, maxWidth, maxHeight)
{
	var img = new Image(); 
	img.src = imageObject.src;
	
	if (maxWidth!=null && maxWidth>0 && maxHeight!=null && maxHeight>0 && img.width>maxWidth && img.height>maxHeight)
	{
	    //Proportional resizing
	    var widthRatio = maxWidth / img.width;
	    var heightRatio = maxHeight / img.height;
	    if (widthRatio<heightRatio)
        {
            imageObject.style.width = img.width * widthRatio;
            imageObject.style.height = img.height * widthRatio;
        }
        else
        {
            imageObject.style.width = img.width * heightRatio;
            imageObject.style.height = img.height * heightRatio;
        }
	}
	else
	{
	    if (maxWidth!=null && maxWidth>0)
	    {
		    if (img.width>maxWidth)
			    imageObject.style.width = maxWidth;
	    }
	    if (maxHeight!=null && maxHeight>0)
	    {
		    if (img.height>maxHeight)
			    imageObject.style.height = maxHeight;
	    }
	}
}

/// <summary>
/// Check if validation is applied on the current page and if the page is valid
/// </summary>
function isPageValid()
{
	var v = true;
	//Call validation
	if (typeof(Page_ClientValidate) == 'function')
	{
		Page_ClientValidate()
	}
	//Check if the page is valid
	if (typeof(Page_IsValid)!='undefined')
	{
		if (Page_IsValid!=null)
			v = Page_IsValid;
	}
	return v;
}

/// <summary>
/// Disables functionality of all child elements in the specified object
/// </summary>
function DisableFunctions(objectID)
{
    var elementsToDisable = "'image','button','reset','submit','text','password','hidden','radio','checkbox','file','textarea','select-one','select-multiple'";
    var obj = gE(objectID);
    for (var i=0; i<obj.all.length; i++)
    {
        var itm = obj.all.item(i);
	    if (typeof(itm.href)!="undefined")
	    {
		    try { itm.href = "javascript:;"; }
		    catch (ex) {}
	    }
	    if (itm.type!="undefined" && itm.type!=null && itm.type!="" && elementsToDisable.indexOf(itm.type)!=-1)
	    {
	        try { itm.disabled = "disabled"; }
            catch (ex) {}
	    }
        try { itm.onclick = "return false;"; }
        catch (ex) {}
    }
}

/// <summary>
/// Resize the width of a control to its parent
/// </summary>
function ResizeControlToParent(elementId, resizeValue, valueIsPercentage)
{
	try
	{
		var elm = $get(elementId);
		if (elm!=null && elm.parentNode!=null)
		{
			if (valueIsPercentage)
				elm.style.width = (elm.parentNode.offsetWidth * resizeValue / 100);
			else
				elm.style.width = (elm.parentNode.offsetWidth + resizeValue);
		}
	}
	catch (e) {}
}
/// <summary>
/// Resize the width of a control to an other element
/// </summary>
function ResizeControlToElement(elementId, otherElementId, resizeValue, valueIsPercentage)
{
	try
	{
		var elm = $get(elementId);
		var otherElm = $get(otherElementId);
		if (elm!=null && otherElm!=null)
		{
			if (valueIsPercentage)
				elm.style.width = (otherElm.offsetWidth * resizeValue / 100);
			else
				elm.style.width = (otherElm.offsetWidth + resizeValue);
		}
	}
	catch (e) {}
}

/// <summary>
/// Resize the width of all elements with the specified element type in the array to the ratio
/// </summary>
function ResizeAllElements(elementTypesArray, ratio, onlyWidthsHigerThan)
{
	try
	{
		for (var typeNr=0; typeNr<elementTypesArray.length; typeNr++)
		{
			//Get all elements of the specific type
			var elements = document.getElementsByTagName(elementTypesArray[typeNr]);
			if (elements!=null)
			{
				for (var elmNr=0; elmNr<elements.length; elmNr++)
				{
					var elm = elements[elmNr];
					if (elm.width!=null && elm.width!='' && elm.width.indexOf('%')==-1)
					{
						//Width of the element must be higer than onlyWidthsHigerThan
						if ( (onlyWidthsHigerThan!=null && parseInt(elm.width)>onlyWidthsHigerThan) ||
							  onlyWidthsHigerThan==null )
							elm.width = (parseInt(elm.width) * ratio) + 'px';
					}
					else if (elm.style.width!=null && elm.style.width!='' && elm.style.width.indexOf('%')==-1)
					{
						//Width of the element must be higer than onlyWidthsHigerThan
						if ( (onlyWidthsHigerThan!=null && parseInt(elm.style.width)>onlyWidthsHigerThan) ||
							  onlyWidthsHigerThan==null )
							elm.style.width = (parseInt(elm.style.width) * ratio) + 'px';
					}
				}
			}
		}
	}
	catch (e) {}
}

/// <summary>
/// Fires the event of the specified element
/// </summary>
function FireElementEvent(element, eventName)
{
    try
    {
        //IE
        if(element.fireEvent)
        {
            element.fireEvent("on" + eventName);
        }
        //Gecko
        else if(document.createEvent)
        {
            var evt = document.createEvent("HTMLEvents");
            if(evt.initEvent)
            {
                evt.initEvent(eventName, true, true);
            }
            if(element.dispatchEvent)
            {
                element.dispatchEvent(evt);
            } 
        }
    }
    catch (e)
    {
    }
}

/// <summary>
/// Centers the specified element on the page
/// </summary>
function CenterElement(elementId)
{
    var e = $get(elementId);
    if (e != null)
    {
        var width = parseInt(document.documentElement.clientWidth);
        if (width == 0 || (document.body.clientWidth < width && document.body.clientWidth > 0))
            width = document.body.clientWidth;

        var height = parseInt(document.documentElement.clientHeight);
        if (height == 0 || (document.body.clientHeight < height && document.body.clientHeight > 0))
            height = document.body.clientHeight;

        var scrollTop = parseInt(document.documentElement.scrollTop);
        if (document.body.scrollTop > scrollTop)
            scrollTop = parseInt(document.body.scrollTop);

        var scrollLeft = parseInt(document.documentElement.scrollLeft);
        if (document.body.scrollLeft > scrollLeft)
            scrollLeft = parseInt(document.body.scrollLeft);

        var top = Math.round((parseInt(height) - parseInt(e.style.height)) / 2) + scrollTop - 80
        if (top < 0)
            e.style.top = 0 + 'px';
        else
            e.style.top = top + 'px';
        var left = Math.round((parseInt(width) - parseInt(e.style.width)) / 2) + scrollLeft;
        if (left < 0)
            e.style.left = 0 + 'px';
        else
            e.style.left = left + 'px';
    }
}

/// <summary>
/// Shows/hides all elements of the specified tag in the specified container
/// </summary>
function ShowHideElementsOfType(containerId, tagName, show)
{
    var elements = null;
    if (containerId == null)
        elements = document.getElementsByTagName(tagName);
    else
        document.getElementById(containerId).getElementsByTagName(tagName);

    var display = (show ? "visible" : "hidden");
    for (var i = 0; i < elements.length; i++)
        elements[i].style.visibility = display;
}

/// <summary>
/// Shows/hides all elements in the element array
/// </summary>
function ShowHideElements(showElements, elementIdArray)
{
    if (elementIdArray == null)
        return;
        
    for (var i = 0; i < elementIdArray.length; i++)
    {
        try
        {
            var element = $get(elementIdArray[i]);
            if (element != null)
                element.style.display = (showElements ? '' : 'none');
        }
        catch (e) { }
    }
}

/// <summary>
/// Gets the actual width and height of the client. Returns an Sys.UI.Bounds object
/// </summary>
function GetClientBounds()
{
    var clientWidth = 0;
    var clientHeight = 0;
    try
    {
        switch (Sys.Browser.agent)
        {
            case Sys.Browser.InternetExplorer:
                clientWidth = document.documentElement.clientWidth;
                clientHeight = document.documentElement.clientHeight;
                break;
            case Sys.Browser.Safari:
                clientWidth = window.innerWidth;
                clientHeight = window.innerHeight;
                break;
            case Sys.Browser.Opera:
                clientWidth = Math.min(window.innerWidth, document.body.clientWidth);
                clientHeight = Math.min(window.innerHeight, document.body.clientHeight);
                break;
            default:  // Sys.Browser.Firefox, etc.
                clientWidth = Math.min(window.innerWidth, document.documentElement.clientWidth);
                clientHeight = Math.min(window.innerHeight, document.documentElement.clientHeight);
                break;
        }
    }
    catch (e) { }
    return new Sys.UI.Bounds(0, 0, clientWidth, clientHeight);
}

/// <summary>
/// Disable error messages
/// </summary>
function errorHandler(sMsg, sUrl, sLine)
{
	return true; //don't display the rrror
}

var ExecutedPageLoadScripts = new Array();
function execPageLoadScript(scriptId, functionCall)
{
    if (!isItemInArray(ExecutedPageLoadScripts, scriptId))
    {
        ExecutedPageLoadScripts.push(scriptId);
        window.setTimeout(functionCall, 0);
    }
}

function isItemInArray(array, item)
{
    if (array != null)
    {
        for (var i = 0; i < array.length; i++)
        {
            if (array[i] == item)
                return true;
        }
    }

    return false;
}
//]]>
