

Array.prototype.inArray = function ( search_phrase ){

	for( var i = 0; i < this.length; i++ ){
		if( search_phrase === this[i] ){
			return true;
		}
	}
	
	return false;
}


function check_category(category){
	
	if(document.getElementById(category).value == 'T'){
		document.getElementById(category).value = '';
	}
	else{
		document.getElementById(category).value = 'T';
	}
}

function submit_search_form(odyseo_code){
	
	//alert("2");
	
	// START TODO //
	var url_params_tbl = new Array('destination','cat_1','cat_2','cat_3','cat_4',
		'cat_5','cat_6','cat_7','cat_8','cat_9','cat_10','cat_11','cat_12','cat_13',
		'cat_14','cat_15','cat_16','cat_17','cat_18','offers_type','transports_type',
		'departure','prices_price','hotels_category','maintenances_type','rooms','offers_date', 'odyseo_code', 'type_advanced'); //tablica przechowujaca kolejnosc parametrow w url
	
	var url_tbl = new Array(); // tablca przechowujaca seo parametry - z ktorej na koncu jest tworzony wlasciwy url
	
	// END TODO //
	
	var categories_tbl = new Array('cat_1','cat_2','cat_3','cat_4','cat_5','cat_6',
		'cat_7','cat_8','cat_9','cat_10','cat_11','cat_12','cat_13','cat_14','cat_15',
		'cat_16','cat_17','cat_18');
	var seo_categories_tbl = new Array('last-minute','first-minute','narty','z-karnetem-narciarskim',
		'egzotyka','rejsy','luksusowe','sylwester','majowka','promocyjne','spa','nurkowanie','dla-rodzin-z-dziecmi',
		'dla-singli','dla-nowozencow','z-ulatwieniami-dla-osob-niepelnosprawnych','blisko-rozrywki','wczesniej-taniej');
	
	
	var non_params_tbl = new Array('destination','transports_type','offers_type','maintenances_type','rooms','offers_date', 'type_advanced');
	
	var params_tbl = new Array('departure','hotels_category','prices_price', 'odyseo_code');
	var seo_params_tbl = new Array('wyjazd','standard','cena', 'kod');
	
	
	var all_values_tbl = new Array('destination','transports_type','offers_type','prices_price','departure',
		'hotels_category','maintenances_type','rooms');
	
	var exceptions_tbl = new Array('offers_date','odyseo_code','type_advanced');
	
	//http://test.inetic.pl/odyseo/wycieczki/egipt,last-minute,luksusowe,promocyjne,spa,nurkowanie,
	//dla-rodzin-z-dziecmi,dla-singli,dla-nowozencow,z-ulatwieniami-dla-osob-niepelnosprawnych,
	//blisko-rozrywki,pobytowa,AIR,wyjazd,katowice,cena,2000.00,standard,2.5,FB,3,2008-07-22.html
	
	var val_tbl = new Array('AIR','BUS','SELF',
		'pobytowa','objazdowa','cat_5',
		'advanced','small',
		'1','2','3','4','5','6','7','8','9','st','ap','fm',
		'AI','BB','FB','HB','SC','PP'
		);
	
	var seo_val_tbl = new Array('samolotowe','autobusowe','z-dojazdem-wlasnym',
		'wypoczynkowe','objazdowe','egzotyka',
		'zaawansowane','proste',
		'1os','2os','3os','4os','5os','6os','7os','8os','9os','studio','apartament','family-room',
		'all-inclusive','sniadania','sniad-ob-i-kol','sniad-i-ob-kol','wlasne','wg-programu'
		//'ai','bb','fb','hb','sc','pp'
		);
	
	var actionform = '';
	var theform = document.getElementById('search_form');

	var formlength = (theform.elements.length -2);
	
	
	for (i=0; i<theform.elements.length; i++){
		
		//alert(theform.elements[i].name);
		
		if(document.getElementById('odyseo_code')){
			if(document.getElementById('odyseo_code').value.length > 0 
				&& (theform.elements[i].name!='odyseo_code' && theform.elements[i].name!='offers_date' && theform.elements[i].name!='type_advanced')){
				continue;
			}
		}
		
		
		
		//alert('test');
		
		if(categories_tbl.inArray(theform.elements[i].name) && theform.elements[i].value == 'T'){
			 
			index_cat = categories_tbl.indexOf(theform.elements[i].name);
			theform.elements[i].value = seo_categories_tbl[index_cat];
			
			actionform = actionform + theform.elements[i].value;
			
			if(url_params_tbl.inArray(theform.elements[i].name)){
				index_url = url_params_tbl.indexOf(theform.elements[i].name);
				url_tbl[index_url] = theform.elements[i].value;	
			}
			
			/*
			if(formlength==i){
				break;
			}
			else{
				//actionform = actionform + '&'
				actionform = actionform + ','
			}
			*/
		}
		else{
				
			//alert(theform.elements[i].name);
				
			if(!categories_tbl.inArray(theform.elements[i].name)){
				
				if(all_values_tbl.inArray(theform.elements[i].name) && theform.elements[i].value!='all'){
					
						
					if(non_params_tbl.inArray(theform.elements[i].name)){
						actionform = actionform + theform.elements[i].value;
						
						if(url_params_tbl.inArray(theform.elements[i].name)){
							index_url = url_params_tbl.indexOf(theform.elements[i].name);
							
							//przepisanie zdefiniowanych seo wartosci
							if(val_tbl.inArray(theform.elements[i].value)){
								index_val = val_tbl.indexOf(theform.elements[i].value);
								url_tbl[index_url] = seo_val_tbl[index_val];
							}
							else{
								
								//if(theform.elements[i].name=='destination'){
								//	url_tbl[index_url] = theform.elements[i].value + '/';
								//}
								//else{
									url_tbl[index_url] = theform.elements[i].value;
								//}
								
							}
							
							//theform.elements[i].value = seo_val_tbl[index_val];
							//url_tbl[index_url] = theform.elements[i].value;
								
						}
						
					}
					else{
						
						
						
						if(url_params_tbl.inArray(theform.elements[i].name)){
							index_url = url_params_tbl.indexOf(theform.elements[i].name);
							
							original_name = theform.elements[i].name;
						}
						
						
						index_param = params_tbl.indexOf(theform.elements[i].name);
						theform.elements[i].name = seo_params_tbl[index_param];
						
						actionform = actionform + theform.elements[i].name + ',' + theform.elements[i].value;
						
						
						if(url_params_tbl.inArray(original_name)){
							url_tbl[index_url] = theform.elements[i].name + ',' + theform.elements[i].value;	
						}
						
					}
					
					/*
					if(formlength==i){
						break;
					}
					else{
						//actionform = actionform + '&'
						actionform = actionform + ','
					}
					*/
				}
				else{
					
					if(exceptions_tbl.inArray(theform.elements[i].name) && theform.elements[i].value.length > 0 ){
						
						//sprawdzenie czy name to data, jesli tak i dzisiejsza to nie dowawac
						
						var date = new Date();
						var d = date.getDate();
						var day = (d < 10) ? '0' + d : d;
						var m = date.getMonth() + 1;
						var month = (m < 10) ? '0' + m : m;
						var yy = date.getYear();
						var year = (yy < 1000) ? yy + 1900 : yy;
						
						fulldate = year + "-" + month + "-" + day
					 
						
						if(theform.elements[i].name == 'offers_date' && theform.elements[i].value == fulldate){
							//alert(fulldate);
						}
						else{
							
							if(non_params_tbl.inArray(theform.elements[i].name)){
								actionform = actionform + theform.elements[i].value;
								
								if(url_params_tbl.inArray(theform.elements[i].name)){
									index_url = url_params_tbl.indexOf(theform.elements[i].name);
									
									
									//przepisanie zdefiniowanych seo wartosci
									if(val_tbl.inArray(theform.elements[i].value)){
										index_val = val_tbl.indexOf(theform.elements[i].value);
										url_tbl[index_url] = seo_val_tbl[index_val];
									}
									else{
										
										url_tbl[index_url] = theform.elements[i].value;
									
									}
									
									//url_tbl[index_url] = theform.elements[i].value;	
								}
								
							}
							else{
								
								if(url_params_tbl.inArray(theform.elements[i].name)){
									index_url = url_params_tbl.indexOf(theform.elements[i].name);
									
									original_name = theform.elements[i].name;
								}
								
								
								index_param = params_tbl.indexOf(theform.elements[i].name);
								theform.elements[i].name = seo_params_tbl[index_param];
								
								actionform = actionform + theform.elements[i].name + ',' + theform.elements[i].value;
								
								
								if(url_params_tbl.inArray(original_name)){
									url_tbl[index_url] = theform.elements[i].name + ',' + theform.elements[i].value;	
								}
								
							}
							
							/*
							if(formlength==i){
								break;
							}
							else{
								//actionform = actionform + '&'
								actionform = actionform + ','
							}
							*/
						}
						
					}
					
				}	
				
			}
			
			
		}
		 
		//actionform = actionform + theform.elements[i].name + ',' + theform.elements[i].value;

		//actionform = actionform + theform.elements[i].name + '='+ theform.elements[i].value ; OLD
	}
	
	
	
	var action_url = '';
	
	//strrr = new String('region,testowy');
   //if (strrr.search("region") != -1){
	//	alert('jest');
	//}
   

	
	for( var ind = 0; ind < url_tbl.length; ind++ ){
		if(url_tbl[ind]){
			
			var str = url_tbl[ind];
			
			//alert(str);
			//alert(str.length);
			//alert(str[5]);
			
			if(ind==0){
				
				if (url_tbl[ind].search("region,") != -1){
					action_url = action_url + url_tbl[ind] + ',';
				}
				else{
					action_url = action_url + url_tbl[ind] + '/';
				}
				
			}
			else{
				action_url = action_url + url_tbl[ind] + ',';
			}
			
			//if(str[(str.length-1)] != '/'){
			//	action_url = action_url + url_tbl[ind] + ',';
			//}
			//else{
			//	action_url = action_url + url_tbl[ind];
			//}
			//alert(str[(str.length-1)]);
			
			
		}	
	}
	
	//action_url = url_tbl.toString();
	
	action_url = action_url.substr(0, (action_url.length-1));
	//alert(action_url);
	
	if(action_url.length > 0){
		actionform = 'wycieczki/' + action_url + '.html';
	}
	else{
		actionform = 'wycieczki.html';
	}
	
	/*
	if(actionform.length > 0){
		actionform = 'wycieczki/' + actionform + '.html';
	}
	else{
		actionform = 'wycieczki.html';
	}
	*/
		
	//window.location.replace('http://gacek.intertele.pl/lukaszrz/test/js/index.php?'+actionform);
	//window.location.replace('http://test.inetic.pl/odyseo/'+actionform);
	//window.location.replace('http://www.odyseo.pl/'+actionform);
	window.location.replace('http://www.odyseo.pl/'+actionform);
	
}

