function updateCounter(elId,elSourceId,minNr,maxNr)
{
	strVal = document.getElementById(elSourceId).value;
	color = strVal.length < minNr || strVal.length > maxNr ? 'red' : 'green';
	document.getElementById(elId).innerHTML = ', hetkel tähemärke: <b style="color:'+color+'">'+strVal.length+'</b>';
}

var emailDialogApi = null;
function email_send()
{
	tmp_em_source_name = document.getElementById("em_source_name").value;
	tmp_em_source_email = document.getElementById("em_source_email").value;	
	tmp_em_email = document.getElementById("em_email").value;
	tmp_em_subject = document.getElementById("em_subject").value;
	tmp_em_content = document.getElementById("em_content").value;
	if (!tmp_em_source_name || !tmp_em_source_email || !tmp_em_email || !tmp_em_subject || !tmp_em_content)
	{
		document.getElementById("em_error").style.display = "";
		return;
	}	
	params = "action_alias=send_email&em_email="+tmp_em_email+'&em_subject='+tmp_em_subject+'&em_content='+tmp_em_content+'&em_source_email='+tmp_em_source_email+'&em_source_name='+tmp_em_source_name;
	document.getElementById("em_error").style.display = "none";
	$.ajax({
		type: "POST",
		url: "/",
		data: params,
		success: function(msg)
		{					
			document.getElementById("em_message").style.display = "";
			document.getElementById("em_error").style.display = "none";
			setTimeout("email_closeDialog();",1200);
		}
 	});	
}
function email_closeDialog()
{	
	emailDialogApi.close();
}
function email_openDialog()
{	
	if (!document.getElementById("emailDialog"))
	{
		return;
	}
	// select the overlay element - and "make it an overlay"
	emailDialogApi = $("#emailDialog").overlay({
	 
		// custom top position
		top: 172,
	 
		// some expose tweaks suitable for facebox-looking dialogs
		expose: {
	 
			// you might also consider a "transparent" color for the mask
			color: '#fff',
	 
			// load mask a little faster
			loadSpeed: 200,
	 
			// highly transparent
			opacity: 0.5
		},
	 
		// disable this for modal dialog-type of overlays
		closeOnClick: false,
	 
		// we want to use the programming API
		api: true
	 
	// load it immediately after the construction
	}).load();	
}


function sendEmailPopup(email)
{
	email = Base64.decode(email);
	document.getElementById("em_message").style.display = "none";
	document.getElementById("em_error").style.display = "none";
	document.getElementById("em_email").value = email;
	document.getElementById("em_subject").value = "";
	document.getElementById("em_content").value = "";
	email_openDialog();
}
function fieldFocus(hasFocus,elementId,defaultKeywordValueTmp,isPassword)
{
	if (!document.getElementById(elementId))
	{
		return;
	}
	if (hasFocus)
	{				
		if (document.getElementById(elementId).value == defaultKeywordValueTmp)
		{
			document.getElementById(elementId).value = '';
		}	
	}
	else
	{
		if (!document.getElementById(elementId).value)
		{			
			document.getElementById(elementId).value = defaultKeywordValueTmp;
		}		
	}
}

function openMapEdit(url)
{
	width = 800;
	height = 600;
	top_n = (screen.height/2 - height/2);
	left_n = (screen.width/2 - width/2);
	newwindow = window.open(url,'mapPopup','height='+height+',width='+width+', left='+left_n+',top='+top_n+',scrollbars=1');	
	if (window.focus) 
	{
		newwindow.focus()
	}
}

function openMap(url)
{
	width = 800;
	height = 600;
	top_n = (screen.height/2 - height/2);
	left_n = (screen.width/2 - width/2);
	newwindow = window.open(url,'mapPopup','height='+height+',width='+width+', left='+left_n+',top='+top_n+',scrollbars=1');	
	if (window.focus) 
	{
			newwindow.focus()
	}
}

