function HideOfferLabel()
{
    if (document.getElementById('lbl1'))
        document.getElementById('lbl1').style.display = 'none';
}
function ShowOfferLabel()
{
    if (document.getElementById('lbl1'))
        document.getElementById('lbl1').style.display = '';
}
function OnOfferLabelClick(id)
{                                                             
    if (document.getElementById(id))
    {
        document.getElementById(id).focus();
    }
}
function CheckOfferLabel(id)
{
    if (document.getElementById(id))
    {
        var val = document.getElementById(id).value;   
        if (val.length > 0)
            HideOfferLabel();
        else
            ShowOfferLabel();
    }
}



function RoomClick(obj, bCheckLot, LotId)
{
    var iRoom = obj.value;
    var checked = (obj.checked) ? 1 : 0;
    var sUrl = '/basket/ajax.php';

    if (!obj.checked)
        AllChDeselect();

    obj.disabled = true;
    
    function complete_handler(data)
    {
        obj.disabled = false;
        RefreshBasketCounter();
    }
    
    sUrl = sUrl + '?click=Y&room=' + iRoom + '&ch=' + checked;
    if (bCheckLot)
        sUrl += '&check_lot=Y&lot='+LotId;
    jsAjaxUtil.LoadData(sUrl, complete_handler);
}
function RoomForBasket(iRoom)
{
    var sUrl = '/basket/ajax.php';    
    
    var div = document.getElementById('basket_for_add');
    var new_div = document.getElementById('basket_for_drop');
    if (div && div.style.display == 'none')
    {
        div = document.getElementById('basket_for_drop');    
        new_div = document.getElementById('basket_for_add');    
    }
    
    jsAjaxUtil.ShowLocalWaitWindow(iRoom, div);
    
    function complete_handler(data)
    {
        jsAjaxUtil.CloseLocalWaitWindow(iRoom, div);
        new_div.style.display = 'block';
        div.style.display = 'none';
        RefreshBasketCounter();      
    }
    
    sUrl = sUrl + '?room_click=Y&room=' + iRoom;
    jsAjaxUtil.LoadData(sUrl, complete_handler);   
}
function RefreshBasketCounter()
{                     
    var sUrl = '/basket/ajax.php'; 
    
    function complete_handler(data)
    {                                                
        jQuery(".basket_cnt").each(function(){this.innerHTML = data;});        
        if (data>0)
        {
            jQuery(".room-links").each(function(){this.style.display = 'block';});    
            jQuery(".basketlink").each(function(){this.style.display = 'block';});    
        }
        else    
        {
            jQuery(".room-links").each(function(){this.style.display = 'none';});                
            jQuery(".basketlink").each(function(){this.style.display = 'none';});                
        }
    }
    
    sUrl = sUrl + '?count=Y';
    jsAjaxUtil.LoadData(sUrl, complete_handler); 
}
function RefreshBasketSum()
{                     
    var sUrl = '/basket/ajax.php'; 
    
    function complete_handler(data)
    {                                               
        jQuery(".basket_sum").each(function(){this.innerHTML = data;});        
    }
    
    sUrl = sUrl + '?sum=Y';
    jsAjaxUtil.LoadData(sUrl, complete_handler); 
}
function RefreshSelectedSum(sLot, sFloor)
{
    var sUrl = '/basket/ajax.php';

    function complete_handler(data)
    {
        jQuery(".sel_sum").each(function(){this.innerHTML = data;});
    }

    sUrl = sUrl + '?sel_sum=Y&lot=' + sLot + '&floor=' + sFloor;
    jsAjaxUtil.LoadData(sUrl, complete_handler);
}
function CheckAllRoom(obj)
{
    bCheck = obj.checked;
    if (bCheck)
        jQuery("td.ch input").attr('checked', true);
    else
        jQuery("td.ch input").attr('checked', false);
}


function SetPrintCSS(isPrint)
{
 var link;

 if (document.getElementsByTagName)
 link = document.getElementsByTagName('link');
 else if (document.all)
 link = document.all.tags('link');
 else
 return;

 for (var index=0; index < link.length; index++)
 {
 if (!link[index].title || link[index].title != 'print')
 continue;

 if (isPrint)
 {
 link[index].disabled = false;
 link[index].rel = "stylesheet";  
 jQuery('.bubble').each(function(){this.style.display='none';});
 jQuery('.ugol-lt').each(function(){this.style.display='none';});
 jQuery('.ugol-lb').each(function(){this.style.display='none';});
 jQuery('.ugol-rt').each(function(){this.style.display='none';});
 jQuery('.ugol-rb').each(function(){this.style.display='none';});
 
 print();
 }
 else
 {
 link[index].disabled = true;
 link[index].rel = "alternate stylesheet";
 
 jQuery('.bubble').each(function(){this.style.display='';});
 jQuery('.ugol-lt').each(function(){this.style.display='';});
 jQuery('.ugol-lb').each(function(){this.style.display='';});
 jQuery('.ugol-rt').each(function(){this.style.display='';});
 jQuery('.ugol-rb').each(function(){this.style.display='';});
 }
 }
         
}

