	
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//
	// Date: 5 Dec 2008
	//
	// StoreFinder Widgets javascript API.
	// Provides StoreFinder subscribers with embedded store locator functionality on their website.
	//
	// Copyright (C) 2008 by Daniel Vidoni, Sydney Australia, All rights reserved.
	// Web: www.storefinder.com.au
	//
	// You may not distribute this code in any manner, modified or otherwise, without the express, written
	// consent from Daniel Vidoni.
	// 
	// You may not make modifications or install this file on your servers.
	//
	// You are permitted to link to this code for the purpose of providing your website with store finder functionality.
	//
	// In all cases copyright and header must remain intact.
	//
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		
		
	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)
	{
		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;
		}
		
		postcodePopupURL(storefinderRootURL + "postcode/core/popup.php" +
											"?RetailerID=" + retaID +
											"&Postcode=" + encodeURIComponent(locality) +
											"&Marketing=" + encodeURIComponent(market) +
											"&Radius=" + radius +
											"&Results=" + results +
											"&ResultsShuffle=" + resultsShuffle +
											"&Query=" + encodeURIComponent(query));
	}
	
	
	function postcodePopupUsingID(RetailerID)
	{
		retailerID = (isDefined(RetailerID)) ? RetailerID : "";
		postcodePopupURL(storefinderRootURL + "postcode/core/popup.php?RetailerID=" + retailerID);
	}
	
	
	/*
	function storeFinderPopupWithArgs(RetailerID, Marketing, Radius, Results, ResultsShuffle)
	{
		market 				 = (isDefined(Marketing)) 		 ? Marketing 		  : "";
		radius 				 = (isDefined(Radius))    		 ? Radius    		  : -1;
		results        = (isDefined(Results))        ? Results        :  3;
		resultsShuffle = (isDefined(ResultsShuffle)) ? ResultsShuffle :  0;
	
		var url = storefinderRootURL + "postcode/core/popup.php" +
																		"?RetailerID=" + RetailerID +
																		"&Marketing=" + encodeURIComponent(market) +
																		"&Radius=" + radius +
																		"&Results=" + results +
																		"&ResultsShuffle=" + resultsShuffle;
		postcodePopupURL(url);
	}
	*/
	
	function InstallStoreFinderWidget(WidgetType, RetailerID, TitleText, Marketing, Radius, NumResults, ResultsShuffle)
	{ 
		retailerID		 = (isDefined(RetailerID) && RetailerID!="")	? RetailerID								: "";
		titleText 		 = (isDefined(TitleText) 	&& TitleText!="")		? TitleText.toUpperCase()		: "FIND NEAREST OUTLETS";
		radius 				 = (isDefined(Radius) 		&& Radius>=-1)			? Radius										: -1;
		numResults		 = (isDefined(NumResults) && NumResults>0)		? NumResults								:  3;
		marketing			 = (isDefined(Marketing))											? Marketing									: "";
		resultsShuffle = (isDefined(ResultsShuffle))								? ResultsShuffle 						:  0;
	
		// CSS
		document.write('<style>' +
									 '.trans { opacity:0.6; filter:alpha(opacity=60); }' +
									 '.fntSml { font-size:8pt; }' +
									 '</style>');
	
		// header
		document.write('<table border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#ffffff" ' +
											'class="fntSml" style="font-family:Verdana, Arial, Helvetica, sans-serif; border:solid 1px #dddddd; background-image:url(\''+storefinderRootURL+'widgets/widg_bg.jpg\'); background-position:right; background-repeat:no-repeat;">' +
										'<tr><td align="center" bgcolor="#FED16F" background="'+storefinderRootURL+'widgets/SF_TEMPLATE_06.gif" style="border-bottom:solid 1px #888888; background-repeat:repeat;">' +
										'<a title="Click to find nearest" style="font-weight:bold; text-decoration:none;" rel="nofollow" href="javascript:;" onClick="javascript:postcodePopupUsingID(' + retailerID + ')">' +
										'<img src="'+storefinderRootURL+'widgets/S.gif" width="28" height="28" hspace="0" vspace="0" border="0" align="absmiddle" /> &nbsp;'+titleText+'</a></td></tr>' );
	
		// render widgets
		switch (WidgetType)
		{
			case 'LINK':
	//			document.write('<a style="font-size:8.5pt; line-height:200%; font-weight:bold; text-decoration:none;" title="Click to find nearest location" rel="nofollow" href="javascript:;" onClick="javascript:storeFinderPopupWithArgs(' + retailerID + ',\'' + marketing + '\',' + radius + ',' + results + ',' + resultsShuffle + ')">' +
	//												'FIND NEAREST OUTLET</a><br /></a>');
				break;
	
			case 'RADIUS':		
				document.write('<tr><td align="center"><br>' +
												'<form method="post" name="sfformRAD" onSubmit="postcodePopupUsingForm(\'sfformRAD\'); return false;">' + 
													'<input type="HIDDEN" name="RetailerID" value="'+retailerID+'">' + 
													'<input type="HIDDEN" name="Marketing" value="'+marketing+'">' + 
													'<input type="HIDDEN" name="Results" value="'+numResults+'">' + 
													'<input type="HIDDEN" name="ResultsShuffle" value="'+resultsShuffle+'">' + 
													'<table border="0" cellpadding="4" cellspacing="0" style="font-size:8.5pt; font-weight:bold;">' + 
														'<tr valign="middle">' + 
															'<td align="right">Town or Postcode:</td>' + 
															'<td><input name="Postcode" type="text" size="15" class="trans" style="border:solid #000000 1px;"></td>' + 
														'</tr>' + 
														'<tr valign="middle">' + 
															'<td align="right">Within Radius:</td>' + 
															'<td><input name="Radius" type="text" size="4" maxlength="4" class="trans" style="border:solid #000000 1px;"> kms</td>' + 
														'</tr>' +
														'<tr>' + 
															'<td colspan="2" align="center"><input type="submit" value="Search" class="fntSml"/></td>' +
														'</tr>' + 
													'</table>' + 
												'</form>' +
												'</td></tr>');
				break;
	
			case 'RADIUS2':		
				document.write('<tr><td align="center"><br>' +
												'<form method="post" name="sfformRAD2" onSubmit="postcodePopupUsingForm(\'sfformRAD2\'); return false;">' + 
													'<input type="HIDDEN" name="RetailerID" value="'+retailerID+'">' + 
													'<input type="HIDDEN" name="Marketing" value="'+marketing+'">' + 
													'<input type="HIDDEN" name="ResultsShuffle" value="'+resultsShuffle+'">' + 
													'<table border="0" cellpadding="4" cellspacing="0" style="font-size:8.5pt; font-weight:bold;">' + 
														'<tr valign="middle">' + 
															'<td align="right">Town or Postcode:</td>' + 
															'<td><input name="Postcode" type="text" size="15" class="trans" style="border:solid #000000 1px;"></td>' + 
														'</tr>' + 
														'<tr valign="middle">' + 
															'<td align="right">Within Radius:</td>' + 
															'<td><input name="Radius" type="text" size="4" maxlength="4" class="trans" style="border:solid #000000 1px;"> kms</td>' + 
														'</tr>' +
														'<tr valign="middle">' + 
															'<td align="right">Number of Results:</td>' + 
															'<td><input name="Results" type="text" size="4" maxlength="2" class="trans" style="border:solid #000000 1px;"></td>' + 
														'</tr>' +
														'<tr>' + 
															'<td colspan="2" align="center"><input type="submit" value="Search" class="fntSml"/></td>' +
														'</tr>' + 
													'</table>' + 
												'</form>' +
												'</td></tr>');
				break;
	
			case 'DIALOG':	
				/* fall through */
			default:	
				document.write('<tr><td align="center"><br>' +
												'<form method="post" name="sfformDLG" onSubmit="postcodePopupUsingForm(\'sfformDLG\'); return false;">' + 
													'<input type="HIDDEN" name="RetailerID" value="'+retailerID+'">' + 
													'<input type="HIDDEN" name="Marketing" value="'+marketing+'">' + 
													'<input type="HIDDEN" name="Radius" value="'+radius+'">' + 
													'<input type="HIDDEN" name="Results" value="'+numResults+'">' + 
													'<input type="HIDDEN" name="ResultsShuffle" value="'+resultsShuffle+'">' + 
													'<table border="0" cellpadding="4" cellspacing="0" style="font-size:8.5pt; font-weight:bold;">' + 
														'<tr valign="middle">' + 
															'<td align="right">Town or Suburb<br>or Postcode</td>' + 
															'<td><input name="Postcode" type="text" size="15" class="trans" style="border:solid #000000 1px;"></td>' + 
														'</tr>' + 
														'<tr>' + 
															'<td>&nbsp;</td>' + 
															'<td colspan="2"><input type="submit" value="Search" class="fntSml"></td>' + 
														'</tr>' + 
													'</table>' + 
												'</form>' +
												'</td></tr>');
				break;
		}
	
		// footer
		document.write( '<tr><td align="center" style="border-top:solid 1px #bbbbbb; font-size:7pt; color:#808080; background-repeat:repeat;" bgcolor="#FFE9B9" background="'+storefinderRootURL+'widgets/SF_TEMPLATE_06.gif">' +
										'Locator service by <a href="'+storefinderRootURL+'" target="_blank">StoreFinder</a></td></tr></table>');
	}
	
	
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//
	// End.
	//
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
