var divSearchDetails = false;
var divTripOrder = false;

function blinkDiv(name,onOff,speed)
{
 	var objStyle = document.getElementById(name).style;
	if (objStyle) {
	   objStyle.display = 'block';
	}
  	
	var div = document.getElementById(name);
	if (!div) return false;
	
  	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;
  	}
}

var divSliderIdCurrent = 1;
 var aDivs = new Array(); 
 aDivs[0] = "table_narty"; 
 aDivs[1] = "table_tropiki";
 
function divSlider(nrDiv)
{
   if (divSliderIdCurrent < (aDivs.length-1)) divSliderIdCurrent++;
   else divSliderIdCurrent = 0;
   
   if (nrDiv==2) nrDiv=0;
   curDiv = aDivs[nrDiv];
     
   if (divSliderIdCurrent%2) {
   	  new Effect.Fade(document.getElementById(curDiv), {duration:0.5});
	  //Element.hide(curDiv);
	  window.setTimeout("divSlider("+(nrDiv+1)+")",1000);
   } else {
   	   new Effect.Appear(document.getElementById(curDiv), {duration:1.0});
	   window.setTimeout("divSlider("+(nrDiv)+")",9000);
   }
 
}

var divOperatorSliderIdCurrent = 1;
 var aOperatorDivs = new Array(); 
 aOperatorDivs[0] = "Operator1"; 
 aOperatorDivs[1] = "Operator2"; 
 aOperatorDivs[2] = "Operator3"; 
 aOperatorDivs[3] = "Operator4"; 
 aOperatorDivs[4] = "Operator5"; 
 aOperatorDivs[5] = "Operator6"; 
 aOperatorDivs[6] = "Operator7"; 
 
function divOperatorSlider(nrDiv)
{
   if (divOperatorSliderIdCurrent < (aOperatorDivs.length-1)) divOperatorSliderIdCurrent++;
   else divOperatorSliderIdCurrent = 0;
   
   if ( nrDiv == aOperatorDivs.length ) nrDiv=0;
   curDiv = aOperatorDivs[nrDiv];
     
   if (divOperatorSliderIdCurrent%2) {
   	  new Effect.Fade(document.getElementById(curDiv), {duration:0.5});
	  //Element.hide(curDiv);
	  window.setTimeout("divOperatorSlider("+(nrDiv+1)+")",1000);
   } else {
   	   new Effect.Appear(document.getElementById(curDiv), {duration:1.0});
	   window.setTimeout("divOperatorSlider("+(nrDiv)+")",3000);
   }
 
}

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;
			}
						if (divSearchDetails == false) {
						   //objStyle.display = 'none';
						   new Effect.BlindUp(document.getElementById(div), {duration:0.5})
						   document.getElementById(div+'Link').innerHTML = 'wyszukiwanie zaawansowane';

						} else {
						   //objStyle.display = 'block';//display_row('block');
						   new Effect.BlindDown(document.getElementById(div), {duration:1.0});
						   document.getElementById(div+'Link').innerHTML = 'ukryj szukanie zaawansowane';

						}	
	}

/**
* 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;
}

var formTarget='document.forms["tripOrder"].';
function sprawdz_maila( pole, warning ) { 
 		 
		 passwordBox = eval(formTarget+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 == '' ) 
			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;
   }
}
