function doesExist(theId) {
	if (document.getElementById(theId)) {
		return true;
	}
	else {
		return false;
	}
}

/*
Järgneva kolme funktsiooni abil loendame tekstiboksi sisestatud tähemärgid, takistame sisestamise üle piirmäära ja
kuvame sisestamise käigus pidevalt muutuva järelejäänud tähemärkide arvu.
*/
var ns6=document.getElementById&&!document.all;
function restrictinput(maxlength,e,placeholder) {
	if (window.event&&event.srcElement.value.length>=maxlength) {
		return false;
	}
}
function countlimit(maxlength,e,placeholder) {
	var theform=eval(placeholder);
	var lengthleft=maxlength-theform.value.length;
	var placeholderobj=document.all?document.all[placeholder]:document.getElementById(placeholder);
	if (window.event||e.target&&e.target==eval(placeholder)) {
		if (lengthleft<0) {
			theform.value=theform.value.substring(0,maxlength);
		}
		placeholderobj.innerHTML=lengthleft;
	}
}
function displaylimit(theform,thelimit) {
	var limittext='<span class="mini">Tähemärke jäänud: </span>';
	var limitnumber='<span class="limitinteger" id="'+theform.toString()+'">'+thelimit+'</span>';
	if (document.all||ns6) {
		document.write(limittext+limitnumber);
	}
	if (document.all) {
		eval(theform).onkeypress=function() {return restrictinput(thelimit,event,theform)}
		eval(theform).onkeyup=function() {countlimit(thelimit,event,theform)}
	}
	else if (ns6) {
		document.body.addEventListener("keypress",function(event){restrictinput(thelimit,event,theform)},true);
		document.body.addEventListener("keyup",function(event){countlimit(thelimit,event,theform)},true);
	}
}

//Flash
function writeFlash(movie,version,width,height,bgcolor) {
	var flashMovie='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+version+'" id="movie_'+movie+'" width="'+width+'" height="'+height+'"><param name="movie" value="'+movie+'" /><param name="quality" value="high" /><param name="menu" value="false" /><param name="bgcolor" value="'+bgcolor+'" /><embed src="'+movie+'" quality="high" menu="false" bgcolor="'+bgcolor+'" width="'+width+'" height="'+height+'" type="application/x-shockwave-flash" pluginspage="http://macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"><\/embed><\/object>';
	document.write(flashMovie);
}
//e-posti lingid
function writeEmailLink(name,domain,linkText) {
  document.write('<a href="mailto:'+name+'@'+domain+'">'+linkText+'<\/a>');
}
//e-posti aadressid
function emailAddr(name,domain,return_val) {
  if (!return_val) {
    document.write(name+'@'+domain);
  }
  else {
    return name+'@'+domain;
  }
}

//sündmuse peale liikuv layer:
var cX=0;
var cY=0;

function updateCurPos(e) {
	cX=e.pageX;
	cY=e.pageY;
}

function updateCurPos_docAll(e) {
	cX=event.clientX;
	cY=event.clientY;
}

if (document.all) {
	document.onmousemove=updateCurPos_docAll;
}
else {
	document.onmousemove=updateCurPos;
}

function setPos(d) {
	d.style.left=(cX+10)+"px";
	d.style.top=(cY+10)+"px";
}

function hideDiv(d) {
	if (d.length<1) {
		return;
	}
	document.getElementById(d).style.display="none";
}

function showDiv(d) {
	if (d.length<1) {
		return;
	}
	var div=document.getElementById(d);
	setPos(div);
	div.style.display="block";
}

function toggleDiv(d) {
	if (d.length<1) {
		return;
	}
	var div=document.getElementById(d);
	setPos(div);
	if (div.style.display=="none") {
		div.style.display="block";
	}
	else {
		div.style.display="none";
	}
}

