﻿/* TRUNK CHECKIN TEST */

/* keep top part of search result on screen at all times */
var controlledDiv;
var initialY;
var currentY = initialY;
var iebody = (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body;
var advancedSearchHidden = false;

function manageScroll() {
    var y = document.all ? iebody.scrollTop : window.pageYOffset;
    y -= 143;

    // early out
    if (y == currentY) {
        return;
    }

    // absolute positioning is necessary, so the position of the column headers is hardcoded here
    initialY = 340;

    if (!currentY) currentY = initialY;

    if (y <= initialY) {
        controlledDiv.style.display = "none";
        currentY = initialY;
    }
    else {
        controlledDiv.style.position = "absolute";
        currentY = Math.round(currentY + (y - currentY) * .5);
        controlledDiv.style.top = ((currentY) - (40)) + "px";
        window.status = y + " " + " " + initialY + " " + currentY;
        controlledDiv.style.display = "block";
    }
}

function setCookie(name, value, expires, path, domain, secure) {
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime(today.getTime());

    /*
    if the expires variable is set, make the correct 
    expires time, the current script below will set 
    it for x number of days, to make it for hours, 
    delete * 24, for minutes, delete * 60 * 24
    */
    if (expires) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date(today.getTime() + (expires));

    document.cookie = name + "=" + escape(value) +
    ((expires) ? ";expires=" + expires_date.toGMTString() : "") +
    ((path) ? ";path=" + path : "") +
    ((domain) ? ";domain=" + domain : "") +
    ((secure) ? ";secure" : "");
}

if (window.addEventListener)
    window.addEventListener("load", InitializePage, false);
else if (window.attachEvent)
    window.attachEvent("onload", InitializePage, false);

function InitializePage() {

    //var AdvancedSearchMk2 = $('AdvancedSearchMk2');
    document.getElementById('AdvancedSearchMk2').style.display = 'block';
    var advSearchSlide = new Fx.Slide('AdvancedSearchMk2');

    var advSearchStatus = Cookie.read("advSearchMK2");

    // Set default
    if (null == advSearchStatus) {
        advSearchStatus = 'hidden';
    }

    var initSearchResult = function() {
        advSearchSlide.slideOut();
    }

    if (!advSearchStatus || advSearchStatus == 'hidden') {
        initSearchResult.delay(1000);

        advancedSearchHidden = false;

    }
    else if (advSearchStatus == 'visible') {
        setCookie('advSearchMK2', 'visible', 365, '/');
        var element = $('searchFloatElement');
        $('slideContainer').appendChild(element.parentNode.removeChild(element));
        document.getElementById('AdvancedSearchMk2').style.visibility = 'visible';
        document.getElementById('advancedSearchButtonMk2').className = 'smallButton arrowDown';
        document.getElementById('showAdvancedSearchHide').style.display = 'block';
        document.getElementById('showAdvancedSearchShow').style.display = 'none';
        advSearchSlide.show();
        advancedSearchHidden = false;
    }
    //	function move(o) {
    //	    var q = document.getElementById('img1');
    //	    o.appendChild(q.parentNode.removeChild(q));
    //	}

    $('showAdvancedSearchShow').addEvent('click', function(e) {
        e.stop();
        var element = $('searchFloatElement');
        $('slideContainer').appendChild(element.parentNode.removeChild(element));
        document.getElementById('AdvancedSearchMk2').style.visibility = 'visible';
        advSearchSlide.slideIn();
        advancedSearchHidden = false;
    });

    $('showAdvancedSearchHide').addEvent('click', function (e) {
        e.stop();
        advSearchSlide.slideOut();
        advancedSearchHidden = true;
    });

    advSearchSlide.addEvent('complete', function () {
        if (advSearchSlide.open == true) {

            setCookie('advSearchMK2', 'visible', 365, '/');
            document.getElementById('advancedSearchButtonMk2').className = 'smallButton arrowDown';
            document.getElementById('showAdvancedSearchHide').style.display = 'block';
            document.getElementById('showAdvancedSearchShow').style.display = 'none';
            advancedSearchHidden = false;
        } else {
            setCookie('advSearchMK2', 'hidden', 365, '/');
            document.getElementById('advancedSearchButtonMk2').className = 'smallButton arrowUp';
            document.getElementById('showAdvancedSearchShow').style.display = 'block';
            document.getElementById('showAdvancedSearchHide').style.display = 'none';
            advancedSearchHidden = true;
        }
    });

    // keep top part of search result at the top of the screen
    controlledDiv = document.getElementById('SearchResultHeaderDynamic');
    if (controlledDiv) {
        setInterval("manageScroll()", 1000 / 15);
    }

    createMouseOverEffect();
}

/* mouse events for the search results list */
function createMouseOverEffect() {
    var container = document.getElementById("SearchResult");

    var tables = container.getElementsByTagName("TABLE");
    var table;
    for (var i = 0, len = tables.length; i < len; i++) {
        // find table in question
        table = (tables[i].className == "searchGrid" ? tables[i] : table);
    }
    if (!table) {
        return;
    }

    var s = table.getElementsByTagName("TR");
    for (i in s) {
        s[i].onmouseover = hilightItem;
        s[i].onmouseout = unHilightItem;
        /* s[i].onclick = showItem; */
    }
}

function hilightItem() {
    this.style.backgroundColor = '#f8f8f8';
    this.style.cursor = 'default'; /* 'pointer'; */
}
function unHilightItem() {
    this.style.backgroundColor = '#ffffff';
    this.style.cursor = 'default';
}
function showItem() {
    var s = this.getElementsByTagName("A");
    for (i in s) {
        if (s[i].className == 'detailLink') {
            window.location.href = s[i].href;
            break;
        }
    }
}

function triggerProperty(propertyid, index, sessionid) {
    try {
        //        var host = window.location.host;
        //        var protocol = window.location.protocol; 
        //        var url = protocol + "//" + host + "/WebService/VacasolWebService.asmx/TriggerProperty";
        //        
        //        jQuery.ajax({
        //            type: "POST",
        //            contentType: "application/json; charset=utf-8",
        //            url: url,
        //            data: "{'propertyid':'" + propertyid + "','index':'" +index+ "'}",
        //            dataType: "json"
        //        });
        Vacasol.Web.WebServices.VacasolWebService.TriggerProperty(propertyid, index, sessionid, onSuccess, onSuccess);
    } catch (Error) {
        //alert(Error);
    }
}
function onSuccess() {
}

