// JavaScript Document
var aktywnaWarstwa = '';

function pobierzDane (plik, id, kotwica) {
	$("#loading").ajaxStart(function(){    
		$(this).show();  
	});
	$("#loading").ajaxStop(function(){    
		$(this).hide();  
	});
	$.ajax({
   type: "POST",
   url: plik,
   data: "id="+id,
   success: function(html){
	 $("#sklep"+id+" .galeria").show();
	 $("#sklep"+id+" .galeria .content").html(html);
	 //document.location.href="#"+kotwica;
   }
 });
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function ustalAktywnaWarstwe(warstwa, pokaz) {
   if (aktywnaWarstwa != warstwa) ukryjWarstwe();
   aktywnaWarstwa = warstwa;	
   if (aktywnaWarstwa != '' && pokaz == true) ukryjWarstwe();
   aktywnaWarstwa = '';
   if (pokaz == true) MM_showHideLayers(warstwa,'','show');
}

function ustalNieAktywnaWarstwe(warstwa, ukryj) {
   aktywnaWarstwa = warstwa;
   if (ukryj == false) setTimeout(ukryjWarstwe, 1);
  else setTimeout(ukryjWarstwe, 1);
}

function ukryjWarstwe() {
   if (aktywnaWarstwa != '') MM_showHideLayers(aktywnaWarstwa,'','hide');
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function chgBg(obj,color){
if (document.all || document.getElementById)
  obj.style.backgroundColor=color;
else if (document.layers)
  obj.bgColor=color;
}


function MM_setTextOfTextfield(objName,x,newText) { //v3.0
  var obj = MM_findObj(objName); if (obj) obj.value = newText;
}


function ulubione() {
	window.external.addFavorite('http://www.kukartka.pl','Kukartka.pl');
}

function polecSerwis() {
   var wnd = window.open('index_polec.php', 'popup_polec', "width="+600+",height="+300+",status=yes,resizable=no,top="+50+",left="+50+",scrollbars=yes,dependent=yes,alwaysRaised=yes");
   wnd.focus();
}

/* --- z edytora --- */
function zdjecie_e(zdj)
{
	var obj=window.open("e-cms/zdjecie_e.php?typ=1&zdj="+zdj, 'zdjecie', "width=50,height=50,status=yes,resizable=no,top=50,left=50,scrollbars=yes,dependent=yes,alwaysRaised=yes");
	obj.focus();
}

// --- wywietla popup z powiekszeniem foty
function zdjeciePowiekszenie(typ, id, lng) {
	var wnd = window.open('index_zdjecie.php?typ='+typ+'&id='+id+'&lng='+lng, 'Zdjecie'+typ+id, 'height=50,width=50,left=50,top=50,status=yes,scrollbars=yes');
   wnd.focus();
}

// --- drukowanie informacja
function drukuj(id, lng) {
	var wnd = window.open('index_wydruk.php?idi='+id+'&lng='+lng, 'Wydruk'+id, 'width=760,height=680,status=yes,resizable=yes,top=50,left=50,scrollbars=yes');
   wnd.focus();
}




/* -- by MichaÄąâ€š --
  Funkcja sprawdza, czy odpowiednie pola na formularzu sĂ„â€¦
	wypeÄąâ€šnione! WyÄąâ€şwietla ALERT.
	
	Parametry:
	  form - obiekt forularz
	  reqElements - tablica napisÄ‚Ĺ‚w, np.:
									'nazwa_w_formularzu|nazwa_dla_oglĂ„â€¦dacza_strony'
									MoÄąÄ˝na pominĂ„â€¦Ă„â€ˇ nazwĂ„â„˘ dla uÄąÄ˝ytkownika :)
*/

function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

function validateFormAlert(form, reqElements, preText, postText) {

  var submitOK = true;
  var alerttext = '';
		
  for (var i=0; i < form.length; i++) {
	  for (var j=0; j< reqElements.length; j++) {
		
		  //rozwalenie parametru drugiego na dwa kawalki
			reArray = reqElements[j].split('|');
	    if ((form[i].name == reArray[0])&&(form[i].value.length==0)) {
			  
				submitOK = false;
				
				//w zaleÄąÄ˝noÄąâ€şĂ„â€ˇi od tego czy string ma nazwĂ„â„˘ 'user friendly' czy teÄąÄ˝
				//nie, konstruujemy odpowiedni napis.
			
        if (reArray[1] == undefined) {
    		  alerttext = alerttext + "Pole \""+reArray[0]+"\" nie może być puste!\n";
				} 
				else {
				  alerttext = alerttext + "Pole \""+reArray[1]+"\" nie może być puste!\n";
				}
			}
	  }
	}

	if (alerttext != '') {
	  alert(preText + alerttext + postText);
	}
 
	return submitOK;
}

function validateFormAlertEng(form, reqElements, preText, postText) {

  var submitOK = true;
  var alerttext = '';
		
  for (var i=0; i < form.length; i++) {
	  for (var j=0; j< reqElements.length; j++) {
		
		  //rozwalenie parametru drugiego na dwa kawalki
			reArray = reqElements[j].split('|');
	    if ((form[i].name == reArray[0])&&(form[i].value.length==0)) {
			  
				submitOK = false;
				
				//w zaleÄąÄ˝noÄąâ€şĂ„â€ˇi od tego czy string ma nazwĂ„â„˘ 'user friendly' czy teÄąÄ˝
				//nie, konstruujemy odpowiedni napis.
			
        if (reArray[1] == undefined) {
    		  alerttext = alerttext + "Field \""+reArray[0]+"\" id required!\n";
				} 
				else {
				  alerttext = alerttext + "Field \""+reArray[1]+"\" id required!\n";
				}
			}
	  }
	}

	if (alerttext != '') {
	  alert(preText + alerttext + postText);
	}
 
	return submitOK;
}

// -- newsletter antyspam
function newsletterAntyspam(frm)
{
         if(frm.email.value.indexOf('@') < 0 || frm.email.value.indexOf('.') < 0)
         {
             alert("Błędny adres e-mail");
             return false;
         }
		 else if(frm.antyspam.checked == false)
         {
             alert("Proszę zaznaczyć pole: Chcę otrzymać informację o otwarciu sklepu");
             return false;
         }else return true;
}

/* -- subskrypcja --- */
function subs_mail(opcja, lng, txt)
{
	var formularz = document.subskrypcja;
	var blad=0;

	if (lng == 'ger')
	{
		var txt_0 = 'Please, enter an e-mail address!';
	}
	else
	{
		var txt_0 = 'Proszę podać adres e-mail!';
	}


	if(formularz.email.value=='')
	{
		blad=1;
	}
	else if(formularz.antyspam.checked == false)
        {
                blad=2;
        }

	switch(blad)
	{
		case 0:
			formularz.se.value = opcja;
			if (opcja == 1)
			{
				formularz.submit();
			}
			else
			{
				return true;
			}
		break;
		case 1:
			alert(txt_0);
			formularz.email.focus();
			return false;
		break;
		case 2:
		        alert("Proszę zaznaczyć pole: "+txt);
                        return false;
                break;
	}
}

/*
    A N K I E T A - Wyswietla tresc danej zakladki
*/
function zakladkaSzczegoly(tab, id)
{
  if(id>0)
  {
    tekst = tab[id];
    for(i=0;i<tab.length;i++)
    {
        document.getElementById('zakladka_'+i).className = "boxTabOff";
    }
    document.getElementById('zakladka_'+id).className = "boxTabOn";
  } else {
    for(i=0;i<tab.length;i++)
    {        
        document.getElementById('zakladka_'+i).className = "boxTabOff";
    }
    document.getElementById('zakladka_'+id).className = "boxTabOn";
    tekst = tab[0];
  }      
   
  document.getElementById('boxTresc').innerHTML = tekst;
}

function ankietaDalej(nrZakladki, podglad)
{
  document.ankieta.numerZakladki.value = nrZakladki;
  if(podglad) document.ankieta.podglad.value = podglad;
  document.ankieta.submit();
}
function ankietaWstecz(nrZakladki)
{
  document.wstecz.numerZakladki.value = nrZakladki;
  document.wstecz.submit();
}

function ankieta()
{
  var obj = window.open("_qpraca_ankieta.php","ankieta","width=720, height=600, toolbar=no, menubar=no, scrollbars=yes");
  obj.focus();  
}

function ankieta2(plik)
{
  var obj = window.open(plik,"ankieta","width=800, height=600, toolbar=no, menubar=no, scrollbars=yes");
  obj.focus();  
}

function mailAktywacja(parametr) {
   var wnd = window.open('_mail_aktywacja.php?login='+parametr, 'aktywacja', "width="+400+",height="+170+",status=yes,resizable=no,scrollbars=yes,dependent=yes,alwaysRaised=yes");
   wnd.focus();
}


function edytujZnajomego(ids, lng) {
  window.location="index.php?id="+ids+"&lng="+lng+"&user=4&idz="+id
}

function okazjeZnajomego(idz, ids, lng) {
  if (id == 0) {
    alert("Wybierz najpierw osobę.")
  }
  else {
    if (idz == 0) window.location="index.php?id="+ids+"&lng="+lng+"&user=5&idz="+id;
    else window.location="index.php?id="+ids+"&lng="+lng+"&user=5&idz="+idz+"&ido="+id;
  }
}

function usunZnajomego(){
  window.location="_qclub_znajomi_usun.php?idz="+id;
}

function edytujOkazje(ids, lng) {
  window.location="index.php?id="+ids+"&lng="+lng+"&user=6&ido="+id
}

function usunOkazje() {
  window.location="_qclub_okazje_usun.php?ido="+id;
}



var id = 0;
var bar_1='#FFDEAD';
var bar_0='#FFF';
var poz='#758490';
function bar(wi,op){
  var kom = wi.getElementsByTagName('td');
  var ile=kom.length;
  switch (op) {
    case -1: if(wi.id!=id){
               for (var i=0; i<ile; i++) {
                 kom[i].style.backgroundColor = bar_0;
               }
             }
             break;
    case 0:  if(id==wi.id){
                 for(var i=0; i<ile; i++) {
                    kom[i].style.backgroundColor = bar_1;
                 }
                 id=0;
             } else {
                 if(id>0){
                     for (var i=0; i<ile; i++) {
                        document.getElementById(id).getElementsByTagName('td')[i].style.backgroundColor=bar_0;
                     }
                 }
                 id=wi.id;
                 for (var i=0; i<ile; i++) {
                    kom[i].style.backgroundColor = poz;
                 }
             }
             return true;
    case 1:  if(wi.id!=id){
               for (var i=0; i<ile; i++) {
                 kom[i].style.backgroundColor = bar_1;
               }
             }
             break;
    case 2:  id=wi.id;
             dbl_a();
             break;

  }
}

function showHideElement(show, element) {  
  if (show) {
     element.style.visibility = "visible";
     element.style.position = "relative";
  }
  else {
     element.style.visibility = "hidden";
     element.style.position = "absolute";  
  }
}

function usunKonto() {
   var wnd = window.open('_qclub_usun_konto.php', 'usun_konto', "width="+400+",height="+170+",status=yes,resizable=no,top="+50+",left="+50+",scrollbars=yes,dependent=yes,alwaysRaised=yes");
   wnd.focus();
}

function zapomnialem() {
   var wnd = window.open('_qclub_zapomnialem.php?page=1', 'usun_konto', "width="+440+",height="+260+",status=yes,resizable=no,top="+50+",left="+50+",scrollbars=yes,dependent=yes,alwaysRaised=yes");
   wnd.focus();
}

function wyslijKartke(idz) {
	window.location="_qclub_wyslij_kartke.php?idz="+idz;
}
