var divSearchDetails = false;
var divTripOrder = false;

function blinkDiv(name,onOff,speed)
{
    if (!document.getElementById(name)) return false;
 	var objStyle = document.getElementById(name).style;
	if (objStyle) {
	   objStyle.display = 'block';
	}
  	
  	if (onOff == 'on') {
	   if (!speed) speed = 0.5;
  	   new Effect.Opacity(name, {duration:speed, from:0.0, to:1.0});return false;
  	} else if (speed>0) {
  	   new Effect.Opacity(name, {duration:speed, from:1.0, to:0.0});return false;
  	} else {
  	   new Element.hide(name);return false;
  	}
}

function mig(div,time)
{
   new Effect.Fade(div,{duration:2.0});
   new Effect.Appear(div);

   window.setTimeout("mig('"+div+"',"+time+")",time);

}

function effectHighlight(div){
		 new Effect.Highlight(document.getElementById(div),{duration:0.3})
}

function pokaz(div,onOff)
{
 var obj = document.getElementById(div);
 if (!obj) return false;
 	 var objStyle = document.getElementById(div).style;
 	 if (objStyle) {
	    if (onOff=='off')
	 	   	objStyle.display = 'none';
		 else
		 	objStyle.display = 'block'; 
	 }
}

function pokazRow(div,onOff)
{
 	 var objStyle = document.getElementById(div).style;
 	 if (objStyle) {
	    if (onOff=='off')
	 	   	objStyle.display = 'none';
		 else
		 	objStyle.display = display_row('block'); 
	 }
}
function showOrderBox(div)
{
 		if (divTripOrder == false) {
			   divTripOrder = true;
		} else {
			   divTripOrder = false;
		}
			
		var objStyle = document.getElementById(div).style;
			if (objStyle) {
						if (divTripOrder == false) {
						   new Effect.BlindUp(document.getElementById(div), {duration:0.5})
						} else {
						   new Effect.BlindDown(document.getElementById(div), {duration:1.0});
						}
			}
}
function hideDivSearchDetails( div ) {
   			if (divSearchDetails == false) {
			   divSearchDetails = true;
			} else {
			   divSearchDetails = false;
			}
			
			var objStyle = document.getElementById(div).style;
					if (objStyle) {
						if (divSearchDetails == false) {
						   //objStyle.display = 'none';
						   new Effect.BlindUp(document.getElementById(div), {duration:0.5})
						   document.getElementById(div+'Link').innerHTML = 'Pokaż szukanie zaawansowane';
						   moveSearch();
						} else {
						   //objStyle.display = 'block';//display_row('block');
						   new Effect.BlindDown(document.getElementById(div), {duration:1.0});
						   document.getElementById(div+'Link').innerHTML = 'Ukryj szukanie zaawansowane';
						   moveSearch();
						}
					}
			
	}
var searchIsMoved = false;
function moveSearch()
{
 	if (searchIsMoved) {
 	   searchIsMoved = false;
	   x = 60;
	} else {
	  searchIsMoved = true;
	   x = -60;
	}
 	 new Effect.MoveBy( 'formSearch', x, 0, {duration:0.5} );
}
	
/**
* detekcja przegladarki
*/
function getBrowser()
{
	var ns4 = (document.layers)? true:false;
	var ns6 = (document.getElementById)? true:false;
	var ie4 = (document.all)? true:false;
	if (ie4)
	{
		if((navigator.userAgent.indexOf('MSIE 5')> 0)||(navigator.userAgent.indexOf('MSIE 6')> 0)||window.opera)
		{
			return('ie5');
		} else {
			return('ie4');
		}
		if (ns6)
		{
			ns6=false;
		}
	} 
	if (ns6) {
		return('ns6');
	} else {
		return('ns4');
	}
	
}

/**
* wyswietla/chowa wiersz tabeli w zaleznosci od przegladarki
*/
function display_row(display) {
  
	if (getBrowser()=='ns6') {
		return 'table-row';
	} else {
		return display;
	}
}

function sprawdz_szukaj()
{
 if (document.forms['szukaj'].szukaj.value.length > 2)
 {
  return true;
 } else
 {
  return false;
 }
}

function dodajDoUlubionych(adres,tytul)
{

	if (confirm("Dodać stronę do ulubionych?"))
	{
	  window.external.addFavorite(adres, tytul); 
	}
}

function przeladuj( adres )
{
      window.document.location.href = adres; 
}

