this.oXMLHTTPRequest = null;

function DGLG(sID, sLabel, sDish, sItems)
{
	if ("createEvent" in document)
	{
		var oGLGElement = document.getElementById('glgdish')
		if (!oGLGElement)
		{
			oGLGElement = document.createElement("GLGDish");
			oGLGElement.id = "glgdish";
		}
		oGLGElement.setAttribute("glglabel", sLabel);
		oGLGElement.setAttribute("glgdish", sDish);
		oGLGElement.setAttribute("glgitems", sItems);
		document.documentElement.appendChild(oGLGElement);

		var oDispEvent = document.createEvent("Events");
		oDispEvent.initEvent("GLGAddRecipeEvent", true, false);
		oGLGElement.dispatchEvent(oDispEvent);
	}
}

function SearchRecipe(sText)
{
	var iEnd = window.location.href.indexOf('?');
	if (iEnd < 0) iEnd = window.location.href.length;
	var sURI = window.location.href.substring(0, iEnd) + '?page=search&q=' + sText;
	window.location.href = sURI;
	document.getElementById('form_main').action = sURI;
	return true;
}

function DisplayRatingStars(iStars)
{
	document.getElementById('reciperating').setAttribute('rating', iStars);
}

function RateRecipe(iRecipeID, iStars)
{
	var iEnd = window.location.href.indexOf('?');
	if (iEnd < 0) iEnd = window.location.href.length;
	var sURI = window.location.href.substring(0, iEnd) + '?page=raterecipe&recipeid=' + iRecipeID + '&rating=' + iStars;

	var oXMLHTTP = new XMLHttpRequest();
	oXMLHTTP.open("GET",sURI,false);
	oXMLHTTP.send(null);
	window.location.href = window.location.href;
}

function TipAFriend()
{
	var sFrom, sTo, sSubject, sMessage;
	
	sFrom = document.getElementById('tipafriend_from').value;
	sTo = document.getElementById('tipafriend_to').value;
	sSubject = document.getElementById('tipafriend_subject').value;
	sMessage = document.getElementById('tipafriend_message').value;
	if (sMessage.length >= 1000) sMessage = sMessage.substr(0,1000);

	var iEnd = window.location.href.indexOf('?');
	if (iEnd < 0) iEnd = window.location.href.length;
	var sURI = window.location.href.substring(0, iEnd) + '?page=tippedafriend&tipafriend_from=' + encodeURIComponent(sFrom) + '&tipafriend_to=' + encodeURIComponent(sTo) + '&tipafriend_subject=' + encodeURIComponent(sSubject) + '&tipafriend_message=' + encodeURIComponent(sMessage);
	window.location.href = sURI;
}

function ReportJunk()
{
	var sFrom, sTo, sSubject, sMessage;
	
	sFrom = document.getElementById('reportjunk_from').value;
	sTo = "report@grocerylistgenerator.com";
	sSubject = document.getElementById('reportjunk_subject').value;
	sMessage = document.getElementById('reportjunk_message').value;
	if (sMessage.length >= 1000) sMessage = sMessage.substr(0,1000);

	var iEnd = window.location.href.indexOf('?');
	if (iEnd < 0) iEnd = window.location.href.length;
	var sURI = window.location.href.substring(0, iEnd) + '?page=reportedjunk&reportjunk_from=' + encodeURIComponent(sFrom) + '&reportjunk_to=' + encodeURIComponent(sTo) + '&reportjunk_subject=' + encodeURIComponent(sSubject) + '&reportjunk_message=' + encodeURIComponent(sMessage);
	window.location.href = sURI;
}

function CreateContact()
{
	var sFrom, sTo, sSubject, sMessage;
	
	sFrom = document.getElementById('contact_from').value;
	sTo = "info@grocerylistgenerator.com";
	sSubject = document.getElementById('contact_subject').value;
	sMessage = document.getElementById('contact_message').value;
	if (sMessage.length >= 1000) sMessage = sMessage.substr(0,1000);

	var iEnd = window.location.href.indexOf('?');
	if (iEnd < 0) iEnd = window.location.href.length;
	var sURI = window.location.href.substring(0, iEnd) + '?page=contacted&contact_from=' + encodeURIComponent(sFrom) + '&contact_to=' + encodeURIComponent(sTo) + '&contact_subject=' + encodeURIComponent(sSubject) + '&contact_message=' + encodeURIComponent(sMessage);
	window.location.href = sURI;
}

function DisplayRecipe(sID)
{
	var iEnd = window.location.href.indexOf('?');
	if (iEnd < 0) iEnd = window.location.href.length;
	var sURI = window.location.href.substring(0, iEnd) + '?page=details&recipeid=' + sID;
	window.location.href = sURI;
}

function showUser(str)
{ 
	this.oXMLHTTPRequest = GetXmlHTTPObject();
	if (this.oXMLHTTPRequest)
	{
		this.oXMLHTTPRequest.onreadystatechange = StateChanged;
		this.oXMLHTTPRequest.open("GET", sURL, true);
		this.oXMLHTTPRequest.send(null);
	}
}

function StateChanged() 
{ 
	if (this.oXMLHTTPRequest.readyState==4 || this.oXMLHTTPRequest.readyState=="complete")
	{
	}
}
function GetXmlHTTPObject()
{
	var oXMLHTTPRequest = null;
	if (window.XMLHttpRequest)
	{
		oXMLHTTPRequest = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		oXMLHTTPRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return oXMLHTTPRequest;
}