var openedCardId=new Array()
openedCardId[0]=""
var searchType=""

var _cityLoad=new Array()
var cityXML=new ActiveXObject("Microsoft.XMLDOM")
cityXML.async=false
cityXML.load("/DATA/activeDestinationsByCountry.xml");

var windowIsOpend = false
var LOADING_STR='<body dir="'+dir+'"><table><tr><td><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"  codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="26" height="26" VIEWASTEXT="true" id="ShockwaveFlash11"><param name="movie" value="'+img_path+'flash/counter.swf"><param name="quality" value="high"><param name="wmode" value="transparent"><embed src="'+img_path+'flash/counter.swf" width="26" height="26" type="application/x-shockwave-flash"></embed></object></td><td>'+dic.LOADING_DATA+'</td></tr></table></body>'
var today="";
var onlX=null
var _activeTimer=true
var SEATS_NUM_SCORE=1000,SEATS_NUM_START=10,CALENDAR_W=409

function OpenCustomerServiceWin(){
	var top=window.screen.availHeight/2-212
	var left=window.screen.availWidth/2-358
	var CustServWin=window.open('/site/WINDOWS/CustomerService/CustomerService.asp?sitePath='+path,'CustServWin','height=425px,width=715px,top='+top+',left='+left)
	return CustServWin
}
function openCard(obj,ind){
	var cells=document.all['cardsTr'+ind].cells
	for(var i=0;i<cells.length;i++){
		var subcells=cells[i].childNodes(0).rows(0).cells
		for(var j=0;j<subcells.length;j++){
			if(cells[i]==obj) subcells[j].className=String(subcells[j].className).replace("_off","_on")
			else subcells[j].className=String(subcells[j].className).replace("_on","_off")
		}
	}
	if(!isnull(openedCardId[ind])) document.getElementById(openedCardId[ind]).style.display='none'
	document.getElementById(obj.cardId).style.display=''
	openedCardId[ind]=obj.cardId
}

/*
//////////////////////////////////////////
function swapPackageTypesDivs(value,id)
{
	var countriesSelect = document.all['countriesSelect_pse'+id]
	_cityLoad[id] = false
	if(value=="ALL"){
		countriesSelect.onclick = "fillCitiesList_Packages(this,id)"
		fillCitiesList_Packages(countriesSelect,id);
		// dispaly hotel category
		document.getElementById("HotelCategory_"+id).style.display="inline";
	}
	else{
		countriesSelect.onclick = "fillCitiesList_FlyAndDrivePackages(this,id)"
		fillCitiesList_FlyAndDrivePackages(countriesSelect,id);
		// hide hotel category
		document.getElementById("HotelCategory_"+id).style.display="none";	
	}
}
//////////////////////////////////////////
*/


function swapPackageTypesDivs(value,id)
{
	_cityLoad[id] = null;
	if (String(value)=="" || String(value)=="undefined")
	{
		var countriesSelect = document.all['countriesSelect_pse'+id];
		document.all['citiesSpan'+id].style.display='inline';
		document.all['flyanddrive_citiesSpan'+id].style.display='none';
		document.getElementById("HotelCategory_"+id).style.display="inline";
		fillCitiesList_Packages(countriesSelect,id);
	} else {
		var countriesSelect = document.all['flyanddrive_countriesSelect_pse'+id];
		document.all['citiesSpan'+id].style.display='none';
		document.all['flyanddrive_citiesSpan'+id].style.display='inline';
		document.getElementById("HotelCategory_"+id).style.display="none";	
		fillCitiesList_FlyAndDrivePackages(countriesSelect,id);
	}
}


function fillCountriesList(obj,id,type,bFlyAndDrive){
	var select=obj;
	var countries=cityXML.documentElement.selectNodes("//Country[@EN!='ISRAEL' and City/@"+type+"='1'"+(bFlyAndDrive?" and City/@FlyAndDrive='1'":" and City[not(@OnlyFlyAndDrive)] " )+"]")
	obj.length=countries.length+1
	obj[0].selected=true
	for(var i=1;i<countries.length+1;i++){
		var e = countries.nextNode();
		obj[i].text=e.getAttribute("HE")
		obj[i].value=e.getAttribute("EN")
	}	
}

// <obj>	= selected element in the countries select list. 
// <id>		= id of the select list element
// <type>	= 'p' or 'f', packages or flights
// <bFlyAndDrive>	= boolean, a fly and drive select list or not.
function fillCitiesList(obj,id,type,bFlyAndDrive)
{
	
	if(isnull(type)) type='f';
	if(!_cityLoad[id])
	{
		_cityLoad[id]=true;//cityXML.load("/DATA/activeDestinationsByCountry.xml")
		if(_cityLoad[id]) fillCountriesList(obj,id,type,bFlyAndDrive)
	}
	if(obj.value=='') return;
	var select=document.getElementById('citiesSelect_'+type+'se'+id)
	var cityes=cityXML.documentElement.selectNodes("//Country[@EN='"+obj.value+"']/City[@"+type+"='1'"+(bFlyAndDrive?" and @FlyAndDrive='1'":" and not(@OnlyFlyAndDrive) ")+"]");
	select.length=cityes.length+1
	select[0].selected=true
	for(var i=1;i<cityes.length+1;i++){
		var e = cityes.nextNode();
		select[i].text=e.getAttribute("HE")
		select[i].value=e.getAttribute("Code")
	}
}


function fillCitiesList_Ski(obj,id){
	var type='ski'
	if(!_cityLoad[id]){
		_cityLoad[id]=true;//cityXML.load("/DATA/activeDestinationsByCountry.xml")
		if(_cityLoad[id]) fillCountriesList(obj,id,type)
	}
	if(obj.value=='') return
	var select=document.getElementById('citiesSelect_pse'+id)
	var cityes=cityXML.documentElement.selectNodes("//Country[@EN='"+obj.value+"']/City[@"+type+"='1']")
	select.length=cityes.length+1
	select[0].selected=true
	for(var i=1;i<cityes.length+1;i++){
		var e = cityes.nextNode();
		select[i].text=e.getAttribute("HE")
		select[i].value=e.getAttribute("Code")
	}
}


