// Uuden ikkunan avaaminen
function UusiIkkuna(URL, leveys, korkeus, otsake){
  var w=600;
  var h=700;
  var Otsikko="BASIC";

  if (arguments.length >= 3){
    w = leveys;
    h = korkeus;
  }
  if (arguments.length >= 4){
    Otsikko = otsake;
  }
  var scroll="yes";
  LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
  TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
  settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable,alwaysRaised'; 
  //if (win.closed || !win){ 
  win = window.open(URL,Otsikko,settings);
  if(win.window.focus){win.window.focus();}
}


// tähän voi tehdä linkin, jolla esim. pikkuikkunan saa kiinni
function SuljeIkkuna() { self.close(); }


// cookien asettaminen javascriptillä
function Set_Cookie(name,value,expires,path,domain,secure) {
  var today = new Date();
  today.setTime( today.getTime() );

  if (expires){
    expires = expires * 1000 * 60 * 60 * 24;
  }
  var expires_date = new Date( today.getTime() + (expires) );

  document.cookie = name + "=" +escape( value ) +
    ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
    ( ( path ) ? ";path=" + path : "" ) + 
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );
}

// tekee linkkivalikon
// links = linkit osoitteisiin
// names = nimet linkeille
// alalinkit = alalinkkivalikko
// now = millä alasivulla nyt ollaan (ala muuttujan kenttä)
function linkkivalikko(links,names,alalinkit,now){
  if (now == ''){
    now = 'eivarmaanole';
  }
  // KOKONAISKORKEUS OLTAVA 53 KUVAN KOHDALLA
  document.write('<tr>');
  //document.write(vali);
  for (k=0;k<links.length;k++){
    if (k){
      document.write('<td width="1" align="center" valign="top">');
      document.write('<img src="fig/style2/linkkipalkki_ala_vali.png"></td>');
    }
    pois = 'alalinkkiOFF';
    if (links[k].search('ala=' + now)>0){
      pois = 'alalinkkiOFFNOW';
    }
    document.write('<td class="' + pois + '" height="28"');
    document.write('onmouseover="');
    document.write('this.className=\'alalinkkiON\'; ');
    document.write('POIS[' + k + ']=0; ');
    if (alalinkit[k] != ''){
      document.write('document.getElementById(\'linkkitaso_' + k + '\').className=\'linkkitasoON\';');
    }
    document.write('" onmouseout="tasopois(' + k + ',\'' + pois + '\');" ');
    document.write('onclick="window.location.href=\'' + links[k] + '\';" ');
    document.write('id="paalinkki_' + k + '"');
    document.write('nowrap>');
    document.write('<span style="margin-left:10px; margin-right:10px">');
    document.write(names[k]);
    document.write('</span>');
    document.write('</td>');
    //document.write(vali);
  }
  document.write('</tr><tr>');
  //document.write('<td height="0"></td>');
  for (k=0;k<links.length;k++){
    pois = 'alalinkkiOFF';
    if (links[k].search('ala=' + now)>0){
      pois = 'alalinkkiOFFNOW';
    }
    document.write('<td height="1" onmouseover="POIS[' + k + ']=0;" valign="top" align="left" ');
    document.write('onmouseout="tasopois(' + k + ',\'' + pois + '\');" nowrap>');
    document.write('<div class="linkkitasoOFF" id="linkkitaso_' + k + '">');
    if (alalinkit[k] != ''){
      // ALALINKKIENKÄSITTELY OMANA LAYERINA    
      document.write('<table border="0" cellspacing="0" cellpadding="0">');
      //document.write('<tr><td class="tummabg" height="1"></td></tr><tr><td>');
      document.write('<tr><td nowrap><table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td>');
      document.write(alalinkit[k]);
      document.write('</td></tr></table>');
      document.write('</td></tr></table>');
    }
    document.write('</div></td><td></td>');	
  }
  document.write('</tr>');
  //document.write('<td height="53" width="2" valign="top"><img src="fig/style/palkki2_oikea.png"></td>');
  //document.write('</td></tr></table></div>');
}

// SEURAAVAT KAKSI FUNKTIOTA LAITTAVAT OIKEASTI TASON POIS NÄKYVISTÄ JA SIIHEN LIITTYVÄN MAHDOLLISEN ALATASON
function tasopois(nro,offclass){
  POIS[nro] = 1;
  setTimeout('piilotaTaso(' + nro + ',\'' + offclass + '\');',100);
}

function piilotaTaso(nro,offclass){
  if (POIS[nro]){
    document.getElementById('paalinkki_' + nro).className=offclass;
    //document.getElementById('paalinkki_' + nro).className='alalinkkiOFF';
    document.getElementById('linkkitaso_' + nro).className='linkkitasoOFF';	
  }
}


// TEKEE PÄÄOTSIKON, 
function ulkoasu_otsikko(teksti,kuva){

  kuvat = new Array('huuto',
		    'kalsin',
		    'kalora',
		    'muistio',
		    'stop');
  polut = new Array('huutomerkki',
		    'kalenteri_sin',
		    'kalenteri_ora',
		    'muistilehtio',
		    'stop');
  kuvanow = 'kalenteri_sin';
  for (k=0;k<kuvat.length;k++){
    if (kuva == kuvat[k]){
      kuvanow = polut[k];
      break;
    }
  }

  document.write('<table border="0" cellspacing="0" cellpadding="0" width="100%">' +
		 '<tr><td width="11" height="55" align="right" valign="top">' +
		 '<div style="margin-top: 17px;">' +
		 '<img src="fig/style2/ots_taustapalkki_vasen.png"></div></td>' +
		 '<td style="background-image: url(fig/style2/ots_taustapalkki_keski.png);' +
		 'background-repeat: repeat-x;' +
		 'background-position: 0 17">' +
		 '<table border="0" cellspacing="0" cellpadding="0">' +
		 '<tr><td width="20" height="55" width="40"></td>' +
		 '<td style="background-image: url(fig/style2/ots_taustapallo.png); ' +
		 'background-repeat: no-repeat;' +
		 'background-position: 0 9;" valign="middle" align="left" width="50">' +
		 '<div style="margin-left: 7px;">' + 
		 '<img src="fig/style2/ots_' + kuvanow +  '.png">' +
		 '</div></td>' +
		 '<td width="20"></td><td valign="middle">' +
		 '<font color="white">' + teksti + '</font>' +
		 '</td><td width="20"></td></tr></table>' +
		 '</td>' +
		 '<td width="11" height="55" align="left" valign="top">' +
		 '<div style="margin-top: 17px;">' +
		 '<img src="fig/style2/ots_taustapalkki_oikea.png"></div></td></tr></table>');

}


// YLEINEN KLIKKAUKSESTA TULEVA TASOJEN VAIHTO
// pois = naytettavan id
// paalle = naytettavan id
function TasoVaihto(pois,paalle){
  document.getElementById(pois).style.visibility='hidden';
  document.getElementById(pois).style.display='none';
  document.getElementById(paalle).style.visibility='visible';
  document.getElementById(paalle).style.display='block';
}

// NÄYTTÄÄ TASON
function TasoShow(id,pos){
  document.getElementById(id).style.visibility='visible';
  if (arguments.length == 1){
    document.getElementById(id).style.display='block';
  }
  else {
    document.getElementById(id).style.position='absolute';
  }
}

// PIILOTTAA TASON
function TasoHide(id){
  document.getElementById(id).style.visibility='hidden';
  document.getElementById(id).style.display='none';
}
