var win;
var features = "menubar=no,location=no,resizable=no,scrollbars=no,status=no,width=260,height=140";
function loadScript() {
	var script = document.createElement("script");
   script.type = "text/javascript";
   script.src = "http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAVHk8vYheVoQgBxYQ6G42-hQEn6XI2cLxNyKHzLF6fbJ0BVO1WRTJ8rS3xARP7zEVYMZFCepF-WVWWg";
   document.getElementById('katalog_firm_tresc').appendChild(script);
}
function wgraj(what){
	win = window.open("upload.php?"+what, "Upload", features);
}
function pokaz(what,width,height){
	win = window.open(what, "Obrazek", "menubar=no,location=no,resizable=no,scrollbars=yes,status=no,width="+width+",height="+height);
}
function get_ed_text(editor_name){
	var oEditor = FCKeditorAPI.GetInstance(editor_name) ;
   if (oEditor.EditorDocument.body.innerHTML) {
   	return oEditor.EditorDocument.body.innerHTML;
   }
   else return '';
}
function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
setCookie('typ','w');
setCookie('typo','w');
setCookie('kal_asc','ASC');
setCookie('kal_sort','nazwa');
setCookie("typ_f","");
setCookie("kat_f","");
function $(what){
	return document.getElementById(what);
}

function wy(co){
	$(co).value='';
}
function sprawdz_czy_mail(){
	var AdresEmail=$('moj_mail').value;
	var TestEmail = /^(.[A-Za-z0-9\-]*\w)+@+([A-Za-z0-9\-]*\w)+(\.[A-Za-z]*\w)+$/;
   var Wynik = AdresEmail.match(TestEmail);

   if (Wynik == null)
   {
      alert("Proszę wpisać poprawny adres e-mail!");
		$('moj_mail').style.backgroundColor='red';
		setTimeout("$('moj_mail').style.backgroundColor='white';",200);
		setTimeout("$('moj_mail').style.backgroundColor='red';",400);
		setTimeout("$('moj_mail').style.backgroundColor='white';",600);
		setTimeout("$('moj_mail').style.backgroundColor='red';",800);
		setTimeout("$('moj_mail').style.backgroundColor='white';",3000);
      return false;
   }
   return true;
}
function add_frm(id,nazwa){
	var mdiv=$('firmy');
	var inp = document.createElement("input");
	inp.setAttribute('type','checkbox');
	inp.setAttribute('checked','checked');
	inp.setAttribute('value',id);
	inp.setAttribute('name','firmy[]');
	var inp2 = document.createElement("span");
	inp2.innerHTML=nazwa;
	var inp3 = document.createElement("br");
	
	mdiv.appendChild(inp);
	mdiv.appendChild(inp2);
	mdiv.appendChild(inp3);
	$('fr').removeChild($('fir'+id));

}
pok=function(){
	if($('menu_o').style.display=='block'){
		$('menu_o').style.display='none';
		$('pokaz_m').style.backgroundImage='url(img/menu_z.gif)';
	}else{
		$('menu_o').style.display='block';
		$('pokaz_m').style.backgroundImage='url(img/menu_o.gif)';
	}
}
function wyslij_f(frm,rt_editors){
		if(FCKeditorAPI){
     		if (arguments.length > 1) {
          	for (var i = 0; i < rt_editors.length; i++){
            	var val = get_ed_text(rt_editors[i]);
               frm.elements[rt_editors[i]].value = val;
          	}
     		}
		}
	xajax_admin_panel_wyslij_mail(xajax.getFormValues(frm));
   return false;
}


