// browser
	var browser = navigator.appName;
	var browserVersion = parseFloat(navigator.appVersion);

// $(prototype)
function $() {
  	var elements = new Array();
  	for (var i = 0; i < arguments.length; i++) {
    	var element = arguments[i];
    	if (typeof element == 'string') {
      		element = document.getElementById(element);
		}
    	if (arguments.length == 1) {
      		return element;
    		elements.push(element);
		}
  	}
  	return elements;
}

// init
window.onload = function() {
	setFooter(); 
}

window.onresize = function() {
	setFooter();
}

// menu
function focusMenu(id) {
	$(id).style.background = "#3C3C3C";		
}

function blurMenu(id) {
	$(id).style.background = "#171717";	
}

function focusSubMenu(id) {
	$(id).style.background = "#313131";		
}

function blurSubMenu(id) {
	$(id).style.background = "#030507";	
}

function goToLink(id)  {	
	document.location.href = $(id).href;	
}

// div functions
function clearMsg(id) {
	$(id).innerHTML = "";
}

function inputFocus(id) {
	$(id).style.background = "#FFFFD2";	
}

function inputBlur(id) {
	$(id).style.background = "#FAFAFA";	
}

function hideDiv(id) {
	$(id).style.display = "none";
}

function showDiv(id) {
	$(id).style.display = "block";
}

function showHide(id) {
	if ($(id).style.display != 'none') {
		hideDiv(id);	
	} else {
		showDiv(id);
	}
}

// forms
function submitForm(id) { 
	$(id).submit();
}

// open fullscreen
function fullScreen(url) {
	window.open(url, '_blank', 'scrollbars=auto, toolbar=0, status=0, location=0, menubar=0, directories=0, resizable=1, titlebar=0', false);
}

// cookies
function createCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days*24*60*60*1000));
		var expires = "; expires=" + date.toGMTString();
	}
	else var expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
	var cName = name + "=";
	var cAttributes = document.cookie.split(';');
	for (var i=0; i < cAttributes.length; i++) {
		var c = cAttributes[i];
		while (c.charAt(0)==' ') c = c.substring(1, c.length);
		if (c.indexOf(cName) == 0) return c.substring(cName.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

// positions 
function findPosY(obj) {
	var posTop = 0;
	while (obj.offsetParent) {
			posTop += obj.offsetTop; 
			obj = obj.offsetParent;
	}
	return posTop;
}

function findPosX(obj) {
	var posLeft = 0;
	while (obj.offsetParent) {
			posLeft += obj.offsetLeft; 
			obj = obj.offsetParent;
	}
	return posLeft;
}

// footer
function setFooter() {
	var windowHeight = document.documentElement.clientHeight;
	var footerElement = $('Footer');	
	var footerPosition = findPosY(footerElement);
	
	if (windowHeight - footerPosition >= 0) {
		var newFooterHeight = (windowHeight - footerPosition);
		footerElement.style.height = (newFooterHeight + 'px');
	}
}


function validateForm() {
	 var okSoFar=true
	 with ($('phpformmailer'))
	 {
	  var foundAt = email.value.indexOf("@",0)
	  if (foundAt < 1 && okSoFar)
	  {
		okSoFar = false
		alert ("Please enter a valid email address")
		email.focus()
	  }
	  var e1 = email.value
	  var e2 = email2.value
	  if (!(e1==e2) && okSoFar)
	  {
		okSoFar = false
		alert ("Email addresses you entered do not match.  Please re-enter.")
		email.focus()
	  }
	  if (thesubject.value=="" && okSoFar)
	  {
		okSoFar=false
		alert("Please enter the subject.")
		thesubject.focus()
	  }
	  if (themessage.value=="" && okSoFar)
	  {
		okSoFar=false
		alert("Please enter the details for your enquiry.")
		themessage.focus()
	  }
	  if (okSoFar==true)  submitForm('phpformmailer');
	 }
}

