var bSkipSeachLookup = false;
var iSelectedSuburbID = -1;

/* ======================================================================= */
/* ==   User naviagtion stuff                                           == */
/* ======================================================================= */

function FormSubmit(sDestintion)
	{
		document.frmMain.sPageAction.value = sDestintion;
		document.frmMain.submit();
	}

function ShowSection(iState, iCategory)
	{
		document.frmMain.iTargetCat.value = iCategory;
		document.frmMain.iTargetState.value = iState;
		FormSubmit('SectionChange');
	}
					
function CheckKey(WindowEvents) 
    {
     
        var iKeyNumber;
        
        if (window.event) { iKeyNumber = window.event.keyCode; } else { iKeyNumber = WindowEvents.which; }
           
	    if (iKeyNumber == 13 || iKeyNumber == 10)
		    {
			    iKeyNumber.returnValue = 0;
		    }
    }
				
function CheckFormEnter(WindowEvents) 
{
    var iKeyNumber;
    
    if (window.event) { iKeyNumber = window.event.keyCode; } else { iKeyNumber = WindowEvents.which; }

	if (parseInt(iKeyNumber) == 13)
		{
			CheckAndSubmitHomeForm(document.frmMain.txtKeywords.value);
		}
}

function CheckArtistFormEnter(WindowEvents) 
{
    var iKeyNumber;
    
    if (window.event) { iKeyNumber = window.event.keyCode; } else { iKeyNumber = WindowEvents.which; }

	if (parseInt(iKeyNumber) == 13)
		{
			CheckAndSubmitArtistSearch(document.frmMain.txtSearchKeywords.value);
		}
}

function CheckAndSubmitHomeForm(sCheckValue) {

	// Make sure that we have something in the text box to start with
	var iCheck;
	var iCharCount = 0;
	var bIsError = false;
	var sSearchErrorText = '';
	
	for (iCheck = 0; iCheck < sCheckValue.length; iCheck++)
		{	
			switch (sCheckValue.substr(iCheck, 1).toUpperCase())
				{
					case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': 
						iCharCount++;
						break;
					case '%':
					    sSearchErrorText = 'Wildcard searching is not permitted.'
						bIsError = true;
						break;
					case '*':
					    sSearchErrorText = 'Wildcard searching is not permitted.'
						bIsError = true;
						break;
					default:
						break;  // Do not increment character counter
				}															
			if (bIsError == true)
				{
					break;
				}
		}

    // Do we have any search criteria //
	// if ((iCharCount == 0) && (bIsError == false))
	//	{
	//	    sSearchErrorText += '\nYou have not entered any keywords to search on.'
	//	}
    
    // Make sure that we have selected either CBD, Regional, or both to search on //
    if (document.frmMain.chkSearchIncludes)
        {
            if ((document.frmMain.chkSearchIncludes[0].checked == false) && (document.frmMain.chkSearchIncludes[1].checked == false))
                {
                    sSearchErrorText += '\nYou have not selected CBD and/or regional locations. That would result in no matches.';            
                }                    
        }
    else
        {
            sSearchErrorText += '\nSearch error';
        }                    
    
    // If we have radius, then do we have all of the fields completed //
    if (document.getElementById('LimitRadius').checked == true)
        {
            // We have selected to use a radius //
            if (document.frmMain.txtRadius.value == '')
                {
                    sSearchErrorText += '\nYou have selected to limit by radius, but not entered a distance.';
                }
            else
                {
                    // Is the distance numeric?
                    if (isNaN(document.frmMain.txtRadius.value))
                        {
                            sSearchErrorText += '\nThe entered radius distance is not a number.';
                        }
                }

           // Do we have either postcode or suburb selected //
           if ((document.getElementById('RadiusPostcode').checked != true) && (document.getElementById('RadiusSuburb').checked != true))
            {
                sSearchErrorText += '\nPlease select either postcode or suburb to limit your radius on.'; 
            }

           // Do we have a starting point selected //
           if (document.frmMain.txtRadiusStart.value == '')
            {
                sSearchErrorText += '\nNo start point has been selected for your radius search'; 
            }
          else
            {
                // We do have something in the start point, but is it valid //
                if (document.getElementById('RadiusSuburb').checked == true)
                    {
                        // We are looking for a suburb, so we should have a suburb id //
                        if (iSelectedSuburbID == -1) { sSearchErrorText += '\nInvalid start suburb selected for your radius search.'; }
                    }
                else
                    {
                        // This is a postcode search, so look for the info bar to test for validity //
                        if (document.getElementById('SuburbList').display != 'none')
                            {
                                // Info bar is shown, so check it
                                if (document.getElementById('SuburbList').innerHTML.indexOf('No suburbs') > -1)
                                    {
                                        sSearchErrorText += '\nInvalid postcode entered for your radius search.'; 
                                    }
                            }
                        else
                            {
                                // Info bar is not shown, so assume problem //
                                sSearchErrorText += '\nInvalid postcode entered for your radius search.'; 
                            }                            
                    }                    
            }            
        }
        
    // Work out what to do now //		
    if (sSearchErrorText != '')
        {
            // Error //
            alert(sSearchErrorText);
        }
	else
		{
            // No error //
            document.frmMain.hidSearchSuburbID.value = iSelectedSuburbID;
			FormSubmit('KeywordSearch');
		}
}

