﻿function propertyCount() {
    if (arguments.length == 0) {
    
        //display loading image
        $("#propertycountHolder").html('<img src="./images/generic/ajax-loader.gif" border="0" />');
        
        //get property count
        var packet = xmlPacket(oLocal);
        wsProperty.getCount(packet, propertyCount);

    } else {
        // Set counter display to proerty number
        $("#propertycountHolder").html(arguments[0]);

    }
}

var agentSearchRunning = false;
var agentanimating = false;
var propSearchRunning = false;
var propanimating = false;
var waiting = false

function getAgentList() {
    waiting = false
    if (arguments.length == 0) {
        if ($(".agentSearch").val() != "") {
            //display loading image
            $("#agentSearchBox").attr("class", "intelliDropdown bgimg");

            //get agent list
            var packet = $(".agentSearch").val();
            wsAgentSearch.getList(packet, getAgentList)
            
        } else {
            hideAgentSearch("instant");
        }
    } else {

        // Change Dropdown values to agent list
        $("#agentSearchBox").html(arguments[0]);
        $("#agentSearchBox").attr("class", "intelliDropdown");
    }
}

function agentSearch() {
    // small wait to avoid multilpe unnecessary database calls
    if (!waiting) {
        setTimeout("getAgentList()", 1000);
        waiting = true
    }
}

function hideAgentSearch() {
    if (arguments.length == 0) {
        setTimeout("agentanimatehide()", 1000);
    } else {
        $("#agentSearchBox").attr("class", "intelliDropdown hidden");
    }
}

function setAgentValue(value) {
    $(".agentSearch").val(value);
    hideAgentSearch("instant");
    $(agentClick).click();
}

function agentanimatehide() {
    if (($("#agentSearchBox").attr("class") != "intelliDropdown hidden") && (agentanimating == false)) {
        agentanimating = true;
        $("#agentSearchBox").animate({
            opacity: 0.10
        }, 2500, function() {
            $("#agentSearchBox").attr("class", "intelliDropdown hidden");
            $("#agentSearchBox").animate({ opacity: 1.00 }, 0);
            agentanimating = false;
        });
    }
}


function getPropertyList() {
    waiting = false
    if (arguments.length == 0) {
        if ($(".propertyReferenceSearch").val() != "") {
           
            //display loading image
            $("#propertyReferenceSearchBox").attr("class", "intelliDropdown bgimg");
            
            //get property list
            var packet = $(".propertyReferenceSearch").val();
            wsPropertyReferenceSearch.getList(packet, getPropertyList)
        } else {
            hidePropertySearch("instant");
        }
    } else {

        // Change Dropdown values to agent list
        $("#propertyReferenceSearchBox").html(arguments[0]);
        $("#propertyReferenceSearchBox").attr("class", "intelliDropdown");
    }
}

function propertySearch() {
    // small wait to avoid multilpe unnecessary database calls
    if (!waiting) {
        setTimeout("getPropertyList()", 1000);
        waiting = true
    }
}

function hidePropertySearch() {
    if (arguments.length == 0) {
        setTimeout("propertyanimatehide()", 1000);
    } else {
        $("#propertyReferenceSearchBox").attr("class", "intelliDropdown hidden");
    }
}

function setPropertyValue(value) {
    $(".propertyReferenceSearch").val(value);
    hidePropertySearch("instant");
    $(propertyClick).click();
}


function propertyanimatehide() {
    if (($("#propertyReferenceSearchBox").attr("class") != "intelliDropdown hidden") && (propanimating == false)) {
        propanimating = true;
        $("#propertyReferenceSearchBox").animate({
            opacity: 0.10
        }, 2500, function() {
            $("#propertyReferenceSearchBox").attr("class", "intelliDropdown hidden");
            $("#propertyReferenceSearchBox").animate({ opacity: 1.00 }, 0);
            propanimating = false;
        });
    }
}

function standardPropertySearch() {

    if (arguments.length == 0) {
        //set search criteria
        var packet = xmlPacket(oLocal);
        wsProperty.propertySearch(packet, standardPropertySearch);

    } else {
        // Redirect to send page
        window.location = arguments[0];
    }
}