function submitSkiMainSearch(id){
	var _yes=false
	var pr='p'
	if(document.all['citiesSelect_'+pr+'se'+id].value==""){
		alert(dic.NOT_DESTINATION)
		document.all['countriesSelect_'+pr+'se'+id].focus()
		return
	}
	if(!isnull(document.all['departureDate_'+pr+'se'+id].value)){
		document.all['OutboundDate_Start_'+pr+'se'+id].value=document.all['departureDate_'+pr+'se'+id].value
		document.all['OutboundDate_End_'+pr+'se'+id].value=document.all['departureDate_'+pr+'se'+id].value
		document.all['BestPrice_'+pr+'se'+id].value='0'
		_yes=true
	}
	if(!isnull(document.all['arrivalDate_'+pr+'se'+id].value)){
		document.all['InboundDate_Start_'+pr+'se'+id].value=document.all['arrivalDate_'+pr+'se'+id].value
		document.all['InboundDate_End_'+pr+'se'+id].value=document.all['arrivalDate_'+pr+'se'+id].value
	}
	try{ _activeTimer=false; }catch(e){}
	if(!_yes) document.all['OutboundDate_End_'+pr+'se'+id].value=EndRangeDateBySkiDestRange	
	document.all['query_'+pr+'se'+id].value='PackageDealsRequestEx'
	var fObj=document.all['form_'+pr+'se'+id]
	fObj.target=''
	fObj.action=(!isnull(fObj.realaction)?fObj.realaction:packages_action)
	fObj.submit()
}


function fillCitiesList_Israel(obj,id){
	var type='p'
	if(!_cityLoad[id]){
		_cityLoad[id]=true;//cityXML.load("/DATA/activeDestinationsByCountry.xml")
		if(!_cityLoad[id]) return
	}
	if(obj.value=='') return
	var select=document.getElementById('citiesSelect_'+type+'se'+id)
	var cityes=cityXML.documentElement.selectNodes("//Country[@EN='"+obj.value+"']/City[@"+type+"='1']")
	select.length=cityes.length+1
	select[0].selected=true
	for(var i=1;i<cityes.length+1;i++){
		var e = cityes.nextNode();
		select[i].text=e.getAttribute((lang!="HE"?"EN":"HE"))
		select[i].value=e.getAttribute("Code")
	}
}
function fillCitiesList_FlyAndDrivePackages(obj,id){ fillCitiesList(obj,id,'p',true);}
function fillCitiesList_Packages(obj,id){ fillCitiesList(obj,id,'p');}
function emptyList(id){
	var coll=document.all[id]
	if(!coll || coll.length==0) return
	for(var i=0;i<coll.length;i++){
		coll[i].value=""
		coll[i].name=""
	}
}
// bIsrael - a boolean to determine the classes used in the drawing of the calendar.
// The calendar should be blue in the Israel section.
function buildCalendar(sDate,iDatesRange,ind,cssType){
	if (!isnull(cssType)) {
		var month_class = "month_"+cssType;
	} else {
		var month_class = "month";
	}
	var sStr="",_contentExist=false,_firstMonth=true,_lastMonth=false,count=0;
	datesRange = !isnull(iDatesRange)?iDatesRange:1;
	today = new Date(sDate.replace(/-/g,'\/'))
	datesRange=Number(datesRange)	
	var endDate=new Date((today.getMonth()+datesRange)+"-"+today.getDate()+"-"+today.getYear())
	var tempDate=new Date("1-1-1900")
	tempDate.setMonth(today.getMonth())
	tempDate.setYear(today.getYear())
	var locTempDate=new Date((tempDate.getMonth()+1)+"-"+tempDate.getDate()+"-"+tempDate.getYear())
	sStr+="<table cellpadding='0' cellspacing='0' border='0'>\
			<tr id='searchByDateMonthes"+ind+"'>"
	for(;tempDate<=endDate;tempDate.setMonth(Number(tempDate.getMonth())+1)){
		locTempDate.setMonth(Number(locTempDate.getMonth())+1)
		if(locTempDate>endDate) _lastMonth=true
		sStr+="<td valign='top' style='display:"+(_firstMonth?"":"none")+";'>\
					<table cellpadding='0' cellspacing='1' border='0' class='calendar'>\
						<tr>\
							<td colspan='7'>\
								<table cellpadding='0' cellspacing='0' border='0'>\
									<tr class='"+month_class+"'>\
										<td class='calend_arrow' onclick='"+(_firstMonth?";":"showPrevMonth("+count+","+ind+")")+"'>"+(_firstMonth?"<img src='"+img_path+"trans.gif' width='13' height='12'>":"<img src='"+img_path+"search_engines/calendar_arrow_right.gif' hspace='3'>")+"</td>\
										<td class='month' width='100%' nowrap>"+dic["MONTH_"+(Number(tempDate.getMonth())+1)]+" : "+tempDate.getYear()+"</td>\
										<td class='calend_arrow' onclick='"+(_lastMonth?";":"showNextMonth("+count+","+ind+")")+"'>"+(_lastMonth?"<img src='"+img_path+"trans.gif' width='13' height='12'>":"<img src='"+img_path+"search_engines/calendar_arrow_left.gif' hspace='3'>")+"</td>\
									</tr>\
								</table>\
							</td>\
						</tr>"+monthTable(tempDate,ind,cssType)+"</table>\
				</td>"
		_contentExist=true
		_firstMonth=false
		count++
	}
	sStr+=	"</tr>\
		   </table>"
	if(_contentExist) document.write(sStr)
}