function CheckAndSubmitArtistSearch(sCheckValue) {

	// Make sure that we have something in the text box to start with
	var iCheck;
	var iCharCount = 0;
	var bIsError = false;
	var sSearchErrorText = '';
	
	for (iCheck = 0; iCheck < sCheckValue.length; iCheck++)
		{	
			switch (sCheckValue.substr(iCheck, 1).toUpperCase())
				{
					case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': 
						iCharCount++;
						break;
					case '%':
					    sSearchErrorText = 'Wildcard searching is not permitted.'
						bIsError = true;
						break;
					case '*':
					    sSearchErrorText = 'Wildcard searching is not permitted.'
						bIsError = true;
						break;
					default:
						break;  // Do not increment character counter
				}															
			if (bIsError == true)
				{
					break;
				}
		}

    // Do we have any search criteria //
	// if ((iCharCount == 0) && (bIsError == false))
	// 	{
	//	    sSearchErrorText += '\nYou have not entered any keywords to search on.'
	//	}
    
    // Make sure that we have selected at least one of the supplied output types //
    if (document.frmMain.chkSearchType)
        {
            if (document.frmMain.chkSearchType.length)  
                {
                    // There are multiple fields
                    var bHaveSelection = false;
                    
                    for (iCheckBoxes = 0; iCheckBoxes < document.frmMain.chkSearchType.length; iCheckBoxes ++)
                        {
                            if (document.frmMain.chkSearchType[iCheckBoxes].checked == true)
                                {
                                    bHaveSelection = true;
                                }
                        }

                    if (!bHaveSelection) 
                        {
                            sSearchErrorText += '\nYou have not selected to include any supplied artwork types. That would result in no matches.';                
                        }                        
                }
            else
                {
                    // There is a single field
                    if (document.frmMain.chkSearchType.checked == false) 
                        {
                            sSearchErrorText += '\nYou have not selected to include any supplied artwork types. That would result in no matches.';                
                        }
                }                
                
        }
    else
        {
            sSearchErrorText += '\nSearch error';
        }                    
    
    // Work out what to do now //		
    if (sSearchErrorText != '')
        {
            // Error //
            alert(sSearchErrorText);
        }
	else
		{
            // No error //
			FormSubmit('ArtistSearch');
		}
}

/* ======================================================================= */
/* ==   Saved search functions                                          == */
/* ======================================================================= */
function RunSavedSearch()
    {
    
        if (document.frmMain.cmbSavedSearches)
            {
                if (document.frmMain.cmbSavedSearches[document.frmMain.cmbSavedSearches.selectedIndex].value == -1)
                    {
                        alert('Please select a saved search from the list to use.');
                    }
                else
                    {
                        // Valid item //
                        document.frmMain.hidSSID.value = document.frmMain.cmbSavedSearches[document.frmMain.cmbSavedSearches.selectedIndex].value;
                        FormSubmit('RunSavedSearch');
                    }
            }
    }

function SSLogin()
    {
        window.location.href = '/UserRegistration.asp';
    }    

/* ======================================================================= */
/* ==   Tab handling                                                    == */
/* ======================================================================= */

