function urlencode(q) {
	q=q.replace(/\//g,"%2F");
	q=q.replace(/\+/g,"%2B");
	q=q.replace(/\s/g,"+");
  return q;
}

var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
var flashvars=new String();
// Handle all the the FSCommand messages in a Flash movie
function walentynkaflash_doFSCommand(command, args) {
  var walentynkaflash = InternetExplorer ? walentynkaflash : document.walentynkaflash;
  document.getElementById('fscommandvars').value=args;
}

function ns_enc(q) {
	q=q.replace(/[^\w\+\-\"\';ęóąśżźćńłĘÓĄŚŁŻŹĆŃ]/g," ");
	q=q.replace(/#/g,"%23%23");
	q=q.replace(/ę/g,"%23e");
	q=q.replace(/ó/g,"%23o");
	q=q.replace(/ą/g,"%23a");
	q=q.replace(/ś/g,"%23s");
	q=q.replace(/ż/g,"%23z");
	q=q.replace(/ź/g,"%23x");
	q=q.replace(/ć/g,"%23c");
	q=q.replace(/ń/g,"%23n");
	q=q.replace(/ł/g,"%23l");
	q=q.replace(/Ę/g,"%23E");
	q=q.replace(/Ó/g,"%23O");
	q=q.replace(/Ą/g,"%23A");
	q=q.replace(/Ś/g,"%23S");
	q=q.replace(/Ż/g,"%23Z");
	q=q.replace(/Ź/g,"%23X");
	q=q.replace(/Ć/g,"%23C");
	q=q.replace(/Ń/g,"%23N");
	q=q.replace(/Ł/g,"%23L");
	q=q.replace(/\+/g,"%23p");
	q=q.replace(/\-/g,"%23m");
	q=q.replace(/\"/g,"%23v");
	q=q.replace(/\'/g,"%23b");
	q=q.replace(/;/g,"%23k");
	return q;
}

function ns_go_to_results(loc, rpp) {
	var elem = document.getElementById('SearchKeywords').value;
	if (elem == null) {
		elem = "";
	}
	document.cookie='ns_query='+ns_enc(elem);
	document.cookie='rpp=1'+rpp;
	window.location=loc;
}


function changebg()
{
  flashvars=flashvars.replace(/filelayer=.*?&/,'filelayer='+urlencode('http://www.express.bydgoski.pl/ekartki/'+this.value.replace(/\.jpg/,'.png'))+'&');
  var fotodiv=document.getElementById('fotomontazdiv');
    if(window.addEventListener)
        fotodiv.innerHTML='<p'+'>Możesz dowolnie przesuwać zdjęcie klikając lewym przyciskiem myszy na obrazek i przeciągając je w odpowiednie miejsce</p'+'>'+ 
              '<object id="walentynkaflash" name="walentynkaflash" type="application/x-shockwave-flash" data="/ekartki/walentynki.swf?'+flashvars+'" width="520" height="520" title="Walentynka w gazecie"'+'>'+
              '<PARAM NAME=movie VALUE="/ekartki/walentynki.swf?'+flashvars+'"'+'>'+
//              '<PARAM NAME="allowScriptAccess" VALUE="always">'+
              '<PARAM NAME=quality VALUE="high">'+
              '<PARAM NAME=bgcolor VALUE="#FFFFFF">'+
              '</OBJECT>';
    else
        fotodiv.innerHTML='<p'+'>Możesz dowolnie przesuwać zdjęcie klikając lewym przyciskiem myszy na obrazek i przeciągając je w odpowiednie miejsce</p'+'>'+
                "<"+"OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" id=\"walentynki\" name=\"walentynki\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" WIDTH=\"520\" HEIGHT=\"520\""+">"+
              '<PARAM NAME=movie VALUE="/ekartki/walentynki.swf?'+flashvars+'"'+'>'+
//              '<PARAM NAME="allowScriptAccess" VALUE="always">'+
              '<PARAM NAME=quality VALUE="high">'+
              '<PARAM NAME=bgcolor VALUE="#FFFFFF">'+
              '</OBJECT>';
}

var prepare_menu_content=new Array();
var done=new Array();

function change_menu_content(id,tag,ile,typ)
{
  document.cookie=id+ "=" +escape(tag);
  if(prepare_menu_content[id][tag].length<5)
  {
    var cont=document.getElementById(id+'_content');
    prepare_menu_content[id][tag]='<p style="text-align: center; padding: 20px 0 20px 0;"><img src="/img/wait.gif" alt="Czekaj..."></p>';
  	var chroot=getOpisik();
  	chroot.onreadystatechange=function()
            {
    					if(chroot.readyState == 4 && chroot.status == 200)
    					{
    						if(chroot.responseText != null)
    						{
    						  var wwwdir='';
  							  prepare_menu_content[id][tag]=chroot.responseText;
  							  done[id][tag]=true;
    							     //alert(prepare_menu_content[id][tag]);
//                  cont.innerHTML=prepare_menu_content[id][tag];
                  
  				   		}
    				 	} else if (chroot.readyState == 4 && chroot != 200)
    					{
    					} else
    					{
    					}
  				}
  	if(typ=='magazyn')
    	chroot.open("POST", "/lukasz/getmag.php?id="+tag+"&ile="+ile);
  	else if(typ=='sport')
    	chroot.open("POST", "/lukasz/getarticlelist3.php?id="+tag+"&ile="+ile);
    else
    	chroot.open("POST", "/lukasz/getarticlelist2.php?id="+tag+"&ile="+ile);
  	chroot.send(null);
    hide(id+'_content',id,tag);
  }else
  {
    hide(id+'_content',id,tag);
//    document.getElementById(id+'_content').innerHTML=prepare_menu_content[id][tag];
  }
}

function expandcollapse(id)
{
  var kont=document.getElementById(id);
  var ul=kont.parentNode.parentNode;
  var kont2=ul.parentNode;
  if(kont.style.display=="none")
  {
    kont.style.display="block";
    kont2.style.height=ul.offsetHeight+"px";
  } else
  {
    kont.style.display="none";
    kont2.style.height=ul.offsetHeight+"px";
  }
}

function __afterShow(i,id,tag)
{
}

function __afterHide(i,id,tag)
{
  if(done[id][tag])
  {
    var cont=document.getElementById(i);
    cont.innerHTML=prepare_menu_content[id][tag];
    timestamphide[id]=null;
    var asa=cont.getElementsByTagName('a');
    for(j=0;j<asa.length;j++)
    {
      var a_exmag=asa[j].id.match(/a_exmag_(\d+)/);
      if(a_exmag)
      {
        asa[j].myid=a_exmag[1];
//        document.getElementById('div_exmag_'+a_exmag[1]).style.height="0px";
        asa[j].onclick=function(e)
        {
          if(e==undefined)
            e=window.event;
          if((e.preventDefault)&&(e.cancellable))
            e.preventDefault();
          expandcollapse('div_exmag_'+this.myid);
          return false;
        }
      }
    }
    kontener[id]=document.getElementById(i);
    kont2=kontener[id].firstChild;
    while(kont2.nodeName.match(/text/)) kont2=kont2.nextSibling;
    kontener[id].curH=kontener[id].offsetHeight;
    kontener[id].toH=kont2.offsetHeight;
    resize(i,id,tag);
  } else
    timestamphide[id]=setTimeout("__afterHide('"+i+"','"+id+"',"+tag+")",mytime);
}

var kont2;

function __afterResize(i,id,tag)
{
    show(i,id,tag);
}

var maxFrames=5;
var fps=50;
var animation=new Array();

var mytime=Math.round(1000/fps);
var currentFrame=new Array();
var kontener=new Array();

var curtag;
var curid;

var timestampshow=new Array();
var timestamphide=new Array();
var timestampresize=new Array();

function show(i1,id,tag)
{
  var what=document.getElementById(i1);
  var opacity=Math.ceil(currentFrame[id]*100/maxFrames);
  if(opacity>=100)
  {
    opacity=100;
    timestampshow[id]=clearInterval2(timestampshow[id]);
    currentFrame[id]=0;
    animation[id]=false;
    if(__afterShow)
      __afterShow(i1,id,tag);
  }else if(animation[id]==false)
  {
    timestampshow[id]=setInterval("show('"+i1+"','"+id+"',"+tag+")",mytime);
    animation[id]=true;
  }
  if(what)
  {
    var op=opacity/100;
    with(what)
    {
      style.opacity = op;
      style.MozOpacity = op;
      style.KhtmlOpacity = op;
      style.filter = "alpha(opacity=" + (opacity) + ")";
      if(opacity==100)
        try{ what.style.removeAttribute("filter"); } catch(err) {}
    }
    currentFrame[id]++;
  }
}

function resize(i1,id,tag)
{
  var tosize=Math.ceil(((kontener[id].toH-kontener[id].curH)/maxFrames)*currentFrame[id]);
  if((currentFrame[id]>=maxFrames)||(kontener[id].toH==kontener[id].curH))
  {
    animation[id]=false;
    if(timestampresize[id]);
      timestampresize[id]=clearInterval2(timestampresize[id]);
    kontener[id].style.height=kontener[id].toH+"px";
    currentFrame[id]=0;
    if(__afterResize)
      __afterResize(i1,id,tag);
  } else if(animation[id]==false)
  {
    timestampresize[id]=setInterval("resize('"+i1+"','"+id+"',"+tag+")",mytime);
    animation[id]=true;
  }
  if(kontener[id].toH!=kontener[id].curH)
    currentFrame[id]++;
  kontener[id].style.height=(kontener[id].curH+tosize)+"px";
}

function clearInterval2(interval)
{
  clearInterval(interval);
  return null;
}

function hide(i1,id,tag)
{
  var what=document.getElementById(i1);
  var opacity=Math.ceil((maxFrames-currentFrame[id])*100/maxFrames);
  if(opacity<=0)
  {
    animation[id]=false;
    opacity=0;
    timestamphide[id]=clearInterval2(timestamphide[id]);
    currentFrame[id]=0;
    if(__afterHide)
      __afterHide(i1,id,tag);
  }else if(animation[id]==false)
  {
    timestamphide[id]=setInterval("hide('"+i1+"','"+id+"',"+tag+")",mytime);
    animation[id]=true;
  }
  if(what)
  {
    var op=opacity/100;
    with(what)
    {
      style.opacity = op;
      style.MozOpacity = op;
      style.KhtmlOpacity = op;
      style.filter = "alpha(opacity=" + (opacity) + ")";
    }
    currentFrame[id]++;
  }
}


function prepare_menu(id,ile,typ)
{
  if(ile == undefined)
    ile=10;
  if(typ == undefined)
    typ='normal';
  prepare_menu_content[id]=new Array();
  done[id]=new Array();
  animation[id]=false;
  kontener[id]=null;
  timestampshow[id]=null;
  timestamphide[id]=null;
  timestampresize[id]=null;
  currentFrame[id]=0;
  var ulmenu=document.getElementById(id);
  if(ulmenu)
  {
    var as=ulmenu.getElementsByTagName('a');
    var cont=document.getElementById(id+'_content');
    for(i=0;i<as.length;i++)
    {
      tagarr=as[i].href.match(/ls=(\d+)/);
      tag=tagarr[1];
      if(as[i].className=="selected")
      {
        prepare_menu_content[id][tag]=cont.innerHTML;
        done[id][tag]=true;
      }
      else
        prepare_menu_content[id][tag]='';
      as[i].tagnr=tag;
      as[i].menuid=id;
      as[i].ile=ile;
      as[i].typ=typ;
      as[i].onclick=function(e)
      {
        if(e==undefined)
          e=window.event;
        if((e.preventDefault)&&(e.cancellable))
          e.preventDefault();
        if((this.className!="selected")&&(!timestampshow[id])&&(!timestamphide[id])&&(!timestampresize[id]))
        {
          change_menu_content(this.menuid,this.tagnr,this.ile,this.typ);
          var as=document.getElementById(this.menuid).getElementsByTagName('a');
          for(i=0;i<as.length;i++)
            as[i].className="";
          this.className="selected";
        }
        return false;
      }
    }
    var asa=cont.getElementsByTagName('a');
    for(j=0;j<asa.length;j++)
    {
      var a_exmag=asa[j].id.match(/a_exmag_(\d+)/);
      if(a_exmag)
      {
        asa[j].myid=a_exmag[1];
//        document.getElementById('div_exmag_'+a_exmag[1]).style.height="0px";
        asa[j].onclick=function(e)
        {
          if(e==undefined)
            e=window.event;
          if((e.preventDefault)&&(e.cancellable))
            e.preventDefault();
          expandcollapse('div_exmag_'+this.myid);
          return false;
        }
      }
    }
  }
}

function NGTDHeight()
{
	// zrownanie
	var td=document.getElementById('tematdniaglowna');
	var ng=document.getElementById('nagoracoglowna');
	if((td)&&(ng))
	{
	  //uwzglednienie obramowania 2x1px
		if(td.offsetHeight>ng.offsetHeight)
			ng.style.height=(td.offsetHeight-2)+'px';
		else
			td.style.height=(ng.offsetHeight-2)+'px';
	}
}

function myonload()
{
// ------------------------ fotomontaż - kartki
  var fotodiv=document.getElementById('fotomontazdiv');
  if(fotodiv)
  {
 //   fotodiv.innerHTML='';
    fotodiv.style.width="520px";
    fotodiv.style.height="590px";
    fotodiv.style.margin="0 auto 0 auto";
    var fobrazek='';
    var inputOBR=document.getElementsByTagName('input');
    for (var i=0; i<inputOBR.length; i++) if (inputOBR[i].name=='obrazek')
    {
      if(fobrazek.length==0)
        fobrazek=inputOBR[i].value;
      if(inputOBR[i].checked)
        fobrazek=inputOBR[i].value;
      inputOBR[i].onclick=changebg;
    }
    fobrazek=fobrazek.replace(/\.jpg$/,'.png');
    flashvars='filelayer='+urlencode('http://www.express.bydgoski.pl/ekartki/'+fobrazek);
    var fotomontaz=urlencode(document.getElementById('fotomontaz').src);
    flashvars+='&amp;filejpeg='+fotomontaz;
    var vararr=document.getElementById('fscommandvars').value.split(';');
    for(i=0;i<(vararr.length-1);i++)
    {
      if(!vararr[i].match(/=undefined/))
        flashvars+='&amp;'+vararr[i];
    }
    if(window.addEventListener)
        fotodiv.innerHTML='<p'+'>Możesz dowolnie przesuwać zdjęcie klikając lewym przyciskiem myszy na obrazek i przeciągając je w odpowiednie miejsce</p'+'>'+
              '<object id="walentynkaflash" name="walentynkaflash" type="application/x-shockwave-flash" data="/ekartki/walentynki.swf?'+flashvars+'" width="520" height="520" title="Walentynka w gazecie"'+'>'+
              '<PARAM NAME=movie VALUE="/ekartki/walentynki.swf?'+flashvars+'"'+'>'+
//              '<PARAM NAME="allowScriptAccess" VALUE="always">'+
              '<PARAM NAME=quality VALUE="high">'+
              '<PARAM NAME=bgcolor VALUE="#FFFFFF">'+
              '<p>Walentynka w gazecie</p>'+
              '</OBJECT>';
    else
        fotodiv.innerHTML='<p'+'>Możesz dowolnie przesuwać zdjęcie klikając lewym przyciskiem myszy na obrazek i przeciągając je w odpowiednie miejsce</p'+'>'+
              "<"+"OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" id=\"walentynki\" name=\"walentynki\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" WIDTH=\"520\" HEIGHT=\"520\""+">"+
              '<PARAM NAME=movie VALUE="/ekartki/walentynki.swf?'+flashvars+'"'+'>'+
//              '<PARAM NAME="allowScriptAccess" VALUE="always">'+
              '<PARAM NAME=quality VALUE="high">'+
              '<PARAM NAME=bgcolor VALUE="#FFFFFF">'+
              '</OBJECT>';
 }
}

function getOpisik()
{
	var opisik=false;
	try
	{
		opisik = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e)
	{
		try
		{
			opisik = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E)
		{
			opisik = false;
		}
	}

	if (!opisik && typeof XMLHttpRequest!='undefined')
	{
		try
		{
			opisik = new XMLHttpRequest();
		} catch (e)
		{
			opisik=false;
		}
	}
	if (!opisik && window.createRequest)
	{
		try
		{
			opisik = window.createRequest();
		} catch (e)
		{
			opisik=false;
		}
	}
	return opisik;
}

if (window.attachEvent) window.attachEvent('onload', myonload);
if (window.addEventListener) window.addEventListener('load', myonload,false);

