function search_init(classification,position,noresmes){
	var link = "http://" + window.location.host + "/json.php?";
	var strParams = "classification="+classification;
	strParams += "&noresmes=" + noresmes;
	new Autocomplete(classification + '_AddressSearch_' + position, {
		serviceUrl: link + strParams,
		classification:classification,
		position:position,
		// callback function:
		    onSelect: function(value, data){
				fillAutocompletedBoxes(classification,position,data,value);
			}
	});
}

function fillAutocompletedBoxes(classification,position,catalogId,catalogTitle){
	var catId = document.getElementById(classification+'_CatalogID_'+position);
	if(catId && catalogId != undefined){
		catId.value = catalogId;
	}
	var catTitle = document.getElementById(classification+'_CatalogTitle_'+position);
	if(catTitle && catalogTitle != undefined){
		catTitle.value = catalogTitle;
	}
	return true;
}

function activateEntry(obj){
	obj.className = "suggest_entry suggest_entry_selected";
}

function deactivateEntry(obj){
	obj.className = "suggest_entry";
}

function hideSearchDiv(classification,position){
	myDiv = document.getElementById(classification+'_suggest_popup_'+position);
	myDiv.innerHTML = "";
	myDiv.style.display = "none";
}

function selectEntry(id,title,classification,position){
	document.getElementById(classification+'_AddressSearch_'+position).value = title;
	document.getElementById(classification+'_CatalogTitle_'+position).value = title;
	document.getElementById(classification+'_CatalogID_'+position).value = id;
	hideSearchDiv(classification,position);
}

function clearData(classification,id,position){
	var posAdd = "";
	if(position){
		posAdd = "_" + position;
	}
	switch(classification){
		case "accommodation":
			document.getElementById(classification+"_Duration").value = "";
			document.getElementById("AvailabilityDate"+posAdd).value = "";
			document.getElementById(id).style.display = "none";
		break;
		case "hotel":
			document.getElementById(id).value = "";
			document.getElementById("cldata_"+id).style.display = "none";
		break;
	}
}

function selectData(classification,id,lang,postfix){
	switch(classification){
		case "accommodation":
			show_calendar(id,lang);
			if(!document.getElementById(classification+"_Duration").value)
				document.getElementById(classification+"_Duration").value = "7";
			document.getElementById("cldata").style.display = "";
		break;
		case "hotel":
			show_calendar(id,lang);
			if(document.getElementById("hotelRoomsData" + postfix)){
				if(document.getElementById("hotelRoomsData" + postfix).innerHTML)
					document.getElementById("hotelRoomsData" + postfix).innerHTML = "";
			}

			if(document.getElementById("cldata_"+id))
				document.getElementById("cldata_"+id).style.display = "";
		break;
	}
}

function setPrice(classification){
	switch(classification){
		case "accommodation":
			if(document.getElementById("MaxPrice").value){
				var reg=/^\d+$/;
				if(reg.test(document.getElementById("MaxPrice").value)){
					document.getElementById("MaxPrice").value = document.getElementById("MaxPrice").value+".00";
				}
			}
		break;
		case "hotel":
			if(document.getElementById("maxTotalPrice").value){
				var reg=/^\d+$/;
				if(reg.test(document.getElementById("maxTotalPrice").value)){
					document.getElementById("maxTotalPrice").value = document.getElementById("maxTotalPrice").value+".00";
				}
			}
		break;
	}
}