var asPagePanelItems = new Array();
var iPagePanelCounter = 0;
var sPagePanelIDStart = 'Header';
var sSearchPanelActiveTabName = '';
var sInactiveTabClassName = 'TabInActive';
var sActiveTabClassName = 'TabActive';
var sHighlightTabClassName = 'TabHover';

function AddPagePanelItem(ItemIDTrailer)
    {
        asPagePanelItems[iPagePanelCounter] = ItemIDTrailer;
        iPagePanelCounter++;    
    }

function SetActiveTab(sTabID)
    {
        sSearchPanelActiveTabName = sTabID;    
    }

function SetTabClassNames(Active, InActive, Hover)
    {
        sInactiveTabClassName = InActive;
        sActiveTabClassName = Active;
        sHighlightTabClassName = Hover;
    }

function SetPagePanelIDStarter(Starter)
    {
        sPagePanelIDStart = Starter;
    }
        
function HighlightSearchTab(sCurrentTab, IsHighlight)
    {
        var iTabLoop; 
 
        // Reset the tabs completely
        for (iTabLoop = 0; iTabLoop < asPagePanelItems.length; iTabLoop++)
            {
                if (asPagePanelItems[iTabLoop] == sSearchPanelActiveTabName)
                    {
                        // This is the currently selected tab
                        if (document.getElementById(sPagePanelIDStart + asPagePanelItems[iTabLoop])) { document.getElementById(sPagePanelIDStart + asPagePanelItems[iTabLoop]).className = sActiveTabClassName; }
                    }
                else
                    {
                        // Not the selected tab
                        if (document.getElementById(sPagePanelIDStart + asPagePanelItems[iTabLoop])) { document.getElementById(sPagePanelIDStart + asPagePanelItems[iTabLoop]).className = sInactiveTabClassName; } 
                    }
            }
        
        // Are we highlighting?
        if (parseInt(IsHighlight))
            {
                if (document.getElementById(sPagePanelIDStart + sCurrentTab)) { document.getElementById(sPagePanelIDStart + sCurrentTab).className = sHighlightTabClassName; }
            }
    }

function ShowSearchTab(sNewTabID)
    {
    
        // Hide all of the tabs first //
        var iTabLoop;
        
        for (iTabLoop = 0; iTabLoop < asPagePanelItems.length; iTabLoop ++)
            {
                if (document.getElementById(asPagePanelItems[iTabLoop])) 
                    { 
                        document.getElementById(asPagePanelItems[iTabLoop]).style.display = 'none'; 
                        HighlightSearchTab(asPagePanelItems[iTabLoop], 0)
                    }
            }

        // Now show the one that we want
        if (document.getElementById(sNewTabID)) 
            {
                document.getElementById(sNewTabID).style.display = 'block';
                SetActiveTab (sNewTabID); 
                HighlightSearchTab(sNewTabID);
            }
    }


/* ======================================================================= */
/* ==   News ticker                                                     == */
/* ======================================================================= */

var asNewsTickerItems = new Array() // Contains a list of NewsTickerItem objects
var iNewsTickerItemCount = 0;
var bNewsTickerIsPaused = false;
var iCurrentTickerItem = 0;
var iNewsItemScrollTime = 10000;

function AddNewsTickerItem(HeadlineText, NewsItemDate)
    {
    
        var asNewsTickerItem = new Array()
        
        asNewsTickerItem[0] = HeadlineText;
        asNewsTickerItem[1] = NewsItemDate;
        
        asNewsTickerItems[iNewsTickerItemCount] = asNewsTickerItem;
        iNewsTickerItemCount++;
    }

function StartTicker()
    {
        // Make sure that we don't go out of bounds of the array //
        if (iCurrentTickerItem > (iNewsTickerItemCount - 1)) { iCurrentTickerItem = 0; }
        
        // Get the details of the current item //
        var asCurrentNewsItem = new Array()
        asCurrentNewsItem = asNewsTickerItems[iCurrentTickerItem];

        
        // Show the current item //
        if (document.getElementById('NewsTicker'))
            {
                document.getElementById('NewsTicker').innerHTML = '<strong>Latest news : </strong>' + asCurrentNewsItem[1] + ' - ' + asCurrentNewsItem[0]; 
            }

        // Set up for the next item //
        iCurrentTickerItem++;
        
        var iNewsRepeatID
        iNewsRepeatID = window.setTimeout("StartTicker()", iNewsItemScrollTime); 
    }

