/* Global */
var currentPage = null;
var currentSubMenu = null;
var currentDropMenu = null;
function addEvent( e, ev, fnc )
{
    if( document.getElementById && !document.all ) e.addEventListener( ev, fnc, true );
    else if( document.all ) e.attachEvent( "on" + ev, fnc );
}
function eventSrc( ev )
{
    if( document.all ) return ev.srcElement;
    else return ev.target;
}
function stopPropagation( ev ) 
{ 
    if( ev == null ) return;
    ev = ev || event;
    ev.stopPropagation? ev.stopPropagation() : ev.cancelBubble = true; 
} 
function load()
{	
    var mainMenu = document.getElementById( "main_menu" );
    var base = document.getElementById( "base" );
    var footer = document.getElementById( "footer" );

    loadingHide();
    mainMenu.style.display = "block";
    base.style.display = "block";
    footer.style.display = "block";
    if( new String( window.location ).indexOf( "?" ) != -1 ) propertiesInspectionOpen( new String( window.location ).split( "?" )[ 1 ] );
    else homeWelcomeOpen();
}
function loadingShow()
{
    var loading = document.getElementById( "loading" ); 

    loading.style.display = "block";
}
function loadingHide()
{
    var loading = document.getElementById( "loading" );

    loading.style.display = "none";
}
function extrasShow( image, propertyExtras, searchResultExtras )
{
    var extras = document.getElementById( "extras" );
    var extraTitle = document.getElementById( "extra_title" );
    var printPropertySummaryExtraButton = document.getElementById( "print_property_summary_extra_button" );
    var printSearchResultsExtraButton = document.getElementById( "print_search_results_extra_button" );
    var friendExtraButton = document.getElementById( "friend_extra_button" );
    var similarExtraButton = document.getElementById( "similar_extra_button" );
    
    extras.style.display = "block";
    extraTitle.style.background = "url(/resources/" + image + ")";
    printPropertySummaryExtraButton.style.display = propertyExtras ? "block" : "none";
    printSearchResultsExtraButton.style.display = searchResultExtras ? "block" : "none";
    friendExtraButton.style.display = propertyExtras ? "block" : "none";
    similarExtraButton.style.display = propertyExtras ? "block" : "none";
}
function extrasHide()
{
    var extras = document.getElementById( "extras" );
    
    extras.style.display = "none";
}
function pageSelect( page )
{
    if( currentPage != null ) currentPage.style.display = "none";
    currentPage = page;
    if( currentPage != null )
    {
        currentPage.style.display = "block";
        new Silk( currentPage, "opacity", null, 1, null, 0.2, 1, null );
    }
}
function subMenuSelect( subMenu )
{
    var fnc = function()
    {
        currentSubMenu = subMenu;
        if( currentSubMenu != null )
        {
            currentSubMenu.style.display = "block";
            new Silk( currentSubMenu, "opacity", null, 1, null, 0.2, 1, null );
        }
    };
    if( currentSubMenu != null )
    {
        currentSubMenu.style.display = "block";
        new Silk( currentSubMenu, "opacity", null, 0, null, 0.2, 1, function()
        {
            currentSubMenu.style.display = "none";
            fnc();
        } );
    }
    else fnc();
}
function dropMenuSelect( dropMenu )
{
    var fnc = function()
    {
        currentDropMenu = dropMenu;
        if( currentDropMenu != null )
        {
            currentDropMenu.style.display = "block";
            new Silk( currentDropMenu, "opacity", null, 1, null, 0.2, 1, null );
        }
    };
    if( currentDropMenu != null )
    {
        currentDropMenu.style.display = "block";
        new Silk( currentDropMenu, "opacity", null, 0, null, 0.2, 1, function()
        {
            currentDropMenu.style.display = "none";
            fnc();
        } );
    }
    else fnc(); 
}
function mainMenuItemOver( mainMenuItem, force )
{
    if( mainMenuItem == null ) return;
    for( var i = 0; i < mainMenuItem.childNodes.length; i ++ ) if( mainMenuItem.childNodes[ i ].className == "main_menu_item_label" ) mainMenuItem.childNodes[ i ].style.borderBottomColor = "rgb(255,55,55)";
}
function mainMenuItemOut( mainMenuItem, force )
{
    if( mainMenuItem == null ) return;
    for( var i = 0; i < mainMenuItem.childNodes.length; i ++ ) if( mainMenuItem.childNodes[ i ].className == "main_menu_item_label" ) mainMenuItem.childNodes[ i ].style.borderBottomColor = "rgb(0,0,0)";
}
function buttonOver( button )
{
    button.style.textDecoration = "underline";
}
function buttonOut( button )
{
    button.style.textDecoration = "none";
}
function propertyOver( property )
{
    new Silk( property, "opacity", null, 0.5, null, 0.1, 1, null );
}
function propertyOut( property )
{
    new Silk( property, "opacity", null, 1, null, 0.1, 1, null );
}
function subMenuItemOver( subMenuItem )
{
    subMenuItem.style.background = "rgb(222,222,255)";
}
function subMenuItemOut( subMenuItem )
{
    subMenuItem.style.background = "rgb(255,255,255)";
}
function dropMenuItemOver( dropMenuItem )
{
    dropMenuItem.style.background = "rgb(222,222,255)";
}
function dropMenuItemOut( dropMenuItem )
{
    dropMenuItem.style.background = "rgb(255,255,255)";
}
function extraButtonOver( text )
{
    var extraLabel = document.getElementById( "extra_label" );
    
    while( extraLabel.hasChildNodes() ) extraLabel.removeChild( extraLabel.firstChild );
    extraLabel.appendChild( document.createTextNode( text ) );
}
function extraButtonOut()
{
    var extraLabel = document.getElementById( "extra_label" );
    
    while( extraLabel.hasChildNodes() ) extraLabel.removeChild( extraLabel.firstChild );
}