function BackToDesignMode()
{
 if (document.all)
 window.location.href = window.location.href.replace('#print','');
 else
 SetPrintCSS(false);

 return false;
}

function SelectAllPage(obj)
{
    ch = obj.checked;
    jQuery('td.ch input').each(function(){
        if (this.checked != ch)
        {
            this.checked = ch;
            RoomClick(this);
        }
    });
}
function AllChDeselect()
{
    jQuery('#all_target').attr('checked', false);
}

/***************************_ROBOINF_*********************************/
var doc_min_width = 1237;
var is_robo_showed = false;
var is_robo_active = false;
var robo_default_right = -120;
var robo_orig_width = 400;
var robo_mask_def_width = 120;
var robo_not_active_min_top = 330;
function RoboInfHideShow(){
    if(jQuery(window).width() < doc_min_width){
        if(is_robo_showed && !is_robo_active){
                jQuery("#robo_inf").hide();
                is_robo_showed = false;                
            }
    }else{
        if(!is_robo_showed){
            jQuery("#robo_inf").show();
            is_robo_showed = true;
        }
    }
}

function RoboInfAutoPos(){
var robo_top = Math.round(jQuery(window).height()/2+jQuery(window).scrollTop()-jQuery("#robo_inf").height()/2);
var robo_right = robo_default_right;
    if(is_robo_active){
        robo_right = Math.round(jQuery("#robo_inf").parent().width()/2-robo_orig_width/2)+'px';
    }else if(robo_top < robo_not_active_min_top){
        robo_top = robo_not_active_min_top;
    }
    robo_top += 'px';
    jQuery("#robo_inf").css({
        top: robo_top,
        right: robo_right
    });
}

function RoboInfActive(){
is_robo_active = true;
is_robo_showed = true;
var robo_top = Math.round(jQuery(window).height()/2+jQuery(window).scrollTop()-jQuery("#robo_inf").height()/2)+'px';
var robo_right = Math.round(jQuery("#robo_inf").parent().width()/2-robo_orig_width/2)+'px';
    jQuery("#robo_inf").show().animate({       
        top: robo_top,
        right: robo_right,
        width: robo_orig_width        
    },"fast",function(){
        jQuery("div.robo_crnrs").show();
    });    
    jQuery("#robo_mask").animate({
        width: robo_orig_width-4
    },"fast",function (){
        jQuery("#robo_mask").css({
        'border-left': '2px solid #4b95c7',
        'border-right': '2px solid #4b95c7'
        });
    });    
    jQuery("#robo_lnk, #robo_show").animate({opacity: 0},"fast",function(){jQuery(this).hide();});
    jQuery("#robo_close,#robo_br").show().animate({opacity: 1},"fast");
}

function RoboInfDeactive(){
is_robo_active = false;
var robo_top = Math.round(jQuery(window).height()/2+jQuery(window).scrollTop()-jQuery("#robo_inf").height()/2);
    if(robo_top < robo_not_active_min_top){
            robo_top = robo_not_active_min_top;
        }
    jQuery("#robo_inf").animate({        
        top: robo_top,
        right: robo_default_right,
        width: jQuery("#robo_lnk").width()
    },"fast",function(){RoboInfHideShow();});
    jQuery("div.robo_crnrs").hide();
    jQuery("#robo_mask").animate({
        width: robo_mask_def_width
    },"fast");
    jQuery("#robo_mask").css({
        'border-left': '0',
        'border-right': '0'
    });
    jQuery("#robo_lnk, #robo_show").show().animate({opacity: 1},"fast");
    jQuery("#robo_close,#robo_br").animate({opacity: 0},"fast",function(){jQuery(this).hide();});    
}

jQuery(document).ready(function(){
    jQuery(window).bind("scroll resize",function (){
        RoboInfAutoPos();
        RoboInfHideShow();
    });
    
    jQuery("#robo_lnk,#robo_lnk2").click(function(){
        if(is_robo_active) return false;
        RoboInfActive();
        return false;
    });
    
    jQuery("#robo_close").click(function(){
        RoboInfDeactive();
    });
    
    RoboInfHideShow();
});