function checkFields(classification, isAddressMandatory, position){
	var posAdd = "";
	if(position){
		posAdd = "_" + position;
	}

	if(document.getElementById("t_"+classification).value == 1){
		alert(lang_s["error.searchInProgress"]);
		return false;
	}

	var loadBox = document.getElementById("load_"+classification);
	if(loadBox && loadBox.style.display == ""){
		alert(lang_s["error.searchInProgress"]);
		return false;
	}

	if(isAddressMandatory){
		if(document.getElementById(classification + "_CatalogID") && !document.getElementById(classification + "_CatalogID").value){
			alert(lang_s["error.selectCountry"]);
			return false;
		}
	}

	switch(classification){
		case "accommodation":
			if(document.getElementById("AvailabilityDate"+posAdd).value){
				var objStringDate = new String(document.getElementById("AvailabilityDate"+posAdd).value);
				var day = objStringDate.substr(8,2);
				var month = objStringDate.substr(5,2)-1;
				var year = objStringDate.substr(0,4);
				d1 = new Date(year,month,day);
				d = new Date();
				d.setHours(0); d.setMinutes(0); d.setSeconds(0); d.setMilliseconds(0);
				if(d1<d){
					alert(lang_s["error.availabilityDateIncorrectValue"]);
					return false;
				}
			}
			if(document.getElementById(classification+"_Duration").value && !document.getElementById("AvailabilityDate"+posAdd).value){
				document.getElementById(classification+"_Duration").value = ""; // default duration if date not selected
			}
			if(!document.getElementById(classification+"_Duration").value && document.getElementById("AvailabilityDate"+posAdd).value){
				document.getElementById(classification+"_Duration").value = 7; // default duration if date selected
			}

			if(document.getElementById(classification+"_Duration") && document.getElementById(classification+"_Duration").value){
				var reg=/^\d+$/;
				if(!reg.test(document.getElementById(classification+"_Duration").value)){
					alert(lang_s["error.durationIncorrectValue"]);
					return false;
				}
			}
			if(document.getElementById("MaxPrice") && document.getElementById("MaxPrice").value){
				var reg=/^\d+[.,]?\d{1,2}$/;
				if(!reg.test(document.getElementById("MaxPrice").value)){
					alert(lang_s["error.maxPriceIncorrectValue"]);
					return false;
				}
			}
			if(document.getElementById("beach") && document.getElementById("beach").value){
				var reg=/^\d+$/;
				if(!reg.test(document.getElementById("beach").value)){
					alert(lang_s["error.beachIncorrectValue"]);
					return false;
				}
			}
			if(document.getElementById("bedrooms") && document.getElementById("bedrooms").value){
				var reg=/^\d+$/;
				if(!reg.test(document.getElementById("bedrooms").value)){
					alert(lang_s["error.bedroomsIncorrectValue"]);
					return false;
				}
			}

			if(document.getElementById("railway") && document.getElementById("railway").value){
				var reg=/^\d+$/;
				if(!reg.test(document.getElementById("railway").value)){
			        alert(lang_s["error.railwayIncorrectValue"]);
					return false;
				}
			}
			if(document.getElementById("golf") && document.getElementById("golf").value){
				var reg=/^\d+$/;
				if(!reg.test(document.getElementById("golf").value)){
			        alert(lang_s["error.golfIncorrectValue"]);
					return false;
				}
			}
			if(document.getElementById("autoban") && document.getElementById("autoban").value){
				var reg=/^\d+$/;
				if(!reg.test(document.getElementById("autoban").value)){
			        alert(lang_s["error.autobanIncorrectValue"]);
					return false;
				}
			}
			if(document.getElementById("elevator") && document.getElementById("elevator").value){
				var reg=/^\d+$/;
				if(!reg.test(document.getElementById("elevator").value)){
			        alert(lang_s["error.elevatorIncorrectValue"]);
					return false;
				}
			}
			if(document.getElementById("skier") && document.getElementById("skier").value){
				var reg=/^\d+$/;
				if(!reg.test(document.getElementById("skier").value)){
			        alert(lang_s["error.skierIncorrectValue"]);
					return false;
				}
			}
		break;
		case "hotel":
			if(document.getElementById("startTravelDate"+posAdd) && !document.getElementById("startTravelDate"+posAdd).value && !document.getElementById("noDate"+posAdd).checked){
				alert(lang_s["error.selectDate"]);
				return false;
			}
			if(document.getElementById("endTravelDate"+posAdd) && !document.getElementById("endTravelDate"+posAdd).value && !document.getElementById("noDate"+posAdd).checked){
				alert(lang_s["error.selectDate"]);
				return false;
			}
           /*
			if(document.getElementById(classification+"_Duration").value && !document.getElementById("startTravelDate"+posAdd).value){
				alert(lang_s["error.selectDate"]);
				return false;
			}

			if(document.getElementById(classification+"_Duration") && !document.getElementById(classification+"_Duration").value){
				alert(lang_s["error.durationIncorrectValue"]);
				return false;
			}

			if(document.getElementById(classification+"_Duration") && document.getElementById(classification+"_Duration").value){
				var reg=/^\d+$/;
				if(!reg.test(document.getElementById(classification+"_Duration").value)){
					alert(lang_s["error.durationIncorrectValue"]);
					return false;
				}

			}
           */
			if(document.getElementById("startTravelDate"+posAdd).value && document.getElementById("endTravelDate"+posAdd).value){
				var objStringDate = new String(document.getElementById("startTravelDate"+posAdd).value);
				var day = objStringDate.substr(8,2);
				var month = objStringDate.substr(5,2)-1;
				var year = objStringDate.substr(0,4);
				startDate = new Date(year,month,day);
				nowDate = new Date();
				nowDate.setHours(0); nowDate.setMinutes(0); nowDate.setSeconds(0); nowDate.setMilliseconds(0);
				if(startDate < nowDate){
					alert(lang_s["error.availabilityDateIncorrectValue"]);
					return false;
				}

				objStringDate = new String(document.getElementById("endTravelDate"+posAdd).value);
				day = objStringDate.substr(8,2);
				month = objStringDate.substr(5,2)-1;
				year = objStringDate.substr(0,4);
				endDate = new Date(year,month,day);
				nowDate = new Date();
				nowDate.setHours(0); nowDate.setMinutes(0); nowDate.setSeconds(0); nowDate.setMilliseconds(0);

				 if(endDate < nowDate){
					alert(lang_s["error.availabilityDateIncorrectValue"]);
					return false;
				}
				if(startDate >= endDate){		            var tempDate = startDate;
		            tempDate.setDate(tempDate.getDate()+1);
		            var y = tempDate.getFullYear();
					var m = tempDate.getMonth()+1;
					if(m<10)
						m = "0"+m;
					var d = tempDate.getDate();
					if(d<10)
						d = "0"+d;
					document.getElementById("endTravelDate"+posAdd).value = y+"-"+m+"-"+d;
				}

			}

			if(document.getElementById(classification + "_Persons") && !document.getElementById(classification + "_Persons").value){
				alert(lang_s["error.personsIncorrectValue"]);
				return false;
			}

			if(document.getElementById("maxTotalPrice") && document.getElementById("maxTotalPrice").value){
				var reg=/^\d+[.,]?\d{1,2}$/;
				if(!reg.test(document.getElementById("maxTotalPrice").value)){
					alert(lang_s["error.maxPriceIncorrectValue"]);
					return false;
				}
			}
		break;
	}


	if(document.getElementById(classification + "_Persons") && document.getElementById(classification + "_Persons").value){
		var reg=/^\d+$/;
		if(!reg.test(document.getElementById(classification + "_Persons").value)){
			alert(lang_s["error.personsIncorrectValue"]);
			return false;
		}
	}

	document.getElementById("t_"+classification).value = 1;
	return true;
}

