var LoadContentService = new Object();
LoadContentService.xmlhttp = null
LoadContentService.baseUrl = "/WebServices/LoadContentService.aspx"
LoadContentService.callback = null



LoadContentService.loadXMLDoc = function(url)
{
	LoadContentService.xmlhttp=null
	
	if (LoadContentService.xmlhttp == null)
	{
		// code for Mozilla, etc.
		if (window.XMLHttpRequest)
		{
			LoadContentService.xmlhttp=new XMLHttpRequest()
		}
		// code for IE
		else if (window.ActiveXObject)
		{
			LoadContentService.xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
		}
	}
	
	if (LoadContentService.xmlhttp!=null)
	{
		LoadContentService.xmlhttp.onreadystatechange = LoadContentService.state_Change
		LoadContentService.xmlhttp.open("GET",url,true)
		LoadContentService.xmlhttp.send(null)
	}
	else
	{
		alert("Your browser does not support XMLHTTP.")
	}
}

LoadContentService.state_Change = function()
{
	if (!window.LoadContentService.xmlhttp)
	{
		//log("got to state_Change() with LoadContentService.xmlhttp undefined");
		return;
	}
	
	// if LoadContentService.xmlhttp shows "loaded"
	if (LoadContentService.xmlhttp.readyState==4)
	{
		// if "OK"
		if (LoadContentService.xmlhttp.status==200)
		{
			//log('done');
			//log('response:' + LoadContentService.xmlhttp.responseText);
			try
			{
				if (LoadContentService.xmlhttp 
					&& LoadContentService.xmlhttp.responseText 
					&& LoadContentService.xmlhttp.responseText != "")
				{
					// parsing XML sucks.  We'll go oldskool instead.
					var txt = LoadContentService.xmlhttp.responseText
					var splitter = txt.indexOf("|");
					if (splitter > 0 )
					{
						var id = txt.substr(0,splitter);
						var html = txt.substr(splitter+1);

						html = LoadContentService.FixRelativeLinks(html);
						
						if (document.getElementById(id))
						{
							document.getElementById(id).innerHTML = html;					
						}
					}
					if (LoadContentService.callback)
					{
						LoadContentService.callback();
					}
				}
			}
			catch(e)
			{
			}
		}
		else
		{
			alert("Pushing a new build.  Chill a second, then hit OK.")
		}
	}
	
}

LoadContentService.FixRelativeLinks = function(html)
{
	var reg = new RegExp(LoadContentService.baseUrl, "g");
	html = html.replace( reg, location.pathname, true);
	return html;
}

LoadContentService.Load = function(content, target, params, callback)
{
	var url = this.baseUrl 
			+ "?control=" + content
			+ "&target=" + target;
			
	if (params)
	{
		url = url + "&" + params;
	}	
	url = url + "&rand=" + Math.random();
	
	this.callback = callback;
	this.loadXMLDoc(url);		
	//window.open(url, "test");	
}


LoadContentService.LoadCity = function(cityID, target)
{
	// http://blogabond.dev/WebServices/LoadContentService.aspx?control=LocationDetail&target=divContent&locationID=100
	if (!target)
	{
		target = "divLocationContent";
	}
	
	this.Load("LocationDetail", target, "cityID=" + cityID);

}

LoadContentService.LoadCountry = function(countryCode, target)
{
	if (!target)
	{
		target = "divLocationContent";
	}
	this.Load("LocationDetail", target, "countryCode=" + countryCode);
}

LoadContentService.LoadComment = function(commentID, target)
{
	if (!target)
	{
		target = "divContentInner";
	}
	
	this.Load("Comment", target, "commentID=" + commentID);
}

LoadContentService.LoadUserContentByLocation = function(userID, locationID, target)
{
	if (!target)
	{
		target = "divContentInner";
	}
	
	this.Load("ContentByLocation", target, "userID=" + userID + "&locationID=" + locationID);
}

LoadContentService.LoadComplimentEdit = function(commentID, target, callback)
{
	if (!callback)
	{
		callback = Vote.onOpen;
	}
	this.Load("ComplimentBlock", target, "commentID=" + commentID + "&mode=Edit", callback);
}

LoadContentService.LoadComplimentScore = function(commentID, imageID, target, callback)
{
	if (!callback)
	{
		callback = Vote.onScoreLoad;
	}
	this.Load("ComplimentBlock", target, "commentID=" + commentID + "&imageID=" + imageID + "&mode=Score", callback);
}

LoadContentService.SendVote = function(commentID, imageID, voteTypeID, text, callback)
{
	var url = "/WebServices/VoteService.aspx?commentID=" + commentID
			+ "&imageID=" + imageID
			+ "&voteTypeID=" + voteTypeID
			+ "&commentText=" + text
			+ "&rand=" + Math.random();
	
	this.callback = callback;
	this.loadXMLDoc(url);		
	//window.open(url, "test");	
}


