

function check_input_len(str,maxv) {

  var field = document.getElementById(str);
  var val = field.value;

  if(maxv) {
    if(val.length >= maxv) {
      field.value = val.substring(0,(maxv-1));
    }
  }

  var max = document.getElementById(str+"_max");
  max.innerHTML = val.length;
}

function ajax_uniqueCmsField(fvalue,fname,colname,tabname) {

  targetDiv = 'div_'+fname;
     advAJAX.post({ url: "/cms/scripts/script.parts/ajax_unique.php?fvalue="+fvalue+"&colname="+colname+"&tabname="+tabname,
       // onLoading : function(obj) {document.getElementById(targetDiv).innerHTML = "<div class=\"comm_status\">Trwa ładowanie danych<br><img src=\"/images/lightbox-ico-loading.gif\" alt=\"\" border=\"0\"></div>";},
	onSuccess : function(obj) { document.getElementById(targetDiv).innerHTML = obj.responseText; }

	// onError : function(obj) { alert("Error: " + obj.status); }
    });

  //advAJAX.download('div_'+fname, '/cms/scripts/script.parts/ajax_unique.php?fvalue='+fvalue+'&colname='+colname+'&tabname='+tabname);
}



function check_MainForm(f) {

  var e=0;
     for(i=0; i<f.elements.length; i++){
      if(f.elements[i].type == 'text') {
        if(f.elements[i].value == '-- wpisz dowolną frazę --' || f.elements[i].value == '') {
          e++;
          }
      }
     }
     if(e>1){
      alert('Uzupełnij przynajmniej jedno pole.');
      return true;
     }

}

function spr_domene_znaki(domena){
  if (/^[a-z]+$/.test(domena)){
    wart = 1;
  }else{
    wart = 0;
  }
  return wart;
}


function highlight(div) {

  if(div.style.backgroundColor == '' || div.style.backgroundColor == '#FAFAFA') {
    div.style.backgroundColor = '#F5F5F5';
  } else {
    div.style.backgroundColor = '';
  }

}

function add_cookie() {
    var d = new Date();
    //d.setMinutes(d.getMinutes() + 1);
    d.setDate(d.getDate() + 1);
    //alert(d.toGMTString());
    var div = document.getElementById("div_swieta");
    div.style.display = "none";
    document.cookie = "name=swieta; expires=" + d.toGMTString();
   // document.location.href='/index.php';
}




function zielone(zdjecie) {


                $(".produkt_akcja").hover(
                function(){
                    $(this).addClass("hover");
                    $(this).children("img").attr("src","/cms/site.files/Image/marelplus_new/" + zdjecie + "_z.jpg");
                }
                ,
                function(){
                    $(this).removeClass("hover");
                    $(this).children("img").attr("src","/cms/site.files/Image/marelplus_new/" + zdjecie + ".jpg");
                }
                );

}



function spr_domene(domena){
  wart=1;
  if (domena==''){
    alert('Proszę wpisać interesującą Państwa domenę');
    wart=0;
  }
  //wart = pr_domene_znaki(domena);

    domenaarray = domena.split('.');
    domlen = domenaarray.length;
    if (domlen>1){
      //wpisana domena
    }else{
      //ciag znakow
    }
    for (var i=0; i < domlen; i++) {

    }
  return wart;
}

function sprawdz_popr_domeny(pkt){

  var domena = document.getElementById('domena').value;
  var dform = document.getElementById('Domeny_form');

  // do dorobienia funkcja sprawdzająca
   wart = spr_domene(domena);

  if (wart==1){
    if (pkt==2){
      var actionf = 'http://'+window.location.hostname+'/mod-forms/path-3/wr-1/';
      //var actionf = 'http://'+window.location.hostname+'/index.php?mod=forms&path=3&wr=1';
    dform.action = actionf;
    dform.submit();
    }else{
      var actionf = 'http://'+window.location.hostname+'/mod-forms/path-3/';
      //var actionf = 'http://'+window.location.hostname+'/index.php?mod=forms&path=3';
      dform.action = actionf;
    }
  }

}
//powiela dane w formularzu rejestracyjnym
function powiel(id) {
  var pole = document.getElementById(id).value;
    if(id!="imie" && id!="nazwisko")
        document.getElementById(id+'_f').value = pole;
    if(id!="tel_kom")
        document.getElementById(id+'_a').value = pole;
}
function sprawdz_dost_domen(ktora, pocz){
  tag = document.getElementById('ret_'+ktora);
  jaka = document.getElementById('wybdomeny_'+ktora).value;
  pocz = document.getElementById('prefixdom').value;
  domena = pocz+jaka;
  tag.innerHTML = '<img src="/cms/pix/klepsydra.gif" width=25>';
  advAJAX.download(tag, '/cms/mod_forms/site.mod/ajax_domeny.php?check=4&domena='+domena);
}
function sprawdz_dost_domen_old(szukana){
        spr = document.getElementById('sprawdzane_domeny').value;

        var domainarray = Array();
        var checkarray = Array();
        a=spr.split(';');
        for (var i=0; i < a.length; i++) {
          if (a[i]!=''){
            b=a[i].split(':');
            ch = b[0];
            domain = b[1];
            if ((ch!='') && (domain!='')){
              domainarray[i] = domain;
              checkarray[i]= ch;
            }
          }
        }
        for (var iz=0; iz < domainarray.length; iz++) {
          document.getElementById('ret_'+checkarray[iz]).innerHTML = '<img src="/cms/pix/klepsydra.gif" width=25>';
          advAJAX.download('ret_'+checkarray[iz], '/cms/mod_forms/site.mod/ajax_domeny.php?check=4&pole='+checkarray[iz]+'&caladomena='+szukana+domainarray[iz]+'&domena='+szukana);
        }
        document.getElementById('sprawdzane_domeny').value='';
        document.getElementById('klikniecia').value='0';
}
function check_domain(tag,str){
	advAJAX.download(tag, '/cms/mod_forms/site.mod/ajax_domeny.php?'+str);
}
function pokaz_wymiary(wybrane){
  var dostepne = Array('tower','rack');
    for (var i=0; i < dostepne.length; i++) {
      if (wybrane==dostepne[i]){
        document.getElementById('Wymiary_'+dostepne[i]).style.display = 'block';
      }else{
        document.getElementById('Wymiary_'+dostepne[i]).style.display = 'none';
      }
    }
}
function display_style(divnone,divblock){
  document.getElementById(divblock).style.display = 'block';
  document.getElementById(divnone).style.display = 'none';
}


