function rep(value)
          {
            return value.replace(',','.');
          }
          
          
function calc()
{
	var calform = document.forms['cal'];
	var hind = Math.ceil(rep(calform.hind.value));
	var sissemaks = Math.ceil(calform.sissemaks.value);
	var sissemakse = Math.ceil(hind/100)*sissemaks;
	var jaak = hind - sissemakse;
	var intress = rep(calform.intress.value);   
	var aastad = parseInt(calform.periood.value * 12)
	var intress2 = (intress/100/12) + 1;
	if(intress && hind && aastad)
	{
	  var it = (1 - Math.pow(intress2, -aastad)) / (intress2 - 1);
	  anym = Math.round(jaak/it);
	 anynum=eval(anym);
	workNum=Math.abs(Math.round(anynum));
	workStr=""+workNum;
	dStr=workStr;
	dNum=dStr-0;
	/*
	pStr=workStr.substr(workStr.indexOf("."));
	while (pStr.length<3) {
	pStr+="0";
	}
	*/
	if (dNum>=1000) {
	dLen=dStr.length;
	dStr=parseInt(""+(dNum/1000))+" "+dStr.substring(dLen-3,dLen);
	}
	calform.sissemakse.value=Math.round(sissemakse);
	if(document.getElementById('kuumakse'))document.getElementById('kuumakse').innerHTML= dStr;
	}
	else
	{
	  if(document.getElementById('kuumakse'))document.getElementById('kuumakse').innerHTML = ' -';
	  calform.sissemakse.value = ' -';
	}
}

function getContent(update,url) {
	new Ajax.Updater(update, url, {asynchronous:true, evalScripts:true, requestHeaders:['X-Update', update]});
}

function pricelist(floor){
	var url='list.php?korrus='+floor
	getContent('pricelist',url);
	
}

function newWin(page,winName,w,h,scrollb,resize) {  
	var win=null;  
	centerWidth = (screen.width) ? (screen.width-w)/2 : 0;  
	centerHeight = (screen.height) ? (screen.height-h)/2 : 0;  
	config = 'height='+h+',width='+w+',top='+centerHeight+',left='+centerWidth+',scrollbars='+scrollb+',resizable='+resize+''; 
	win = window.open(page,winName,config);  
}  


function virttuur(){
	newWin('http://www.vd.fi/uusmaa/keskuse_park/park.htm','virt',600,400,false,false);
}


/*POPUP*/
function putwin(){
	
	var JH = 0;
	var JW = 0;
	var JX = 0;
	var JY = 0;
	
	var wm = document.getElementById('popup');
	
	JH = document.documentElement.clientHeight;
	JW = document.documentElement.clientWidth;
	JX = document.documentElement.scrollLeft;
	JY = document.documentElement.scrollTop;
	
	
	l_top = JH + JY - parseInt(parseFloat(JH/2) + parseFloat(440)/2);
	l_left = JW + JX - parseInt(parseFloat(JW/2) + parseFloat(790)/2);
	
	
	wm.style.top = l_top+'px';
	wm.style.left = l_left+'px';
	
}

function showpopup(url,floor,img){
	putwin();
	
	var url='popup.php?nr='+url;
	if(img)url='img.php?f='+img;
	if(floor)url+='&k='+floor;
	
	$('popup').style.display='block';
	var objBody = document.getElementsByTagName("body").item(0);

	var objOverlay = document.createElement("div");
	objOverlay.id = "overlay";
	var pagesize = getPageSize();

	objOverlay.style['width'] = pagesize[0]+'px';
	objOverlay.style['height'] = pagesize[1]+'px';

	objBody.appendChild(objOverlay);
	
	getContent('popup_content',url);

}
	
function closepopup(){
	$('popup').style.display='none';
	var objBody = document.getElementsByTagName("body").item(0);
	objBody.removeChild($('overlay'));
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
