
// See on vaja 
var variableFromEditRubriik_id='';


function zoomTo(width,height,Page) {

    if (document.all) {

	//if (Page!=''){this.location.href=Page};

	var newTop = (screen.width-width)/2
	var newLeft = (screen.height-height)/2

	window.moveTo(newTop,newLeft)
	window.resizeTo(width,height)
    }
}

function avapopup(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',notresizable'
	win = window.open(mypage, myname, winprops)
	if (win.opener == null) { win.opener = self }
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function avaaken(link, x, y, nimi) {
	var winl = (screen.width - x) / 2;
	var wint = (screen.height - y) / 2;
	editWindow = window.open(link, nimi,'width='+x+',height='+y+',top='+wint+',left='+winl+',toolbar=0,directories=0,menubar=0,status=0,resizable=1,location=0,scrollbars=yes,copyhistory=0');
	if (editWindow.opener == null) { editWindow.opener = self }
}

function avaaken2(link, x, y, doScroll) {

var winl = (screen.width-x)/2;
var wint = (screen.height-y)/2;

var scr = (doScroll)? 'yes' : 'no'

var newWin = window.open(link, 'Fail','width='+x+',height='+y+',toolbar=0,directories=0,menubar=0,status=0,resizable=1,location=0,scrollbars=' + scr + ',copyhistory=0,left=' + winl + ',top=' + wint);
newWin.focus();
}

function avaprintaken(link, x, y, nimi) {
	var winl = (screen.width - x) / 2;
	var wint = (screen.height - y) / 2;
	editWindow = window.open(link, nimi,'width='+x+',height='+y+',top='+wint+',left='+winl+',toolbar=1,directories=0,menubar=1,status=0,resizable=1,location=100,scrollbars=yes,copyhistory=0');
	if (editWindow.opener == null) { editWindow.opener = self }
}

function gallupaken(link, x, y, nimi) {
	var winl = (screen.width - x) / 2;
	var wint = (screen.height - y) / 2;
	editWindow = window.open(link, nimi,'width='+x+',height='+y+',top='+wint+',left='+winl+',toolbar=0,directories=0,menubar=0,status=0,resizable=1,location=0,scrollbars=no,copyhistory=0');
	if (editWindow.opener == null) { editWindow.opener = self }
}



//----------------------------


// width of the ticker
var tickerwidth=230

// height of the ticker
var tickerheight=67

// distance from the messagetext to the tickermarrgin (pixels)
var tickerpadding=5

// borderwidth of the ticker (pixels)
var borderwidth=0

// font-family
var fnt="Verdana,Arial Cyr,Helvetica Cyr,Arial,Ms Sans Serif"

// font-size of the text (px)
var fntsize=11

// font-color of the text
var fntcolor="000000"

// font-weight. Set a value between 1 to 9 to adjust the boldness
var fntweight=3

// backgroundcolor
var backgroundcolor="dadada"

// horizontal distance from the textlink to the popupbox (pixels)
//var xdistance=-tickerwidth-10
var xdistance=-10

// vertical distance from the textlink to the popupbox (pixels)
var ydistance=-84

// Do not edit the variables below
var topposition=200;
var rightposition=500;
var x=screen.width/2;
var y=screen.height/2;
var i_message=0;
var message;
var messagecontent="";
var messagebackground="";
fntweight=fntweight*100;



function getmessagebackground() {
	messagebackground="<table border=0 cellspacing=0 cellpadding=1><tr><td bgcolor=#1A5959><table border="+borderwidth+" width="+tickerwidth+" height="+tickerheight+" cellspacing=0 cellpadding=0><tr><td valign=top bgcolor='"+backgroundcolor+"'>";
	messagebackground+="&nbsp;</td></tr></table></td></tr></table>";
}

function getmessagecontent(defword,sometext) {
	messagecontent="<table border=0 cellspacing=0 cellpadding="+tickerpadding+" width="+tickerwidth+" height="+tickerheight+"><tr><td valign=top>";
	messagecontent+="<span style='position:relative; font-family:"+fnt+";color:"+fntcolor+";font-size:"+fntsize+"px;font-weight:"+fntweight+"'>" ;
	messagecontent+="<font color='"+fntcolor+"'>";
	messagecontent+="<b>"+defword+"</b><br>"+sometext;
	messagecontent+="</font>";
	messagecontent+="</span>";
	messagecontent+="</td></tr></table>";
}


function showmessage(word,linkmessage,myevent) {


	x = (document.layers) ? myevent.pageX : document.body.scrollLeft+event.clientX;
	y = (document.layers) ? myevent.pageY : document.body.scrollTop+event.clientY;

	leftposition = x;

	getmessagebackground();
	myword=word;
    getmessagecontent(myword,linkmessage);

	rightposition=x+xdistance+tickerwidth;
	topposition = y-ydistance-tickerheight;
	leftposition=x+xdistance;


	if (document.all) {


		document.all.ticker.style.posLeft=leftposition;
		document.all.ticker.style.posTop=topposition;
		document.all.tickerbg.style.posLeft=leftposition;
		document.all.tickerbg.style.posTop=topposition;
		tickerbg.innerHTML=messagebackground;
		document.all.ticker.style.visibility="visible";
		document.all.tickerbg.style.visibility="visible";
		ticker.innerHTML=messagecontent;

	}

	if (document.layers) {

		document.captureEvents(Event.MOUSEMOVE);

		document.ticker.left=leftposition
		document.ticker.top=topposition
		document.tickerbg.left=leftposition
		document.tickerbg.top=topposition
		document.tickerbg.document.write(messagebackground)
		document.tickerbg.document.close()
		document.ticker.visibility="visible"
		document.tickerbg.visibility="visible"

		document.ticker.document.write(messagecontent)
		document.ticker.document.close()

	}

}



function hideticker() {



	if (document.all) {
		document.all.ticker.style.visibility="hidden"
		document.all.tickerbg.style.visibility="hidden"
	}

	if (document.layers) {
		document.ticker.visibility="hidden"
		document.tickerbg.visibility="hidden"
	}
}


function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;
    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;
    var newstr = string.substring(0,i) + by;
    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);
    return newstr;
}

function jsCloseRefresh() {
	if (window.opener!=null)
	{

		if (variableFromEditRubriik_id!='undefined' && variableFromEditRubriik_id!=null && variableFromEditRubriik_id!='')
			{

				mylocation = ''+window.opener.location+'';
				mylocation = replace(mylocation,'?id=','?old_id=');
				mylocation = replace(mylocation,'&id=','&old_id=');
				temp= mylocation.indexOf('?');
				if (temp == -1) {
				mylocation+='?id='+variableFromEditRubriik_id;
				} else {
				mylocation+='&id='+variableFromEditRubriik_id;};
				window.opener.location=mylocation;

			} else {window.opener.location=window.opener.location;}
	}
	window.close();
}

function do_perm(first,seccond) {
  self.opener.location.replace(first+'&puu_keel='+seccond);
  self.close();
}