function sprawdz_klikniecia(h,str,domena){
        ile = document.getElementById('klikniecia').value;
        spr = document.getElementById('sprawdzane_domeny').value;
        znacznik = h+':'+domena+';';
        ile = parseFloat(ile);
        check = document.getElementById('wybdomeny_'+h);
        if (check.checked==true){
          if (ile<5){
            mat = ile+1;
            dom = spr+znacznik;
          } else{
            check.checked = false;
            alert(str);
          }
        }else{
            dom = dom.replace(znacznik, '');
            mat = ile-1;
        }
        document.getElementById('sprawdzane_domeny').value = dom;
        document.getElementById('klikniecia').value = mat;
}

//mapa polski - pokazuje wybrany adres
function pokaz_adres (div) {
    ukryj_all();
    var gdzie = document.getElementById(div);
    gdzie.style.display = "block";
}

function ukryj_adres(div) {
    var gdzie = document.getElementById(div);
   // gdzie.style.visibility = "hidden";
    gdzie.style.display = "none";
}
function zmien_przycisk(ktory, jaki){
     var gdzie = document.getElementById('menu_center_td_'+ktory);
    var link = document.getElementById('menu_center_a_'+ktory);
     if (jaki==1){
      link.style.color = "#000000";
      gdzie.style.background = "url(/cms/pix/przycisk_menu.gif)";
     }else{
      link.style.color = "#ffffff";
      gdzie.style.background = "url(/cms/pix/przycisk_menu_pod.gif)";
     }
}


function powiel_wysylka(id) {
    var pole = document.getElementById(id).value;

    document.getElementById(id+'_a').value = pole;
}

function powiel_vat(id) {
    var pole = document.getElementById(id).value;

    document.getElementById(id+'_f').value = pole;

}

function sprawdzDaneUser()
{
    if(document.frm.pass.value!="" || document.frm.retpass.value!="")
    {
      if(document.frm.pass.value!=document.frm.retpass.value)
      {
        alert("Hasła są różne!");
        return false;
      }
      if(document.frm.pass.value.length<6)
      {
        alert("Hasło za krótkie!");
        return false;
      }
    }
    return true;
}

//przepisuje z dane klienta do VAT
function przepisz_vat() {
    powiel_vat("firma");
    powiel_vat("ulica");
    powiel_vat("nr_domu");
    powiel_vat("kod");
    powiel_vat("miejscowosc");
    powiel_vat("kraj");
}


//przepisuje z dane klienta do wysyłki
function przepisz_wysylka() {
    powiel_wysylka("firma");
    powiel_wysylka("imie_nazwisko");
    powiel_wysylka("ulica");
    powiel_wysylka("nr_domu");
    powiel_wysylka("kod");
    powiel_wysylka("miejscowosc");
    powiel_wysylka("kraj");
}





function checkbox_os() {

    var pola = new Array('firma','firma_f','firma_a','nip');

    if(document.getElementById("os_fiz").checked==true) {
        for(i=0;i<pola.length;i++) {
            var v = document.getElementById(pola[i]);
            v.disabled = true;
            v.style.backgroundColor = '#D4D3D2';
        }
    }
    else {
        for(i=0;i<pola.length;i++) {
            var v = document.getElementById(pola[i]);
            v.disabled = false;
            v.style.backgroundColor = '';
        }
    }

}




/*
function checkbox_os() {
    if(document.getElementById("os_fiz").checked==true) {
        document.getElementById("os").innerHTML = "<input style=\"background-color:#D4D3D2\" type=\"text\" size=\"25\" name=\"firma\" DISABLED id=\"firma\"  onkeyup=\"powiel(\'firma\');\" />";
        document.getElementById("os_f").innerHTML = "<input style=\"background-color:#D4D3D2\" type=\"text\" size=\"25\" name=\"firma_f\" DISABLED id=\"firma_f\"  />";
        document.getElementById("os_a").innerHTML = "<input style=\"background-color:#D4D3D2\" type=\"text\" size=\"25\" name=\"firma_a\" DISABLED id=\"firma_a\"   />";
        document.getElementById("os_nip").innerHTML = "<input style=\"background-color:#D4D3D2\" type=\"text\" size=\"25\" name=\"nip\" DISABLED id=\"nip\"  />";
    }
    else {
        document.getElementById("os").innerHTML = "<input  type=\"text\" size=\"25\" name=\"firma\" id=\"firma\"  onkeyup=\"powiel(\'firma\');\" />";
        document.getElementById("os_f").innerHTML = "<input  type=\"text\" size=\"25\" name=\"firma_f\" id=\"firma_f\"  />";
        document.getElementById("os_a").innerHTML = "<input  type=\"text\" size=\"25\" name=\"firma_a\" id=\"firma_a\"   />";
        document.getElementById("os_nip").innerHTML = "<input  type=\"text\" size=\"25\" name=\"nip\" id=\"nip\"  />";
    }

}
*/
//UKRYWA WSZYSZYSTKIE DIVY Z ADRESAMI
function ukryj_all() {
    document.getElementById("adr1").style.display = "none";
    document.getElementById("adr2").style.display = "none";
    document.getElementById("adr3").style.display = "none";
    document.getElementById("adr4").style.display = "none";
    document.getElementById("adr5").style.display = "none";
    document.getElementById("adr6").style.display = "none";
    document.getElementById("adr7").style.display = "none";
}

