// Converts links with an attribute of rel="external" to target="_blank"
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
     anchor.target = "_blank";
     anchor.title = "This link will open in a new window.";
  }
 }
}

// Makes IE understand getElementsByClassName
onload=function() {
	if (document.getElementsByClassName == undefined) {
		document.getElementsByClassName = function(className)
		{
			var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");
			var allElements = document.getElementsByTagName("*");
			var results = [];
			var element;
			for (var i = 0; (element = allElements[i]) != null; i++) {
				var elementClass = element.className;
				if (elementClass && elementClass.indexOf(className) != -1 && hasClassName.test(elementClass))
					results.push(element);
			}
			return results;
		}
	}
	hideDetail();
	// as above
	externalLinks();
}

// Clears input values
function clearDefault(objInput,strDefaultText) {
	if (objInput.value==strDefaultText) objInput.value = '';
}
// Restores the default text, if the input box is empty
function restoreDefault(objInput,strDefaultText) {
	if (objInput.value=='') objInput.value = strDefaultText;
}

// This is used to post form variables to a popup
// Pop up script
function oWin(url,width,height,name) {
	if (typeof(name)=="undefined") name="w"+new Date().getTime();
	if ((typeof(window["win_"+name])=="object")&&!window["win_"+name].closed) {
		window["win_"+name].location = url;
	} else {
		window["win_"+name]=window.open(url,name,"location=0,status=0,resizable=1,menubar=0,directories=0,width="+width+",height="+height);
	}
	window["win_"+name].focus();
}

// Pop up with scroll
function oWinWithScroll(url,width,height,name) {
	if (typeof(name)=="undefined") name="w"+new Date().getTime();
	if ((typeof(window["win_"+name])=="object")&&!window["win_"+name].closed) {
		window["win_"+name].location = url;
	} else {
		window["win_"+name]=window.open(url,name,"scrollbars=1,location=0,status=0,resizable=1,menubar=0,directories=0,width="+width+",height="+height);
	}
	window["win_"+name].focus();
}

// Writes out a link to print this page, if the browser supports it.
function pageTools() {
	// If the browser understands any of this
    if (window.external || window.sidebar || window.print) document.write('<ul id="pagetools">');
    // Print
    if (window.print) document.write('<li id="printlink"><a href="#" onclick="window.print(); return false;" title="Print this page">Print this page</a></li>' );
    // IE Bookmark
    if (window.external && !window.sidebar)
    	document.write('<li id="favlink"><a href="#" onclick="window.external.AddFavorite(location.href, document.title);return false;" title="Bookmark this page">Bookmark this page</a></li>' );
    // Gekko bookmark
    if (window.sidebar) document.write('<li id="favlink"><a href="#" onclick="window.sidebar.addPanel(document.title, location.href, \'\');return false;">Bookmark this page</a></li>' );
    if (window.external || window.sidebar || window.print) document.write('</ul>');
}

// Hides all the definitions
function hideDetail() {
	if (document.getElementById('foldlist')) {
		// The containing list for the results
		var objSearchTerms = document.getElementById('foldlist');
		// An array of all the DIV elements inside this list
		var arrDivs = objSearchTerms.getElementsByTagName('DIV');
		// Hiding all these elements
		for (i=0; i < arrDivs.length; i++)
		{
			arrDivs[i].style.display = "none";
		}
		// An array of all the H3 elements inside this list
		var arrHead3 = objSearchTerms.getElementsByTagName('H3');
		// Making sure all the headings have the default background graphic
		for (i=0; i < arrHead3.length; i++)
		{
			arrHead3[i].style.background = "white url(/img/bg-searchterms-dt-js.png) top left no-repeat";
		}
		// An array of all elements which have the class "odd"
		var arrOddHead3 = document.getElementsByClassName('odd');
		// Making sure all the elements have the default background graphic
		for (i=0; i < arrOddHead3.length; i++)
		{
			arrOddHead3[i].style.background = "white url(/img/bg-searchterms-dt-js.png) top left no-repeat";
		}
		// An array of all elements which have the class "oddNoLink"
		var arrOddHead3 = document.getElementsByClassName('oddNoLink');
		// Making sure all the elements have the default background graphic
		for (i=0; i < arrOddHead3.length; i++)
		{
			arrOddHead3[i].style.background = "white url(/img/bg-searchterms-dt-odd.png) top left no-repeat";
		}
	}
}

