<!-- //

function PowiekszZdjecie(url, width, height, info, tytul)
{
	var okno = null;
	if(okno) okno.close();
	ScrWidth = 640;
	ScrHeight = 480;
	if(window.screen)
	{
		ScrWidth = window.screen.width;
		ScrHeight = window.screen.height;
	}
	PosX = Math.round((ScrWidth - width) / 2);
	PosY = Math.round((ScrHeight - height) / 2);
	width = width;
	height = height;
	okno = window.open("", "zdjecie", "menubar=no,toolbar=no,location=no,directories=no,status=yes,scrollbars=no,resizable=no,copyhistory=no,width=" + width + ",height=" + height + ",left=" + PosX + ",top=" + PosY);
	okno.document.clear();
	okno.document.write("<html><head><title>" + tytul + "</title><meta http-equiv='content-type' content='text/html; charset=ISO-8859-2'></head><style type=\"text/css\">body { margin:0; padding:0; }</style><body><div align=\"center\"><img src=\""+ url +"\" alt=\"" + info + "\" title=\"" + info + "\" border=\"0\" onclick=\"window.close();\" /></div></body></html>");
	okno.document.close();
	okno.focus();
}

function SprawdzFormularzKontaktu(msg1,msg2)
{
	var form = document.forms["FormularzKontaktu"];
	var error = false;
	if(form.elements["imie_i_nazwisko"].value == "")
	{
		alert(msg1);
		form.elements["imie_i_nazwisko"].focus();
		return false;
	}
	if(!error && form.elements["email"].value == "")
	{
		alert(msg1);
		form.elements["email"].focus();
		return false;
	}
	if(!error && form.elements["email"].value != "")
	{
		if(!SprawdzEmail(form.elements["email"]))
		{
			alert(msg2);
			form.elements["email"].focus();
			return false;
		}
	}
	if(!error && form.elements["tresc"].value == "")
	{
		alert(msg1);
		form.elements["tresc"].focus();
		return false;
	}

	return true;
}