/* Home */
function homeWelcomeOpen()
{
    var page = document.getElementById( "home_welcome_page" );
    var intro = document.getElementById( "home_welcome_intro" );

    extrasHide();
    intro.style.width = "0px";
    intro.style.backgroundPosition = "0px -100px"
    intro.style.top = "100px";
    intro.style.height = "10px";
    pageSelect( page );
    new Silk( intro, "width", null, 850, "px", 20, 1, function()
    {
        new Silk( intro, "background-position", "0px ", 0, "px", 5, 1, null );
        new Silk( intro, "top", null, 0, "px", 5, 1, null );
        new Silk( intro, "height", null, 200, "px", 9, 1, null );
    } );
}

/* Company */
function companyCorporateProfileOpen()
{
    var page = document.getElementById( "company_corporate_profile_page" );
   
    extrasShow( "company.jpg", false, false );
    pageSelect( page, null );
}
function companyOurVisionOpen()
{
    var page = document.getElementById( "company_our_vision_page" );
    
    extrasShow( "company.jpg", false, false );
    pageSelect( page, null );
}
function companyOurMissionOpen()
{
    var page = document.getElementById( "company_our_mission_page" );
    
    extrasShow( "company.jpg", false, false );
    pageSelect( page, null );
}
function companyAboutUsOpen()
{
    var page = document.getElementById( "company_about_us_page" );

    extrasShow( "company.jpg", false, false );
    pageSelect( page, null );
}
function companyMarketingOpen()
{
    var page = document.getElementById( "company_marketing_page" );

    extrasShow( "company.jpg", false, false );
    pageSelect( page, null );
}
function companySalesAndLeasingOpen()
{
    var page = document.getElementById( "company_sales_and_leasing_page" );

    extrasShow( "company.jpg", false, false );
    pageSelect( page, null );
}
function companyAssetManagementOpen()
{
    var page = document.getElementById( "company_asset_management_page" );

    extrasShow( "company.jpg", false, false );
    pageSelect( page, null );
}
function companyBuyersAgencyOpen()
{
    var page = document.getElementById( "company_buyers_agency_page" );

    extrasShow( "company.jpg", false, false );
    pageSelect( page, null );
}
function companyAuctionServicesOpen()
{
    var page = document.getElementById( "company_auction_services_page" );

    extrasShow( "company.jpg", false, false );
    pageSelect( page, null );
}
function companyIndustryContactsOpen()
{
    var page = document.getElementById( "company_industry_contacts_page" );

    extrasShow( "company.jpg", false, false );
    pageSelect( page, null );
}
function companyCorporateBrochureOpen()
{
    var page = document.getElementById( "company_corporate_brochure_page" );

    extrasShow( "company.jpg", false, false );
    pageSelect( page, null );
}
function companyCorporateBrochureError(){
	alert("Name Required and either Phone or Email required!");
}

function companyCorporateBrochureSubmit()
{
    var name = document.getElementById( "company_corporate_brochure_name" );
    var phone = document.getElementById( "company_corporate_brochure_phone" );
    var email = document.getElementById( "company_corporate_brochure_email" );
    
    if(name.value == '' || name.value == null){
    	companyCorporateBrochureError();
    	return null;
    }
    else{
    	if((phone.value != '' && phone.value != null  ) || (email.value != '' && email.value != null )){
		}
		else{
			companyCorporateBrochureError();
			return null;
		}
    }


    loadingShow();
    ajaxSend( "/global/services/meta3.1.aspx", "<request><command>get_items</command><session>hinterland_commercial</session><table>email</table></request>", function( responseXml )
    {
        var corporateBrochureRequestsValue = responseXml.getElementsByTagName( "corporate_brochure_requests" )[ 0 ].firstChild.nodeValue;
        
        ajaxSend( "/global/services/proto1.5.aspx", "<request><command>smtp_send</command><to>" + ajaxEncode( corporateBrochureRequestsValue ) + "</to><subject>Corporate Brochure Request</subject><message>" + ajaxEncode( "Name :: " + name.value + "\r\nPhone :: " + phone.value + "\r\nEmail :: " + email.value ) + "</message></request>", function()
        {
            alert( "Your request has been submitted. Thankyou." );
            window.open('/resources/brochure.pdf','brochure','') 
            companyCorporateBrochureClear();
            loadingHide();
        } );
    } );
}
function companyCorporateBrochureClear()
{
    var name = document.getElementById( "company_corporate_brochure_name" );
    var phone = document.getElementById( "company_corporate_brochure_phone" );
    var email = document.getElementById( "company_corporate_brochure_email" );
    
    name.value = "";
    phone.value = "";
    email.value = "";
}

