function apply_shadow(img_name)
	{
		if (document.images)
		{
			if (img_name=="ok")		
				document.images[img_name].src="ok_sh.gif";
			if	(img_name=="trash")
				document.images[img_name].src="trash_sh.gif";
			if	(img_name=="delete")
				document.images[img_name].src="delete_sh.gif";
			if (img_name=="ok_s")		
				document.images[img_name].src="ok_sh.gif";
			if (img_name=="arrow")		
				document.images[img_name].src="shift-right_sh.gif";
			if (img_name=="leftarrow")		
				document.images[img_name].src="shift-left_sh.gif";
			if (img_name=="help")		
				document.images[img_name].src="help_sh.gif";
			if (img_name=="reload")		
				document.images[img_name].src="reload_sh.gif";
			if (img_name=="uparrow")		
				document.images[img_name].src="shift-up_sh.gif";
		}
	}

function delete_shadowUIF(img_name)
	{
		
		if (document.images)
		{
			if (img_name=="ok")		
				document.images[img_name].src="../ok.gif";
			if	(img_name=="trash")
				document.images[img_name].src="../trash.gif";
			if	(img_name=="delete")
				document.images[img_name].src="../delete.gif";
			if (img_name=="arrow")		
				document.images[img_name].src="../shift-right.gif";
			if (img_name=="leftarrow")		
				document.images[img_name].src="../shift-left.gif";
			if (img_name=="help")		
				document.images[img_name].src="../help.gif";
		}
	}

function apply_shadowUIF(img_name)
	{
		if (document.images)
		{
			if (img_name=="ok")		
				document.images[img_name].src="../ok_sh.gif";
			if	(img_name=="trash")
				document.images[img_name].src="../trash_sh.gif";
			if	(img_name=="delete")
				document.images[img_name].src="../delete_sh.gif";
			if (img_name=="arrow")		
				document.images[img_name].src="../shift-right_sh.gif";
			if (img_name=="leftarrow")		
				document.images[img_name].src="../shift-left_sh.gif";
			if (img_name=="help")		
				document.images[img_name].src="../help_sh.gif";
		}
	}
function delete_shadowObjectUIF(img)
	{
		
		if (document.images)
		{
			if	(img.name=="TrashB")
				img.src="../trash.gif";
			if	(img.name=="zoomOut")
				img.src="../zooumOut.gif";
			if	(img.name=="zoomIn")
				img.src="../zooumIn.gif";
		}
	}

function apply_shadowObjectUIF(img)
	{
		if (document.images)
		{
			if	(img.name=="TrashB")
				img.src="../trash_sh.gif";
			if	(img.name=="zoomOut")
				img.src="../zooumOut_sh.gif";
			if	(img.name=="zoomIn")
				img.src="../zooumIn_sh.gif";
		}
	}
function delete_shadowObject(img)
	{
		
		if (document.images)
		{
			if	(img.name=="TrashB")
				img.src="trash.gif";
			if	(img.name=="zoomOut")
				img.src="zoomOut.gif";
			if	(img.name=="zoomIn")
				img.src="zoomIn.gif";
			if	(img.name=="info")
				img.src="info.gif";
		}
	}

function apply_shadowObject(img)
	{
		if (document.images)
		{
			if	(img.name=="TrashB")
				img.src="trash_sh.gif";
			if	(img.name=="zoomOut")
				img.src="zoomOut_sh.gif";
			if	(img.name=="zoomIn")
				img.src="zoomIn_sh.gif";
			if	(img.name=="info")
				img.src="info_sh.gif";
		}
	}

function delete_shadow(img_name)
	{
		
		if (document.images)
		{
			if (img_name=="ok")		
				document.images[img_name].src="ok.gif";
			if	(img_name=="trash")
				document.images[img_name].src="trash.gif";
			if	(img_name=="delete")
				document.images[img_name].src="delete.gif";
			if (img_name=="ok_s")		
				document.images[img_name].src="ok.gif";
			if (img_name=="arrow")		
				document.images[img_name].src="shift-right.gif";
			if (img_name=="leftarrow")		
				document.images[img_name].src="shift-left.gif";
			if (img_name=="help")		
				document.images[img_name].src="help.gif";
			if (img_name=="reload")		
				document.images[img_name].src="reload.gif";
			if (img_name=="uparrow")		
				document.images[img_name].src="shift-up.gif";
		}
	}