// This shows the following sibling, and changes a background graphic.
function showDetail(objHeading) {
	// For browsers who believe in text nodes
	if(objHeading.nextSibling.nodeType==3) {
		objDiv = objHeading.nextSibling.nextSibling;
	}
	// For those who doubt their existance
	else {
		objDiv = objHeading.nextSibling;
	}
	// If the current definition is already showing, hide it
	if(objDiv.style.display == "block") {
		hideDetail();
	}
	// If the current definition is hidden, show it
	else {
		// Comment the following line out, to turb this from radio, to checkbox style
		hideDetail();
		// Shows the new definition
		objDiv.style.display = "block";
		// If this is an odd numbered heading
		if (objHeading.className == 'odd') {
			objHeading.style.background = "white url(/img/bg-searchterms-dt-expanded.png) top left no-repeat";
		}
		else {
			objHeading.style.background = "white url(/img/bg-searchterms-dt-expanded.png) top left no-repeat";
		}
	}
}

//make sure the http is removed from the mylink if it already exists
//this only works in IE
function checkMyLinkUrl(Id){
    //get the clipboard data
    if (window.clipboardData)
    {
        var text = window.clipboardData.getData("Text"); 
        if(text.indexOf("http") >= 0){
            document.getElementById(Id).value = "";
        }
    }    
}




// Hides all the definitions
function hideAll() {
	// The containing list for the results
	var objfoldlist = document.getElementById('foldlist');

	// An array of all the DIV elements inside this list
	var arrDefinitions = objfoldlist.getElementsByTagName('DIV');
	
	// An array of all elements which have the class "odd"
	var arrOddTerms = document.getElementsByClassName('odd');

	// Hiding all these elements
	for (i=0; i < arrDefinitions.length; i++)
	{
		arrDefinitions[i].style.display = "none";
	}
	// Making sure all the DTs have the default background graphic
	for (i=0; i < arrTerms.length; i++)
	{
		arrTerms[i].style.background = "url(/img/bg-searchterms-dt-odd-js.png) top left no-repeat";
	}
	// Making sure all the odd DTs have the odd background graphic
	for (i=0; i < arrOddTerms.length; i++)
	{
		arrOddTerms[i].style.background = "url(/img/bg-searchterms-dt-odd-js.png) top left no-repeat";
	}
}

// Hides juyst this definition
function hideThis(objDefTerm) {
	// For browsers who believe in text nodes
	if(objDefTerm.nodeType==3) {
		objDefinition = objDefTerm.nextSibling;
	}
	// For those who doubt their existance
	else {
		objDefinition = objDefTerm;
	}
	// Hiding all these elements
	objDefinition.style.display = "none";
}

// This shows the following sibling, and changes a background graphic.
function showDetail(objDefTerm) {
	// For browsers who believe in text nodes
	if(objDefTerm.nextSibling.nodeType==3) {
		objDefinition = objDefTerm.nextSibling.nextSibling;
	}
	// For those who doubt their existance
	else {
		objDefinition = objDefTerm.nextSibling;
	}
	// If the current definition is already showing, hide it
	if(objDefinition.style.display == "block") {
		hideThis(objDefinition);
		//hideAll();
	}
	// If the current definition is hidden, show it
	else {
		// Comment the following line out, to turn this from radio, to checkbox style
		//hideAll();
		// Shows the new definition
		objDefinition.style.display = "block";
		// If this is an odd numbered definition
		if (objDefTerm.className == 'odd') {
			objDefTerm.style.background = "url(/img/bg-searchterms-dt-expanded.png) top left no-repeat";
		}
		else {
			objDefTerm.style.background = "url(/img/bg-searchterms-dt-expanded.png) top left no-repeat";
		}
	}
}

function showDetailAll() {
    var zDD=document.getElementById('foldlist').getElementsByTagName('div');
    for(var i=0;i<zDD.length;i++){
	    zDD[i].style.display='block';
    }
	return false;
}

function hideDefAll() {
    var zDD=document.getElementById('foldlist').getElementsByTagName('div');
    for(var i=0;i<zDD.length;i++){
	   zDD[i].style.display='none';
    }
	return false;
}

function doHideShowAllCriteria(x){
    var zDD=document.getElementById('foldlist').getElementsByTagName('div');
    zDD[x].className=(zDD[x].style.display=='none')?'block':'none';
}

function hideShowAllCriteria(){
    if (document.getElementById && document.getElementsByTagName){ 
	    var zDD=document.getElementById('foldlist').getElementsByTagName('div');
	    var hideShowOn = document.getElementById('hideShowOn');
	    var hideShowOff = document.getElementById('hideShowOff'); 
		    if (hideShowOn && hideShowOff){
				hideShowOn.onclick = showDetailAll;
				hideShowOn.title = "Show all criteria";
				hideShowOn.href = "#";
			   	hideShowOff.onclick = hideDefAll; 
 			   	hideShowOff.title = "Hide all criteria";
				hideShowOff.href = "#";
			}
    }
}