//sprawdza czy login jest wolny czy zajety
function przetwarzajDane(src, dest)
{
    //if(dest!="")
        document.getElementById(dest).style.display = "block";
    var tfValue = document.getElementById(src).value;
    var str = "tekst="+tfValue;
    var tmp = advAJAX.download(dest, '/cms/scripts/php/login.php?'+str);
}


//sprawdza czy wpisana liczba do form
function IsDigit( e )
{
	if ( !e )
		e = event ;

	var iCode = ( e.keyCode || e.charCode ) ;

	return (
			( iCode >= 48 && iCode <= 57 )		// Numbers
			|| (iCode >= 37 && iCode <= 40)		// Arrows
			|| iCode == 8						// Backspace
			|| iCode == 46						// Delete
	) ;
}


//sprawdza poprawnosc pola 'ilosc osob' w zamowieniu wycieczki
function check(arg) {

        var input = document.getElementById(arg).value;
        if(input=="") {
                alert("Wypełnij pole 'Ilość'");
                return false;
        }

        else if(input.substr(0,1)==0) {
                alert("Pole 'Ilość' nie może być równe 0!");
                return false;
        }
        else
                return true;
}

//sprawdza poprawnosc formularza rejestracji
function sprawdz_rej(){
  if(  document.form_rej.imie_nazwisko.value=="" || document.form_rej.ulica.value=="" || document.form_rej.nr_domu.value=="" || document.form_rej.kod.value=="" || document.form_rej.miejscowosc.value=="" || document.form_rej.kraj.value==""  || document.form_rej.email.value=="" || document.form_rej.login.value=="" || document.form_rej.haslo.value=="" || document.form_rej.tel_kom.value=="" || (document.form_rej.firma.value=="" && document.form_rej.os_fiz.checked==false) || (document.form_rej.firma_f.value=="" && document.form_rej.os_fiz.checked==false) || (document.form_rej.nip.value=="" && document.form_rej.os_fiz.checked==false) ||  document.form_rej.obrtext.value=="" || document.form_rej.ulica_f.value=="" || document.form_rej.nr_domu_f.value=="" || document.form_rej.kod_f.value=="" || document.form_rej.miejscowosc_f.value=="" || document.form_rej.kraj_f.value=="" )
   {
        alert("Wypełnij wszystkie pola oznaczone gwiazdką!");
        return false;
   }
  if (!checkEmail(document.form_rej.email.value)) {
        return false;
  }
  if(document.form_rej.obr.value!=document.form_rej.obrtxt.value) {
        alert("Niepoprawny kod z obrazka");
        return false;
  }

  przetwarzajDane('login', 'div1');
  var spr = document.getElementById("spr").value;

  if (spr == 0) {
        alert("Podany login jest zajęty!");
        return false;
  }

  return true;
}


//sprawdza poprawnosc formularza rejestracji
function sprawdz(){

  if(  document.form_rej.imie.value=="" || document.form_rej.nazwisko.value=="" || document.form_rej.ulica.value=="" || document.form_rej.nr_domu.value=="" || document.form_rej.kod.value=="" || document.form_rej.miejscowosc.value=="" || document.form_rej.email.value=="" || document.form_rej.login.value=="" || document.form_rej.haslo.value=="" || document.form_rej.tel_kom.value=="" || (document.form_rej.firma.value=="" && document.form_rej.os_fiz.checked==false) || (document.form_rej.firma_f.value=="" && document.form_rej.os_fiz.checked==false) || (document.form_rej.firma_a.value=="" && document.form_rej.os_fiz.checked==false) || (document.form_rej.nip.value=="" && document.form_rej.os_fiz.checked==false) ||  document.form_rej.obrtext.value=="" || document.form_rej.ulica_f.value=="" || document.form_rej.nr_domu_f.value=="" || document.form_rej.kod_f.value=="" || document.form_rej.miejscowosc_f.value=="" || document.form_rej.imie_a.value=="" || document.form_rej.nazwisko_a.value=="" || document.form_rej.ulica_a.value=="" || document.form_rej.nr_domu_a.value=="" || document.form_rej.kod_a.value=="" || document.form_rej.miejscowosc_a.value=="")
   {
        alert("Wypełnij wszystkie pola oznaczone gwiazdką!");
        return false;
   }
  if (!checkEmail(document.form_rej.email.value)) {
        return false;
  }
  if(document.form_rej.obr.value!=document.form_rej.obrtxt.value) {
        alert("Niepoprawny kod z obrazka");
        return false;
  }

  przetwarzajDane('login', 'div1');
  var spr = document.getElementById("spr").value;

  if (spr == 0) {
        alert("Podany login jest zajęty!");
        return false;
  }

  return true;
}








function OpenImage(file)
{
	window.open("/cms/openimage.php?id="+file, "obrazek", "toolbar=no , menubar=0, status=no, top=250, left=225" );
}
function get_akt(id,title){
	window.open('/cms/mod_news/aktualnosci_popup.php?path='+id, 'title'+id, 'height=540, width=660, status=no, toolbar=no, menubar=yes, location=no, scrollbars=yes');
}
function get_content(id,title){
	window.open('/cms/mod_content/content_popup.php?path='+id, 'title'+id, 'height=540, width=660, status=no, toolbar=no, menubar=no, location=no, scrollbars=yes');
}
function swap(dv) {
	var d = document.getElementById(dv);
	if (dv=="libraries") {
		var b = document.getElementById('tdlibs');

	}



	if (d.style.display=="none") {
		d.style.display = "block";
		if (dv=="libraries") {
			b.style.height="200";
		}
		foldifr.location.href="_actions/setfold.php?code=" + dv + "&foldtype=show";
	} else {
		if (dv=="libraries") {
			b.style.height="0";
		}
		d.style.display = "none";
		foldifr.location.href="_actions/setfold.php?code=" + dv + "&foldtype=hide";
	}
}

