
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, features)
{
	features = (isDefined(features) && features!="") ? ","+features : "";
	urlWindow = window.open ( url, 'SFPopup', 'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,height=770,width=800' + features );
	urlWindow.focus();
}


function postcodePopupUsingForm(frmName, noPopup, features)
{
	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) && noPopup==true)
		window.location.href = url;
	else
		postcodePopupURL(url, features);
}


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


// Browser Detection Javascript. Copyright 1 Feb 2003, by Stephen Chapman, Felgall P/L
function whichBrowser()
{
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("opera") != -1) return 'Opera';
	if (agt.indexOf("staroffice") != -1) return 'Star Office';
	if (agt.indexOf("webtv") != -1) return 'WebTV';
	if (agt.indexOf("beonex") != -1) return 'Beonex';
	if (agt.indexOf("chimera") != -1) return 'Chimera';
	if (agt.indexOf("netpositive") != -1) return 'NetPositive';
	if (agt.indexOf("phoenix") != -1) return 'Phoenix';
	if (agt.indexOf("firefox") != -1) return 'Firefox';
	if (agt.indexOf("safari") != -1) return 'Safari';
	if (agt.indexOf("skipstone") != -1) return 'SkipStone';
	if (agt.indexOf("msie") != -1) return 'Internet Explorer';
	if (agt.indexOf("netscape") != -1) return 'Netscape';
	if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';

	if (agt.indexOf('\/') != -1) {
		if (agt.substr(0,agt.indexOf('\/')) != 'mozilla')
			return navigator.userAgent.substr(0,agt.indexOf('\/'));
		else return 'Netscape';
	}
	else if (agt.indexOf(' ') != -1)
		return navigator.userAgent.substr(0,agt.indexOf(' '));
	else return navigator.userAgent;
}


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 br = whichBrowser();
	if ( br == "Firefox" )
		document.write('<form><input style="font-size:8.5pt;" type="button" value="Print Results" name="Print" onClick="_printIt()"></form>');
}
