function addLoadListener(fn) {
	if (typeof window.addEventListener != 'undefined') {
		window.addEventListener('load', fn, false);
	} else if (typeof document.addEventListener != 'undefined')	{
		document.addEventListener('load', fn, false);
	} else if (typeof window.attachEvent != 'undefined') {
		window.attachEvent('onload', fn);
	} else {
		return false;
	}
	return true;
};

function attachEventListener(target, eventType, functionRef, capture) {
    if (typeof target.addEventListener != "undefined") {
        target.addEventListener(eventType, functionRef, capture);
    } else if (typeof target.attachEvent != "undefined") {
        target.attachEvent("on" + eventType, functionRef);
    } else {
        return false;
    }
    return true;
};

function emailvalidation(entered, alertbox)
	{
	with (entered)
	{
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		lastpos=value.length-1;
		if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) 
			{if (alertbox) {alert(alertbox);} return false;}
		else {return true;}
	}
}

function emptyvalidation(entered, alertbox)
	{
	with (entered)
	{
		if (value==null || value=="")
			{if (alertbox!="") {alert(alertbox);} return false;}
		else {return true;}
	}
}

function formvalidation(thisform)
	{
	with (thisform)
	{
		if (emptyvalidation(name,"Please enter your name")==false) {name.focus(); return false;};
		if (emailvalidation(email,"Please enter a valid email address")==false) {email.focus(); return false;};
		if (emptyvalidation(message,"Please provide the nature of your enquiry")==false) {message.focus(); return false;};	
	}
}

function clearField(thefield) {
	if (thefield.defaultValue==thefield.value)
	thefield.value = ""
} 

function clearInputs(){
	var input=document.getElementsByTagName('input');
	for(var i=0;i<input.length;i++){
		if(input[i].type=='text'){
			input[i].setAttribute('rel',input[i].defaultValue)
			input[i].onfocus=function(){
				if(this.value==this.getAttribute('rel')) { this.value=''; }
				else { return false; }
			}
			input[i].onblur=function(){
				if(this.value=='') { this.value=this.getAttribute('rel'); }
				else { return false;}
			}
			input[i].ondblclick=function() { this.value=this.getAttribute('rel') }
		}
	}
}

function buttons() {
    var inputs = document.getElementsByTagName("input");
    var i=0;
    for (i=0; i<inputs.length; i++) {
        if(inputs[i].getAttribute('type') == 'image') {
			var image = inputs[i];
            image.offImage = new Image();
            image.offImage.src = image.src;
            image.onImage = new Image();
            image.onImage.imageElement = image;
            if (navigator.userAgent.toLowerCase().indexOf('safari') != - 1) {
               image.onmouseover = function() { this.src = this.onImage.src; };
			   image.onfocus = function() { this.src = this.onImage.src; };
               image.onmouseout = function() { this.src = this.offImage.src; };
			   image.onblur = function() { this.src = this.offImage.src; };
            } else {
               image.onImage.onload = function() {
                  this.imageElement.onmouseover = function() { this.src = this.onImage.src; };
				  this.imageElement.onfocus = function() { this.src = this.onImage.src; };
                  this.imageElement.onmouseout = function() { this.src = this.offImage.src; };
				  this.imageElement.onblur = function() { this.src = this.offImage.src; };
               };
            }
            image.onImage.src = image.src.replace(/-off\./, '-on.');
        }
    }
}

clearInputs();
attachEventListener(window, "load", clearInputs, false);
buttons();
attachEventListener(window, "load", buttons, false);