/* Properties */
var propertiesCurrentProperty = null;
var propertiesPageCount = 0;
var propertiesCurrentPage = 0;
var propertiesSearchConditions = null;
var propertiesSearchSort = null;
function propertiesSearchOpen( categoryValue )
{
    var page = document.getElementById( "properties_search_page" );
    var category = document.getElementById( "properties_search_category" );

    extrasShow( "listings.jpg", false, false );
    if( categoryValue != null ) category.value = categoryValue;
    pageSelect( page );
}
function propertiesSearchClear()
{
    var type = document.getElementById( "properties_search_type" );
    var suburb = document.getElementById( "properties_search_suburb" );
    var priceMinimum = document.getElementById( "properties_search_price_minimum" );
    var priceMaximum = document.getElementById( "properties_search_price_maximum" );
    var sortBy = document.getElementById( "properties_search_sort_by" );
    
    type.value = "";
    suburb.value = "";
    priceMinimum.value = "";
    priceMaximum.value = "";
    sortBy.value = "PriceVal"; 
}
function propertiesSearchSearch()
{
    var category = document.getElementById( "properties_search_category" );
    var type = document.getElementById( "properties_search_type" );
    var suburb = document.getElementById( "properties_search_suburb" );
    var priceMinimum = document.getElementById( "properties_search_price_minimum" );
    var priceMaximum = document.getElementById( "properties_search_price_maximum" );
    var sortBy = document.getElementById( "properties_search_sort_by" ); 

    propertiesCurrentPage = 0;
    propertiesSearchConditions = "<condition><field>MainCategory</field><operator>equal_to</operator><operand>Commercial</operand></condition>";
    propertiesSearchConditions += ( category.value == "buying" || category.value == "both" ? ( propertiesSearchConditions == "" ?  "" : "<link>and</link>" ) + "<condition><field>ForSale</field><operator>equal_to</operator><operand>y</operand></condition>" : "" );
    propertiesSearchConditions += ( category.value == "leasing" || category.value == "both" ? ( propertiesSearchConditions == "" ?  "" : "<link>and</link>" ) + "<condition><field>ForLease</field><operator>equal_to</operator><operand>y</operand></condition>" : "" );
    propertiesSearchConditions += ( type.value == "" ? "" : ( propertiesSearchConditions == "" ?  "" : "<link>and</link>" ) + "<condition><field>SubCategory</field><operator>equal_to</operator><operand>" + type.value + "</operand></condition>" );
    propertiesSearchConditions += ( suburb.value == "" ? "" : ( propertiesSearchConditions == "" ?  "" : "<link>and</link>" ) + "<condition><field>Suburb</field><operator>equal_to</operator><operand>" + suburb.value + "</operand></condition>" );
    propertiesSearchConditions += ( priceMinimum.value == "" ? "" : ( propertiesSearchConditions == "" ?  "" : "<link>and</link>" ) + "<condition><field>" + ( category.value == "buying" ? "Price" : "Lease" ) + "Val</field><operator>greater_than</operator><operand>" + priceMinimum.value + "</operand><link>or</link><field>" + ( category.value == "buying" ? "Price" : "Lease" ) + "Val</field><operator>equal_to</operator><operand>" + priceMinimum.value + "</operand></condition>" );
    propertiesSearchConditions += ( priceMaximum.value == "" ? "" : ( propertiesSearchConditions == "" ?  "" : "<link>and</link>" ) + "<condition><field>" + ( category.value == "buying" ? "Price" : "Lease" ) + "Val</field><operator>less_than</operator><operand>" + priceMaximum.value + "</operand><link>or</link><field>" + ( category.value == "buying" ? "Price" : "Lease" ) + "Val</field><operator>equal_to</operator><operand>" + priceMaximum.value + "</operand></condition>" );
    propertiesSearchSort = ( sortBy.value != "" ? "<order><field>" + sortBy.value + "</field><direction>ascending</direction></order>" : "" );
    loadingShow();
    ajaxSend( "/global/services/meta3.1.aspx", "<request><session>hinterland_commercial</session><command>get_items</command><table>Listings</table><start>" + ( propertiesCurrentPage * 8 ) + "</start><count>8</count><condition>" + propertiesSearchConditions + "</condition>" + propertiesSearchSort + "</request>", propertiesSearchResponse );
}
function propertiesSearchResponse( responseXml )
{
    var category = document.getElementById( "properties_search_category" );
    var propertyTemplate = document.getElementById( "property_template" );
    var target = document.getElementById( "properties_results_target" );
    var nextButton = document.getElementById( "properties_results_next_button" );
    var previousButton = document.getElementById( "properties_results_previous_button" );
    var nextButton1 = document.getElementById( "properties_results_next_button2" );
    var previousButton1 = document.getElementById( "properties_results_previous_button2" );
    var pageInfo = document.getElementById( "properties_results_page_info" );
    
   	var totalListings = responseXml.getElementsByTagName( "count" )[ 0 ].firstChild.nodeValue;

    while( target.hasChildNodes() ) target.removeChild( target.firstChild );
    while( pageInfo.hasChildNodes() ) pageInfo.removeChild( pageInfo.firstChild );
    propertiesPageCount = Math.ceil( totalListings / 8 );
    nextButton.style.display = ( responseXml.getElementsByTagName( "item" ).length > 0 ? "block" : "none" );
    previousButton.style.display = ( responseXml.getElementsByTagName( "item" ).length > 0 ? "block" : "none" );
    if(nextButton1)nextButton1.style.display = ( responseXml.getElementsByTagName( "item" ).length > 0 ? "block" : "none" );
    if(nextButton1)previousButton1.style.display = ( responseXml.getElementsByTagName( "item" ).length > 0 ? "block" : "none" );
//    pageInfo.appendChild( document.createTextNode( responseXml.getElementsByTagName( "item" ).length > 0 ? "Page " + ( propertiesCurrentPage + 1 ) + " of " + propertiesPageCount : "No results to display." ) );
    
    for( var i = 0; i < responseXml.getElementsByTagName( "item" ).length; i ++ )
    {
        var idValue = responseXml.getElementsByTagName( "ListingsNumber" )[ i ].firstChild.nodeValue;
        var primaryImageValue = ( responseXml.getElementsByTagName( "Photo1TN" )[ i ].hasChildNodes() ? responseXml.getElementsByTagName( "Photo1TN" )[ i ].firstChild.nodeValue : "" );
        var suburbValue = ( responseXml.getElementsByTagName( "Suburb" )[ i ].hasChildNodes() ? responseXml.getElementsByTagName( "Suburb" )[ i ].firstChild.nodeValue : "" );
        var mainSellingPointValue = ( responseXml.getElementsByTagName( "MainSellingPoint" )[ i ].hasChildNodes() ? responseXml.getElementsByTagName( "MainSellingPoint" )[ i ].firstChild.nodeValue : "" );
        var typeValue = ( responseXml.getElementsByTagName( "SubCategory" )[ i ].hasChildNodes() ? responseXml.getElementsByTagName( "SubCategory" )[ i ].firstChild.nodeValue : "" );
        var priceDisplayValue = responseXml.getElementsByTagName( "PriceDisplay" )[ i ].firstChild.nodeValue;
        var descriptionValue = ( responseXml.getElementsByTagName( "Description" )[ i ].hasChildNodes() ? responseXml.getElementsByTagName( "Description" )[ i ].firstChild.nodeValue : "" );

        var property = propertyTemplate.cloneNode( true ); property.id = "";
        target.appendChild( property );
        property.childNodes[ 0 ].src = "/soldImages/" + primaryImageValue;
        property.childNodes[ 1 ].appendChild( document.createTextNode( mainSellingPointValue ) );
        property.childNodes[ 2 ].firstChild.childNodes[ 0 ].childNodes[ 1 ].appendChild( document.createTextNode( suburbValue ) );
        property.childNodes[ 2 ].firstChild.childNodes[ 0 ].childNodes[ 3 ].appendChild( document.createTextNode( typeValue ) );
        property.childNodes[ 2 ].firstChild.childNodes[ 1 ].childNodes[ 1 ].appendChild( document.createTextNode( priceDisplayValue ) );
        property.childNodes[ 3 ].appendChild( document.createTextNode( descriptionValue.substring( 0, 60 ) + "..." ) );
        property.property = idValue;
        addEvent( property, "click", function( ev )
        {
            propertiesInspectionOpen( eventSrc( ev ).parentNode.property ); 
        } );
    }
    pageInfo.appendChild( document.createTextNode( responseXml.getElementsByTagName( "item" ).length > 0 ? "Listings " + ( (propertiesCurrentPage*8) + 1 ) + " - " + ((propertiesCurrentPage*8) + i  ) + " of " + totalListings : "No results to display." ) );
  
    
    loadingHide();
    propertiesResultsOpen( null );
}
function propertiesResultsPrevious()
{
    propertiesCurrentPage --;
    if( propertiesCurrentPage < 0 ) propertiesCurrentPage = propertiesPageCount - 1;
    loadingShow();
    ajaxSend( "/global/services/meta3.1.aspx", "<request><session>hinterland_commercial</session><command>get_items</command><table>Listings</table><start>" + ( propertiesCurrentPage * 8 ) + "</start><count>8</count><condition>" + propertiesSearchConditions + "</condition>" + propertiesSearchSort + "</request>", propertiesSearchResponse );
}
function propertiesResultsNext()
{
    propertiesCurrentPage ++;
    if( propertiesCurrentPage >= propertiesPageCount ) propertiesCurrentPage = 0;
    loadingShow();
    ajaxSend( "/global/services/meta3.1.aspx", "<request><session>hinterland_commercial</session><command>get_items</command><table>Listings</table><start>" + ( propertiesCurrentPage * 8 ) + "</start><count>8</count><condition>" + propertiesSearchConditions + "</condition>" + propertiesSearchSort + "</request>", propertiesSearchResponse );
}
function propertiesResultsOpen()
{
    var page = document.getElementById( "properties_results_page" );
   
    extrasShow( "listings.jpg", false, true );
    pageSelect( page, null );
}
function propertiesInspectionOpen( property )
{
    var page = document.getElementById( "properties_inspection_page" );
    var referenceNo = document.getElementById( "properties_inspection_reference_no" );
    var category = document.getElementById( "properties_inspection_category" );
    var type = document.getElementById( "properties_inspection_type" );
    var suburb = document.getElementById( "properties_inspection_suburb" );
    var price = document.getElementById( "properties_inspection_price" );
    var description = document.getElementById( "properties_inspection_description" );
    var mainSellingPoint = document.getElementById( "properties_inspection_main_selling_point" );
    var imageTarget = document.getElementById( "properties_inspection_images_panel" );
    var imageTemplate = document.getElementById( "inspection_image_template" );
    
    propertiesCurrentProperty = property;
    loadingShow();
    ajaxSend( "/global/services/meta3.1.aspx", "<request><session>hinterland_commercial</session><command>get_items</command><table>listings</table><condition><field>ListingsNumber</field><operator>equal_to</operator><operand>" + propertiesCurrentProperty + "</operand></condition></request>", function( responseXml )
    {
        var mainSellingPointValue = ( responseXml.getElementsByTagName( "MainSellingPoint" )[ 0 ].hasChildNodes() ? responseXml.getElementsByTagName( "MainSellingPoint" )[ 0 ].firstChild.nodeValue : "" );
        var imageValues = new Array( ( responseXml.getElementsByTagName( "Photo1TN" )[ 0 ].hasChildNodes() ? responseXml.getElementsByTagName( "Photo1TN" )[ 0 ].firstChild.nodeValue : "" ), ( responseXml.getElementsByTagName( "Photo2TN" )[ 0 ].hasChildNodes() ? responseXml.getElementsByTagName( "Photo2TN" )[ 0 ].firstChild.nodeValue : "" ), ( responseXml.getElementsByTagName( "Photo3TN" )[ 0 ].hasChildNodes() ? responseXml.getElementsByTagName( "Photo3TN" )[ 0 ].firstChild.nodeValue : "" ), ( responseXml.getElementsByTagName( "Photo4TN" )[ 0 ].hasChildNodes() ? responseXml.getElementsByTagName( "Photo4TN" )[ 0 ].firstChild.nodeValue : "" ) );
        var suburbValue = responseXml.getElementsByTagName( "Suburb" )[ 0 ].hasChildNodes() ? responseXml.getElementsByTagName( "Suburb" )[ 0 ].firstChild.nodeValue : "";
        var typeValue = responseXml.getElementsByTagName( "PropertyType" )[ 0 ].hasChildNodes() ? responseXml.getElementsByTagName( "PropertyType" )[ 0 ].firstChild.nodeValue : "";
        var forSaleValue = responseXml.getElementsByTagName( "ForSale" )[ 0 ].firstChild.nodeValue == "y";
        var forLeaseValue = responseXml.getElementsByTagName( "ForLease" )[ 0 ].firstChild.nodeValue == "y";
        var priceDisplayValue = responseXml.getElementsByTagName( "PriceDisplay" )[ 0 ].hasChildNodes() ? responseXml.getElementsByTagName( "PriceDisplay" )[ 0 ].firstChild.nodeValue : "";
        var descriptionValue = responseXml.getElementsByTagName( "Description" )[ 0 ].hasChildNodes() ? responseXml.getElementsByTagName( "Description" )[ 0 ].firstChild.nodeValue : "";
        
        while( referenceNo.hasChildNodes() ) referenceNo.removeChild( referenceNo.firstChild );
        while( category.hasChildNodes() ) category.removeChild( category.firstChild );
        while( type.hasChildNodes() ) type.removeChild( type.firstChild );
        while( suburb.hasChildNodes() ) suburb.removeChild( suburb.firstChild );
        while( price.hasChildNodes() ) price.removeChild( price.firstChild );
        while( description.hasChildNodes() ) description.removeChild( description.firstChild );
        while( imageTarget.childNodes.length > 1 ) imageTarget.removeChild( imageTarget.firstChild );
        while( mainSellingPoint.hasChildNodes() ) mainSellingPoint.removeChild( mainSellingPoint.firstChild );
        mainSellingPoint.appendChild( document.createTextNode( mainSellingPointValue ) );
        referenceNo.appendChild( document.createTextNode( propertiesCurrentProperty ) );
        category.appendChild( document.createTextNode( forSaleValue && forLeaseValue ? "Buying/Leasing" : ( forSaleValue ? "Buying" : "Leasing" ) ) );
        type.appendChild( document.createTextNode( typeValue ) );
        suburb.appendChild( document.createTextNode( suburbValue ) );
        price.appendChild( document.createTextNode( priceDisplayValue ) );
        description.appendChild( document.createTextNode( descriptionValue ) );
        for( var i = 0; i < imageValues.length; i ++ ) if( imageValues[ i ] != "NoPhotoTN.jpg" && imageValues[ i ] != null )
        {
            var image = imageTemplate.cloneNode( true ); image.id = "";
            imageTarget.insertBefore( image, imageTarget.lastChild );
            image.src = "/soldImages/" + imageValues[ i ];
            image.index = i;
            addEvent( image, "click", function( ev )
            {
                var windowHandle = window.open( "tour.aspx?" + property + "&" + eventSrc( ev ).index, "Tour", "width=600,height=500,resizable=no,status=no,toolbar=no,titlebar=no,status=no,scrollbars=no,resizable=no,menubar=no,location=no" );
            } );
        }
        extrasShow( "listings.jpg", true, false );
        pageSelect( page, null );
        loadingHide(); 
    } );
}
function propertiesFriendOpen()
{
    var page = document.getElementById( "properties_friend_page" );
    var propertyValue = document.getElementById( "properties_friend_property" );

    while( propertyValue.hasChildNodes() ) propertyValue.removeChild( propertyValue.firstChild );
    propertyValue.appendChild( document.createTextNode( propertiesCurrentProperty ) );
    extrasShow( "listings.jpg", true, false );
    pageSelect( page, null );
}
function propertiesFriendSend()
{
    var name = document.getElementById( "properties_friend_name" );
    var email = document.getElementById( "properties_friend_email" );
    var message = document.getElementById( "properties_friend_message" );
    
    loadingShow();
    ajaxSend( "/global/services/meta3.1.aspx", "<request><command>get_items</command><session>hinterland_commercial</session><table>email</table></request>", function( responseXml )
    {
        var friendNotificationsValue = responseXml.getElementsByTagName( "friend_notifications" )[ 0 ].hasChildNodes() ? responseXml.getElementsByTagName( "friend_notifications" )[ 0 ].firstChild.nodeValue : "";

        ajaxSend( "/global/services/proto1.5.aspx", "<request><command>smtp_send</command><to>" + ajaxEncode( email.value ) + "</to><bcc>" + ajaxEncode( friendNotificationsValue ) + "</bcc><subject>Central Coast Commercial Friend Referral</subject><message>Your friend " + ajaxEncode( name.value ) + " is referring a property to you listed by Central Coast Commercial. Click the following link or paste it into your browser's address.\r\n\r\n" + ajaxEncode( "http://" + window.location.hostname + "/interface.aspx?" + propertiesCurrentProperty ) + "\r\n\r\n" + ajaxEncode( name.value ) + " says: \r\n" + ajaxEncode( message.value ) + "</message></request>", function( responseXml )
        {
            alert( "Property has been sent." );
            name.value = "";
            email.value = "";
            propertiesInspectionOpen( propertiesCurrentProperty );
        } );
    } );
}
function propertiesEmailSimilarOpen()
{
    var page = document.getElementById( "properties_email_similar_page" );
    var property = document.getElementById( "inspection_email_similar_property" );
    
    while( property.hasChildNodes() ) property.removeChild( property.firstChild );
    property.appendChild( document.createTextNode( propertiesCurrentProperty ) );
    extrasShow( "listings.jpg", true, false );
    pageSelect( page, null );
}
function propertiesEmailSimilarSubmit()
{
    var name = document.getElementById( "properties_email_similar_name" );
    var phone = document.getElementById( "properties_email_similar_phone" );
    var mobile = document.getElementById( "properties_email_similar_mobile" );
    var email = document.getElementById( "properties_email_similar_email" );
    var message = document.getElementById( "properties_email_similar_message" );
    
    loadingShow();
    ajaxSend( "/global/services/meta3.1.aspx", "<request><command>get_items</command><session>hinterland_commercial</session><table>listings</table><condition><field>ListingsNumber</field><operator>equal_to</operator><operand>" + propertiesCurrentProperty + "</operand></condition></request>", function( responseXml )
    {
        var addressValue = responseXml.getElementsByTagName( "Address" )[ 0 ].hasChildNodes() ? responseXml.getElementsByTagName( "Address" )[ 0 ].firstChild.nodeValue : "";
        
        ajaxSend( "/global/services/meta3.1.aspx", "<request><command>get_items</command><session>hinterland_commercial</session><table>email</table></request>", function( responseXml )
        {
            var emailSimilarSubmissionsValue = responseXml.getElementsByTagName( "email_similar_submissions" )[ 0 ].hasChildNodes() ? responseXml.getElementsByTagName( "email_similar_submissions" )[ 0 ].firstChild.nodeValue : "";
            
            ajaxSend( "/global/services/proto1.4.aspx", "<request><command>smtp_send</command><to>" + ajaxEncode( emailSimilarSubmissionsValue ) + "</to><subject>Email Similar Submission</subject><message>property :: " + ajaxEncode( addressValue ) + "\r\nname :: " + ajaxEncode( name.value ) + "\r\nphone :: " + ajaxEncode( phone.value ) + "\r\nmobile :: " + ajaxEncode( mobile.value ) + "\r\nemail :: " + ajaxEncode( email.value ) + "\r\n\r\n" + ajaxEncode( message.value ) + "</message></request>", function( responseXml )
            {
                alert( "Your submission has been made. Thankyou." );
                name.value = "";
                phone.value = "";
                mobile.value = "";
                email.value = "";
                message.value = "";
                propertiesInspectionOpen( propertiesCurrentProperty );
            } );
        } );
    } );
}
function propertiesPrintPropertySummary()
{
    window.open( "print_property_summary.aspx?" + propertiesCurrentProperty, "", "width=600,height=500,resizable=no,status=no,toolbar=no,titlebar=no,status=no,scrollbars=no,resizable=no,menubar=no,location=no" );
}
function propertiesPrintSearchResults()
{
    var category = document.getElementById( "properties_search_category" ); 
    var type = document.getElementById( "properties_search_type" );
    var suburb = document.getElementById( "properties_search_suburb" );
    var priceMinimum = document.getElementById( "properties_search_price_minimum" );
    var priceMaximum = document.getElementById( "properties_search_price_maximum" );
    var sortBy = document.getElementById( "properties_search_sort_by" ); 

    window.open( "print_search_results.aspx?" + propertiesCurrentPage + "&" + ajaxEncode( category.value ) + "&" + ajaxEncode( type.value ) + "&" + ajaxEncode( suburb.value ) + "&" + ajaxEncode( priceMinimum.value ) + "&" + ajaxEncode( priceMaximum.value ) + "&" + ajaxEncode( sortBy.value ), "", "width=600,height=500,resizable=no,status=no,toolbar=no,titlebar=no,status=no,scrollbars=no,resizable=no,menubar=no,location=no" );
}