/* ======================================================================= */
/* ==   User poll                                                       == */
/* ======================================================================= */
    
var MaxPollResultPixelWidth = 100

function SetMaxPollPixelWidth(iWidth)
    {
        MaxPollResultPixelWidth = iWidth;
    }
    
function getPollResults(PollID, SelectedAnswerID)
    {  
        
        var xmlHttpPoll;
        try
            {    // Firefox, Opera 8.0+, Safari    
                 xmlHttpPoll=new XMLHttpRequest();    
            }
        catch (e)
            {    
                 // Internet Explorer    
                 try
                    {      
                        xmlHttpPoll=new ActiveXObject("Msxml2.XMLHTTP");      
                    }
                catch (e)
                    {      
                        try
                            {        
                                xmlHttpPoll=new ActiveXObject("Microsoft.XMLHTTP");        
                            }
                        catch (e)
                            {        
                                alert("Your browser does not support AJAX!");        
                                return false;        
                            }      
                     }    
             }

        xmlHttpPoll.onreadystatechange=function()
            {
                if(xmlHttpPoll.readyState==4)
                    {
                        // Process the results that we get from our call
                        var sResultText = xmlHttpPoll.responseText;
                        
                        // Sort out the information panel
                        if (document.getElementById('pollInfo'))
                            {
                                document.getElementById('pollInfo').innerHTML = '&nbsp;';
                            }
                                       
                        // Trim off the spurious script block from the reply
                        if (sResultText.indexOf("/script")  > -1)
                            {
                                sResultText = sResultText.substr(sResultText.indexOf("/script") + 8);
                            }
                        
                        // Trim off the spaces and things
                        var sResultText = sResultText.replace(/^\s+|\s+$/g, '')

                        // Clear down the items in the voting panel
                        if (document.getElementById('pollPanel'))
                            {
                                document.getElementById('pollPanel').innerHTML = '';
                            }
                            
                        // Split the result up into the individual items
                        var asItemList = sResultText.split('|')
                        
                        // Make sure we know how much space each percentage point is worth
                        var iPercentWidth = (MaxPollResultPixelWidth / 100)

                        // Loop through the items that we have 
                        var iLoop;
                        
                        for (iLoop = 0; iLoop < asItemList.length; iLoop++)
                            {
                                // Split up the individual item (AnswerID~AnswerText~VoteCount~Percentage)
                                asSingleItem = asItemList[iLoop].split('~');
                                
                                CreateResultItem(asSingleItem[1], asSingleItem[2], asSingleItem[3], iPercentWidth);
                            }

                    }
            }

        // Sort out the information panel
        if (document.getElementById('pollInfo'))
            {
                document.getElementById('pollInfo').innerHTML = 'Submitting answer. Please wait ...';
            }
   
        // Make the main request
        xmlHttpPoll.open('GET','PollResults.asp?PollID=' + PollID + '&AnswerID=' + SelectedAnswerID ,true);
        xmlHttpPoll.send(null);  
    }          
    
function CreateResultItem(AnswerText, VoteCount, Percentage, PercentWidth)
    {
        
        if (document.getElementById('pollPanel'))
            {
                var ItemText = document.createElement('span');
                //ItemText.setAttribute('class', '');
                ItemText.innerHTML = AnswerText;
                
                var CharSpace = document.createElement('span');
                CharSpace.innerHtml = '&nbsp;'
                
                var LineSpace = document.createElement('br');
                var LineSpace2 = document.createElement('br');
                var LineSpace3 = document.createElement('br');
                
                var VoteText = document.createElement('span');
                VoteText.setAttribute("className", "HelpText");
                VoteText.setAttribute("class", "HelpText");
                VoteText.innerHTML = ' (' + VoteCount + ' votes)';
                
                var OnImage = document.createElement('img');
                OnImage.setAttribute('src', '/Images/GaugeOn.gif');
                OnImage.setAttribute('height', 10);
                OnImage.setAttribute('width', (PercentWidth * Percentage));
                
                var OffImage = document.createElement('img');
                OffImage.setAttribute('src', '/Images/GaugeOff.gif');
                OffImage.setAttribute('height', 10);
                OffImage.setAttribute('width', (PercentWidth * (100 - Percentage)) );
                
                document.getElementById('pollPanel').appendChild(ItemText);
                document.getElementById('pollPanel').appendChild(LineSpace);
                document.getElementById('pollPanel').appendChild(OnImage);
                document.getElementById('pollPanel').appendChild(OffImage);
                document.getElementById('pollPanel').appendChild(LineSpace3);
                document.getElementById('pollPanel').appendChild(VoteText);
                document.getElementById('pollPanel').appendChild(LineSpace2);
                
            }
    }