function pokaz_opis(nr){
	$('katalog_zawartosc').innerHTML=$('opis_nr_'+nr).innerHTML;
	if(nr=='kontakt'){
			var mc=document.getElementsByClassName("map_canvas");
			mc[1].id='map_canvas';
		  //	var newdiv = document.createElement('map_canvas');
		  //newdiv.setAttribute('id','map_canvas');
		  //$('map_canvas2').appendChild(newdiv);
	}
}
var map = null;
var geocoder = null;
function initialize() {
	if (GBrowserIsCompatible()) {
      map = new GMap2(document.getElementById('map_canvas'));
      map.setCenter(new GLatLng(51.771578, 19.451606), 1);
      geocoder = new GClientGeocoder();
		map.addControl(new GSmallMapControl());	
		map.addControl(new GMapTypeControl());
   }
}
function zaz(co){
	$(co).checked='checked';
}
function showAddress(address,geo1,geo2) {
	if(geo1 && geo2){
		point = new GLatLng(geo1,geo2);
	 	map.setCenter(point, 15);
      var marker = new GMarker(point);
      map.addOverlay(marker);
      marker.openInfoWindowHtml(address);
	 }else{	
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert('Niestety nie odnaleziono adresu : ' + address);
            } else {
              map.setCenter(point, 15);
              var marker = new GMarker(point);
              map.addOverlay(marker);
              marker.openInfoWindowHtml(address);
            }
          }
        );
      }
	 }
}
function initialize2(geo,alt) {
	if (GBrowserIsCompatible()) {
   	map = new GMap2(document.getElementById('map_canvas'));
		if(geo != ''){
			geocoder.getLatLng(
          geo,
          function(point) {
            if (!point) {
              map.setCenter(new GLatLng(51.771578, 19.451606), 6);
            } else {
              map.setCenter(point, alt);
            }
          }
        );
		} else {
			map.setCenter(new GLatLng(51.771578, 19.451606), 6);
		}	
      geocoder = new GClientGeocoder();
		map.addControl(new GSmallMapControl());	
		map.addControl(new GMapTypeControl());
   }
}
function showAddress2(address,geo1,geo2,nr,pt) {
	if(geo1 && geo2){
	 	point = new GLatLng(geo1,geo2);
	 	//map.setCenter(point, 15);
      var marker = new GMarker(point);
		document.nr = address;
		marker.value = address;
		
      GEvent.addListener(marker, "click", function() {
    		var myHtml = address;
    		map.openInfoWindowHtml(new GLatLng(geo1,geo2), nr);
  		});
		map.addOverlay(marker);
		
	}
}
function porownaj(h1,h2){
	if(h1==h2&&$('slij')){
		$('wiadomosc').innerHTML='&nbsp;';
		$('slij').disabled=false;
	}else{
		$('wiadomosc').innerHTML='<p style="color:#ff0000">Hasła nie są identyczne</p>';
		$('slij').disabled=true;
	}
}
function isValidEmail(str) {
	var result;
 	var filter=/^.+@.+\..{2,3}$/;
 	if (filter.test(str)){
    	result=true;
	}else{
   	alert("Wpisano niepoprawny adres E-mail");
    	result=false;
	 	return false;
	}
 	return (result)
}
function sprawdz(){
	if($('login') && $('haslo') && $('haslo2')){
	 	if(($('login').value!='')&&($('haslo').value!='')&&($('haslo2').value!='')&&($('nazwa').value!='')){
			$('slij').disabled=false;
		}else{
			$('slij').disabled=false;
		}
	}else{
		$('slij').disabled=false;
	}
}	
function blokuj(){
	$('slij').disabled=true;
}
function submit_form(frm,rt_editors){
	if($('fckopis')){
		if(FCKeditorAPI){
     		if (arguments.length > 1) {
          	for (var i = 0; i < rt_editors.length; i++){
            	var val = get_ed_text(rt_editors[i]);
               frm.elements[rt_editors[i]].value = val;
          	}
     		}
		}
	}
	xajax_process_form(xajax.getFormValues(frm));
   return false;
}
function submit_opis(frm,rt_editors){
		if(FCKeditorAPI){
     		if (arguments.length > 1) {
          	for (var i = 0; i < rt_editors.length; i++){
            	var val = get_ed_text(rt_editors[i]);
               frm.elements[rt_editors[i]].value = val;
          	}
     		}
		}
	xajax_process_form_opis(xajax.getFormValues(frm));
   return false;
}
function submit_zak(frm,rt_editors,akcja){
		if(FCKeditorAPI){
     		if (arguments.length > 1) {
          	for (var i = 0; i < rt_editors.length; i++){
            	var val = get_ed_text(rt_editors[i]);
               frm.elements[rt_editors[i]].value = val;
          	}
     		}
		}
	xajax_admin_panel_zakladki(xajax.getFormValues(frm),akcja);
   return false;
}
function submit_zakl(frm,rt_editors,akcja){
		if(FCKeditorAPI){
     		if (arguments.length > 1) {
          	for (var i = 0; i < rt_editors.length; i++){
            	var val = get_ed_text(rt_editors[i]);
               frm.elements[rt_editors[i]].value = val;
          	}
     		}
		}
	xajax_zakladki(xajax.getFormValues(frm),akcja);
   return false;
}
function edit_ogloszenie(frm,rt_editors){
		if(FCKeditorAPI){
     		if (arguments.length > 1) {
          	for (var i = 0; i < rt_editors.length; i++){
            	var val = get_ed_text(rt_editors[i]);
               frm.elements[rt_editors[i]].value = val;
          	}
     		}
		}
	xajax_admin_panel_edytuj_ogloszenie(xajax.getFormValues(frm));
   return false;
}
function edit_omnie(frm,rt_editors){
		if(FCKeditorAPI){
     		if (arguments.length > 1) {
          	for (var i = 0; i < rt_editors.length; i++){
            	var val = get_ed_text(rt_editors[i]);
               frm.elements[rt_editors[i]].value = val;
          	}
     		}
		}
	xajax_projektant_omnie(xajax.getFormValues(frm));
   return false;
}
function targi(frm,rt_editors){
		if(FCKeditorAPI){
     		if (arguments.length > 1) {
          	for (var i = 0; i < rt_editors.length; i++){
            	var val = get_ed_text(rt_editors[i]);
               frm.elements[rt_editors[i]].value = val;
          	}
     		}
		}
	xajax_targi(xajax.getFormValues(frm));
   return false;
}
function edit_praca(frm,rt_editors){
		if(FCKeditorAPI){
     		if (arguments.length > 1) {
          	for (var i = 0; i < rt_editors.length; i++){
            	var val = get_ed_text(rt_editors[i]);
               frm.elements[rt_editors[i]].value = val;
          	}
     		}
		}
	xajax_admin_panel_edytuj_praca(xajax.getFormValues(frm));
   return false;
}

