function ScaleFrame(freimi){
	var doc = freimi.contentWindow.document;
	try{
		height = freimi.contentWindow.document.body.scrollHeight;
		freimi.style.height =  height +"px";
	} catch( e ){
		alert( "Crash:" + e );
	}
}

function setValueInSelect(elementid,initvalue) {

	for ( var i=0; i < document.getElementById(elementid).length; i++ ) {
		if ( document.getElementById(elementid)[i].value == initvalue ) {
			document.getElementById(elementid)[i].selected = true;
		}
	}
}





DynamicSelectOptions = {

	createBank : function( bank, subgroup ){
		if ( !this[bank] ){
			this[bank] = [];
		}
		bank = this[bank];
		if( bank ){
			bank[subgroup] = [];
		}
		return (bank[subgroup])? bank[subgroup] : null;

	},
	
	createOption : function( value,key ) {
	
		var optn = document.createElement("OPTION");
		
		if ( value.indexOf('~') != -1 ) {
			var splitted = new Array();
			splitted = value.split('~');
			optn.text = splitted[1];
			optn.value = splitted[0];
			optn.setAttribute( 'type', splitted[2] );
		} else {
			optn.text = key;
			optn.value = value;
		}
		
		return optn;
		
	},
	
	initSelect: function( target, bank, subgroup, value, filter ){

		//'majapaikat','Majoitus','','', document.getElementById('kategoria')[document.getElementById('kategoria').selectedIndex].value  
		//Reservation.Product.Spa,Reservation.Product.Hotel,Reservation.Product.Ship
		
		if ( filter != 'all') {
			switch (filter){
				case '_000':
					var showProducts = 'Reservation.Product.Hotel';
					break;			
				case '_100':
					var showProducts = 'Reservation.Product.Spa';
					break;						
				case '_200':
					var showProducts = 'Reservation.Product.Ship';
					break;					
				case '_300':
					var showProducts = 'Reservation.Product.Hotel';				
					break;			
			}
		}
		
	
		target = document.getElementById(target);

		var options = this[bank];
		options = options[subgroup];
		
		target.length = 1;

		if(options){

			for( i = 0 ; i < options.length ; i++ ){
				
				if ( filter != 'all') {
					//alert ( 'filter: ' + showProducts + ' text: ' + options[i].text + ' value: ' + options[i].value + ' type: ' + options[i].getAttribute('type') );
					if ( showProducts == options[i].getAttribute('type') ) {
						target.options[target.length] = options[i];
					}
				} else {
					target.options[target.length] = options[i];
				}				
				
				if(value){
					if( value == options[i].value){
						target.selectedIndex = target.length-1;
					}
				}
			}
		}
	},
	
	populateSelect: function( source, target, bank, filter ){
	
		//DynamicSelectOptions.populateSelect( this, 'majapaikat','Majoitus')"	
	
		if ( filter != 'all') {
			switch (filter){
				case '_000':
					var showProducts = 'Reservation.Product.Hotel';
					break;			
				case '_100':
					var showProducts = 'Reservation.Product.Spa';
					break;						
				case '_200':
					var showProducts = 'Reservation.Product.Ship';
					break;					
				case '_300':
					var showProducts = 'Reservation.Product.Hotel';				
					break;			
			}
		}
		
		target = document.getElementById(target);

		sourceSelectedValue = source.options[source.selectedIndex].value;
		
		var options = this[bank];
		options = options[sourceSelectedValue];
		
		target.length = 1;
		if(options){
			for( i = 0 ; i < options.length ; i++ ){
				if ( filter != 'all') {
					//alert ( 'filter: ' + showProducts + ' text: ' + options[i].text + ' value: ' + options[i].value + ' type: ' + options[i].getAttribute('type') );
					if ( showProducts == options[i].getAttribute('type') ) {
						target.options[target.length] = options[i];
					}
				} else {
					target.options[target.length] = options[i];
				}
			}
		}
		
		
		
	}
};



/* Ylavalikon javascriptitunkit IE:ta varten */

activateMenu = function(nav) {

/* currentStyle restricts the Javascript to IE only */
	if (document.all &&
 document.getElementById(nav).currentStyle) {  
        var navroot = document.getElementById(nav);
        
        /* Get all the list items within the menu */

        var lis=navroot.getElementsByTagName("LI");  
        for (i=0; i<lis.length; i++) {
        
           /* If the LI has another menu level */
            if(lis[i].lastChild.tagName=="UL"){
            
                /* assign the function to the LI */
             	lis[i].onmouseover=function() {	
                
                   /* display the inner menu */
                   this.lastChild.style.display="block";
                }
                lis[i].onmouseout=function() {   
                   this.lastChild.style.display="none";
                }
            }
        }
    }
}
window.onload= function(){
    /* pass the function the id of the top level UL */

    /* remove one, when only using one menu */
    activateMenu('nav'); 
}



function backButtonOverride()
{
  // Work around a Safari bug
  // that sometimes produces a blank page
  setTimeout("backButtonOverrideBody()", 1);

}

function backButtonOverrideBody()
{
  // Works if we backed up to get here
  try {
    history.forward();
  } catch (e) {
    // OK to ignore
  }
  // Every quarter-second, try again. The only
  // guaranteed method for Opera, Firefox,
  // and Safari, which don't always call
  // onLoad but *do* resume any timers when
  // returning to a page
  setTimeout("backButtonOverrideBody()", 100);
}