function show(dv) {
	var d = document.getElementById(dv);
		if (dv=="libraries") {
		var b = document.getElementById('tdlibs');
	}
	d.style.display = "block";
		if (dv=="libraries") {
		b.style.height="200";
	}


}
function hide(dv) {
	var d = document.getElementById(dv);
		if (dv=="libraries") {
		var b = document.getElementById('tdlibs');
	}
	d.style.display = "none";
		if (dv=="libraries") {
		b.style.height="0";
	}
}


function set(dv, val) {
	if (val=="1") {
		show(dv);
	} else {
		hide(dv);
	}
}

function ONWHelp(Url, nazwa, wys, szer) {
   window.open(Url, nazwa, "height=" + wys + ",width=" + szer + ",status=no,resizable=no,scrollbars=yes,menubar=no,location=no");
}

function HideSearch(){
	parent.document.getElementById('cms-wyszuk').style.display='none';
}
function HideStats(){
	parent.document.getElementById('cms-stats').style.display='none';
}

//funkcja do ustawiania praw dostepu
function swapbtns(id) {

	var vl = document.getElementById('cms-rights-value-'+id);


	if (vl.value==1) {
		newval = 3;
	} else if (vl.value==2) {
		newval = 2;
	} else if (vl.value==3) {
		newval=1;
	}

	var im = document.getElementById('cms-rights-image-'+id);

	im.src='/cms/pix_cms/ico.rights.'+newval+'.gif';
	vl.value = newval;

}

function swapbtnswv(id,val) {

	var vl = document.getElementById('cms-rights-value-'+id);

	if (vl.value!=2) {
		newval = val;



	var im = document.getElementById('cms-rights-image-'+id);

	im.src='/cms/pix_cms/ico.rights.'+newval+'.gif';
	vl.value = newval;
	}

}

function ONWGal(Url, nazwa, wys, szer) {
   window.open(Url, nazwa, "height=" + wys + ",width=" + szer + ",status=no,resizable=no,scrollbars=yes,menubar=no,location=no");
}
function set_cars_od_ilosc(val) {
	f = document.getElementById('select_cars');
	f.target='ifr_cars';
	f.action='cms/_actions/select_cars.php';
	f.od_ilosc.value=val;
	f.submit();
}
function set_cars_orderby(val) {
	f = document.getElementById('select_cars');
	f.target='ifr_cars';
	f.action='cms/_actions/select_cars.php';
	f.orderby.value=val;
	f.submit();
}
function set_cars_desc(val) {
	f = document.getElementById('select_cars');
	f.target='ifr_cars';
	f.action='cms/_actions/select_cars.php';
	f.desc.value=val;
	f.submit();
}
function set_cars_sort(val) {
	f = document.getElementById('select_cars');
	f.target='ifr_cars';
	f.action='cms/_actions/select_cars.php';
	f.sort.value=val;
	f.submit();
}
function set_cars_demo(val) {
	f = document.getElementById('select_cars');
	f.target='ifr_cars';
	f.action='cms/_actions/select_cars.php';
	f.demo.value=val;
	//f.g2.value='';
	f.submit();
}
function set_cars_g2(val) {
	f = document.getElementById('select_cars');
	f.target='ifr_cars';
	f.action='cms/_actions/select_cars.php';
	f.g2.value=val;
	//f.demo.value='';
	f.submit();
}
function updateSubCat(tag,mark) {
	advAJAX.download(tag, 'cms/_actions/cars_model.php?mark='+mark);
}
function open_close(div){

  var d = document.getElementById(div);
  if (d.style.display=="block"){
    d.style.display="none";
  }else{
    d.style.display="block";
  }
}
function checkEmail2(myForm,txt) {

if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.newsletterEmail.value)){
return (true)
}
alert(txt)
return (false)
}
function show_poczta(stan){
  var trp = document.getElementById("faktura_poczta");
  if (stan=="1"){
    trp.style.display = "";
  }else{
    trp.style.display = "none";
  }
 }
function show_firma(stan,domena){
  var trn = document.getElementById("trnip");
  var trp = document.getElementById("trpesel");
  var trr = document.getElementById("trregon");
  if (domena=="eu"){
   if (stan==1){
    trr.style.display = "block";
    trn.style.display = "block";
    trp.style.display = "none";
   }else{

    trr.style.display = "none";
    trn.style.display = "none";
    trp.style.display = "block";
   }
  }else{
    trr.style.display = "none";
    trn.style.display = "block";
    trp.style.display = "none";
    }
}

function show_danek(stan){

  var trp = document.getElementById("fieldset_danek");
  if (stan=="1"){
    trp.style.display = "block";
  }else{
    trp.style.display = "none";
  }
 }

function logowanie_check() {
  var login = document.getElementById("login").value;
  var haslo = document.getElementById("haslo").value;
  if(login=="" || haslo=="") {
    alert("Wypełnij oba pola!!");
    return false;
  }
  return true;
}


/* PLYWAJACA CHMURKA */