/* Selling */
function sellingMethodsOfSaleOpen()
{
    var page = document.getElementById( "selling_methods_of_sale_page" );

    extrasShow( "selling.jpg", false, false );
    pageSelect( page, null );
}
function sellingWhyListWithUsOpen()
{
    var page = document.getElementById( "selling_why_list_with_us_page" );

    extrasShow( "selling.jpg", false, false );
    pageSelect( page, null );
}
function sellingMarketingYourPropertyOpen()
{
    var page = document.getElementById( "selling_marketing_your_property_page" );

    extrasShow( "selling.jpg", false, false );
    pageSelect( page, null );
}
function sellingMarketAppraisalsOpen()
{
    var page = document.getElementById( "selling_market_appraisals_page" );

    extrasShow( "selling.jpg", false, false );
    pageSelect( page, null );
}
function sellingMarketAppraisalsSend()
{
    var name = document.getElementById( "selling_market_appraisals_name" );
    var homePhone = document.getElementById( "selling_market_appraisals_home_phone" );
    var mobilePhone = document.getElementById( "selling_market_appraisals_mobile_phone" );
    var email = document.getElementById( "selling_market_appraisals_email" );
    var propertyAddress = document.getElementById( "selling_market_appraisals_property_address" );
    var suburb = document.getElementById( "selling_market_appraisals_suburb" );
    var details = document.getElementById( "selling_market_appraisals_details" );

    loadingShow();
    ajaxSend( "/global/services/meta3.1.aspx", "<request><command>get_items</command><session>hinterland_commercial</session><table>email</table></request>", function( responseXml )
    {
        var marketAppraisalApplicationsValue = responseXml.getElementsByTagName( "market_appraisal_applications" )[ 0 ].firstChild.nodeValue;
        
        ajaxSend( "/global/services/proto1.4.aspx", "<request><command>smtp_send</command><to>" + ajaxEncode( marketAppraisalApplicationsValue ) + "</to><subject>Market Appraisal Application</subject><message>" + ajaxEncode( "Name :: " + name.value + "\r\nHome Phone :: " + homePhone.value + "\r\nMobile Phone :: " + mobilePhone.value + "\r\nEmail :: " + email.value + "\r\nProperty Address :: " + propertyAddress.value + "\r\nSuburb :: " + suburb.value + "\r\n\r\n" + details.value ) + "</message></request>", function()
        {
            alert( "Your market appraisal application has been sent. Thankyou." );
            sellingMarketAppraisalsClear();
            loadingHide();
        } );
    } );
}
function sellingMarketAppraisalsClear()
{
    var name = document.getElementById( "selling_market_appraisals_name" );
    var homePhone = document.getElementById( "selling_market_appraisals_home_phone" );
    var mobilePhone = document.getElementById( "selling_market_appraisals_mobile_phone" );
    var email = document.getElementById( "selling_market_appraisals_email" );
    var propertyAddress = document.getElementById( "selling_market_appraisals_property_address" );
    var suburb = document.getElementById( "selling_market_appraisals_suburb" );
    var details = document.getElementById( "selling_market_appraisals_details" );
    
    name.value = "";
    homePhone.value = "";
    mobilePhone.value = "";
    email.value = "";
    propertyAddress.value = "";
    suburb.value = "";
    details.value = "";
}

