	
	/*
	 * A simple utility function to confirm accessing a URL. It will display
	 * the given message in a alert box and proceed to the given URL if the
	 * user clicks OK.
	 */
	function confirmUrl(message, url)
	{
		if(confirm(message)) 
			location.href = url;
	}
	
	
	
	/**
	  * Selects the text in a textbox. Use such as:
	  * <input type="text" name="userId" maxlength="20" value="user name" onclick="removeText(this)"/>
	  */
	function selectText(element)
	{
		element.select();
	}
	
	
	
	/**
	  * Removes the text in a textbox. Use such as:
	  * <input type="text" name="userId" maxlength="20" value="user name" onclick="removeText(this)"/>
	  */
	function removeText(element)
	{
		element.value = "";
	}  
	
	
	
	/*
	 * Tries to copy the given string into the clipboard. If that fails, displays
	 * a dialog.
	 */	
	function copyToClipboard(content)
	{
		if(window.clipboardData && clipboardData.setData) {
			window.clipboardData.setData("Text", content);
		}
		else {
			prompt('Sorry, your browser does not support copying data to the clipboard. Please copy the text from here by hand.\nThen click any button.', content);
		}
	}



	/*
	 * Swaps the class of the element with the given id between 'visible' and
	 * 'invisible'
	 */
	function toggleVisibility(id)
	{
		element = document.getElementById(id);
		if(element != null) {
			if(element.className == "visible")
				element.className = "invisible";
			else
				element.className = "visible";
		}
	}

	

	/*
	 * Hides all <div> sections within the given parent element.
	 */	
	function hideDivChildren(parentId)
	{
		p = document.getElementById(parentId);
		children = p.getElementsByTagName('div');
		
		for(i=0; i<children.length; i++) {
			children[i].className = "invisible";
		}
	}
	
	
	
	/*
	 * Allows to register a function to execute once the page has loaded.
	 * http://simonwillison.net/2004/May/26/addLoadEvent/
	 */
	function addLoadEvent(func)
	{
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		}
		else {
			window.onload = function() {
				if (oldonload) {
		        	oldonload();
		      	}
		      	func();
		    }
	    }
	}
	
	
	
	
	function showTab(sTabsDivId, sTabContentsDivId, nTabIndex)
	{
		// Set all tabs to inactive
		div = document.getElementById(sTabsDivId);
		children = div.getElementsByTagName('span');
		for(i=0; i<children.length; i++) {
			children[i].className = "tab";
		}
		
		// Set new tab as active
		if(nTabIndex != null && nTabIndex != -1) {
			e = document.getElementById(sTabsDivId+"_"+nTabIndex);
			if(e != null)
				e.className = "tabActive";
		}
		
		
		// Set all tab contentss to invisible
		div = document.getElementById(sTabContentsDivId);
		children = div.getElementsByTagName('div');
		for(i=0; i<children.length; i++) {
			children[i].className = "invisible";
		}
		
		// Set new tab as active
		if(nTabIndex != null && nTabIndex != -1) {
			e = document.getElementById(sTabContentsDivId+"_"+nTabIndex);
			if(e != null)
				e.className = "visible";
		}
	}
	
	
	
	function submitForm(sFormId)
	{
		form = document.getElementById(sFormId);
		if(form != null) {
			form.submit();
		}
		else
			alert("Can't find form element with name ["+sFormId+"]");
	}
	
	
	
	function setFormActionAndSubmit(sFormId, sAction)
	{
		form = document.getElementById(sFormId);
		if(form != null) {
			form.action = sAction;
			form.submit();
		}
		else
			alert("Can't find form element with name ["+sFormId+"]");
	}
		