/* ======================================================================= */
/* ==   General functions                                               == */
/* ======================================================================= */
function WaypointLogin()
    {
        window.location.href = '/UserRegistration.asp?ItemID=' + document.frmMain.hidAID.value + '&ItemTitle=' + document.frmMain.hidActName.value;
    }

function CheckNumeric(TextField)
    {
    
        if (TextField.value != '')
            {
                if (isNaN(TextField.value))
                    {
                        // Not a number //
                        alert('This field can only contain numbers.');
                        TextField.value = TextField.value.substr(0, TextField.value.length - 1);
                    }
            }
    }

function getTodayAsShortDate() {

        var objToday = new Date();
        var sMonthName = '';
        var iMonthNumber = objToday.getMonth();

        switch (iMonthNumber) {
            case 1: sMonthName = 'Jan'; break;
            case 2: sMonthName = 'Feb'; break;
            case 3: sMonthName = 'Mar'; break;
            case 4: sMonthName = 'Apr'; break;
            case 5: sMonthName = 'May'; break;
            case 6: sMonthName = 'Jun'; break;
            case 7: sMonthName = 'Jul'; break;
            case 8: sMonthName = 'aug'; break;
            case 9: sMonthName = 'Sep'; break;
            case 10: sMonthName = 'Oct'; break;
            case 11: sMonthName = 'Nov'; break;
            case 12: sMonthName = 'Dec'; break;

        }

        var iDayNumber = objToday.getDate();
        if (iDayNumber < 10) { iDayNumber = '0' + iDayNumber; }

        return iDayNumber + ' ' + sMonthName + ' ' + objToday.getFullYear(); 

    }

function readQueryStringValue(parameterName) {

        q = location.search;

        if (q.indexOf(parameterName) >= 0) {
            var pntr = q.indexOf(parameterName) + parameterName.length + 1;
                if (q.indexOf("&", pntr) >= 0) {
                    return q.substring(pntr, q.indexOf("&", pntr));
                } else {
                    return q.substring(pntr, q.length);
                }
            } else {
                return null;
            }

        return getParam; 
    }

function selectComboValue(comboObject, valueToSelect) {


    if (comboObject) {

        for (findValue = 0; findValue < comboObject.options.length; findValue++) {

            if (comboObject.options[findValue].value == valueToSelect) {

                comboObject.options[findValue].selected = true; 
                break; 

            }

        }

    }

}

/* ======================================================================= */
/* ==   Cookie handling functions                                       == */
/* ======================================================================= */
function setCookie(parameterName, parameterValue, daysToExpiry) {

    var expiryDate = new Date();

    expiryDate.setDate(expiryDate.getDate() + daysToExpiry);
    document.cookie = parameterName + "=" + escape(parameterValue) + ((daysToExpiry == null) ? "" : ";expires=" + expiryDate.toGMTString());
}

function getCookie(parameterName) {

    if (document.cookie.length > 0) {
        
        var parameterLocation = document.cookie.indexOf(parameterName + "=");
        if (parameterLocation != -1) {
            parameterLocation = parameterLocation + parameterName.length + 1;
            var parameterLocationEnd = document.cookie.indexOf(";", parameterLocation);
            if (parameterLocationEnd == -1) parameterLocationEnd = document.cookie.length;
            
            return unescape(document.cookie.substring(parameterLocation, parameterLocationEnd));
        }
    }
    return '';
}
    
