var xmlHttp

function suggestContent(getSuggestedContent,category){	

	getSuggestedContent = getSuggestedContent.replace("&","[and]");
	
	xmlHttp = GetXMLHttpObject()	
	
	if (xmlHttp==null){
		alert ("Browser doesn't support HTTP request")
		return
	}
	
	var url = "registeredUser/suggestContent.php?category="+ category +"&suggestedContentName=" + getSuggestedContent;
	
	xmlHttp.onreadystatechange=stateChanged
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)			
}

function sendQuestionFAQ(getQuestion){	

	xmlHttp = GetXMLHttpObject()	
	
	if (xmlHttp==null){
		alert ("Browser doesn't support HTTP request")
		return
	}
	
	var url = "registeredUser/sendQuestionFaq.php?question=" + getQuestion;
	
	xmlHttp.onreadystatechange=stateChanged
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)			
}

function addComment(getComment,category,id){	

	xmlHttp = GetXMLHttpObject()	
	
	if (xmlHttp==null){
		alert ("Browser doesn't support HTTP request")
		return
	}
	
	var url = "registeredUser/commentContent.php?comment="+getComment+"&category="+ category +"&id=" + id;
	
	xmlHttp.onreadystatechange=stateChangedComment
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)			
}

function stateChanged(){

	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById("suggestAjaxOutput").innerHTML = xmlHttp.responseText	
	}
	
	//the 2 lines of code below is used to disable the save button for 5 seconds. This is done to make sure the user doesn't accidentally click the save button twice
	//document.getElementById("save").disabled = true;	
	//setTimeout("document.getElementById('save').disabled = false",5000);
	
}

function stateChangedComment(){

	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById("commentRecipeOutput").innerHTML = xmlHttp.responseText	
	}
	
	//the 2 lines of code below is used to disable the save button for 5 seconds. This is done to make sure the user doesn't accidentally click the save button twice
	//document.getElementById("save").disabled = true;	
	//setTimeout("document.getElementById('save').disabled = false",5000);
	
}

function GetXMLHttpObject(){
	var xmlHttp = null;
	try{
		//firefox,opera,safari
		xmlHttp = new  XMLHttpRequest();
	}catch (e){
		//internet explorer
		try{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e){
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}	

function submitBlog(blogTitle,blogURL,blogDescription,blogTrymasakLink){	

	xmlHttp = GetXMLHttpObject()	
	
	if (xmlHttp==null){
		alert ("Browser doesn't support HTTP request")
		return
	}
	
	var url = "registeredUser/submit-blog-processs.php?title="+ blogTitle +"&URL=" + blogURL + "&description="+blogDescription + "&trymasakLink=" + blogTrymasakLink;
	
	xmlHttp.onreadystatechange=submitBlogDone
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)			
}

function submitBlogDone(){

	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById("submitBlogStatus").innerHTML = xmlHttp.responseText	
	}
	
}