function setPage(page,classification){
	document.getElementById('page').value=page;
	doSearch(page,classification);
}
function setDaysList(value,t,p)
{   if(t!="")
     t = "_"+t;
   var selDate = document.getElementById(p+"TravelDate"+t+"Day").value;
   var year = value.substr(0,4);
   var month = parseInt(value.substr(5,2))-1;
   var count = 32 - new Date(year, month, 32).getDate();
   if(!count)
   	count = 31;
   if(selDate>count)
   	 selDate = 1;
   document.getElementById(p+"TravelDate"+t+"Day").options.length = count+1;
   var option = new Option('---',0);
   document.getElementById(p+"TravelDate"+t+"Day").options[0]=option;
   for(var i=1;i<=count;i++)
   {   	  var v = i;
   	  if(v<10)
   	  	v = "0"+v;
      var option = new Option(i,v);
   	  document.getElementById(p+"TravelDate"+t+"Day").options[i]=option;   }
   document.getElementById(p+"TravelDate"+t+"Day").value = selDate;
}
function setEndDate(value,type,position)
{	var posAdd = "";
	var pEnd = "end";
	var pStart = "start";
	var date = "";
	if(position){
		posAdd = "_" + position;
	}
	else
	{		pEnd = "hotelEnd";
		pStart = "hotelStart";	}
   	if(!value)
   		return;
    var month = "";
    var day = "";
    if(document.getElementById(pEnd+'TravelDate'+posAdd+'YearMonth').value && document.getElementById(pEnd+'TravelDate'+posAdd+'Day').value)
    {
    	var d = document.getElementById(pEnd+'TravelDate'+posAdd+'Day').value;
    	var endDate = new Date(document.getElementById(pEnd+'TravelDate'+posAdd+'YearMonth').value+"-"+d);
		d = document.getElementById(pEnd+'TravelDate'+posAdd+'Day').value;
    	var startDate = new Date(document.getElementById(pStart+'TravelDate'+posAdd+'YearMonth').value+"-"+d);
    	if(startDate=="Invalid Date" || endDate =="Invalid Date")
    		return;
    	if(startDate<endDate)
    		return;
    }
    if(type=='day' && document.getElementById(pStart+'TravelDate'+posAdd+'YearMonth').value)
    {      var str = parseInt(value)+1;
      if(str<10)
      	str = "0"+str;
      day = str;
      month = document.getElementById(pStart+'TravelDate'+posAdd+'YearMonth').value;
      date = new Date(document.getElementById(pStart+'TravelDate'+posAdd+'YearMonth').value+"-"+str);
      if(date=="Invalid Date")
      {
      	var index = document.getElementById(pStart+'TravelDate'+posAdd+'YearMonth').selectedIndex;
      	if(!document.getElementById(pStart+'TravelDate'+posAdd+'YearMonth').options[index+1])
      		return;
      	//date = new Date(document.getElementById('startTravelDate_'+position+'YearMonth').options[index+1].value+"-01");
	    month = document.getElementById(pStart+'TravelDate'+posAdd+'YearMonth').options[index+1].value;
	    day = "01";
      }
    }

    if(type=='month' && document.getElementById(pStart+'TravelDate'+posAdd+'Day').value)
    {
      var str = parseInt(document.getElementById(pStart+'TravelDate'+posAdd+'Day').value)+1;
      if(str<10)
      	str = "0"+str;
      month = value;
      day = str;
      date = new Date(value+"-"+str);
      if(date=="Invalid Date")
      {       	var index = document.getElementById(pStart+'TravelDate'+posAdd+'YearMonth').selectedIndex;
      	if(!document.getElementById(pStart+'TravelDate'+posAdd+'YearMonth').options[index+1])
      		return;
      	//date = new Date(document.getElementById('startTravelDate_'+position+'YearMonth').options[index+1].value+"-01");
	    month = document.getElementById(pStart+'TravelDate'+posAdd+'YearMonth').options[index+1].value;
	    day = "01";
      }
    }
      if(month && day)
      {
      	 document.getElementById(pEnd+'TravelDate'+posAdd+'YearMonth').value=month;
      	 document.getElementById(pEnd+'TravelDate'+posAdd+'Day').value=day;
      	 setDaysList(document.getElementById(pEnd+'TravelDate'+posAdd+'YearMonth').value,position,pEnd);
      }

}
function doSearch(page,classification){
	try{
		var strParams = this.query;
		strParams += "&p="+page;
		var link = lang_s["URL"]+"ajax.php?grandparent=site";
		strParams += "&a="+0;
		strParams += "&m=accommodation_search";
		strParams += "&classification="+classification;
		document.getElementById("load_"+classification).style.display="";
		document.getElementById("divDisplaySearchResults_"+classification).style.display="none";
		//document.getElementById("ñh").disabled=true;
		new Ajax.Updater("divDisplaySearchResults_"+classification, link + strParams,
		    { onComplete: function () {
		        document.getElementById("load_"+classification).style.display = "none";
				document.getElementById("divDisplaySearchResults_"+classification).style.display="block";
		      }
		    }
		);
    }catch(e){
    	alert(e.toString());
    }
}