/**
 *
 *
 */  
function choose_offer() {
    //document.other_dates.submit();
   
    if (document.getElementById("details_offers").prices_price.value){
	 	document.getElementById("details_offers").submit();
	 }
	 else{
	 	window.location.replace('index.php');
	 }
	 
}
/**
 *
 *
 */  
function change_date_offers() {
    window.location.replace(document.other_dates.date_offers.value);
}


/**
 *
 *
 */  
function formularz_open(adres) 
  {
  noweOkno = window.open(adres, 'okienko', 'menubar=no, toolbar=no, location=no, scrollbars=no, resizable=no, status=no, width=560, height=260')
  }

//CHMURKA///////////////////////////////////////////////////////////////////////
function wyswietl(T,t){
   T.nextSibling.style.display=t?'block':'none'
  }


//POP-UP-ZDJECIA////////////////////////////////////////////////////////////////////////
function ImgWinOpen(file,title,w,h)
{
     look='';
     sbars = 0;
     resize = 0;
     if(w > screen.availWidth)
     {
     		w = screen.availWidth-30;
     		sbars = 1;
     		resize = 1;
     }
     if(h > screen.availHeight)
     {
     		h = screen.availHeight-60;
     		sbars = 1;
     		resize = 1;
     }
     
	  look = 'scrollbars='+sbars+', resizable='+resize+', width='+w+',height='+h+'';
     newWin = window.open(file,'newWindow','toolbar=0,location=0,'+look);
	  newWin.document.write("<html><head><title>"+title+"</title></head>");
	  newWin.document.write("<body leftmargin=0 rightmargin=0 topmargin=0 bottommargin=0 marginwidth=0 marginheight=0 margin=0 onClick='window.close();' style='cursor:pointer;'><img src=" +file+ " / alt='Kliknij, aby zamknąć okno'>");
	  newWin.document.write("</body></html>");
	 
}
 
 

