// number formatting function
// copyright Stephen Chapman 24th March 2006, 10th February 2007
// permission to use this function is granted provided
// that this copyright notice is retained intact

function formatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2) {var x = Math.round(num * Math.pow(10,dec));if (x >= 0) n1=n2='';var y = (''+Math.abs(x)).split('');var z = y.length - dec; if (z<0) z--; for(var i = z; i < 0; i++) y.unshift('0');y.splice(z, 0, pnt); if(y[0] == pnt) y.unshift('0'); while (z > 3) {z-=3; y.splice(z,0,thou);}var r = curr1+n1+y.join('')+n2+curr2;return r;}

//Javascript to show/hide div element
function hideshow(which){
	if (!document.getElementById)
	return
	if (which.style.display=="block")
	which.style.display="none"
	else
	which.style.display="block"
}

intImage = 2;
function swapImage(id) {
switch (intImage) {
 case 1:
   document.getElementById(id).src = "./images/specsArrow.gif"
   intImage = 2
   return(false);
case 2:
   document.getElementById(id).src = "./images/specsArrow_down.gif"
   intImage = 1
   return(false);
 }
}

function reload(val){
	self.location = window.location.pathname +'?searchTerm=' +val;
}

function reload2(val1, val2){
	self.location = window.location.pathname +'?searchTerm=' +val1 +val2;
}

function reload3(val){
	self.location = window.location.pathname +'?id=' +val;
}

//Browser Support Code
function ajaxFunction(data, val, page, variable, folder){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 1){
			var ajaxDisplay = document.getElementById(data);
			ajaxDisplay.innerHTML = '<img src="http://demo.cmcs.com.au/completehomespackages/admin/img/ajax-loader.gif" style="margin-left: 360px; margin-top: 15px;" border="0" alt="Loading, please wait..." />';
		}else if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById(data);
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}
	
	var queryString = "?val=" + val + "&folder=" + folder;
	ajaxRequest.open("GET", page + queryString + variable, true);
	ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); // set Header
	ajaxRequest.send(null); 
}

//auto complete
function lookup(inputString, page) {
	if(inputString.length == 0) {
		// Hide the suggestion box.
		$('#suggestions').hide();
	} else {
		$.post("autoComplete.php" + page, {queryString: ""+inputString+""}, function(data){
			if(data.length >0) {
				$('#suggestions').show();
				$('#autoSuggestionsList').html(data);
			}
		});
	}
} // lookup

function fill(thisValue) {
	$('#inputString').val(thisValue);
	setTimeout("$('#suggestions').hide();", 200);
}

function confirmation(folder, id) {
	var answer = confirm("Are you sure you want to delete this item?")
	if (answer){
		window.location = "itemDelete.php?folder="+folder+"&id="+id;
	}
}
