/* ------------------------------------------
Client: Natural England
Functions
Author: Reading Room (NG)
------------------------------------------ */

/* ------------------------------------------------
-- ADD LOAD EVENT
------------------------------------------------ */


function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}


/* ------------------------------------------------
-- RESET FORM FIELDS
------------------------------------------------ */

function resetFields() {
	var form = document.getElementById("search");
	var element = form.getElementsByTagName("input")[0];
	element.onfocus = function() {
		if (this.value == this.defaultValue) {
			this.value = "";
		}
	}

	element.onblur = function() {
		if (this.value == "") {
			this.value = this.defaultValue;
		}
	}
}

/* ------------------------------------------------
-- CLEAR SEARCH BOX
------------------------------------------------ */

function clearTextBox() {

    var searchformtext = document.forms.searchform.search;
    if (searchformtext.value == 'enter search terms') {
        searchformtext.value = '';
    }
}

/* ------------------------------------------------
-- EXPAND BODY AREA TO FULL WIDTH
------------------------------------------------ */

function expandBody() {

        // expand main content area if the right content area does not exist
    if (document.getElementById("terCont") == null)
    {
        if (document.body.className != "home")
            document.body.className = "detail - page";
    }
}

/* ------------------------------------------------
-- CHANGE ACTION URL IN REGION SELECTOR
------------------------------------------------ */

function changePath() {

    var regionform = document.forms.regionform;
    regionform.action = regionform.regions.options[regionform.regions.selectedIndex].value;
}

/* ------------------------------------------------
-- SUBMIT REGION SELECTOR
------------------------------------------------ */

function submitForm()
{
    var regionform = document.forms.regionform;
    if (regionform.regions.options[regionform.regions.selectedIndex].value != "")
    {
        regionform.submit();
    }
}

//addLoadEvent(resetFields);
addLoadEvent(expandBody);


