var sel_pos = 0;
var sel_pos2 = 0;
function sel_item(id) {
	if (sel_pos !=0)
		$('kat_'+sel_pos).style.display = 'none';
	sel_pos = id;
	$('kat_'+id).style.display = 'block';
}

function sel_poditem(id) {
	if (sel_pos2 !=0)
		$('kat_'+sel_pos2).style.display = 'none';
	sel_pos2 = id;
	$('kat_'+id).style.display = 'block';
}

function oferta_ajax(id) {

	$('oferta_body').innerHTML='Trwa ładowanie strony...';
	new Ajax.Updater('oferta_body', 'ajax_resp/oferta.php?id='+id, {asynchronous:true});
}

function show_oferta(id) {
	$('oferta_body').innerHTML='Trwa ładowanie strony...';
	new Ajax.Updater('oferta_body', 'ajax_resp/show_oferta.php?id='+id, {asynchronous:true});
	
}

function onlyDigits(evt)
    {
     var keycode;
     
      if (evt)
        ;
      else if (window.event)
        evt = window.event;
      else if (event)
        evt = event;
      else
        return true;
 
      if(evt.altKey) return true;
      if(evt.ctrlKey) return true;
 
      if (evt.charCode)
        keycode = evt.charCode;
      else if (evt.keyCode)
        keycode = evt.keyCode;
      else if (evt.which)
        keycode = evt.which;
      else
        keycode = 0;
      return ((keycode == 8) || (keycode >= 13 && keycode <= 57));
    }
    
function valid_search()
    {
    	var od = $('od').value;
    	
    	var dod = $('do').value;
    	var kraj = $('kraj').value;
    	var region = $('region').value;
    	var szukajw = $('szukajw').value;
    	var slowo = $('slowo').value;
    	var czas = $('czas').value;
    	
    	if(od=='' && dod=='' && slowo == '' && kraj == 0 && region == 0 && szukajw ==0 && czas ==0)
    	{	
    		alert("Musisz podać przynajmniej jedno kryterium");
    		
    		return false;
    	}
    	else
    		return true;
    }
    
 function valid_newsletter() 
 {
 	if(!validMail('emial'))
    		return false;
    	
 	
 	
 	new Ajax.Updater('message_news', 'ajax_resp/save_newsletter.php', {asynchronous:true, parameters:Form.serialize("newsletter_form")});
 	
 	return true;	
 }
 
function validMail(email)
    {
      mail = document.getElementById(email).value;
      if(mail !="")
      {
	      pos = mail.indexOf('@');
	     
	      if((pos <= 0) || (mail.length-1 == pos)) 
	      {
	        alert('Niepoprawny adres mail');
	        return false;
	      }
      }
      
      return true;
      
    }

function valid_kontakt()
    {
    	var imie = $('imie').value;
    	
    	var nazwisko = $('nazwisko').value;
    	var ulica = $('ulica').value;
    	var miasto = $('miasto').value;
    	var kod = $('kod').value;
    	var email_zamow = $('emial_zamow').value;
    	var rodzaj = $('rodzaj').value;
    	var termin = $('termin').value;
    	var wylot = $('wylot').value;
    	var miejsce = $('miejsce').value;
    	
    	if(imie=='')
    	{	
    		alert("Musisz wypełnić pola 'Imie'");
    		
    		return false;
    	}
    	if(nazwisko=='')
    	{	
    		alert("Musisz wypełnić pola 'Nazwisko'");
    		
    		return false;
    	}
    	if(ulica=='')
    	{	
    		alert("Musisz wypełnić pola 'Ulica'");
    		
    		return false;
    	}
    	if(miasto=='')
    	{	
    		alert("Musisz wypełnić pola 'Miasto'");
    		
    		return false;
    	}
    	if(kod=='')
    	{	
    		alert("Musisz wypełnić pola 'Kod Pocztowy'");
    		
    		return false;
    	}
    	if(email_zamow=='')
    	{	
    		alert("Musisz wypełnić pola 'Email'");
    		
    		return false;
    	}
    	if(rodzaj=='')
    	{	
    		alert("Musisz wypełnić pola 'Rodzaj oferty'");
    		
    		return false;
    	}
    	if(termin=='')
    	{	
    		alert("Musisz wypełnić pola 'Termin wyjazdu'");
    		
    		return false;
    	}
    	if(wylot=='')
    	{	
    		alert("Musisz wypełnić pola 'Wylot z'");
    		
    		return false;
    	}
    	if(miejsce=='')
    	{	
    		alert("Musisz wypełnić pola 'Miejsce docelowe'");
    		
    		return false;
    	}
    	
    	
    	
    	
    	if(validMail('emial_zamow'))
    		return true;
    	else
    		return false;
    	
    }


function valid_zapytaj()
    {
    	var email = $('email_pytanie').value;
    	
    	
    	
    	if(email=='')
    	{	
    		alert("Musisz wypełnić pola 'Email'");
    		
    		return false;
    	}
    	
    	
    	
    	
    	if(validMail('email_pytanie'))
    		return true;
    	else
    		return false;
    	
    }

function valid_zamow()
    {
    	var imie = $('imie').value;
    	
    	var nazwisko = $('nazwisko').value;
    	var ulica = $('ulica').value;
    	var miasto = $('miasto').value;
    	var kod = $('kod').value;
    	var katalog = $('katalog_name').value;
    	var email = $('emial_zamow').value;
    	
    	if(imie=='')
    	{	
    		alert("Musisz wypełnić pola 'Imie'");
    		
    		return false;
    	}
    	if(nazwisko=='')
    	{	
    		alert("Musisz wypełnić pola 'Nazwisko'");
    		
    		return false;
    	}
    	if(ulica=='')
    	{	
    		alert("Musisz wypełnić pola 'Ulica'");
    		
    		return false;
    	}
    	if(miasto=='')
    	{	
    		alert("Musisz wypełnić pola 'Miasto'");
    		
    		return false;
    	}
    	if(kod=='')
    	{	
    		alert("Musisz wypełnić pola 'Kod Pocztowy'");
    		
    		return false;
    	}
    	
    	if(katalog=='')
    	{	
    		alert("Musisz wypełnić pola 'Katalog'");
    		
    		return false;
    	}
    	
    	if(email=='')
    	{	
    		alert("Musisz wypełnić pole 'Email'");
    		
    		return false;
    	}
    	
    	if(validMail('emial_zamow'))
    		return true;
    	else
    		return false;
    	
    }
    
function zipCodeMask(obj)
    {
      str = obj.value;
      len = str.length;
      if(len == 2)
      {
        obj.value += '-';
      }
      else
      if(len > 2)
      {
        if(str.charAt(2) != '-')  obj.value = str.substring(0,2) + '-' + str.substring(2,5);
      }
    }
    