function showNextMonth(index,ind){
	document.getElementById('searchByDateMonthes'+ind).cells(index).style.display='none'
	document.getElementById('searchByDateMonthes'+ind).cells(++index).style.display=''
}
function showPrevMonth(index,ind){
	document.getElementById('searchByDateMonthes'+ind).cells(index).style.display='none'
	document.getElementById('searchByDateMonthes'+ind).cells(--index).style.display=''
}
function monthTable(dDate,ind,cssType){
	
	if (!isnull(cssType)) {
		var days_class	= "days_"+cssType;
		var days_over	= "days_over_"+cssType;
		var days		= "days_"+cssType;
	} else {
		var days_class = "days";
		var days_over	= "days_over";
		var days		= "days";
	}
	var dCurrDayInMonth=new Date("1-1-1900")
	var dLastDayInMonth=new Date("1-1-1900")
	var currDayInWeek
	var sStr=""
	with(dCurrDayInMonth){
		setYear(dDate.getYear())
		setMonth(dDate.getMonth())
		setDate(1)
	}
	with(dLastDayInMonth){
		setYear(dDate.getYear())	
		setMonth(Number(dDate.getMonth())+1)	
		setDate(0)
	}
	currDayInWeek=dCurrDayInMonth.getDay()
	sStr+="<tr class='days_in_week'>"
		for(var i=0;i<7;i++){
			sStr+="<td class='days_in_week' "+(i==0?"style='border-right:solid 0 white;'":"")+">"+dic["DAY_"+(i+1)]+"</td>"
		}
	sStr+="</tr>"
	if(currDayInWeek>0){
		sStr+="<tr class='"+days_class+"'>"
		for(var i=0;i<currDayInWeek;i++){
			sStr+="<td class='empty_day'>&nbsp;</td>"
		}
	}
	for(;dCurrDayInMonth<=dLastDayInMonth;dCurrDayInMonth.setDate(Number(dCurrDayInMonth.getDate())+1)){
		currDayInWeek=dCurrDayInMonth.getDay()
		if(currDayInWeek==0) sStr+="</tr><tr class='"+days_class+"'>"
		var sMonth=String(dCurrDayInMonth.getMonth()+1)
		if(sMonth.length<2) sMonth="0"+sMonth
		var sDay=String(dCurrDayInMonth.getDate())
		if(sDay.length<2) sDay="0"+sDay
		var sCurrDayInMonth=dCurrDayInMonth.getYear()+"-"+sMonth+"-"+sDay
		sStr+="<td class='days"+(dCurrDayInMonth<today?" notactive_day":"")+"' "
		if(dCurrDayInMonth>=today) {
			sStr+=" onmouseover='this.className=\""+days_over+"\"' onmouseout='this.className=\""+days+"\"' \
					 onclick='runSearchByDate(\""+sCurrDayInMonth+"\","+ind+")' "
		}
		sStr+=">"+dCurrDayInMonth.getDate()+"</td>"
	}
	if(currDayInWeek<6){
		for(var i=currDayInWeek;i<6;i++){
			sStr+="<td class='empty_day'>&nbsp;</td>"
		}
		sStr+="</tr>"
	}	
	return sStr
}
function runSearchByDate(sDate,ind){
	try{ _activeTimer=false;}catch(e){}
	var emptyAction=document.getElementById("emptyAction"+ind).value
	if(emptyAction=="NOFSHONIM")
	{
		emptyList('Dest_FlightsDate'+ind);
		searchType='ByDate_packages';
	}
	if(emptyAction=="FLIGHTS")
	{
		emptyList('Dest_PackagesDate'+ind);
		searchType='ByDate_flights';
	}
	if(emptyAction=="FLYANDDRIVE")
	{
		searchType='ByDate_flyanddrive';
	}
	with(document){
		getElementById("OutboundDate_Start_date"+ind).value=sDate;
		getElementById("OutboundDate_End_date"+ind).value=sDate;
	}
	
	if(pi==home_pi) Update_STAT_SEARCHENGINE(ind)
	document.getElementById("searchFormByDate"+ind).submit();
}
function openCalendar(obj,id){
	var mode=obj.mode
	var formID="detailsForm_"+id
	var dealType=obj.dealType
	if(isnull(dealType)) dealType="FLIGHTS"//"PACKAGES"
	var CALENDAR_H=460;
	var top=window.screen.availHeight/2-CALENDAR_H/2
	var left=window.screen.availWidth/2-CALENDAR_W/2
	var calendarWinFeatures = "height="+CALENDAR_H+"px,width="+CALENDAR_W+"px,top="+top+",left="+left+",center=no,status=no,scrollbars=yes,resizable=no"
	var calendarWin = window.open('about:blank','calendarWin',calendarWinFeatures)
	calendarWin.document.write(LOADING_STR)
	calendarWin.document.body.style.cursor='wait'
	var formObj=document.getElementById(formID)
	formObj.action=windows_path+"CALENDAR/calendar.asp?pi="+node_pi+"&id="+id+"&sitePath="+path
	formObj.target="calendarWin"
	formObj.submit()
	calendarWin.focus()
}

function goToFlightPriceTemplate(id,module){ goToPriceTemplate(id,false,module);}

function goToPackagePriceTemplate(id,module){ goToPriceTemplate(id,true,module);}

