function initPage()
{
	var inputs = document.getElementsByTagName("input");
	for (var i=0; i<inputs.length; i++)
	{
		if (inputs[i].type == "text" && (inputs[i].name == "email"))
		{
			var form = getAncestor(inputs[i], "form");
			if (form)
				form.onsubmit = handleSubmit;

			inputs[i].onfocus = function () {
					if (this.value == "Enter Email Address")
						this.value = "";
				}
			inputs[i].onblur = function () {
					if (this.value == "" && this.name == "email") this.value = "Enter Email Address";
				}
		}
	}
}

function handleSubmit()
{
	var re = new RegExp('^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$');
	var element = this.elements["email"];
	if (element)
	{
		if (element.value == "")
		{
			alert("Email address is empty!");
			return false;
		}
		else
			return element.value.match(re)
				|| (alert("You have entered incorrect email address!"), false);
	}
	return true;
}

function getAncestor(element, tagName)
{
	var node = element;
	while (node.parentNode && (!node.tagName ||
			(node.tagName.toUpperCase() != tagName.toUpperCase())))
		node = node.parentNode;
	return node;
}

function bookmarksite(title, url){
    if (document.all)
        window.external.AddFavorite(url, title);
    else
        if (window.sidebar)
            window.sidebar.addPanel(title, url, "")
        else
            alert("Please press CTRL+D to bookmark this site");
}

function testimonials(classname,showtotal,arrayName,arrayName2){
    var y;
    var uniqueArr = new Array();
    var uniqueArrNames = new Array();
    if(showtotal > arrayName.length)
        showtotal = arrayName.length;
    
    for(var i=0; i < showtotal; i ++){
        y = Math.ceil(Math.random()*arrayName.length);
        uniqueArr[i] = arrayName[y-1];
        arrayName.splice(y-1,1);
        uniqueArrNames[i] = arrayName2[y-1];
        arrayName2.splice(y-1,1);
    }
    
    for(var i = 0; i < showtotal; i++) {
        document.write("<p>" + uniqueArr[i] + "</p>");
        document.write("<p class='sign'>" + uniqueArrNames[i] + "</p>");
    }
}

if (window.addEventListener)
	window.addEventListener("load", initPage, false);
else if (window.attachEvent){
	window.attachEvent("onload", initPage);
	}