// detekcja przegladarki
var ns4 = (document.layers)? true:false;
var ns6 = (document.getElementById)? true:false;
var ie4 = (document.all)? true:false;
var ie5 = false;
if (ie4)
{
	if((navigator.userAgent.indexOf('MSIE 5')> 0)||(navigator.userAgent.indexOf('MSIE 6')> 0)||window.opera)
	{
		ie5=true;
	}
	if (ns6)
	{
		ns6=false;
	}
}


// wielkosc okienka przegladarki
function browsewidth()
{
	if (ns4 || ns6)
	{
        available_width=innerWidth;
    } else {
        available_width=document.body.clientWidth;
    }
	return available_width
}

function browseheight()
{
	if (ns4 || ns6)
	{
        available_height=innerHeight;
    } else {
        available_height=document.body.clientHeight;
    }
	return available_height
}

function wlaczWarstwe(divv,onoff,wid,hei)
{
    // polozenie
	if (browsewidth()>=760)
	{
		x=((browsewidth()/2)-(wid/2));
	} else
	{
		x=300;
	}
	if (browseheight()>=500)
	{
		y=((browseheight()/2)-(hei/2));
	} else
	{
		y=300;
	}
	if ( onoff == "on" )
	{
		warstwa( divv,'on',x,y,wid,hei );
	}
	if ( onoff == "off" || onoff == null )
	{
		warstwa(divv);
	} 
    
    
}

function warstwa(nazwa,wlacz,pozx,pozy,wid,hei)
{
	// Netscape 4.x Code
	if (ns4)
	{
		objWarstwa = document.layers[nazwa];
	}
	// Netscape 6.x Code
	/*if (ns6)
	{*/
		objWarstwa = document.getElementById(nazwa);
		if (objWarstwa)
			objWarstwa = document.getElementById(nazwa).style;
		else
			return false;
	/*}
	// IE
	if (ie4 || ie5)
	{
		objWarstwa = eval(document.all[nazwa]);
		objWarstwa = objWarstwa.style;
	}*/

	if (pozx && pozy)
	{
		objWarstwa.left = pozx;
		objWarstwa.top = pozy;
		objWarstwa.width = wid;
		objWarstwa.height = hei;
	}

	if (objWarstwa && (wlacz == 'off' || wlacz == null))
	{
		if (ns4)
		{
			objWarstwa.visibility="hide";
		} else
		{
			objWarstwa.visibility="hidden";
		}
	}

	if (objWarstwa && (wlacz == 'on'))
	{
		if (ns4)
		{
			objWarstwa.visibility="show";
		} else
		{
			objWarstwa.visibility="visible";
		}
	}
}

noweokno=null;
function okno(url,nazwa,x,y,scroll,resize) {
	if (noweokno)
	{
		noweokno.close();
	}
	if (nazwa==null)
	{
		nazwa = '';
	}
	if (scroll==null)
	{
		scroll=0;
	}
	if (resize==null)
	{
		resize=0;
	}
	if (x!=null)
	{
		x1=((screen.availWidth/2)-(x/2)); y1=((screen.availHeight/2)-(y/2));
		noweokno=window.open(url,nazwa,'toolbar=0,location=0,status=0,menubar=0,scrollbars='+scroll+',resizable='+resize+',left='+x1+',top='+y1+',width='+x+',height='+y);
	} else
	{
		window.open(url,nazwa,'toolbar=0,location=0,status=0,menubar=0,scrollbars='+scroll+',resizable=yes,left=0,top=0,width='+(screen.availWidth-40)+',height='+(screen.availHeight-40));
	}
}

