var d, dom, nu = '',
    brow = '',
    ie, ie4, ie5, ie5x, ie6, ie7, ie11;
var ns4, moz, moz_rv_sub, release_date = '',
    moz_brow, moz_brow_nu = '',
    moz_brow_nu_sub = '',
    rv_full = '';
var mac, win, old, lin, ie5mac, ie5xwin, konq, saf, op, op4, op5, op6, op7, chrome;
var webkit;
d = document;
n = navigator;
nav = n.appVersion;
nan = n.appName;
nua = n.userAgent;
old = (nav.substring(0, 1) < 4);
mac = (nav.indexOf('Mac') != -1);
win = (((nav.indexOf('Win') != -1) || (nav.indexOf('NT') != -1)) && !mac) ? true : false;
lin = (nua.indexOf('Linux') != -1);




if (!document.layers) {
    dom = (d.getElementById) ? d.getElementById : false
} else {
    dom = false;
    ns4 = true
}
op = (nua.indexOf('Opera') != -1);
chrome = (nua.indexOf('Chrome') != -1) ? true : false;
saf = (!chrome && nua.indexOf('Safari') != -1) ? true : false;
konq = (!saf && (nua.indexOf('Konqueror') != -1)) ? true : false;
moz = ((!saf && !konq) && (nua.indexOf('Gecko') != -1)) ? true : false;
ie = ((nua.indexOf('MSIE') != -1) && !op);
webkit = (nua.indexOf('WebKit') != -1) ? true : false;


if (op) {
    str_pos = nua.indexOf('Opera');
    nu = nua.substr((str_pos + 6), 4);
    brow = 'Opera'
} else if (chrome) {
    str_pos = nua.indexOf('Chrome');
    nu = nua.substr((str_pos + 7), 5);
    brow = 'Chrome'
} else if (saf) {
    str_pos = nua.indexOf('Safari');
    nu = nua.substr((str_pos + 7), 5);
    brow = 'Safari'
} else if (konq) {
    str_pos = nua.indexOf('Konqueror');
    nu = nua.substr((str_pos + 10), 3);
    brow = 'Konqueror'
} else if (moz) {
    pattern = /[(); \n]/;
    moz_types = new Array('Firebird', 'Phoenix', 'Firefox', 'Iceweasel', 'Galeon', 'K-Meleon', 'Camino', 'Epiphany', 'Netscape6', 'Netscape', 'MultiZilla', 'Gecko Debian', 'rv');
    rv_pos = nua.indexOf('rv');
    rv_full = nua.substr(rv_pos + 3, 6);
    rv_slice = (rv_full.search(pattern) != -1) ? rv_full.search(pattern) : '';
    (rv_slice) ? rv_full = rv_full.substr(0, rv_slice) : '';
    nu = rv_full.substr(0, 3);
    for (i = 0; i < moz_types.length; i++) {
        if (nua.indexOf(moz_types[i]) != -1) {
            moz_brow = moz_types[i];
            break
        }
    }
    if (moz_brow) {
        str_pos = nua.indexOf(moz_brow);
        moz_brow_nu = nua.substr((str_pos + moz_brow.length + 1), 3);
        moz_brow_nu = (isNaN(moz_brow_nu)) ? moz_brow_nu = nu : moz_brow_nu;
        moz_brow_nu_sub = nua.substr((str_pos + moz_brow.length + 1), 8);
        sub_nu_slice = (moz_brow_nu_sub.search(pattern) != -1) ? moz_brow_nu_sub.search(pattern) : '';
        (sub_nu_slice) ? moz_brow_nu_sub = moz_brow_nu_sub.substr(0, sub_nu_slice) : ''
    }
    if (moz_brow == 'Netscape6') {
        moz_brow = 'Netscape'
    } else if (moz_brow == 'rv' || moz_brow == '') {
        moz_brow = 'Mozilla'
    }
    if (!moz_brow_nu) {
        moz_brow_nu = nu;
        moz_brow_nu_sub = nu
    }
    if (n.productSub) {
        release_date = n.productSub
    }
} else if (ie) {
    str_pos = nua.indexOf('MSIE');
    nu = nua.substr((str_pos + 5), 3);
    brow = 'Microsoft Internet Explorer'
} else {
    brow = nan
}
op5 = (op && (nu.substring(0, 1) == 5));
op6 = (op && (nu.substring(0, 1) == 6));
op7 = (op && (nu.substring(0, 1) == 7));
op8 = (op && (nu.substring(0, 1) == 8));
op9 = (op && (nu.substring(0, 1) == 9));
ie4 = (ie && !dom);
ie5 = (ie && (nu.substring(0, 1) == 5));
ie6 = (ie && (nu.substring(0, 1) == 6));
ie7 = (ie && (nu.substring(0, 1) == 7));

ie11 = (moz && (nu.substring(0, 2) == 11));
if (!nu) {
    nu = nav.substring(0, 1)
}
ie5x = (d.all && dom);
ie5mac = (mac && ie5);
ie5xwin = (win && ie5x);

function checkBrowser() {
    var browser = null;
    if (ie && nu >= 6.0) browser = brow + " " + nu;
    else if(ie11) browser = brow + " " + nu;
    else if (moz && moz_brow_nu >= 2.0 && moz_brow == "Firefox") browser = "Mozilla " + moz_brow + " " + moz_brow_nu;
    else if (chrome) browser = brow + " " + nu;
    else if (saf) browser = brow + " " + nu;
    return browser
}

function isIE6() {
    if (ie && nu >= 6.0 && nu < 7.0) return true;
    else return false
}

function isWebkit() {
    return webkit
}