// JavaScript Document

addLoadEvent(externalLinks);

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";
    }
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

booGovernment = false;
booEconomic = false;
booSectors = false;
booPrivate = false;

function hideShowGovernment(object) {
	if (booGovernment == true ) {
		booGovernment = false;
		hide(object);
	} else {
		booGovernment = true;
		show(object);
	}
}

function hideShowEconomic(object) {
	if (booEconomic == true ) {
		booEconomic = false;
		hide(object);
	} else {
		booEconomic = true;
		show(object);
	}
}

function hideShowSectors(object) {
	if (booSectors == true ) {
		booSectors = false;
		hide(object);
	} else {
		booSectors = true;
		show(object);
	}
}

function hideShowPrivate(object) {
	if (booPrivate == true ) {
		booPrivate = false;
		hide(object);
	} else {
		booPrivate = true;
		show(object);
	}
}

function show(object) {
    if (document.layers && document.layers[object] != null) {
        document.layers[object].display = 'inline';
		}
    else if (document.all) {
        document.all[object].style.display = 'inline';
		}
		else if (document.getElementById) {
				document.getElementById(object).style.display = 'inline';
		}
}
function hide(object) {
    if (document.layers && document.layers[object] != null) {
        document.layers[object].display = 'none';
		}
    else if (document.all) {
        document.all[object].style.display = 'none';
		}
		else if (document.getElementById) {
				document.getElementById(object).style.display = 'none';
		}
}

function isReady(form) {
	if (isFilled(form.Name) === false) {
		alert("Please enter your name and try again.");
		form.Name.focus();
		return false;
	}
	if (isFilled(form.BusinessName) === false) {
		alert("Please enter the name of your business and try again.");
		form.BusinessName.focus();
		return false;
	}
	if (isFilled(form.BusinessType) === false) {
		alert("Please enter the type of your business and try again.");
		form.BusinessType.focus();
		return false;
	}
	if (isFilled(form.BusinessPostcode) === false) {
		alert("Please enter your business postcode and try again.");
		form.BusinessPostcode.focus();
		return false;
	}
	if (isFilled(form.ContactNumber) === false) {
		alert("Please enter a contact number and try again.");
		form.ContactNumber.focus();
		return false;
	}
	if (isFilled(form.email) === false) {
		alert("Please enter your email address and try again.");
		form.email.focus();
		return false;
	}
	if (isFilled(form.email) === true) {
		if (isemail(form.email) === false) {
			alert("Your email address appears to be incorrect. \n\Please check it and try again.");
			form.email.focus();
			return false;
		}
	}
}

// check for null and for empty
function isFilled(elm) {
	if (elm.value === "" || elm.value === null) {
		return false;
	}
	else {
		return true;
	}
}

// check for email addy: looking for [@] & [.]
function isemail(elm) {
	if (elm.value.indexOf("@") != "-1" && elm.value.indexOf(".") != "-1" && elm.value != " ") {
		return true;
	}
	else {
		return false;
	}
}