fotaokno=null;
function fotka( url, nazwa, x, y, scroll ) {
	if (nazwa==null)
	{
		nazwa = '';
	}
	if (scroll==null)
	{
		scroll=0;
	}
	if (noweokno)
	{
		fotaokno.close();
	}
	if (x!=null)
	{
		x1=((screen.availWidth/2)-(x/2)); y1=((screen.availHeight/2)-(y/2));
		if (x1<0)
		{
			x1=0; scroll=1; x=screen.availWidth-50; y=y+40;
		}
		if (y1<0)
		{
			y1=0; scroll=1; y=screen.availHeight-50; x=x+40;
		}
		fotaokno = window.open('','fotogaleria','toolbar=0,location=0,status=0,menubar=0,scrollbars='+scroll+',resizable=1,left='+x1+',top='+y1+',width='+x+',height='+y);
		fotaokno.document.open();
		fotaokno.document.write ('<html>'); 
		fotaokno.document.write ('<head>'); 
		fotaokno.document.write ('<title>'+nazwa+'</title>'); 
		fotaokno.document.write ('<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">'); 
		fotaokno.document.write ('</head>'); 
		fotaokno.document.write ('<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">'); 
		fotaokno.document.write ('<p align="center"><a href="javascript:void(null)" onClick="window.close();"><img src="'+url+'" border="0"></a></p>'); 
		fotaokno.document.write ('</body>'); 
		fotaokno.document.write ('</html>'); 
		fotaokno.document.close();
		fotaokno.focus();
	} else
	{
		fotaokno = window.open(url,'fotogaleria','toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1');
		fotaokno.document.open();
		fotaokno.document.write ('<html>'); 
		fotaokno.document.write ('<head>'); 
		fotaokno.document.write ('<title>'+nazwa+'</title>'); 
		fotaokno.document.write ('<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">'); 
		fotaokno.document.write ('</head>'); 
		fotaokno.document.write ('<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">'); 
		fotaokno.document.write ('<p align="center"><a href="javascript:void(null)" onClick="window.close();"><img src="'+url+'" border="0"></a></p>'); 
		fotaokno.document.write ('</body>'); 
		fotaokno.document.write ('</html>'); 
		fotaokno.document.close();
		fotaokno.focus();
	}
}

/**
* maskaOnlyDigits
*
* pozostawia w polu jedynie cyfry
*/
function  maskaInt(field) {
        var str, field;
        var myRegExp = /[^0-9]/g;
        str = field.value;
        str = str.replace(myRegExp,"");

        var oEvent = window.event;
        // pomijamy zmiany dla klawisza TAB - bo tracil sie focus
        if (oEvent && ((oEvent.which && oEvent.which!=9 && oEvent.which!=16 && oEvent.which!=37 && oEvent.which!=39) ||
           (oEvent.keyCode && oEvent.keyCode!=9 && oEvent.keyCode!=16 && oEvent.keyCode!=37 && oEvent.keyCode!=39))) {
            field.value = str;
            field.focus();

        }  else if (getBrowser()=='ns6') {
        	field.value = str;
            field.focus();
        }
}


function  maskaDaty(field) {

	var str, field;
	var myRegExp = /[^0-9]/g;
	str = field.value;
	str = str.replace(myRegExp,"");
	switch (str.length){
		case 0:
		case 1:
		case 2:
		break;
		case 3:
			str = str.substr(0,2) + "-" + str.substr(2);
		break;
		case 4:
			str = str.substr(0,2) + "-" + str.substr(2);
		break;
		case 5:
			str = str.substr(0,2) + "-" + str.substr(2,2) + "-" + str.substr(4,4);
		break;
		case 6:
			str = str.substr(0,2) + "-" + str.substr(2,2) + "-" + str.substr(4,4);
		break;
		case 7:
			str = str.substr(0,2) + "-" + str.substr(2,2) + "-" + str.substr(4,4);
		break;
		case 8:
			str = str.substr(0,2) + "-" + str.substr(2,2) + "-" + str.substr(4,4);
		break;
		default:
			str = str.substr(0,2) + "-" + str.substr(2,2) + "-" + str.substr(4,4);
		break;			
	}

        var oEvent = window.event;

        // pomijamy zmiany dla klawisza TAB - bo tracil sie focus
        if (oEvent && ((oEvent.which && oEvent.which!=9 && oEvent.which!=16) ||
           (oEvent.keyCode && oEvent.keyCode!=9 && oEvent.keyCode!=16))) {
            field.value = str;
            field.focus();

//            alert('zmiana pola: kayCode=' + oEvent.keyCode + ' which=' + oEvent.which);
        } else if (getBrowser()=='ns6') {
        	field.value = str;
            field.focus();
        }
}

function sprawdzZmianeHasla() 
{
    achtung = "";
    error=false;
    testform = false;
    if (   document.formChangePassw.username.value.length==0 
        || document.formChangePassw.old_password.value.length==0 
        || document.formChangePassw.new_password.value.length==0 
        || document.formChangePassw.new_password2.value.length==0 
        ) 
        {
            error = true;
            achtung = "Nie wypełniono wszystkich pól !";
        } else
        {
            if ( document.formChangePassw.new_password.value !=
                 document.formChangePassw.new_password2.value )
                 {
                    error = true;
                    achtung = "Podane nowe hasło jest różne w dwóch polach !";
                 }
        }

    if (error)
    {
        alert(achtung);
    } else
    {
        var testform = window.confirm("Zapisać nowe hasło ?");
    }
    return testform;
}