function goToPriceTemplate(id,bPackages,module){
	var viewIn = ""
	if(document.getElementById('view_in_'+id)) viewIn = document.getElementById('view_in_'+id).value;
	
	var oInFlightID=document.getElementById('InFlightID_'+id)
	if(isnull(oInFlightID.value)){
		alert(dic.CHOOSE_RETURN_DATE)
		return
	}
	/*
	with(document){
		getElementById('detailsForm_'+id).action='';
		getElementById('queryName_'+id).value=(bPackages?'PackageDealDetailsRequest':'FlightDealDetailsRequest');
		getElementById('detailsForm_'+id).submit();
	}*/
	with(document){
		switch(module){
			case "FLIGHTS":
				isnull(viewIn)?tempAction=flights_action:tempAction=(pagePath+"?pi="+viewIn);	
				getElementById('detailsForm_'+id).action=tempAction;
				break;
			case "ISRAEL":
				isnull(viewIn)?tempAction=israel_action:tempAction=(pagePath+"?pi="+viewIn);	
				getElementById('detailsForm_'+id).action=tempAction;
				break;
			case "PACKAGES":
				isnull(viewIn)?tempAction=packages_action:tempAction=(pagePath+"?pi="+viewIn);	
				getElementById('detailsForm_'+id).action=tempAction;
				break;
			default:
				getElementById('detailsForm_'+id).action=''
		}
		getElementById('queryName_'+id).value=(bPackages?'PackageDealDetailsRequest':'FlightDealDetailsRequest');
		getElementById('detailsForm_'+id).submit();
	}
}
function goToFlightPassengersDetailes(){
	if(document.getElementById('num_of_passengers0').value==""){
		alert(dic.CHOOSE_PASSENGERS_NUMBER)
		return
	}
	with(document){
		getElementById('step').value='_passengers_detailes';
		getElementById('query').value='FlightPriceTemplateRequest';
		getElementById('passengers_detailes').submit();
	}
}
function submitPromotionByCacheID(id,sCacheID,sMode){
	var viewIn = ""
	if(document.getElementById('view_in_'+id) && document.getElementById('view_in_'+id).value!="DEAL") viewIn = document.getElementById('view_in_'+id).value;
	
	var seatsNum=document.getElementById('seatsNum_'+id)
	if(seatsNum && seatsNum.innerText=='0') return
	var oForm=document.getElementById('detailsForm_'+id)
	switch(sMode){
		case "FLIGHTS":
			isnull(viewIn)?tempAction=flights_action:tempAction=(pagePath+"?pi="+viewIn);
			oForm.action=tempAction;
			document.getElementById('query_'+id).value="FlightDealDetailsRequest"
			break;
		case "ISRAEL":
			isnull(viewIn)?tempAction=israel_action:tempAction=(pagePath+"?pi="+viewIn);
			oForm.action=tempAction;
			document.getElementById('query_'+id).value="PackageDealDetailsRequest"
			break
		default:
			isnull(viewIn)?tempAction=packages_action:tempAction=(pagePath+"?pi="+viewIn);
			oForm.action=tempAction;
			document.getElementById('query_'+id).value="PackageDealDetailsRequest"
	}
	
	document.getElementById('step_'+id).value="_passengers_number"
	oForm.submit()
}
function submitPromotion(id,ShowOutCalendar){
	var viewIn = ""
	if(document.getElementById('view_in_'+id) && document.getElementById('view_in_'+id).value!="DEAL") viewIn = document.getElementById('view_in_'+id).value;
	
	if(isnull(ShowOutCalendar)) ShowOutCalendar=='0'
	ShowOutCalendar=String(ShowOutCalendar)
	if(ShowOutCalendar=='1'){
		document.getElementById('step_'+id).value='_search_results'
		try{
			var fareVal=document.getElementById('Fare_'+id).value
			document.getElementById('MinFare_'+id).value=fareVal
			document.getElementById('MaxFare_'+id).value=fareVal
		}catch(e){}
		switch(document.getElementById('mode_'+id).value){
			case "FLIGHTS":
				document.getElementById('query_'+id).value="FlightDealsRequestEx"
				isnull(viewIn)?tempAction=flights_action:tempAction=(pagePath+"?pi="+viewIn);
				document.getElementById('detailsForm_'+id).action = tempAction;
				break;
			case "ISRAEL":
				document.getElementById('query_'+id).value="PackageDealsRequestEx"
				isnull(viewIn)?tempAction=israel_action:tempAction=(pagePath+"?pi="+viewIn);
				document.getElementById('detailsForm_'+id).action = tempAction;
				break;
			default:
				document.getElementById('query_'+id).value="PackageDealsRequestEx"
				isnull(viewIn)?tempAction=packages_action:tempAction=(pagePath+"?pi="+viewIn);
				document.getElementById('detailsForm_'+id).action = tempAction;
		}
		document.getElementById('detailsForm_'+id).submit()
		return
	}
	var oCacheID=document.getElementById('CacheID_'+id)
	var oModeField=document.getElementById('mode_'+id)
	if(oCacheID && !isnull(oCacheID.value) && oCacheID.value != "0"){
		submitPromotionByCacheID(id,oCacheID.value,oModeField.value)
		return
	}
	var seatsNum=document.getElementById('seatsNum_'+id)
	if(seatsNum && seatsNum.innerText=='0') return
	var oForm=document.getElementById('detailsForm_'+id)
	var oStepField=document.getElementById('step_'+id)
	var oInFlightID=document.getElementById('InFlightID_'+id)	
	if(oModeField.value=="FLIGHTS"){
		if(!isnull(oInFlightID.value)){
			isnull(viewIn)?tempAction=flights_action:tempAction=(pagePath+"?pi="+viewIn);
			oForm.action=tempAction;
			oStepField.value="_passengers_number"
			document.getElementById('query_'+id).value="FlightDealDetailsRequest"
		}
		else{
			document.getElementById('query_'+id).value="FlightReturnDatesRequestEx"
			openCalendar({'mode':'RETURN'},id)
			return
		}
	}
	else{	
		if(oModeField.value=="ISRAEL"){
			if(!isnull(oInFlightID.value)){
				isnull(viewIn)?tempAction=israel_action:tempAction=(pagePath+"?pi="+viewIn);
				oForm.action=tempAction;
				oStepField.value="_passengers_number"
				document.getElementById('query_'+id).value="PackageDealDetailsRequest"
			}
			else{
				document.getElementById('query_'+id).value="PackageReturnDatesRequestEx"
				openCalendar({'mode':'RETURN'},id)
				return
			}
		}
		else{
			if(!isnull(oInFlightID.value)){
				isnull(viewIn)?tempAction=packages_action:tempAction=(pagePath+"?pi="+viewIn);
				oForm.action=tempAction;
				oStepField.value="_passengers_number"
				document.getElementById('query_'+id).value="PackageDealDetailsRequest"
			}
			else{
				document.getElementById('query_'+id).value="PackageReturnDatesRequestEx"
				openCalendar({'mode':'RETURN'},id)
				return
			}
		}
	}
	try{
		_activeTimer=false
	}catch(e){}
	oForm.submit()
}
function submitPromotionWithoutCheck(id){
	var viewIn = ""
	if(document.getElementById('view_in_'+id) && document.getElementById('view_in_'+id).value!="DEAL") viewIn = document.getElementById('view_in_'+id).value;
	
	var oForm=document.getElementById('detailsForm_'+id)
	var oStepField=document.getElementById('step_'+id)
	var oModeField=document.getElementById('mode_'+id)
	oStepField.value="_passengers_number"
	if(oModeField.value=="FLIGHTS"){
		document.getElementById('query_'+id).value="FlightDealDetailsRequest"
		isnull(viewIn)?tempAction=flights_action:tempAction=(pagePath+"?pi="+viewIn);
		oForm.action=tempAction;
	}
	if(oModeField.value=="PACKAGES"){
		document.getElementById('query_'+id).value="PackageDealDetailsRequest"
		isnull(viewIn)?tempAction=packages_action:tempAction=(pagePath+"?pi="+viewIn);
		oForm.action=tempAction;
	}
	if(oModeField.value=="ISRAEL"){
		document.getElementById('query_'+id).value="PackageDealDetailsRequest"
		isnull(viewIn)?tempAction=israel_action:tempAction=(pagePath+"?pi="+viewIn);
		oForm.action=tempAction;
	}
	oForm.target=''
	try{
		_activeTimer=false
	}catch(e){}
	oForm.submit()
}
function runSeatsNumberTimer(id,currNum){
	if(isnull(currNum)) currNum=SEATS_NUM_START+1
	var arr=eval('timersArr'+id)
	if(currNum==0) currNum=SEATS_NUM_START+1
	currNum--
	for(var i=0;i<arr.length;i++){
		if(currNum==0){
			document.all['timerSeatsNum_'+arr[i]].style.visibility='hidden'
			document.all['timerSeatsLabel_'+arr[i]].style.visibility='hidden'
		}
		else{
			document.all['timerSeatsNum_'+arr[i]].style.visibility='visible'
			document.all['timerSeatsLabel_'+arr[i]].style.visibility='visible'
		}
		
		document.all['timerNum_'+arr[i]].innerText=currNum
	}
	var score=SEATS_NUM_SCORE
	if(currNum==0) score=SEATS_NUM_SCORE*3
	if(_activeTimer) onlX=setTimeout('runSeatsNumberTimer("'+id+'",'+currNum+')',score)
}
function updateSeatsNum(id,newArr){
	var arr=eval('onlObj_'+id)
	for(var i=0;i<arr.length;i++){
		for(var j=0;j<newArr.length;j++){
			if(arr[i].obj.param1==newArr[j].param1 && arr[i].obj.param2==newArr[j].param2 && arr[i].obj.param3==newArr[j].param3 && arr[i].obj.param4==newArr[j].param4){
				arr[i].obj.innerHTML=Math.min(Number(newArr[j].AvailableSeats),10)
				document.all['seatsLabel_'+String(arr[i].obj.id).replace("seatsNum_","")].style.visibility='visible'
				break
			}
		}
	}
	seatsNumTimer(11,id)
}
function submitFlightOrPackageMainSearch(id,bPackage){
	var _yes=false
	var pr=(bPackage?'p':'f')
	if(document.all['citiesSelect_'+pr+'se'+id].value==""){
		alert(dic.NOT_DESTINATION)
		document.all['countriesSelect_'+pr+'se'+id].focus()
		return
	}
	if(!isnull(document.all['departureDate_'+pr+'se'+id].value)){
		document.all['OutboundDate_Start_'+pr+'se'+id].value=document.all['departureDate_'+pr+'se'+id].value
		document.all['OutboundDate_End_'+pr+'se'+id].value=document.all['departureDate_'+pr+'se'+id].value
		document.all['BestPrice_'+pr+'se'+id].value='0'
		_yes=true
	}
	if(!isnull(document.all['arrivalDate_'+pr+'se'+id].value)){
		document.all['InboundDate_Start_'+pr+'se'+id].value=document.all['arrivalDate_'+pr+'se'+id].value
		document.all['InboundDate_End_'+pr+'se'+id].value=document.all['arrivalDate_'+pr+'se'+id].value
	}
	try{ _activeTimer=false; }catch(e){}
	if(!_yes) document.all['OutboundDate_End_'+pr+'se'+id].value=EndRangeDateByDestRange	
	document.all['query_'+pr+'se'+id].value=(bPackage?'PackageDealsRequestEx':'FlightDealsRequestEx')
	var fObj=document.all['form_'+pr+'se'+id]
	fObj.target=''
	fObj.action=(!isnull(fObj.realaction)?fObj.realaction:(bPackage?packages_action:flights_action))
	if( css=='CARMEN' && String(document.location).indexOf('dbg=1')>-1 )
	{
		var ga_object_name = bPackage? (fObj.Category?"packagesMainSearch":"FLYANDDRIVE")+":PackageDealsRequestEx" : "flightsMainSearch:FlightDealsRequestEx";
		var ga_action_name = document.all['citiesSelect_'+pr+'se'+id].value;
		var ga_act_label = "dates:"+document.all['departureDate_'+pr+'se'+id].value+"|"+document.all['arrivalDate_'+pr+'se'+id].value;
		var ga_label_value = id;
		var CreateEventTrackerRes = GA_CreateEventTracker(ga_object_name, ga_action_name, ga_act_label, ga_label_value);
		ga_act_label = "hotel_stars|min_seats:"+ (bPackage && fObj.Category)? fObj.Category.value : fObj.MinSeats.value;
		CreateEventTrackerRes = GA_CreateEventTracker(ga_object_name, ga_action_name, ga_act_label, ga_label_value);
	}
	if(pi==home_pi) 
	{
		//alert("pi="+pi+" home_pi="+home_pi)
		//alert("pi==home_pi="+(pi==home_pi))
		searchType = bPackage? (fObj.Category?"Advanced_packages":"Advanced_flyanddrive") : "Advanced_flights";
		Update_STAT_SEARCHENGINE(id);
	}
	fObj.submit()
}
function submitFlightMainSearch(id){
	submitFlightOrPackageMainSearch(id,false)
}
function submitPackageMainSearch(id){
	submitFlightOrPackageMainSearch(id,true)
}
function submitIsraelMainSearch(id){
	var _yes=false
	var pr='p'
	if(document.all['citiesSelect_'+pr+'se'+id].value==""){
		alert(dic.NOT_DESTINATION)
		document.all['countriesSelect_'+pr+'se'+id].focus()
		return
	}
	if(!isnull(document.all['departureDate_'+pr+'se'+id].value)){
		document.all['OutboundDate_Start_'+pr+'se'+id].value=document.all['departureDate_'+pr+'se'+id].value
		document.all['OutboundDate_End_'+pr+'se'+id].value=document.all['departureDate_'+pr+'se'+id].value
		document.all['BestPrice_'+pr+'se'+id].value='0'
		_yes=true
	}
	if(!isnull(document.all['arrivalDate_'+pr+'se'+id].value)){
		document.all['InboundDate_Start_'+pr+'se'+id].value=document.all['arrivalDate_'+pr+'se'+id].value
		document.all['InboundDate_End_'+pr+'se'+id].value=document.all['arrivalDate_'+pr+'se'+id].value
	}
	try{ _activeTimer=false; }catch(e){}
	if(!_yes) document.all['OutboundDate_End_'+pr+'se'+id].value=EndRangeDateByDestRange	
	document.all['query_'+pr+'se'+id].value='PackageDealsRequestEx'
	var fObj=document.all['form_'+pr+'se'+id]
	fObj.target=''
	fObj.action=(!isnull(fObj.realaction)?fObj.realaction:israel_action)
	fObj.submit()
}
function setArrivalAndDepartureLabels(id){
	var opt=document.all['citiesSelect_fse'+id].options
	for(var i=0;i<opt.length;i++){
		if(opt[i].selected){
			document.all['ArrivalCityDesc_fse'+id].value=opt[i].text
			break
		}
	}
	var opt=document.all['departureCitySelect_fse'+id].options
	for(var i=0;i<opt.length;i++){
		if(opt[i].selected){
			document.all['DepartureCityDesc_fse'+id].value=opt[i].text
			break
		}
	}
}
function setArrivalAndDepartureLabels_Package(id){
	var opt=document.all['citiesSelect_pse'+id].options
	for(var i=0;i<opt.length;i++){
		if(opt[i].selected){
			document.all['ArrivalCityDesc_pse'+id].value=opt[i].text
			break
		}
	}
}
function getDepartureDateFlightPackageMainSearch(id,bPackage){
	var pr=(bPackage?'p':'f')
	if(document.all['citiesSelect_'+pr+'se'+id].value==""){
		alert(dic.NOT_DESTINATION)
		document.all['countriesSelect_'+pr+'se'+id].focus()
		return
	}
	if(bPackage)
		setArrivalAndDepartureLabels_Package(id)
	else
		setArrivalAndDepartureLabels(id)
	document.all['departureDate_'+pr+'se'+id].value=""
	document.all['arrivalDate_'+pr+'se'+id].value=""
	var CALENDAR_H=300;
	var top=window.screen.availHeight/2-CALENDAR_H/2
	var left=window.screen.availWidth/2-CALENDAR_W/2
	var calendarWinFeatures = "height="+CALENDAR_H+"px,width="+CALENDAR_W+"px,top="+top+",left="+left+",center=no,status=no,scrollbars=yes,resizable=no"
	var calendarWin=window.open('about:blank','calendarWin',calendarWinFeatures)
	calendarWin.document.write(LOADING_STR)
	calendarWin.document.body.style.cursor='wait'
	document.all['query_'+pr+'se'+id].value=(bPackage?'PackageDepartureDatesByDestRequest':'FlightDepartureDatesByDestRequest')
	var formObj=document.all['form_'+pr+'se'+id]
	formObj.action=windows_path+"FLIGHTS_SEARCH_CALENDAR/flights_search_calendar.asp?pi="+node_pi+"&id="+id+"&mode=exit&dealType="+(bPackage?"PACKAGE":"FLIGHT")+"&sitePath="+path
	formObj.target="calendarWin"
	formObj.submit()
	calendarWin.focus()
}
function getDepartureDateFlightMainSearch(id){
	getDepartureDateFlightPackageMainSearch(id,false)
}
function getDepartureDatePackageMainSearch(id){
	getDepartureDateFlightPackageMainSearch(id,true)
}
function getArrivalDateFlightPackageMainSearch(id,bPackage){
	var pr=(bPackage?'p':'f')
	if(document.all['citiesSelect_'+pr+'se'+id].value==""){
		alert(dic.NOT_DESTINATION)
		document.all['countriesSelect_'+pr+'se'+id].focus()
		return
	}
	if(document.all['departureDate_'+pr+'se'+id].value==""){
		alert(dic.CHOOSE_EXIT_DATE)
		return
	}
	if(bPackage)
		setArrivalAndDepartureLabels_Package(id)
	else
		setArrivalAndDepartureLabels(id)
	document.all['arrivalDate_'+pr+'se'+id].value=""
	var CALENDAR_H=300;
	var top=window.screen.availHeight/2-CALENDAR_H/2
	var left=window.screen.availWidth/2-CALENDAR_W/2	
	var calendarWinFeatures = "height="+CALENDAR_H+"px,width="+CALENDAR_W+"px,top="+top+",left="+left+",center=no,status=no,scrollbars=yes,resizable=no"	
	var calendarWin=window.open('about:blank','calendarWin',calendarWinFeatures)
	calendarWin.document.write(LOADING_STR)
	calendarWin.document.body.style.cursor='wait'
	document.all['query_'+pr+'se'+id].value=(bPackage?'PackageReturnDatesByDestRequest':'FlightReturnDatesByDestRequest')
	var formObj=document.all['form_'+pr+'se'+id]
	formObj.action=windows_path+"FLIGHTS_SEARCH_CALENDAR/flights_search_calendar.asp?pi="+node_pi+"&id="+id+"&mode=return&dealType="+(bPackage?"PACKAGE":"FLIGHT")+"&sitePath="+path
	formObj.target="calendarWin"
	formObj.submit()
	calendarWin.focus()
}
function getArrivalDateFlightMainSearch(id){
	getArrivalDateFlightPackageMainSearch(id,false)
}
function getArrivalDatePackageMainSearch(id){
	getArrivalDateFlightPackageMainSearch(id,true)
}
function updateNightsNumber(id){
	var obj=document.all['nightsNumber_pse'+id]
	if(!obj) return
	var str=obj.innerHTML;
	var date1=document.all['departureDate_pse'+id].value
	var date2=document.all['arrivalDate_pse'+id].value
	obj.innerHTML=str.replace(/\d/g,'');
	if(isnull(date2) || isnull(date1)){
		
		obj.style.visibility='hidden'
		return
	}	
	date1=new Date(date1.replace(/-/g,'/'))
	date2=new Date(date2.replace(/-/g,'/'))
	obj.innerHTML+=String(Math.round((date2-date1)/(1000*60*60*24)))
	obj.style.visibility='visible'
}
function isIn(list,arg,delim){
	if (isnull(list) || isnull(arg)) return false;
	delim = (isnull(delim)?",":delim)
	return ((delim + list + delim).search(delim + arg + delim) >= 0);
}
function isnull(arg) {
	arg = arg+'';
	return (arg == '' || arg == 'null' || arg == 'undefined');
}
String.prototype.toFirstLetterCase=function(){
	return (this.substring(0,1).toUpperCase()+this.substring(1,this.length).toLowerCase())
}
function clearRadios(id){ return; }
function clear_fse(id){
	try{
		document.all['departureDate_fse'+id].value=""
		document.all['arrivalDate_fse'+id].value=""

		// reassign the initial values of the departure dates
		// START 
		var const_out_start = document.all['Const_OutboundDate_Start_fse'+id].value;
		document.all['OutboundDate_Start_fse'+id].value = const_out_start;
		// END
		var const_out_end = document.all['Const_OutboundDate_End_fse'+id].value;
		document.all['OutboundDate_End_fse'+id].value = const_out_end;	

	}catch(e){}
}
function clear_pse(id){
	try{
		document.all['departureDate_pse'+id].value=""
		document.all['arrivalDate_pse'+id].value=""
	
		// reassign the initial values of the departure dates
		// START 
		var const_out_start = document.all['Const_OutboundDate_Start_pse'+id].value;
		document.all['OutboundDate_Start_pse'+id].value = const_out_start;
		// END
		var const_out_end = document.all['Const_OutboundDate_End_pse'+id].value;
		document.all['OutboundDate_End_pse'+id].value = const_out_end;	

		updateNightsNumber(id)
	} catch(e){}
}





