function showhide(show,hide)
{
	if(document.getElementById)
	{
		if(document.getElementById(show))
			document.getElementById(show).style.display = 'block';
		if(document.getElementById(hide))
			document.getElementById(hide).style.display = 'none';
	}
}

function createOrAddToComparison(device_id, sender)
{
    var comparisonString = getCookie("product_comparison");
    comparisonString = addStringToUniqueList(comparisonString, device_id);
    setCookie("product_comparison",comparisonString,null,"/");
    if (sender) {
        sender.onclick = function() { removeFromComparison(device_id, sender); return false; }
        sender.innerHTML = "Eemalda v&otilde;rdlusest";
        sender.className = "bt red block";
    }
}

function removeFromComparison(device_id, sender)
{
    var comparisonString = getCookie("product_comparison");
    comparisonString = removeStringFromList(comparisonString, device_id);
    setCookie("product_comparison",comparisonString,null,"/");
    if(sender) {
        sender.onclick = function() { createOrAddToComparison(device_id, sender); return false; };
        sender.innerHTML = "Lisa v&otilde;rdlusesse";
        sender.className = "bt block";
    }
}

function addStringToUniqueList(listString,addString)
{
    if(listString == "" || (","+listString).indexOf(","+addString+",") == -1)
    {
        listString = listString + addString + ",";
    }
    return listString;
}

function removeStringFromList(listString,removeString)
{
    if((","+listString).indexOf(","+removeString+",") != -1)
    {
        listString = ((","+listString).replace(","+removeString+",",",")).substring(1);
    }    
    return listString;
}


function setCookieSimple(name, value)
{
	setCookie(name,value,null,"/",null,null);
}

function setCookie(name, value, expires, path, domain, secure) 
{
    document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function getExpDate(days, hours, minutes) 
{
    var expDate = new Date();
    if (typeof days == "number" && typeof hours == "number" && typeof minutes == "number") 
    {
        expDate.setDate(expDate.getDate() + parseInt(days));
        expDate.setHours(expDate.getHours() + parseInt(hours));
        expDate.setMinutes(expDate.getMinutes() + parseInt(minutes));
        return expDate.toGMTString();
    }
}

function getCookie(cookieName)
{
	c = document.cookie;
	i = c.indexOf(cookieName + "=");
	if (i == -1) 
		return "";
	i2 = c.indexOf(";", i);
	return unescape(c.substring(i + cookieName.length + 1, (i2 == -1 ? c.length : i2)));
}

//Main navigation menu
function toggleChild(callerId,containerId)
{
	if(document.getElementById(callerId+'_child') && document.getElementById(callerId+'_child').style.display == 'none')
	{
		var doOpen = true;
	}

	closeAll(containerId);

	if(doOpen)
	{
	    if(document.getElementById(callerId+'_child'))
	    {
		    document.getElementById(callerId+'_child').style.display = 'block';
		    document.getElementById(callerId+'_child_img').src = document.getElementById(callerId+'_child_img').src.replace('right','down');
    		
		    setOpenMenuCookie(callerId);
		}
	}
}

function closeAll(containerId)
{
	var children = document.getElementById(containerId).childNodes;
	for(var i = 0; i < children.length; i++)
	{
		if(children[i].id && children[i].id.indexOf('child') > 0)
		{
			children[i].style.display = 'none';
		}
	}
	var childImgs = document.getElementById(containerId).getElementsByTagName('img');
	for(var i = 0; i < childImgs.length; i++)
	{
		if(childImgs[i].id && childImgs[i].id.indexOf('child_img') > 0)
		{
			childImgs[i].src = childImgs[i].src.replace('down','right');						
		}
	}
	setOpenMenuCookie('');
}

function setOpenMenuCookie(menuId)
{
	document.cookie = 'openMenu=' + menuId + '; path=/';
}

function goToPage(url)
{
	setOpenMenuCookie('');
	window.location = url;
}

if (window.onload)
{
	document.oldloadcall = document.onload;
}
window.onload=function()
{
	if(getCookie('openMenu') != '')
	{
		toggleChild(getCookie('openMenu'),'mnu_leftnav'); //HARDCODED DIV ID
	}
}

function toggleTreeViewNode(headerId, contentId) {
	var header = document.getElementById(headerId);	
	var content = document.getElementById(contentId);
	
	if(content.style.display == 'block') {
		content.style.display = 'none';
		header.style.backgroundImage = header.style.backgroundImage.replace("minus","plus");			
	}
	else {
		content.style.display = 'block';
		header.style.backgroundImage = header.style.backgroundImage.replace("plus","minus");	
	}
}