// JavaScript Document

function follow_tweet(form) {
	var username = form.username.value;
	var password = form.passw.value;
	if (username != "" && password != "") {
		document.getElementById('follow_box').style.display = 'none';
		document.getElementById('loader_box').style.display = 'block';
		
		xmlHttp		= GetXmlHttpObject();
		if (xmlHttp == null) {
			alert ("Browser does not support HTTP Request");
			return;
		}
		
		var url		= "functions/subscribe_tweet.php";
		url		+= "?user=" + username;
		url		+= "&pass=" + password;
		url		+= "&sid=" + Math.random();
		
		xmlHttp.onreadystatechange	= tweetDone;
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);	
	}
}


//================================================================================
//							AJAX FUNCTIONS
//================================================================================

function GetXmlHttpObject() {
	var xmlHttp=null;
	try
	{
	// Firefox, Opera 8.0+, Safari
	xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		//Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function tweetDone() {
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		var response = xmlHttp.responseText;
		document.getElementById('loader_box').style.display = 'none';
		if (response == -1)
			document.getElementById('fail_box').style.display = 'block';		
		else
			document.getElementById('succes_box').style.display = 'block';
	} 
}