function openKrediidiinfo(code)
{
	width = 800;
	height = 600;
	url = "http://firmaparing.krediidiinfo.ee/jakjs.php?eregnr="+code;
	top_n = (screen.height/2 - height/2);
	left_n = (screen.width/2 - width/2);
	newwindow = window.open(url,'krediidiinfoPopup','height='+height+',width='+width+', left='+left_n+',top='+top_n+',scrollbars=1');	
	if (window.focus) 
	{
			newwindow.focus()
	}
}

function HandleEndSession(sonum)
{
	//alert(sonum);
	document.location = "index.php?id=10&logout=1";
}

function changeMenuPicture(img_id,rollover_img)
{
	document.getElementById(img_id).src=rollover_img;
}

function flashPopup(url,width,height)
{	
	top_n = (screen.height/2 - height/2);
	left_n = (screen.width/2 - width/2);
	newwindow = window.open(url,'datasheetPopup','height='+height+',width='+width+', left='+left_n+',top='+top_n+',scrollbars=1');	
	if (window.focus) 
	{
			newwindow.focus()
	}
	return false;
}

function windowPopup(url,windowName,width,height)
{	
	top_n = (screen.height/2 - height/2);
	left_n = (screen.width/2 - width/2);
	newwindow = window.open(url,windowName,'height='+height+',width='+width+', left='+left_n+',top='+top_n+',scrollbars=1');	
	if (window.focus) 
	{
			newwindow.focus()
	}
}


function infoPopup(msg,width,height)
{	
	newwindow = window.open('','infoPopup','height='+height+',width='+width+', left=10,top=10,scrollbars=1');	
	if (window.focus) 
	{
			newwindow.focus()
	}
	var tmp = newwindow.document;
	tmp.write("<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8' /><title>Info</title></head><body style='font-family:arial;font-size:11px;line-height:22x'>"+msg+"</body></html>")
	//tmp.write(msg)
	return false;
}

function datasheetPopup(url,width,height)
{	
	newwindow = window.open(url,'datasheetPopup','height='+height+',width='+width+', left=10,top=10,scrollbars=1');	
	if (window.focus) 
	{
			newwindow.focus()
	}
	return false;
}

function openNewWindow(url)
{
	if (url)
	{
		popupWin = window.open(url, 'newPopupWindow', '');
		popupWin.focus();
	}
}

function openGalleryInPopup(url, width, height)
{
	top_n = (screen.height/2 - height/2);
	left_n = (screen.width/2 - width/2);
	top_n = 50;
	height = height+20;
	popupWin = window.open(url, 'galleryInPopup', 'scrollbars=0,width='+width+',height='+height+', left='+left_n+',top='+top_n);
	popupWin.focus();
}

function giveFeedback(url)
{
  feedbackWin = window.open(url, 'feedbackWin', 'left=200;top=100,scrollbars=1,width=560,height=400');
	feedbackWin.focus();
}
function prindi(url) {
	popupWin = window.open(url, 'popup', 'top=20,scrollbars=1,width=560,height=600')		
	popupWin.focus();
}

function printPage(url,width,height) 
{
	top_n = (screen.height/2 - height/2);
	left_n = (screen.width/2 - width/2);
	popupWin = window.open(url, 'popup', 'top='+top_n+',left='+left_n+',scrollbars=1,width='+width+',height='+height)		
	popupWin.focus();
}

function printPageArctic(url,width,height) {
	popupWin = window.open(url, 'popup', 'top=20,scrollbars=1,width='+width+',height='+height)		
	popupWin.focus();
}

function sendToFriend(url, width, height) 
{
	left = (screen.width / 2 - width / 2);
	popupWin = window.open(url, 'sendToFriend', 'left='+left+',top=200,scrollbars=1,width='+width+',height='+height)	
	popupWin.focus();
}

var w;
function openImagePopup(img, height, width) 
{
	scrollbarWidth = 20;
	if (w) 
	{
		w.close();
	}
	top_n = (screen.height/2 - height/2);
	left_n = (screen.width/2 - width/2);
	scrollbars = '0';
	if (screen.height < height)
	{
		scrollbars = '1';
		width += scrollbarWidth; 
	}
	w = window.open ('', "win", "height="+height+",width="+width+"location=0,menubar=0,resizable=0,scrollbars="+scrollbars+",status=0,toolbar=0,left="+left_n+",top="+top_n);
	w.document.write('<html><head><title></title></head><body topmargin="0" leftmargin="0">');
	w.document.write('<div align="center"><a href="javascript:self.close();"><img src="'+img+'" border="0"></a></div>');
	w.document.write('</body></html>');
	w.focus();
}

