function showPopup(ev, detail)
{
	if (document.getElementById("popup"))
	{
		document.getElementById("popup").style.display = "block";
	}
	else
	{
		thePopup = document.createElement("div");
		thePopup.id = "popup"
		thePopup.style.display = "block";
		thePopup.className = "rightcol-b";
	//	thetop = ev.parentNode.pageYOffset
   //             || ev.parentNode.scrollTop
 //               || 500 + "px";
//		alert(thetop);
		thePopup.style.top = "700px";
		thePopup.innerHTML = detail;
		ev.parentNode.parentNode.appendChild(thePopup);
	}
}
function hidePopup()
{
	if (document.getElementById("popup"))
	{
		document.getElementById("popup").style.display = "none";
	}
}
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e)
		{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }
	return xmlHttp;
}

//function stateChanged()
//{
//	if (xmlHttp.readyState==4)
//	{
		//document.getElementById("flavour").innerHTML=xmlHttp.responseText;
//	}
//}

//	xmlHttp=GetXmlHttpObject();
//	if (xmlHttp==null)
//		{
//			alert ("Your browser does not support AJAX!");
///			return;
//		}

  //  xmlHttp.onreadystatechange=stateChanged;
//    xmlHttp.open("GET","prod_offer.asp?prod_id=" + document.frmoffer.product.value + "&flav_id=" + document.frmoffer.hidflavour.value,true);
  //  xmlHttp.send(null);


function toggleImg(tmp, id, cname, lang)
{
	var ids = new Array();
	if (tmp.src.match("star_unlit.gif"))
	{



		comp = getCookie("comp");
	cname2 = getCookie("cname");
	if (cname2==null || cname2=="")
		setCookie("cname", cname, 30);
	else
	{
		if (cname!=cname2)
		{
			if (confirm("Vertailuun tähän mennessä lisätyt tuotteet kuuluvat tuoteryhmään " + cname2.split(",")[lang] + ". Voit lisätä vertailuun vain saman tuoteryhmän tuotteita. Jos haluat jatkaa tuoteryhmän " + cname2.split(",")[lang] + " tuotteiden vertailua, napsauta Peruuta. Jos haluat tyhjentää vertailuun tähän mennessä lisätyt tuotteet ja vertailla uuden tuoteryhmän tuotteita, napsauta OK."))
			{
				ClearAllComp();
				setCookie("cname", cname, 30);
			}
			else
			{
				if (cname2.split(",").length==3)
					window.location.href = "prod_catalog.asp?prod_cat=" + cname2.split(",")[2];
				return;
			}
		}
	}




		if (comp==null || comp=="")
			ids = id;
		else
		{
			ids[0]=id;
			ids[1]=comp;
			comp = comp.split(",");
			for(i=0; i<comp.length; i++)
			{
				if (comp[i]==id)
				{
					tmp.src = "images/star_lit.gif";
					return;
				}
			}
			if (comp.length>4)
			{
				alert("Mass-tuotevertailuun voi lisätä enintään 5 tuotetta.");
				return;
			}
		}
		tmp.src = "images/star_lit.gif";
		setCookie("comp", ids, 30);
		check2compare();
	}
	else
	{
		tmp.src = "images/star_unlit.gif";
		comp = getCookie("comp");
		if (comp!=null && comp!="")
		{
			comp = comp.split(",");
			j = 0;
			for(i=0; i<comp.length; i++)
				if (comp[i]!=id)
					ids[j++] = comp[i];
			if (j==0)
				setCookie("cname", "", -30);
			setCookie("comp", ids, 30);
			check2compare();
		}
	}
	location.hash="compare";
}

function SetCompBox()
{
	if (xmlHttp.readyState==4)
	{
		document.getElementById("compareBox").innerHTML = xmlHttp.responseText;
		//alert(xmlHttp.responseText);
	}
}

function ClearAllComp()
{
	setCookie("comp", "", -30);
	setCookie("cname", "", -30);
	for (i=0; i<document.images.length; i++)
		if (document.images[i].src.match("star_lit.gif"))
			document.images[i].src = "images/star_unlit.gif";
	check2compare();
}

function setCookie(c_name, value, expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	  {
		  c_start = document.cookie.indexOf(c_name + "=");
		  if (c_start!=-1)
			{
				c_start=c_start + c_name.length+1;
				c_end=document.cookie.indexOf(";",c_start);
				if (c_end==-1) c_end=document.cookie.length;
				return unescape(document.cookie.substring(c_start,c_end));
			}
	  }
	return "";
}

function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}


function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

function trim( value ) {
	
	return LTrim(RTrim(value));
	
}
function closeKlarnaWindow()
{
	
	document.getElementById("KlarnaInvoice").style.visibility="hidden";
}

function showKlarnaWindow()
{
	document.getElementById("KlarnaInvoice").style.visibility="visible";
}
		

