
function OnChangePropertyTypeBasic()
{
    var ptypeCtrl = document.getElementById("ptype_basic");
    var proptype = ptypeCtrl.value;
    if (proptype == 4)
    {
        document.getElementById("bed_basic").value = 0;
        document.getElementById("bath_basic").value = 0;
		
        document.getElementById("bed_basic").disabled = true;
        document.getElementById("bath_basic").disabled = true;
        document.getElementById("bed_basic").style.backgroundColor = "#DEDEDE";
        document.getElementById("bath_basic").style.backgroundColor = "#DEDEDE";

    }
    else
    {
        document.getElementById("bed_basic").disabled = false;
        document.getElementById("bath_basic").disabled = false;
        document.getElementById("bed_basic").style.backgroundColor = "white";
        document.getElementById("bath_basic").style.backgroundColor = "white";
    }
}

function OnChangePropertyTypeAdvanced()
{
    var radioBox = document.getElementById("radio_search_status"); // DL: So we don't enable open house when searching sold properties

    var ptypeCtrl = document.getElementById("ptype_advanced");
    var proptype = ptypeCtrl.value;
    if (proptype == 4)
    {
        document.getElementById("bed_advanced").value = 0;
        document.getElementById("bath_advanced").value = 0;
        document.getElementById("sqft_advanced").value = 0;
        document.getElementById("open_house_from").value = "";
        document.getElementById("open_house_to").value = "";
        document.getElementById("pet_friendly").checked = false;
		
        document.getElementById("bed_advanced").disabled = true;
        document.getElementById("bath_advanced").disabled = true;
        document.getElementById("sqft_advanced").disabled = true;
        document.getElementById("open_house_from").disabled = true;
        document.getElementById("open_house_to").disabled = true;
        document.getElementById("pet_friendly").disabled = true;

        document.getElementById("bed_advanced").style.backgroundColor = "#DEDEDE";
        document.getElementById("bath_advanced").style.backgroundColor = "#DEDEDE";
        document.getElementById("sqft_advanced").style.backgroundColor = "#DEDEDE";
        document.getElementById("open_house_from").style.backgroundColor = "#DEDEDE";
        document.getElementById("open_house_to").style.backgroundColor = "#DEDEDE";
        document.getElementById("pet_friendly").style.backgroundColor = "#DEDEDE";
    }
    else
    {
        document.getElementById("bed_advanced").disabled = false;
        document.getElementById("bath_advanced").disabled = false;
        document.getElementById("sqft_advanced").disabled = false;
        document.getElementById("pet_friendly").disabled = false;

        document.getElementById("bed_advanced").style.backgroundColor = "white";
        document.getElementById("bath_advanced").style.backgroundColor = "white";
        document.getElementById("sqft_advanced").style.backgroundColor = "white";
        document.getElementById("pet_friendly").style.backgroundColor = "white";

        if (radioBox.checked != false) { // DL: Important for Open House
            document.getElementById("open_house_from").disabled = false;
            document.getElementById("open_house_to").disabled = false;
            document.getElementById("open_house_from").style.backgroundColor = "white";
            document.getElementById("open_house_to").style.backgroundColor = "white";
        }
    }
}

function OnChangePropertyTypeSearchAgent()
{
    var ptypeCtrl = document.getElementById("property_type");
    var proptype = ptypeCtrl.value;
    if (proptype == 4)
    {
        document.getElementById("beds").value = 0;
        document.getElementById("baths").value = 0;
        document.getElementById("sq_ft").value = 0;
        document.getElementById("pet_friendly").checked = false;
		
        document.getElementById("beds").disabled = true;
        document.getElementById("baths").disabled = true;
        document.getElementById("sq_ft").disabled = true;
        document.getElementById("pet_friendly").disabled = true;
    }
    else
    {
        document.getElementById("beds").disabled = false;
        document.getElementById("baths").disabled = false;
        document.getElementById("sq_ft").disabled = false;
        document.getElementById("pet_friendly").disabled = false;
    }
}

