function BrowserCheck() {
	var b = navigator.appName;
	if (b == 'Netscape') this.b = 'NS';
	else if (b == 'Microsoft Internet Explorer') this.b = 'IE';
	else this.b = b;
	this.v = parseInt(navigator.appVersion);
	this.NS = (this.b == 'NS' && this.v>=4);
	this.NS4 = (this.b == 'NS' && this.v == 4);
	this.NS5 = (this.b == 'NS' && this.v == 5);
	this.IE = (this.b == 'IE' && this.v>=4);
	this.IE4 = (navigator.userAgent.indexOf('MSIE 4')>0);
	this.IE5 = (navigator.userAgent.indexOf('MSIE 5')>0);
	if (this.IE5 || this.NS5) this.VER5 = true;
	if (this.IE4 || this.NS4) this.VER4 = true;
	this.OLD = (! this.VER5 && ! this.VER4) ? true : false;
	this.min = (this.NS||this.IE);
}
is = new BrowserCheck();

function popupPilt(asukoht, laius, korgus, tiitel){
	parameetrid  = 'directories=0,height='+( korgus+13 )+',width='+( laius+10 )+',location=0,menubar=0,';
	parameetrid += 'personalbar=0,resizable=0,scrollbars=no,status=0,toolbar=0';
	fs=window.open('', 'pilt', parameetrid);
	fs.document.write('<html>');
	fs.document.write('<head>');
	fs.document.write('<title>' + tiitel + '</title>');
	fs.document.write('</head>');
	fs.document.write('<body bgcolor="silver" marginwidth="0" marginheight="0" leftmargin="0" topmargin="0">');
	fs.document.write('<table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%">');
	fs.document.write('<tr><td align="center" valign="middle">');
	fs.document.write('<img src="' + asukoht + '" ALT="['+tiitel+']" BORDER="1">');
	fs.document.write('</td></tr>');
	fs.document.write('</table>');
	fs.document.write('</body>');
	fs.document.write('</html>');
}
//-- FLASH DETECTION --

function detectingFLASH() {
	var browser = navigator.userAgent.toLowerCase();
	flashVersion = 0;	
	// NS3+, Opera3+, IE5+ Mac
	if ( navigator.plugins != null && navigator.plugins.length > 0 ) {
		var flashPlugin = navigator.plugins['Shockwave Flash'];
		if ( typeof flashPlugin == 'object' ) { 
			if ( flashPlugin.description.indexOf('7.') != -1 ) flashVersion = 7;
			else if ( flashPlugin.description.indexOf('6.') != -1 ) flashVersion = 6;
			else if ( flashPlugin.description.indexOf('5.') != -1 ) flashVersion = 5;
			else if ( flashPlugin.description.indexOf('4.') != -1 ) flashVersion = 4;
			else if ( flashPlugin.description.indexOf('3.') != -1 ) flashVersion = 3;
		}
	} // IE4+ Win32 (VBscript)
	else if ( browser.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && browser.indexOf("win")!= -1 && browser.indexOf("16bit")== -1 ) {
		document.write('<scr' + 'ipt language="VBScript"\> \n');
		document.write('on error resume next \n');
		document.write('DIM obFlash \n');
		document.write('SET obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.7") \n');
		document.write('IF IsObject(obFlash) THEN \n');
		document.write('flashVersion = 7 \n');
		document.write('ELSE SET obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.6") END IF \n');
		document.write('IF flashVersion < 7 and IsObject(obFlash) THEN \n');
		document.write('flashVersion = 6 \n');
		document.write('ELSE SET obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.5") END IF \n');
		document.write('IF flashVersion < 6 and IsObject(obFlash) THEN \n');
		document.write('flashVersion = 5 \n');
		document.write('ELSE SET obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.4") END IF \n');
		document.write('IF flashVersion < 5 and IsObject(obFlash) THEN \n');
		document.write('flashVersion = 4 \n');
		document.write('ELSE SET obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.3") END IF \n');
		document.write('IF flashVersion < 4 and IsObject(obFlash) THEN \n');
		document.write('flashVersion = 3 \n');
		document.write('END IF\n');
		document.write('</s'+'cr'+'ipt\> \n');
	} else { // no Flash
		flashVersion = -1;
	}
	return flashVersion; 
}

function openNewWindow(URLtoOpen, windowName, windowFeatures) { 
  newWindow=window.open(URLtoOpen, windowName, windowFeatures);
}


//emaili validaator
function is_email(o){
	if ( !isEmail(o.value) && o.value.length>0) {
		alert ('Kontrolli e-posti aadressi korrektsust!\nE-mail address is not valid!')
		o.focus();
	}
}


function isEmail(str){
    var objRegExp =  /^((?:(?:(?:(\w|~)[~\.\-\+]?)*)(\w|~))+)\@((?:(?:(?:\w[\.\-\+]?){0,62})\w)+)\.([a-zA-Z]{2,6})$|^$/;
    return objRegExp.test(str);
}    

/////////////////////////////////////////////////////////////////////////////////////
function numbers(myfield, e, dec){
	var key;
	var keychar;

	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	keychar = String.fromCharCode(key);

	// control keys
	if ((key==null) || (key==0) || (key==8) || 
		(key==9) || (key==13) || (key==27) )
	   return true;

	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
	   return true;

	// decimal point jump
	else if (dec && (keychar == ".")){
	   myfield.form.elements[dec].focus();
	   return false;
	} else
	   return false;
}

function floatnumbers(myfield, e, dec){
	var key;
	var keychar;

	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	keychar = String.fromCharCode(key);

	// control keys
	if ((key==null) || (key==0) || (key==8) || 
		(key==9) || (key==13) || (key==27) )
	   return true;

	// numbers
	else if (((".,0123456789").indexOf(keychar) > -1))
	   return true;

	// decimal point jump
	else if (dec && (keychar == ".")){
	   myfield.form.elements[dec].focus();
	   return false;
	} else
	   return false;
}


function checkID(ik){
	if (ik.length != 11)
		return false;
	var s1 = 0;
	var s2 = 0;
	var k1 = 1;
	var k2 = 3;
	for (i=0; i < ik.length-1; i++){
		ch = ik.charAt(i);
		s1 += ch*k1;
		s2 += ch*k2;
		k1 = (k1>=9 ? 1 : k1+1);
		k2 = (k2>=9 ? 1 : k2+1);
	}
	if ((s1%11)<10)
		var ksum = s1%11
	else if ((s2%11)<10)
		var ksum = s2%11
	else
		var ksum = 0;

	var chk = ik.charAt(ik.length-1);
	if (chk == ksum)
		return true
	else
		return false;

}