function showRooms(id,mode,startTravelDate,endTravelDate,postfix,itemUrl,noDate){
	try{
		var strParams = "";
		var link = lang_s["URL"]+"ajax.php?grandparent=site";
		strParams += "&m=accommodation_hotels";
		strParams += "&serviceId="+id;
		switch(mode){
			case "singleHotel":
				if(document.getElementById("hotelStartTravelDate" + postfix) && document.getElementById("hotelEndTravelDate" + postfix) && document.getElementById("hotelRoomsData" + postfix) && document.getElementById("hotelRoomsDataHeader" + postfix)){
					strParams += "&a=120";
					strParams += "&startTravelDate="+document.getElementById("hotelStartTravelDate" + postfix).value;
//					strParams += "&Duration="+document.getElementById("hotelDuration" + postfix).value;
					strParams += "&endTravelDate="+document.getElementById("hotelEndTravelDate" + postfix).value;
					//strParams += "&noDate="+document.getElementById("noDate" + postfix).value;
					document.getElementById("hotelRoomsData" + postfix).style.align = "center";
					document.getElementById("hotelRoomsData" + postfix).innerHTML = "<table width=100%><tr><td width=47%>&nbsp;</td><td width=16px; padding=0px><img style='width:16px;border:0px;' src=\"/images/loading.gif\"/></td><td padding=0px width=100% align='left'>"+lang_s["label.common.ajaxLoading"]+"</td></tr></table>";
					document.getElementById("hotelRoomsDataHeader" + postfix).style.display = "block";
					if(postfix && postfix != undefined)
						link = link + "&postfix=" + postfix;
					var objAj = new Ajax.Updater("hotelRoomsData" + postfix, link + strParams);
				}
			break;
			default:
				strParams += "&a=110";
				strParams += "&startTravelDate="+startTravelDate;
				strParams += "&endTravelDate="+endTravelDate;
//				strParams += "&Duration="+Duration;
				strParams += "&noDate="+noDate;
				strParams += "&itemUrl="+itemUrl;
				document.getElementById("hotelRooms_"+id).style.align = "center";
				document.getElementById("hotelRooms_"+id).innerHTML = "<table width=100%><tr><td width=47%>&nbsp;</td><td width=16px; padding=0px><img style='width:16px;border:0px;' src=\"/images/loading.gif\"/></td><td padding=0px width=100% align='left'>"+lang_s["label.common.ajaxLoading"]+"</td></tr></table>";
				new Ajax.Updater("hotelRooms_"+id, link + strParams,
				    { onComplete: function () {
				        document.getElementById("controllerLink_"+id).style.display = "none";
				      }
				    }
				);
		}

    }catch(e){
    	alert(e.toString());
    }
}

