﻿var k_push_vars = {
    "display_after": 30,
    "view_percentage": 10,
    "popup_font_color": "#000000",
    "popup_background": "#D4E2F0",
    "header": "Your feedback is important to us!",
    "question": "Would you be willing to give us a short (1 minute) feedback?",
    "footer": "Thank you for helping us improve our website",
    "remind": "Remind me later",
    "remind_font_color": "#3882C3",
    "yes": "Yes",
    "no": "No",
    "text_direction": "ltr",
    "images_dir": "http://cf.kampyle.com/",
    "yes_background": "#76AC78",
    "no_background": "#8D9B86",
    "site_code": 1461105
}


// this function should always be called to initialize control


function changeSavedPropertiesCount(value) {
    var savedCount = document.getElementById("savedPropertiesCount");
    var count = parseInt(savedCount.innerHTML) + value;
    document.getElementById("savedPropertiesCount").innerHTML = count;

    if (count <= 0) {
        document.getElementById("savedProperties").style.display = "none";
        document.getElementById("emptySavedProperties").style.display = "";
    }
    else {
        document.getElementById("savedProperties").style.display = "";
        document.getElementById("emptySavedProperties").style.display = "none";
    }
}

// this function should always be called to initialize control
function switchSearchControl(state) {

    updatePropertyTypes();

    // change closed part
    var objNameButton = document.getElementById("searchFilterNameButton");
    var objOpenButton = document.getElementById("searchFilterOpenButton");

    if (state == 'search') {
        objNameButton.style.backgroundImage = "url(/Content/Images/financial_tab_off.png)";
        objOpenButton.onclick = function() {
            showFinancial(true);
        }
        document.getElementById("searchClosedText").style.display = "block";
        document.getElementById("analyticsClosedText").style.display = "none";
    }
    else if (state == 'analyze') {
        objNameButton.style.backgroundImage = "url(/Content/Images/analytics_tab_off.png)";
        objOpenButton.onclick = function() {
            showAnalytics(true);
        }
        document.getElementById("analyticsClosedText").style.display = "block";
        document.getElementById("searchClosedText").style.display = "none";
    }

    // close opened if any
    showAnalytics(false);
    showFinancial(false);
}


function changeResultView(view) {
    var searchForm = document.getElementById('searchForm')
    if (view == 'Map') {
        document.getElementById('searchResult').value = "map";
    }
    else {
        document.getElementById('searchResult').value = "list";
    }
}

function searchOnMap() {
    changeResultView('Map');
    document.searchForm.submit();
}

function showSearch() {
    document.getElementById('searchType').value = 'search';

    document.getElementById("arrowSearch").style.visibility = "visible";
    document.getElementById("arrowAnalyze").style.visibility = "hidden";

    showShadow('searchControl', false);
    showShadow('analyzeControl', true);

    switchSearchControl('search');
}

function showAnalyze() {
    document.getElementById('searchType').value = 'analyze';

    document.getElementById("arrowSearch").style.visibility = "hidden";
    document.getElementById("arrowAnalyze").style.visibility = "visible";

    showShadow('analyzeControl', false);
    showShadow('searchControl', true);

    switchSearchControl('analyze');
}

function showShadow(id, show) {
    var shadow = document.getElementById(id + '_shadow');

    if (shadow) {
        shadow.style.display = show == true ? 'block' : 'none';
        /* IE6 fix */
        if (shadow.offsetParent != null)
            shadow.style.height = shadow.offsetParent.offsetHeight + "px";
    }
}

function containsDOM(container, containee) {
    var isParent = false;
    do {
        if ((isParent = container == containee))
            break;
        containee = containee.parentNode;
    }
    while (containee != null);
    return isParent;
}

function checkMouseEnter(element, evt) {
    if (element.contains && evt.fromElement)
        return !element.contains(evt.fromElement);
    else if (evt.relatedTarget)
        return !containsDOM(element, evt.relatedTarget);
}

function checkMouseLeave(element, evt) {
    if (element.contains && evt.toElement)
        return !element.contains(evt.toElement);
    else if (evt.relatedTarget)
        return !containsDOM(element, evt.relatedTarget);
    return false;
}

function saveProperty(propertyId) {
    $.post("/Property/Save", {
        propertyId: propertyId
    });

    document.getElementById("ctrlSave" + propertyId).style.display = "none";
    document.getElementById("ctrlSaved" + propertyId).style.display = "block";

    // call function from master page to increase saved count
    changeSavedPropertiesCount(1);
}
