﻿Global = {
    setCookie: function(cName, value) {
        //alert("name: " + cName + " value: " + value + " days: " + days)
        //if (!days) days = 1; // default to 1 day if empty
        var expdate = new Date();
        //expdate.setTime(expdate.getTime() + days*24*60*60*1000);
        expdate.setFullYear(2035);  // Safari doesn't seem to accept dates after 2038
        document.cookie = cName + "=" + escape(value) + "; expires=" + expdate.toGMTString() + "; path=/";
        //document.cookie = cName + "=" + escape(value); 
    },

    getCookie: function(name) {
        var dc = document.cookie;
        var cname = name + "=";
        var clen = dc.length;
        var cbegin = 0;
        while (cbegin < clen) {
            var vbegin = cbegin + cname.length;
            if (dc.substring(cbegin, vbegin) == cname) {
                var vend = dc.indexOf(";", vbegin);
                if (vend == -1) vend = clen;
                return unescape(dc.substring(vbegin, vend));
            }
            cbegin = dc.indexOf(" ", cbegin) + 1;
            if (cbegin == 0) break;
        }
        return null;
    },

    addLoadEvent: function(func) {
        var oldonload = window.onload;
        if (typeof window.onload != 'function') {
            window.onload = func;
        }
        else {

            window.onload = function() {
                oldonload();
                func();
            }
        }
    },

    addUnLoadEvent: function(func) {
        var oldonunload = window.onunload;

        if (typeof window.onunload != 'function') {
            window.onunload = func;
        }
        else {
            window.onunload = function() {
                oldonunload();
                func();
            }
        }
    }
};



// Sweet PNG Hack on demand (http://homepage.ntlworld.com/bobosola/pnginfo.htm)
//  -- Just add this to img tag: onload="fixPNG(this)"   (Must have height/width defined)
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

function fixPNG(myImage) {
    if ((version >= 5.5) && (version < 7) && (document.body.filters)) {
        var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
        var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
        var imgTitle = (myImage.title) ?
		             "title='" + myImage.title + "' " : "title='" + myImage.alt + "' "
        var imgStyle = "display:inline-block;" + myImage.style.cssText
        var strNewHTML = "<span " + imgID + imgClass + imgTitle
                  + " style=\"" + "width:" + myImage.width
                  + "px; height:" + myImage.height
                  + "px;" + imgStyle + ";"
                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
        myImage.outerHTML = strNewHTML
    }
}

//apply png fix to all images on page load
//Event.observe(window, 'load', function() { $$('img.png').each(function(png) { fixPng(png) }) });

function backToProducts() {
    window.location = '/products/';
}