showHintBox=showHintBoxForVar=function( S,T,W, d,E,b ) {
  d=document;E=d.documentElement;b=d.body;if(!E)return;
  //check if hintBox appears somwhere in code
  if( ! ( S.h=document.getElementById( 'hintBox' ) ) ) {
  	//if not create new element
  	S.h=d.createElement('div');
  	//and add some looks
  	S.h.id='hintbox';
  } //here's IE bug fix - if hintBox appears within table tag it won't
  //accept table as inner html, so to preserve user defined formatting we clone node and add it in
  //the beginning of document
 	//do not remove !!!!
	else S.h=S.h.cloneNode(true);
	//if T string was not sent look for title tag and if it's not found give it default string
	S.h.innerHTML = !T ? (S.title?S.title:'&nbsp;value not defined&nbsp;'):unescape( T );
	//set properties essential for div positioning
	with( S.h.style ) { position='absolute'; zIndex=2; top=left=0;}
	//the heart of the script - enable onmousemove event
	S.onmousemove=function(e,l,t,mX, mY,c,h,w){
		e=e||event;
		var di=15; friction=.3;
		with( this.h.style ) {
			//show div
			display='block'; visibility='visible';
			mX = e.clientX+( E.scrollLeft || b.scrollLeft );
			mY = e.clientY+( E.scrollTop  || b.scrollTop  );
			c = clientSize();
			l=parseInt(left),	t=parseInt(top),	h=this.h.offsetHeight,	w=this.h.offsetWidth
			if( c[0]-mX-w < di )
				left=(l > mX-di-w?l+(mX-di-w-l)*friction:mX-di-w)+'px';
			else
				left= (l > mX-w-di && l < mX+di?l+(mX+di-l)*friction: mX+di)+'px';

			if( c[1]-mY-h < di )
				top=(t>mY-di-h?t+(mY-di-h-t)*friction:mY-di-h)+'px';
			else
				top=(t > mY-h-di && t < mY+di?t+(mY+di-t)*friction:mY+di)+'px';
		} return!1;
	}
	//add hiding
	S.onmouseout=function(){
		with( this ) {
			//remove div from document's node tree
	  	if(h)b.removeChild( h );
	  	//stop catching mouse position
			onmousemove=h=null;
		}
		return!1;
  }
  //add div to the document
	b.appendChild(S.h);
}

function clientSize() {
	if (window.innerHeight >= 0) {
		return [window.innerWidth, window.innerHeight];
	} else if (document.documentElement) {
		return [document.documentElement.clientWidth,		document.documentElement.clientHeight]
	} else if (document.body.clientHeight >= 0) {
		return [document.body.clientWidth,document.body.clientHeight]
	} else {
		return [0, 0]
	}
}


//GALERIA ZDJEC W SZCZEGOLACH PRODUKTU
function pokaz_zdjecie(zdjecie) {
    document.getElementById("zdjecie").innerHTML = '<img onclick="window.open(\'/cms/site.files/Image/Products/origs/' + zdjecie + '\')" style="cursor:pointer" title="powiększ" alt="powiększ" width="250" src="/cms/site.files/Image/Products/images_250xY/' + zdjecie + '" />';
    document.getElementById("actual_photo").value = zdjecie;
}

function print_pdf(url) {
    foto = document.getElementById("actual_photo").value;
    window.open(url+'&photo='+foto);
}
function print_pdf2(url) {
    //foto = document.getElementById("actual_photo").value;
    window.open(url);
}

function wylicz_koszta(dest,netto,brutto,forma){

        str = 'netto='+netto+'&brutto='+brutto+'&forma='+forma;
	var tmp = advAJAX.download(dest, '/cms/mod_shop/site.mod/kosztatransportu.php?'+str);
}

function load(wsp1,wsp2, opis) {
                if (GBrowserIsCompatible()) {
                        var map = new GMap2(document.getElementById("map"));


                        map.addControl(new GSmallMapControl());
                        map.addControl(new GMapTypeControl());
                        map.setCenter(new GLatLng(wsp1,wsp2), 14);
                        map.setMapType(G_NORMAL_MAP);
                        // Create a base icon for all of our markers that specifies the
                        // shadow, icon dimensions, etc.
                        var baseIcon = new GIcon();
                        baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
                        baseIcon.iconSize = new GSize(20, 34);
                        baseIcon.shadowSize = new GSize(37, 34);
                        baseIcon.iconAnchor = new GPoint(9, 34);
                        baseIcon.infoWindowAnchor = new GPoint(9, 2);
                        baseIcon.infoShadowAnchor = new GPoint(18, 25);

                        // Creates a marker whose info window displays the letter corresponding
                        // to the given index.
                        function createMarker(point, index, litera, lokal) {
                                // Create a lettered icon for this point using our icon class
                                var letter = String.fromCharCode("A".charCodeAt(0) + index);
                                var icon = new GIcon(baseIcon);
                                icon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";
                                var marker = new GMarker(point, icon);

                                GEvent.addListener(marker, "mouseover", function() { 	marker.openInfoWindowHtml(lokal);});

                                return marker;
                        }

                        // Add 10 markers to the map at random locations
                        var bounds = map.getBounds();
                        var southWest = bounds.getSouthWest();
                        var northEast = bounds.getNorthEast();
                        var lngSpan = northEast.lng() - southWest.lng();
                        var latSpan = northEast.lat() - southWest.lat();

                        //var point = new GLatLng(53.748305,18.820953);
                        // map.addOverlay(createMarker(point, 0));

                        var morska = new GLatLng(wsp1,wsp2);
                        map.addOverlay(createMarker(morska, 0, "A",opis));

                        map.setCenter(new GLatLng(wsp1,wsp2), 15);
                }

        }


        function zapytanie_sprawdz() {
            if(!$("input[@name=nazwisko]").val() || !$("input[@name=telefon]").val() || !$("input[@name=email]").val() || !$("textarea[@name=pytanie]").val()) {
              alert("Wypełnij wszystkie pola oznaczone gwiazdką.");
              return false;
            }
            if (!checkEmail($("input[@name=email]").val())) {
                return false;
            }
            return true;



        }

function rozwin(id) {
	element = document.getElementById(id);
	if (element.style.display=="none") element.style.display="";
	else element.style.display="none";
}

