﻿// --------------------------------
// Menu
// --------------------------------

function MenuOver(objId) {
    var dropMenuObj = document.getElementById(objId + 'DropMenu');
    if (dropMenuObj != null && dropMenuObj != 'undefined') {
        var menuItemPos = getObjPosition(document.getElementById(objId));
        dropMenuObj.style.left = (menuItemPos.x + 0) + 'px';
        if (document.getElementById(objId).className == 'First') {
            dropMenuObj.style.left = (menuItemPos.x + -15) + 'px';
        }
        else {

            dropMenuObj.style.left = (menuItemPos.x + 0) + 'px';
        }
        dropMenuObj.style.top = (menuItemPos.y + 25) + 'px';
        dropMenuObj.style.display = '';
    }
}

function MenuOut(objId) {
    var dropMenuObj = document.getElementById(objId + 'DropMenu');
    if (dropMenuObj != null && dropMenuObj != 'undefined') {
        dropMenuObj.style.display = 'none';
        dropMenuObj.style.top = '0px';
        dropMenuObj.style.left = '0px';
    }
}

// --------------------------------
// Position & size
// --------------------------------

function getObjPosition(obj) {
    x = y = 0;
    h = obj.offsetHeight;
    w = obj.offsetWidth;
    while (obj) {
        x += obj.offsetLeft;
        y += obj.offsetTop;
        obj = obj.offsetParent;
    }
    return { height: h, width: w, x: x, y: y }
}

function getBodySize() {
    var myWidth = 0, 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;
    }
    return { height: myHeight, width: myWidth }
}

// --------------------------------
// Print
// --------------------------------

function PrintPage() {
    window.print();
}

// --------------------------------
// Cookie
// --------------------------------

function SetCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
}

function GetCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function DeleteCookie(name, path, domain) {
    if (GetCookie(name)) {
        document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

// --------------------------------
// BrowserDetect
// --------------------------------

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: "OmniWeb",
		    versionSearch: "OmniWeb/",
		    identity: "OmniWeb"
		},
		{
		    string: navigator.vendor,
		    subString: "Apple",
		    identity: "Safari"
		},
		{
		    prop: window.opera,
		    identity: "Opera"
		},
		{
		    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"
		}
	],
    dataOS: [
		{
		    string: navigator.platform,
		    subString: "Win",
		    identity: "Windows"
		},
		{
		    string: navigator.platform,
		    subString: "Mac",
		    identity: "Mac"
		},
		{
		    string: navigator.platform,
		    subString: "Linux",
		    identity: "Linux"
		}
	]

};
BrowserDetect.init();

// --------------------------------
// Email
// --------------------------------

function WriteEmailAddress(a, x, y) {
    b = '@';
    c = '.';
    var output = '';
    output += a;
    output += b;
    output += x;
    output += c;
    output += y;
    document.write('<a href=\"mailto:' + output + '\" title=\"' + output + '\">' + output + '</a>');
}
