var LoadContentService = new Object();
LoadContentService.xmlhttp = null
LoadContentService.baseUrl = "/WebServices/LoadContentService.aspx"
LoadContentService.callback = null

// TODO - queue

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);		
}

LoadContentService.ExecuteWebServiceRequest = function(url, callback)
{
	this.callback = callback;
	this.loadXMLDoc(url);		
}


LoadContentService.LoadMedia = function(callback)
{
	// http://blogabond.dev/WebServices/LoadContentService.aspx?control=LocationDetail&target=divContent&locationID=100
	//this.Load("MediaToolPalette", "divMediaPalette", null, callback);
	this.Load("MediaToolPalette", "divMediaPalleteScroll", null, callback);

}

LoadContentService.LoadSnapShot = function(callback, actionID)
{
	// http://dev.twiddla/WebServices/LoadContentService.aspx?control=SnapShotActions&target=divActions&actionID=24881
	this.Load("SnapShotActions", "divActions", "actionID=" + actionID, callback);

}

LoadContentService.CopyMedia = function(callback, fromUserID, src)
{
	var url = format("/WebServices/CopyMediaService.aspx")
			+ "?userid=" + fromUserID
			+ "&src=" + src
			+ "&rand=" + Math.random();

	this.ExecuteWebServiceRequest(url, callback);
}

LoadContentService.LoadUserStatus = function(callback)
{
	this.Load("UserStatusBlock", "divUserStatus", null, callback);

}

LoadContentService.BanUser = function(callback, sessionID, userID, ipBlock, ip, ban)
{
	var url = "/WebServices/BanUserService.aspx"
			+ "?sessionid=" + sessionID
			+ "&userid=" + userID
			+ "&ipBlock=" + ipBlock
			+ "&ip=" + ip
			+ "&ban=" + (ban ? 1 : 0);
			+ "&rand=" + Math.random();

	this.ExecuteWebServiceRequest(url, callback);
}
;