/* ======================================================================= */
/* ==   Search entry functions                                          == */
/* ======================================================================= */
function EnableRadiusSearchFields()
    {
    
        // Enable the radius fields if the limit box is checked //
        if (document.getElementById('LimitRadius'))
            {
                if (document.getElementById('RadiusPostcode')) { document.getElementById('RadiusPostcode').disabled = (!document.getElementById('LimitRadius').checked == true) ? 'disabled' : ''; }
                if (document.getElementById('RadiusSuburb')) { document.getElementById('RadiusSuburb').disabled = (!document.getElementById('LimitRadius').checked == true) ? 'disabled' : ''; }
                if (document.getElementById('RadiusDistance')) { document.getElementById('RadiusDistance').disabled = (!document.getElementById('LimitRadius').checked == true) ? 'disabled' : ''; }
                if (document.getElementById('RadiusStart')) { document.getElementById('RadiusStart').disabled = (!document.getElementById('LimitRadius').checked == true) ? 'disabled' : ''; }
                
                if (document.getElementById('PostcodeLabel')) { document.getElementById('PostcodeLabel').style.color = (!document.getElementById('LimitRadius').checked == true) ? '#cccccc' : '#000000'; }
                if (document.getElementById('SuburbLabel')) { document.getElementById('SuburbLabel').style.color = (!document.getElementById('LimitRadius').checked == true) ? '#cccccc' : '#000000'; }
                if (document.getElementById('RadiusText')) { document.getElementById('RadiusText').style.color = (!document.getElementById('LimitRadius').checked == true) ? '#cccccc' : '#000000'; }
            }
    }    

function GetRadiusLookup(SearchField)    
    {
    
        // Use the AJAX function to build a list of suburbs that start with the entered text (for the specified state) //
        if (document.getElementById('LimitRadius'))
            {
                if (document.getElementById('LimitRadius').checked == true)
                    {
                        // We are looking to do the radius search //
                        var iStateID = -1;
                        
                        // Work out which state we are interested in //
                        if (document.frmMain.cmbSearchState)
                            {
                                iStateID = document.frmMain.cmbSearchState[document.frmMain.cmbSearchState.selectedIndex].value;
                            }        

                        // If we have some text in the field then we can do our lookup //
                        if ((SearchField.value != '') && (document.getElementById('RadiusSuburb').checked == true))
                            {
                                var xmlHttp;
                                try
                                    {    // Firefox, Opera 8.0+, Safari    
                                         xmlHttp=new XMLHttpRequest();    
                                    }
                                catch (e)
                                    {    
                                         // Internet Explorer    
                                         try
                                            {      
                                                xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
                                            }
                                        catch (e)
                                            {      
                                                try
                                                    {        
                                                        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
                                                    }
                                                catch (e)
                                                    {        
                                                        alert("Your browser does not support AJAX!");        
                                                        return false;        
                                                    }      
                                             }    
                                     }

                                xmlHttp.onreadystatechange=function()
                                    {
                                        if(xmlHttp.readyState==4)
                                            {
                                                // Process the results that we get from our call
                                                var sResultText = xmlHttp.responseText;
                                                
                                                // Trim off the spurious script block from the reply
                                                if (sResultText.indexOf("/script")  > -1)
                                                    {
                                                        sResultText = sResultText.substr(sResultText.indexOf("/script") + 8);
                                                    }
                                                    
                                                // Trim off the spaces and things
                                                var sResultText = sResultText.replace(/^\s+|\s+$/g, '')

                                                // Split the result up into the individual items
                                                var asItemList = sResultText.split('|')

                                                // Show the lookup field //
                                                var objLookupArea;
                                                
                                                if (document.getElementById('RadiusLookupArea'))
                                                    {
                                                        // Clear down any items that are currently in the DIV //
                                                        objLookupArea = document.getElementById('RadiusLookupArea');
                                                        objLookupArea.innerHTML = '';
                                                        
                                                        // Show the lookup area in the correct place //
                                                        objLookupArea.style.top = 603;
                                                        objLookupArea.style.left = 610;
                                                        objLookupArea.style.width = 210; //SearchField.style.width;
                                                        objLookupArea.style.display = 'block';
                                                        
                                                        // alert(objLookupArea.style.width);
                                                    }
                                                    
                                                // Loop through the items that we have and add them to the map
                                                if (sResultText != '')
                                                    {
                                                        var iLoop;
                                                        
                                                        for (iLoop = 0; iLoop < asItemList.length; iLoop++)
                                                            {
                                                                // Split up the individual item (ID~Title~Lat~Long~Synopsis~ImagePath)
                                                                asSingleItem = asItemList[iLoop].split('~');
                                                                
                                                                var objNewSuburbItem = document.createElement('div');
                                                                objNewSuburbItem.setAttribute('id', 'LookupSuburb_' + asSingleItem[0]);
                                                                objNewSuburbItem.innerHTML = asSingleItem[1];
                                                                objNewSuburbItem.style.cursor = 'pointer';
                                                                
                                                                objNewSuburbItem.onmouseover = function() 
                                                                    {
                                                                        // Highlight the selected item //
                                                                        this.style.backgroundColor = '#cccccc';                                                                            
                                                                    }
                                                                    
                                                                objNewSuburbItem.onmouseout = function()
                                                                    {
                                                                        // De-Highlight the selected item //
                                                                        this.style.backgroundColor = '#ffffff';                                                                            
                                                                    }
                                                                
                                                                objNewSuburbItem.onclick = function() 
                                                                    {  
                                                                        bSkipSeachLookup = true;
                                                                        document.frmMain.txtRadiusStart.value = this.innerHTML;
                                                                        iSelectedSuburbID = this.getAttribute('id');
                                                                        bSkipSeachLookup = false;
                                                                        
                                                                        document.getElementById('RadiusLookupArea').style.display = 'none';
                                                                    }
                                                                
                                                                objLookupArea.appendChild(objNewSuburbItem);
                                                            }
                                                
                                                    }
                                                else
                                                    {
                                                        // No matching items found //
                                                        objLookupArea.innerHTML = '<span style="color:#cccccc; text-decoration:italic;">There are no matching suburbs</span>';
                                                    }                                                    
                                            }
                                    }

                                    // Make the main request - pass the map bounds (split out) to the read page
                                    if (!bSkipSeachLookup)
                                        {
                                            xmlHttp.open('GET','LookupSuburb.asp?SID=' + iStateID + '&StartChars=' + SearchField.value + '&ms=' + new Date().getTime(),true);
                                            xmlHttp.send(null);  
                                
                                        }
                            }                            
                        else
                            {
                                // No text entered //
                                if (document.getElementById('RadiusLookupArea')) { document.getElementById('RadiusLookupArea').style.display = 'none'; }
                                bSkipSeachLookup = false;
                                iSelectedSuburbID = -1;   
                                
                                // Is this a postcode search //
                                if (document.getElementById('RadiusPostcode').checked == true)
                                    {
                                        CheckNumeric(document.frmMain.txtRadiusStart);
                                        
                                        if (document.frmMain.txtRadiusStart.value.length > 4)
                                            {
                                                alert('Postcodes can only be a maximum 4 numbers long.'); 
                                                document.frmMain.txtRadiusStart.value = document.frmMain.txtRadiusStart.value.substr(0, 4);
                                            }
                                    }        
                            }                            
                    }
            }
    }
    