function getConstant(sName)
	{
		var sValue;
    		if (sName == "ComputerName" )
		    sValue = "tar2:81"
		else  if (sName == "IncomingFolder" )
		    sValue = "public/SisseTulnud"
		else  if (sName == "EelnouFolder" )
		    sValue = "public/Eelnoud"
		else
		   sValue = "!!Undefined constant name " + sName;
		
		getConstant = sValue;
}


	function uploadFile(sType, bParent, sFolder, sID, sAppl, sAasta ){
				var sFolderName, i, j ;
				var sRet;
				var cComputerName;
				cComputerName	= "195.250.186.251:81";
				sFolderName=sFolder;
				i = sFolderName.indexOf('Eelnoud' + sAasta +  '/');
				sFolderName = sFolderName.substr(i+12);
				i = sFolderName.indexOf('/');
				sFolderName = sFolderName.substr(0, i);
			if (bParent) {
				sRet=showModalDialog( '../'  + sAppl +  '?foldername=' + sFolderName + '&doctype=' + sType + '&document_id=' + sID + '&aasta=' + sAasta ,11  , 'dialogheight=25;dialogwidth=27;status:no;resizable:no' ) ;
				} 
			else {
				sRet=showModalDialog( sAppl +  '?foldername=' + sFolderName + '&doctype=' + sType + '&document_id=' + sID + '&aasta=' + sAasta ,11  , 'dialogheight=25;dialogwidth=27;status:no;resizable:no' ) ;
				//setInterval("document.location.reload(true);", 2000);
				setInterval("document.location.reload(true);");
			}

		}

	function getUploadMultipleUrl(sType, bParent, sFolder, sID, sAppl, sParams ){
			//ei kasutata, sest modaldialoogi ei saa uuendada
			if (bParent) {
				//sRet=showModalDialog( '../'  + sAppl +  '?foldername=' + sFolder+ '&doctype=' + sType + '&document_id=' + sID +  sParams,11  , 'dialogheight=25;dialogwidth=27;status:no;resizable:no' ) ;
				//return '../'  + sAppl +  '?foldername=' + sFolder+ '&doctype=' + sType + '&document_id=' + sID +  sParams;
				return 'http://aktalnts/'  + sAppl +  '?foldername=' + sFolder+ '&doctype=' + sType + '&document_id=' + sID +  sParams;
				} 
			else {
				//sRet=showModalDialog(sAppl +  '?foldername=' + sFolder + '&doctype=' + sType + '&document_id=' + sID + sParams ,11  , 'dialogheight=25;dialogwidth=27;status:no;resizable:no' ) ;
				return sAppl +  '?foldername=' + sFolder+ '&doctype=' + sType + '&document_id=' + sID +  sParams;
			}

		}
	function showXDialog(sfolderName, sType, sID, sAppl, sAasta){
		var cComputerName = '195.250.186.251:81'

		if (sType == '') {
		  sRet=showModalDialog( sAppl + 'foldername=' + sfolderName + '&eelnou_id=' + sID  + '&aasta=' + sAasta ,11  , 'dialogheight=35;dialogwidth=25;status:no;resizable:no' ) ; 
			}
		else {
		    if (sType=='d' || sType=='a' || sType=='p'|| sType=='l')
		      sRet=showModalDialog( sAppl + 'foldername=' + sfolderName + '&doctype=' + sType + '&document_id=' + sID + '&aasta=' + sAasta , 11  , 'dialogheight=35;dialogwidth=25;status:no;resizable:no' ) ;
		    else if (sType=='pr' || sType=='pk') 
			{
		      	sRet=showModalDialog( sAppl + 'foldername=' + sfolderName + '&doctype=' + sType + '&koosolek_id=' + sID + '&aasta=' + sAasta, 11  , 'dialogheight=35;dialogwidth=25;status:no;resizable:no' ) ;
			}
		    else if (sType=='ap'||sType=='apv'||sType=='apl')
		      sRet=showModalDialog( sAppl + 'foldername=' + sfolderName + '&doctype=' + sType + '&arupar_id=' + sID + '&aasta=' + sAasta, 11  , 'dialogheight=35;dialogwidth=25;status:no;resizable:no' ) ;
		    else if (sType=='vv' || sType=='ht')
		      sRet=showModalDialog( sAppl + 'foldername=' + sfolderName + '&doctype=' + sType + '&paevakosa_id=' + sID + '&aasta=' + sAasta, 11  , 'dialogheight=35;dialogwidth=25;status:no;resizable:no' ) ;
		    else if (sType == 'tv')
		  	sRet=showModalDialog( sAppl + 'foldername=' + sfolderName + '&eelnou_id=' + sID  + '&aasta=' + sAasta + '&doctype=' + sType ,11  , 'dialogheight=35;dialogwidth=25;status:no;resizable:no' ) ; 
		    else if (sType == 'oa')
			  sRet=showModalDialog( sAppl + 'foldername=' + sfolderName + '&eelnou_id=' + sID  + '&aasta=' + sAasta + '&doctype=' + sType ,11  , 'dialogheight=35;dialogwidth=25;status:no;resizable:no' ) ; 
		    else if (sType=='ava')
		      sRet=showModalDialog( sAppl + 'foldername=' + sfolderName + '&doctype=' + sType + '&avaldus_id=' + sID + '&aasta=' + sAasta, 11  , 'dialogheight=35;dialogwidth=25;status:no;resizable:no' ) ;
		    else if (sType=='prdok')
		      sRet=showModalDialog( sAppl + 'foldername=' + sfolderName + '&doctype=' + sType + '&protokpunkt_id=' + sID + '&aasta=' + sAasta, 11  , 'dialogheight=35;dialogwidth=25;status:no;resizable:no' ) ;
		    else if (sType=='komdok')
		      sRet=showModalDialog( sAppl + 'foldername=' + sfolderName + '&doctype=' + sType + '&komisjon_id=' + sID + '&aasta=' + sAasta, 11  , 'dialogheight=35;dialogwidth=25;status:no;resizable:no' ) ;
		    }
		return sRet
		}

	function showDelDialog(sfolderName, sType, sID, sFileName, sFileName2){

  		sRet=showModalDialog( 'listDelete.asp?foldername=' + sfolderName  + '&doctype=' + sType + '&objekt_id=' + sID  + '&filename=' + sFileName + '&filename2=' + sFileName2 ,11  , 'dialogheight=20;dialogwidth=30;status:no;resizable:no' ) ; 
		while (sRet=='3') //teeb reloadi
		{
	  		sRet=showModalDialog( 'listDelete.asp?foldername=' + sfolderName  + '&doctype=' + sType + '&objekt_id=' + sID  + '&filename=' + sFileName + '&filename2=' + sFileName2,11  , 'dialogheight=20;dialogwidth=30;status:no;resizable:no' ) ; 
		}		
		return sRet
		}


	function changeParamInUrl(sName, sValue, bParent){
		var sUrl, i, j,  sBeg, sEnd, sStr;
		if (bParent)
			sUrl = parent.document.URL;
		else
			sUrl = document.URL;
		i = sUrl.indexOf(sName + '=');
		if (i > 0) {
			sBeg=sUrl.substr(0, i); 
			sStr=sUrl.substr(i);
			j = sStr.indexOf('&');
			if (j > 0)
			   sEnd = sStr.substr(j);
			else
			   sEnd= '';

			sUrl=sBeg + sName + '=' + sValue + sEnd ;

			}
		else
			{

			j = sUrl.indexOf('?');
			if (j>0)
				sUrl = sUrl + '&' + sName + '=' + sValue;
			else
				sUrl = sUrl + '?' + sName + '=' + sValue;
			}
		return sUrl ;
		}


	function changeParamInString(sUrl, sName, sValue){
		var  i, j,  sBeg, sEnd, sStr;

		i = sUrl.indexOf(sName + '=');
		if (i > 0) {
			sBeg=sUrl.substr(0, i); 
			sStr=sUrl.substr(i);
			j = sStr.indexOf('&');
			if (j > 0)
			   sEnd = sStr.substr(j);
			else
			   sEnd= '';

			sUrl=sBeg + sName + '=' + sValue + sEnd ;

			}
		else
			{

			j = sUrl.indexOf('?');
			if (j>0)
				sUrl = sUrl + '&' + sName + '=' + sValue;
			else
				sUrl = sUrl + '?' + sName + '=' + sValue;
			}
		return sUrl ;
		}


	function getParamFromString(sUrl, sParam){
		if (sUrl.length>0 && sParam.length>0){
			i = sUrl.indexOf(sParam + '=');
			if (i>0){
				iStart = i + sParam.length +1;
				j = sUrl.indexOf('&', i);
				if (j > 0)
			   		iEnd = j;
				else
			   		iEnd= sUrl.length;
			   	//alert(sParam +":" + iStart +";" + iEnd);
			   	return sUrl.substr(iStart, iEnd-iStart);
			}			
		}
		return '';
	}
	function addParamToUrl(sName, sValue, bParent){
		var s;
		if (bParent)
		  s = parent.document.URL;
		else
		  s = document.URL;
		s = s + "&" + sName + "=" + sValue;
		return s;		
		}
	function delParamFromUrl(sName, bParent){
		var s;
		if (bParent)
		  s = parent.document.URL;
		else
		  s = document.URL;
		i=s.indexOf(sName);
		if (i>0){
			iAnd=s.indexOf("&", i);
			if (iAnd>0){
				s= s.substr(0,i-1) + s.substr(iAnd);
			}else
				s= s.substr(0,i-1);
		}
	//	alert(s);
		return s;		
		}

	function getNewUrl(sOldUrl, sName, sValue){
		var s;
		s = sOldUrl;
		s = s + "&" + sName + "=" + sValue;
		return s;		
		}

	function showSendDialog(sAppl, sTo, sUrl ){
		var cComputerName = '195.250.186.251:81'
		  sRet=showModalDialog( '../' + sAppl + '?to=' + sTo + '&url=' + sUrl  , 0  , 'dialogheight=25;dialogwidth=17;status:no;resizable:no' ) ; 
		  return sRet
		}

	//adds computer name to the url, if needed
	function composeURL(sUrl){
		var cComputerName, sFullUrl;
		cComputerName = "195.250.186.251:81";
		sFullUrl = 'http://' + cComputerName + '/' + sUrl;
		return sFullUrl;
		}


	function getToday(){
		var d, s, temp;
		d = new Date();

		s = "";   
		if ((d.getMonth()== '9')||(d.getMonth()== '10') || (d.getMonth()== '11'))
		{
			if ((d.getDate() >= '1') && (d.getDate() <= '9'))
				s += "0" + d.getDate()+ ".";      
			else
				s += d.getDate()+ ".";      
				s += (d.getMonth() + 1) + ".";     
				temp = "\"" + d.getYear() + "\"";
				temp = temp.substr(3,2);
				s += temp;  
			
		}
		else 
		{
			if ((d.getDate() >= '1') && (d.getDate() <= '9'))
				s += "0" + d.getDate()+ ".0";      
			else
				s += d.getDate()+ ".0";      

				s += (d.getMonth() + 1) + ".";               
				temp = "\"" + d.getYear() + "\"";
				temp = temp.substr(3,2);
				s += temp;  
		}
 	return s;
}
	function getTodayString(){
		var d, s, temp;
		d = new Date();

		s = "";   
		if ((d.getMonth()== '9')||(d.getMonth()== '10') || (d.getMonth()== '11'))
		{
			temp = "\"" + d.getYear() + "\"";
			temp = temp.substr(3,2);
			s = temp
			s += (d.getMonth() + 1); 
			if ((d.getDate() >= '1') && (d.getDate() <= '9'))
				s += "0" + d.getDate();
			else
				s += d.getDate();
			
		}
		else 
		{
			temp = "\"" + d.getYear() + "\"";
			temp = temp.substr(3,2);
			s = temp;  
			s += "0" + d.getMonth(); 
			if ((d.getDate() >= '1') && (d.getDate() <= '9'))
				s += "0" + d.getDate();
			else
				s += d.getDate();

		}
 	return s;
}


