var xmlHttp;

function getTheThingsChecked(option, startwith)
{ 
	if(option == "iwantlogin")
	{
		var usernameEntered = document.getElementById("txtLoginUsername").value;
		var passwordEntered = document.getElementById("txtLoginPassword").value;
		var optionto = document.getElementById("optionToGo").value;
		var taskto = document.getElementById("taskToGo").value;
		var idto = document.getElementById("idToGo").value;
		var keywordto = document.getElementById("keywordToGo").value;
	}
	if(option == 'com_category' || option == 'com_invite')
	{
		window.scrollTo(0,0);
	}
	xmlHttp=GetXmlHttpObject1()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	var url=startwith+"javascript/ajax/ajax.php"
	
	url=url+"?requestfor="+option
	if(option == "iwantlogin") url = url+"&uname="+usernameEntered+"&pass="+passwordEntered+"&optionto="+optionto+"&taskto="+taskto+"&idto="+idto+"&keyword="+keywordto;
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		var response = xmlHttp.responseText;
		if(response != "formsubmit")
		{
			document.getElementById("trForLoginMessage").style.display = "";
			document.getElementById("spanMessage").innerHTML = response;
			document.getElementById("focusOnMe").focus();
			window.scrollTo(0,0);
		}
		else
		{
			document.frmLogin.submit();
		}
	}
} 
 function getTheUsernameChecked(startwith, username, email)
{ 
	xmlHttp=GetXmlHttpObject1()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	var url=startwith+"javascript/ajax/ajaxRegister.php"
	url=url+"?username="+username+"&email="+email
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChangedforUsername 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function stateChangedforUsername() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		var response = xmlHttp.responseText;
		switch(response)
		{
			case "1" :
				document.frmRegister.submit();
				break;
			case "2":
				document.getElementById("trForUsernameError").style.display = "";
				document.getElementById("spanMessageAreaForUsername").innerHTML = "This E-Mail is already registered with us.";
				return false;
				break;
			default:
				document.getElementById("trForUsernameError").style.display = "";
				document.getElementById("txtUsernameRegister").focus();
				document.getElementById("spanMessageAreaForUsername").innerHTML = response;
				return false;
				break;
		}
	}
} 

function getTheTabsChanged(startwith, request, id, pageNo)
{ 
	xmlHttp=GetXmlHttpObject1()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	if(pageNo == "" || pageNo == "undefined") pageNo = 1;
	var url=startwith+"javascript/ajax/ajaxtabs.php"
	url=url+"?request="+request+"&id="+id+"&pageNo="+pageNo
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChangedforTabs 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function stateChangedforTabs() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		var response = xmlHttp.responseText;
		var parts = response.split("%~~~~~~~%");
		var idActive = parts[2].replace(" ","");
		if(idActive.search(/punches/i) != -1) idActive = "punches";
		else if(idActive.search(/recent/i) != -1) idActive = "recent";
		else if(idActive.search(/comments/i) != -1) idActive = "comments";
		else if(idActive.search(/read/i) != -1) idActive = "read";
		switch(idActive)
		{
			case "recent":
				document.getElementById("recent").style.backgroundImage = 'url('+parts[1]+'bg_activebutton.gif)';
				document.getElementById("read").style.backgroundImage = 'url('+parts[1]+'bg_inactivebutton.gif)';
				document.getElementById("punches").style.backgroundImage = 'url('+parts[1]+'bg_inactivebutton.gif)';
				document.getElementById("comments").style.backgroundImage = 'url('+parts[1]+'bg_inactivebutton.gif)';
				break;
			case "read":
				document.getElementById("recent").style.backgroundImage = 'url('+parts[1]+'bg_inactivebutton.gif)';
				document.getElementById("read").style.backgroundImage = 'url('+parts[1]+'bg_activebutton.gif)';
				document.getElementById("punches").style.backgroundImage = 'url('+parts[1]+'bg_inactivebutton.gif)';
				document.getElementById("comments").style.backgroundImage = 'url('+parts[1]+'bg_inactivebutton.gif)';
				break;
			case "punches":
				document.getElementById("recent").style.backgroundImage = 'url('+parts[1]+'bg_inactivebutton.gif)';
				document.getElementById("read").style.backgroundImage = 'url('+parts[1]+'bg_inactivebutton.gif)';
				document.getElementById("punches").style.backgroundImage = 'url('+parts[1]+'bg_activebutton.gif)';
				document.getElementById("comments").style.backgroundImage = 'url('+parts[1]+'bg_inactivebutton.gif)';
				break;
			case "comments":
				document.getElementById("recent").style.backgroundImage = 'url('+parts[1]+'bg_inactivebutton.gif)';
				document.getElementById("read").style.backgroundImage = 'url('+parts[1]+'bg_inactivebutton.gif)';
				document.getElementById("punches").style.backgroundImage = 'url('+parts[1]+'bg_inactivebutton.gif)';
				document.getElementById("comments").style.backgroundImage = 'url('+parts[1]+'bg_activebutton.gif)';
				break;
			default :
				document.getElementById("recent").style.backgroundImage = 'url('+parts[1]+'bg_activebutton.gif)';
				document.getElementById("read").style.backgroundImage = 'url('+parts[1]+'bg_inactivebutton.gif)';
				document.getElementById("punches").style.backgroundImage = 'url('+parts[1]+'bg_inactivebutton.gif)';
				document.getElementById("comments").style.backgroundImage = 'url('+parts[1]+'bg_inactivebutton.gif)';
				break;
		}
		document.getElementById("spanForRagesDisplay").innerHTML = parts[0];
	}
} 

function GetXmlHttpObject1()
{ 
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}