﻿var mapPath = "FlashMapContainer.swf";
var postcodePath = "PostCode.php";
var captchaPath = "CheckCaptcha.php";
var captchaReloadPath = "Captcha.php?date={0}";
var operationalEmailPath = "EmailOperational.php";
var franchiseEmailPath = "EmailFranchises.php";
var genericEmailPath = "EmailGeneral.php";


var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
function FlashMapContainer_DoFSCommand(command, args) {
	ShowStateLocations(command);
}

if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<script language=\"VBScript\"\>\n');
	document.write('On Error Resume Next\n');
	document.write('Sub FlashMapContainer_FSCommand(ByVal command, ByVal args)\n');
	document.write('	Call FlashMapContainer_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('</script\>\n');
}

var ERROR_Required = "Please fill in this required field.";
var ERROR_Email = "You have entered an incorrect email address.";
var ERROR_Phone = "Please enter a correct phone number";
var ERROR_Mobile = "Please enter a correct mobile number";
var ERROR_State = "Please select a valid state.";
var ERROR_Human = "That is not what the image says!";
var ERROR_HumanService = "We could not contact the image verification service. Please try again in a few minutes.";
var ERROR_SendEmail = "There was an error when sending your details.<br />Please try again in a few minutes.";

var EmailPattern = /^[0-9a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
var StatePattern = /NSW|VIC|QLD|NT|SA|TAS|WA/;
var PhonePattern = /[0-9 \-\(\)\[\]]+/;

var thiz = this;

var liFormat = "<div class=\"ErrorHeader\"></div><div class=\"ErrorContent\">{0}</div><div class=\"ErrorFooter\"></div>";
//var locationFormat = "<a class=\"{3}\" href='javascript:ShowLocation({2})'><em>{0}</em><span>{1}</span></a>";
var locationFormat = "<a class=\"{3}\" href='javascript:ShowLocation({2})'><em>{0} - <strong>{1}</strong></em><span>{4}</span>{5}</a>";
var descriptionFormat = "<span class='Desc'>{0}</span>";
//var swfFormat = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="FlashMapContainer" width="{width}" height="{height}" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="{path}" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="{path}" loop="false" menu="false" quality="high" bgcolor="#ffffff" width="{width}" height="{height}" swLiveConnect=true id="FlashMapContainer" name="FlashMapContainer" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
var swfFormat =   '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="FlashMapContainer" width="{width}" height="{height}" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="{path}" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="{path}" loop="false" menu="false" quality="high" bgcolor="#ffffff" width="{width}" height="{height}" swLiveConnect=true id="FlashMapContainer" name="FlashMapContainer" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
var emailFormat = "Name={0}&Email={1}&City={2}&WorkPhone={3}&MobilePhone={4}&Comments={5}&FirstLearn={6}&ContactAtWork={7}&PreferredSuburb={8}&PotentialSite={9}";
var genericEmailFormat = "Name={0}&Email={1}&City={2}&WorkPhone={3}&Fax={4}&Comments={5}&Address={6}&City={7}";

var overlayFormat = "<div style='padding: 0px 0px 15px;'>"; //url({4}) 99% 50% no-repeat;'>";
overlayFormat += "<strong>{0}</strong>";
overlayFormat += "<span style='display: block;'>{1}</span>";
overlayFormat += "Status: <span style='color: {2};'><strong>{3}</strong></span>";
overlayFormat += "<span style='display: block; color: #99b3cc; margin-top: 5px;'>{5}</span>";
overlayFormat += "</div>";

var locationData = {};
locationData["NSW"] = new Array();
locationData["VIC"] = new Array();
locationData["QLD"] = new Array();
locationData["TAS"] = new Array();
locationData["SA"] = new Array();
locationData["WA"] = new Array();
locationData["NT"] = new Array();
locationData["ALL"] = new Array();

var AusX = -25.274398;
var AusY = 133.775136;
var NswX = -32.831001;
var NswY = 150.139008;
var VicX = -36.5588;
var VicY = 145.468994;
var NTX = -19.228177;
var NTY = 135.395508;
var SAX = -32.0289;
var SAY = 135.001999;
var WAX = -24.413299;
var WAY = 121.079002;
var QldX = -19.7061;
var QldY = 145.774002;
var TasX = -41.707199;
var TasY = 146.149002;

var map = null;
var googleMapInitialized = false;
var googleMapApiLoaded = false;
var mapXml = null;

var iconPaths = {};
iconPaths["Sold"] = "http://www.everywhereinternet.com/EIImages/IconEI-Sold.png";
iconPaths["Under Offer"] = "http://www.everywhereinternet.com/EIImages/IconEI-UnderOffer.png";
iconPaths["Available"] = "http://www.everywhereinternet.com/EIImages/IconEI-Available.png";
iconPaths["Trading - Available"] = "http://www.everywhereinternet.com/EIImages/IconEI-Available.png";

var iconClasses = {};
iconClasses["Sold"] = "Sold";
iconClasses["Under Offer"] = "UnderOffer";
iconClasses["Available"] = "Available";
iconClasses["Trading - Available"] = "Available";

var statusClasses = {};
statusClasses["Sold"] = "StatusSold";
statusClasses["Under Offer"] = "StatusUnderOffer";
statusClasses["Available"] = "StatusAvailable";
statusClasses["Trading - Available"] = "StatusAvailable";

var statusColours = {};
statusColours["Sold"] = "#cd3d3d";
statusColours["Under Offer"] = "#4282be";
statusColours["Available"] = "#57a457";
statusColours["Trading - Available"] = "#57a457";

var statusImages = {};
statusImages["Sold"] = "http://www.everywhereinternet.com/EIImages/IconEI-Sold.png";
statusImages["Under Offer"] = "http://www.everywhereinternet.com/EIImages/IconEI-UnderOffer.png";
statusImages["Available"] = "http://www.everywhereinternet.com/EIImages/IconEI-Available.png";
statusImages["Trading - Available"] = "http://www.everywhereinternet.com/EIImages/IconEI-Available.png";

var FlashContainer = null;
var MapData = null;
var MapContainer = null;
var WebsiteForm = null;
var TextContainer = null;
var ScrollContainer = null;
var MainContainer = null;

var MapContainerSlider = null;
var FlashContainerSlider = null;
var WebsiteFormSlider = null;
var Scroller = null;

var SortMessage = null;
var SortByAvailableLink = null;
var SortByUnderOfferLink = null;
var SortBySoldLink = null;
var SortByAzLink = null;

var QueryFranchise = null;
var QueryWiFi = null;
var QueryGeneral = null;

var PreferredSuburbRequired = null;
var CityRequired = null;
var EmailRequired = null;
var MobileRequired = null;
var WorkPhoneRequired = null;
var FullNameRequired = null;
var HumanCaptchaRequired = null;

var PreferedSuburbYes = null;

var FirstLearnItem = null;
var ContactAtWorkItem = null;
var HavePreferredSuburbItem = null;
var PotentialSiteItem = null;

var FullNameItem = null;
var WorkPhoneItem = null;
var MobileItem = null;
var PhoneItem = null;
var FaxItem = null;
var EmailItem = null;
var AddressItem = null;
var CityItem = null;
var PreferredSuburbItem = null;
var HumanCaptchaItem1 = null;
var HumanCaptchaItem2 = null;

var FullNameErrorItem = null;
var WorkPhoneErrorItem  = null;
var MobileErrorItem  = null;
var PhoneErrorItem = null;
var FaxErrorItem = null;
var EmailErrorItem = null;
var AddressErrorItem = null;
var CityErrorItem = null;
var PreferredSuburbErrorItem = null;

var ContactExtraInfo = null;

var EmailSendErrorItem = null;
var EmailSendSuccessItem = null;
var EmailSubmitItem = null;
var EmailProcessingItem = null;

var locationsHtmlByAvailable = "";
var locationsHtmlByUnderOffer = "";
var locationsHtmlBySold = "";
var locationsHtmlByTrading = "";
var locationsHtml = "";

var mapInitialized = false;
var qX = null;
var qY = null;

function ShowLocation(index) {
	
	if (map) { map.closeInfoWindow(); }
	
	var data = locationData["ALL"][index];
	if (data && data.X && data.Y) {
		map.setCenter(new GLatLng(data.X, data.Y), 13);
		if (data.Marker) {
		    data.Marker.openInfoWindowHtml(data.Html);
		}		
	}
}

function SortBy(str) {

	if (str=="Available") {
		MapData.innerHTML = locationsHtmlByAvailable;
	} else if (str=="UnderOffer") {
		MapData.innerHTML = locationsHtmlByUnderOffer;	
	} else if (str=="Sold") {
		MapData.innerHTML = locationsHtmlBySold;	
	} else if (str=="Az") {
	    MapData.innerHTML = locationsHtml;	
	}

}

function ShowStateLocations(state) {
	
	var links = $("Toolbar").getElementsByTagName("a");
	for (var i=0; i<links.length; i++) {
		var link = links[i];
		if (link.href.indexOf(state)>-1) {
			link.className = "Selected";
		} else {
			link.className = "";
		}
	}
	
    SortMessage.style.display = "none";
    SortByAvailableLink.style.display = "none";
    SortByUnderOfferLink.style.display = "none";
    SortBySoldLink.style.display = "none";
    SortByAzLink.style.display = "none";	
		
	if (state!="Back" && state!="Contact" && state!="Franchises") {
		
		if (googleMapApiLoaded && !googleMapInitialized) {
		    InitializeGoogleMap(); 
		}
		
		ScrollTo(2000, 0, "GMap");
		MapData.className = "States " + state;
		switch (state) {
			case "ALL": map.setCenter(new GLatLng(AusX, AusY), 4); break;
			case "NSW": map.setCenter(new GLatLng(NswX, NswY), 6); break;
			case "VIC": map.setCenter(new GLatLng(VicX, VicY), 6); break;
			case "QLD": map.setCenter(new GLatLng(QldX, QldY), 6); break;
			case "NT": map.setCenter(new GLatLng(NTX, NTY), 6); break;
			case "SA": map.setCenter(new GLatLng(SAX, SAY), 6); break;
			case "WA": map.setCenter(new GLatLng(WAX, WAY), 6); break;
			case "TAS": map.setCenter(new GLatLng(TasX, TasY), 6); break;
		}
		
        SortMessage.style.display = "block";
        SortByAvailableLink.style.display = "block";
        SortByUnderOfferLink.style.display = "block";
        SortBySoldLink.style.display = "block";
        SortByAzLink.style.display = "block";		
		
	} else if (state=="Back") {
		ScrollTo(1000, 0, "AMap");
	} else if (state=="Contact") {
		ScrollTo(3000, 0, "Contact");
	} else if (state=="Franchises") {
		ScrollTo(0, 0, "Home");	
	}
	
	if (window.gecko) {
	    ShowHideFormValues(state);
	}
}

function ScrollTo(x, y, ref) {
    
    if (window.gecko) {
        if (ref=="Contact") {
            if (TextContainer) { TextContainer.setStyle('visibility', 'hidden'); }
            if (WebsiteForm) { WebsiteForm.setStyle('visibility', 'visible');  }
            if (MapContainer) { MapContainer.setStyle('visibility', 'hidden');  }
            if (FlashContainer) { FlashContainer.setStyle('visibility', 'hidden'); }
        } else if (ref=="GMap") {
            if (TextContainer) { TextContainer.setStyle('visibility', 'hidden');  }
            if (WebsiteForm) { WebsiteForm.setStyle('visibility', 'hidden');  }
            if (MapContainer) { MapContainer.setStyle('visibility', 'visible');  }
            if (FlashContainer) { FlashContainer.setStyle('visibility', 'hidden');  }         
        } else if (ref=="AMap") {
            if (TextContainer) { TextContainer.setStyle('visibility', 'hidden');  }
            if (WebsiteForm) { WebsiteForm.setStyle('visibility', 'hidden');  }
            if (MapContainer) { MapContainer.setStyle('visibility', 'hidden');  }
            if (FlashContainer) { FlashContainer.setStyle('visibility', 'visible');  } 
        } else if (ref=="Home") {
            if (TextContainer) { TextContainer.setStyle('visibility', 'visible');  }
            if (WebsiteForm) { WebsiteForm.setStyle('visibility', 'hidden'); }
            if (MapContainer) { MapContainer.setStyle('visibility', 'hidden'); } 
            if (FlashContainer) { FlashContainer.setStyle('visibility', 'hidden');  }
        }
    } else {
        Scroller.scrollTo(x, y);
    }
}

function InitializeFlash() {
    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="FlashMapContainer" width="550" height="400" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="FlashMapContainer.swf" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="FlashMapContainer.swf" loop="false" menu="false" quality="high" bgcolor="#ffffff" width="550" height="400" swLiveConnect=true id="FlashMapContainer" name="FlashMapContainer" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>');
}

function GoogleMapApiLoaded() {
	googleMapApiLoaded = true;
	$("MapContainer").style.background = "none";
}

function InitializeGoogleMap() {
	if (GBrowserIsCompatible()) {
		map = new GMap2($("Map"));
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        map.addControl(new GOverviewMapControl());
        map.addControl(new GScaleControl());
        map.setCenter(new GLatLng(AusX, AusY), 4);
        googleMapInitialized = true;
        InitializeLocations();
	}
}

function ShowAll() {

	MapData.className = "States";
	
	$("Toolbar").style.visibility = "visible";
	
	if (!window.gecko) {
	    FlashContainer.style.visibility = "visible";
	    MapContainer.style.visibility = "visible";
	    WebsiteForm.style.visibility = "visible";
	    TextContainer.style.visibility = "visible";
	}
	
	ShowStateLocations("Franchises");

}


function PreferredSuburbChanged() {
	if (!PreferredSuburbItem) { PreferredSuburbItem = $("PreferredSuburbItem"); }
	if (!PreferedSuburbYes) { PreferedSuburbYes = $("PreferedSuburbYes"); }
	PreferredSuburbItem.setStyle('display', PreferedSuburbYes.checked ? 'block' : 'none');
}




function SendEmailData() {
	
	var ok = false;
	
	var generalMode = QueryWiFi.checked||QueryGeneral.checked;
	
	var nameOk = CheckDataValues("FullName");
	
	var emailOk = CheckDataValues("Email");
	if (emailOk) { 
	    emailOk = CheckDataValues("Email", EmailPattern, ERROR_Email); 
	}	
	
	if (generalMode) {
	    ok = nameOk && emailOk;
	} else {	    
	    var cityOk = CheckDataValues("City");
	    var workphoneOk = CheckDataValues("WorkPhone", PhonePattern, ERROR_Phone);
	    var mobileOk = CheckDataValues("Mobile", PhonePattern, ERROR_Mobile);
	    var suburbOk = true;
	    if (PreferedSuburbYes.checked) {
		    suburbOk = CheckDataValues("PreferredSuburb");
	    }	    
	    ok = nameOk && emailOk && cityOk && suburbOk && workphoneOk && mobileOk;
	}

	//var ok = generalMode ? (nameOk && emailOk && cityOk && suburbOk && workphoneOk && mobileOk) : ();
	
	if (ok) {
		CheckCaptcha();
	}
	
}

function CheckCaptcha() {

	//var challenge = Recaptcha.get_challenge();
	//var response = Recaptcha.get_response();
	var humanErrorItem = $("HumanErrorItem");
	var txtCaptcha = $("HumanCaptcha").value;
	
	function CaptchaSuccess() {
		ReloadCaptcha();
		var response = this.response["text"];
		var ok = response=="OK!";
		if (ok) {
			humanErrorItem.style.display = "none";
			SendEMail();
		} else {
			humanErrorItem.style.display = "block";
			humanErrorItem.innerHTML = liFormat.replace(/\{0\}/, ERROR_Human);
			ShowSubmit();
		}
	}
	
	function CaptchaFailed() {
		ReloadCaptcha();
		humanErrorItem.style.display = "block";
		humanErrorItem.innerHTML = liFormat.replace(/\{0\}/, ERROR_HumanService);
		ShowSubmit();
	}
	
	HideSubmit();
	
	var myXHR = new XHR({
		method: 'post',
		onSuccess: CaptchaSuccess,
		onFailure: CaptchaFailed
	}).send(captchaPath, 'txtCaptcha=' + txtCaptcha);

}

function SendEMail() {

	function EmailSuccess() {
		var response = this.response["text"];
		var ok = response=="OK!";
		EmailSendSuccessItem.style.display = ok ? "block" : "none";
		EmailProcessingItem.style.display = "none";
		if (ok) {
			$("FullName").value = "";
			$("Email").value = "";
			$("City").value = "";
			$("WorkPhone").value = "";
			$("Mobile").value = "";
			$("Comments").value = "";
			$("Where").value = "";
			$("ContactAtWorkYes").checked = false;
			$("ContactAtWorkNo").checked = false;
			$("PreferredSuburb").value = "";
			//$("PotentialSite").value = "";
			ShowSubmit();
		} else {
			EmailFailed();
		}		
	}
	
	function EmailFailed() {
	    EmailSendErrorItem.innerHTML = liFormat.replace(/\{0\}/, ERROR_SendEmail);		
	    EmailSendErrorItem.style.display = "block";
        ShowSubmit();
	}

	var generalMode = QueryWiFi.checked||QueryGeneral.checked;
	var emailParams = "";
	
	if (generalMode) {
	    emailParams = genericEmailFormat
		.replace(/\{0\}/, $("FullName").value)
		.replace(/\{1\}/, $("Email").value)
		.replace(/\{2\}/, $("City").value)
		.replace(/\{3\}/, $("Phone").value)
		.replace(/\{4\}/, $("Fax").value)
		.replace(/\{5\}/, $("Comments").value)
		.replace(/\{6\}/, $("Address").value);	
	} else {
        emailParams = emailFormat
	    .replace(/\{0\}/, $("FullName").value)
	    .replace(/\{1\}/, $("Email").value)
	    .replace(/\{2\}/, $("City").value)
	    .replace(/\{3\}/, $("WorkPhone").value)
	    .replace(/\{4\}/, $("Mobile").value)
	    .replace(/\{5\}/, $("Comments").value)
	    .replace(/\{6\}/, $("Where").value)
	    .replace(/\{7\}/, $("ContactAtWorkYes").checked ? "Yes" : "No")
	    .replace(/\{8\}/, $("PreferredSuburb").value)
	    //.replace(/\{9\}/, $("PotentialSite").value);
	}
	
	EmailProcessingItem.style.display = "block";
	
	HideSubmit();
	
	var emailPath = "";
	
	if (QueryFranchise.checked) {
	    emailPath = franchiseEmailPath;
	} else if (QueryWiFi.checked) {
	    emailPath = operationalEmailPath;
	} else if (QueryGeneral.checked) {
	    emailPath = genericEmailPath;
	}
	
	if (emailPath) {
	    var myXHR = new XHR({
		    method: 'post',
		    onSuccess: EmailSuccess,
		    onFailure: EmailFailed
	    }).send(emailPath, emailParams);			
	} else {
	    EmailFailed();
	}
		
}

function HideSubmit() {
	EmailSubmitItem.style.display = "none";
	EmailSendSuccessItem.style.display = "none";
	EmailSendErrorItem.style.display = "none";
	EmailProcessingItem.style.display = "none";
}

function ShowSubmit() {	
	EmailSubmitItem.style.display = "block";
	EmailProcessingItem.style.display = "none";
}

function CheckDataValues(id, pattern, errorMessage, transform) {
	
	var item = $(id);
	var itemRef = $(id+"Item");
	var errorItemRef = $(id+"ErrorItem");
	var ok = false;
	
	if (transform) {
		if (transform=="U") { 
			item.value = item.value.toUpperCase();
		} else if (transform=="L") { 
			item.value = item.value.toLowerCase();
		}
	}
	
	if (pattern) {
		ok = item.value.match(pattern);
		errorItemRef.innerHTML = liFormat.replace(/\{0\}/, errorMessage || "");//errorMessage || "";
	} else {
		ok = (item.value.trim()!="");
		//errorItemRef.innerHTML = ERROR_Required;
		errorItemRef.innerHTML = liFormat.replace(/\{0\}/, ERROR_Required);
	}
	
	if (ok) { 
		itemRef.className = itemRef.className.replace(/\s?Error/, ""); 
	} else {
		itemRef.className += " Error";
	}
	
	errorItemRef.style.display = ok ? "none" : "block";
	itemRef.error = !ok;
	
	return ok;
	
}

function ShowHideFormValues(mode) {

    var generalMode = QueryWiFi.checked||QueryGeneral.checked;

    FullNameItem.className = FullNameItem.className.replace(/\s?Error/, "");
    WorkPhoneItem.className = WorkPhoneItem.className.replace(/\s?Error/, "");
    MobileItem.className = MobileItem.className.replace(/\s?Error/, "");
    PhoneItem.className = PhoneItem.className.replace(/\s?Error/, "");
    FaxItem.className = FaxItem.className.replace(/\s?Error/, "");
    EmailItem.className = EmailItem.className.replace(/\s?Error/, "");
    AddressItem.className = AddressItem.className.replace(/\s?Error/, "");
    CityItem.className = CityItem.className.replace(/\s?Error/, "");
    //PreferredSuburbItem.className = PreferredSuburbItem.className.replace(/\s?Error/, "");
    
    PreferredSuburbRequired.style.visibility = generalMode ? "hidden" : "visible";
    CityRequired.style.visibility = generalMode ? "hidden" : "visible";
    //EmailRequired.style.visibility = generalMode ? "hidden" : "visible";
    MobileRequired.style.visibility = generalMode ? "hidden" : "visible";
    WorkPhoneRequired.style.visibility = generalMode ? "hidden" : "visible";
    
    //alert (WorkPhoneRequired.style.visibility);
    //FullNameRequired.style.visibility = generalMode ? "hidden" : "visible";
    
    PhoneItem.style.display = generalMode ? "block" : "none"; 
    FaxItem.style.display = generalMode ? "block" : "none"; 
    AddressItem.style.display = generalMode ? "block" : "none";     
    WorkPhoneItem.style.display = generalMode ? "none" : "block"; 
    MobileItem.style.display = generalMode ? "none" : "block";     
            
    FullNameErrorItem.style.display = "none";
    WorkPhoneErrorItem.style.display = "none";
    MobileErrorItem.style.display = "none";
    PhoneErrorItem.style.display = "none";
    FaxErrorItem.style.display = "none";
    EmailErrorItem.style.display = "none";
    AddressErrorItem.style.display = "none";
    CityErrorItem.style.display = "none";
    //PreferredSuburbErrorItem.style.display = "none";
    
    ContactExtraInfo.style.display = generalMode ? "none" : "block"; 
    
    if (window.gecko && mode && mode!="Contact") {
        PreferredSuburbRequired.style.visibility = "hidden";
        CityRequired.style.visibility = "hidden";
        //EmailRequired.style.visibility = "hidden"; generalMode ? "hidden" : "visible";
        MobileRequired.style.visibility = "hidden";
        WorkPhoneRequired.style.visibility = "hidden";  
    }
    
}

function ReloadCaptcha() {
	$("HumanCaptchaImage").src = captchaReloadPath.replace(/\{0\}/, (new Date()));
}

function InitializeComplete() {

	ReloadCaptcha();
	
	googleMapApiLoaded = true;

	ScrollContainer = $("ScrollContainer");
	MainContainer = $("MainContainer");
	MapData = $("MapData");
	MapContainer = $("MapContainer");
	FlashContainer = $("FlashContainer");
	WebsiteForm = $("WebsiteForm");
	TextContainer = $("TextContainer");
	
    SortMessage = $("SortMessage");
    SortByAvailableLink = $("SortByAvailableLink");
    SortByUnderOfferLink = $("SortByUnderOfferLink");
    SortBySoldLink = $("SortBySoldLink");
    SortByAzLink = $("SortByAzLink");	
    
    QueryFranchise = $("QueryFranchise");
    QueryWiFi = $("QueryWiFi");
    QueryGeneral = $("QueryGeneral"); 
    
    PreferredSuburbRequired = $("PreferredSuburbRequired");
    CityRequired = $("CityRequired");
    EmailRequired = $("EmailRequired");
    MobileRequired = $("MobileRequired");
    WorkPhoneRequired = $("WorkPhoneRequired");
    FullNameRequired = $("FullNameRequired");  
	HumanCaptchaRequired = $("HumanCaptchaRequired");
    
    PreferredSuburbItem = $("PreferredSuburbItem");    
    FirstLearnItem = $("FirstLearnItem");    
    ContactAtWorkItem = $("ContactAtWorkItem");    
    HavePreferredSuburbItem = $("HavePreferredSuburbItem");    
    PreferredSuburbErrorItem = $("PreferredSuburbErrorItem");    
    PotentialSiteItem = $("PotentialSiteItem"); 
    
    FullNameItem = $("FullNameItem");
    WorkPhoneItem = $("WorkPhoneItem");
    MobileItem = $("MobileItem");       
    PhoneItem = $("PhoneItem");    
    FaxItem = $("FaxItem");
    EmailItem = $("EmailItem");
    AddressItem = $("AddressItem");
    CityItem = $("CityItem");
    PreferredSuburbItem = $("PreferredSuburbItem");
	HumanCaptchaItem1 = $("HumanCaptchaItem1");
	HumanCaptchaItem2 = $("HumanCaptchaItem2");
            
    FullNameErrorItem = $("FullNameErrorItem");
    WorkPhoneErrorItem = $("WorkPhoneErrorItem");
    MobileErrorItem = $("MobileErrorItem");
    PhoneErrorItem = $("PhoneErrorItem");    
    FaxErrorItem = $("FaxErrorItem");
    EmailErrorItem = $("EmailErrorItem");    
    AddressErrorItem = $("AddressErrorItem");
    CityErrorItem = $("CityErrorItem");
    PreferredSuburbErrorItem = $("PreferredSuburbErrorItem");
    
    ContactExtraInfo = $("ContactExtraInfo");
    
	EmailSendErrorItem = $("EmailSendErrorItem");
	EmailSendSuccessItem = $("EmailSendSuccessItem");
	EmailSubmitItem = $("EmailSubmitItem");
	EmailProcessingItem = $("EmailProcessingItem");	    
    
    QueryFranchise.checked = true;   
    QueryFranchise.onclick = ShowHideFormValues;    
    QueryWiFi.onclick = ShowHideFormValues; 
    QueryGeneral.onclick = ShowHideFormValues; 
    
    ShowHideFormValues("Back");    
	
	if (window.gecko) {
	    TextContainer.setStyle('left', 0);
	    MapContainer.setStyle('left', 0);
	    FlashContainer.setStyle('left', 0);
	    WebsiteForm.setStyle('left', 0);
	    TextContainer.setStyle('visibility', 'hidden');
	    MapContainer.setStyle('visibility', 'hidden');
	    FlashContainer.setStyle('visibility', 'hidden');
	    WebsiteForm.setStyle('visibility', 'hidden');
	}
	
	if (!window.gecko) {
	    Scroller = new Fx.Scroll('MainContainer', {
		    wait: false,
		    duration: 500,
		    offset: {x:0, y:0},
		    transition: Fx.Transitions.Quad.easeInOut
	    });
	}	
	
	var suburbInput = $("PreferredSuburb");
	var PreferedSuburbYes = $("PreferedSuburbYes");
	
	var indicator2 = new Element('div', {'class': 'autocompleter-loading', 'styles': {'display': 'none'}}).setHTML('').injectAfter(suburbInput);
	var completer2 = new Autocompleter.Ajax.Json(suburbInput, postcodePath, {
		
		'onRequest': function(el) {
			indicator2.setStyle('display', '');
		},
		
		'onComplete': function(el) {
			indicator2.setStyle('display', 'none');
		},
				
		'ajaxOptions': { method: 'get' } ,
		
		'injectNode' : window.gecko ? document.body : ScrollContainer
		
	});
	
	var cityInput = $("City");
	var indicator3 = new Element('div', {'class': 'autocompleter-loading', 'styles': {'display': 'none'}}).setHTML('').injectAfter(cityInput);
	var completer3 = new Autocompleter.Ajax.Json(cityInput, postcodePath, {
		
		'onRequest': function(el) {
			indicator3.setStyle('display', '');
		},
		
		'onComplete': function(el) {
			indicator3.setStyle('display', 'none');
		},
		
		'ajaxOptions': { method: 'get' },
		
		'injectNode' : window.gecko ? document.body : ScrollContainer
	});
	
	thiz.PreferredSuburbChanged();
    	
	var myXHR = new XHR({
		method: 'get',
		onSuccess: ProcessLocations,
		onFailure: LocationsLoadError
	}).send('EIData/LocationData.xml?date'+new Date());
	

	
	function ProcessLocations() {
		mapXml = this.response["xml"].documentElement;
		setTimeout("ShowAll();", 1000);
	}
	
	function LocationsLoadError() {
		//alert ("Error");
	}

}

	function InitializeLocations() {
		
		locationsHtmlByTrading = "";
		locationsHtmlByAvailable = "";
		locationsHtmlByUnderOffer = "";
		locationsHtmlBySold = "";
				
		locationsHtml = "";
		var locations = mapXml.getElementsByTagName("Location");
		
		for (var i=0; i<locations.length; i++) {
			var node = locations[i];
			var obj = {};
			obj.State = GetNodeData(node, "State").toUpperCase();
			obj.Id = GetNodeData(node, "Id");
			obj.Name = GetNodeData(node, "Name");
			obj.Postcode = GetNodeData(node, "Postcode");
			obj.Status = GetNodeData(node, "Status");
			obj.Coordinates = GetNodeData(node, "Coordinates");
			obj.Address = GetNodeData(node, "Address");
			obj.Description = GetNodeData(node, "Description");
			obj.X = 0;
			obj.Y = 0;
			if (obj.Coordinates.indexOf(",")>0) {
				var coords = obj.Coordinates.split(",");
				if (coords.length==2) {
					obj.X = coords[0];
					obj.Y = coords[1];				
					
					if (map) {
						var html = "";
						var address = (obj.Address ? obj.Address : "") + (obj.State ? ("<br />" + obj.State) : "") + (obj.Postcode ? ((obj.State ? " " : "<br />") + obj.Postcode) : "");
						html = overlayFormat.replace(/\{0\}/, obj.Name).replace(/\{1\}/, address).replace(/\{2\}/, statusColours[obj.Status] || "#000000").replace(/\{3\}/, obj.Status).replace(/\{4\}/, statusImages[obj.Status] || "").replace(/\{5\}/, obj.Description || "").replace(/\[BR\]/g, "<br />");
						
						
//						html += "<strong>" + obj.Name + "</strong>";
//						if (obj.State) { html += "<br />" + obj.State; }
//						if (obj.Postcode) { html += (obj.State ? " " : "<br />") + obj.Postcode; }
//						if (obj.Status) { html += "<br />Status: " + obj.Status; }
						
						var marker = CreateMarker(obj, html);
					    obj.Marker = marker;
					    obj.Html = html;						
						map.addOverlay(marker);
					}
				}
			}			
			if (obj.State) {
				if (obj.State=="ACT") { obj.State = "NSW"; }				
				// var locationFormat = "<a class=\"{3}\" href='javascript:ShowLocation({2})'><em>{0} - <strong>{1}</strong></em><span>{4}</span></a>";
				var address = obj.Address || (obj.State + " " + obj.Postcode);
				locationData[obj.State].push(obj);
				
				
				
				var locationHtml = locationFormat.replace(/\{0\}/, (obj.Name)).replace(/\{1\}/, obj.Status).replace(/\{2\}/, locationData["ALL"].length).replace(/\{3\}/, obj.State + " " + (iconClasses[obj.Status] || "")).replace(/\{4\}/, address).replace(/\{5\}/, descriptionFormat.replace(/\{0\}/, obj.Description) || "").replace(/\[BR\]/g, "<br />");
													 
				locationsHtml += locationHtml;

				if (obj.Status=="Trading - Available") {
					 locationsHtmlByTrading += locationHtml;
				} else if (obj.Status=="Available") {
					locationsHtmlByAvailable += locationHtml;
				} else if (obj.Status=="Under Offer") {
					locationsHtmlByUnderOffer += locationHtml;
				} else if (obj.Status=="Sold") {
					locationsHtmlBySold += locationHtml;				
				}
				
				locationData["ALL"].push(obj);
				
			}
		}
		
		var tmpA = locationsHtmlByAvailable + locationsHtmlByTrading;
		var tmpU = locationsHtmlByUnderOffer;
		var tmpS = locationsHtmlBySold;
		
		locationsHtmlByAvailable = tmpA + tmpU + tmpS;
		locationsHtmlBySold = tmpS + tmpA + tmpU;
		locationsHtmlByUnderOffer = tmpU + tmpA + tmpS;

		MapData.innerHTML = locationsHtml;
		
	}

	function CreateMarker(obj, html) {
		var point = new GLatLng(obj.X, obj.Y);
		var baseIcon = new GIcon();
		baseIcon.shadow = "http://www.everywhereinternet.com/Franchises/FImages/Icon-Shadow.png";
		baseIcon.image = iconPaths[obj.Status] || "http://www.everywhereinternet.com/Franchises/FImages/Icon-Shadow.png";
		baseIcon.iconSize = new GSize(29, 36);
		baseIcon.shadowSize = new GSize(29, 36);
		baseIcon.iconAnchor = new GPoint(5, 35);
		baseIcon.infoWindowAnchor = new GPoint(5, 35);
		baseIcon.infoShadowAnchor = new GPoint(5, 35);
		var marker = new GMarker(point, { icon:baseIcon });
		
		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(html);
		});
				
		return marker;
	}
	
	function GetNodeData(node, tag) {
		var value = "";
		var tagnode = node.getElementsByTagName(tag);
		if (tagnode.length>0) {
			if (tagnode[0].firstChild) {
				value = tagnode[0].firstChild.nodeValue;
			}
		}
		return value;
	}