	function get_xmlHttp(){
	  var xmlHttp;
	  try
		{
		// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
		}
	  catch (e)
		{
		// Internet Explorer
		try
		  {
		  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		  }
		catch (e)
		  {
		  try
			{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
		  catch (e)
			{
			alert("Sorry, your browser does not support AJAX. This website requires this element to work properly.");
			return false;
			}
		  }
		}
		return xmlHttp;
	}
	
	//Ajax request
	function ajax_request(file,params,callFunc){
		xmlHttp=get_xmlHttp();
			xmlHttp.open("POST",file,true);
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			//xmlHttp.setRequestHeader("Content-length", params.length);
			//xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.send(params);
		xmlHttp.onreadystatechange=function()
			{
				if(xmlHttp.readyState==4 && callFunc!=undefined)
				{
				callFunc(xmlHttp);
				}
			}
	}
	
	//Ajax request 2
	function ajax_request2(file,params){
		xmlHttp=get_xmlHttp();
			xmlHttp.open("POST",file,false);
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			//xmlHttp.setRequestHeader("Content-length", params.length);
			//xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.send(params);
		return xmlHttp;
	}

	function addremovebr(id,id2){
		if (document.getElementById(id).checked==false){
			//it's now unchecked
			// do they want to add <br/>s to the existing text?
			conf=confirm("When this post is added, new lines in the main article will now not automatically be replaced with <br/> tags . This can be useful when adding your own custom xhtml code. Do you wish to convert any line breaks that are currently in the text into <br/> tags?");
			if (conf){
				textareatxt = document.getElementById(id2).value;
				var textareatxt = textareatxt.replace(/\r\n|\r|\n/g, '<br/>\n');
				document.getElementById(id2).value=textareatxt;
			}
		} else {
			//it's now checked
			// do they want to remove <br/>s to the existing text and replace them with \n?
			conf=confirm("When this post is added, new lines in the main article will now automatically be replaced with <br/> tags (the xhtml symbol for a new line). Do you wish to remove any <br/> tags that are currently in the text box?");
			if (conf){
				textareatxt = document.getElementById(id2).value;
				var textareatxt = textareatxt.replace(/<br\/\>/g, '');
				document.getElementById(id2).value=textareatxt;
			}
		}
	}

	function addremovep(id,id2){
		if (document.getElementById(id).checked==false){
			//it's now unchecked
			// do they want to add <p>s to the existing text?
			alert("When this post is saved, paragraphs in the main article will no longer be automatically converted to their xhtml equivelants. <p> tags will now be added arround any paragraphs that are currently in the text box, but you are now responsible for starting/closing them properly yourself.");
			textareatxt = document.getElementById(id2).value;
			var textareatxt = textareatxt.replace(/\r\n\r\n|\r\r|\n\n|\r\n|\r|\n/g, '<\/p\>\n\n<p\>');
			document.getElementById(id2).value="<p class='first_p'>"+textareatxt+"</p>";
		} else {
			//it's now checked
			// do they want to remove <br/>s to the existing text and replace them with \n?
			alert("When this post is saved, paragraphs in the main article will now automatically be converted to their xhtml equivelants. Any <p> tags that are currently in the text box will now be removed.");
			textareatxt = document.getElementById(id2).value;
			var textareatxt = textareatxt.replace(/<\/p\>/g, '');
			var textareatxt = textareatxt.replace(/<p\>/g, '');
			var textareatxt = textareatxt.replace(/<p class='first_p'\>/g, '');
			document.getElementById(id2).value=textareatxt;
		}
	}

	function dump(arr,level) {
		var dumped_text = "";
		if(!level) level = 0;
		
		//The padding given at the beginning of the line.
		var level_padding = "";
		for(var j=0;j<level+1;j++) level_padding += "    ";
		
		if(typeof(arr) == 'object') { //Array/Hashes/Objects 
			for(var item in arr) {
				var value = arr[item];
				
				if(typeof(value) == 'object') { //If it is an array,
					dumped_text += level_padding + "'" + item + "' ...\n";
					dumped_text += dump(value,level+1);
				} else {
					dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
				}
			}
		} else { //Stings/Chars/Numbers etc.
			dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
		}
		return dumped_text;
	}

	function object_length(obj) {
		var size = 0, key;
		for (key in obj) {
			if (obj.hasOwnProperty(key)) size++;
		}
		return size;
	};



	// Main Menu Item Mouse Over
	function mmover(id){
		document.getElementById(id+"_menu").style.display="block";
		link=document.getElementById("link_"+id);
		//link.childNodes[1].style.color="#ffffff";
		//link.childNodes[1].childNodes[1].src="/images/arrow_down_hover.png";
	}

	// Main Menu Item Mouse Out
	function mmout(id){
		document.getElementById(id+"_menu").style.display="none";
		link=document.getElementById("link_"+id);
		//link.childNodes[1].style.color="#ffffff";
		//link.childNodes[1].childNodes[1].src="/images/arrow_down.png";
	}

	String.prototype.ucFirst = function () {
		return this.substr(0,1).toUpperCase() + this.substr(1,this.length);
	};	

	objImage = new Image();
	objImage.src="images/drop_down_bg.png";
	objImage.src="images/tab_bg.png";

	
	function insert_link_at_cursor(insert_to_id,link_source_id) {
		linkURL=document.getElementById(link_source_id).value.replace(/\"/g,'\\"');
		start='<a href="'+linkURL+'">';
		close='</a>';
		insert_tags_at_cursor(insert_to_id,start,close);
	}

	function insert_image_at_cursor(insert_to_id,img_source_id,escape_text) {
		imgURL=document.getElementById(img_source_id).value.replace(/\"/g,'&quot;');
		start='<img src="'+imgURL+'" alt="';
		close='" />';
		insert_tags_at_cursor(insert_to_id,start,close,escape_text);
	}
	
	function insert_tags_at_cursor(insert_to_id,start,close,escape_text) {
		myField=document.getElementById(insert_to_id);
		defaultText=start+"Text Goes Here"+close;
		
		//IE support
		if (document.selection) {
			myField.focus();
			sel = document.selection.createRange();
			if (sel.text!=""){
				if (escape_text==true){
					sel.text=sel.text.replace(/\"/g,'&quot;');
				}
				sel.text = start + sel.text + close;
			} else {
				sel.text = defaultText;
			}
		}
		//MOZILLA/NETSCAPE support
		else if (myField.selectionStart || myField.selectionStart == '0') {
			var startPos = myField.selectionStart;
			var endPos = myField.selectionEnd;
			if (startPos!=endPos){
				if (escape_text==true){
					the_text=myField.value.substring(startPos,endPos).replace(/\"/g,'&quot;');
				} else {
					the_text=myField.value.substring(startPos,endPos);
				}
				myField.value = myField.value.substring(0, startPos)
					+ start 
					+ the_text
					+ close 
					+ myField.value.substring(endPos, myField.value.length);
			} else {
				myField.value = myField.value.substring(0, startPos)
					+ defaultText 
					+ myField.value.substring(endPos, myField.value.length);
			}
		} else {
			myField.value += defaultText;
		}							
	}	