// Sets the value of the specified key field to zero and text field to empty text
// hides the frame

function setNothing(sKeyField, sTextField, sFrameName)
	{
	if (sKeyField == 'ESITAJA_ID'){
	  window.parent.hidden_form.ESIT.value = '';
	  window.parent.ESITAJA_ID.innerHTML= 0;
	  parent.document.all.hidden_form.upd.value = '1';
	  //parent.frames.tegijad.style.display='none';
	}
	else if(sKeyField == 'KOOSTAJA_ID')
	{
	  window.parent.hidden_form.KOOST.value = '';
	  window.parent.KOOSTAJA_ID.innerHTML= 0;
	  parent.document.all.hidden_form.upd.value = '1';
	  //parent.frames.tegijad.style.display='none';
	}
	else if(sKeyField == 'LABIVAATAJA_ID')
	{
	  //window.parent.hidden_form.KOOST.value = '';
	  //window.parent.KOOSTAJA_ID.innerHTML= 0;
	  //parent.frames.tegijad.style.display='none';
	}
	else if (sKeyField=='ETTEK') 
	{
		if (! window.parent.document.all.hidden_form)
		{	 
			window.parent.document.all.ETTEK.value='';
			window.parent.document.all.upd.value = '1';
		}		
		if (window.parent.document.all.hidden_form)
		{
			window.parent.document.all.hidden_form.ETTEK.value='';
			window.parent.document.all.hidden_form.upd.value = '1';
		}
	}
	if (parent.frames.tegijad)
		parent.frames.tegijad.style.display='none';
	else {
		parent.frames.esitajad.style.display='none';
		parent.frames.koostajad.style.display='none';}
	}

