function doAJAXget(ajaxURL,callbackFunction)
{
	/**
	 * The variable http will hold our new XMLHttpRequest object
	 */
	var http = CreateRequestObject(); 
	var d = new Date();

	ajaxURL = addQueryParam(ajaxURL, 'rand', d.getTime());

	http.open('POST',ajaxURL);
	
	/** 
	 * Define a function to call once a response has been received. This will be our
	 * handleProductCategories function that we define below
	 */	
	http.onreadystatechange = function()
	{
		if (http.readyState==4)
		{
			try
			{
				if(http.status !== undefined && http.status != 0)
				{
					httpStatus = http.status;
				}
				else
				{
					httpStatus = 13030;
				}
			}
			catch(e)
			{
				// 13030 is the custom code to indicate the condition -- in Mozilla/FF --
				// when the o object's status and statusText properties are
				// unavailable, and a query attempt throws an exception.
				httpStatus = 13030;
			}
			switch(httpStatus)
			{
				case 200:
					myFunction = eval(callbackFunction);	
					myFunction(http.responseText);
					break;
				case 404:
					//alert("The requested page could not be found");
					break;
				case 12002: // Server timeout
				case 1252:
				case 1259:
				case 12029: // Dropped connections. }
				case 12030: // Dropped connections. } See http://www.savarese.org/workarounds/index.html
				case 12031: // Dropped connections. } for further info
				case 12032:
				case 12152: // Connection closed by server.
					//alert("Lost Server Connection");
					break;
				case 13030:
					// 13030 is the custom code to indicate the condition -- in Mozilla/FF --
					// when the o object's status and statusText properties are
					// unavailable, and a query attempt throws an exception.
					// http://www.yui-ext.com/deploy/yui-ext/docs/output/connection.js.html
					//alert("The browser threw an error creating this request");
					break;
				default :
					//alert("Failed because " + httpStatus);
					return false;
			}
		}
	}   
	
	http.send(null);
}



function addQueryParam(url, name, value){
	
	if (url.indexOf('?') == -1) {
		url += "?"+name+"="+value;
	} else {
		url += "&"+name+"="+value;
	}
	
	return url;
}

function validateComment() {
	
	var passed = true;
	
	if (trim(document.getElementById('comment_text').value) == '') {
		document.getElementById('comment_text').style.borderColor = '#F00';
		passed = false;
	}
	else {
		document.getElementById('comment_text').style.borderColor = 'rgb(0, 67, 149)';
	}
	
	return passed;
}

function unsubscribeToBlog(postId) {
	doAJAXget("/blog/unsubscribe?id="+postId, "hideThrobber");
	hideDiv("unsub"+postId);
	showDivInline("sub"+postId);
}

function subscribeToBlog(postId) {
	doAJAXget("/blog/subscribe?id="+postId, "hideThrobber");
	hideDiv("sub"+postId);
	showDivInline("unsub"+postId);
}

function showDivInline(id) {
	var obj = document.getElementById(id);
	obj.style.visibility = "visible";
	obj.style.display = "inline";
}

function CreateRequestObject()
{
	var xrequest = false;
	try
	{
		xrequest = new ActiveXObject("Msxml2.XMLHTTP");	
	}	 
	catch (othermicrosoft) 		
	{
		try
		{
			xrequest = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch (failed) 	
		{
			try 
			{
				xrequest = new XMLHttpRequest();
			} 
			catch (trymicrosoft) 		
			{	
				xrequest = false;
			}
		}
	}
	return xrequest;
}

function validatePost() {	
	var passed = true;
	
	if(trim(document.getElementById('post_title').value)=='') {
		document.getElementById('post_title').style.borderColor = '#F00';
		passed =  false;
	} else {
		document.getElementById('post_title').style.borderColor = 'rgb(0, 67, 149)';
	}
	
	if(trim(document.getElementById('post_body').value)=='') {
		document.getElementById('post_body').style.borderColor = '#F00';
		passed = false;
	} else {
		document.getElementById('post_body').style.borderColor = 'rgb(0, 67, 149)';
	}
	
	return passed;
}
