function switchCheckbox(x, id, v) {
	try {
		for (var i = 1; i <= x; i++) {
			document.forms[0].elements[id+i].checked = v;
		}
	} catch (e) {
	}
}

function confirmAction(message) {
	try {
		if (confirm(message)) {
			return true;
		}
		return false;
	} catch (e) {
	}
}

function replaceBlock(objStyle, className) {
	//Can't use this for showing/hiding iframe content as IE Mac can't handle it properly
	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') ? 'block' : '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 toggleView(className,replaceType) {
	try {
		if(replaceType=="row") {
			cssSwitch = replaceRows(document.styleSheets[2], '.' + className);
		} else if(replaceType=="cell") {
			cssSwitch = replaceCells(document.styleSheets[2], '.' + className);
		} else if(replaceType=="block") {
			cssSwitch = replaceBlock(document.styleSheets[2], '.' + className);
		}
		
		//Nudge window to force browser to re-render. Using resizeBy is buggy in some browsers - the window origin can be reset too!
		window.scrollBy(0,1);
		window.scrollBy(0,-1);
		
		//Use cssSwitch to detect an error in changing the display property and so default to show item
		if(document.getElementById(className + 'Off').style.display=="none" || !cssSwitch) {
			document.getElementById(className + 'Off').style.display="inline";
			document.getElementById(className + 'On').style.display="none";
		} else {
			document.getElementById(className + 'Off').style.display="none";
			document.getElementById(className + 'On').style.display="inline";
		}
	} catch (e) {
	}
}

function fixCaption() {
	//the combination of the toggleView function and the setActiveStyleSheet function in styleSwitcher.js
	//causes Firefox to stop cascading the font size of a table element into the table's caption element.
	//This function fixes the caption font size to 70% (roughly equal to .8 x .87 which are the sizes in text and caption rules)
	if ((navigator.userAgent.indexOf("Firefox")!=-1) && (navigator.userAgent.indexOf("Firefox/3")==-1)) {
		try {
			document.getElementById('cap').style.fontSize="70%";
		} catch (e) {
		}
	}
}

function autoLoadLink(linkID,newWindow) {
	try {
		if (typeof newWindow == "undefined") {
			newWindow = 1;
		}

		//what is the url of the linkID?
		linkURL = document.getElementById(linkID).href;
		//does it contain a named anchor?
		anchorLoc = linkURL.lastIndexOf("#");
		if (anchorLoc > -1) {
			//strip out the named anchor
			linkURL = linkURL.substring(0,anchorLoc);
		}
		
		//what is my url?
		pageURL = new String(window.location);
		//does it contain a named anchor?
		anchorLoc = pageURL.lastIndexOf("#");
		if (anchorLoc > -1) {
			//extract the named anchor
			linkAnchor = pageURL.substr(anchorLoc);
		} else {
			linkAnchor = ""
		}
		
		//append the page named anchor to the link
		linkURL += linkAnchor;
		
		//open link
		if (newWindow) {
			var doc = window.open(linkURL, 'ViewLink', 'resizable,scrollbars,status');
			doc.focus();
		} else {
			window.location = linkURL;
		}
	} catch (e) {
		return(false);
	}
}