function doHotelsBooking(type,hotelId,roomId,url){
	var arrivalDate = formatDate(document.getElementById('startTravelDate').value);
	var departureDate = formatDate(document.getElementById('endTravelDate').value);
	//var duration = document.getElementById('hotel_Duration').value;
	var persons = document.getElementById('hotel_Persons').value;
    var locationUrl = url + "&arrivalDate="+arrivalDate+"&departureDate=" + departureDate +
			"&persons=" + persons + "&type="+type + "&provider=bkg&serviceId="+hotelId+"&serviceRooms="+roomId+"&serviceRoomsCount=1";
	acePopup(locationUrl,'Booking',800,600);
}

function formatDate(strDate){
	var inDate = new String(strDate);
	var year = inDate.substr(0,4);
	var month = inDate.substr(5,2);
	var day = inDate.substr(8,2);
	objStringDate = day+"."+month+"."+year;
	return objStringDate;
}

function checkHotelFields(RoomId,postfix){
	if(postfix == undefined)
		postfix = "";
	if(document.getElementById("hotelStartTravelDate" + postfix) && !document.getElementById("hotelStartTravelDate" + postfix).value){
		alert(lang_s["error.selectDate"]);
		return false;
	}
	if(document.getElementById("hotelEndTravelDate" + postfix) && !document.getElementById("hotelEndTravelDate" + postfix).value){
		alert(lang_s["error.selectDate"]);
		return false;
	}
/*
	if(document.getElementById("hotelDuration" + postfix) && document.getElementById("hotelDuration" + postfix).value && !document.getElementById("hotelStartTravelDate" + postfix).value){
		alert(lang_s["error.selectDate"]);
		return false;
	}

	if(document.getElementById("hotelDuration" + postfix) && !document.getElementById("hotelDuration" + postfix).value){
		alert(lang_s["error.durationIncorrectValue"]);
		return false;
	}

	if(document.getElementById("hotelDuration" + postfix) && document.getElementById("hotelDuration" + postfix).value){
		var reg=/^\d+$/;
		if(!reg.test(document.getElementById("hotelDuration" + postfix).value)){
			alert(lang_s["error.durationIncorrectValue"]);
			return false;
		}
	}
*/
	if(document.getElementById("hotelEndTravelDate" + postfix) && document.getElementById("hotelStartTravelDate" + postfix) && document.getElementById("hotelStartTravelDate" + postfix).value && document.getElementById("hotelEndTravelDate" + postfix).value){
		var objStringDate = new String(document.getElementById("hotelStartTravelDate" + postfix).value);
		var day = objStringDate.substr(8,2);
		var month = objStringDate.substr(5,2)-1;
		var year = objStringDate.substr(0,4);
		startDate = new Date(year,month,day);
		nowDate = new Date();
		nowDate = new Date();
		nowDate.setHours(0); nowDate.setMinutes(0); nowDate.setSeconds(0); nowDate.setMilliseconds(0);
		if(startDate.valueOf() < nowDate.valueOf()){
			alert(lang_s["error.availabilityDateIncorrectValue"]);
			return false;
		}

		objStringDate = new String(document.getElementById("hotelEndTravelDate" + postfix).value);
		day = objStringDate.substr(8,2);
		month = objStringDate.substr(5,2)-1;
		year = objStringDate.substr(0,4);
		endDate = new Date(year,month,day);
		nowDate = new Date();
		nowDate = new Date();
		nowDate.setHours(0); nowDate.setMinutes(0); nowDate.setSeconds(0); nowDate.setMilliseconds(0);
		if(endDate.valueOf() < nowDate.valueOf()){
			alert(lang_s["error.availabilityDateIncorrectValue"]);
			return false;
		}
		if(endDate<=startDate)
		{
            var tempDate = startDate;
            tempDate.setDate(tempDate.getDate()+1);
            var y = tempDate.getFullYear();
			var m = tempDate.getMonth()+1;
			if(m<10)
				m = "0"+m;
			var d = tempDate.getDate();
			if(d<10)
				d = "0"+d;
			document.getElementById("hotelEndTravelDate"+postfix).value = y+"-"+m+"-"+d;
		}

	}
	showRooms(RoomId,"singleHotel","","",postfix,"");
}

