
/***** CALENDAR FUNCTION  ******/

function changeMonth(changeDir,curMonth, curYear, curCity, fromDate, calType, toDate, fromCity, searchBox){
	if (changeDir=="back"){
		if ((curMonth-2) == 0){
			curMonth=12;
			curYear--;
		} else if ((curMonth-2) < 0){
			curMonth=11;
			curYear--;
		} else {
			curMonth=(curMonth-2);
		}
	} else {
		if ((curMonth+2) == 13){
			curMonth=12;
	} else if ((curMonth+2)>13){
			curMonth=1;
			curYear++;
		} else {
			curMonth=(curMonth+1);
		}
	}
	location.href="?curMonth="+curMonth+"&curYear="+curYear+"&calType="+calType+"&curCity="+curCity+"&fromDate="+fromDate+"&toDate="+toDate+"&subjName="+subjName+"&fromCity="+fromCity+"&searchBox="+searchBox;
}

function tdMouseOver(tdID)
{
	document.getElementById(tdID).style.borderColor="#000000";
}

function tdMouseOut(tdID)
{
	document.getElementById(tdID).style.borderColor="#FFFFFF";
}

function selectDate(curDay, curMonth, curYear)
{
	curDay=(curDay < 10)?"0"+curDay:curDay;
	curMonth=(curMonth < 10)?"0"+curMonth:curMonth;
	newDate = curDay+"/"+curMonth+"/"+curYear;
	if (calType=="fromDate"){
		opener.document[fid].fromDate.value=newDate;
		opener.focus();
		window.close();
	} else if (calType=="toDate"){
		opener.document[fid].toDate.value=newDate;
		opener.focus();
		window.close();
	} else {
		alert (calType);
	}
}


function openCalendar(calType, fid, field_fCity, field_tCity){
	subjName = fid.subjName.value;
	if (calType=="toDate" && fid.fromDate.value==""){
		alert (_alert_selectFromDate);
	} else {
		if (calType!="toDate")
			fid.toDate.value="";

		switch (subjName)
		{
			case "FLT":
				curCal = "calendarBox_FLT.php";
				break;
			case "HTL":
				curCal = "calendarBox_HTL.php";
				break;
			default:
				curCal = "calendarBox_PCK.php";
				break;
		}
		curCity = fid[field_tCity].value;
		fromCity = fid[field_fCity].value;
		fromDate = (fid.fromDate) ? fid.fromDate.value : "";
		toDate = (fid.toDate) ? fid.toDate.value : "";
		searchBox = fid.searchBox.value;
		calUrl=curCal+"?calType="+calType+"&curCity="+curCity+"&fromCity="+fromCity+"&fromDate="+fromDate+"&toDate="+toDate+"&subjName="+subjName+"&searchBox="+searchBox;
		popupWin(calUrl, 350, 200);
	}
}


/***** END CALENDAR FUNCTION  ******/

function advFlt_populateForm()
{
	f = document.getElementById("fltSearch_adv"); // advanced search form identifier
	mf = document.getElementById("search_main"); // get top search form for passing vars

	s_fcnt_out = f.search_fCountry;
	s_fcit_out = f.search_fCity;
	s_tcnt_out = f.search_country;
	s_tcit_out = f.search_city;
	s_fcnt_in = f.search_fCountry_in;
	s_fcit_in = f.search_fCity_in;
	s_tcnt_in = f.search_country_in;
	s_tcit_in = f.search_city_in;

	v_fcnt_out = (mf.search_fCountry_main) ? mf.search_fCountry_main.value : "";
	v_fcit_out = (mf.search_fCity_main) ? mf.search_fCity_main.value : "";
	v_tcnt_out = (mf.search_main_country) ? mf.search_main_country.value : "";
	v_tcit_out = (mf.search_main_city) ? mf.search_main_city.value : "";
	v_fcnt_in = (mf.search_fCountry_in_main) ? mf.search_fCountry_in_main.value : "";
	v_fcit_in = (mf.search_fCity_in_main) ? mf.search_fCity_in_main.value : "";
	v_tcnt_in = (mf.search_country_in_main) ? mf.search_country_in_main.value : "";
	v_tcit_in = (mf.search_city_in_main) ? mf.search_city_in_main.value : "";

	if ((v_fcnt_out == undefined || v_fcnt_out == "") && v_tcnt_out != "IL")  v_fcnt_out = "IL"; // set israel as default outbound country

	populate_searchFields (f, s_fcnt_out, v_fcnt_out, "action=countries&byType=FLT_adv");
	populate_searchFields (f, s_fcit_out, v_fcit_out, "action=cities&cntryCode="+s_fcnt_out.value+"&byType=FLT_adv");
	populate_searchFields (f, s_tcnt_out, v_tcnt_out, "action=countries&cntryCode="+(s_fcnt_out.value != "IL" ? "IL" : "")+"&byType=FLT_adv");
	populate_searchFields (f, s_tcit_out, v_tcit_out, "action=cities&cntryCode="+s_tcnt_out.value+"&byType=FLT_adv");

	populate_searchFields (f, s_fcnt_in, (v_fcnt_in != undefined && v_fcnt_in != "" ? v_fcnt_in : s_tcnt_out.value) , "action=countries&byType=FLT_adv");
	populate_searchFields (f, s_fcit_in, (v_fcit_in != undefined && v_fcit_in != "" ? v_fcit_in : s_tcit_out.value), "action=cities&cntryCode="+s_fcnt_in.value+"&byType=FLT_adv");
	populate_searchFields (f, s_tcnt_in, (v_tcnt_in != undefined && v_tcnt_in != "" ? v_tcnt_in : s_fcnt_out.value), "action=countries&cntryCode="+(s_fcnt_in.value != "IL" ? "IL" : "")+"&byType=FLT_adv");
	populate_searchFields (f, s_tcit_in, (v_tcit_in != undefined && v_tcit_in != "" ? v_tcit_in : s_fcit_out.value), "action=cities&cntryCode="+s_tcnt_in.value+"&byType=FLT_adv");
}

