function OpenKontrwywiad() {
  w = window.open('/fakty/kontrwywiad-live.html', "RMFkontrwywiadWindow", 'width=415,height=363,menubar=no,toolbar=no,location=no,scrollbars=no,resizable=no,status=no');
  if (window.focus) w.focus();
}
function OpenGallery(id,p) {
  w = window.open('/fakty/gallery.html?id='+id+'&p='+p,'GalleryWindow','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=860,height=680');
  if (window.focus) w.focus();
}
function OpenMusicGallery(id,p) {
  w = window.open('/muzyka/bio/gallery.html?id='+id+'&p='+p,'GalleryWindow','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=620,height=585');
  if (window.focus) w.focus();
}
function OpenPic(id,p) {
  w = window.open('/fakty/pic.html?id='+id+'&img='+p,'PicWindow','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=860,height=700');
  if (window.focus) w.focus();
}
function OpenPicCurrentPath(id,p) {
  w = window.open('pic.html?id='+id+'&img='+p,'PicWindow','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=860,height=700');
  if (window.focus) w.focus();
}
function OpenPrint(id) {
  w = window.open('/fakty/print.html?id='+id,'PrintWindow','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=620,height=560,top=100,left=100');
  if (window.focus) w.focus();
}
function OpenMiastoMuzykiPlayer(s) {
  w = window.open('http://www.miastomuzyki.pl/play.html?id='+s, "RMFplayerWindow", 'width=468,height=512,menubar=no,toolbar=no,location=no,scrollbars=no,resizable=no,status=no');
  if (window.focus) w.focus();
}

function OpenKumulacjaRegulamin() {
  w = window.open('/akcje/kumulacja/regulamin.html', "RMFkumulacjaWindow", 'width=470,height=400,menubar=no,toolbar=no,location=no,scrollbars=yes,resizable=no,status=no');
  if (window.focus) w.focus();
}

function OpenStream(s) {
  window.location.href = s;
}

function createCookie(name,value,hours) {
  if (hours) {
    var date = new Date();
    date.setTime(date.getTime()+(hours*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for (var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function eraseCookie(name) {
  createCookie(name,"",-1);
}

function FlvLoadTel(n,doplay) {
  $('telewyk').update(Teledyski[n].w);
  $('teletyt').update(Teledyski[n].t);
  $('cliptel').loadFile({'file':'http://gruul.rmf.pl/teledyski/'+Teledyski[n].n+'.flv','image':'http://doc.rmf.pl/rmf_fm/teledyski_img/'+Teledyski[n].n+'.jpg'});
  //$('cliptel').callback = '/muzyka/glosuj.php?id='+Teledyski[n].id;
  if (doplay) {
    new Ajax.Request('/muzyka/glosuj.php', {  //?punktow=1%26id_radio=0%26type=teledyskplay%26id_type='.$songid
      method: 'get',
      parameters: { 'punktow':1, 'type':'teledyskrmf', 'id_type':Teledyski[n].id }
    });
    $('cliptel').sendEvent('playitem',1);
  }
}
function FlvMiniPic(n) {
  var telalt = (n+' '+Teledyski[n].w+': '+Teledyski[n].t).stripTags().strip();
  return '<A HREF="#" TITLE="'+telalt+'" onClick="FlvLoadTel('+n+',true);return false;" style="position: relative;"><img src="/muzyka/img/teledyski_strzalka.gif" style="position: absolute; margin-left: 42px;margin-top: 30px;" /><IMG BORDER=0 STYLE="margin:6px;" WIDTH=88 HEIGHT=66 '+
         'SRC="http://doc.rmf.pl/rmf_fm/teledyski_img_s/'+Teledyski[n].n+'.jpg" alt=""></A>';
}

function FlvTelList(start) {
  var telcnt = Teledyski.length;
  var xpre  = start>0 ? '<A HREF="#" onClick="FlvTelList('+(start-1)+');return false;"><IMG SRC="/inc/img/arleft.gif" STYLE="margin-bottom:27px;"></A>' : '<IMG SRC="/inc/img/arleft_dead.gif" WIDTH=8 HEIGHT=16 STYLE="margin-bottom:27px;">';
  var xpost = start<telcnt-3 ? '<A HREF="#" onClick="FlvTelList('+(start+1)+');return false;"><IMG SRC="/inc/img/arright.gif" STYLE="margin-bottom:27px;"></A>' : '<IMG SRC="/inc/img/arright_dead.gif" WIDTH=8 HEIGHT=16 STYLE="margin-bottom:27px;">';
  $('telelist').update(xpre+FlvMiniPic(start%telcnt)+FlvMiniPic((start+1)%telcnt)+FlvMiniPic((start+2)%telcnt)+xpost);
}

function FlvLoadMulti(n) {
	$('flvplayermultiID').loadFile({'file':Mfilms[n].file,'image':Mfilms[n].image});
	$('flvplayermultiID').sendEvent('playitem',1);
	if (Mfilms[n].desc != "") {
		$('flvplayermultiDesc').update(Mfilms[n].desc);
		$('flvplayermultiDesc').show();
	}
	else {
		$('flvplayermultiDesc').hide();
	}
}

function FlvMultiPic(n) {
  return '<A HREF="#" onClick="FlvLoadMulti('+n+');return false;" style="position: relative;"><img src="/muzyka/img/teledyski_strzalka.gif" style="position: absolute; margin-left: 42px;margin-top: 26px;" /><IMG BORDER=0 STYLE="margin:6px;" WIDTH=80 height="60" SRC="'+Mfilms[n].image+'"></A>';
}

function FlvMutliList(start) {
  var telcnt = Mfilms.length;
  var xpre  = start>0 ? '<A HREF="#" onClick="FlvMutliList('+(start-1)+');return false;"><IMG SRC="/inc/img/arleft_video.gif" STYLE="margin-bottom:27px;"></A>' : '<IMG SRC="/inc/img/arleft_dead.gif" WIDTH=8 HEIGHT=16 STYLE="margin-bottom:27px;">';
  var xpost = start<telcnt-3 ? '<A HREF="#" onClick="FlvMutliList('+(start+1)+');return false;"><IMG SRC="/inc/img/arright_video.gif" STYLE="margin-bottom:27px;"></A>' : '<IMG SRC="/inc/img/arright_dead.gif" WIDTH=8 HEIGHT=16 STYLE="margin-bottom:27px;">';
  $('flvplayermultiList').update(xpre+FlvMultiPic(start%telcnt)+FlvMultiPic((start+1)%telcnt)+FlvMultiPic((start+2)%telcnt)+xpost);
}

function $RR(aform,aname) {
  var valx = $(aform).getInputs('radio',aname).find(function(radio) { return radio.checked; });
  return valx==null ? '' : valx.value;
}

function gaTrackEvent(category,evt,data) {
  //console.log(category,evt,data);
  if (typeof pageTracker !== 'undefined') pageTracker._trackEvent(category,evt,data);
}

function RandomizeMMLogo() {
  $('mmStacje').selectedIndex = Math.floor($('mmStacje').options.length * Math.random());
  UpdateMMLogo();
}

function UpdateMMLogo() {
  var selRadio = $F('mmStacje');   
  $('mmStacjeImage').src = '/inc/img/mmlogos/'+$('opt'+selRadio).readAttribute('rname')+'.jpg';
  //$('mmStacjeHref').href = 'http://www.miastomuzyki.pl/radio,'+selRadio;
}

function OpenMMPlayer() {
  var selRadio = $F('mmStacje');   
  OpenMiastoMuzykiPlayer(selRadio);
}
