function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
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 MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



function clearSelected(element) {
	element.style.border='0px solid #990000';;


}
document.selectedStep = Array();
function markSelected(element,step) {

if (document.selectedStep[step])
clearSelected(document.selectedStep[step]);

document.selectedStep[step]=element;

	element.style.border='3px solid #990000';;

}
document.steps_orig = new Array();


function savePrevious() {

	var alltags=document.getElementsByTagName('div');

	for (i=0; i<alltags.length; i++) {


		var test = '' + alltags[i].id;

		if (test.match(/^step.*/)) {
			

			
		
				document.steps_orig[alltags[i].id]=document.getElementById(alltags[i].id).innerHTML;
			
			
			
		}
	}

}


function activeSection(div_id) {

	var layers_i=0;
	sections_list = new Array();

	var alltags=document.getElementsByTagName('div');

	for (i=0; i<alltags.length; i++) {


		var test = '' + alltags[i].id;

		if (test.match(/^step.*/)) {
			sections_list[layers_i] = alltags[i].id;
			layers_i++;
			
			
			


			}
	}

	active_i = div_id.replace(/^step_/,"");
	
	for (i=0;i<sections_list.length;i++) {
		if (sections_list[i]!=div_id) passiveSection(sections_list[i]);
		nmbr = parseInt(sections_list[i].replace(/^step_/,""));
		
	if (nmbr>active_i) document.getElementById('step_' + nmbr).innerHTML=document.steps_orig['step_' + nmbr];

		}
	
	document.getElementById(div_id).style.filter='alpha(opacity=75)'; 
	document.getElementById(div_id).style.opacity='.75';
	document.getElementById(div_id).style.border='1px solid #990000';

	document.getElementById(div_id).onmouseover= function() {
	this.style.filter='alpha(opacity=99)'; 
	this.style.opacity='.99';
	}; 

	document.getElementById(div_id).onmouseout= function() {
	this.style.filter='alpha(opacity=75)'; 
	this.style.opacity='.75';
	};

}

function previousSection(div_id) {

	document.getElementById(div_id).style.filter='alpha(opacity=25)'; 
	document.getElementById(div_id).style.opacity='.25';

	document.getElementById(div_id).onmouseover= function() {
	this.style.filter='alpha(opacity=99)'; 
	this.style.opacity='.99';
	}; 

	document.getElementById(div_id).onmouseout= function() {
	this.style.filter='alpha(opacity=25)'; 
	this.style.opacity='.25';
	};

}

function passiveSection(div_id) {

	document.getElementById(div_id).style.filter='alpha(opacity=25)'; 
	document.getElementById(div_id).style.opacity='.25';
	document.getElementById(div_id).style.border='0px solid #990000';
	
	document.getElementById(div_id).onmouseover= function() {
	this.style.filter='alpha(opacity=25)'; 
	this.style.opacity='.25';
	}; 

	document.getElementById(div_id).onmouseout= function() {
	this.style.filter='alpha(opacity=25)'; 
	this.style.opacity='.25';
	};

}


var xmlhttp;
document.activeSection='';
document.url='';
function loadStep(url,postparameters,div_id,selectActive,selectActiveStep) {

		document.url=url;
		update=false;
		
		active_i = parseInt(div_id.replace(/^step_/,""));
		
		if (active_i<=parseInt(document.activeSection.replace(/^step_/,""))) {
		
			if (confirm('Oletko varma että haluat muuttaa tätä kohtaa? Muuttaessasi jo tehtyä valintaa, nollautuvat kaikki myöhemmät valinnat.')) {
		
				update=true;
			
			}
	
		}
		else update=true;
	
	if (update) {
			loadXMLDoc(url,postparameters,div_id);
			document.activeSection=div_id;
			activeSection(div_id);
			
			if(typeof(selectActive)=="object") {
				
				markSelected(selectActive,selectActiveStep);
			}
	
	}
}

function loadXMLDoc(url,postparameters,div_id)
{
xmlhttp=null
// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest()
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  }

  
  if (xmlhttp!=null)
  {
  loadXMLDoc.div_id=div_id;
  xmlhttp.onreadystatechange=state_Change
  xmlhttp.open("GET",url,true)
  xmlhttp.send(null)
  }
else
  {
  alert("Your browser does not support XMLHTTP.")
  }
}

function state_Change()
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
  {
  // if "OK"
  if (xmlhttp.status==200)
  {
 // alert("XML data OK")
//  document.getElementById('A1').innerHTML=xmlhttp.status
//  document.getElementById('A2').innerHTML=xmlhttp.statusText
//  document.getElementById('A3').innerHTML=xmlhttp.responseText

if (xmlhttp.responseText!='') {
document.getElementById(loadXMLDoc.div_id).innerHTML=xmlhttp.responseText;





}

  }
  else
  {
  alert("Problem retrieving XML data:" + xmlhttp.statusText)
  }
  }
}


function lataaStepinUrl() {
	loadStep(document.url,'',document.activeSection);
}


function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if ( 
aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
} 