function sprawdz_maila( pole, warning, wymagane ) { 

		 passwordBox = pole;
		 emailok = false;
		 wzore=/^[0-9a-z.-]+(@|\(at\))+[0-9a-z._-]+\.[a-z]{2,3}$/i;// wzor emaila
		 
		 if (!(!wzore.test(passwordBox.value)) || 
		 	(passwordBox.value == '' && !wymagane) ) 
			emailok=true;
 		if (!emailok)
 		{
		  passwordBox.focus();
		  alert(warning);
		  return false;
 		} else 
		  return true;
}

function czyWypelnionePole( pole, komunikat, minLen )
{
   if (!minLen) minLen = 3;
   txtBox = eval(formTarget+pole);
   if (!txtBox) {
   	  txtBox = document.getElementById(pole);
   }
   if (txtBox) {
      if (txtBox.value.length >= minLen)
      {
       return true;
      } else
      {
       alert( komunikat );
       txtBox.focus();
       return false;
      }
   } else {
   	 //alert(pole);
   }
}
function czyWypelnioneJednoZPol( pole1, pole2, komunikat, minLen )
{
   if (!minLen) minLen = 3;
   txtBox = eval(formTarget+pole1);
   txtBox2 = eval(formTarget+pole2);
   
   if (txtBox.value.length >= minLen || txtBox2.value.length >= minLen)
   {
    return true;
   } else
   {
    alert( komunikat );
    txtBox.focus();
    return false;
   }
}