function colorOnAlt(oControl){
	oControl.style.backgroundColor='#99cc66';
	}

function colorOffAlt(oControl){
	oControl.style.backgroundColor='#ffffcc';
	}

function colorOn(oControl){
	oControl.style.backgroundColor='#ffffee';
	}

function colorOff(oControl){
	oControl.style.backgroundColor='#99cc66';
	}

function staatus_aasta(id_nimi)
	{
		if (id_nimi == "st")
		{
			if (staatus.style.display == "none")
			{
				staatusFrame.frameElement.src= "staatus.jsv?liik=en"  ;
				staatus.style.display = "inline";
			}
			else 
				staatus.style.display = "none";
		}
		else if (id_nimi == "aa")
		{
			if (aasta.style.display == "none")
				{
				aastaFrame.frameElement.src= "staatus.jsv?liik=aa"  ;
				aasta.style.display = "inline";
				}
			else 
				aasta.style.display = "none";
		}
		else if (id_nimi == "ap")
		{
			if (staatus.style.display == "none")
				{
				staatusFrame.frameElement.src= "staatus.jsv?liik=ap"  ;
				staatus.style.display = "inline";
				}
			else 
				staatus.style.display = "none";
		}
	}


//checks and returns false, if string contains of spaces

function checkSpaces(sString){

  var bNoSpaces = false;
  var i;

  if (sString.length > 0)
    for (i = 0; i < sString.length; i++)
      if (sString.substr(i,1) != ' '){
        bNoSpaces = true;
	break;
	}
    return bNoSpaces;
}


//true, if user is logged in, false if not

	function loggedIn(){
		var sUserName ;
		sUserName = GetCookie("username");

		if (sUserName == null)
			return false;
		else
			return true;
		}