function edit_video(frm,rt_editors){
		if(FCKeditorAPI){
     		if (arguments.length > 1) {
          	for (var i = 0; i < rt_editors.length; i++){
            	var val = get_ed_text(rt_editors[i]);
               frm.elements[rt_editors[i]].value = val;
          	}
     		}
		}
	xajax_admin_panel_edytuj_video(xajax.getFormValues(frm));
   return false;
}
function edit_produkt(frm,rt_editors){
		if(FCKeditorAPI){
     		if (arguments.length > 1) {
          	for (var i = 0; i < rt_editors.length; i++){
            	var val = get_ed_text(rt_editors[i]);
               frm.elements[rt_editors[i]].value = val;
          	}
     		}
		}
	xajax_admin_panel_edytuj_produkt(xajax.getFormValues(frm));
   return false;
}
function edit_porada(frm,rt_editors){
		if(FCKeditorAPI){
     		if (arguments.length > 1) {
          	for (var i = 0; i < rt_editors.length; i++){
            	var val = get_ed_text(rt_editors[i]);
               frm.elements[rt_editors[i]].value = val;
          	}
     		}
		}
	xajax_admin_panel_edytuj_porade(xajax.getFormValues(frm));
   return false;
}
function edit_porada2(frm,rt_editors){
		if(FCKeditorAPI){
     		if (arguments.length > 1) {
          	for (var i = 0; i < rt_editors.length; i++){
            	var val = get_ed_text(rt_editors[i]);
               frm.elements[rt_editors[i]].value = val;
          	}
     		}
		}
	xajax_admin_panel_edytuj_porade2(xajax.getFormValues(frm));
   return false;
}
function submit_edit_form(frm,rt_editors){
	if($('firma')){
		if(FCKeditorAPI){
	     	if (arguments.length > 1) {
				for (var i = 0; i < rt_editors.length; i++){
	        		var val = get_ed_text(rt_editors[i]);
	            frm.elements[rt_editors[i]].value = val;
	         }
	     	}
		}
	}
   xajax_process_form_edit(xajax.getFormValues(frm));
   return false;
}
function autozapis(){
	var content = FCKeditorAPI.GetInstance('firma').GetXHTML();
	$('firma').value=content;
	frm=document.getElementById('main_form');
	rt_editors=Array('firma');
	if($('firma')){
		if(FCKeditorAPI){
	     	if (arguments.length > 1) {
				for (var i = 0; i < rt_editors.length; i++){
	        		var val = get_ed_text(rt_editors[i]);
	            frm.elements[rt_editors[i]].value = val;
	         }
	     	}
		}
	}
   xajax_process_form_edit(xajax.getFormValues(frm),1);
   return false;
}
function submit_edit_boks(frm,rt_editors){
if($('firma')){
	if(FCKeditorAPI){
     	if (arguments.length > 1) {
			for (var i = 0; i < rt_editors.length; i++){
        		var val = get_ed_text(rt_editors[i]);
            frm.elements[rt_editors[i]].value = val;
         }
     	}
	}
}
   xajax_admin_panel_edytuj_boks(xajax.getFormValues(frm));
   return false;
}
function submit_edit_mail(frm,rt_editors){
if($('firma')){
	if(FCKeditorAPI){
     	if (arguments.length > 1) {
			for (var i = 0; i < rt_editors.length; i++){
        		var val = get_ed_text(rt_editors[i]);
            frm.elements[rt_editors[i]].value = val;
         }
     	}
	}
}
   xajax_admin_panel_edytuj_mail(xajax.getFormValues(frm));
   return false;
}
function submit_form_produkt(frm,rt_editors){
     		if (arguments.length > 1) {
          	for (var i = 0; i < rt_editors.length; i++){
            	var val = get_ed_text(rt_editors[i]);
               frm.elements[rt_editors[i]].value = val;
          	}
     		}
	xajax_process_form_produkt(xajax.getFormValues(frm));
   return false;
}
var tablica= new Array();
var strona=0; 
var ileNaStronie=15; 

