﻿$(document).ready(function () {
    if (BrowserDetect.browser == "Explorer" && BrowserDetect.version <= 7) $("#logoAndSearch .site").css({ "margin-top": "89px" });
});

function getQueryString(key, default_) {
    if (default_ == null) default_ = "";
    key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
    var qs = regex.exec(window.location.href);
    if (qs == null) return default_;
    else return qs[1];
}
function getCookie(c_name) {
    var i, x, y, ARRcookies = document.cookie.split(";");
    for (i = 0; i < ARRcookies.length; i++) {
        x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
        y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
        x = x.replace(/^\s+|\s+$/g, '');
        if (x == c_name) {
            return unescape(y);
        }
    }
}
var val = getQueryString("overwritefull");
if (val == "y") document.cookie = "overwrite_mobile=true";
if ((DetectIphoneOrIpod() || DetectIpad()) && getCookie("overwrite_mobile") != "true" && window.location.hostname == "www.techlighting.com") window.location = "http://m.techlighting.com/";

var myWidth = 0;
var myHeight = 0;

if (typeof (window.innerWidth) == 'number') {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
}
else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
}
else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
}

function submitHomePage(val, f) {
    var whichBtn = $get("whichBtnClicked");
    var fm = $get("aspnetForm");
    whichBtn.value = val;

    fm.submit();
}

function showNavMenu(id, level, menuWidth, parentWidth, parentID, itemDown) {
    hideAllTopLevelMenus();

    parentID = (parentID != 0) ? parentID : id;
    var menuImgObj = $get("menuImg_" + parentID);

    var menu = "menu_" + id
    var divObj = $get(menu);
    var moveDown = (itemDown > 1) ? itemDown * 16 : 0;

    parentWidth = (parentWidth != 0) ? parentWidth : menuWidth;

    if (divObj) {
        //alert(getPos(menuImgObj).x + "\n" + parentWidth + "\n" + level);
        divObj.className = "navMenuShow";
        xPos = getPos(menuImgObj).x + (parentWidth * level);
        yPos = getPos(menuImgObj).y + 24;
        xPos = (menuWidth == parentWidth) ? xPos : xPos + 6
        yPos = (menuWidth == parentWidth) ? yPos : yPos + (moveDown);

        divObj.style.left = xPos + "px";
        divObj.style.top = yPos + "px";
        divObj.style.width = menuWidth + "px";
    }
}
function hideNavMenu(id) {
    var sp = id.split("_");
    var menu = (sp.length <= 1) ? "menu_" + id : id;
    var divObj = $get(menu);

    if (!event.fromElement.contains(event.toElement) && !divObj.contains(event.toElement)) {
        // Test to see what's being passed
        if (divObj)
            divObj.className = "navMenuHide";
    }
}
function hideAllTopLevelMenus() {
    var id = "\n";
    var divs = document.getElementsByTagName('div');

    for (var i = 0; i < divs.length; i++) {
        if (divs[i].title == "navMenus" && divs[i].className != "undefined") {
            var sp = divs[i].id.split("_");
            hideNavMenu(sp[1]);
        }
    }
}

function getPos(elm) {
    for (var zx = zy = 0; elm != null; zx += elm.offsetLeft, zy += elm.offsetTop, elm = elm.offsetParent);
    return { x: zx, y: zy }
}

function searchFocus(t) {
    if (t.value == "SEARCH PRODUCT NAMES AND SKUS")
        t.value = "";
    else t.select();
}
function searchBlur(t) {
    if (t.value == "")
        t.value = "SEARCH PRODUCT NAMES AND SKUS";
}


function catalogWindow(url) {
    window.open("CatalogView.aspx?" + url, "_blank", "status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=0,height=600,width=800");
}

var tempX = 0;
var tempY = 0;
var IE = document.all ? true : false;

function getMousePositionX() {
    if (!IE) document.captureEvents(Event.MOUSEDOWN);

    document.onmousemove = getMouseXY;
    return tempX;
}

function getMousePositionY() {
    if (!IE) document.captureEvents(Event.MOUSEDOWN);

    document.onmousedown = getMouseXY;
    return tempY;
}

function getMouseXY(e) {
    if (IE) {
        tempX = event.clientX + document.body.scrollLeft;
        tempY = event.clientY + document.body.scrollTop;
    }
    else {
        tempX = e.pageX;
        tempY = e.pageY;
    }
    return true;
}

function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
        while (1) {
            curleft += obj.offsetLeft;
            if (!obj.offsetParent) break;
            obj = obj.offsetParent;
        }
    }
    else if (obj.x)
        curleft += obj.x;

    return curleft;
}