// AJAX #######################################################################

    var bSelectedMonth = false;
    function textChanger_cb(result) {
    	result = (unescape(result));
//    	alert('wynik: '+result);
        var result_array = result.split("~~|~~");
                
        if ( result_array[0] == 'Location' )
        {
        	document.location = result_array[1];
        } else {
        	document.getElementById(result_array[1]).innerHTML = result_array[0];	
        }
        wlaczWarstwe("waitIcon","off");
        var monthsWait = document.getElementById('months_wait');
        if (monthsWait) monthsWait.innerHTML = '';
        var departuresWait = document.getElementById('departures_wait');
        if (departuresWait) departuresWait.innerHTML = '';
        var countryWait = document.getElementById('country_wait');
        if (countryWait) countryWait.innerHTML = '';
        
        var x= document.getElementById("monthSelector");
                if (x) {
                  for (i=0;i<x.length;i++)
                  {
                    if ( x.options[i].value && document.getElementById('szukaj_termin').value && 
                          (x.options[i].value == document.getElementById('szukaj_termin').value) ) {
                      x.options[i].selected = true;
                      if (!bSelectedMonth) {
                        getSelectors(true);
                        bSelectedMonth = true;
                      }
                      continue;
                    }
                  }
                }
        var y = document.getElementById("departureSelector");
            if (y) {
              for (i=0;i<y.length;i++)
              {
                //alert(document.getElementById('szukaj_wyjazd').value);
                if ( y.options[i].text && document.getElementById('szukaj_wyjazd').value && 
                      (y.options[i].text == document.getElementById('szukaj_wyjazd').value) ) {
                  y.options[i].selected = true;
                  continue;
                }
              }
            } 
    }
    
    function sajaxGetTripPrice(id) {

        parseFormGetTripPrice( id, id+"_room", id+"_transport", id+"_maitenance" );

    }
    /**
	* Pobranie danych z AJAX i wyswietlenie CEN
	*/
    function parseFormGetTripPrice(cellID, roomID, transportID, maitenanceID) {
        var transportVal;
        if (document.getElementById(transportID)) transportVal = document.getElementById(transportID).value; // czy nie jest transport własny
        var st = escape(document.getElementById(roomID).value) + '~~|~~' + escape(transportVal) + '~~|~~' + escape(document.getElementById(maitenanceID).value) + '~~|~~' + cellID;
              
        document.getElementById(cellID).innerHTML = "<BR><DIV class='ajax_working'><IMG SRC='images/schemat/throbber.gif' WIDTH='16' HEIGHT='16' BORDER='0' ALT='AJAX'></DIV><BR><DIV class='update'>Pobieram dane...</DIV>";
        x_getPrice(st, textChanger_cb);
        
    }
    
    function getMonths( cellID, country ) {
        var monthWait = document.getElementById('months_wait');
        var last = document.getElementById('lastminute');
        var offerType = document.getElementById('type_hid').value;
        var bLast = 0;
        var bTour = 0;
        if (last && last.checked) bLast = 1;
        if (offerType=='wycieczki') bTour = 1;
        
        var st = escape(country) + '~~|~~' + escape(bLast) + '~~|~~' + escape(bTour) + '~~|~~' + cellID;
//        alert(st);
        
        monthWait.innerHTML = "<IMG SRC='images/schemat/throbber.gif' WIDTH='16' HEIGHT='16' BORDER='0' ALT='AJAX'>";
        x_getMonths(st, textChanger_cb);
        
    }
    function getDepartures( cellID, country ) {
        var monthWait = document.getElementById('departures_wait');
        var monthSel = document.getElementById('monthSelector');
        if (!monthSel) {
          document.getElementById(cellID).innerHTML = '<B>wybierz termin</B>';
          return;
        }
        monthSel = monthSel.value;
        var last = document.getElementById('lastminute');
        var offerType = document.getElementById('type_hid').value;
        var bLast = 0;
        var bTour = 0;
        if (last && last.checked) bLast = 1;
        if (offerType=='wycieczki') bTour = 1;
//        alert(monthSel);
        
        var st = escape(country) + '~~|~~' + escape(monthSel) + '~~|~~' + escape(bLast) + '~~|~~' + escape(bTour) + '~~|~~' + cellID;
//        alert(st);
        monthWait.innerHTML = "<IMG SRC='images/schemat/throbber.gif' WIDTH='16' HEIGHT='16' BORDER='0' ALT='AJAX'>";
        x_getDepartures(st, textChanger_cb);
        
    }
    function getDepartures2( cellID, country ) {
        var monthWait = document.getElementById('departures_wait');
        var monthSel = document.getElementById('monthSelector');
        if (!monthSel) {
          document.getElementById(cellID).innerHTML = '<B>wybierz termin</B>';
          return;
        }
        monthSel = monthSel.value;
        var last = document.getElementById('lastminute');
        var offerType = document.getElementById('type_hid').value;
        var bLast = 0;
        var bTour = 0;
        if (last && last.checked) bLast = 1;
        if (offerType=='wycieczki') bTour = 1;
//        alert(monthSel);
        
        var st = escape(country.value) + '~~|~~' + escape(monthSel) + '~~|~~' + escape(bLast) + '~~|~~' + escape(bTour) + '~~|~~' + cellID;
//        alert(st);
        monthWait.innerHTML = "<IMG SRC='images/schemat/throbber.gif' WIDTH='16' HEIGHT='16' BORDER='0' ALT='AJAX'>";
        x_getDepartures2(st, textChanger_cb);
        
    }
    function getCountry( cellID, country ) {
        var countryWait = document.getElementById('country_wait');
        var monthSel = document.getElementById('monthSelector');
        var departureSel = document.getElementById('departureSelector');
        if (!monthSel || !departureSel) {
          document.getElementById(cellID).innerHTML = '<B>wybierz termin</B>';
          return;
        }
        monthSel = monthSel.value;
        var last = document.getElementById('lastminute');
        var offerType = document.getElementById('type_hid').value;
        var bLast = 0;
        var bTour = 0;
        if (last && last.checked) bLast = 1;
        if (offerType=='wycieczki') bTour = 1;
//        alert(monthSel);
        
        var st = escape(departureSel.value) + '~~|~~' + escape(monthSel) + '~~|~~' + escape(bLast) + '~~|~~' + escape(bTour) + '~~|~~' + cellID;
//        alert(st);
        countryWait.innerHTML = "<IMG SRC='images/schemat/throbber.gif' WIDTH='16' HEIGHT='16' BORDER='0' ALT='AJAX'>";
        x_getCountries(st, textChanger_cb);
        
    }

var divSliderIdCurrent = 1;
 var aDivs = new Array();
 aDivs[0] = "ban_promocja_1";
 aDivs[1] = "ban_promocja_2";
 aDivs[2] = "ban_promocja_3";
 
function divSlider(nrDiv)
{
   if (divSliderIdCurrent < (aDivs.length-1)) divSliderIdCurrent++;
   else divSliderIdCurrent = 0;

   if (nrDiv==3) nrDiv=0;
   curDiv = aDivs[nrDiv];

   if (divSliderIdCurrent%3) {
   	  new Effect.Fade(document.getElementById(curDiv), {duration:0.5});
	  //Element.hide(curDiv);
	  window.setTimeout("divSlider("+(nrDiv+1)+")",500);
   } else {
   	   new Effect.Appear(document.getElementById(curDiv), {duration:1.0});
	   window.setTimeout("divSlider("+(nrDiv)+")",5000);
   }

}