//Kui bLessen=true, siis lahutab kuupäevast sAdd, muidu liidab kuupäevale sAdd
function incrementDate(sDate, sAdd, bLessen)
{
	var sDay;
	var sMonth;
	var sYear;

	sDay = sDate.substr(0,2);
	sMonth = sDate.substr(3,2);
	sYear = sDate.substr(6,2);
//Lahutamine
	if (bLessen==true)
	{
		while (sAdd>0)
		{
			if (sDay == 1 && ( sMonth == 5 || sMonth == 7 || sMonth == 10 || sMonth == 12   )  )
			{
				sDay=30;
				sMonth=eval(sMonth)-1;
				}
			else if (sDay == 1 && ( sMonth == 2 || sMonth == 4 || sMonth == 6 || sMonth == 8 || sMonth == 9 || sMonth == 11 ))
			{
				sDay=31;
				sMonth=eval(sMonth)-1;
			}
			else if (sDay == 1 &&  sMonth == 1)
			{
				sDay=31;
				sMonth=12;
				if (sYear==00)
					sYear=99;
				else
					sYear=eval(sYear) - 1;
			}
			else if (sDay == 1 &&  sMonth == 3)
			{		
				var bY;
				bY = false;

				if ( sYear/4 == Math.floor(sYear/4 )   )
					bY = true;
	
			    if (bY == true)
					sDay=29;
				else
					sDay=28;
				sMonth=eval(sMonth)-1;				
			}
			else
				sDay=eval(sDay)-1;
			sAdd=eval(sAdd)-1;
		}
	}
//Liitmine
	else
	{
		while (sAdd>0)
		{
			if (sDay == 30 && ( sMonth == 4 || sMonth == 6 || sMonth == 9 || sMonth == 11   )  )
			{
				sDay=1;
				sMonth=eval(sMonth)+1;
				}
			else if (sDay == 31 && ( sMonth == 1 || sMonth == 3 || sMonth == 5 || sMonth == 7 || sMonth == 8 || sMonth == 10 ))
			{
				sDay=1;
				sMonth=eval(sMonth)+1;
			}
			else if (sDay == 31 &&  sMonth == 12)
			{
				sDay=1;
				sMonth=1;
				if (sYear==99)
					sYear=0;
				else
					sYear=eval(sYear) + 1;
			}
			else if (sDay > 27 &&  sMonth == 2)
			{		
				var bY;
				bY = false;


				if ( sYear/4 == Math.floor(sYear/4 )   )
					bY = true;
	
			    if (sDay == 28 &&  bY == true)
					sDay=eval(sDay)+1;
				else
					{
					sDay=1;
					sMonth=eval(sMonth)+1;
					}
				
			}
			else
				sDay=eval(sDay)+1;
			sAdd=eval(sAdd)-1;
		}
	}
	if (sDay<10 && sDay.length!=2){sDay="0"+sDay}
	if (sMonth<10 && sMonth.length!=2){sMonth="0"+sMonth}
	if (sYear<10 && sYear.length!=2){sYear="0"+sYear}
//	alert(sDay+"."+sMonth+"."+sYear);
	
	var sNewDate=sDay+"."+sMonth+"."+sYear;
	return sNewDate;
}
function getToday()
{
	var the_date = new Date();

	var the_day = the_date.getDate();
	var the_month = the_date.getMonth() + 1;
	var the_year = the_date.getYear();

	if (the_day<10 && the_day.length!=2){the_day="0"+the_day}
	if (the_month<10 && the_month.length!=2){the_month="0"+the_month}
	//Aasta pikkus peab olema 2
	the_year=the_year+"";
	the_year=the_year.substr(2, 2);
	//if (the_year<10 && the_year.length!=2){the_year="0"+the_year}

	return the_day + "." + the_month + "." + the_year;
}

//funktsioon võrdleb kuupäevi
//kui gDate on suurem kui lDate, siis tagastab true
//kui lDate on suurem kui lDate, siis tagastab false
//kui gDate võrdub lDate ja bEqual=true, siis tagastab true
//kui gDate võrdub lDate ja bEqual=fasle, siis tagastab false
function compareDates(greaterDate, lowerDate, bEqual)
{
	var sgDay;
	var sgMonth;
	var sgYear;
	var slDay;
	var slMonth;
	var slYear;
	var bReturn;

	bReturn=false;

	sgDay = greaterDate.substr(0,2);
	sgMonth = greaterDate.substr(3,2);
	sgYear = greaterDate.substr(6,2);

	slDay = lowerDate.substr(0,2);
	slMonth = lowerDate.substr(3,2);
	slYear = lowerDate.substr(6,2);

	if (sgYear>slYear)
		bReturn=true;
	else if (sgYear==slYear)
	{
		if (sgMonth>slMonth)
			bReturn=true;
		else if (sgMonth==slMonth)
		{
			if (sgDay>slDay)
				bReturn=true;
			else if (sgDay==slDay)
			{
				if (bEqual==true)
					bReturn=true;
			}
		}
	}	
	return bReturn;
}

function handleError(sStatus, sXML){
  var bOK;
			if(sStatus == 'Unauthorized'){
			  	window.status = "Sessioon aegunud";
				alert('Sessioon on aegunud. Palun proovige uuesti peale kasutajatunnuse ja parooli sisestamist.' );
				bOK = false;
				window.open('../UIF/login.html','login','width=300,height=170,resizable=no,scrollbars=no,toolbar=no,location=no,status=no,menubar=no,left=300,top=250,screenX=300,screenY=250');
				window.open("../ules.html","UPPER");
				}
			else {
				if (sXML != ""){
					alert(sXML);
					bOK = false;
					}
				else 
				  bOK = true ;
			     }
   return bOK;
}