function showSubMenu(id) {
  menuElement = document.getElementById('menuLevel1');
  topElement = document.getElementById('top');
  if (id!="21") {
    menuElement.style.height = "30px";
    topElement.style.height = "237px";
  }
  else {
    menuElement.style.height = "60px";
    topElement.style.height = "267px";
  }
  menuElement.style.display = "block";
  menuElement.innerHTML = "";
  advAJAX.download('menuLevel1', '/cms/scripts/php/getSubmenu.php?id='+id);
}

function highlightActiveMenu(id) {
  section = document.getElementById('menuLevel0');
  divs = section.getElementsByTagName('div');
  for (i=0; i<divs.length; i++) {
    if (divs[i].getAttribute('name') == id) {
      if (divs[i-1].getAttribute('class') == 'menuSeparatorFirst') {
	divs[i-1].setAttribute('class', 'menuSeparatorActiveFirst');
      }
      else
	divs[i-1].setAttribute('class', 'menuSeparatorActive');

      divs[i].setAttribute('class', 'menuActive');

      if (i+1<divs.length) {
	divs[i+1].setAttribute('class', 'menuSeparatorActiveClose');
	i++;
      }
    }
    else if (divs[i].getAttribute('class') == 'menuActive') {
      divs[i].setAttribute('class', 'menuNormal');
    }
    else if (divs[i].getAttribute('class') == 'menuSeparatorActive') {
      divs[i].setAttribute('class', 'menuSeparatorNormal');
    }
    else if (divs[i].getAttribute('class') == 'menuSeparatorActiveFirst') {
      divs[i].setAttribute('class', 'menuSeparatorFirst');
    }
    else if (divs[i].getAttribute('class') == 'menuSeparatorNormal') {
      divs[i].setAttribute('class', 'menuSeparatorNormal');
    }
    else if (divs[i].getAttribute('class') == 'menuSeparatorActiveClose') {
      divs[i].setAttribute('class', 'menuSeparatorNormal');
    }
    else if (divs[i].getAttribute('class') == 'menuSeparatorFirst') {
      divs[i].setAttribute('class', 'menuSeparatorFirst');
    }
  }
}


// LOOPY'S //

    function hideSubmenus() {
	var element = document.getElementById("menu");
	var divs = element.getElementsByTagName("div");
	i = 0;
	for (i=0; i<divs.length; i++) {
	  if (divs[i].getAttribute("class") == "submenu") {
	    divs[i].style.display = "none";
	  }
	  if (divs[i].getAttribute("className") == "submenu") {
	    divs[i].style.display = "none";
	  }
	}
    }

    function hoveroutAll() {
	var element = document.getElementById("menu");
	var as = element.getElementsByTagName("a");
	i = 0;
	for (i=0; i<as.length; i++) {
	  if (as[i].getAttribute("class") == "main_menu") {
	    as[i].style.backgroundImage = "";
	  }
	  if (as[i].getAttribute("className") == "main_menu") {
	    as[i].style.backgroundImage = "";
	  }
	}
    }

    function replaceImagesLayout(sub) {
	txt = "";
	if (sub==1) {
	    txt = "Sub";
	    element1 = document.getElementById("left");
	    element1.style.height = "810px";
	    element1.style.backgroundImage = "url(/pix/images/v4_2_08.png)";
	    element2 = document.getElementById("right");
	    element2.style.height = "810px";
	    element2.style.backgroundImage = "url(/pix/images/v4_2_09.png)";
	}

	if (screen.width < 1200) {
	    element1 = document.getElementById("left");
	    element1.style.width = "10px";
	    element1.style.backgroundImage = "url(/pix/images/leftNarrow"+txt+".png)";

	    element2 = document.getElementById("right");
	    element2.style.width = "10px";
	    element2.style.backgroundImage = "url(/pix/images/rightNarrow"+txt+".png)";

	    document.getElementById('wrapper').style.width = "978px";
	}
    }

    /* COLDTEAM */

    function activeMenu(id) {
	linkDiv = document.getElementById(id);
	linkAnchors = linkDiv.getElementsByTagName("a");
	var i;
	for(i=0; i<linkAnchors.length; i++) {
	    if (linkAnchors[i].getAttribute("class") == "topMenuLeft")
		linkAnchors[i].setAttribute("class", "topMenuLeftActive");
	    else if (linkAnchors[i].getAttribute("class") == "topMenuRight")
		linkAnchors[i].setAttribute("class", "topMenuRightActive");

	    if (linkAnchors[i].getAttribute("className") == "topMenuLeft")
		linkAnchors[i].setAttribute("className", "topMenuLeftActive");
	    else if (linkAnchors[i].getAttribute("className") == "topMenuRight")
		linkAnchors[i].setAttribute("className", "topMenuRightActive");
	}
    }

    function normalMenu(id) {
	linkDiv = document.getElementById(id);
	linkAnchors = linkDiv.getElementsByTagName("a");
	var i;
	for(i=0; i<linkAnchors.length; i++) {
	    if (linkAnchors[i].getAttribute("class") == "topMenuLeftActive")
		linkAnchors[i].setAttribute("class", "topMenuLeft");
	    else if (linkAnchors[i].getAttribute("class") == "topMenuRightActive")
		linkAnchors[i].setAttribute("class", "topMenuRight");

	    if (linkAnchors[i].getAttribute("className") == "topMenuLeftActive")
		linkAnchors[i].setAttribute("className", "topMenuLeft");
	    else if (linkAnchors[i].getAttribute("className") == "topMenuRightActive")
		linkAnchors[i].setAttribute("className", "topMenuRight");
	}
    }

    function showSubmenu(id) {
	element = document.getElementById(id);
	element.style.display = 'block';
    }

    function hideSubmenu(id) {
	element = document.getElementById(id);
	element.style.display = 'none';
    }

    function hoverin(id) {
	linkDiv = document.getElementById(id);
	linkAnchors = linkDiv.getElementsByTagName("a");
	//linkAnchors[1].style.backgroundImage = "url('/pix/coldteam/menu_top_green.png')";
	linkAnchors[1].setAttribute("class", "active");
	linkAnchors[1].setAttribute("className", "active");
	activeMenu(id);
    }

    function hoverout(id) {
	linkDiv = document.getElementById(id);
	linkAnchors = linkDiv.getElementsByTagName("a");
	//linkAnchors[1].style.backgroundImage = "url('/pix/coldteam/menu_top_blue.png')";
	linkAnchors[1].setAttribute("class", "");
	linkAnchors[1].setAttribute("className", "");
	normalMenu(id);
    }


    /* CKIS */
    function addBookmark() {
      var name = navigator.appName;
      if (name == "Microsoft Internet Explorer") {
	window.external.addFavorite('http://ckis.artnet.pl','Centrum Kultury i Sportu w Pruszczu Gdańskim');
      }
    }

    function sendNewsletterForm(action) {
      newsletterForm = document.getElementById('newsletterForm');
      newsletterEmail = document.getElementById('newsletterEmail');
      newsletterAction = document.getElementById('newsletterAction');

      if (newsletterEmail.value != "") {
	if (action == 1) { //add
	  newsletterAction.value = "add";
	}
	else if (action == 0) { //remove
	  newsletterAction.value = "remove";
	}
	newsletterForm.submit();
      }
      else alert("Wpisz poprawny adres e-mail.");
    }


