﻿//------------------------------------------------------------------------------------------
var oTarget;
$(document).ready(function() {
    $(document).bind('mousedown', function(e) { getTarget(e); });
}
    );
var Xrow;
if (typeof (Xrow) == 'undefined' || !Xrow) {
    Xrow = function() { };
}
//Tao ra mot doi tuong anh theo duong dan 
Xrow.createImg = function(sPath) {
    var img = new Image();
    img.src = sPath;
    return img;
};
function getTarget(e) {
    evt = e ? e : event;
    oTarget = evt.target ? evt.target : evt.srcElement;
}
//------------------------------------------------------------------------------------------
//Lay ve doi tuong theo id
Xrow.getObj = function(id, o) {
    if (!o) {
        if (document.getElementById) {
            obj = document.getElementById(id);
        }
        else if (document.all) {
            obj = document.all[id];
        }
        else if (document.layers) {
            obj = document[id];
        }
    }
    else {
        if (top.document.getElementById) {
            obj = top.document.getElementById(id);
        }
        else if (top.document.all) {
            obj = top.document.all[id];
        }
        else if (top.document.layers) {
            obj = top.document[id];
        }
    }
    return obj;
};

//------------------------------------------------------------------------------------------
//Lay ve thong tin vi tri cua mot doi tuong theo id
//x,y,width,height
Xrow.getPosId = function(id) {
    var pos = new Object();
    pos.x = 0;
    pos.y = 0;
    pos.width = 0;
    pos.height = 0;
    if (Xrow.getObj(id)) {
        pos.x = $('#' + id).position().left;
        pos.y = $('#' + id).position().top;
        pos.width = $('#' + id).outerWidth();
        pos.height = $('#' + id).outerHeight();
    }
    return pos;
};
//------------------------------------------------------------------------------------------
//Lay ve thong tin vi tri cua mot doi tuong 
//x,y,width,height
Xrow.getPosObj = function(obj) {
    return WebForm_GetElementPosition(obj);
};
//------------------------------------------------------------------------------------------
//Lay ve vi tri cua scrollbar ngang
Xrow.getScrX = function() {
    return WebForm_GetScrollX();
};
//------------------------------------------------------------------------------------------
//Lay ve vi tri cua scrollbar doc
Xrow.getScrY = function() {
    return WebForm_GetScrollY();

};
Xrow.windowTop = function() {
    return window.top.document.documentElement.scrollTop || window.top.document.body.scrollTop;
};
Xrow.ScrollDown = function() {
    if ($.browser.opera) { $('html').animate({ scrollTop: $('#scrollDown').offset().top }, 2000); } else $('html,body').animate({ scrollTop: $('#scrollDown').offset().top }, 2000);
};
Xrow.ScrollUp = function() {
    if ($.browser.opera) { $('html').animate({ scrollTop: $('#scrolltest').offset().top }, 2000); } else $('html,body').animate({ scrollTop: $('#scrolltest').offset().top }, 2000);
};
//------------------------------------------------------------------------------------------
//Lay ve do cao cua cua so trinh duyet
Xrow.clientHeight = function() {
    if (document.body)
        return document.body.clientHeight;
    else if (document.documentElement && document.documentElement.clientHeight)
        return document.documentElement.clientHieght;
    return 0;
};
//------------------------------------------------------------------------------------------
//Lay ve do rong cua cua so trinh duyet
Xrow.clientWidth = function() {
    if (document.body)
        return document.body.clientWidth;
    else if (document.documentElement && document.documentElement.clientWidth)
        return document.documentElement.clientWidth;

    return 0;
};
//------------------------------------------------------------------------------------------
//Loai bo khoang trang o hai dau mot chuoi
Xrow.Trim = function(iStr) {
    return iStr.replace(/^\s+|\s+$/g, '');
};
//-----------------------------------------------------------------------------------------
//Tao mot cookie theo ten , gia tri, va thoi gian song
Xrow.setCookie = function(name, value, duration) {
    CookieString = name + "=" + escape(value) + ";EXPIRES=" + Xrow.getExpDate(duration) + ";PATH=/";
    document.cookie = CookieString;
};
//-----------------------------------------------------------------------------------------
//Doc thong tin mot cookie theo ten
Xrow.getCookie = function(name) {
    var CookieString = "" + document.cookie;
    var index1 = CookieString.indexOf(name);
    if (index1 == -1 || name == "") return "";
    var index2 = CookieString.indexOf(';', index1);
    if (index2 == -1) index2 = CookieString.length;
    return unescape(CookieString.substring(index1 + name.length + 1, index2));
};
//------------------------------------------------------------------------------------------
Xrow.getExpDate = function(DayCount) {
    var UTCstring;
    Today = new Date();
    nomilli = Date.parse(Today);
    Today.setTime(nomilli + DayCount * 24 * 60 * 60 * 1000);
    UTCstring = Today.toUTCString();
    return UTCstring;
};
//------------------------------------------------------------------------------------------
//Ma cua phim duoc bam
Xrow.getKey = function(e) {
    if (document.all)
        return e.keyCode;
    else
        return e.which;
};
//------------------------------------------------------------------------------------------
// Lay ve doi tuong dich
Xrow.getTarget = function(e) {
    evt = e ? e : event;
    oTarget = evt.target ? evt.target : evt.srcElement;
    return oTarget;
}
//------------------------------------------------------------------------------------------
Xrow.CheckCapsLock = function(e) {
    var myKeyCode = 0;
    var myShiftKey = false;
    var myMsg = 'Phím Caps Lock đang bật.\nĐể nhập mật khẩu chính xác,Bạn nên tắt phím Caps Lock .';
    switch (xLg) {
        case "en":
            myMsg = "Caps Lock is on.\n Please turn off Caps Lock and re-enter password.";
    }


    // Internet Explorer 4+
    if (document.all) {
        myKeyCode = e.keyCode;
        myShiftKey = e.shiftKey;

        // Netscape 4
    }
    else if (document.layers) {
        //alert('Netscape 4')
        myKeyCode = e.which;
        myShiftKey = (myKeyCode == 16) ? true : false;

        // Netscape 6
    }
    else if (document.getElementById) {
        //alert(e.shiftKey)
        myKeyCode = e.which;
        myShiftKey = e.shiftKey

    }

    // Upper case letters are seen without depressing the Shift key, therefore Caps Lock is on
    if ((myKeyCode >= 65 && myKeyCode <= 90) && !myShiftKey) {
        alert(myMsg);
        return false;
    }
    else if ((myKeyCode >= 97 && myKeyCode <= 122) && myShiftKey) {
        alert(myMsg);
        return false;
    }
};
//------------------------------------------------------------------------------------------
//Xoa noi dung trong tat ca cac o textbox
Xrow.ClearText = function() {
    $("input[type='text']").attr('value', '');
};
Xrow.CheckAll = function(o, id) {
    $('input[id$=_' + id + ']').attr('checked', $('#' + o.id).attr('checked'));
    if ($('#' + o.id).attr('checked'))
        $('input[id$=_' + id + ']').parent().parent().parent().toggleClass('actived');
    else
        $('input[id$=_' + id + ']').parent().parent().parent().removeClass('actived');
};
Xrow.CheckTreeAll = function(o, trace) {
    if (!$(o).attr('checked'))
        $(o).parent().parent().parent().removeClass('actived');
    if (trace) {
        var spanID = $(o).parent().attr('guid');
        var arr = spanID.split('#');
        for (var i = 0; i < arr.length; i++) {
            if ($(o).attr('checked')) {
                $('span[guid=' + spanID + ']').find('input[type=checkbox]').attr('checked', $(o).attr('checked'));
                $('span[guid=' + spanID + ']').parent().parent().toggleClass('actived')
            }
            spanID = spanID.replace(arr[i] + '#', '');
        }
    }
    else {
        if ($(o).attr('checked'))
            $(o).parent().parent().parent().toggleClass('actived');
    }
    $('span[guid$=#' + $(o).parent().attr('guid') + ']').each(function() {
        if ($(o).attr('checked'))
            $(this).parent().parent().toggleClass('actived')
        else
            $(this).parent().parent().removeClass('actived')
        $(this).find('input[type=checkbox]').attr('checked', $(o).attr('checked'));

    });

}
