//<![CDATA[

var dont_toggle = false;
function toggle_visibility(aId){
	if(dont_toggle){
		dont_toggle = !dont_toggle;
		return;
	}
	if(typeof(aId) == 'string')
		myObject = document.getElementById(aId);
	else if(typeof(aId) == 'object')
		myObject = aId;

	if(myObject.className.lastIndexOf('closed')>=0)
		myObject.className = myObject.className.replace('closed', '');
	else
		myObject.className = myObject.className + ' closed';

}

var lastvisible;
var caller;
function toggle_single_visibility(aId){
	if(dont_toggle){
		dont_toggle = !dont_toggle;
		return;
	}
	if(typeof(aId) == 'string')
		myObject = document.getElementById(aId);
	else if(typeof(aId) == 'object')
		myObject = aId;

	lastobject = document.getElementById(lastvisible);
//	alert(lastvisible+' '+myObject.id);
	

	if(myObject.className.lastIndexOf('closed')>=0) {
		myObject.className = myObject.className.replace('closed', '');
		lastvisible = myObject.id;
		row = myObject.id.split(/_/);
		if(document.getElementById('orrow_'+caller)){
			document.getElementById('orrow_'+caller).style.backgroundColor='transparent';
		}
		caller = row[1];
		document.getElementById('orrow_'+caller).style.backgroundColor='#98d7fa';

		if(lastobject!=myObject) {
			lastobject.className = lastobject.className + ' closed';
		}
	} else {
//		myObject.className = myObject.className + ' closed';
	}
	
}

function datePickerCheckDate(aId, valMin, valMax) {
	if(typeof(aId) == 'string')
		myObject = document.getElementById(aId);
	else if(typeof(aId) == 'object')
		myObject = aId;

	dmY = myObject.value.split('.');

	var newdate = new Date();		
	if( !isNaN(dmY[0]) && !isNaN(dmY[1]) && !isNaN(dmY[2]) )
		newdate.setFullYear(dmY[2],dmY[1]-1,dmY[0]);
		
	mindate = new Date();
	mindate.setDate(mindate.getDate()+valMin);

	maxdate = new Date();
	maxdate.setDate(maxdate.getDate()+valMax);
	
	if(newdate > maxdate)
		newdate = maxdate;
	else if(newdate < mindate)
		newdate = mindate;
	
	myObject.value = newdate.getDate()+'.'+(newdate.getMonth()+1)+'.'+newdate.getFullYear();
}

function strToFloat(aStr){
	spacesRemoved = "";
	for(i=0;i<aStr.length ;i++)
		if(aStr.charAt(i)!=" ")spacesRemoved+=aStr.charAt(i);
	aStr = spacesRemoved;
	aFloat	 = aStr.split(","); // Pilkunnussintaa

	aStr	 = aFloat[0];
	if(!isNaN(aFloat[1])){
		if(aFloat[1].length==1) aFloat[1]=aFloat[1]+"0";
		aStr += "."+aFloat[1];
	}
	
	return aStr*1;
}

function wFlt(aFloat){
	if(!aFloat)
		return "0,00";

	sign = aFloat < 0 ? '-' : '';
	aFloat = Math.round(Math.abs(aFloat)*100) + '';

	integerpart = aFloat.substring(0,aFloat.length-2);
	decimalpart = aFloat.substring(aFloat.length-2);

/*
	integerpart =  Math.floor(aFloat);
	decimalpart = Math.round((aFloat - integerpart)*100);
	integerpart+= '';
	if(decimalpart<10)
		decimalpart='0' + decimalpart;
	if(decimalpart==0)
		decimalpart='00';*/
	var buff = '';
	for(j=-1, i=integerpart.length; i>=0; i--, j++){
		if((j%3) == 0 && j>1)
			buff = " " + buff;
		buff = integerpart.charAt(i) + buff;
	}
	if(buff=='0' && decimalpart == '00')
		sign='';
	return sign+''+buff+','+decimalpart;
}

function myPopup(href, width, height){
	dont_toggle = true;
	if(typeof(width)=='undefined')
		width=800;
	if(typeof(height)=='undefined')
		height = Math.round(width * 9 / 16);
//	alert('toolbar=yes,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width='+width+',height='+height+',left=200,top=250');
//	return;
	myPopupHandle = window.open(href,'myPopup','toolbar=yes,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width='+width+',height='+height+',left=200,top=250');
	return false;	
}

// ]]>