////////////////////////////////////////////////////////////////////////////////  
function subskrypcja_box()
  {
  if (document.getElementById("e_mail").value)
    {
    document.getElementById("formularz_subskrypcja").submit();
    }
  else
    {
    alert("wpisz poprawnie adres e-mail");
    } 
  }


////////////////////////////////////////////////////////////////////////////////  
function szukaj(page)
  {

   //var komunikat="";
	//if(document.formularz_search.sentence.value=="") komunikat="* Wpisz szukaną frazę?";
	//if(document.formularz_search.sentence.value.length < 3) komunikat+="* Wpisana fraza jest za krótka ( min.3 znaki )";
	//if( komunikat!="") {
	//	alert(komunikat);
	//	return false;
	//}
	
	//if (page){
		//document.formularz_search.action='index.php?action=search&page='+page+'';
	//}
	
	document.formularz_search.submit();
  }


////////////////////////////////////////////////////////////////////////////////
function biuletyn()
  {
  
  var komunikatBledu="" ;
  var komunikatBledu1="" ;
  var komunikatBledu2="" ;
  var komunikatBledu3="" ;

  if (document.getElementById("wiek").value=="") komunikatBledu1 += "Proszę wypełnić pole: Firma\n\n" ;
	if (document.getElementById("status").value=="") komunikatBledu2 += "Proszę wypełnić pole: Login\n\n" ;
	if (document.getElementById("wojewodztwo").value=="") komunikatBledu3 += "Proszę wypełnić pole: Hasło\n\n" ;
  
  
	
//	if (document.getElementById("status").value=="0") 
//    {komunikatBledu += "*Status\n" ;}
	
//	if (document.getElementById("wojewodztwo").value=="0") 
//    {komunikatBledu += "*Wojewdztwo\n" ;}
	
//	if (document.getElementById("wellness").value=="0") 
//    {komunikatBledu += "*Wellness\n" ;}
	
//	alert ("asdasdasd");
	
  if (komunikatBledu != "") 
    { 
    komunikatBledu = komunikatBledu ; 
    alert(komunikatBledu);
    }
	else
    {
    document.getElementById("formularz_biuletyn").submit();
    }	 
 
  }
  
  
