/*
 * Slightly modified version of Prototip (http://insin.woaf.net/projects/history/index.html).
 * Based on Sweet Titles by Dustin Diaz.
 */
function init() {
    document.form_changed = 0;
    var x = document.forms['slform'].elements;
    for (var i=0;i<x.length;i++)
    {
        if ( x[i].name != 'shoplet_id') { 
            x[i].onchange = function (e) { register(e) };
        }
    }
}

function register(e)
{
    if (!e)
    {
        e = window.event;
        var targ = e.srcElement;
    }
    else
        var targ = e.target;

    document.form_changed = 1;
    return true;
}

var ProtoTip =
{
    xCord : 0,
    yCord : 0,
    obj : null,

    attachTooltipBehavior: function()
    {
        if (   !document.getElementById
            || !document.createElement
            || !document.getElementsByClassName)
        {
            return;
        }
        
        Event.observe(document, 'mousemove', ProtoTip.updateXY, false);
        if (document.captureEvents)
        {
            document.captureEvents(Event.MOUSEMOVE);
        }

        var elements = document.getElementsByClassName('tooltip');
        for (var j = 0, element; element = elements[j]; j++)
        {
            if (!element.getAttribute('tip')) // Safely allow multiple calls
            {
                Event.observe(element, 'mouseover', ProtoTip.tipOver, false);
                Event.observe(element, 'mouseout', ProtoTip.tipOut, false);
                var title = element.title;
                var parts = title.split(/:/, 2);
                element.setAttribute('tip_title', parts[0]);
                element.setAttribute('tip', parts[1]);
                element.removeAttribute('title');
            }
        }
    },

    updateXY: function(e)
    {
        ProtoTip.xCord = Event.pointerX(e);
        ProtoTip.yCord = Event.pointerY(e);
    },

    tipOut: function(e)
    {
        if (window.tID)
        {
            clearTimeout(tID);
        }
        if (window.opacityID)
        {
            clearTimeout(opacityID);
        }

        var div = $('toolTip');
        if (div != null)
        {
            div.parentNode.removeChild(div);
        }
    },

    checkNode: function(obj)
    {
        if (obj.nodeName.toLowerCase() == 'a')
        	return obj;
        return obj.parentNode;
    },

    tipOver: function(e)
    {
        ProtoTip.obj = Event.element(e);
        tID = setTimeout('ProtoTip.tipShow()', 10)
    },

    tipShow: function()
    {
        var element = ProtoTip.checkNode(ProtoTip.obj);

        var tooltip = document.createElement('div');
        tooltip.id = 'toolTip';
        document.body.appendChild(tooltip);
        tooltip.innerHTML = 
            '<span class="tl">&nbsp;</span><span class="tr">&nbsp;</span>' +
            '<h5>' + element.getAttribute('tip_title') + '</h5>' +
            '<p>' + element.getAttribute('tip') + '</p>' +
	        '<span class="bl">&nbsp;</span><span class="br">&nbsp;</span>' + 
	        '<div class="cl">&nbsp;</div>';
		tooltip.style.zIndex = 99999;
		
        var top = ProtoTip.yCord + 15;
        var left = ProtoTip.xCord + 10;

        // Prevent horizontal hiding
        if (ProtoTip.willOverflowHorizontal(tooltip.offsetWidth + left))
        {
            tooltip.style.right = '20px';
        }
        else
        {
            tooltip.style.left = left + 'px';
        }

        // Prevent vertical hiding
        if (ProtoTip.willOverflowVertical(tooltip.offsetHeight + top))
        {
            tooltip.style.top = (ProtoTip.yCord - tooltip.offsetHeight - 10) + 'px';
        }
        else
        {
            tooltip.style.top = top + 'px';
        }
        
        // tooltip.style.opacity = '.1';
        // tooltip.style.filter = 'alpha(opacity:10)';
        // ProtoTip.tipFade('toolTip', 10);
    },

    willOverflowHorizontal: function(tooltipRight)
    {
        var x;
        if (self.innerHeight) // all except Explorer
        {
            x = self.innerWidth;
        }
        else if (document.documentElement && document.documentElement.clientHeight)
            // Explorer 6 Strict
        {
            x = document.documentElement.clientWidth;
        }
        else if (document.body) // other Explorers
        {
            x = document.body.clientWidth;
        }

        var scrollX;
        if (self.pageYOffset) // all except Explorer
        {
            scrollX = self.pageXOffset;
        }
        else if (document.documentElement && document.documentElement.scrollTop)
            // Explorer 6 Strict
        {
            scrollX = document.documentElement.scrollLeft;
        }
        else if (document.body) // all other Explorers
        {
            scrollX = document.body.scrollLeft;
        }

        return (tooltipRight > x + scrollX);
    },

    willOverflowVertical: function(tooltipBottom)
    {
        var y;
        if (self.innerHeight) // all except Explorer
        {
            y = self.innerHeight;
        }
        else if (document.documentElement && document.documentElement.clientHeight)
            // Explorer 6 Strict Mode
        {
            y = document.documentElement.clientHeight;
        }
        else if (document.body) // other Explorers
        {
            y = document.body.clientHeight;
        }

        var scrollY;
        if (self.pageYOffset) // all except Explorer
        {
            scrollY = self.pageYOffset;
        }
        else if (document.documentElement && document.documentElement.scrollTop)
            // Explorer 6 Strict
        {
            scrollY = document.documentElement.scrollTop;
        }
        else if (document.body) // all other Explorers
        {
            scrollY = document.body.scrollTop;
        }

        return (tooltipBottom > y + scrollY);
    }
};

Event.observe(window, 'load', ProtoTip.attachTooltipBehavior, false);

