		
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function setPage(form_name,n) {
	// procedure will be called to move another page in navigation
	p = MM_findObj(form_name+'page_nr')
	switch(n) {
		case 'begin':	
			if (p.selectedIndex==0) {
				alert(error_firstpage)
				return false
			} else {
				p.selectedIndex=0
			}
			break;
		case 'prev':
			if (p.selectedIndex==0) {
				alert(error_firstpage)
				return false
			} else {
				p.selectedIndex=p.selectedIndex-1
			}
			break;
		case 'next':
			if (p.selectedIndex==p.length-1) {
				alert(error_lastpage)
				return false
			} else {
				p.selectedIndex=p.selectedIndex+1
				
			}
			break;
		case 'end':
			if (p.selectedIndex==p.length-1) {
				alert(error_lastpage)
				return false
			} else {
				p.selectedIndex=p.length-1
			}
			break;
	}
	return true;
}

function selectEdit(form_name,val) {

  s=document.forms[form_name].ids
  if (s.length==null) {
    s.checked=true
  } else {
    for (i=0; i<s.length; i++) {
      if (s[i].value == val) {
  	    s[i].checked=true
		  } else {
		    s[i].checked=false
	 		}
		}
	}
}

lastCount = 0;
function round(num,after) {
	with (Math) {
		return round(pow(10,after)*num)/pow(10,after)
	}
}

function showProduct(id,width,height) {
	window.open('info.php?id='+id,'info','width='+width+',height='+height+',scrollbars=1');
}

function detectCounter() {
	return document.getElementById('totalKmta')?true:false;
}

function add(id,num) {
	var sum;
	var obj = document.getElementById(id);
	if ((sum = parseInt(obj.value))>=0)
	{
		obj.value = sum+num;
	} else {
		obj.value = 0;
	}
}

function reduce(id,num) {
	var sum;
	var obj = document.getElementById(id);
	if ((sum = parseInt(obj.value))>0)
	{
		obj.value = sum-num;
	} else {
		obj.value = 0;
	}
}

function checkChange(id) {
	var sum;
	var obj = document.getElementById(id);
	if ((sum = parseInt(obj.value))<0 || isNaN(sum))
	{
		obj.value = 0;
	}
}

function findItem(id) {
	for(var i=0;items.length;i++) {
		if (items[i].id == id)
		{
			return items[i];
		}
	}
	return false;
}

function avaAken(file, nimi, w, h) {
        var winl = (screen.width - w) / 2;
        var wint = (screen.height - h) / 2;
        winprops = "height="+h+",width="+w+",top="+wint+",left="+winl+",scrollbars=no,resizable";
        var aken = window.open('', nimi, winprops);
        if (parseInt(navigator.appVersion) >= 4) { aken.window.focus(); }
        aken.document.writeln("<html><head><title>Pilt</title></head><body marginheight='0' marginwidth='0' rightmargin='0' topmargin='0' bottommargin='0'onBlur=window.close();><img src='"+file+"' onClick='window.close()' height='"+h+"' width='"+w+"' border=0 alt=''></body></html>");
}

function fAsk(what) {
	// procedure will be called if we want to make ask for confirmation
  a=confirm(what)
  if (a) {
    return true
  } else {
    return false
  }
}
