/*
*** mod date:		09/07/08
--- description:	removes the dashed line round links
                    
--- usage:			uses a mootools 'domready' function to apply to all links on the page
*/
function unblur() {
	this.blur();
} 
function blurLinks() {
	if (!document.getElementById) return;
	theLinks = document.getElementsByTagName("A");
	theAreas = document.getElementsByTagName("AREA");
	for(i=0; i<theLinks.length; i++) {theLinks[i].onfocus = unblur;}
	for(i=0; i<theAreas.length; i++) {theAreas[i].onfocus = unblur;}
}
window.addEvent('domready', function(){blurLinks();});


/*
	opens a pop-up window in the centre of the screen
	use as: javascript:centreWindowOpener('index.asp','windowName','widthInPixels','heightInPixels','scrollingYesNo')
*/
function centreWindowOpener(url, windowName, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2 - 20;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=no,status=yes';
	win = window.open(url, windowName, winprops);

	if (parseInt(navigator.appVersion) >= 4) {
		win.window.focus();
	}
}

/*
	only allow numeric chars
*/
function NumbersOnly(e) {
	var key;
	var keychar;

	if (window.event) {
	   key = window.event.keyCode;
	} else if (e) {
	   key = e.which;
	} else {
	   return true;
	}
	keychar = String.fromCharCode(key);

	// control keys and numbers
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) ) {
	   return true;
	} else if ((("0123456789").indexOf(keychar) > -1)) {
	   return true;
	} else {
	   return false;
	}
}

/*
	checks the char length of a text area
*/
function checkFieldLength(fieldID,maxLength) {
	var fieldID = document.getElementById(fieldID);
	var fieldIDLength = fieldID.value.length;
	if(fieldIDLength > maxLength) {
		return false;
	} else {
		return true;
	}   
}

/*
	opens the facebook share window
*/
function shareOnFacebook() {
	u=location.href;
	t=document.title;
	centreWindowOpener('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','626','436','Yes');	
	return false;
}

/*
	confirm dialog box prior to delete
*/
function confirmDelete(){
    return confirm("This option will:\n\n    - Delete the selected item\n\nAre you sure you want to do this?");
}

/*
	confirm dialog box prior to posting a property
*/
function confirmPropertyPost(){
    return confirm("Posting Property - Image Upload:\n\n    - Resizing your images will result in faster upload times\n    - Uploading multiple images will be slower\n    - If you do not have broadband, upload one image at a time\n\nWhen submitting your property, please be patient.");
}

/*
	sets the check box selected value
*/
function setCheckBox(id,blnChecked){
	$(id).checked = blnChecked;
}

/*
	Function: $get
	This function provides access to the “get” variable scope + the element anchor

	Version: 1.3

	Arguments:
	key - string; optional; the parameter key to search for in the url’s query string (can also be “#” for the element anchor)
	url - url; optional; the url to check for “key” in, location.href is default

	Example:
	>$get(”foo”,”http://example.com/?foo=bar”); //returns “bar”
	>$get(”foo”); //returns the value of the “foo” variable if it’s present in the current url(location.href)
	>$get(”#”,”http://example.com/#moo”); //returns “moo”
	>$get(”#”); //returns the element anchor if any, but from the current url (location.href)
	>$get(,”http://example.com/?foo=bar&bar=foo”); //returns {foo:’bar’,bar:’foo’}
	>$get(,”http://example.com/?foo=bar&bar=foo#moo”); //returns {foo:’bar’,bar:’foo’,hash:’moo’}
	>$get(); //returns same as above, but from the current url (location.href)
	>$get(”?”); //returns the query string (without ? and element anchor) from the current url (location.href)

	Returns:
	Returns the value of the variable form the provided key, or an object with the current GET variables plus the element anchor (if any)
	Returns “” if the variable is not present in the given query string

	Credits:
	Regex from [url=http://www.netlobo.com/url_query_string_javascript.html]http://www.netlobo.com/url_query_string_javascript.html[/url]
	Function by Jens Anders Bakke, webfreak.no
	http://webfreak.no/wp/2007/09/05/get-for-mootools-a-way-to-read-get-variables-with-javascript-in-mootools/
*/
function $get(key,url){
if(arguments.length < 2) url =location.href;
if(arguments.length > 0 && key != ""){
if(key == "#"){
var regex = new RegExp("[#]([^$]*)");
} else if(key == "?"){
var regex = new RegExp("[?]([^#$]*)");
} else {
var regex = new RegExp("[?&]"+key+"=([^&#]*)");
}
var results = regex.exec(url);
return (results == null )? "" : results[1];
} else {
url = url.split("?");
var results = {};
if(url.length > 1){
url = url[1].split("#");
if(url.length > 1) results["hash"] = url[1];
url[0].split("&").each(function(item,index){
item = item.split("=");
results[item[0]] = item[1];
});
}
return results;
}
}


/*
	set up the cookie to play the sounds
*/
var playSound = Cookie.read("playSound");
if ((playSound != 'true') && (playSound != 'false')) {
	playSound = 'true';
	Cookie.write('playSound', 'true', {duration: 30});
}
/*
	events fired by the stop/start buttons in flash
*/
function playerStart() {
	playSound = Cookie.read("playSound");
	playSound = 'true';
	Cookie.write('playSound', playSound, {duration: 30});
}
function playerStop() {
	playSound = Cookie.read("playSound");
	playSound = 'false';
	Cookie.write('playSound', playSound, {duration: 30});
}