/* 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 = advancedSearchHidden ? 130 : 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) - (advancedSearchHidden ? 40 : initialY)) + "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() {

	$('AdvancedSearch').style.display = 'block';

	var advSearchSlide = new Fx.Slide('AdvancedSearch');

	var advSearchStatus = Cookie.read("advSearch");
	
	// Set default
	if (null == advSearchStatus)
	{
	    advSearchStatus = 'visible';
	}

	var initSearchResult = function(){
		advSearchSlide.slideOut();
	}

	if(!advSearchStatus || advSearchStatus == 'hidden')
	{
		advSearchSlide.show();
		initSearchResult.delay(1000);
        advancedSearchHidden = false;
	}
	else if(advSearchStatus == 'visible')
	{
		setCookie('advSearch', 'visible', 365, '/');
		$('advancedSearchButton').className = 'bigButton arrowDown';
		$('showAdvancedSearchHide').style.display = 'block';
		$('showAdvancedSearchShow').style.display = 'none';
        advancedSearchHidden = false;
	}

	$('showAdvancedSearchShow').addEvent('click', function(e){
		e.stop();
		advSearchSlide.slideIn();
		advancedSearchHidden = false;
	});

	$('showAdvancedSearchHide').addEvent('click', function(e){
		e.stop();
		advSearchSlide.slideOut();
		advancedSearchHidden = true;
	});

	advSearchSlide.addEvent('complete', function() {
	    if (advSearchSlide.open) {
	        setCookie('advSearch', 'visible', 365, '/');
	        $('advancedSearchButton').className = 'bigButton arrowDown';
	        $('showAdvancedSearchHide').style.display = 'block';
	        $('showAdvancedSearchShow').style.display = 'none';
	        advancedSearchHidden = false;
	    } else {
	        setCookie('advSearch', 'hidden', 365, '/');
	        $('advancedSearchButton').className = 'bigButton arrowUp';
	        $('showAdvancedSearchShow').style.display = 'block';
	        $('showAdvancedSearchHide').style.display = 'none';
	        advancedSearchHidden = true;
	    }
	});

	// keep top part of search result at the top of the screen
	controlledDiv = $('SearchResultHeaderDynamic');
	if (controlledDiv)
	{
	    setInterval("manageScroll()", 1000/15);
	}

    createMouseOverEffect();	
}

/* mouse events for the search results list */
function createMouseOverEffect()
{
    var container = $("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() {    
}
