function makeHttpRequest(url, callback_function, return_xml)
{
   var http_request = false;

   if (window.XMLHttpRequest) { // Mozilla, Safari,...
       http_request = new XMLHttpRequest();
       if (http_request.overrideMimeType) {
           http_request.overrideMimeType('text/xml');
       }
   } else if (window.ActiveXObject) { // IE
       try {
           http_request = new ActiveXObject("Msxml2.XMLHTTP");
       } catch (e) {
           try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
           } catch (e) {}
       }
   }

   if (!http_request) {
       alert('Unfortunatelly you browser doesn\'t support this feature.');
       return false;
   }
   http_request.onreadystatechange = function() {
       if (http_request.readyState == 4) {
           if (http_request.status == 200) {
               if (return_xml) {
                   eval(callback_function + '(http_request.responseXML)');
               } else {
                   eval(callback_function + '(http_request.responseText)');
               }
           } else {
               alert('There was a problem with the request.(Code: ' + http_request.status + ')');
           }
       }
   }
   http_request.open('GET', url, true);
   http_request.send(null);
}

//New window links
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;

function toggleComment(){

	if (document.getElementById('encoding')) {
		var form = document.getElementById('encoding');
		document.getElementById('encoding').onsubmit = function() {
		makeHttpRequest("/html_translate.php?text="+form.text.value.replace("&","*am*")+"&quotes="+form.quotes.value,"eval");
		return false;
		}
	}
	if (document.getElementById('comment')) {
		// if browser doesn't support this method, return false
		if(!document.getElementById) return false;
		
		// create the anchor content and element
		var linkText = document.createTextNode('Make textarea bigger');
		var toggleLink = document.createElement('a');
		toggleLink.href = 'javascript:void(null)';
		toggleLink.appendChild(linkText);
		
		//create a paragraph element for the anchor to live in
		var linkPara = document.createElement('p');
		linkPara.setAttribute('id','toggle');
		linkPara.appendChild(toggleLink);
		
		// Get a reference to the comment input and it's parent fieldset
		var commentArea = document.getElementById('comment');
		var commentFieldset = commentArea.parentNode;
		
		//place the paragraph element at the end of the comment fieldset
		commentFieldset.appendChild(linkPara);
		
		// set the callback function
		toggleLink.onclick = function(){
			var theText = this.firstChild;
			var newText;
			var commentField = document.getElementById('comment');
			
			if(theText.nodeValue == 'Make textarea bigger'){
				// make the height of the comment input bigger
				//commentField.setAttribute('class','bigComment');
				commentField.style.height = '300px';
				
				// I was origionally setting the nodevalue of the anchor text.
				// however the size of the node wasn't changing, so I figured I'd have to
				// use the replace child method instead
				newText = document.createTextNode('Make textarea smaller');
				this.replaceChild(newText,theText);
				
			} else {
				// return the comment input to it's default html size
				// rather than directly changing the size, it would probably be better
				//to change the class. Thus seporating the display from the logic
				//commentField.setAttribute('class','smallComment');
				commentField.style.height = '100px';
				newText = document.createTextNode('Make textarea bigger');
				this.replaceChild(newText,theText);	
			}
		}
	}
}

//START: Comment Preview
var authorDefault='';
function previewAuthor(e) {
	var p = document.getElementById('previewAuthor');
	var a = e.form.name.value;
	var u = e.form.url.value;
	if (u.indexOf('http://') != 0 && u != '') {u = 'http://' + u;}
	if (authorDefault=='') { authorDefault = p.innerHTML; }
	p.innerHTML = (!checkEmpty(a))?a:authorDefault; 
	p.href = (!checkEmpty(u))?u:'#post';
	p.title = u;
	}
function preview(e) { document.getElementById('preview').innerHTML = '<p>'+e.value.replace(/(\n|\r)/g,'<br />').replace(/(<br \/>){2,}/gi,'<'+'/p><p>')+'<'+'/p>'; }
//END: Comment Preview
//START: Check if empty function
function checkEmpty(val) { var empty = /^\s*$/; return empty.test(val); }
//END: Check if empty function

function CentredPopup(mypage,myname,w,h,scroll){
	var win = null;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
	win = window.open(mypage,myname,settings)
}
//javascript:CentredPopup('/forsale/NSW/lindfield/index.html','lindfield','780','420','no');