function OnChangeSearchHomesOrValues()
{
    var ptypeCtrl = document.getElementById("ptype_advanced");
    var proptype = ptypeCtrl.value;

    var status = null;
    $$('#radio_search_status').each( function(i) {
        if ($F(i)) {
            status = $F(i);
        }
    } );
if (status == 2)
{		
    document.getElementById("open_house_from").value = "";
    document.getElementById("open_house_to").value = "";

    document.getElementById("open_house_from").disabled = true;
    document.getElementById("open_house_to").disabled = true;
    document.getElementById("open_house_from").style.backgroundColor = "#DEDEDE";
    document.getElementById("open_house_to").style.backgroundColor = "#DEDEDE";

    document.getElementById("advanced_search_market_days").style.display = 'none';
    document.getElementById("advanced_search_sold_in_last").style.display = 'block';
}

else {
    document.getElementById("advanced_search_market_days").style.display = 'block';
    document.getElementById("advanced_search_sold_in_last").style.display = 'none';

    if (proptype != 4) {
        document.getElementById("open_house_from").disabled = false;
        document.getElementById("open_house_to").disabled = false;
        document.getElementById("open_house_from").style.backgroundColor = "white";
        document.getElementById("open_house_to").style.backgroundColor = "white";
    }
}
}

function enableSubmit(el) {
    $(el).disabled = false;
}

function accordionToggle(dt, dd) {
    var el = $(dt);
    if (el.hasClassName('closed')) {
        el.removeClassName('closed');
        el.addClassName('open');
    }
    else if (el.hasClassName('open')) {
        el.removeClassName('open');
        el.addClassName('closed');
    }
    toggle(dd);
}

function showDemo(){
    var url = '/ajax/parts/demo_popup?k='+ Math.round(100000*Math.random());
    curtain.load();
    new Ajax.Request(url, {
        method: 'get',
        onSuccess: function(showDemo2) {
            curtain.content(showDemo2.responseText);
        }
    });
}

function showDemoListing(){
    var url = '/ajax/parts/demo_popup_listing_page?k='+ Math.round(100000*Math.random());
    curtain.load();
    new Ajax.Request(url, {
        method: 'get',
        onSuccess: function(showDemo2) {
            curtain.content(showDemo2.responseText);
        }
    });
}

function showRegLogin(){
    var url = '/ajax/register-login/?k='+ Math.round(100000*Math.random());
    curtain.load();
    new Ajax.Request(url, {
        method: 'get',
        onSuccess: function(showRegister2) {
            curtain.content(showRegister2.responseText);
        }
    });
}

// Swaps medium size pic of property thumbnail
function showPhoto(photo) {
    if (photo.indexOf('-med') >= 0) {
        photo = photo.replace(/-med/, '');
    }
    else if (photo.indexOf('-tiny') >= 0) {
        photo = photo.replace(/-tiny/, '');
    }
    $('main-photo').src = photo;
}
// Shows large photo in popup
function showLargePhoto(id, builder){
    var photo = $('main-photo').src;
    if (photo.indexOf('-med') >= 0) {        
        photo = photo.replace(/-med/, '');        
    }
    else if (photo.indexOf('-tiny') >= 0) {
        photo = photo.replace(/-tiny/, '');
    }

    var url = '/ajax/photos/index/?id='+id+'&photo='+photo+'&k='+ Math.round(100000*Math.random());
    if(builder){
        url += '&builder='+builder;
    }
    curtain.load();
    new Ajax.Request(url, {
        method: 'get',
        onSuccess: function(showLargePhoto2) {
            curtain.content(showLargePhoto2.responseText, '', 800, 600);
        }
    });
}

function showPopUp(page, queryString, needEscape, valForm){
    var url = '/ajax/'+page+'/?k='+ Math.round(100000*Math.random());
    if (queryString !== undefined) {
        if (needEscape !== undefined && needEscape != '') {
            url += '&url=' + escape(queryString);
        }
        else {
            url += queryString;
        }
    }
    curtain.load();
    new Ajax.Request(url, {
        method: 'get',
        onSuccess: function(showPopUp2) {
            curtain.content(showPopUp2.responseText);
            if (valForm !== undefined) {
                setTimeout("valForm.init('" + page + "-form'); customTitle.init('curtain_contentLayer"+curtain.index+"')" , 100);
            }
        }
    });
}

function toggleHelpContent() {    
    var a = $('help-content-toggle');
    var div = $('help-content');
    toggle(div);

    if (div.style.display == 'block') {
        a.innerHTML = 'Hide X';
    }
    else {
        a.innerHTML = 'Help <img src="/images/help2.gif" alt="Help" width="15" height="15" />';
    }
}