// newsletter_action:	1 = subscribe
//						0 = unsubscribe
function newsletter_subscribe(action) {
	function validateEmail(email) {
		var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
		return (re.test(email))
	} 
	var email = document.getElementById('newsletter_email').value;
	if (!validateEmail(email)) {
		alert(dic.BAD_MAIL);
	} else {
		var oXML=new ActiveXObject("Msxml2.DOMDocument");
		oXML.async=false;
		var obj = {};
		obj.exist = oXML.load("/SITE/UTILS/XX/newsletterSubscription.hx.asp?newsletter_action="+action+"&email="+email+"&category="+MEMBERS_CLUB_CATEGORY+"&lang="+lang);
		if(!obj.exist) alert(oXML.parseError.reason);
		var result = oXML.documentElement.selectSingleNode("//RESULT");
		var res_code   = result.getAttribute("code");
		var res_action = result.getAttribute("action");
		if (res_code=='1' || res_code=='-2') {
			msg = (res_action=="add")?dic.NEWSLETTER_EMAIL_ADDED:dic.NEWSLETTER_EMAIL_REMOVED;
		} else {
			msg = dic.MAIL_ERROR;
		}
		alert(msg);
	}
}


// force form inputs to be filled only in English (in NON-HEBREW sites; lang='en')
function validateEnglish(obj){
	if (lang.toUpperCase()=='HE') return true;
	var str = obj.value.toUpperCase();
	var strOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZ "
	for(var i=0 ; i < str.length ; i++){
		if(strOK.indexOf(str.substring(i,i+1)) == -1){
			return false;
		}
	}
	return true;
}
function goToPriceTemplateOfFlyAndDrive(id){
	var oInFlightID=document.getElementById('InFlightID_'+id)
	if(isnull(oInFlightID.value)){
		alert(dic.CHOOSE_RETURN_DATE)
		return
	}
	with(document){
		getElementById('detailsForm_'+id).action = ""
		getElementById('queryName_'+id).value='PackageDealDetailsRequest';
		getElementById('detailsForm_'+id).submit();
	}
}