/* Show News Details
/****************************************************/
function showNews(title, date, desc, pdf, url) {
    msg = "<strong style='font-family:Calibri, Sans-Serif;'>" + title + "</strong><br />";
    msg += "<label style='font-family:Calibri, Sans-Serif;'>" + date + "</label><br /><br />";

    if (desc && desc != "") msg += "<label style='font-family:Calibri, Sans-Serif;'>" + desc + "</label><br /><br />";
    if (pdf && pdf != "") msg += "<a href='" + url + "/Tech/documents/news_events/" + pdf + "' target='_blank' style='text-decoration:underline;color:#000;'>Download PDF</a>";

    popItUp(msg);
}
function popItUp(msg) {
    var label = $get('helpLabel');
    label = (!label) ? $get('helpLabel') : label;
    label = (!label) ? $get('ctl00_helpLabel') : label;

    label.innerHTML = msg;

    var panel = $get('helpPanelMPE');
    panel = (!panel) ? $find('helpPanelMPE') : panel;
    panel = (!panel) ? $find('ctl00_helpPanelMPE') : panel;

    panel.show();
}
/****************************************************/

function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        while (1) {
            curtop += obj.offsetTop;
            if (!obj.offsetParent) break;
            obj = obj.offsetParent;
        }
    }
    else if (obj.y)
        curtop += obj.y;

    return curtop;
}

function removeBadHiddenText() {
    var resObj = $get("hiresTxt");
    if (resObj != null) resObj.value = "";
}

function checkEnter(e) {
    var key;

    if (window.event)
        key = window.event.keyCode;
    else
        key = e.which;

    return (key != 13);
}

var BrowserDetect = {
    init: function () {
        this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
        this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
        this.OS = this.searchString(this.dataOS) || "an unknown OS";
    },
    searchString: function (data) {
        for (var i = 0; i < data.length; i++) {
            var dataString = data[i].string;
            var dataProp = data[i].prop;
            this.versionSearchString = data[i].versionSearch || data[i].identity;
            if (dataString) {
                if (dataString.indexOf(data[i].subString) != -1)
                    return data[i].identity;
            }
            else if (dataProp)
                return data[i].identity;
        }
    },
    searchVersion: function (dataString) {
        var index = dataString.indexOf(this.versionSearchString);
        if (index == -1) return;
        return parseFloat(dataString.substring(index + this.versionSearchString.length + 1));
    },
    dataBrowser: [
		{
		    string: navigator.userAgent,
		    subString: "Chrome",
		    identity: "Chrome"
		},
		{ string: navigator.userAgent,
		    subString: "OmniWeb",
		    versionSearch: "OmniWeb/",
		    identity: "OmniWeb"
		},
		{
		    string: navigator.vendor,
		    subString: "Apple",
		    identity: "Safari",
		    versionSearch: "Version"
		},
		{
		    string: navigator.vendor,
		    subString: "iCab",
		    identity: "iCab"
		},
		{
		    string: navigator.vendor,
		    subString: "KDE",
		    identity: "Konqueror"
		},
		{
		    string: navigator.userAgent,
		    subString: "Firefox",
		    identity: "Firefox"
		},
		{
		    string: navigator.vendor,
		    subString: "Camino",
		    identity: "Camino"
		},
		{		// for newer Netscapes (6+)
		    string: navigator.userAgent,
		    subString: "Netscape",
		    identity: "Netscape"
		},
		{
		    string: navigator.userAgent,
		    subString: "MSIE",
		    identity: "Explorer",
		    versionSearch: "MSIE"
		},
		{
		    string: navigator.userAgent,
		    subString: "Gecko",
		    identity: "Mozilla",
		    versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
		    string: navigator.userAgent,
		    subString: "Mozilla",
		    identity: "Netscape",
		    versionSearch: "Mozilla"
		},
		{
		    prop: window.opera,
		    identity: "Opera",
		    versionSearch: "Version"
		}
	],
    dataOS: [
		{
		    string: navigator.platform,
		    subString: "Win",
		    identity: "Windows"
		},
		{
		    string: navigator.platform,
		    subString: "Mac",
		    identity: "Mac"
		},
		{
		    string: navigator.userAgent,
		    subString: "iPhone",
		    identity: "iPhone/iPod"
		},
		{
		    string: navigator.platform,
		    subString: "Linux",
		    identity: "Linux"
		}
	]

};
BrowserDetect.init();