// Utility function to trim spaces from both ends of a string
function Trim(inString) {
  var retVal = "";
  var start = 0;
  while ((start < inString.length) && (inString.substr(start,1) == ' ')) {
    ++start;
  }
  var end = inString.length;
  while ((end > 0) && (inString.substr(end - 1,1) == ' ')) {
    --end;
  }
  retVal = inString.substring(start, end);
  return retVal;
}

function changeUPD(){
	if(upd)
		upd.value='1';
}

//Funktsoon kontrollib, kas tegemist on laupäeva või pühapäevaga, või riigipühaga. kui on siis tagastab true
function isHoliday(sHolDay) {
	var sNewDate, sDay;
	var bReturn=false;

	//sNewDate=Date.parse(sHolDay.substr(3,2) + "/" + sHolDay.substr(0,2) + "/" + sHolDay.substr(6,2));
	//alert(sHolDay);
	var dHoliday = new Date();
	dHoliday.setYear(eval("20"+sHolDay.substr(6,2)));
	dHoliday.setMonth(eval(sHolDay.substr(3,2))-1);
	dHoliday.setDate(eval(sHolDay.substr(0,2)));
	
	//alert(dHoliday.toLocaleString());
	sDay=dHoliday.getDay();
	if (sDay==0||sDay==6) //pühapäev ja laupäev
	{
	//	alert(sDay);
		bReturn=true;
	}
	//Kontrollib, kas on kindla kuupäevaga püha

	var sHol=sHolDay.substr(0, 5);
	if (sHol=="01.01"||sHol=="24.02"||sHol=="01.05"||sHol=="01.05"||sHol=="23.06"||sHol=="24.06"||sHol=="20.08"||sHol=="26.12"||sHol=="25.12")
	{
		bReturn=true;
	}
	return bReturn;

}


function checkOtsustusvoime (iMax, iReal, esimees, erakorraline) {

	if (esimees==0)
		return 0;//esimeest või aseesimeest ei ole kohal

	var iSuhe=3;  // by default - mitte erakorraline

	if (erakorraline=="1")
	{
		iSuhe=2;
	}
	//korraline koosolek Komisjon on otsustusvõimeline, kui korralisest komisjoni koosolekust võtab osa vähemalt kolmandik  
	//komisjoni koosseisust olevatest linnavolikogu liikmetest, sealhulgas komisjoni esimees või aseesimees (saavad olla ainult volikogu liikmed).
	if (eval(iMax)/iSuhe<=iReal)
	{
		return 1;
	}
	else
		return 0;
	// erakorralise komisjoni koosolek on otsustusvõimeline, kui koosolekust võtab osa 
	//vähemalt pool komisjoni koosseisus olevatest linnavolikogu liikmetest sealhulgas komisjoni esimees või aseesimees 
	//(saavad olla ainult volikogu liikmed).	
}

function insertRowNumbers() {
var i=window.document.hidden_form.nr.value;
window.document.hidden_form.nr.value = eval(i) + 1;
document.write(i + ".");
}
function insertPubTekst(id) {
	var oName= "window.document.hidden_form.i_" + id;
	//var oName= "document.all.i_" + id;
	var o = eval(oName);
	var sTekst=o.value;
/*	while (sTekst.indexOf(eval("String.fromCharCode(10)") + eval("String.fromCharCode(13)") + eval("String.fromCharCode(10)") + eval("String.fromCharCode(13)") + eval("String.fromCharCode(10)"))!=-1) {
		sTekst=sTekst.replace(eval("String.fromCharCode(10)") + eval("String.fromCharCode(13)") + eval("String.fromCharCode(10)" + eval("String.fromCharCode(13)") + eval("String.fromCharCode(10)")), "<BR/>");
	}*/
	while (sTekst.indexOf(eval("String.fromCharCode(10)"))!=-1) {
		sTekst=sTekst.replace(eval("String.fromCharCode(10)"), "<BR/>");
	}
	document.write(sTekst);
}

