// DON'T CHANGE THIS script...it is used across multiple service user interfaces!
// This script is from http://serviceportal.wamnet.com/scripts/formTips.js
// Ident: $Id: formTips.js 48156 2009-02-25 18:54:43Z rabrahamson $

function replaceRule(objStyle, className) {
	try {
		if (objStyle.cssRules) {
			var r = objStyle.cssRules;
		} else {
			var r = objStyle.rules;
		}

		for ( var i = 0; i < r.length; i++ ) {
			if( r[i].selectorText == className || r[i].selectorText == '*' + className) {
				try {
					r[i].style.display = (r[i].style.display == 'none') ? 'table-cell' : 'none';
				} catch (e) {
					// IE Windows doesn't do table-cell!
					r[i].style.display = (r[i].style.display == 'none') ? 'block' : 'none';
				}
				return(true);
			}
		}
	} catch (e) {
		return(false);
	}
}

function toggleTips() {
	try {
		cssSwitch = replaceRule(document.styleSheets[1], '.tips');
		//Use cssSwitch to detect an error in changing the display property and so default to show tips
		if(document.getElementById('tipsOff').style.display=="none" || !cssSwitch) {
			document.getElementById('tipsOff').style.display="inline";
			document.getElementById('tipsOn').style.display="none";
		} else {
			document.getElementById('tipsOff').style.display="none";
			document.getElementById('tipsOn').style.display="inline";
		}
	} catch (e) {
	}
}

// name: writeTips
// desc: dumps h3 with show/hide tips. These are automatically hidden
// depending on the current display style inside the toggleTips function
// args: tips - text (localized) for 'Tips', show - text for 'Show',
// hide - text for 'Hide'
function writeTips(tips, show, hide) {
	var txt_tips = "Tips";
	var txt_show = "Show";
	var txt_hide = "Hide";

	// if strings have been passed use them
	// otherwise use default english, embedded ones.
	if (typeof(tips) != "undefined") 
		txt_tips = tips;

	if (typeof(show) != "undefined") 
		txt_show = show;

	if (typeof(hide) != "undefined") 
		txt_hide = hide;


	document.write('<h3>&nbsp;'); // Force formatting of element to display even if next document.write isn't successful
	try {
		if(document.styleSheets) {
			// Only display switch if browser can handle it!
			document.write('<a class="bold toggle" href="JavaScript:toggleTips();" tabindex="2"><span id="tipsOff">' + txt_hide + '<\/span><span style="display: none;">\/<\/span><span id="tipsOn">' + txt_show + '<\/span> ' + txt_tips + '<\/a>');
		}
	} catch (e) {
		document.write(txt_tips);
	}
	document.write('<\/h3>'); 
}