function ValidateRadiusText(SearchField)
    {
    
        // Is this a valid thing to test //
        if ((document.getElementById('RadiusPostcode').checked == true) && (SearchField.value != '') && (!isNaN(SearchField.value)))
            {
                // Show that we are looking up the postcodes //
                if (document.getElementById('SuburbList'))
                    { 
                        document.getElementById('SuburbList').style.display = 'block';
                        document.getElementById('SuburbList').innerHTML = 'Validating postcode, please wait ...'; 
                    }

                // Do the validation //
                var xmlHttp;
                try
                    {    // Firefox, Opera 8.0+, Safari    
                         xmlHttp=new XMLHttpRequest();    
                    }
                catch (e)
                    {    
                         // Internet Explorer    
                         try
                            {      
                                xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
                            }
                        catch (e)
                            {      
                                try
                                    {        
                                        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
                                    }
                                catch (e)
                                    {        
                                        alert("Your browser does not support AJAX!");        
                                        return false;        
                                    }      
                             }    
                     }

                xmlHttp.onreadystatechange=function()
                    {
                        if(xmlHttp.readyState==4)
                            {
                                // Process the results that we get from our call
                                var sResultText = xmlHttp.responseText;
                                
                                // Trim off the spurious script block from the reply
                                if (sResultText.indexOf("/script")  > -1)
                                    {
                                        sResultText = sResultText.substr(sResultText.indexOf("/script") + 8);
                                    }
                                    
                                // Trim off the spaces and things
                                var sResultText = sResultText.replace(/^\s+|\s+$/g, '')

                                // Show the result field //
                                if (document.getElementById('SuburbList'))
                                    {
                                        document.getElementById('SuburbList').style.display = 'block';
                                        
                                        if (sResultText != '')
                                            {
                                                // We have a result //
                                                document.getElementById('SuburbList').innerHTML = sResultText;
                                            }
                                        else
                                            {
                                                document.getElementById('SuburbList').innerHTML = '<span class="GeneralRed">No suburbs found for the postcode entered, please check the postcode</span>';
                                            }
                                    }

                            }
                    }

                    // Make the main request
                    xmlHttp.open('GET','GetSuburbFromPostcode.asp?PCode=' + document.frmMain.txtRadiusStart.value + '&ms=' + new Date().getTime(),true);
                    xmlHttp.send(null);  
            }
        else
            {
                // No need to check now //
                if (document.getElementById('SuburbList')) { document.getElementById('SuburbList').style.display = 'none'; }
            }            
    }   

