function value_checked(form_name, message) {
	var OK = false;
	for (i = 0; i < document.forms[form_name].elements.length; i++)	{
		if (document.forms[form_name].elements[i].checked) {
			OK = true;
			break;
		}
	}
	if (OK == false) {
		alert(message);
	}
	return OK
}

function confirmation (text) {
	OK = false
	var confirmation = confirm(text);
	if (confirmation == true) {
		OK = true
	}
	return OK
}

function validate(form_name, field, message) {
	OK = true
	for (i = 0; i < field.length; i++) {
		if (document.forms[form_name].elements[field[i]] != null) {
			if (document.forms[form_name].elements[field[i]].value == "" && document.forms[form_name].elements[field[i]].value != null) {
				alert(message[i]);
				OK = false;
				break;
			}
		}
	}
	return OK;
}

function get_window_width(){
   width = screen.width;
   return width;
}
function get_window_height(){
   height = screen.height;
   return height;
}

function na_open_window(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable)
{
  left = left+(screen.width-600)/2;
	top = top+(screen.height-480)/2;
  toolbar_str = toolbar ? 'yes' : 'no';
  menubar_str = menubar ? 'yes' : 'no';
  statusbar_str = statusbar ? 'yes' : 'no';
  scrollbar_str = scrollbar ? 'yes' : 'no';
  resizable_str = resizable ? 'yes' : 'no';
  window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);
}

function photo_window(url, width, height, left, top) {
	
	left = left+(screen.width-width)/2;
	top = top+(screen.height-height)/2;
	photo_win = window.open('about:blank', 'win', 'width='+width+',height='+height+', top='+top+', left='+left+', toolbar=no, menubar=no,statusbar=no,scrollbar=no, resizable=no');
	photo_win.document.write('<html><head></head><body leftmargin="0" topmargin="0"><table border="0" width="100%" height="100%" cellpadding="0" cellspacing="0">');
	photo_win.document.write('<tr valign="middle"><td align="center"><img src="'+url+'" border=0 width="'+width+'" height="'+height+'" align="center"></tr></table></body></html>');

}

function photo_text_window(url, width, height, left, top, text, img_width, img_height, weburl) {
	
	left = left+(screen.width-width)/2;
	top = top+(screen.height-height)/2;
	photo_text_win = window.open('about:blank', 'win', 'width='+(width)+',height='+(height+7)+', top='+top+', left='+left+', toolbar=0, menubar=0,status=0,scrollbars=0,resizable=no');
	photo_text_win.document.write('<html><head><LINK rel="stylesheet" type="text/css" name="styles" href="'+weburl+'new_styles.css"></head><body leftmargin="0" topmargin="0">');
	photo_text_win.document.write('<table border="0" cellpadding="0" cellspacing="0" align="center">');
		photo_text_win.document.write('<tr valign="top"><td align="center"><img src="'+url+'" border="0" width="'+img_width+'" height="'+img_height+'" align="center"></tr>');
		photo_text_win.document.write('<tr valign="top"><td height="1"></td></tr>');
		photo_text_win.document.write('<tr><td height="3"><img src="'+weburl+'/images/sininejoon.gif" width="'+width+'" height="2" valign="bottom"></td></tr>');
		photo_text_win.document.write('<tr align="center"><td height="85">');
			photo_text_win.document.write('<table cellpadding="0" cellspacing="0" width="'+(width-10)+'" border="0" valign="middle" align="center">');
				photo_text_win.document.write('<tr><td align="center"><p class="text">'+text+'</p></td></tr>');
			photo_text_win.document.write('</table></td>');
		photo_text_win.document.write('</tr>');
	photo_text_win.document.write('</table></body></html>');

}

function na_preload_img()
{ 
  var img_list = na_preload_img.arguments;
  if (document.preloadlist == null) 
    document.preloadlist = new Array();
  var top = document.preloadlist.length;
  for (var i=0; i < img_list.length; i++) {
    document.preloadlist[top+i] = new Image;
    document.preloadlist[top+i].src = img_list[i+1];
  } 
}

function na_change_img_src(name, nsdoc, rpath, preload)
{ 
  var img = eval((navigator.appName.indexOf('Netscape', 0) != -1) ? nsdoc+'.'+name : 'document.all.'+name);
  if (name == '')
    return;
  if (img) {
    img.altsrc = img.src;
    img.src    = rpath;
  } 
}

function na_restore_img_src(name, nsdoc)
{
  var img = eval((navigator.appName.indexOf('Netscape', 0) != -1) ? nsdoc+'.'+name : 'document.all.'+name);
  if (name == '')
    return;
  if (img && img.altsrc) {
    img.src    = img.altsrc;
    img.altsrc = null;
  } 
}

function jump(url_list)
{
	var new_url = url_list.options[url_list.selectedIndex].value;
	window.location.href = new_url;

}

function checkbox_jump(url) {

	var new_url = url.value;
	window.location.href = new_url;

}

function bold() {

	txt=prompt("Sisesta tekst, mis peaks olema rasvases kirjas.","Tekst");
	if (txt != null && txt != '') {
		AddTxt = "[b]"+txt+"[/b]";
		AddText(AddTxt);
	}

}

function italicize() {
	
	txt=prompt("Sisesta tekst, mis peaks olema kaldkirjas.","Tekst");
	if (txt!=null && txt != '') {
		AddTxt="[i]"+txt+"[/i]";
		AddText(AddTxt);
	}

}

function underline() {

	txt=prompt("Sisesta tekst, mis peaks olema alla joonitud.","Tekst");     
	if (txt!=null && txt != '') {
		AddTxt="[u]"+txt+"[/u]";
		AddText(AddTxt);
	}

}

function hyperlink() {

	txt2=prompt("Sisesta tekst, mis kuvatakse lingina. Kui see väli tühjaks jätta, kuvatakse lingi aadress.","");
	if (txt2 != null)	{
		txt=prompt("Sisesta aadress, kuhu link viitab.","http://");
		if (txt == '' || txt == 'http://') {
			alert("Lingi aadress jäi sisestamata!");
		}
		else if (txt != null)	{
			if (txt2 == "") {
				AddTxt="[url="+txt+"]"+txt+"[/url]";
				AddText(AddTxt);
			}else {
				AddTxt="[url="+txt+"]"+txt2+"[/url]";
				AddText(AddTxt);
			}
		}

	}
	
}

function AddText(text) {
	
	if (document.input.message.createTextRange && document.input.message.caretPos) {
		var caretPos = document.input.message.caretPos
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		setfocus();
	}else {
		document.input.message.value  += text;
		setfocus();
	}

}

function storeCaret(textEl) {

	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();

}

function setfocus() {

	document.input.message.focus();

}

