var lastSub   = false;
var statusSub = 0;
var msg       = "";

    //if (!navigator.cookieEnabled && !RegExp("cookies=0").exec(window.location.href))
    if (!navigator.cookieEnabled && !window.location.href.indexOf("cookies=0"))
    {
        window.location.href = "index.php?cookies=0";
    }

function clickIE4()
{
    if (event.button == 2)
    {
        alert(msg);
        return false;
    }
}

function clickNS4(e)
{
    if (document.layers || document.getElementById && !document.all)
    {
        if (e.which == 2 || e.which==3)
        {
            alert(msg);
            return false;
        }
    }
}

function disableRightMouseButton(str, show)
{
    msg = str;
    
    if (document.layers)
    {
        document.captureEvents(Event.MOUSEDOWN);
        document.onmousedown = clickNS4;
    }
    else if (document.all && !document.getElementById)
    {
        document.onmousedown = clickIE4;
    }

    if (show)
    {
        document.oncontextmenu = new Function("alert('" + msg + "'); return false");
    }
    else
    {
        document.oncontextmenu = new Function("return false");
    }        
}

function attachObjEvent(oObject, oEvent, oFunction)
{
	if(document.all)
	{
		oObject.attachEvent("on" + oEvent, oFunction);
	}
	else
	{
		oObject.addEventListener(oEvent, oFunction, false);
	}
}

function goToScroll(id)
{
    window.location.href = "prod_list.php?category=" + id + "&top=" + document.body.scrollTop;
}

function checkRegExp(str, pattern)
{
	reg = new RegExp(pattern);	
	
	if (reg.exec(str))
	{			
		ret = (RegExp.$1 == str);
	}
	else
	{
		ret = false;
	}

	return ret;
}
function trim(str)
{
    return str.replace(/(^\s*)|(\s*$)/g, "");
}
function getAbsolutePosition(element)
{
    var positions;    
    var tempLeft    = element.offsetLeft;
    var tempTop     = element.offsetTop;        
    var tempElement = element;
        
    while (tempElement.tagName != "BODY")
    {
        tempLeft   += parseInt(tempElement.offsetLeft);
        tempTop    += parseInt(tempElement.offsetTop);            
        tempElement = tempElement.offsetParent;
    }        
    
    positions    = Array();
    positions[0] = parseInt(tempLeft);
    positions[1] = parseInt(tempTop);
    return positions;
}
function goTo(url)
{
    setBusy();
    window.location.href = url;
}

function liOut(src, event)
{
    src.className    = "";
	src.style.cursor = "default"; 
}

function liOver(src, event)
{
    src.className    = "over";
    src.style.cursor = "hand"; 
}

function divOut(src, event)
{
    src.className                       = 'menu';
	src.style.cursor                    = 'default'; 
}

function divOver(src, event)
{
    src.className                       = 'menuover';
	src.style.cursor                    = 'hand'; 
}

function divClick(src, i)
{
    if (lastSub == ("sub" + i))
    {
        statusSub = (statusSub + 1) % 2;
    }
    else
    {
        statusSub = 0;
    }
    
    if (statusSub)
    {
        disp1 = "block";
        disp2 = "none";
    }
    else
    {
        disp1 = "none";
        disp2 = "block";
    }
    
    if (lastSub)
    {
        document.getElementById(lastSub).style.display = disp1;
    }
    
    document.getElementById("sub" + i).style.display = disp2;    
    lastSub = "sub" + i;
    
}

function onChangeSelect(form)
{
    f = eval("document." + form);
    f.op.value = "select";
    f.submit();
}

function stepsBack(form)
{
    f = eval("document." + form);
    f.op.value = "back";
    f.submit();
}

function stepsNext(form)
{
    f = eval("document." + form);
    f.op.value = "next";
    f.submit();
}

function updateShoppingCart(form)
{
    f = eval("document." + form);
    f.op.value = "update";
    f.submit();
}

function emptyShoppingCart(form, msg)
{
    if (confirm(msg))
    {
        f = eval("document." + form);
        f.op.value = "empty";
        f.submit();
    }
}

function deleteLastProduct()
{
    form = "lastproduct";
    f = eval("document." + form);    
    f.op.value = "remove";
    f.submit();
}