///////////////////////////////////////////////////////////////////////////////
function pop_up(plik,tytul,w,h) 
{	
var pl=plik;
var title=tytul;
var hight=h;
var width=w;
newWin =window.open(pl, title,'height='+hight+', width='+width+',resizable=yes,scrollbars=yes,screenX=0,screenY=0');
}



/////WYSOKOSC DIVOV/////////////////////////////////////////////////////////////
function div_home() { 
    
	var left = document.getElementById('left');
	var center = document.getElementById('center');
	var right = document.getElementById('right'); 
 
	  
	var left_h = left.offsetHeight;
	var center_h = center.offsetHeight;
	var right_h = right.offsetHeight;
     
   
	var maks; 
    
	maks = Math.max(left_h,center_h,right_h)
    
	left.style.height = maks +"px";
	center.style.height = maks +"px";
	right.style.height = maks +"px";
}



function div_page() { 
    
    var left = document.getElementById('left');
  	var content = document.getElementById('box_content');
    
 
	  
	  var top_h = left.offsetHeight;
    var content_h = content.offsetHeight;
	  
     
   
    var maks; 
    
    maks = Math.max(top_h,content_h)
    
    left.style.height = maks +"px";
    content.style.height = maks +"px";
  
}




function divy_consensus() { 
    var okno= new Array (); 
  
    var top = document.getElementById('top');
  	var box_location = document.getElementById('box_location');
    var box_content = document.getElementById('box_content'); 
    var box_promotion = document.getElementById('box_promotion'); 
    
    var suma_box;
	  var roznica;
	  
	  var top_h = top.offsetHeight;
    var box_location_h = box_location.offsetHeight;
	  var box_content_h = box_content.offsetHeight;
    var box_promotion_h = box_promotion.offsetHeight;
   
    okno = getPageSize();
 
    suma_box=top_h + box_location_h + box_content_h + box_promotion_h;
  
    if (suma_box < okno[1]){
   
      var test1 = document.body.scrollHeight;
      var test2 = document.body.offsetHeight;
      
      roznica = (okno[1] - suma_box);
      //alert('roznica = ' + roznica);
      box_promotion.style.marginTop = (roznica) + "px";
      //box_promotion.style.background = "ffffff";
      
      var test3 = document.body.scrollHeight;
      //var test4 = document.body.offsetHeight;
      
      box_promotion.style.marginTop = (roznica - (test1 - test3)) + "px";
    
    }
   
}

///ROZMIAR STRONY///////////////////////////////////////////////////////////////
function getPageSize(){
  var windowWidth, windowHeight;
  
  if (self.innerHeight) {    // all except Explorer
    windowWidth = self.innerWidth;
    windowHeight = self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
  } else if (document.body) { // other Explorers
      windowWidth = document.body.clientWidth;
      windowHeight = document.body.clientHeight;
  }    
  
  
  //alert (windowWidth);
  //alert (windowHeight);
  
  var arrayPageSize = new Array(windowWidth,windowHeight); 
  return arrayPageSize;
  }