function GA_CreateEventTracker(object_name, action_name, act_label, label_value)
{
	//alert("object_name="+object_name);
	//alert("action_name="+action_name);
	//alert("act_label="+act_label);
	//alert("label_value="+label_value);

	try{
		if(!myEventObject)
		{
			var myEventObject = pageTracker._createEventTracker(object_name);
		}
		else
		{
			alert(myEventObject);
		}
	
		myEventObject._trackEvent(action_name, act_label, label_value);
		return true;
	}
	catch(e)
	{
		alert(e.description);
		return false;
	}
}


function Update_STAT_SEARCHENGINE(id)
{
	var updateStatXML=new ActiveXObject("Microsoft.XMLDOM");
	updateStatXML.async=true;
	var update_url = '/SITE/UTILS/XX/Update_STAT_SEARCHENGINE.hx.asp';
	var oDate = new Date();
	try{
		updateStatXML.load(update_url+"?search_type="+searchType+"&rn="+oDate.getMilliseconds())
	}
	catch(e){
		//alert(e.description)
		return "javascript:void(0)";
		//header_part = "<ERROR_GETHEADERBANNERS desc='"+String(e.description).replace(/\'/gim,'`')+"'/>";
	}
	
}
function checkSaturdayDate()
{
	var saturdayXML=new ActiveXObject("Microsoft.XMLDOM");
	saturdayXML.async=false;
	oDate = new Date();
	try{
		//window.open("/SITE/INCLUDES/getSaturdayDates.hx.asp?rn="+oDate.getMilliseconds()+"&pi="+home_pi)	
		if( saturdayXML.load("/SITE/INCLUDES/getSaturdayDates.hx.asp?rn="+oDate.getMilliseconds()+"&pi="+home_pi) )
		{
			var elements = saturdayXML.documentElement;
			if(!isnull(elements)){
				var saturday_url = elements.selectSingleNode("//ROWSET/saturday_date").text;		
				
				if(!isnull(saturday_url)) window.location.href = saturday_url;
			}
		}
	}
	catch(e){
		
		return "javascript:void(0)";
	}
}



