/*

Written by Simon Willison:
http://simon.incutio.com/archive/2004/05/26/addLoadEvent

Queue up a whole series of events to be triggered when the document loads. If you simply use window.onload = func, then you run the risk of overwriting existing functions that are supposed to run when the onload event is triggered.

*/

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}


/*

This function loops through all the text inputs on a page and stores their default values.
When a text input is brought into focus, its current value is checked against its default value.
If they are the same, the value is cleared.

This allows you to add placeholder text to inputs (recommended for accessibility) but users don't have to manually delete the placeholder text.

This function is triggered when the page loads.
The addLoadEvent.js file is required for this.

*/



addLoadEvent(clearInputs);

function clearInputs() {
	if (!document.getElementsByTagName) return false;
	var all_inputs = document.getElementsByTagName('input');
	for (var i=0;i<all_inputs.length;i++) {
		var current_input = all_inputs[i];
		if (current_input.getAttribute('type') == 'text' && current_input.getAttribute('value') != '') {
			current_input.default_text = current_input.getAttribute('value');
			current_input.onfocus = function() {
				if (this.getAttribute('value') == this.default_text) {
					this.setAttribute('value','');
				}
			}
		}
	}
}


/*

The following script enables :hover behaviour on form buttons in IE

*/


startHover = function() {
if (document.all&&document.getElementById) {

buttonRoot = document.getElementsByTagName("INPUT");
for(i=0;i<buttonRoot.length;i++){
	if(buttonRoot[i].className == 'button' || buttonRoot[i].className == 'searchSubmit'){
		buttonRoot[i].onmouseover=function() {
			this.className+=" over";
		}
		buttonRoot[i].onmouseout=function() {
			this.className=this.className.replace(" over", "");
		}	
		buttonRoot[i].onfocus=function() {
			this.className+=" over";
		}
		buttonRoot[i].onblur=function() {
			this.className=this.className.replace(" over", "");
		}			
	}
}

 }

}




/*

The following script counts how many inlineHelp divs there are on the FAQ pages and then hides them.

*/

countHelpItems = function()  {
	var countHelp = 0;

	pRoot = document.getElementsByTagName("div");

	for(i=0;i<pRoot.length;i++)	{

 		if(pRoot[i].className == 'inlinehelp')  {

 	 	countHelp = countHelp + 1;

	 	var IDtoHide = "help" + countHelp;

	 	var IDLinktoHide = "linkhelp" + countHelp;

    	document.getElementById(IDtoHide).style.display = "none";

	  	document.getElementById(IDLinktoHide).className = "helpLink";

		}
	}
}








/*

The following script counts enables show hide functionality of the inline help divs on the FAQ pages.

*/

function showHideHelp (div)  {

	var IDtoChange = "help" + div;

	var IDLinktoChange = "linkhelp" + div;      

	var elem = document.getElementById(IDtoChange); 

	var currentStatus = elem.style.display; 

	if (currentStatus == 'none' || currentStatus == '')  {

		elem.style.display = 'block';

		document.getElementById(IDLinktoChange).className = "helpLink downArrow"                 

   } 

	else 	{

		elem.style.display = 'none';

		document.getElementById(IDLinktoChange).className = "helpLink"

	}
}

//PM: Adding in for Active Comms 13 Jan

function hidePostalDetails() {
	if (!document.getElementById) return false;
	
	document.getElementById('postaldetails').className = 'hide';
}


function showPostalDetailsListener() {
	if (!document.getElementById) return false;
		
	document.getElementById('confirmpublications').onclick = function() {
		
		switch(document.getElementById('postaldetails').className) {
			case 'hide':
				document.getElementById('postaldetails').className = 'col-one';
			break;
			
			default:
				document.getElementById('postaldetails').className = 'hide';
		}
	}
}

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
}

function disableDropdown() {
	if (getQueryVariable('simpleOrAdvanced') != 'simple')
	{
		with (window.document.advancedSearch)
		{
			fromDay.disabled=true;
			fromMonth.disabled=true;
			fromYear.disabled=true;
			toDay.disabled=true;
			toMonth.disabled=true;
			toYear.disabled=true;
		}
	}
}



/* external links handling for xhtml 1.0 strict compliance */

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";
 }
}



addLoadEvent(externalLinks);

var docDomainSitestat = document.domain;



