var siteDomainName = "hermitageadvisors.com";
var sMapQuestLink = "http://www.mapquest.com/directions/main.adp?2a=1750+Montgomery+St&2c=San%20Francisco&2s=CA&2z=94111&2y=US&cid=lfddlink";

function changeClassName(elem, className)
{
     var elem = document.getElementById(elem);
     elem.className = className;
}


function createEmailLink(sEmailName, sDomain, sSubject)
{
    if (!sDomain) sDomain = siteDomainName;
	var subject = (sSubject) ? "?subject=" + sSubject : "";
	var sEmailLink = "mailto:" + sEmailName + "@" + sDomain + subject;
    location.href = sEmailLink;
}

function openWindow(URLToOpen, windowName, windowWidth, windowHeight)
{
	var xPos = (screen.availWidth - windowWidth)/2;
	var yPos = (screen.availHeight - windowHeight)/2;
	var features = "height=" + windowHeight 
				 + ",width=" + windowWidth + ",top=" + yPos 
				 + ",left=" + xPos + ",scrollbars=yes,status=yes,location=yes,menubar=yes,resizable=yes,toolbar=yes";
	newWindow = window.open(URLToOpen, windowName);
	newWindow.focus();
}

function addEvent(oObjectRef, sEventType, fFunctionName)
{
	if (oObjectRef.addEventListener) { 
		oObjectRef.addEventListener(sEventType,fFunctionName,false); 
		return true; 
	} else if (oObjectRef.attachEvent) { 
		return oObjectRef.attachEvent("on"+sEventType,fFunctionName); 
	} else { return false; } 
}

function valContForm()
{
	var sMsg = "Validation Errors Occured:\n";
	var sPassVal = true;
	
	var sNameVal = document.getElementById('name').value;
	var sEmailVal = document.getElementById('email').value;
	var sMessageVal = document.getElementById('message').value;
	
	if (sNameVal == "") {
		sMsg += "- Please enter your name.\n";
		sPassVal = false;
	}
	
	if (sEmailVal == "") {
		sMsg += "- Please enter your email address.\n";
		sPassVal = false;
	}
	
	if (sMessageVal == "") {
		sMsg += "- Please enter your message.\n";
		sPassVal = false;
	}
	
	if (!sPassVal) {
		alert(sMsg);
		return false;
	}
	
	document.getElementById('contactForm').submit();
	return true;
}

function pginit()
{
	if (document.forms[0]) {
		document.forms[0].elements[0].focus();
	}
	
	if (document.getElementById('submitContForm')) {
		var oSubmit = document.getElementById('submitContForm');
		addEvent(oSubmit, 'click', valContForm);
	}
}

addEvent(window, "load", pginit);