function validateFormElement(l,a,b) {
	var myErrorHolderDiv = document.getElementById("error-message");
	var myErrorHolder = document.getElementById("error-p");
	var myErrorMessageDiv = "error-message";

	myErrorHolder.style.display = "block";
	myErrorHolderDiv.style.left = l;
	myErrorHolderDiv.style.top = a;
	makeOpacityZero(myErrorMessageDiv);
	myErrorHolder.innerHTML = b;
	opacity(myErrorMessageDiv, 0, 100, 500);
}

function validateForm()
{
	var contactName = document.getElementById("name");
	var contactEmail = document.getElementById("email");
	var contactComments = document.getElementById("comments");
	
	if (contactName.value == "" || /^\s+$/.test(contactName.value))
		{
		validateFormElement("260px", "20px", "Name is Required");
		contactName.focus();
		return false;
		}

	if (contactEmail.value == "" || /^\s+$/.test(contactEmail.value))
		{
		validateFormElement("260px", "94px", "Email is Required");
		contactEmail.focus();
		return false;
		}

	if (!/^[\w\.\-]+@([\w\-]+\.)+[a-zA-Z]+$/.test(contactEmail.value))
		{
		validateFormElement("260px", "94px", "Email is Invalid");
		contactEmail.focus();
		return false;
		}

	if (contactComments.value == "" || /^\s+$/.test(contactComments.value))
		{
		validateFormElement("440px", "250px", "Comments Field is Required");
		contactComments.focus();
		return false;
		}

	return true;

}

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

	//determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(var i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
} 

function shiftOpacity(id, millisec) { 
    //if an element is invisible, make it visible, else make it ivisible 
    if(document.getElementById(id).style.opacity == 0) { 
        opacity(id, 0, 100, millisec); 
    } else { 
        opacity(id, 100, 0, millisec); 
    } 
}

function makeOpacityZero(id) {
	var thisZero = document.getElementById(id);
	thisZero.style.opacity = (0 / 100); 
	thisZero.style.MozOpacity = (0 / 100); 
	thisZero.style.KhtmlOpacity = (0 / 100); 
	thisZero.style.filter = "alpha(opacity=0)";
}