/* Contact */
function contactUsContactUsOpen()
{
    var page = document.getElementById( "contact_us_contact_us_page" );
    var detailsTarget = document.getElementById( "contact_us_contact_us_details_target" );
    var labelTemplate = document.getElementById( "label_template" );
    var valueTemplate = document.getElementById( "value_template" );
    var linkTemplate = document.getElementById( "link_template" );
   
    loadingShow();
    ajaxSend( "/global/services/meta3.1.aspx", "<request><session>hinterland_commercial</session><command>get_items</command><table>contact_details</table></request>", function( responseXml )
    {
        while( detailsTarget.firstChild.hasChildNodes() ) detailsTarget.firstChild.removeChild( detailsTarget.firstChild.firstChild );
        for( var i = 0; i < responseXml.getElementsByTagName( "item" ).length; i ++ )
        {
            var labelValue = responseXml.getElementsByTagName( "item" )[ i ].getElementsByTagName( "label" )[ 0 ].firstChild.nodeValue;
            var valueValue = responseXml.getElementsByTagName( "item" )[ i ].getElementsByTagName( "value" )[ 0 ].firstChild.nodeValue;
            
            var row = document.createElement( "tr" );
            var label = labelTemplate.cloneNode( true ); label.id = "";
            var value = valueTemplate.cloneNode( true ); value.id = "";
            row.appendChild( label );
            row.appendChild( value );
            detailsTarget.firstChild.appendChild( row );
            label.appendChild( document.createTextNode( labelValue.toLowerCase() + " :: " ) );
            if( labelValue.toLowerCase() == "web" )
            {
                var link = linkTemplate.cloneNode( true );
                link.id = "";
                link.appendChild( document.createTextNode( valueValue ) );
                link.href = "http://" + valueValue;
                value.appendChild( link );
            }
//            else if( labelValue.toLowerCase() == "email" )
//            {
//                var link = linkTemplate.cloneNode( true );
//                link.id = "";
//                link.appendChild( document.createTextNode( valueValue ) );
//                //link.href = "mailto:" + valueValue;
//                value.appendChild( link );
//            }
            else
            {
                var values = valueValue.split( "\n" );
                for( var t = 0; t < values.length; t ++ )
                {
                    value.appendChild( document.createTextNode( values[ t ] ) );
                    value.appendChild( document.createElement( "br" ) );
                }
            }
        }
        extrasShow( "contact_us.jpg", false, false );
        pageSelect( page );
        loadingHide();
    } );
}
function contactUsContactUsSend()
{
    var name = document.getElementById( "contact_us_contact_us_name" );
    var homePhone = document.getElementById( "contact_us_contact_us_home_phone" );
    var mobilePhone = document.getElementById( "contact_us_contact_us_mobile_phone" );
    var email = document.getElementById( "contact_us_contact_us_email" );
    var message = document.getElementById( "contact_us_contact_us_message" );

    loadingShow();
    ajaxSend( "/global/services/meta3.1.aspx", "<request><command>get_items</command><session>hinterland_commercial</session><table>email</table></request>", function( responseXml )
    {
        var generalEnquiriesValue = responseXml.getElementsByTagName( "general_enquiries" )[ 0 ].firstChild.nodeValue;
        
        ajaxSend( "/global/services/proto1.3.aspx", "<request><command>smtp_send</command><to>" + ajaxEncode( generalEnquiriesValue ) + "</to><subject>General Enquiry</subject><message>" + ajaxEncode( "Name :: " + name.value + "\r\nHome Phone :: " + homePhone.value + "\r\nMobile Phone :: " + mobilePhone.value + "\r\nEmail :: " + email.value + "\r\n\r\n" + message.value ) + "</message></request>", function()
        {
            loadingHide();
            alert( "Your enquiry has been sent. Thankyou." );
            contactUsContactUsClear();
        } );
    } );
}
function contactUsContactUsClear()
{
    var name = document.getElementById( "contact_us_contact_us_name" );
    var homePhone = document.getElementById( "contact_us_contact_us_home_phone" );
    var mobilePhone = document.getElementById( "contact_us_contact_us_mobile_phone" );
    var email = document.getElementById( "contact_us_contact_us_email" );
    var message = document.getElementById( "contact_us_contact_us_message" );
    
    name.value = "";
    homePhone.value = "";
    mobilePhone.value = "";
    email.value = "";
    message.value = "";
}