function getHeaderBanners(affiliatecode){
	//alert("getHeaderBanners");
	var sBannersDiv = "";
	
	var bannersXML=new ActiveXObject("Microsoft.XMLDOM");
	bannersXML.async=false;
	oDate = new Date();

	try{
	//document.write("/SITE/INCLUDES/getHeaderBanners.hx.asp?affiliatecode="+affiliatecode+"&pi="+home_pi+"&rn="+oDate.getMilliseconds());
	//return;
		if( bannersXML.load("/SITE/INCLUDES/getHeaderBanners.hx.asp?affiliatecode="+affiliatecode+"&pi="+home_pi+"&rn="+oDate.getMilliseconds()) )
		{
			//var header_part_div=bannersXML.documentElement.selectNodes("//header_part_div");
			var elements = bannersXML.documentElement;
			if(!isnull(elements)){
				var header_part_div = elements.selectSingleNode("//ROWSET/header_part_div");
				if(!isnull(header_part_div.text)){
				// && header_part_div.length>0){
					document.all['header_part'].innerHTML = header_part_div.text;
				}
			}
		}
		else{
			header_part  = "bannersXML error";//"<ERROR_GETHEADERBANNERS desc='"+String(bannersXML.parseError.reason).replace(/\'/gim,'`')+"'/>";
		}	
	}
	catch(e){
		//alert(e.description);
		return "javascript:void(0)";
		//header_part = "<ERROR_GETHEADERBANNERS desc='"+String(e.description).replace(/\'/gim,'`')+"'/>";
	}
}


