/*
	ReUIMain.js
	-käyttöliittymän javascriptit
	Version:
	20040909 (S.K) -ScrollMeTo, DeHiLight, HiLight, ResizeButtonToTop
	20040913 (S.K) -ScrollFrameTo, HideElement, ShowElement
	20041001 (S.K) -ScrollFrame, ShowElement, HideElement, dehilightme
	20041012 (S.K) -DeHiLight2
	20041013 (S.K) -SetPallo
*/

/* Globaalit */

var arrowtop=391;
var arrownow=arrowtop;
var scrollspeed=1;
var scrollstop=false;

/* Funktiot */
function DeSetPallo()
{
	for(i=1;i<51;i++)
	{
		nappi="nappi"+i;
		document.getElementById(nappi).style.background="url('UIKuvat/nappi-myymalakartta.gif')"; //"white";
	}
}

function SetPallo(tblcell, pallo, x, y)
{
	DeSetPallo();
	document.getElementById(tblcell).style.background="url('UIKuvat/nappi-myymalakartta-alas.gif')"; //"white";
	document.getElementById(pallo).style.visibility='visible';
	document.getElementById(pallo).style.left=x-8;
	document.getElementById(pallo).style.top=y-8;
}

function ScrollMeTo(yto, direction)
{
	yto-=1;
	if (yto>0)
	{
		arrownow+=direction;
		if (arrownow<arrowtop)
			arrownow=arrowtop;
		document.getElementById('arrowsframe').style.top=arrownow;
		self.scrollBy(0, direction);
		setTimeout('ScrollMeTo('+yto+','+direction+')', 10);
	}		
}
function ScrollFrame(frami, direction, init, initagain)
{
	if (init)
	{
		scrollstop=true;
		setTimeout('ScrollFrame("'+frami+'",'+direction+', false, true)', 10);
		return;
	}
	if (initagain)
		scrollstop=false;
		
	if (scrollstop)
		return;

	if (document.getElementById('arrowsframe').style.top<1)
		return;	
	if (document.getElementById('arrowsframe').style.top>document.getElementById('arrowsframe').style.height*2)
		return;	
	parent.frames[frami].scrollBy(0, direction);
	setTimeout('ScrollFrame("'+frami+'",'+direction+', false)', 1);
}
function ScrollFrameTo(frami, yto, direction)
{
	yto-=1;
	if (yto>0)
	{
		parent.frames[frami].scrollBy(0, direction);
		setTimeout('ScrollFrameTo("'+frami+'",'+yto+','+direction+')', 10);
	}		
}
function DeHiLight2(imagefile)
{
//	alert(dehilightme);
	if (dehilightme!=null)
		DeHiLight(dehilightme, imagefile);
}
function DeHiLight(tblcell, imagefile)
{
	document.getElementById(tblcell).style.background='url('+imagefile+')';
	document.getElementById(tblcell).style.backgroundRepeat='no-repeat';	
}
function HiLight(tblcell, imagefile)
{
	//alert(dehilightme);
	
	if (dehilightme!=null)
		DeHiLight(dehilightme, "UIKuvat/valikko-nappi-resepti.gif");
	document.getElementById(tblcell).style.background='url('+imagefile+')';
}
function ResizeButtonToTop(button, fx, fy, tx, ty, finalbutton)
{
	sx=(tx-fx)/4;
	sy=(ty-fy)/4;
	
	fx=fx+sx;
	fy=fy+sy;

	if (Math.abs(tx+ty-fx-fy)>10)
	{
		parent.document.getElementById(finalbutton).style.visibility='hidden';
		document.getElementById(button).style.visibility='visible';
		document.getElementById(button).style.left=fx;
		document.getElementById(button).style.top=fy;
		
		setTimeout('ResizeButtonToTop("'+button+'",'+fx+','+fy+','+tx+','+ty+',"'+finalbutton+'")', 25);
	}
	else
	{
		document.getElementById(button).style.visibility='hidden';
		parent.document.getElementById(finalbutton).style.visibility='visible';
		parent.document.getElementById(finalbutton).innerHTML="Testi";
		parent.document.getElementById('ylapalkkinappireseptit').src="UIKuvat/ylapalkki-nappi-reseptit.gif";
	}
}
function HideElement(button)
{
	document.getElementById(button).style.visibility='hidden';
}
function ShowElement(button)
{
	document.getElementById(button).style.visibility='visible';
}
function SetImage(button, bscr)
{
	document.getElementById(button).style.background=bscr;
}

var g_NaytonsaastajaAjastinId = 0;
var g_NaytonsaastajaUrl = '';
var g_NaytonsaastajaAika = 5;

function naytonsaastaja(url, timeout)
{
    g_NaytonsaastajaAika = timeout;
    g_NaytonsaastajaUrl = url;
	
//	alert(top.location+" "+url);
	
	if (top.location!=url)
		reset_naytonsaastaja();
		//g_NaytonsaastajaAjastinId = setTimeout('top.location="' + url + '";', timeout * 60000);
}

function reset_naytonsaastaja()
{
}

function reAppear(divname1)
{
	var divid=document.getElementById(divname1);
	if (parseInt(divid.filters.alpha.opacity)==100)
		divid.filters.alpha.opacity=0;
	divid.filters.alpha.opacity+=20;
	if (parseInt(divid.filters.alpha.opacity)<100)
		setTimeout('reAppear("'+divname1+'");', 100);
	return(false);
}
function Vanish(divname1)
{
	var divid=document.getElementById(divname1);
	divid.filters.alpha.opacity-=5;
	if (parseInt(divid.filters.alpha.opacity)>1)
		setTimeout('Vanish("'+divname1+'");', 10);
	return(false);
}

function flipflopdiv(div1, sx, sy, tx, ty)
{
	var divi=div1; //top.document.getElementById(div1);
	
	//alert(parseInt(divi.style.left));
	
	if (parseInt(divi.style.left)==sx)
		divi.style.left=tx;
	else
		divi.style.left=sx;
	if (parseInt(divi.style.top)==sy)
		divi.style.top=ty;
	else
		divi.style.top=sy;
}

function ImageFlipFlop(image, img1, img2)
{
	var imgnow=image.src;
	imgnow="UIKuvat/"+imgnow.substring(imgnow.lastIndexOf('/')+1, 100);
	if (imgnow==img1)
	{
		image.src=img2;
		image.src.img=img2;
	}
	else
	{
		image.src=img1;
		image.src.img=img1;
	}
}