function advFlt_changeForm(s) {
	f = document.getElementById("fltSearch_adv"); // advanced search form identifier

	s_fcnt_out = f.search_fCountry;
	s_fcit_out = f.search_fCity;
	s_tcnt_out = f.search_country;
	s_tcit_out = f.search_city;
	s_fcnt_in = f.search_fCountry_in;
	s_fcit_in = f.search_fCity_in;
	s_tcnt_in = f.search_country_in;
	s_tcit_in = f.search_city_in;

	switch (s.name) {
		case "search_fCountry":
			populate_searchFields (f, s_fcit_out, "", "action=cities&cntryCode="+s_fcnt_out.value+"&byType=FLT_adv");
			populate_searchFields (f, s_tcnt_out, "", "action=countries&cntryCode="+(s_fcnt_out.value != "IL" ? "IL" : "")+"&byType=FLT_adv");
			populate_searchFields (f, s_tcit_out, "", "action=cities&cntryCode="+s_tcnt_out.value+"&byType=FLT_adv");
			f.fromDate.value = "";
			break;
		case "search_country":
			populate_searchFields (f, s_tcit_out, "", "action=cities&cntryCode="+s_tcnt_out.value+"&byType=FLT_adv");
			f.fromDate.value = "";
			break;
		case "search_fCity":
		case "search_city":
			f.fromDate.value = "";
			break;
		case "search_fCountry_in":
			populate_searchFields (f, s_fcit_in, "", "action=cities&cntryCode="+s_fcnt_in.value+"&byType=FLT_adv");
			populate_searchFields (f, s_tcnt_in, "", "action=countries&cntryCode="+(s_fcnt_in.value != "IL" ? "IL" : "")+"&byType=FLT_adv");
			populate_searchFields (f, s_tcit_in, "", "action=cities&cntryCode="+s_tcnt_in.value+"&byType=FLT_adv");
			f.toDate.value = "";
			break;
		case "search_country_in":
			populate_searchFields (f, s_tcit_in, "", "action=cities&cntryCode="+s_tcnt_in.value+"&byType=FLT_adv");
			f.toDate.value = "";
			break;
		case "search_fCity_in":
		case "search_city_in":
			f.toDate.value = "";
			break;
	}

}

function searchStrip_checkSub(fid){
	// check submition of search from main search strip
	if (fid.fromDate.value=="")
	{
		alert (_alert_selectFromDate);
		return false;
	}
	else
	{
		show_preload();
		return true;
	}
}

function searchHotels_checkSub(fid){
	// check submition of search from main search strip
	if (fid.fromDate.value=="")
	{
		alert (_alert_selectFromDate);
		return false;
	}
	if (fid.toDate.value=="")
	{
		alert (_alert_selectToDate);
		return false;
	}
	show_preload();
	return true;
}

