function addLoadEvent(func){
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
	window.onload = func;
	}else{
		window.onload = function(){
		oldonload();
		func();
		}
	}
}

function resetFields(){
	var formname = document.getElementsByTagName("form")[0];
	for (var i=0;i<formname.elements.length;i++){
		var element = formname.elements[i];
		element.onfocus = function(){
			if(this.type == "text" || this.type == "textarea") {
			this.style.border ="#968557 1px solid";
			}
			if (this.type == "submit"){
			this.style.color="#7c755c";
			}
		}
		element.onblur = function(){
			if(this.type == "text" || this.type == "textarea") {
			this.style.border ="#9ebd3e 1px solid";
			}
			if (this.type == "submit"){
			this.style.color="#7aa633";
			}
		}
		element.onmouseover = function(){
			if (this.type == "submit"){
				this.style.color="#7c755c";
			}
		}
		element.onmouseout = function(){
			if (this.type == "submit"){
				this.style.color="#7aa633";
			}
		}
		if(element.type == "submit") continue;
		if (!element.defaultValue) continue;
		element.onfocus = function(){
			if (this.value == this.defaultValue){
				this.style.border ="#968557 1px solid";
			this.value = "";
			}
		}
		element.onblur = function(){
			if (this.value == ""){
				this.style.border ="#9ebd3e 1px solid";
			this.value = this.defaultValue;
			}
		}
	}	
	formname.onsubmit = function(){
	return validateForm(this);	
	}
}

function validateForm(form){
	for (var i=0;i<form.elements.length;i++){
		var element = form.elements[i];
		if (element.className.indexOf("required") != -1){
		if (!isFilled(element)){
		alert("Please fill in the "+element.name+" field");
		return false;
		}
		}
		if (element.className.indexOf("email") != -1){
		if (!isEmail(element)){
		alert("Please enter a valid email address");
		return false;
		}
		}
	}
}

function isFilled(field){
	if (field.value == "" || field.value == field.defaultValue){
	return false;
	}else{
		return true;
	}
}

function isEmail(field){
	if (field.value.indexOf("@")==-1 || field.value.indexOf(".")==-1){
	return false;
	}else{
		return true;
	}
}


function hideHcardInfo(){
	if (!document.getElementById || !document.getElementsByTagName || !document.getElementById("hcard")) return false;
	var hcard = document.getElementById("hcard");
	var links = hcard.getElementsByTagName("a");
	for (var i=0;i<links.length;i++){
		var linkClass = links[i].className;
		if (linkClass == "email" || linkClass == "url"){
		links[i].style.display = "none";
		}
	}
}

addLoadEvent(hideHcardInfo);
addLoadEvent(resetFields);