function cmsShowMiniPhoto() {
  document.getElementById('miniPhotoDiv').style.display = "block";
}

function cmsHideMiniPhoto() {
  document.getElementById('miniPhotoDiv').style.display = "none";
}

function cmsLoadSubPage(link)
{
  $("div#cms-cursect").html('<img src="/cms/pix_cms/loading.gif"/>');
  $.getJSON(link, function(data) {
    $("div#cms-cursect").html(data.lewemenu);
    $("div#nawigacja").html(data.tytulsekcji);
    cmsLoadSubPageContent(data.link);
  }); 
}


var timeout_ready = null;
function cmsLoadSubPageContent(link)
{
  $('div#main_content').html('<img src="/cms/pix_cms/loading.gif"/>');
  $.get(link, function(data) {
    $('div#main_content').html(data);
    timeout_ready = setTimeout('ustaw_wysokosci_ready();', 300); }
  );
}

function ustaw_wysokosci_ready()
{
  if(timeout_ready) clearTimeout(timeout_ready);
  if(!ustaw_wysokosci()) timeout_ready = setTimeout('ustaw_wysokosci_ready();', 300);
}

function wyslijFormPostem(form_name)
{
  $('#'+form_name).ajaxForm({
    beforeSubmit: function(a,f,o) {
      o.dataType = 'json';
    },
    success: function(data) {
      var re = new RegExp("amp;", "g");
      if(data.act) cmsLoadSubPageContent(data.act.replace(re,''));
      if(data.skrypt) eval(data.skrypt);
    }
  });
  $('#'+form_name).submit();
}

function aktualnieEdytowane(page, id, log)
{
  page = page.replace('%2F','/');
  if(document.getElementById('kontrolny_'+page+id+log) && document.getElementById('kontrolny_'+page+id+log).innerHTML=='true')
  {
    $.get('/cms/_actions/aktualnieEdytowane.php?curpage='+page+'&curid='+id+'&curlog='+log);
    setTimeout("aktualnieEdytowane('"+page+"', '"+id+"', '"+log+"')", 5000);
  }
}

function aktualizujZalogowanie()
{
  $.get('/cms/_actions/aktualnieZalogowani.php', function(data) {
    if(pierwszy_reload==1) { $.get('/cms/_actions/ostatnieDzialania.php', function(data) { $('div#top_dzialania').html(data); }); pierwszy_reload=2; }
    $('div#lista_zalogowani').html(data);
  });
}

function in_array(what, where)
{
  for(var i=0;i<where.length;i++)
  {
    if(what == where[i]) return true;
  }
  return false;
}

function sprawdzEdytowane(page)
{
  $.get('/cms/_actions/aktualnieEdytowane.php?curpage='+page, function(data) {
    edytowane = data.split('|');
    $('.aktualnie_edytowany_info').each(function(index) {
      var czesci = $(this).attr("id").split('|');
      if(!in_array(czesci[1], edytowane)) $(this).html('');
    });
  });
}

function zaznaczCheckboxa(table, field, id, value, sekcja)
{
  $.getJSON('/cms/_actions/zapiszCheckbox.php?table='+table+'&field='+field+'&id='+id+'&value='+value+'&sekcja='+sekcja, function(data) {
    var re = new RegExp("amp;", "g");
    cmsLoadSubPage(data.link);
  });
}

var menu_blokada = new Array();
var menu_timeout = new Array();
var menu_timeout2 = new Array();

function zaznacz_menu(id)
{
  zapalone=id;
  $("div#menu_pozycja_lewa_"+id).css('background-image', 'url(\'/cms/pix_cms/menu_lewa_szary.png\')');
  $("div#menu_pozycja_srodek_"+id).css('background-image', 'url(\'/cms/pix_cms/menu_srodek_szary.png\')');
  $("div#menu_pozycja_srodek_"+id).css('color', '#444444');
  $("div#menu_pozycja_prawa_"+id).css('background-image', 'url(\'/cms/pix_cms/menu_prawa_szary.png\')');
  $("img#menu_down_img_"+id).attr('src','/cms/pix_cms/menu_down2.png');
}