function searchStrip_changeCountries(f, v, type) {
	s = f.search_main_country;
	populate_searchFields (f, s, v, "action=countries"+(type != undefined && type != "" ? "&byType="+type : ""));
}

function searchStrip_changeCities(f, v, fv, type){
	s = f.search_main_city;
	cnt_v = f.search_main_country.value;
	populate_searchFields (f, s, v, "action=cities&cntryCode="+cnt_v+(type != undefined && type != "" ? "&byType="+type : ""));
	searchStrip_changeFormTypes (f, fv, type);
}

function searchStrip_changeFormTypes(f, v, type){
	s = f.search_main_forms;
	cnt_v = f.search_main_country.value;
	cit_v = f.search_main_city.value;
	advanced = ""; // passed to changeForm function, in order to select _adv form if set.

	switch (v)
	{
		case "FLT_adv":
			advanced = "_adv";
			v = "FLT";
			break;
	}

	populate_searchFields (f, s, v, "action=forms&cntryCode="+cnt_v+"&cityCode="+cit_v+(type != undefined && type != "" ? "&byType="+type : ""));
	searchStrip_changeForm(s.value, advanced);
}

function searchStrip_changeForm(v, advanced)
{
	cHolder = document.getElementById("formContainer");
//	cHolder.className = "loading";

	if (advanced==undefined) advanced = "";
	var url = "xml_populateSearchEngine.php?action=select_form&form_id="+v+advanced;
//	clipboardData.setData("Text", url);
	var xml = LoadXML(url);
	if(xml != null)
	{
		cKey = xml.getElementsByTagName('id')[0].firstChild.data;
		cType = xml.getElementsByTagName('type')[0].firstChild.data;
		cSubject = xml.getElementsByTagName('subject')[0].firstChild.data;
		cInclude = xml.getElementsByTagName('include')[0].firstChild.data;

		f = document.getElementById("search_main"); // get top search form for passing vars
		cInclude+="?searchBox="+cKey+"&c_subjName="+escape(cSubject)+"&fromDate="+f.fromDate_main.value+"&toDate="+f.toDate_main.value+"&maxPrice="+f.maxPrice_main.value+"&dateRange="+f.dateRange_main.value+"&search_country="+f.search_main_country.value+"&search_city="+f.search_main_city.value;

		formData = LoadHTML(cInclude);
		if (formData != null)
		{
			v = v+advanced;
			cHolder.innerHTML = LoadHTML(cInclude);
			switch (v) {
				case "org":
					org_form = document.getElementById("orgSearch");
					populate_searchFields (org_form, org_form.search_pck, f.search_pck_main.value, "action=org_trips&cntryCode="+f.search_main_country.value);
				break;

				case "fltcruise":
					org_form = document.getElementById("orgSearch");
					populate_searchFields (org_form, org_form.search_pck, f.search_pck_main.value, "action=fltcruise&cntryCode="+f.search_main_country.value);
				break;

				case "FLT_adv":
					advFlt_populateForm();
					break;
			}
		}
	}
}

function searchStrip_resetGet() {
	f = document.getElementById("search_main"); // get top search form for passing vars
	f.fromDate_main.value = "";
	f.toDate_main.value = "";
	f.maxPrice_main.value = "";
	f.dateRange_main.value = "";
	if (f.search_fCountry_main) f.search_fCountry_main.value = "";
	if (f.search_fCountry_in_main) f.search_fCountry_in_main.value = "";
	if (f.sesearch_fCity_in_mainarch_fCountry_main) f.search_fCity_in_main.value = "";
	if (f.search_city_in_main) f.search_city_in_main.value = "";
	if (f.search_country_in_main) f.search_country_in_main.value = "";
}

function populate_searchFields (f, s, v, vars) {

	var url = "xml_populateSearchEngine.php?"+vars;
//	clipboardData.setData("Text", url);
	var xml = LoadXML(url);
	if(xml != null)
	{
		var options = xml.getElementsByTagName('option');
		var values = xml.getElementsByTagName('value');

		s.options.length = 0;
		for(var j = s.options.length; j > 0; j --)
		{
			s.options[j] = null;
		}

		if (options.length <= 0) {
			var opt = new Option('', '');
			s.options[0] = opt;
			return;
		}

		for(var k = 0; k < options.length; k++)
		{
			var cOpt = options[k].firstChild.data;
			var cVal = values[k].firstChild.data;
			var opt = new Option(cOpt, cVal);
			s.options[k] = opt;
			if (cVal == v && v != "")
			{
				s.options.selectedIndex = k;
			}
		}
	}
}
