document.observe("dom:loaded", function() {

	$$("#headmenulist li").each( function(x) {
		Event.observe($(x), 'mouseover', function(xx) {
			x.addClassName('hover');
		});
	});	
		 
	$$("#headmenulist li").each( function(x) {
		Event.observe($(x), 'mouseout', function(xx) {
			x.removeClassName('hover');
		});
	});	
});

		
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : ";path=/") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function cancelevent(evt, message) {
   evt = (evt) ? evt : window.event;
   alert(message);
   evt.cancelBubble = true;
}

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 showElement(id)
{
	setDisplay(id, "block");
}

function clearText(field) 
{
    if (field.defaultValue==field.value) 
        field.value = "";
}

function hideElement(id)
{
	setDisplay(id, "none");
}

function setDisplay(id, display)
{
	elem = document.getElementById(id);
	if (elem && elem.style)
	{
		elem.style.display = display;
	}
}

function startList() {
    if (document.all && document.getElementById) {
        navRoot = document.getElementById("headmenulist");
        for (i = 0; i < navRoot.childNodes.length; i++) {
            node = navRoot.childNodes[i];
            if (node.nodeName == "LI") {
                node.onmouseover = function () {this.className += " over";};
                node.onmouseout = function () {this.className = this.className.replace(" over", "");};
            }
        }
    }
}

function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=650,height=500');
return false;
}

function productview_quantity_change()
{
	try
	{
		$('totalprice_total').update( (parseFloat($('totalprice_base').innerHTML) * parseFloat($('quantity[0]').value)).toFixed(2) );
	}
	catch (e) {	}
}

				function showFullSearchResults(cat)
				{
					document.search_form.search_action.value = 'fullresults';
		
					$('searchfrom').setValue(cat);
					$('search_sb_words').setValue($('search_sb_words_source').value);
					document.search_form.submit();
				}

				function addItemToCart(pid)
				{
					$('product[0]').value = pid;
					$('quantity[0]').value = $('q_' + pid).value;
					document.scart_form.submit();
				}
				function orderBy(col)
				{
					$('ordercol').value = col;
					$('product_list_form').submit();
				}

				function showBigContent(vcat_id, pg_id)
				{
					new Ajax.Request('/products/ajax/content/',
						{
							parameters: {
								vcat_id: vcat_id,
								pg_id: pg_id
							},
							onSuccess: function (t)
							{
								var response = t.responseText.strip();
								if (response.length > 0)
									$('contentdiv').update(response);
							}
						}
					);
				}

				function showCat(vcat_id, pg_id, subgroups, getcontent)
				{
					if (subgroups == 0)
					{
						// show contents
						window.location.href="/products/?pg_id="+pg_id;
						return;
					}

					if (vcat_id == -1)
					{
						vcat_id = 0;
						if (getCookie('last_vcat_id'))
							vcat_id = getCookie('last_vcat_id');
					}
					if (pg_id == -1)
					{
						pg_id = 0;
						if (getCookie('last_pg_id'))
							pg_id = getCookie('last_pg_id');
					}
					setCookie('last_vcat_id', vcat_id);
					setCookie('last_pg_id', pg_id);

					if (getcontent == 1)
					{
						// notify spam-o-matic
						if (self.showBigContent)
							showBigContent(vcat_id, pg_id);
						if (self.showBanners && pg_id == 0)
							showBanners(vcat_id);
					}
					

					$('producttree_data').update( $('loading').innerHTML );
					new Ajax.Updater('producttree_data', '/products/ajax/subcats/',
						{
							parameters: {
								ptree_action: 'getsubcats',
								vcat_id: vcat_id,
								pg_id: pg_id
							}
						}
					);
				}