﻿//------------------------------------------------------------------------------------------

var Xrow;
if (typeof (Xrow) == 'undefined' || !Xrow) {
    Xrow = function() { };
}
function X_BrowserDetect() {
    doc = window.document;
    navVersion = navigator.appVersion.toLowerCase();
    this.ie4 = (!doc.getElementById && doc.all) ? true : false;
    this.ie5 = (navVersion.indexOf("msie 5.0") != -1) ? true : false;
    this.ie55 = (navVersion.indexOf("msie 5.5") != -1) ? true : false;
    this.ie6 = (navVersion.indexOf("msie 6.0") != -1) ? true : false;
    this.ie7 = (navVersion.indexOf("msie 7.0") != -1) ? true : false;
    this.isNS = (navigator.appName.indexOf('Netscape') != -1);
    this.isIE = (this.ie5 || this.ie55 || this.ie6 || this.ie7) ? true : false;
    this.isGecko = !this.isIE;
}
//Tao ra mot doi tuong anh theo duong dan 
Xrow.createImg = function(sPath) {
    var img = new Image();
    img.src = sPath;
    return img;
};
Xrow.Browser = new X_BrowserDetect();
//------------------------------------------------------------------------------------------
//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.windowHeight = function() {
    return Xrow.Browser.isNS ? window.top.innerHeight : window.top.document.documentElement.offsetHeight;
};
Xrow.windowWidth = function() {
    return Xrow.Browser.isNS ? window.top.innerWidth : window.top.document.documentElement.offsetWidth;
};
Xrow.windowTop = function() {
    return window.top.document.documentElement.scrollTop || window.top.document.body.scrollTop;
};

//------------------------------------------------------------------------------------------
//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) {
    e ? evt = e : evt = event;
    return evt.target ? evt.target : evt.srcElement;
}
//------------------------------------------------------------------------------------------
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 .';

    // 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'));
};