function confirmAction(str) {
	if (confirm(str)) {
		return true;
	}
	return false;
}

function setActiveStyle(myStyle, activeStyleID)
{		
	setActiveStyleSheet(myStyle, 1);		
	document.getElementById(activeStyleID).src = 'index.php?activeStyle='+myStyle;
}

function popupImage(popup_id, file, url, width, height, left, top) {
	var w = window.open ('', "winPicture_"+popup_id, "height="+height+",width="+width+"location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0,left="+left+",top="+top);
	target="";
	onclick="";
	if (url=="") {
		url = "#";
	}
	else {
		target = " target=\"_blank\"";
		onclick="self.close()";
	}
	w.document.write('<html><head><title></title></head><body topmargin="0" leftmargin="0">');	
	w.document.write('<a href="'+url+'" onclick="'+onclick+'" '+target+'><img src="'+file+'" border=0></a>');
	w.document.write('</body></html>');
	w.focus();	
}

function popupFlash(popup_id, file, url, width, height, left, top) {	
	var w = window.open ('', "winFlash_"+popup_id, "height="+height+",width="+width+"location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0,left="+left+",top="+top);
	w.document.write('<html><head><title></title></head><body topmargin="0" leftmargin="0">');	
	w.document.write('<object><embed src="'+file+'" width="'+width+'" height="'+height+'"></embed></object>');
	w.document.write('</body></html>');	
	w.focus();
}

function popupCalendar(field, form) {
	var w = window.open ('popupCalendar.php?form='+form+'&field='+field, "calendar", "width=193,height=184,location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0");
	w.focus();
}

function popupCourseSearch(page_id) {
	var aken = window.open('?id='+page_id+'&windowType=popup','','width=400,height=400,location=0,menubar=0,resizable=0,scrollbars=1,status=1,toolbar=0');
	aken.focus();
}
function popupTeacherSearch(page_id) {
	var aken = window.open('?id='+page_id+'&windowType=popup','','width=400,height=400,location=0,menubar=0,resizable=0,scrollbars=1,status=1,toolbar=0');
	aken.focus();
}
function popupCompetitionUserSearch(page_id) {
	var aken = window.open('?id='+page_id+'&windowType=popup','','width=400,height=400,location=0,menubar=0,resizable=0,scrollbars=1,status=1,toolbar=0');
	aken.focus();
}

function popupManorMap(url) {
	width = 571
	height = 450
	var w = window.open (url, "manor_map", "width="+width+",height="+height+",left=100,top=60,location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0");
	w.focus();
}


function popupProgramme(page_id, programme_id, course_id, action) {
	var aken = window.open('?id='+page_id+'&windowType=popup&course_id='+course_id+'&programme_id='+programme_id+'&action='+action,'','left=50,top=84,width=420,height=240,location=0,menubar=0,resizable=0,scrollbars=1,status=0,toolbar=0');
	aken.focus(); 
}

function popupScheduleItem(page_id, item_id, schedule_id, action) {
	var aken = window.open('?id='+page_id+'&windowType=popup&item_id='+item_id+'&schedule_id='+schedule_id+'&action='+action,'','left=50,top=84,width=420,height=440,location=0,menubar=0,resizable=0,scrollbars=1,status=0,toolbar=0');
	aken.focus(); 
}

function popup(url) {
  var aken = window.open(url,'','width=400,height=400,location=0,menubar=0,resizable=0,scrollbars=1,status=0,toolbar=0');
	aken.focus();
}

function List_resetFilter(page_id, windowTypeStr) 
{
	url = '?id='+page_id+'&reset_filter=1&windowType='+windowTypeStr;	
  document.location = url;
} 

function List_changeClass(rida, klass) {
	rida.className=klass;
}
function List_changeClass2(rida, klass) {
	if (rida.className=='list_selected_row') {
	}
	else {
	  rida.className=klass;
	}
}