function zapal_menu(id)
{
  $(".menu_submenu").each(function(index) { if(index!=id) zgas_menu(index); });
  if(zapalone!=id)
  {
    $("div#menu_pozycja_lewa_"+id).css('background-image', 'url(\'/cms/pix_cms/menu_lewa.png\')');
    $("div#menu_pozycja_srodek_"+id).css('background-image', 'url(\'/cms/pix_cms/menu_srodek.png\')');
    $("div#menu_pozycja_prawa_"+id).css('background-image', 'url(\'/cms/pix_cms/menu_prawa.png\')');
  }
  $("div#menu_pozycja_lewa_"+id).css('cursor', 'pointer');
  $("div#menu_pozycja_srodek_"+id).css('cursor', 'pointer');
  $("div#menu_pozycja_prawa_"+id).css('cursor', 'pointer');
  if(menu_blokada[id] != 1)
  {
    clearTimeout(menu_timeout[id]);
    clearTimeout(menu_timeout2[id]);
    menu_timeout[id] = setTimeout('menu_blokada['+id+'] = 1; $("div#menu_submenu_'+id+'").slideDown(200, function() { menu_blokada['+id+'] = 0; })', 100);
  }
  //$("div#menu_submenu_"+id).css('display', 'block');
}

function zgas_menu(id)
{
  if(zapalone!=id)
  {
    $("div#menu_pozycja_lewa_"+id).css('background-image', 'none');
    $("div#menu_pozycja_srodek_"+id).css('background-image', 'none');
    $("div#menu_pozycja_srodek_"+id).css('color', '#FFFFFF');
    $("div#menu_pozycja_prawa_"+id).css('background-image', 'none');
    $("img#menu_down_img_"+id).attr('src','/cms/pix_cms/menu_down.png');
  }
  if(menu_blokada[id] != 1)
  {
    clearTimeout(menu_timeout[id]);
    clearTimeout(menu_timeout2[id]);
    menu_timeout2[id] = setTimeout('$("div#menu_submenu_'+id+'").css(\'display\', \'none\')', 350);
    menu_timeout[id] = setTimeout('menu_blokada['+id+'] = 1; $("div#menu_submenu_'+id+'").slideUp(200, function() { menu_blokada['+id+'] = 0; });', 200);
  }
}

function ustaw_submenu(id)
{
  if($.browser.msie)
  {
    ile = -1*($("div#menu_pozycja_srodek_"+id).width()+14);
    $("div#menu_submenu_"+id).css('margin-left', ile);
  }
}

function przesun_wszystkie()
{
  /*przesun = $("div#odstep_submenu_0").offset().left;
  
  $(".submenu_odstep").each(function(index) {
    nowy_margin = parseInt($(this).css('margin-left').replace('px', ''))-przesun+7;
    $(this).css('margin-left', nowy_margin);
  });*/
}

function ustaw_wysokosci()
{
  //zerowanie wymiarow
  $("div#main_prawa").width('19%');
  $("div#main_rozszerz").width('1%');
  $("div#main_prawa").css('height', 'auto');
  $("div#main_lewa").css('height', 'auto');
  $("img#rozszerz_button").css('margin-top', 0);
  $("div#main_rozszerz").css('height', 'auto');
  $(document).css('height', 'auto');
  if($("div#main_prawa").height()>$("div#main_lewa").height()) max = $("div#main_prawa").height(); else max = $("div#main_lewa").height();
  if($(document).height()-164>max) max = $(document).height()-164;
  max--;
  $("div#main_prawa").css('height',max);
  $("div#main_lewa").css('height',max);
  $("div#main_rozszerz").css('height',max);
  $("img#rozszerz_button").css('margin-top',max/2-24);
  $("div#main_prawa").width($("div#main_prawa").width()+$("div#main_rozszerz").width()-11);
  $("div#main_rozszerz").width(9);
  dopasuj_nawigacje();
}

function dopasuj_nawigacje()
{
  if($('div#nawigacja_strony'))
  {
    $('div#nawigacja_strony').css('margin-left', '0px');
    $('div#nawigacja_strony').css('margin-left', $('div#cms').width()-$('div#nawigacja_strony').width());
  }
}

function rozszerz()
{
  if($("div#main_prawa").css('display')=='none')
  {
    $("div#main_prawa").css('display', 'block');
    $("div#main_lewa").css('width', '80%');
  }
  else
  {
    $("div#main_prawa").css('display', 'none');
    $("div#main_lewa").css('width', '99%');
  }
}

function up_down(id)
{
  $("div#prawa_"+id).toggle();
}

function hide_other_versions(id)
{
  $('.last_versions').each(function(index) {
      if($(this).attr("id")!='last_versions_'+id)
      {
        if($(this).css('display')=='block')
        {
          $(this).slideUp();
          return true;
        }
      }
    });
  return true;
}

function hide_stats_profile(id)
{
  $('.user_stats_profile').each(function(index) {
      if($(this).attr("id")!='user_stats_profile_'+id)
      {
        if($(this).css('display')=='block')
        {
          $(this).slideUp();
          return true;
        }
      }
    });
  return true;
}

function show_hide_last_versions(id, table, sekcja)
{
  hide_other_versions(id);
  if($('div#last_versions_'+id).css('display')=='none')
  {
    $.get('/cms/_actions/pobierzWersje.php?tabela='+table+'&id='+id+'&sekcja='+sekcja, function(data) {
      if(data!='') $("div#last_versions_"+id).html('<p class="last_versions_p"><b>Wybierz wersję do przywrócenia:</b></p>'+data);
      else $("div#last_versions_"+id).html('<p class="last_versions_p">Brak poprzednich wersji!</p>');
      $('div#last_versions_'+id).slideToggle();
    });
  } else $('div#last_versions_'+id).slideToggle();
}

function przywroc_wersje(wersja_id, sekcja)
{
  ret = confirm("Czy na pewno przywrócić tę wersję?");
  if (ret) {
    $.get('/cms/_actions/pobierzWersje.php?rekord_id='+wersja_id+'&sekcja='+sekcja, function(data) {
      cmsLoadSubPageContent(data);
      alert('Poprzednia wersja rekordu została przywrócona!');
    });
  } else {
    alert("Operacja anulowana!");
  }
}
