// JavaScript 
//
// Pientalon teknisen laadun arviointi
// 2005
//

// macromedia's cross browser find object -function
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;
}

// macromedia's change property
function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false) { eval("obj."+theProp+"="+theValue); }
    else { 
	var doMe = "obj." + theProp + "='" + theValue + "'" ;
	eval( doMe );
	}
  }
}

// macromedia's show/hide layers
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

// showHideElement()
// hides an element
//
// targetElement is the element to be shown/hid.
//
// note:
// doesn't get the right object reference with 'this' in a-tag href, ie.
// href="showHideObject('someElement');" instead, has to be put in the onclick event.
// The targetElement (the one being hidden/shown) has to have style="display:block;"
// or style="display:none;" set it it's parameters for the function to work correctly

var returnVal = true;

function showHideElement(targetElement) {

	var theObj = MM_findObj(targetElement);

	// hide / show the 
	if ( theObj.style ) {
		var currentDisplay = theObj.style.display;
		if ( currentDisplay == 'block' ) {
			// classElement.className = 'plus'; # redundant
			theObj.style.display = 'none';
		} else {
			// classElement.className = 'minus'; # redundant
			theObj.style.display = 'block';
		}
	}
	returnVal = false;
}

function dialogAnswer(message) {
	returnVal = confirm(message) ;
}

function alertAnswer() {
	alert("Jotta kohde täyttäisi rakennusmääräykset, täytyy tähän kysymykseen vastata 'Kyllä'.") ;
}