function prepareBookingForHotel(type,hotelId,url,arrivalDate,depDate,postfix){
	var roomsList = document.getElementsByName("roomsList_"+hotelId + postfix);
	var roomId;
	var requestRooms = "";
	var requestRoomsCount = "";
	var requestPersons = 0;
	for(var i=0;i<roomsList.length;i++){
		roomId = roomsList[i].value;
		selIndex = document.getElementById("roomsCounter_"+roomId + postfix).selectedIndex;
		if(selIndex){
			if(requestRooms)
				requestRooms += ",";
			requestRooms += roomId;

			if(requestRoomsCount)
				requestRoomsCount += ",";
			requestRoomsCount += selIndex;

			requestPersons = requestPersons + (parseInt(document.getElementById("roomsMaxPersons_"+roomId + postfix).value)*selIndex);
		}
	}

	if(requestRooms && requestRoomsCount && requestPersons){
		var arrivalDate = formatDate(document.getElementById(arrivalDate).value);
		var departureDate = formatDate(document.getElementById(depDate).value);
	    var locationUrl = url + "&arrivalDate="+arrivalDate+"&departureDate=" + departureDate +
				"&persons=" + requestPersons + "&type="+type + "&provider=bkg&serviceId="+hotelId+"&serviceRooms="+requestRooms+"&serviceRoomsCount="+requestRoomsCount;
		acePopup(locationUrl,'Booking',800,600);
	}else{
		alert(lang['alert.selectRoomsToBook']);
		return false;
	}
}

