<!--
//
// Use the following variable to specify the maximum 
// number of times the user can submit the form
//
var maxSubmits = 10

function popupform(myform, windowname)
{
	if (! window.focus)return true;
	window.open('', windowname, 'height=200,width=400,scrollbars=yes');
	myform.target=windowname;
	return true;
}

function validate_times(frm)
{
    //
    // Get the "TotalSubmissions" cookie
    //
    var totalSubmits = eval(GetCookie('TotalSubmissions'))
    //
    // If it hasn't been set, initialize it to 0
    //
    if (totalSubmits == null)
        totalSubmits = 0
    //
    // See if totalSubmits is greater than or equal to maxSubmits
    //
    if (totalSubmits >= maxSubmits)
    {
        //
        // If so, don't submit the form
        //
        alert("This form can't be submitted more than 3 times. Try again 3 hours later.")
        return false
    }
    else
    {
        //
        // Otherwise, increment and save the cookie and submit the form
        //
        totalSubmits = totalSubmits + 1
        BakeIt(totalSubmits, "TotalSubmissions")
		popupform(frm, "contact")
        return true
    }
}

//
// This function is for testing purposes only!
//
function ResetCounter()
{
    BakeIt(0, "TotalSubmissions")
}

function BakeIt(cookieData, cookieName) 
{
    //
    // Calculate the expiration date
    //
    var expires = new Date ();
    expires.setTime(expires.getTime() + 10000000); 
    //
    // Set the cookie
    //
    SetCookie(cookieName, cookieData, expires);
}

function SetCookie(cookieName, cookieData, expireDate) 
{
    document.cookie = cookieName + "=" + escape(cookieData) + "; expires=" + expireDate.toGMTString();
}    

function GetCookie(name) 
{
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
            return GetCookieVal (j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break; 
    }
    return null;
}

function GetCookieVal (offset) 
{
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
        endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}

