
function isDefined(variable)
{
	return ( typeof(variable) == "undefined" ) ? false : true;
} 


// A javascript, in a normal html document, opens on an http connection: document.location.protocol equals "http" in Konqueror.
// However in Netscape and Explorer it equals "http:". This can breaks things, therefore we do a case insensitive search for the letter 's'
// to determine whether we are in secure mode or not.
if (typeof(storefinderRootURL)=="undefined") {
storefinderRootURL  = (document.location.protocol.search(/s/i) == -1) ? "http://www." : "https://anchor.net.au/secure/";
storefinderRootURL += "storefinder.com.au/";
}


function postcodePopupURL(url)
{
	urlWindow = window.open ( url, 'SFPopup','toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,height=770,width=800');
	urlWindow.focus();
}


function postcodePopupUsingForm(frmName, noPopup)
{
	form = document.forms[frmName];

	if      (isDefined(form.Postcode) && form.Postcode!="") locality = form.Postcode.value;
	else if (isDefined(form.Locality) && form.Locality!="") locality = form.Locality.value;
	else 																										locality = "";

	market				 = (isDefined(form.Marketing))			? form.Marketing.value			: "";
	query 				 = (isDefined(form.Query))					? form.Query.value					: "";
	results				 = (isDefined(form.Results))				? form.Results.value        :  3;
	resultsShuffle = (isDefined(form.ResultsShuffle)) ? form.ResultsShuffle.value :  0;
	retaID				 = (isDefined(form.RetailerID))			? form.RetailerID.value			: "";
	radius				 = (isDefined(form.Radius))					? parseInt(form.Radius.value,10)	: -1;	
	if (radius=="NaN") radius = -1;

	if (retaID=="") {
		alert(retaID + " ID Invaid.\n");
		return;
	}

	if (locality=="" && query=="") {
		alert("Please enter a 3 or 4 digit postcode, locality name or a valid query.");
		return;
	}

	if (locality.search(',')!=-1 || locality.search('/')!=-1) {
		alert("Please enter either a postcode, town or suburb name.");
		return;
	}

	url = storefinderRootURL +
				"postcode/core/popup.php" +
										"?RetailerID=" + retaID +
										"&Postcode=" + encodeURIComponent(locality) +
										"&Marketing=" + encodeURIComponent(market) +
										"&Radius=" + radius +
										"&Results=" + results +
										"&ResultsShuffle=" + resultsShuffle +
				"&Query=" + encodeURIComponent(query);

	if (isDefined(noPopup))
		window.location.href = url;
	else
		postcodePopupURL(url);
}


function postcodePopupUsingID(RetailerID)
{
	retailerID = (isDefined(RetailerID)) ? RetailerID : "";
	postcodePopupURL(storefinderRootURL + "postcode/core/popup.php?RetailerID=" + retailerID);
}


function _printIt()
{  
	if (window.print) {
		window.print();
	}
	else {
		var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH="0" HEIGHT="0" CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
		document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
		WebBrowser1.ExecWB(6, 2);		//Use a 1 vs. a 2 for a prompting dialog box
		WebBrowser1.outerHTML = "";  
	}
}

function printIt()
{
//	if (parseInt(navigator.appVersion) > 3)
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("firefox") != -1)
		document.write('<form><input style="font-size:8.5pt;" type="button" value="Print Results" name="Print" onClick="_printIt()"></form>');
}