function ShowUrlTrip(url)
{
	var CALENDAR_H=500;
	var CALENDAR_W=750;
	var top=window.screen.availHeight/2-CALENDAR_H/2
	var left=window.screen.availWidth/2-CALENDAR_W/2	
	var calendarWinFeatures = "height="+CALENDAR_H+"px,width="+CALENDAR_W+"px,top="+top+",left="+left+",center=no,status=yes,scrollbars=no,resizable=yes"	
	var UrlTrip=window.open('/site/UrlTrip.asp?sUrl='+escape(url),'UrlTrip',calendarWinFeatures)
	
}




/////////////////////////////////////////////////////////////////////////////////////////

function checkIfAffiliate(affiliatecode,doaffildiscount){
//alert("affiliatecode = " + affiliatecode + ", doaffildiscount = " + doaffildiscount)
	
	var bannersXML=new ActiveXObject("Microsoft.XMLDOM");
	bannersXML.async=false;
	oDate = new Date();

	try{
		if( bannersXML.load("/SITE/INCLUDES/getHeaderBanners.hx.asp?affiliatecode="+affiliatecode+"&doaffildiscount="+doaffildiscount+"&pi="+home_pi+"&rn="+oDate.getMilliseconds()) )
		{
			var elements = bannersXML.documentElement;
			if(!isnull(elements)){
				var doaffildiscount_serv = elements.selectSingleNode("//ROWSET/doaffildiscount").text;
				var affiliatecode_serv = elements.selectSingleNode("//ROWSET/affiliatecode").text;
//alert("affiliatecode_serv = " + affiliatecode_serv + ", doaffildiscount_serv = " + doaffildiscount_serv)

				if(!isnull(affiliatecode_serv) && isnull(affiliatecode)){
					var s = window.location.href
					if(s.indexOf("?") > -1) s = s + "&affiliatecode=" + affiliatecode_serv
					else  s = s + "?affiliatecode=" + affiliatecode_serv
					if(!isnull(doaffildiscount_serv))  s + "&doaffildiscount=" + doaffildiscount_serv
					else   s + "&doaffildiscount=0"

					window.location.href = s

				}
				
			}
		}
	
	}
	catch(e){

	}
}

function getHeaderBanners(affiliatecode,doaffildiscount){


//alert("affiliatecode = " + affiliatecode + ", doaffildiscount = " + doaffildiscount)


	var sBannersDiv = "";
	
	var bannersXML=new ActiveXObject("Microsoft.XMLDOM");
	bannersXML.async=false;
	oDate = new Date();

	try{
		if( bannersXML.load("/SITE/INCLUDES/getHeaderBanners.hx.asp?affiliatecode="+affiliatecode+"&doaffildiscount="+doaffildiscount+"&pi="+home_pi+"&rn="+oDate.getMilliseconds()) )
		{
			var elements = bannersXML.documentElement;
			if(!isnull(elements)){
/*
				var doaffildiscount_serv = elements.selectSingleNode("//ROWSET/doaffildiscount").text;
				var affiliatecode_serv = elements.selectSingleNode("//ROWSET/affiliatecode").text;


//alert("affiliatecode_serv = " + affiliatecode_serv + ", doaffildiscount_serv = " + doaffildiscount_serv)


if(!isnull(affiliatecode_serv) && isnull(affiliatecode)){
	var s = window.location.href
	if(s.indexOf("?") > -1) s = s + "&affiliatecode=" + affiliatecode_serv
	else  s = s + "?affiliatecode=" + affiliatecode_serv
	if(!isnull(doaffildiscount_serv))  s + "&doaffildiscount=" + doaffildiscount_serv
	else   s + "&doaffildiscount=0"

	window.location.href = s

	return
}
*/
				var header_part_div = elements.selectSingleNode("//ROWSET/header_part_div");
				if(!isnull(header_part_div.text)){
					document.all['header_part'].innerHTML = header_part_div.text;
				}
			}
		}
		else{
			header_part  = "bannersXML error";
		}	
	}
	catch(e){
		return "javascript:void(0)";
	}
}