﻿var _prefix = "ctl00_PageContent_";

window.onload = function()
{
    var message = document.getElementById(_prefix + "Message");
    if( message )
        window.location = "#" + _prefix + "Message";
}

function validatePost()
{
    var name = document.getElementById(_prefix + "NameTextBox").value;
    var link = document.getElementById(_prefix + "LinkTextBox").value;
    var comment = document.getElementById(_prefix + "CommentTextBox").value;
    return checkInput(name, link, comment);
}

function checkInput(name, link, comment)
{
	if( name.length == 0 )
		alert("You must enter a name.");
	else if( name.length > 50 )
		alert("Your name is too long");
	else if( comment.length == 0 )
		alert("You must enter a comment.");
	else if( link.length != 0 )
	{
		var re = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/i;
		if( !(re.test(link) || (link.substring(0,7).toLowerCase() == "http://" && link.length > 7)) )
			alert("You must provide either a valid e-mail address or a link starting with http://");
		else
			return true;
	}
	else
		return true;
	
	return false;
}
