/*****************************************************
	Artcon - artcon.css
------------------------------------------------------
	Copyright (c) Artcon 2008+. All rights reserved.
	Created by Stewart Orr @ Qodo (www.qodo.co.uk)
*****************************************************/

function gID(id) {
	return document.getElementById(id);	
}

/*	clever function to add multiple "window.onloads" */
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

function isValidEmail(email) {
	var RegExp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/;
	return RegExp.test(email);
} 

function validateFooterContactForm() {
	if (gID('FooterContactForm')) {
		var errors = "";
		var Name = gID('Name');
		var Email = gID('Email');
		var Phone = gID('Phone');
		var Enquiry = gID('Enquiry');
		
		if (Name.value == "") {
			errors += "\n - Please enter your name.";
		}
		if (Email.value == "" || !isValidEmail(Email.value)) {
			errors += "\n - Please enter your email address.";
		}
		if (Phone.value == "") {
			errors += "\n - Please enter your phone number.";
		}
		if (Enquiry.value == "") {
			errors += "\n - Please enter your enquiry.";
		}
		
		if (errors!="") {
			alert("Errors:\n" + errors);
			return false;
		}
		
	}
}

function prepareFooterContactForm() {
	if (gID('FooterContactForm')) {
		gID('FooterContactForm').onsubmit = function() {
			return validateFooterContactForm();	
		}
		
	}
}

function prepareSearchBar() {
	if (gID("searchTerm")) {
		var searchTerm = gID("searchTerm");
		searchTerm.onclick = function() {
			if (this.value == "Enter search keywords") {
				this.value = "";
			}
		}
		searchTerm.onblur = function() {
			if (this.value == "") {
				this.value = "Enter search keywords";
			}
		}
	}
}

function ieFunctions() {
	var inputs = new Array("Name","Enquiry","Email","Phone","searchTerm");
	for (var i=0; i< inputs.length; i++) {
		 var sinput = document.getElementById(inputs[i]);
		 sinput.onfocus = function() {
			 this.className += " focus";
		 }
		 sinput.onblur = function() {
			 this.className = this.className.replace(" focus","");
		 }
		 
	}
	
	/*var tabs = gID("menu_ul");
	for (var i=0; i<tabs.childNodes.length; i++) {
		if (tabs.childNodes[i].tagName == "LI") {
			tabs.childNodes[i].onmouseover = function() {
				if (this.className.indexOf("current_page") > -1) {
					this.className = this.className.replace("current_page_item","current_page_item_hover");
					this.className = this.className.replace("current_page_parent","current_page_parent_hover");
				} else {
					this.className += " li_hover";
				}
			}
			tabs.childNodes[i].onmouseout = function() {
				if (this.className.indexOf("current_page") > -1) {
					this.className = this.className.replace("current_page_item_hover","current_page_item");
					this.className = this.className.replace("current_page_parent_hover","current_page_parent");
				} else {
					this.className = this.className.replace("li_hover","");
				}
			}
		}
	}*/
}

//****************************************************
addLoadEvent(prepareSearchBar);
addLoadEvent(prepareFooterContactForm);