﻿var ctlTinRaoTomTat_XemBanDoRieng_MaTinRao="";
var Top_Limit=0;
var Left_Limit=0;
var ctlTinRaoTomTat_DaXemBanDoRieng=0;

function ctlTinRaoTomTat_load(ctlID)
{
    ctlPageTool_load(ctlID+"_ctlPhanTrang");
}

function ctlTinRaoTomTat_selectItem(ctlID, MaTinRao, urlTinRao, e)
{
    try
    {
        var BanDoID = document.getElementById(ctlID+"_txtBanDoID").value;
        var MaLoaiTinRao = parseInt(document.getElementById(ctlID+"_txtMaLoaiTinRao").value);
        ctlBanDo_showMarker(BanDoID, 1, MaLoaiTinRao, MaTinRao);
        ctlTinRaoTomTat_XemBanDoRieng(ctlID, MaTinRao, urlTinRao, e);
        ctlTinRaoTomTat_DaXemBanDoRieng=1;
    }
    catch(e)
    {
    }
}

function ctlTinRaoTomTat_btnXemBanDoRieng(ctlID, MaTinRao, urlTinRao, e)
{
    if(!ctlTinRaoTomTat_DaXemBanDoRieng)
    {
        ctlTinRaoTomTat_XemBanDoRieng(ctlID, MaTinRao, urlTinRao, e);
    }
    ctlTinRaoTomTat_DaXemBanDoRieng=0;
}


function ctlTinRaoTomTat_XemBanDoRieng(ctlID, MaTinRao, urlTinRao, e)
{
    var divBanDoRieng = document.getElementById("divBanDoRieng");
    var divBanDoRieng_Arrow = document.getElementById("divBanDoRieng_Arrow");
    try
    {
        var HT='none';
        if(ctlTinRaoTomTat_XemBanDoRieng_MaTinRao==MaTinRao)
        {
            if(divBanDoRieng.style.display == 'none')
            {
                HT = '';
            }
        }
        else
        {
            HT = '';
        }
        if(HT=='')
        {
            var divBanDoRieng_link = document.getElementById("divBanDoRieng_link");
            divBanDoRieng_link.href = urlTinRao ;
            ctlTinRaoTomTat_XemBanDoRieng_MaTinRao=MaTinRao;
            if(Top_Limit==0)
            {
                var ctl = document.getElementById(ctlID);
                var ctlBounds   = Sys.UI.DomElement.getBounds(ctl);
//                Left_Limit = ctlBounds.x;
                Top_Limit = ctlBounds.y;
            }
            var divTinRao=document.getElementById("div"+ctlID+"_"+MaTinRao);
            var divTinRaoBounds   = Sys.UI.DomElement.getBounds(divTinRao);
            //var mp = getMousePosition(e);            
            //var x=mp.x - 270;
            //var y=mp.y - 235;
            var x=divTinRaoBounds.x - 550;
            var y=divTinRaoBounds.y - 280;
            
//            if(x < Left_Limit)
//            {
//                x = x + 275;
//            }
            if(y < Top_Limit)
            {
                y = Top_Limit;
            }
            Sys.UI.DomElement.setLocation(divBanDoRieng, x, y);
            
            var xArrow=divTinRaoBounds.x - 287;
            var yArrow=divTinRaoBounds.y - 30;
            //Sys.UI.DomElement.setLocation(divBanDoRieng_Arrow, xArrow, yArrow);
        }        
        divBanDoRieng.style.display = HT;
        //divBanDoRieng_Arrow.style.display = HT;
        if(HT=='')
        {
            var BanDoID = "BanDoRieng";
            var MaLoaiTinRao = parseInt(document.getElementById(ctlID+"_txtMaLoaiTinRao").value);
            ctlBanDo_setMarkerMode(BanDoID, 1, MaLoaiTinRao);
            ctlBanDo_showMarker(BanDoID, 1, MaLoaiTinRao, MaTinRao);
        }
    }
    catch(e)
    {
    } 
}


function ctlTinRaoTomTat_LuuTrangRieng(ctlID,MaTinRao)
{
    PageMethods.LuuTrangRieng(MaTinRao, ctlTinRaoTomTat_LuuTrangRieng_CallSuccess, ctlTinRaoTomTat_LuuTrangRieng_CallFailed);
}

function ctlTinRaoTomTat_LuuTrangRieng_CallSuccess(res)
{ 
    alert(res);
}

function ctlTinRaoTomTat_LuuTrangRieng_CallFailed(res)
{
    alert(res.get_message());
}

function getMousePosition(e)
{
    return e.pageX ? {'x':e.pageX, 'y':e.pageY}:{'x':e.clientX + (document.documentElement ? document.documentElement.scrollLeft : document.body.scrollLeft),'y':e.clientY + (document.documentElement ? document.documentElement.scrollTop : document.body.scrollTop)};
}