function setNextDay(id,changedId){
	try{
		if(document.getElementById(changedId).value == ""){
			objStringDate = new String(document.getElementById(id).value);
			day = objStringDate.substr(8,2);
			month = objStringDate.substr(5,2)-1;
			year = objStringDate.substr(0,4);
			objDate = new Date(year,month,day);
			objDate.setDate(objDate.getDate()+1);
			alert(objDate);
			alert(objDate.toString());

			document.getElementById(changedId).value
		}
    }catch(e){
    	alert(e.toString());
    }
}

function handleRoomInfo(id){
	var roomInfo = document.getElementById(id);
	var showMinus = true;
	if(roomInfo){
		if(roomInfo.style.display == "none"){
			roomInfo.style.display = "block";
		}else{
			roomInfo.style.display = "none";
			showMinus = false;
		}
	}
	return showMinus;
}

function preLoadSearchBoxes(IsCityTemplate,classification,formExists){
	try{
		var strParams = "";
		var link = lang_s["URL"]+"ajax.php?grandparent=site";
		strParams += "&m=accommodation_search";
		strParams += "&a=13";
		strParams += "&classification="+classification;
		strParams += "&wrapper=1&inner=index&IsCityTemplate="+IsCityTemplate+"&formExists="+formExists;
		var objAj = new Ajax.Updater('search_boxes_wrapper', link + strParams, {evalScripts: true});
    }catch(e){
    	alert(e.toString());
    }
}

/*
 *
 */
function setActiveTab(classification,contentNodes,tabActive){
	var index = 0;
	var activeClassName = "ai_active";
	var className = "ai";
	for (key in contentNodes) {
	    var topItem = document.getElementById(key);
	    if (!topItem) {
//       alert("Can't find element with ID:" + key);
	       return;
	    }

	    var targetItem = document.getElementById(contentNodes[key]);
	    if (!targetItem) {
//       alert("Can't find element with ID:" + params.nodes[key]);
	       return;
	    }

	    if ((tabActive && tabActive == key) || (index == 0 && !tabActive)) {
	      if (activeClassName) {
	        topItem.className = activeClassName;
	      }
	      targetItem.style.display = "";
	    } else {
	      if (className) {
	        topItem.className = className;
	      }
	      targetItem.style.display = "none";
	    }

	    index++;
	}
}

/*
 *   window onload listener
 */
function addWindowOnloadEvent(customFunction,args){
	if (window.addEventListener) /* W3C */
		window.addEventListener("load", function(){
							customFunction(args)
					}, true);
	else
		if (window.attachEvent) /* IE */
			window.attachEvent("onload", function(){
							customFunction(args)
						});
		else
			window.onload = function(){
						customFunction(args)
				};
}

/*
 *   window document body onload listener
 */
function addOnloadEvent(customFunction,args){
	if (window.document.body.addEventListener){ /* W3C */
		window.document.body.addEventListener("load", function(){
							customFunction(args)
					}, true);
	}else{
		if (window.attachEvent){ /* IE */
			window.attachEvent("onload", function(){
							customFunction(args)
						});
		}else{
			window.document.body.onload = function(){
						customFunction(args)
				};
		}
	}
}

function sortObjects(type){
	document.getElementById('sorttype').value=type;
	document.getElementById('link').value=document.location;
	document.sortform.submit();
}