function SprawdzEmail(adres)
{
	a = adres.value.search(/@/i);
	a1 = adres.value.substring(0,a);
	a2 = a1.length;
	a = a + 1;
	b = adres.value.indexOf(".");
	b1 = adres.value.substring(a,b);
	b2 = b1.length;
	b = b + 1;
	c = adres.value.length;
	c1 = adres.value.substring(b,c);
	c2 = c1.length;
	if(adres.value.indexOf("@") != "-1" && adres.value.indexOf(".") != "-1" && a2 >= 1 && b2 >= 1 && c2 >= 1)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function Drukuj(podstrona_id,akcja,q,akt_id)
{
	var okno = null;
	okno = window.open("/drukuj.php?pod_id="+podstrona_id+"&action="+akcja+"&q="+q+"&akt_id="+akt_id+"", "wersja_do_druku", "menubar=no,toolbar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=no,copyhistory=no,width=600,height=600,left=50,top=50");
	okno.focus();
}
function $_(id)
{
	return document.getElementById(id);
}


function zaloguj()
{
	var email 		= $_('l_email').value;
	var password 	= $_('l_haslo').value;

	if(SprawdzEmail($_('l_email')))
	{
		if(password!='')
		{
			advAJAX.get({
				url: "/include/ajax_logowanie.php?e="+email+"&p="+password,
				onLoading : function(obj)
				{$_('pasek_konta_err').innerHTML= 'trwa weryfikacja danych';},
				onSuccess : function(obj) {
					if(obj.responseText=="true")
					{
						//alert('test');
						window.location=window.location;
					}else
					{
						$_('pasek_konta_err').innerHTML="Błędny adres email lub hasło";
					} },
					onError : function(obj) { alert("Error: " + obj.status); }
			});
		}else
		{
			$_('pasek_konta_err').innerHTML= 'podaj hasło';
		}
	}else
	{
		$_('pasek_konta_err').innerHTML= ' wpisz poprawny adres email';
	}
}
function zaloguj_oferent()
{
	var email 		= $_('l_email').value;
	var password 	= $_('l_haslo').value;

	if(SprawdzEmail($_('l_email')))
	{
		if(password!='')
		{
			advAJAX.get({
				url: "/include/ajax_logowanie_oferent.php?e="+email+"&p="+password,
				onLoading : function(obj)
				{$_('pasek_konta_err').innerHTML= 'trwa weryfikacja danych';},
				onSuccess : function(obj) {
					if(obj.responseText=="true")
					{
						var strURL = window.location.pathname;
						var regExp = /wyloguj/;
						var match = strURL.search(regExp);
						if(match!=-1)
						window.location = window.location.protocol + "//" + window.location.host
						else
						window.location=window.location;

					}else
					{
						$_('pasek_konta_err').innerHTML="Błędny adres email lub hasło";
					} },
					onError : function(obj) { alert("Error: " + obj.status); }
			});
		}else
		{
			$_('pasek_konta_err').innerHTML= 'podaj hasło';
		}
	}else
	{
		$_('pasek_konta_err').innerHTML= ' wpisz poprawny adres email';
	}
}

var pozycje = new Array();
var tmpDaty = new Array();

function sprawdz_pozycje_koszyka(forma_reklamy_id,harmonogram_id)
{
	//alert(forma_reklamy_id+''+harmonogram_id);
	if(!pozycje[forma_reklamy_id])
	{
		pozycje[forma_reklamy_id] = new Array;
		pozycje[forma_reklamy_id][harmonogram_id]=0;
	}

	if(pozycje[forma_reklamy_id][harmonogram_id]==1)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function odswiez_pozycje_koszyka(forma_reklamy_id)
{
	if(forma_reklamy_id=='')
	{
		$_('harmonogram').style.display='none';
	}else
	{
		$_('harmonogram').style.display='';

		var pozReklama = pozycje[forma_reklamy_id];
		for(i=0;i<tmpDaty.length;i++)
		{
			if($_('poz_'+i))
			{
				$_('poz_'+i).style.backgroundColor='#FFFFFF';
			}
		}
		for(i=0;i<pozReklama.length;i++)
		{
			if($_('poz_'+i))
			{
				if(pozReklama[i]==1)
				{
					$_('poz_'+i).style.backgroundColor='#D3D3D3';
				}
			}
		}
	}

}
function odswiez_wybrane_pozycje()
{
	var ile =0;
	var tmpIle =0;

	$_('wybrane_pozycje').innerHTML='';
	for(i=0;i<pozycje.length;i++)
	{
		if(pozycje[i]!=undefined)
		{
			var formyreklam = $_('forma_reklamy').options;
			var nazwa = '';
			for(var j=0;j<formyreklam.length;j++)
			{
				if(formyreklam[j])
					if(formyreklam[j].value==i)	nazwa = formyreklam[j].text;
			}
			var daty= pozycje[i];
			if(daty.length>0)
			{
				//$_('wybrane_pozycje').innerHTML+='<div class="forma" >'+nazwa+':</div>';
				var strDaty ='';
				tmpIle =0;
				for(var k=0;k<daty.length;k++)
				{
					if(daty[k]==1){strDaty+=$_('poz_'+k).innerHTML;ile++;tmpIle++;}
					else pozycje[i][k]='';
				}
				if(tmpIle>0)$_('wybrane_pozycje').innerHTML += '<div class="forma" >'+nazwa+':</div>'+'<div class="daty">'+strDaty+'</div>';
			}
		}else
		{
			pozycje[i]= new Array('');
		}
	}
	if(ile>0) $_('do_koszyka').style.display='';
	else  $_('do_koszyka').style.display='none';

	$_('strPozycje').value= toJsonString(pozycje);
}


function CheckValidEmail(adres)
{
   a = adres.search(/@/i);
   a1 = adres.substring(0,a);
   a2 = a1.length;
   a = a + 1;
   b = adres.indexOf(".");
   b1 = adres.substring(a,b);
   b2 = b1.length;
   b = b + 1;
   c = adres.length;
   c1 = adres.substring(b,c);
   c2 = c1.length;
   if(adres.indexOf("@") != "-1" && adres.indexOf(".") != "-1" && a2 >= 1 && b2 >= 1 && c2 >= 1)
   {
   	return true;
   }
   else
   {
   	return false;
   }
}

function Newsletter(lang,newsletter_action,msg1,msg2,msg3,msg4,msg5)
{


	if(!CheckValidEmail(jQuery('#newsletter_email').val()))
	{
		jQuery('#newsletter_info').html(msg1);
		jQuery('#newsletter_email').focus();
	}
	else
	{
		jQuery('#newsletter_info').html(msg2);
		jQuery.get("ajax/newsletter.php?lang="+lang, { e: jQuery('#newsletter_email').val(), a: newsletter_action },
		function(data)
		{
			if(data == "true") jQuery('#newsletter_all').html(msg3);
			else if(data == "exists" || data == "notexists") jQuery('#newsletter_all').html(msg5);
			else jQuery('#newsletter_all').html(msg4);
  		}

		);
	}
}
//HARMONOGRAM
function aktywujWiersz(id)
{
	$_('h_nr_'+id).readOnly=false;
	$_('h_nr_'+id).style.backgroundColor='#FFFFFF';
	$_('h_dpz_'+id).readOnly=false;
	$_('h_dpz_'+id).style.backgroundColor='#FFFFFF';
	$_('h_dm_'+id).readOnly=false;
	$_('h_dm_'+id).style.backgroundColor='#FFFFFF';
	$_('h_dmg_'+id).readOnly=false;
	$_('h_dmg_'+id).style.backgroundColor='#FFFFFF';

	$_('h_ds_'+id).readOnly=false;
	$_('h_ds_'+id).style.backgroundColor='#FFFFFF';
	$_('h_a_'+id).disabled=false;
	$_('h_a_'+id).style.backgroundColor='#FFFFFF';
	$_('h_e_'+id).style.display='none';
	$_('h_s_'+id).style.display='';
	$_('h_c_'+id).style.display='';
	$_('h_d_'+id).style.display='';
}

function anulujWiersz(id)
{
	$_('h_nr_'+id).value=pozycje[id].numer;
	$_('h_nr_'+id).readOnly=true;
	$_('h_nr_'+id).style.backgroundColor='#F5F5F4';

	$_('h_dpz_'+id).value=pozycje[id].data_przyjecia_zlecenia;
	$_('h_dpz_'+id).readOnly=true;
	$_('h_dpz_'+id).style.backgroundColor='#F5F5F4';

	$_('h_dm_'+id).value=pozycje[id].data_materialy_do_opracowania;
	$_('h_dm_'+id).readOnly=true;
	$_('h_dm_'+id).style.backgroundColor='#F5F5F4';

	$_('h_dmg_'+id).value=pozycje[id].data_materialy_gotowe;
	$_('h_dmg_'+id).readOnly=true;
	$_('h_dmg_'+id).style.backgroundColor='#F5F5F4';


	$_('h_ds_'+id).value=pozycje[id].data_sprzedazy;
	$_('h_ds_'+id).readOnly=true;
	$_('h_ds_'+id).style.backgroundColor='#F5F5F4';

	$_('h_a_'+id).value=pozycje[id].aktywny;
	$_('h_a_'+id).disabled=true;
	$_('h_a_'+id).style.backgroundColor='#F5F5F4';

	$_('h_e_'+id).style.display='';
	$_('h_s_'+id).style.display='none';
	$_('h_c_'+id).style.display='none';
	$_('h_d_'+id).style.display='none';
}

function zapiszWiersz(id)
{
	pozycje[id].numer = $_('h_nr_'+id).value;
	$_('h_nr_'+id).readOnly=true;
	$_('h_nr_'+id).style.backgroundColor='#F5F5F4';

	pozycje[id].data_przyjecia_zlecenia = $_('h_dpz_'+id).value;
	$_('h_dpz_'+id).readOnly=true;
	$_('h_dpz_'+id).style.backgroundColor='#F5F5F4';

	pozycje[id].data_materialy_do_opracowania = $_('h_dm_'+id).value;
	$_('h_dm_'+id).readOnly=true;
	$_('h_dm_'+id).style.backgroundColor='#F5F5F4';

	pozycje[id].data_materialy_gotowe = $_('h_dmg_'+id).value;
	$_('h_dm_'+id).readOnly=true;
	$_('h_dm_'+id).style.backgroundColor='#F5F5F4';



	pozycje[id].data_sprzedazy = $_('h_ds_'+id).value;
	$_('h_ds_'+id).readOnly=true;
	$_('h_ds_'+id).style.backgroundColor='#F5F5F4';

	pozycje[id].aktywny = $_('h_a_'+id).checked?1:0;
	$_('h_a_'+id).disabled=true;
	$_('h_a_'+id).style.backgroundColor='#F5F5F4';

	$_('h_e_'+id).style.display='';
	$_('h_s_'+id).style.display='none';
	$_('h_c_'+id).style.display='none';
	$_('h_d_'+id).style.display='none';
	posortujPozycje()
	wyswietlHarmonogram();

}

function dodajWiersz()
{
	id = pozycje.length;

	pozycje[id]= {"id":"","czasopismo_id":"","numer":"","data_sprzedazy":"","data_przyjecia_zlecenia":"","data_materialy_do_opracowania":"","data_inserty":"","aktywny":""};
	pozycje[id].numer = $_('h_nr').value;

	pozycje[id].data_przyjecia_zlecenia = $_('h_dpz').value;
	pozycje[id].data_materialy_do_opracowania = $_('h_dm').value;
	pozycje[id].data_materialy_gotowe = $_('h_dmg').value;

	pozycje[id].data_sprzedazy = $_('h_ds').value;
	pozycje[id].aktywny = $_('h_a').checked?1:0;
	posortujPozycje();
	wyswietlHarmonogram();
}

function usunWiersz(id)
{
	pozycje[id]=undefined;
	posortujPozycje();
	wyswietlHarmonogram();
}
function wyswietlHarmonogram()
{
	var tab = $_('tblHarmonogram').innerHTML='';
	var strHTML = '';
	strHTML = '<table  cellspacing="0" width="796" ><tr><th class="lista_tlo" width="60" >numer</th><th class="lista_tlo" width="70" >przyjecie zlec.</th><th class="lista_tlo" width="70" >mat. do opr.</th><th class="lista_tlo" width="70" >mat. gotowe.</th><th class="lista_tlo" width="70" >data sprzedazy</th><th class="lista_tlo" width="55" >aktywny</th><th class="lista_tlo"  >operacja</th><tr>';
	for (var j = 0; j < pozycje.length; j++) {
		if(pozycje[j])
		{
			strHTML += '<tr><td class="lista_tlo" width="60" ><input type="text" class="lista_tlo_pole data" readonly id="h_nr_'+j+'" value="'+pozycje[j].numer+'" style="width:70px;" /></td><td class="lista_tlo" ><input type="text" class="lista_tlo_pole" readonly id="h_dpz_'+j+'" value="'+pozycje[j].data_przyjecia_zlecenia+'" style="width:70px;" /></td><td class="lista_tlo" ><input type="text" class="lista_tlo_pole" readonly id="h_dm_'+j+'" value="'+pozycje[j].data_materialy_do_opracowania+'" style="width:70px;" /></td><td class="lista_tlo" ><input type="text" class="lista_tlo_pole" readonly id="h_dmg_'+j+'" value="'+pozycje[j].data_materialy_gotowe+'" style="width:70px;" /></td><td class="lista_tlo" ><input type="text" class="lista_tlo_pole" readonly id="h_ds_'+j+'" value="'+pozycje[j].data_sprzedazy+'" style="width:70px;" /></td><td class="lista_tlo" ><input type="checkbox" class="lista_tlo_pole" disabled id="h_a_'+j+'" value="1" '+(pozycje[j].aktywny=="1"?' checked="checked" ':'')+' style="width:15px;"  /></td><td class="lista_tlo" ><input type="button" class="lista_tlo_pole" id="h_e_'+j+'" value="edytuj" onclick="aktywujWiersz('+j+')" /><input type="button" style="display:none;width:50px;background: red;" class="lista_tlo_pole" id="h_s_'+j+'" value="zapisz" onclick="zapiszWiersz('+j+')" /><input type="button" style="display:none;width:50px" class="lista_tlo_pole" id="h_c_'+j+'" value="anuluj" onclick="anulujWiersz('+j+')" /><input type="button" style="display:none;width:50px" class="lista_tlo_pole" id="h_d_'+j+'" value="usun" onclick="usunWiersz('+j+')" /><td></tr>';
		}
	}
	strHTML += '<tr><td class="lista_tlo" ><input type="text" class="lista_tlo_pole_aktywne"  id="h_nr" value="" style="width:70px;" /></td><td class="lista_tlo" ><input type="text" class="lista_tlo_pole_aktywne data"  id="h_dpz" value="" style="width:70px;" /></td><td class="lista_tlo" ><input type="text" class="lista_tlo_pole_aktywne"  id="h_dm" value="" style="width:70px;" /></td><td class="lista_tlo" ><input type="text" class="lista_tlo_pole_aktywne"  id="h_dmg" value="" style="width:70px;" /></td><td class="lista_tlo" ><input type="text" class="lista_tlo_pole_aktywne"  id="h_ds" value="" style="width:70px;" /></td><td class="lista_tlo" ><input type="checkbox" class="lista_tlo_pole"	 id="h_a" value="1"  style="width:15px;"  /></td><td class="lista_tlo" ><input type="button" class="lista_tlo_pole" id="h_e" value="dodaj" onclick="dodajWiersz()" /><td></tr></table>';
	$_('tblHarmonogram').innerHTML = strHTML;
	$_('strHarmonogram').value= toJsonString(pozycje);
	jQuery("iCennik_11").mask("9999-99-99");
}

function posortujPozycje()
{
	function sortData(a, b)
	{
		a= parseInt(a.data_sprzedazy.replace("-",""));
		b= parseInt(b.data_sprzedazy.replace("-",""));
	   if(a > b)
	      return 1
	   if(a < b)
	      return -1
	   return 0
	}
pozycje = pozycje.sort(sortData);
}

function BullStatistic()
{
	var colorDepth = window.screen.colorDepth;
	var res = window.screen.width + "," + window.screen.height;
	var referer = escape(document.referrer);
	document.write('<img src="/statystyka/zlicz.php?colors=' + colorDepth + '&resolution=' + res + '&referer=' + referer + '" style="width:0;height:0;" />');
}

function showMap()
{
	jQuery('#wyszukiwarka_lokalizacja').show("slow");
}
function hideMap()
{
	jQuery('#wyszukiwarka_lokalizacja').hide("slow");
}

function PokazPrzedstawicieli(id,zaznaczone)
{
	jQuery.get("/ajax/powiaty.php",'woj='+id+zaznaczone,function (data){jQuery('#wyszukiwarka_lokalizacja_powiaty').html(data)})
}

      function toJsonString(o)
      {
          var UNDEFINED
          switch (typeof o) {
              case 'string': return '"' + encodeJS(o) + '"'
              case 'number': return String(o)
              case 'object':
                  if(o) {
                      var a = []
                      if (o.constructor == Array) {
                          for (var i = 0; i <o.length; i++) {
                              var json = toJsonString(o[i])
                              if(json != UNDEFINED) a[a.length] = json
                   }
                          return '[' + a.join(',') + ']'
                      } else if (o.constructor == Date) {
                          return 'new Date(' + o.getTime() + ')'
                      } else {
                          for (var p in o) {
                              var json = toJsonString(o[p])

                              if (json != UNDEFINED) a[a.length] = (/^[A-Za-z_]\w*$/.test(p) ? ('"' + p + '":') : ('"' + encodeJS(p) + '":')) + json
                          }

                          return '{' + a.join(',') + '}'
                      }

                  }

                  return 'null'
              case 'boolean'  : return String(o)

              case 'function' : return
              case 'undefined': return 'null'
          }
      }


function chgOfferType(type)
{
	jQuery.get("/ajax/chgOfferType.php?type="+type, function(data){ jQuery('#os_oferta_id').html(data)});

}

function cntDays(date1,date2)
{
	jQuery.get("/ajax/cntDays.php?date1="+date1+"&date2="+date2, function(data){ if(parseInt(data)>0){jQuery('#cntDays').html(' '+data);jQuery('#os_koszt').val(data*dayCost);jQuery('#lblCost').html(data*dayCost);}else{jQuery('#cntDays').html(' błędnie podane daty emisji')}});
}


      function encodeJS(s) {
          return (!/[\x00-\x19\'\\]/.test(s)) ? s : s.replace(/([\\'])/g, '\\$1').replace(/\r/g, '\\r').replace(/\n/g, '\\n').replace(/\t/g, '\\t').replace(/[\x00-\x19]/g, '')
      }

function chngRadioCost(ratio)
{
	ratio = ratio.value;
	jQuery('.tabcena').each(function(i){jQuery(this).children('span').html(parseInt(parseFloat(jQuery(this).children('input').val())*parseFloat(ratio)*100)/100);});
}

function  delBriefcaseItem_inside(id)
{
	jQuery.get('/include/ajax_usun_pozycje_showka.php',{id: id}, function(data){if(data=="true"){jQuery('#briefcaseItem-'+id).hide(); }});
}

function  delBriefcaseItem(id)
{
	jQuery.get('/include/ajax_usun_pozycje_showka.php',{id: id}, function(data){if(data=="true"){jQuery('#dodaj_do_schowka').html('usunięto'); }});
}

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

// -->