function ChangeRadiusSearchOption()
    {
        if (document.getElementById('SuburbList')) { document.getElementById('SuburbList').style.display = 'none'; }
        document.frmMain.txtRadiusStart.value = ''; 
        iSelectedSuburbID = -1;
        bSkipSeachLookup = false;
    }
    
function RunEventSearch(FieldKey)
    {
    
        // Make sure that there are no wildcards in the search field //
        var iCheckWC; 
        var sKWFieldName = 'document.frmMain.txtEventSearchKW_' + FieldKey
        var sCheckValue = ''; 
        var bIsError = false;
        
        if (eval(sKWFieldName))
            {
                sCheckValue = eval(sKWFieldName + '.value');
                
	            for (iCheckWC = 0; iCheckWC < sCheckValue.length; iCheckWC++)
		            {	
			            switch (sCheckValue.substr(iCheckWC, 1).toUpperCase())
				            {
					            case '%':
					            case '*':
						            bIsError = true;
						            break;
					            default:
						            break;  // Do not increment character counter
				            }															
			            if (bIsError == true)
				            {
					            break;
				            }
		            }

                if (bIsError)
                    {
                        // Wildcard in the search string //
                        alert('Wildcard searching is not permitted, please remove all % and * characters from your search.');
                    }
                else
                    {
                        // Good to search //
                        var iESStateID = eval('document.frmMain.cmbEventSearchState_' + FieldKey + '[document.frmMain.cmbEventSearchState_' + FieldKey + '.selectedIndex].value');
                        var iESFromDay = eval('document.frmMain.cmbEventSearchFromDay_' + FieldKey + '[document.frmMain.cmbEventSearchFromDay_' + FieldKey + '.selectedIndex].value');
                        var iESFromMonth = eval('document.frmMain.cmbEventSearchFromMonth_' + FieldKey + '[document.frmMain.cmbEventSearchFromMonth_' + FieldKey + '.selectedIndex].value');
                        var iESFromYear = eval('document.frmMain.cmbEventSearchFromYear_' + FieldKey + '[document.frmMain.cmbEventSearchFromYear_' + FieldKey + '.selectedIndex].value');
                        var iESToDay = eval('document.frmMain.cmbEventSearchToDay_' + FieldKey + '[document.frmMain.cmbEventSearchToDay_' + FieldKey + '.selectedIndex].value');
                        var iESToMonth = eval('document.frmMain.cmbEventSearchToMonth_' + FieldKey + '[document.frmMain.cmbEventSearchToMonth_' + FieldKey + '.selectedIndex].value');
                        var iESToYear = eval('document.frmMain.cmbEventSearchToYear_' + FieldKey + '[document.frmMain.cmbEventSearchToYear_' + FieldKey + '.selectedIndex].value');
                        
                        window.location.href='/EventSearch.asp?SID=' + iESStateID + '&FD=' + iESFromDay + '&FM=' + iESFromMonth + '&FY=' + iESFromYear + '&TD=' + iESToDay + '&TM=' + iESToMonth + '&TY=' + iESToYear + '&KW=' + sCheckValue;
                    }		            

		    }
        else
            {
                alert('A problem has occurred which has prevented your search from being conducted. Please try again later.');
            }		    
		        
    }