function publishKoosolek(staatus, id){
	if(staatus==0){
		window.status="Avalikustatakse p" + eval("String.fromCharCode(228)") + "evakorda ...";
		//sRet=showModalDialog("publish.asp?tyyp=koosolek&id=" + id + "&staatus=0" ,11  , 'dialogheight=15;dialogwidth=25;status:no;resizable:no' ) ; 
		window.open("publish.asp?tyyp=koosolek&id=" + id + "&staatus=0" ,"Avalikustamine",  "height=300,width=600,status=yes,toolbar=no,scrollbars=yes,resizable=no,menubar=no,location=no"); 
		//sRet=showModalDialog("http://localhost/aktal/publish.asp?tyyp=koosolek&id=" + id + "&staatus=0" ,11  , 'dialogheight=15;dialogwidth=25;status:no;resizable:no' ) ; 
	}
	else {
		window.status="Avalikustatakse protokolli ...";
		//sRet=showModalDialog("publish.asp?tyyp=koosolek&id=" + id + "&staatus=1" ,11  , 'dialogheight=15;dialogwidth=25;status:no;resizable:no' ) ; 
		window.open("publish.asp?tyyp=koosolek&id=" + id + "&staatus=1" ,"Avalikustamine",  "height=300,width=600,status=yes,toolbar=no,scrollbars=yes,resizable=no,menubar=no,location=no"); 
		 //sRet=showModalDialog("http://localhost/aktal/publish.asp?tyyp=koosolek&id=" + NUM.innerText + "&staatus=1" ,11  , 'dialogheight=15;dialogwidth=25;status:no;resizable:no' ) ; 
	}
	window.status="";
}
function publishKoosolekList(liik, aasta){
	window.status="Avalikustatakse koosolekute nimekirja ...";
	//sRet=showModalDialog("publish.asp?tyyp=koosolekud&id=" + liik + "&staatus=" + aasta ,11  , 'dialogheight=15;dialogwidth=25;status:no;resizable:no' ) ; 
	window.open("publish.asp?tyyp=koosolekud&id=" + liik + "&staatus=" + aasta ,"Avalikustamine",  "height=300,width=600,status=yes,toolbar=no,scrollbars=yes,resizable=no,menubar=no,location=no"); 
	window.status="";
}
function publishAruparimisedList(aasta){
	window.status="Avalikustatakse arupärimiste nimekirja ...";
	//sRet=showModalDialog("publish.asp?tyyp=aruparimised&staatus=" + aasta ,11  , 'dialogheight=15;dialogwidth=25;status:no;resizable:no' ) ; 
	window.open("publish.asp?tyyp=aruparimised&staatus=" + aasta ,"Avalikustamine",  "height=300,width=600,status=yes,toolbar=no,scrollbars=yes,resizable=no,menubar=no,location=no"); 
	window.status="";
}
function publishArupar(id){
	window.status="Avalikustatakse arupärimist ...";
	//sRet=showModalDialog("publish.asp?tyyp=arupar&id=" + id ,11  , 'dialogheight=15;dialogwidth=25;status:no;resizable:no' ) ; 
	window.open("publish.asp?tyyp=arupar&id=" + id ,"Avalikustamine",  "height=300,width=600,status=yes,toolbar=no,scrollbars=yes,resizable=no,menubar=no,location=no"); 
	window.status="";
}
function publishEelnoudList(aasta){
	window.status="Avalikustatakse eelnõude nimekirjad ...";
	//sRet=showModalDialog("publish.asp?tyyp=eelnoud&staatus=" + aasta ,11  , 'dialogheight=15;dialogwidth=25;status:no;resizable:no' ) ; 
	window.open("publish.asp?tyyp=eelnoud&staatus=" + aasta ,"Avalikustamine",  "height=300,width=600,status=yes,toolbar=no,scrollbars=yes,resizable=no,menubar=no,location=no"); 
	window.status="";
}
function publishEelnou(id){
	window.status="Avalikustatakse eelnõud ...";
	window.open("publish.asp?tyyp=eelnou&id=" + id ,"Avalikustamine",  "height=300,width=600,status=yes,toolbar=no,scrollbars=yes,resizable=no,menubar=no,location=no"); 
	//sRet=showModalDialog("publish.asp?tyyp=eelnou&id=" + id ,11  , 'dialogheight=15;dialogwidth=25;status:no;resizable:no' ) ; 
	window.status="";
}

function pealehele(){
	w = window.parent;
	w.location="avalik.html"
}
function pealehele_up(){
	w = window.parent;
	w.location="../avalik.html"
}

function getShortClockTime()
{
   var now    = new Date();
   var hour   = now.getHours();
   var minute = now.getMinutes();
   var second = now.getSeconds();
   if (hour   < 10) { hour   = "0" + hour;   }
   if (minute < 10) { minute = "0" + minute; }
   if (second < 10) { second = "0" + second; }
   var timeString = hour + ''+ minute + ''+ second;
   return timeString;
} // function getClockTime()

function tabs_clickTab(tab){
	
	var divs = document.getElementsByTagName("div");
    for (di=0;di<divs.length;di++) {
        thisDiv = divs[di];
        if ((thisDiv.id.indexOf("tabarea") != -1) && (thisDiv.id)) {
	        //alert(thisDiv.id);
			if (thisDiv.id == tab)
				thisDiv.style.display='inline';
			else
				thisDiv.style.display='none';
        }
    }
	var lis = document.getElementsByTagName("li");
    for (li=0;li<lis.length;li++) {
        thisLi = lis[li];
        thisLiName = thisLi.getAttribute("name");
        //alert(thisLi.getAttribute("name"));
        if ((thisLi.id.indexOf("tab") != -1) && (thisLi.id)) {
	        //alert(thisLi.id);
			if (thisLi.id == 'currenttab')
				thisLi.id= thisLiName;
			if (thisLiName == tab + '_tab')
				thisLi.id='currenttab';
        }
    }
  }
