function backToTop() {
    var x1 = x2 = x3 = 0;
    var y1 = y2 = y3 = 0;

    if (document.documentElement) {
        x1 = document.documentElement.scrollLeft || 0;
        y1 = document.documentElement.scrollTop || 0;
    }

    if (document.body) {
        x2 = document.body.scrollLeft || 0;
        y2 = document.body.scrollTop || 0;
    }

    x3 = window.scrollX || 0;
    y3 = window.scrollY || 0;

    var x = Math.max(x1, Math.max(x2, x3));
    var y = Math.max(y1, Math.max(y2, y3));

    window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));

    if (x > 0 || y > 0) {
        window.setTimeout("backToTop()", 25);
    }
}

//  puhelinluettelon haku-sivun focus

function putFocus(formInst, elementInst) {
  if (document.forms.length > 0) {
   document.forms[formInst].elements[elementInst].focus();
  }
}

function printpage() {

window.print();  
}

<!--
// Nannette Thacker http://www.shiningstar.net
function confirmDeleteCountry()
{
var agree=confirm("Before deleting a country, \nplease take a look at the list of all countries. \nPress ok to proceed.");
if (agree)
	return true ;
else
	return false ;
}
// -->
<!--
// Nannette Thacker http://www.shiningstar.net
function confirmDelete()
{
var agree=confirm("Delete?");
if (agree)
	return true ;
else
	return false ;
}
// -->

function blocking(nr)
{
	if (document.layers)
	{
		current = (document.layers[nr].display == 'none') ? 'block' : 'none';
		document.layers[nr].display = current;
	}
	else if (document.all)
	{
		current = (document.all[nr].style.display == 'none') ? 'block' : 'none';
		document.all[nr].style.display = current;
	}
	else if (document.getElementById)
	{
		vista = (document.getElementById(nr).style.display == 'none') ? 'block' : 'none';
		document.getElementById(nr).style.display = vista;
	}
}

//show content
function showcontent() {
	
var myWidth = 0, myHeight = 0; var height = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
		height = myHeight-120;//-150
	  } else if( document.documentElement &&
		  ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
		height = myHeight-175;//-140
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
		height = myHeight-165;//-125
	  }
	//window.alert( 'Height= ' + myHeight );
	//document.write('<td class="content" height="100%">');
	//window.alert( 'height= ' + height );
	if( typeof( window.innerWidth ) == 'number' ) {
		//for moz, firefox, opera, safari
		
		document.write('<div style="padding-top: 0px; padding-right: 0px; height: ' + height +'px; overflow: auto;">');
	} else {
		//for ie
		//document.write('<div style="height: ' + height +'px;">');
		
		document.write('<div style="padding-top: 0px; padding-right: 0px; height: ' + height +'px; overflow: auto;">');
	}
}

//show content
function closecontent() {
	
	document.write('</div>');
}

/*DW scripts*/

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

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_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

/*
* pakkaja 11.8.2009
* PD specific scripts for company contact info handling on forms
*
*
*/
function PDFieldCheckCompanyAddress(ElementId, ElementToHide, PostElement) {

    var elem = document.getElementById(ElementId);
    
    var elemToHide = document.getElementById(ElementToHide);
        
    var elemPost = document.getElementById(PostElement);
    
    if (elem.checked) {
    
       
        elemToHide.style.display = 'block';
        elemPost.value = 'true';
        
        alert("Anna uudet yhteystiedot");

    
    } else {
    
        elemToHide.style.display = 'none';
        elemPost.value = 'false';
        
    
    }
    
              
}


/*
* pakkaja 7.7.2009
* PD specific scripts for CustomerId handling on forms
*
*
*/
function PDFieldCheck(ElementId, ElementToHide, PostElement) {

    var elem = document.getElementById(ElementId);
    
    var elemToHide = document.getElementById(ElementToHide);
        
    var elemPost = document.getElementById(PostElement);
    
    if (elem.value!='') {
    
        if (IsNumeric(elem.value) && PDCustomerIdLength(elem.value)) {
        
            alert("Olet antanut asiakasnumeron ja osoitetietoja ei kysytä");
           
            elemToHide.style.display = 'none';
            elemPost.value = 'false';
            
        }   else {
        
            alert("Asiakasnumero on virheellinen.\nSinun tulee antaa osoitetiedot.");
           
            elemToHide.style.display = 'block';
            elemPost.value = 'true';
        
        }

    
    } else {
    
            elemToHide.style.display = 'block';
            elemPost.value = 'true';
    
    }
    
              
}

function PDCustomerIdLength(sText) {

    var PDCustomerIdLength=true;
    
    // PD specific valid CustomerId length
   if (sText.length<4 || sText.length>5) 
    PDCustomerIdLength=false;
    
    return PDCustomerIdLength;
   
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

    
   // valid string contains only chars of ValidChars 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   
      
   return IsNumber;
}
   
function ChangeSectionVisibility(ElementId, ElementToHide) {
    
    var elem = document.getElementById(ElementId);
    
    var elemToHide = document.getElementById(ElementToHide);
      
    if (elem && elemToHide) {
    
        if (elem.value!='true')
            elemToHide.style.display = 'none';
        else 
            elemToHide.style.display = 'block';    
    
    }
    
}

function ChangeSectionVisibilityCheckbox(ElementId, ElementToHide) {
    
    var elem = document.getElementById(ElementId);
    
    var elemToHide = document.getElementById(ElementToHide);
      
    if (elem && elemToHide) {
    
        if (!elem.checked)
            elemToHide.style.display = 'none';
        else 
            elemToHide.style.display = 'block';    
    
    }
    
}


