function checkEmail(sEmail)
{
	var re_check_email = new RegExp("[A-Za-z0-9_]+([-+.][A-Za-z0-9_-]+)*@[A-Za-z0-9_]+([-.][A-Za-z0-9_]+)*\\.[A-Za-z0-9_]{2,}([-.][A-Za-z0-9_]+)*");
	var ares = re_check_email.exec(sEmail);
	var res = true;
	if( ares == null )
	{
		res = false;
	}

	return res;
}

function loadurl(dest, processFunc, method)
{
	var processFunc;
	var method;

	try
	{
		xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
	}catch(e){
	}

    if ( processFunc != undefined )
    {
		xmlhttp.onreadystatechange = processFunc;
    }
	else
	{
		xmlhttp.onreadystatechange = triggered;
	}
    if ( undefined == method )
    {
		method = "GET";
    }
	xmlhttp.open(method, dest);
	xmlhttp.send(null);
}

function loadurlpost(dest, processFunc, params)
{
	var processFunc;
	var params;

	try
	{
		xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
	}catch(e){
	}

	xmlhttp.open("POST", dest);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlhttp.onreadystatechange = processFunc;
	xmlhttp.send(params);
}

function triggered()
{
	// if the readyState code is 4 (Completed)
	// and http status is 200 (OK) we go ahead and get the responseText
	// other readyState codes:
	// 0=Uninitialised 1=Loading 2=Loaded 3=Interactive

	if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
		// xmlhttp.responseText object contains the response.
		document.getElementById("limits_table").innerHTML = xmlhttp.responseText;
	}
}

function signUpNewsletter(theForm)
{
	if ( !checkEmail(theForm.sign_up_email.value) )
	{
		alert("Please, enter the correct e-mail.");
		theForm.sign_up_email.focus();
	}
	else
	{
		loadurlpost('/main.php', processNewsletter, 'a=71&email=' + theForm.sign_up_email.value);
	}

	return false;
}

function processNewsletter()
{
	// if the readyState code is 4 (Completed)
	// and http status is 200 (OK) we go ahead and get the responseText
	// other readyState codes:
	// 0=Uninitialised 1=Loading 2=Loaded 3=Interactive
	if ((4 == xmlhttp.readyState) && (200 == xmlhttp.status))
	{
		// xmlhttp.responseText object contains the response.
		if ( parseInt(xmlhttp.responseText) == 0 )
		{
			var errorDiv = document.getElementById("error_message_div");
			errorDiv.innerHTML = "<font color=\"red\">The subscriber already exists.</font>";
		}
		else
		{
			var newsletterDiv = document.getElementById("newsletter_div");
			newsletterDiv.innerHTML = "Thank you!";
		}
	}
}