function toggleHelpContentSave() {
    toggleHelpContent();
    var url = window.CPROOT+'/action/save_toggle_help?k='+ Math.round(100000*Math.random());
    new Ajax.Request(url, {
        method: 'get',
        onSuccess: function(saveToggleHelp2) {
        }
    });
        
}

function togglePrivateAgentInformation() {
    toggle($('private_info'));
}

function chooseSimilarListings(myForm, element, value) {

    if (element.checked == true) {
        $(value).addClassName('similar-listing-on');
    }
    else {
        $(value).removeClassName('similar-listing-on');
    }

    var count = 5;

    $(myForm).getInputs('checkbox').each(function (elem) {
        if (elem.checked == true) {
            count--;

        }
    });

    $('comparables-left').innerHTML = ' ' + count + ' ';
    if (count == 0) {
        $(myForm).getInputs('checkbox').each(function (elem) {
            if (elem.checked != true) {
                elem.setAttribute('disabled', 'disabled');

            }
        });
    }
    else {
        $(myForm).getInputs('checkbox').each(function (elem) {
            elem.removeAttribute('disabled');
        });
    }

    if (count == 5) {
        $('compare_button').hide();
    }
    else {
        $('compare_button').show();
    }
}

function switchTabActiveListing(value) {
    if (value == 'listing_description') {
        $('listing_description_tab').className = 'listing-tab listing-tab-on';
        $('listing_compare_analyze_tab').className = 'listing-tab listing-tab-off';

        $('listing_description').show();
        $('similar-active-listings').show();
        $('listing_compare_analyze').hide();
    }
    else if (value == 'listing_compare_analyze') {
        $('listing_description_tab').className = 'listing-tab listing-tab-off';
        $('listing_compare_analyze_tab').className = 'listing-tab listing-tab-on';

        $('listing_description').hide();
        $('similar-active-listings').hide();
        $('listing_compare_analyze').show();
    }
}

function switchTabSoldListing(value) {
    if (value == 'listing_description') {
        $('listing_description_tab').className = 'listing-tab listing-tab-on';
        $('listing_compare_analyze_tab').className = 'listing-tab listing-tab-off';
        $('listing_transaction_history_tab').className = 'listing-tab listing-tab-off';

        $('listing_description').show();
        $('listing_compare_analyze').hide();
        $('listing_transaction_history').hide();
    }
    else if (value == 'listing_compare_analyze') {
        $('listing_description_tab').className = 'listing-tab listing-tab-off';
        $('listing_compare_analyze_tab').className = 'listing-tab listing-tab-on';
        $('listing_transaction_history_tab').className = 'listing-tab listing-tab-off';

        $('listing_description').hide();
        $('listing_compare_analyze').show();
        $('listing_transaction_history').hide();
    }
    else if (value == 'listing_transaction_history') {
        $('listing_description_tab').className = 'listing-tab listing-tab-off';
        $('listing_compare_analyze_tab').className = 'listing-tab listing-tab-off';
        $('listing_transaction_history_tab').className = 'listing-tab listing-tab-on';

        $('listing_description').hide();
        $('listing_compare_analyze').hide();
        $('listing_transaction_history').show();
    }
}

function switchHousingTypeTab(value){
    var tab_on = 'listing-tab listing-tab-on'
    var tab_off = 'listing-tab listing-tab-off'
    var active_tabs = $$('.listing-tab.listing-tab-on');
    active_tabs.each(function(elem){
        elem.className = tab_off
    });
    $(value + '_tab').className = tab_on;
    var active_tables = $$('.listing-table');
    active_tables.each(function(elem){
        elem.hide();
    });
    $(value).show();

}

function textCounter(field, countfield, maxlimit) {
    if ( field.value.length > maxlimit ) {
        field.value = field.value.substring( 0, maxlimit );
        alert( 'Textarea value can only be ' + maxlimit + ' characters in length.' );
        return false;
    }

    else {
        countfield.value = maxlimit - field.value.length;
    }
    return true;
}

function toggleHeaderLogin() {
    if (document.getElementById('header_login_form').style.display == 'none') {
        document.getElementById('header_login_form').style.display = 'block';
    }
    else {
        document.getElementById('header_login_form').style.display = 'none';
    }
}

function setBasicSearch() {
    document.basicsearch.search.value = "basic";
    document.basicsearch.submit();
}