function getMonthIndex(month){
	if (month.indexOf("0")==0){
		month=month.substr(1);
	}
	month=eval(month);
	month--;
	return month;
}
function convertDate(date){
	var objDate = new Date();
	objDate.setFullYear('20' + date.substr(6),getMonthIndex(date.substr(3,2)),date.substr(0,2))
	//alert(objDate);
	//alert(objDate.getTime());
}

function writeLink(subject, text, path){
		var AKTALAV = "/aktalav";
		var AKTALNTS = "aktalnts";

		var host = window.location.hostname;
		var href = window.location.href;

		if (host == AKTALNTS)
		{
			host = host + "/avalik.html";
		}
		if (href.indexOf(AKTALAV)>0)
		{
			host = host + AKTALAV + "/";
		}

		if (!text){
			text ="Saada link";
		}
		if (!path){		
			var path = window.location.pathname;
		}

		var url = window.location.protocol + "//" + host + "?frame=" + path;

		if (subject)
		{
			subject = "&subject=" + subject;
		}
		var body = "body=<a href='" + url + "'>"+ url + "</a>";

		var out = '<a href="mailto:?' + body + subject + '">' + text + '</a>';

		document.write(out);
		//return out;
}

function confirmEndStructure(){
	//history.go(-1);
	document.edit_yksus.action.value="close_yksus";
	document.edit_yksus.submit(); 
}

function confirmChangeKuuluvused(){
	//history.go(-1);
	document.koosseis_muuda.action.value="kuuluvuste_andmete_muutmine";
	document.koosseis_muuda.submit(); 
}

function confirmKatkesta(){
//alert('zy');
	var agree=confirm("Kas oled kindel?");
	if (agree){
		history.go(-1);
		//document.edit_yksus.action.value="yksused";
		//document.edit_yksus.submit();
	}
//	return true;
//else
//	return false ;
}

function checkEmail(epost){
	if(epost != ''){
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (filter.test(epost)){
			return true;
		}else{
			alert('E-posti aadress on vale');
			return false;
		}
	}else{
		return true;
	}
}

//Ja"rgmised 3 funktsiooni on kontrollimiseks kas kasutaja on vormil midagi muutnud vo~i mitte.
/*
kasutamine:
- ma"rgisele <body> tuleb panna onload="vaikimisi()", ehk siis <body onload="vaikimisi()">
- lisada kaks elementi vormile: <input type="hidden" name="attrs2"/>
								<input type="hidden" name="attrs3"/>
- submitile lisada "tagasi()" funktsiooni ka"ivitus.
*/
function vaikimisi(){
	var elemValues = new Array();
	var elemNames = new Array();
	var elemendid = document.forms[0].elements;
	
	for (var i = 0; i < elemendid.length; i++){
		elemValues[i] = elemendid[i].value;
		elemNames[i] = elemendid[i].name;
	}
	document.forms[0].attrs2.value = elemValues.join("$");
	document.forms[0].attrs3.value = elemNames.join("$");
 }

  function tagasi(){
	var elemendidVormilt = document.forms[0].elements;
	var elemVanadVar = getArray(document.forms[0].attrs2.value, elemendidVormilt.length);
	var elemNimed = getArray(document.forms[0].attrs3.value, elemendidVormilt.length);

	for (var j = 0; j < elemendidVormilt.length; j++){
		for (var i = 0; i < elemNimed.length; i++){
			if(elemNimed[i]==elemendidVormilt[j].name &&
				elemVanadVar[i]!=elemendidVormilt[j].value && 
					elemNimed[i]!='attrs2' && 
						elemNimed[i]!='attrs3' && 
							elemNimed[i].length>0){
//						elemendidVormilt[j].focus();
				return false;
			}
		}
	}
	return true;
 }

  function getArray(stringElem, elemArv){
	var ar = new Array();
	for(var i=0; i<elemArv; i++){
		ar[i] = stringElem.substring(stringElem.lastIndexOf('$')+1, stringElem.length);
		stringElem = stringElem.substring(0, stringElem.lastIndexOf('$'));
	}
	return ar;
  }
  
function checkAll(field){
	for (i = 0; i < field.length; i++)
		field[i].checked = true ;
}

function uncheckAll(field){
	for (i = 0; i < field.length; i++)
		field[i].checked = false ;
}
  
  function goTo(url){
	  window.location=url;
  }
  
  function openPrint(url){
	  printwindow = window.open(url,'print','menubar=yes,toolbar=yes,location=yes,scrollbars=yes,width=1000px,height=700px')
	  printwindow.moveTo(10,10);
  }
  
  function openHistory(value){
	  goTo('main?action=ajaloo_yksused&volikogu_id='+value);
  }
  
  function openHalduskogudeAjalugu(value){
	  goTo('main?action=halduskogu_ajalugu&yksusId='+value);
  }
function openDocPopup(url){
	var a = window.open(url, "DokEdit", 'menubar=1,resizable=1,width=800,height=350');
	if(window.focus){
		a.focus();
	}
}