var layer = "";
function selectPic(id)
{
	if (layer!="")
	{
		document.getElementById(layer).style.borderColor='';

	}
	document.getElementById(id).style.borderColor='green';
	document.join.avatar.value=parseInt(id.substring(1));
	layer = id;
}



function moderateFashionGuru(id)
{
	moderate = window.open('guruFunctions.php?action=3&id='+id,'fashionGuru','width=450,height=400,resizable=yes,scrollbars=yes');
	moderate.focus();
}

function jututOpen()
{
	moderate = window.open('jututFunctions.php?action=1','jutut','width=450,height=400,resizable=yes,scrollbars=yes');
	moderate.focus();
}

function jututEdit(id)
{
	moderate = window.open('jututFunctions.php?action=1&id='+id,'jutut','width=450,height=400,resizable=yes,scrollbars=yes');
	moderate.focus();
}

function jututView()
{
	moderate = window.open('jututFunctions.php?action=2','jutut','width=540,height=400,resizable=yes,scrollbars=yes');
	moderate.focus();
}

function upload()
{
	moderate = window.open('jututFunctions.php?action=3','upload','width=540,height=400,resizable=yes,scrollbars=yes');
	moderate.focus();
}


function openOnlineUsers()
{
	moderate = window.open('onlineUsers.php','onlineusers','width=450,height=400,resizable=yes,scrollbars=yes');
	moderate.focus();
}

function delGuruEntry(id)
{
	if (confirm("Haluatko varmasti poistaa rivin?"))
	{
		location.href="guruFunctions.php?action=0&id=" + id;
	}
}

function enableDisable(field,bool)
{
	field.disabled = bool;
}

function checkOrder()
{
	if (document.order.id.value=="")
	{
		alert("Tsekkaa koko.");
		return false;
	}
	else
	{
		return true;
	}
}

function jumpMenu(elem, category, cid, p, c, s)
{
	id = elem.options[elem.selectedIndex].value;
	if (id=='') id = 0;
	if (cid == 0) s = ''; else s = '&s='+s;

	if (elem.name=="sivulla")
	{
		document.location.href='index.php?m='+category+s+'&cid='+cid+'&p='+p+'&c='+id;
	}
	if (elem.name=="order")
	{
		document.location.href='index.php?m='+category+s+'&cid='+cid+'&p='+id+'&c='+c;	
	}
	if (elem.name=="label")
	{
		if (id == 0) s = ''; else s = '&s='+id;
		if (cid == 0) s = '';
		document.location.href='index.php?m='+category+s+'&cid='+cid+'&p='+p+'&c='+c;	
	}
	if (elem.name=="prodType")
	{
		document.location.href='index.php?m='+category+'&cid='+id+'&c=12&p=0';
	}
}


var requester;
function fetchXML(xmlsource)
{

	try
	{
		requester = new XMLHttpRequest();
	}
	catch (error)
	{
		try
		{
			requester = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (error)
		{
			return false;
		}
	}

	requester.open("GET", xmlsource);
	requester.send(null);
	requester.onreadystatechange = stateHandler;

}


function stateHandler()
{
	if (requester.readyState == 4)
	{
		if (requester.status == 200)
		{
			printXML();
		}
		else
		{
			alert("Tietoja ei saatavilla.");
		}
	}
	return true;
}


function printXML()
{
	nameNode = requester.responseXML.getElementsByTagName("id");

	for (var i=0; i<nameNode.length;i++)
	{
		nameTextNode = nameNode[i].childNodes[0];
		name = nameTextNode.nodeValue;
		alert(name);
	}
}

function printProduct(iterator,array)
{
	arr = eval(array);
	if (iterator>0)
	{
		prev = (iterator-1);
	}
	else
	{
		prev = (arr.length-1);
	}

	if (iterator<(arr.length-1))
	{
		next = (iterator+1);
	}
	else
	{
		next = 0;		
	}
	
	if (arr.length>0)
	{
		currentPic = '<img src="/images/thumbs/'+arr[iterator][4][1]+'-'+arr[iterator][3][1]+'.jpg" width="85" alt="">';
		if (array!='top10')
		{
			top10html='<h3 id="uutuustuotteet"><span>Uutuustuotteet</span></h3>';
		}
		else
		{
			top10html='<h3 id="top10"><span>Top-10</span></h3>';	
		}
		top10html+='<div class="prodName"><span>'+ (iterator+1) +'. - '+arr[iterator][0][1]+'</span></div><div class="bcc" style="height:133px;"><div class="prodImg">'+currentPic+'</div><div class="prodInfo"><div class="prodLogo"><img src="images/logot/'+arr[iterator][5][1].toLowerCase()+'.jpg" width="100" alt="'+arr[iterator][5][1]+'"></div><div class="prodPrice"><span class="offerPrice">Hinta: '+arr[iterator][1][1]+'&euro;</span><a href="/index.php?m=2&cid=0&pid='+arr[iterator][4][1]+'" class="readmore"><span>Lue Lis��</span></a></div></div></div><div class="naviPanel"><a href="javascript:printProduct('+(prev)+',\''+array+'\');" class="prev"><span>Edellinen</span></a><a href="javascript:printProduct('+next+',\''+array+'\');" class="next"><span>Seuraava</span></a><a href="/index.php?m=2" class="all"><span>N&auml;yt&auml; kaikki</span></a></div>';
		
		document.getElementById(array+"Box").innerHTML=top10html;
	
	}
	else
	{
		if (array!='top10')
		{
			top10html='<h3 id="uutuustuotteet"><span>Uutuustuotteet</span></h3>';
		}
		else
		{
			top10html='<h3 id="top10"><span>Top-10</span></h3>';	
		}
		document.getElementById(array+"Box").innerHTML=top10html;
	}
}
