var $toid;

function sendRequest(url,callback) {
	var postData;
	var req = createXMLHTTPObject();
	if (!req) return;
	var method = (postData) ? "POST" : "GET";
	req.open(method,url,true);
	req.setRequestHeader('User-Agent','XMLHTTP/1.0');
	if (postData) req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	req.onreadystatechange = function () {
		if (req.readyState != 4) return;
		if (req.status != 200 && req.status != 304) {
			//alert('HTTP error ' + req.status);
			return;
		}
		callback(req);
	}
	if (req.readyState == 4) return;
	req.send();
}

function createXMLHTTPObject() {
	var xmlhttp = false;

	try{
		xmlhttp = new XMLHttpRequest();
	} catch (e){
		try{
			xmlhttp = new ActiveXObject("Msxml3.XMLHTTP");
		} catch (e){
			try{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e){
				try{
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e){
					alert("Your browser doesn't support AJAX");
					return false;
				}
			}
		}
	}

	return xmlhttp;
}

function addmailing() {
	$varemail = 'mailinglist.php?e=' + (document.getElementById('mailingemail').value);
	sendRequest($varemail, returnemail);
}

function returnemail(req) {
	clearTimeout($toid);

	var notbox = document.getElementById('notif');

	nt = new Tween(notbox.style, 'top', Tween.easeInOut, -50, 0, 0.5, 'px');
	nt.start();

	notbox.innerHTML = req.responseText;

	$toid = setTimeout("hideNotif();",5000);
}

function hideNotif() {
	var notbox = document.getElementById('notif');

	nt = new Tween(notbox.style, 'top', Tween.easeInOut, 0, -50, 0.5, 'px');
	nt.start();
}