function handleAcmdSearch(id, lblId, lblMore, lblSimple){
	var searchBox = document.getElementById(id);
	var searchLabel = document.getElementById(lblId);
	if(searchBox){
		if(searchBox.style.display == "none"){
			searchBox.style.display = "block";
			if(lblId && searchLabel)
				searchLabel.innerHTML = lblSimple;
		}else{
			searchBox.style.display = "none";
			if(lblId && searchLabel)
				searchLabel.innerHTML = lblMore;
		}
	}
}

	function selectSTab(aTab,position){
		var tabConf;
		var tabTopConf = {
							'tab_accommodation_top':'contentCottages_top',
							'tab_hotel_top':'contentHotel_top',
							'tab_route_top':'contentRoutes_top'
				};
		var tabLeftConf = { 'tab_accommodation_left':'contentCottages_left',
						'tab_hotel_left':'contentHotel_left',
						'tab_route_left':'contentRoutes_left'
				};
		if(position == "top")
			tabConf = tabTopConf;
		if(position == "left")
			tabConf = tabLeftConf;

		for(tab in tabConf){
			if(document.getElementById(tab) && document.getElementById(tabConf[tab])){
				if(aTab == tab){
					document.getElementById(tab).className = "on";
					document.getElementById(tabConf[tab]).style.display = "block";
				}else{
					document.getElementById(tab).className = "";
					document.getElementById(tabConf[tab]).style.display = "none";
				}
			}
		}
	}

	function setAdvSB(id,myForm,btnId){
		if(document.getElementById(id) && document.getElementById(id).style.display == "none"){
			myForm.sbm_full.value='';
			myForm.isFull.value=0;
			document.getElementById(btnId+"_adv").style.display = "none";
			document.getElementById(btnId+"_sngl").style.display = "block";
		}else{
			myForm.sbm_full.value=1;
			myForm.isFull.value=1;
			document.getElementById(btnId+"_adv").style.display = "block";
			document.getElementById(btnId+"_sngl").style.display = "none";
		}
	}

	function fillInDate(id){
		var mainDate = document.getElementById(id);
		var incomingDay = document.getElementById(id + 'Day');
		var incomingYearMonth = document.getElementById(id + 'YearMonth');
		var result = false;
		if(mainDate && incomingDay && incomingYearMonth){
			if(incomingYearMonth.value && incomingDay.value)
				mainDate.value = incomingYearMonth.value + '-' + incomingDay.value;
			else
				mainDate.value = "";

			result = true;
		}
		return result;
	}

	function getSiteList(mess){
	try{
		var val = document.getElementById("affiliate_CatalogID_top").value;
		if(!val)
		{
			alert(mess);
			return;
		}
		var link = "http://" + window.location.host+"/ajax.php?";
		var strParams = "m=affiliate&a=30&grandparent=site";
		strParams += "&id="+document.getElementById("affiliate_CatalogID_top").value;
		document.getElementById("addressSitesResult").style.display="none";
		new Ajax.Updater("addressSitesResult", link + strParams,
		    { onComplete: function () {
				document.getElementById("addressSitesResult").style.display="block";
		      }
		    }
		);
    }catch(e){
    	alert(e.toString());
    }

	}
    function setAccCatalogCook()
    {		var exdate=new Date();
		var expiredays = 90;
		var anchor = self.document.location.hash;
        if(anchor && anchor.indexOf("#ref=")>=0)
        {
            var value = anchor.substr(5);
			exdate.setDate(exdate.getDate()+expiredays);
			document.cookie="bookPartner"+ "=" +escape(value)+
			((expiredays==null) ? "" : ";expires="+exdate.toUTCString()+";path=/");
		}
    }
	function cruisesFillInSearchBoxes(boxId,paramName,paramValue,defaultValue){
		var isOK = false;
		if(paramName && paramValue){
			var link = "http://" + window.location.host+"/ajax.php?";
			var strParams = "m=accommodation_search&grandparent=site";
			strParams += "&" + paramName + "=" + paramValue;
			if(defaultValue && defaultValue != undefined)
				strParams += "&defaultValue=" + defaultValue;
			switch(paramName){
				case "shipOwner":
					strParams += "&a=200"; // get ships by ship owner id
				break;
				case "destinationType":
					strParams += "&a=210"; // get destinations by destination type id
				break;
			}
			var doc = document.getElementById(boxId);
			if(doc && doc != undefined){
				new Ajax.Updater(boxId, link + strParams,
						{
						  onCreate: function () {
							doc.disabled = true;
						  },

						onComplete: function () {
								doc.disabled = false;
								isOK = true;
						}
					}
				);
			}
		}
		return isOK;
	}

