
/*
 * 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);
	}
}



function hideDivChildren(parentId) {
	parent = document.getElementById(parentId);
	children = parent.getElementsByTagName('div');
	
	for(i=0; i<children.length; i++) {
		children[i].className = "invisible";
	}	
}


function toggleVisibility(id) {
	element = document.getElementById(id);
	if(element != null) {
		if(element.className == "visible")
			element.className = "invisible";
		else
			element.className = "visible";
	}
}



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+"]");
}