function wyswietl() 
{ 
  	var tekst="",i,a; 

 	for (i=0;i<ileNaStronie;i++){
 		if(tablica[i+strona*ileNaStronie]){
	   	tekst+=tablica[i+strona*ileNaStronie]+"<BR>"; 
		}
 	}
	for (i=0;i<Math.round(tablica.length/ileNaStronie);i++){ 
		tekst+="<a onclick='strona="+i+";wyswietl();' class='link'>["+(a=i+1)+"]</a>";
	}
	document.getElementById('katalog_produktow_tresc').innerHTML=tekst; 
}
function geo(ulica,miasto){
	if(ulica!="" && miasto!=""){
   	alert(geocoder.getLatLng(ulica + miasto,function(point) {
      	if (!point) {
         	alert(address + " not found");
         } else {
         	alert(point);
			}
		}))
	}
}
function pokaz_kat(nazwa,srodek){
	if(srodek.innerHTML=='<img src="img/plus.gif">'){
		srodek.innerHTML='<img src="img/minus.gif">';
		$(nazwa).style.display='block';
	}else{
		srodek.innerHTML='<img src="img/plus.gif">';
		$(nazwa).style.display='none';
	}	
}
function czy_puste(ids){
	if($('kategoria'+ids).innerHTML==''){
		$('aa'+ids).innerHTML='';
	}
}
function setfocus(a_field_id) {
	if($(a_field_id)){
   	setTimeout(function(){$(a_field_id).focus();},1);
	}		
}
function zaznacz(id){
	$('star').value=id;
	for(i=1;i<11;i++){
		var ids='gw' + i;
		if(i<id+1){
			$(ids).src='img/ocena.png';
		}else{
			$(ids).src='img/ocena0.png';
		}
	}
}
function s(){
	var sp=['_a','_v','_o'];
	for(i=0;i<3;i++){
		a="_" + $('w').value;
		if(a==sp[i]){
			$(sp[i]).style.fontWeight='bold';
		}else{
			$(sp[i]).style.fontWeight='normal';
		}
	}	
}
function op(co){
	if($(co).style.display=='none'){
		$(co).style.display='block'
	}else{
		$(co).style.display='none'
	}
}
function pokaz_v(what){
	var co=['ov','og','nv','ng'];
	for(i=0;i<4;i++){
		if(what==co[i]){
			$(co[i]).style.display='block';
		}else{
			$(co[i]).style.display='none';
		}
	}
}
d='';
var firmy=Array();
function pokaz_firmy(i){
	var el=$('za_tab').getElementsByTagName('table');
	//alert(el.length);
	ile=i*10;
	for(a=0;a<el.length;a++){
		if(a<=(ile+10)&&a>=ile){
			$('zaa'+a).style.display='block';
		}else{
			$('zaa'+a).style.display='none';
		}
	}
	$('ile_fi').innerHTML="";
	var licz='';
	for(a=0;a<(el.length/10);a++){
		licz+="<a href='#' onclick='pokaz_firmy(" + a + ");'>";
		if(i==a)licz+="<b>";
		licz+="[" + (a+1) + "]";
		if(i==a)licz+="</b>";
		licz+="</a> ";	
	}
	$('ile_fi').innerHTML+=licz;
}
function getElementByClass(tagName,className){
   var tags = document.getElementsByTagName(tagName);
   var finds = [];   for(var i = 0, len = tags.length;i < len;++i){
      if(tags[i].className.indexOf(className) != -1)
         finds.push(tags[i]);
   }
   return finds;
}
function za_st(w){
	var el;
	el=getElementByClass('div','rodz1m');
	for(a=0;a<el.length;a++){
		el[a].setAttribute("class", "rodzm");
		el[a].setAttribute("className", "rodzm");
	}
	w.setAttribute("class", "rodz1m");
	w.setAttribute("className", "rodz1m");
}
function za_st1(w){
	var el;
	el=getElementByClass('div','rodz1');
	for(a=0;a<el.length;a++){
		el[a].setAttribute("class", "rodz");
		el[a].setAttribute("className", "rodz");
	}
	w.setAttribute("class", "rodz1");
	w.setAttribute("className", "rodz1");
}
function Clickheretoprint(){
	var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,";
	disp_setting+="scrollbars=yes,width=650, height=600, left=100, top=25";
	var content_vlue = document.getElementById("map_canvas").innerHTML;
	var com=document.getElementById("kont").innerHTML;
	var docprint=window.open("","",disp_setting);
	
	docprint.document.open();
	docprint.document.write('<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-2\"><title>Mapa z domimedia.pl</title>');

	docprint.document.write('</head><body onLoad="window.print();window.close()"><center><div style="height:600px;width:650px;">');
	docprint.document.write(content_vlue);
	docprint.document.write('</div></center><table>');
	docprint.document.write(com);
	docprint.document.write('</table><br/><br/><br/></body></html>');
	docprint.document.close();
	docprint.focus();
}
function proj_spr(){
	var oks;
	if($('proj_nazwisko').value==''){
		alert('Proszę wpisać nazwisko.');
		oks=false;
	}else if($('proj_kraj').value==''){
		alert('Proszę wpisać kraj.');
		oks=false;
	}else if($('proj_miasto').value==''){
		alert('Proszę wpisać miasto');
		oks=false;
	}else if($('proj_kod').value==''){
		alert('Proszę wpisać kod pocztowy.');
		oks=false;
	}else if($('proj_adres').value==''){
		alert('Proszę wpisać adres');
		oks=false;
	}else if($('proj_tel').value==''){
		alert('Proszę wpisać telefon kontaktowy.');
		oks=false;
	}else if($('proj_mail').value==''){
		alert('Proszę wpisać mail');
		oks=false;
	}else{
		oks=true;
	}
	return oks;
}
function showhide(z,c){
	if(document.getElementById(c).style.display!="block"){
		document.getElementById(c).style.display="block";
		z.innerHTML="mniej";
	}else{
		document.getElementById(c).style.display="none";
		z.innerHTML="więcej";
	}
}
function go(gdzie){
	window.location=gdzie;
}

