function open_popup(osio,pvm,id) {
    if(osio=="mtv3+"){
    	var ohjtied = window.open("http://www.mtv3.fi/ohjelmat/ohjelmatiedot/popup.shtml/mtv3%20/"+pvm+"?"+id,"ohjelmatiedot","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=300,height=400");
    }
    else{
    	var ohjtied = window.open("http://www.mtv3.fi/ohjelmat/ohjelmatiedot/popup.shtml/"+osio+"/"+pvm+"?"+id,"ohjelmatiedot","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=300,height=400");
    }
    ohjtied.focus();
}

function open_popup_ojo(osio,pvm,id) {
    if(osio=="mtv3+"){
        var ohjtied = window.open("http://www.mtv3.fi/ohjelmat/ohjelmatiedot/popup_ojo.shtml/mtv3%20/"+pvm+"?"+id,"ohjelmatiedot","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=310,height=600");
    }
    else{
        var ohjtied = window.open("http://www.mtv3.fi/ohjelmat/ohjelmatiedot/popup_ojo.shtml/"+osio+"/"+pvm+"?"+id,"ohjelmatiedot","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=310,height=600");
    }
    ohjtied.focus();
}

function taustapopup() { 
    var taustapopup = window.open('http://www.mtv3.fi/suuriseikkailu/taustakuvat.shtml','taustakuvat','status=yes,scrollbars=no,width=850,height=650'); 
    taustapopup.focus(); 
} 

function korosta(laji) {
  var ohjelmisto = document.getElementById('ohjelmisto');
  var ohjelmistodiv = ohjelmisto.getElementsByTagName('div');
  var nappi = document.getElementById('korosta_'+laji);
  if (nappi.className.match('selected')) {
    nappi.className=nappi.className.replace('selected','');
    for (i=0; i<ohjelmistodiv.length; i++) {
      node = ohjelmistodiv[i];
      if (node.className.match(laji+'focus')) {
        node.className=node.className.replace(laji+'focus', laji);
      }
    }
  } else {
    nappi.className+='selected';
    for (i=0; i<ohjelmistodiv.length; i++) {
      node = ohjelmistodiv[i];
      if (node.className.match(laji)) {
        node.className=node.className.replace(laji, laji+'focus');
      }
    }
  }
}

function naytaseloste(itse) {
  var ohjelmisto = document.getElementById('ohjelmisto');
  var ohjelmistodiv = ohjelmisto.getElementsByTagName('div');
  if (itse.className.match('active')) {
    var nakyi = 'yes';
  } else {
    var nakyi = 'no';
  }
  for (i=0; i<ohjelmistodiv.length; i++) {
    node = ohjelmistodiv[i];
    if (node.className.match('active')) {
      node.className=node.className.replace(' active', '');
      jQuery(node).find(".seloste").slideUp("fast");
    }
  }
  if (nakyi == 'no') {
    itse.className+=' active';
    jQuery(itse).find(".seloste").slideDown("fast");
  }
}

function toggleMenneet() {
  var nappi2 = document.getElementById('tvopas_menneet');
  if (!nappi2.className.match('selected')) {
    document.getElementById('tvopas0400').style.display="";
    document.getElementById('tvopas1200').style.display="";
    document.getElementById('tvopas1500').style.display="";
    document.getElementById('tvopas1800').style.display="";
    document.getElementById('tvopas2100').style.display="";
    document.getElementById('tvopas2400').style.display="";
    nappi2.className+="selected";
  } else {
    if (1 == 1) {
      if (tunnit >= 12) {
        document.getElementById('tvopas0400').style.display="none";
      }
      if (tunnit >= 15) {
        document.getElementById('tvopas1200').style.display="none";
      }
      if (tunnit >= 18) {
        document.getElementById('tvopas1500').style.display="none";
      }
      if (tunnit >= 21) {
        document.getElementById('tvopas1800').style.display="none";
      }
      if (tunnit >= 0 && tunnit < 4) {
        document.getElementById('tvopas2100').style.display="none";
      }
    }
    nappi2.className=nappi2.className.replace("selected","");
  }
}

if (pathinfo.charAt(pathinfo.length-2) == '0') {
  var pvm_pv = pathinfo.charAt(pathinfo.length-1);
} else {
  var pvm_pv = pathinfo.substring(pathinfo.length-2,pathinfo.length);
}
if (pathinfo.charAt(pathinfo.length-4) == '0') {
  var pvm_kk = pathinfo.charAt(pathinfo.length-3);
} else {
  var pvm_kk = pathinfo.substring(pathinfo.length-4,pathinfo.length-2);
}
var pvm_vvvv = pathinfo.substring(pathinfo.length-8,pathinfo.length-4);

var linkityspvm = new Date();

linkityspvm.setFullYear(pvm_vvvv,pvm_kk-1,pvm_pv);
linkityspvm.setDate(linkityspvm.getDate()-1);
if (String(linkityspvm.getMonth()+1).length == 1) {
  linkityspvm_mon = '0'+(linkityspvm.getMonth()+1);
} else {
  linkityspvm_mon = linkityspvm.getMonth()+1;
}
if (String(linkityspvm.getDate()).length == 1) {
  linkityspvm_date = '0'+linkityspvm.getDate();
} else {
  linkityspvm_date = linkityspvm.getDate();
}
var pathinfo_edel = '/'+linkityspvm.getFullYear()+linkityspvm_mon+linkityspvm_date;

linkityspvm.setFullYear(pvm_vvvv,pvm_kk-1,pvm_pv);
linkityspvm.setDate(linkityspvm.getDate()+1);
if (String(linkityspvm.getMonth()+1).length == 1) {
  linkityspvm_mon = '0'+(linkityspvm.getMonth()+1);
} else {
  linkityspvm_mon = linkityspvm.getMonth()+1;
}
if (String(linkityspvm.getDate()).length == 1) {
  linkityspvm_date = '0'+linkityspvm.getDate();
} else {
  linkityspvm_date = linkityspvm.getDate();
}
var pathinfo_seur = '/'+linkityspvm.getFullYear()+linkityspvm_mon+linkityspvm_date;

jQuery(document).ready(function() {
  jQuery("#tvopas_datePicker").datepicker({
    firstDay: 1,
    dateFormat: 'dd.mm.yy',
    dayNamesMin: ['su','ma','ti','ke','to','pe','la'],
    monthNames: ['Tammikuu','Helmikuu','Maaliskuu','Huhtikuu','Toukokuu','Kes&auml;kuu','Hein&auml;kuu','Elokuu','Syyskuu','Lokakuu','Marraskuu','Joulukuu'], // Names of months for drop-down and formatting
    changeFirstDay: false,    
    changeMonth: false,
    changeYear: false,
    numberOfMonths: 2,
    prevText: 'Edellinen',
    nextText: 'Seuraava',
    currentText: 'T&auml;n&auml;&auml;n',
    hideIfNoPrevNext: true,
    minDate: 0,
    maxDate: 20,
    onSelect: function(date){
      y = date.substr(6,4).toString();
      m = date.substr(3,2).toString();
      d = date.substr(0,2).toString();
      location.href = osoite+'/'+y+m+d;
    }
  });

  jQuery("#tvopas_kal1").hover(function() {
    jQuery("#tvopas_kal2").show();
  }, function(){
  });

  jQuery("#tvopas_kal2").hover(function() {
  }, function(){
    jQuery(this).hide();
  });

  jQuery("#tvopas_piilolinkit").hide();
  
  jQuery("#ohjelmisto .ohjelma a.nimi").click(function() {
    naytaseloste(jQuery(this).parent().get(0));
    return false;
  });

});


