// package search panel

var bBigPsbLoaded = true;
var oBigPsbSel = new Array();
var bBigPsbChangeInProcess = false;
var sBigPsbIgnoredValue = 0;
var sBigPsbAjaxScript = "/inc/sitespecific/danubius/modul1/getform_packages_ajaxhandler.php";
var sBigPsbWaitingText = ""; //"in process...";
var sBigPsbNullText = "-- all --";
var aBigPsbSetIndexTo1 = new Array();
var sBigPsbSubcatAll = "-- all --";
var sBigPsbSubcatSelected = "My selected categories";
var iBigPsbCatsOpen = 0;
var aBigPsbSubcatsChecked = new Array();
var oBigPsbCatsDiv = null;
var iBigPsbSavedCity = 0;
var sBigPsbBgChecked = "";
var sBigPsbBgNormal = "";
var sBigPsbBgCheckedOnOver = "";
var sBigPsbBgNormalOnOver = "";
var sBigPsbMyPrefix = "Bigdanupackagebox_";
var iBigPsbMaincatID = 0;
var iCommonPsbTimerCounter = 0;


function BigPsbInit(sLang, sWaitingText, sNullText, sSubcatAll, sSubcatSelected, sMustOneSubcat, sMustCityOrHotel, sPsbBgNormal, sPsbBgChecked, sPsbBgNormalOnOver, sPsbBgCheckedOnOver, iMaincatID) {
	oBigPsbSel["countries"] = document.getElementById(sBigPsbMyPrefix + "countries");
	oBigPsbSel["cities"] = document.getElementById(sBigPsbMyPrefix + "cities");
	oBigPsbSel["hotels"] = document.getElementById(sBigPsbMyPrefix + "hotels");
	oBigPsbSel["pcats"] = document.getElementById(sBigPsbMyPrefix + "pcats");
	
	aBigPsbSetIndexTo1["countries"] = false;
	aBigPsbSetIndexTo1["cities"] = false;
	aBigPsbSetIndexTo1["hotels"] = false;
	
	sBigPsbWaitingText = sWaitingText;
	sBigPsbNullText = sNullText;
	sBigPsbSubcatAll = sSubcatAll;
	sBigPsbSubcatSelected = sSubcatSelected;
	sBigPsbMustOneSubcat = sMustOneSubcat;
	sBigPsbMustCityOrHotel = sMustCityOrHotel;
	sBigPsbBgChecked = sPsbBgChecked;
	sBigPsbBgNormal = sPsbBgNormal;
	sBigPsbBgCheckedOnOver = sPsbBgCheckedOnOver;
	sBigPsbBgNormalOnOver = sPsbBgNormalOnOver;
	iBigPsbMaincatID = iMaincatID;
	
	sBigPsbAjaxScript += "?place=page&callerlang=" + sLang + "&maincat_id=" + iBigPsbMaincatID + "&change=";
	
	aAjaxModul_specialFinisher[sBigPsbMyPrefix + "countries"] = "BigPsbFinisherCountries";
	aAjaxModul_specialFinisher[sBigPsbMyPrefix + "cities"] = "BigPsbFinisherCities";
	aAjaxModul_specialFinisher[sBigPsbMyPrefix + "hotels"] = "BigPsbFinisherHotels";
	
	sAjaxModul_otherReceiver[sBigPsbMyPrefix + "pcats"] = "BigPsbReceiverForSubcats";
	
	AjaxModul_init("AjaxModul_receiverForSelectBox");
	
	bPsbForm19Loaded = true;
}

function BigPsbCheckOnSubmit() {
	if(oBigPsbSel["cities"] && (oBigPsbSel["cities"].selectedIndex<=0 || !oBigPsbSel["cities"].selectedIndex)&& (oBigPsbSel["hotels"].selectedIndex<=0 || !oBigPsbSel["hotels"].selectedIndex)) {
		alert(sBigPsbMustCityOrHotel);
		return false;
	}
	var a = BigPsbGetSubcatCheckboxesCheckeds();
	if(!a || a.length==0) {
		alert(sBigPsbMustOneSubcat);
		return false;
	}
	return true;
}

function BigPsbFinisherGlobal(sMyID) {
	if(oBigPsbSel[sMyID] && oBigPsbSel[sMyID].tagName=="TABLE") return;
	oBigPsbSel[sMyID].options[0].text = sBigPsbNullText;
	if(aBigPsbSetIndexTo1[sMyID]) {
		if(oBigPsbSel[sMyID].options.length==2) BigPsbSetSelectedIndex(oBigPsbSel[sMyID], 1);
		else if(sMyID=="countries") {
			setTimeout("BigPsbChangeCountries_ifSetToOneButCant()", iCommonPsbTimeOut);
		}
		aBigPsbSetIndexTo1[sMyID] = false;
	}
	oBigPsbSel[sMyID].style.color = "#000000";
}
function BigPsbFinisherCountries() { BigPsbFinisherGlobal("countries"); }
function BigPsbFinisherCities() { BigPsbFinisherGlobal("cities"); }
function BigPsbFinisherHotels() { BigPsbFinisherGlobal("hotels"); }

function BigPsbCallAjax(sToChange, sCountry, sCity, sHotel, sPcats) {
	if(!oBigPsbSel[sToChange]) return;
	BigPsbClearSelect(sToChange);
	var sParams = "";
	if(sCountry && sCountry>"") sParams += "&country_id="  + escape(sCountry);
	if(sCity && sCity>"")       sParams += "&city_id="     + escape(sCity);
	if(sHotel && sHotel>"")     sParams += "&hotel_id="    + escape(sHotel);
	if(sPcats && sPcats>"")     sParams += "&category_id=" + escape(sPcats+",0");
	var sUrl = sBigPsbAjaxScript + sToChange + sParams;
	AjaxModul_call(sUrl, "AjaxModul_receiverForSelectBox", sBigPsbMyPrefix + "");
}

function BigPsbClearSelect(sMyID) {
	if(oBigPsbSel[sMyID] && oBigPsbSel[sMyID].tagName=="TABLE") {
		//document.getElementById("catsel_selectebox").options[0].text = sBigPsbWaitingText;
		return;
	}
	for(var i=oBigPsbSel[sMyID].options.length-1; i>0; i--) oBigPsbSel[sMyID].options[i] = null;
	oBigPsbSel[sMyID].options[0].text = sBigPsbWaitingText;
	oBigPsbSel[sMyID].style.color = "#cbcbcb";
}

function BigPsbResetAll() {
	if(bBigPsbChangeInProcess) return;
	bBigPsbChangeInProcess = true;
	
	for(var i in aCommonsPsbSuffixes) {
		oSource = oBigPsbSel[aCommonsPsbSuffixes[i]];
		if(oSource.tagName=="SELECT" && oSource.options[0].text==sPsbWaitingText) {
			// valaki túl gyorsan nyomta meg a resetet egymás után!!!
			bBigPsbChangeInProcess = false;
			return false;
		}
	}
	
	for(var i in aCommonsPsbSuffixes) {
		oSource = oBigPsbSel[aCommonsPsbSuffixes[i]];
		if(oSource.tagName=="SELECT" && oSource.options[0].text==sBigPsbWaitingText) {
			setTimeout("BigPsbResetAll()", iCommonPsbTimeOut);
			return false;
		}
	}
	
	BigPsbPreparePsb();
	
	AjaxModul_waitingObjectState[sBigPsbMyPrefix + "countries"] = "busy";
	AjaxModul_waitingObjectState[sBigPsbMyPrefix + "cities"] = "busy";
	AjaxModul_waitingObjectState[sBigPsbMyPrefix + "hotels"] = "busy";
	AjaxModul_waitingObjectState[sBigPsbMyPrefix + "pcats"] = "busy";
	BigPsbClearSelect("countries");
	BigPsbClearSelect("cities");
	BigPsbClearSelect("hotels");
	BigPsbCallAjax("countries");
	BigPsbCallAjax("cities");
	BigPsbCallAjax("hotels");
	
	BigPsbSetSubcatsToUnchecked();
	BigPsbCallAjax("pcats");
	BigPsbSetSubcatsRows();
	
	x = document.getElementById("package_from_string"); if(x) x.value = "";
	x = document.getElementById("package_from"); if(x) x.value = "";
	x = document.getElementById("package_to_string"); if(x) x.value = "";
	x = document.getElementById("package_to"); if(x) x.value = "";
	x = document.getElementById("package_nights"); if(x) BigPsbSetSelectedIndex(x, 0); //x.selectedIndex = 0;
	x = document.getElementById("package_to_holder_dynamic"); if(x) x.style.display = "none";
	x = document.getElementById("package_nights_holder_dynamic"); if(x) x.style.display = "none";
	x = document.getElementById("package_to_holder_static"); if(x) x.style.display = "block";
	x = document.getElementById("package_nights_holder_static"); if(x) x.style.display = "block";
	
	bBigPsbChangeInProcess = false;
	
	BigPsbSynchronizePsb();
	
	return false;
}

function BigPsbResetCats() {
	if(bBigPsbChangeInProcess) return;
	bBigPsbChangeInProcess = true;
	
	BigPsbSetSubcatsToUnchecked();
	
	bBigPsbChangeInProcess = false;
	BigPsbChangePcats();
	
	return false;
}

function BigPsbChangeCountries() {
	if(bBigPsbChangeInProcess) return;
	bBigPsbChangeInProcess = true;
	BigPsbPreparePsb();
	if(oBigPsbSel["countries"]==null || oBigPsbSel["cities"]==null || oBigPsbSel["hotels"]==null) {
		BigPsbWaitToInitialization("BigPsbChangeCountries");
		return;
	}
	AjaxModul_waitingObjectState[sBigPsbMyPrefix + "cities"] = "busy";
	AjaxModul_waitingObjectState[sBigPsbMyPrefix + "hotels"] = "busy";
	AjaxModul_waitingObjectState[sBigPsbMyPrefix + "pcats"] = "busy";
	BigPsbClearSelect("cities");
	BigPsbClearSelect("hotels");
	if(oBigPsbSel["countries"].selectedIndex<=0) BigPsbCallAjax("countries");
	BigPsbCallAjax("cities", oBigPsbSel["countries"].value);
	BigPsbCallAjax("hotels", oBigPsbSel["countries"].value);
	BigPsbCallAjax("pcats", oBigPsbSel["countries"].value);
	bBigPsbChangeInProcess = false;
	
	//oPsbSel["countries"].selectedIndex = oBigPsbSel["countries"].selectedIndex;
	//PsbChangeCountries();
}

function BigPsbChangeCountries_ifSetToOneButCant() {
	if(oBigPsbSel["cities"].options[0].text==sBigPsbWaitingText) {
		setTimeout("BigPsbChangeCountries_ifSetToOneButCant()", iCommonPsbTimeOut);
		return;
	}
	var sCountry = oBigPsbSel["cities"].options[oBigPsbSel["cities"].selectedIndex].id;
	if(oBigPsbSel["countries"]!=sCountry) {
		for(var i=0; i<oBigPsbSel["countries"].options.length; i++) {
			if(oBigPsbSel["countries"].options[i].text==sCountry) {
				BigPsbSetSelectedIndex(oBigPsbSel["countries"], i);
				break;
			}
		}
	}
}

function BigPsbChangeCities() {
	if(bBigPsbChangeInProcess) return;
	bBigPsbChangeInProcess = true;
	BigPsbPreparePsb();
	if(oBigPsbSel["countries"]==null || oBigPsbSel["cities"]==null || oBigPsbSel["hotels"]==null) {
		BigPsbWaitToInitialization("BigPsbChangeCities");
		return;
	}
	
	//AjaxModul_waitingObjectState[sBigPsbMyPrefix + "countries"] = "busy";
	AjaxModul_waitingObjectState[sBigPsbMyPrefix + "hotels"] = "busy";
	AjaxModul_waitingObjectState[sBigPsbMyPrefix + "pcats"] = "busy";
	if(oBigPsbSel["cities"].selectedIndex>0) {
		sCountryOfTheCity = oBigPsbSel["cities"].options[oBigPsbSel["cities"].selectedIndex].id;
		if(sCountryOfTheCity!=oBigPsbSel["countries"].options[oBigPsbSel["countries"].selectedIndex].text) {
			BigPsbClearSelect("hotels");
			aBigPsbSetIndexTo1["countries"] = true;
			BigPsbCallAjax("countries", 0, oBigPsbSel["cities"].value);
		}
		//else AjaxModul_waitingObjectState[sBigPsbMyPrefix + "countries"] = "finished";
		BigPsbCallAjax("hotels", sBigPsbIgnoredValue, oBigPsbSel["cities"].value);
		BigPsbCallAjax("pcats", sBigPsbIgnoredValue, oBigPsbSel["cities"].value);
	}
	else {
		BigPsbClearSelect("countries");
		BigPsbCallAjax("countries", sPsbIgnoredValue);
		BigPsbCallAjax("cities", sPsbIgnoredValue);
		BigPsbCallAjax("hotels", sPsbIgnoredValue);
		BigPsbCallAjax("pcats", sPsbIgnoredValue);
	}
	bBigPsbChangeInProcess = false;

	//oPsbSel["cities"].selectedIndex = oBigPsbSel["cities"].selectedIndex;
	//PsbChangeCities();
}

function BigPsbChangeHotels() {
	if(bBigPsbChangeInProcess) return;
	bBigPsbChangeInProcess = true;
	BigPsbPreparePsb();
	if(oBigPsbSel["countries"]==null || oBigPsbSel["cities"]==null || oBigPsbSel["hotels"]==null) {
		BigPsbWaitToInitialization("BigPsbChangeHotels");
		return;
	}
	
	AjaxModul_waitingObjectState[sBigPsbMyPrefix + "countries"] = "busy";
	AjaxModul_waitingObjectState[sBigPsbMyPrefix + "cities"] = "busy";
	AjaxModul_waitingObjectState[sBigPsbMyPrefix + "pcats"] = "busy";
	
	BigPsbClearSelect("countries");
	iBigPsbSavedCity = oBigPsbSel["cities"].value;
	if(oBigPsbSel["hotels"].value==0) iBigPsbSavedCity = 0;
	BigPsbClearSelect("cities");
	aBigPsbSetIndexTo1["countries"] = true;
	BigPsbCallAjax("countries", sBigPsbIgnoredValue, sBigPsbIgnoredValue, oBigPsbSel["hotels"].value);
	setTimeout("BigPsbChangeHotels_Step2()", iCommonPsbTimeOut);
	
	//oPsbSel["hotels"].selectedIndex = oBigPsbSel["hotels"].selectedIndex;
	//PsbChangeHotels();
}

function BigPsbChangeHotels_Step2() {
	if(oBigPsbSel["countries"].options[0].text==sBigPsbWaitingText) {
		setTimeout("BigPsbChangeHotels_Step2()", iCommonPsbTimeOut);
		return;
	}
	aBigPsbSetIndexTo1["cities"] = true;
	BigPsbCallAjax("cities", sBigPsbIgnoredValue, sBigPsbIgnoredValue, oBigPsbSel["hotels"].value);
	setTimeout("BigPsbChangeHotels_Step3()", iCommonPsbTimeOut);
}

function BigPsbChangeHotels_Step3() {
	if(oBigPsbSel["cities"].options[0].text==sBigPsbWaitingText) {
		setTimeout("BigPsbChangeHotels_Step3()", iCommonPsbTimeOut);
		return;
	}
	
	if(oBigPsbSel["hotels"].selectedIndex<=0 && iBigPsbSavedCity) {
		if(oBigPsbSel["cities"].value!=iBigPsbSavedCity) {
			for(var i=0; i<oBigPsbSel["cities"].options.length; i++) {
				if(oBigPsbSel["cities"].options[i].value==iBigPsbSavedCity) {
					//oBigPsbSel["cities"].selectedIndex = i;
					BigPsbSetSelectedIndex(oBigPsbSel["cities"], i);
					break;
				}
			}
		}
		iBigPsbSavedCity = 0;
	}
	
	BigPsbCallAjax("pcats", sBigPsbIgnoredValue, oBigPsbSel["cities"].options[oBigPsbSel["cities"].selectedIndex].value, oBigPsbSel["hotels"].value);
	
	bBigPsbChangeInProcess = false;
}

function BigPsbChangePcats() {
	if(bBigPsbChangeInProcess) return;
	bBigPsbChangeInProcess = true;
	
	BigPsbPreparePsb();
	if(oBigPsbSel["countries"]==null || oBigPsbSel["cities"]==null || oBigPsbSel["hotels"]==null) {
		BigPsbWaitToInitialization("BigPsbChangePcats");
		return;
	}
	
	var a = BigPsbGetSubcatCheckboxesCheckeds();
	sSubacts = "";
	if(a && a.length) for(var i in a) if(a[i] && a[i].value) sSubacts += (sSubacts ? "," : "") + a[i].value;
	
	BigPsbSetSubcatsRows();
	
	if(oBigPsbSel["countries"].selectedIndex<=0) {
		AjaxModul_waitingObjectState[sBigPsbMyPrefix + "countries"] = "busy";
		AjaxModul_waitingObjectState[sBigPsbMyPrefix + "cities"] = "busy";
		AjaxModul_waitingObjectState[sBigPsbMyPrefix + "hotels"] = "busy";
		BigPsbCallAjax("countries", sBigPsbIgnoredValue, sBigPsbIgnoredValue, sBigPsbIgnoredValue, sSubacts);
		setTimeout("BigPsbChangePcats_Step2('" + sSubacts + "')", iCommonPsbTimeOut);
		return;
	}
	else if(oBigPsbSel["cities"].selectedIndex<=0) {
		AjaxModul_waitingObjectState[sBigPsbMyPrefix + "cities"] = "busy";
		AjaxModul_waitingObjectState[sBigPsbMyPrefix + "hotels"] = "busy";
		BigPsbCallAjax("cities", oBigPsbSel["countries"].value, sBigPsbIgnoredValue, sBigPsbIgnoredValue, sSubacts);
		setTimeout("BigPsbChangePcats_Step3('" + sSubacts + "')", iCommonPsbTimeOut);
		return;
	}
	else if(oBigPsbSel["hotels"].selectedIndex<=0) {
		AjaxModul_waitingObjectState[sBigPsbMyPrefix + "hotels"] = "busy";
		BigPsbCallAjax("hotels", sBigPsbIgnoredValue, oBigPsbSel["cities"].value, sBigPsbIgnoredValue, sSubacts);
	}
	bBigPsbChangeInProcess = false;
	
}

function BigPsbChangePcats_Step2(sSubacts) {
	if(oBigPsbSel["countries"].options[0].text==sBigPsbWaitingText) {
		setTimeout("BigPsbChangePcats_Step2('" + sSubacts + "')", iCommonPsbTimeOut);
		return;
	}
	BigPsbCallAjax("cities", oBigPsbSel["countries"].value, sBigPsbIgnoredValue, sBigPsbIgnoredValue, sSubacts);
	setTimeout("BigPsbChangePcats_Step2_2('" + sSubacts + "')", iCommonPsbTimeOut);
}

function BigPsbChangePcats_Step2_2(sSubacts) {
	if(oBigPsbSel["cities"].options[0].text==sBigPsbWaitingText) {
		setTimeout("BigPsbChangePcats_Step2_2('" + sSubacts + "')", iCommonPsbTimeOut);
		return;
	}
	BigPsbCallAjax("hotels", oBigPsbSel["countries"].value, oBigPsbSel["cities"].value, sBigPsbIgnoredValue, sSubacts);
	bBigPsbChangeInProcess = false;
}

function BigPsbChangePcats_Step3(sSubacts) {
	if(oBigPsbSel["cities"].options[0].text==sBigPsbWaitingText) {
		setTimeout("BigPsbChangePcats_Step3('" + sSubacts + "')", iCommonPsbTimeOut);
		return;
	}
	BigPsbCallAjax("hotels", oBigPsbSel["countries"].value, oBigPsbSel["cities"].value, sBigPsbIgnoredValue, sSubacts);

	bBigPsbChangeInProcess = false;
}

function BigPsbGetSubcatCheckboxes() {
	var aSubcatCheckboxes = new Array();
	var j = -1;
	a = document.bigpsbform.getElementsByTagName("INPUT");
	if(a && a.length) for(i in a) {
		if(a[i] && a[i].id && a[i].id.search(/^Bigpcats\_/)!=-1) {
			j++;
			aSubcatCheckboxes[j] = a[i];
		}
	}
	return aSubcatCheckboxes;
}

function BigPsbGetSubcatCheckboxesCheckeds() {
	var a = BigPsbGetSubcatCheckboxes();
	var aCheckeds = new Array();
	var j = -1;
	if(a && a.length) for(var i in a) {
		if(a[i].checked) {
			j++;
			aCheckeds[j] = a[i];
		}
	}
	return aCheckeds;
}

function BigPsbSetSubcatsToUnchecked() {
	var a = BigPsbGetSubcatCheckboxesCheckeds();
	if(a && a.length) for(var i in a) if(a[i]) a[i].checked = false;
	
	PsbSetSubcatsToUnchecked();
}

function BigPsbSetSubcatsRows() {
	/*
	var oSel = document.getElementById("catsel_selectebox");
	if(!oSel) return;
	var aCheckeds = BigPsbGetSubcatCheckboxesCheckeds();
	oSel.options[0].text = aCheckeds && aCheckeds.length>0 ? sBigPsbSubcatSelected : sBigPsbSubcatAll;
	*/
	
	var aCats = BigPsbGetSubcatCheckboxes();
	if(aCats && aCats.length) for(i in aCats) {
		sRowColor = aCats[i].checked ? sBigPsbBgChecked : sBigPsbBgNormal;
		oRow = document.getElementById("Bigrow_subcat_" + aCats[i].id.replace(/^Bigpcats\_/, ""));
		if(oRow) {
			for(i in oRow.cells) if(oRow.cells[i] && oRow.cells[i].tagName=="TD") {
				oRow.cells[i].style.backgroundColor = sRowColor;
			}
		}
	}
}

function BigPsbSubcatOver(oRow, sSubcatID) {
	var oSubcat = document.getElementById(sSubcatID);
	for(i in oRow.cells) if(oRow.cells[i] && oRow.cells[i].tagName=="TD") {
		oRow.cells[i].style.backgroundColor = oSubcat.checked ? sBigPsbBgCheckedOnOver : sBigPsbBgNormalOnOver;
	}
}

function BigPsbubcatOut(oRow, sSubcatID) {
	var oSubcat = document.getElementById(sSubcatID);
	for(i in oRow.cells) if(oRow.cells[i] && oRow.cells[i].tagName=="TD") {
		oRow.cells[i].style.backgroundColor = oSubcat.checked ? sBigPsbBgChecked : sBigPsbBgNormal;
	}
}

function BigPsbReceiverForSubcats(sReturnValue) {
	var oTable = document.getElementById(sBigPsbMyPrefix + "pcats");
	if(!oTable) return;
	var sSeparator0 = "¨˙¨";
	var aX = sReturnValue.split(sSeparator0);
	
	if(aX[1].search(/id=\"row_subcat/)!=-1) {
		// this is a wrong table!
		// do not receive it!
		AjaxModul_waitingObjectState[sBigPsbMyPrefix + "pcats"] = "finished";
		return;
	}
	
	if(sOcms_BrowserName=="MSIE") {
	
		var oOldTBody = null;
		if(oTable && oTable.childNodes) for(var i in oTable.childNodes) {
			if(oTable.childNodes[i] && oTable.childNodes[i].tagName=="TBODY") {
				oOldTBody = oTable.childNodes[i];
				break;
			}
		}
		
		aCommonInterTables = new Array();
		iCommonInterTablesIndex = -1;
		
		var oNewTBody = CommonPsbConstructTBody(aX[1]);
		oTable.replaceChild(oNewTBody, oOldTBody);
		
		if(iCommonInterTablesIndex>=0) for(var i=0; i<=iCommonInterTablesIndex; i++) {
			var oP = document.getElementById("BigPsbInterTable" + i);
			if(oP) oP.replaceNode(aCommonInterTables[i]);
		}
	}
	else {
		oTable.innerHTML = aX[1]; // row index = 721.
	}
	BigPsbSetSubcatsRows();
	AjaxModul_waitingObjectState[sBigPsbMyPrefix + "pcats"] = "finished";
}


function BigPsbCheckSubcats(oAhref, iMaincatID, sSubcatIds) {
	oAhref.blur();
	if(!sSubcatIds) return false;
	aBigPsbSubcatsChecked[iMaincatID] = aBigPsbSubcatsChecked[iMaincatID] ? false : true;
	var a = sSubcatIds.split(",");
	if(a && a.length) for(var i in a) {
		oCheckbox = document.getElementById("Bigpcats_" + a[i]);
		if(oCheckbox) {
			oCheckbox.checked = aBigPsbSubcatsChecked[iMaincatID];
			oBlueCheckbox = document.getElementById("pcats_" + a[i]);
			if(oBlueCheckbox) oBlueCheckbox.checked = oCheckbox.checked;
		}
	}
	BigPsbSetSubcatsRows();
	//PsbSetSubcatsRows();
	return false;
}

function BigPsbSetSelectedIndex(oSel, iIndex) {
	if(!oSel) return;
	if(sOcms_BrowserName=="MSIE") {
		if(oSel.options[iIndex]) oSel.options[iIndex].setAttribute('selected',true);
	}
	else {
		oSel.selectedIndex = iIndex;
	}
}

function BigPsbSynchronizePsb() {

	if(sCommonsPsbMainSynchronizator=="BlueSearchBox") return;
	sCommonsPsbMainSynchronizator = "BigSearchPage";
	
	if(bBigPsbChangeInProcess) {
		setTimeout("BigPsbSynchronizePsb()", iCommonPsbTimeOut);
		return;
	}
	
	for(var i in aCommonsPsbSuffixes) {
		if(AjaxModul_waitingObjectState[sBigPsbMyPrefix + aCommonsPsbSuffixes[i]]=="busy") {
			setTimeout("BigPsbSynchronizePsb()", iCommonPsbTimeOut);
			return;
		}
	}
	
	for(var i in aCommonsPsbSuffixes) {
		oSource = oBigPsbSel[aCommonsPsbSuffixes[i]];
		if(oSource.tagName=="SELECT" && oSource.options[0].text==sBigPsbWaitingText) {
			setTimeout("BigPsbSynchronizePsb()", iCommonPsbTimeOut);
			return;
		}
	}

	var oTableSource = null;
	var oTableDestination = null;
	for(var i in aCommonsPsbSuffixes) {
		oSource = oBigPsbSel[aCommonsPsbSuffixes[i]];
		oDestination = oPsbSel[aCommonsPsbSuffixes[i]];
		if(oSource.tagName=="TABLE") { oTableSource = oSource; oTableDestination = oDestination; }
		else CommonPsbCopyOptions(oSource, oDestination, "");
	}
	if(oTableSource && oTableDestination) {
		CommonPsbCopyTable(oTableSource, oTableDestination, "");
	}

	setTimeout("CommonPsbResetMainSynchronizatorParameter()", iCommonPsbTimeOut);
	
}

function BigPsbWaitToInitialization(sFunctionName) {
	eval("setTimeout(\"" + sFunctionName + "()\", " + iCommonPsbTimeOut + ");");
}

function BigPsbPreparePsb() {
	for(var i in aCommonsPsbSuffixes) PsbClearSelect(aCommonsPsbSuffixes[i]);
}




//--------------------------------------------------------------------------------------------------
// Common functions & parameters
//--------------------------------------------------------------------------------------------------

var iCommonPsbTimeOut = sOcms_BrowserName!="MSIE" ? 50 : (sOcms_BrowserVersionMajor<=6 ? 100 : 75);
var sCommonsPsbMainSynchronizator = "";
var aCommonsPsbSuffixes = new Array("countries", "cities", "hotels", "pcats");
var aCommonInterTables = new Array();
var iCommonInterTablesIndex = -1;

function CommonPsbCopyOptions(oSelSource, oSelDestination, sPrefix) {
	
	eval("b" + sPrefix + "PsbChangeInProcess = true;")
	
	for(i=oSelDestination.childNodes.length-1; i>=0; i--) oSelDestination.removeChild(oSelDestination.childNodes[i]);
	
	var j = 0;
	while(j<=oSelSource.children.length-1) {
		oOption = oSelSource.children[j];
		if(oOption.tagName=="OPTGROUP") {
			var oGroup = document.createElement("OPTGROUP");
			oGroup.label = oOption.label;
			oGroup.style.fontWeight = "bold";
			oGroup.style.color = "black";
			oGroup.style.fontStyle = "normal";
			for(var k=0; k<=oOption.children.length-1; k++) {
				CommonPsbInsertNewOption(oGroup, oOption.children[k].text, oOption.children[k].value, oOption.children[k].id);
			}
			oSelDestination.appendChild(oGroup);
		}
		else {
			CommonPsbInsertNewOption(oSelDestination, oOption.text, oOption.value, oOption.id);
		}
		j++;
	}
	
	oSelDestination.selectedIndex = oSelSource.selectedIndex;
	
	oSelDestination.style.color = "#000000";
	
	eval("b" + sPrefix + "PsbChangeInProcess = false;")
}

function CommonPsbInsertNewOption(oSel, sText, sValue, sID) {
	if(document.all) {
		oNewOption = document.createElement("OPTION");
		oNewOption.setAttribute("value", sValue);
		oNewOption.setAttribute("innerText", sText);
		if(sID) oNewOption.setAttribute("id", sID);
    oSel.insertBefore(oNewOption);
	}
	else {
		oNewOption = new Option(sText, sValue);
		if(sID) oNewOption.id = sID;
    oSel.appendChild(oNewOption);
  }
}

function CommonPsbCopyTable(oTableSource, oTableDestination, sPrefix) {
	if(oTableDestination.id=="danupackagebox_pcats") {
		AjaxModul_waitingObjectState["danupackagebox_pcats"] = "busy";
		PsbCallAjax("pcats", oBigPsbSel["countries"].value, oBigPsbSel["cities"].value, oBigPsbSel["hotels"].value);
		iCommonPsbTimerCounter = 0;
		CommonPsbCopyTable_step2(sPrefix);
		
		//PsbSetSubcatsRows();
	}
	else {
		AjaxModul_waitingObjectState["Bigdanupackagebox_pcats"] = "busy";
		BigPsbCallAjax("pcats", oPsbSel["countries"].value, oPsbSel["cities"].value, oPsbSel["hotels"].value);
		
		iCommonPsbTimerCounter = 0;
		CommonPsbCopyTable_step2(sPrefix);
		
		//BigPsbSetSubcatsRows();
	}
}

function CommonPsbCopyTable_step2(sPrefix) {
	var sContraPrefix = sPrefix=="Big" ? "" : "Big";
	if(AjaxModul_waitingObjectState[sPrefix + "danupackagebox_pcats"]=="busy") {
		iCommonPsbTimerCounter++;
		if(iCommonPsbTimerCounter<100) {
			document.body.focus();
			setTimeout("CommonPsbCopyTable_step2('" + sPrefix + "')", iCommonPsbTimeOut);
			return;
		}
	}
//alert("AjaxModul_waitingObjectState['" + sPrefix + "danupackagebox_pcats'] = " + AjaxModul_waitingObjectState[sPrefix + "danupackagebox_pcats"]);
	AjaxModul_waitingObjectState[sPrefix + "danupackagebox_pcats"] = "finished";
	iCommonPsbTimerCounter = 0;

	eval("b" + sPrefix + "PsbChangeInProcess = true;")
	eval("var a = " + sContraPrefix + "PsbGetSubcatCheckboxes();");
	var sPcats = "";
	if(a && a.length>0) for(var i in a) {
		oCheckbox = document.getElementById(sPrefix + "pcats_"+a[i].value);
		if(oCheckbox) {
			oCheckbox.checked = a[i].checked;
		}
//alert(sPrefix + "pcats_" + a[i].value + " = " + oCheckbox + "\na[" + i + "].checked = " + a[i].checked);
	}
	
	eval("b" + sPrefix + "PsbChangeInProcess = false;")
	
	eval(sPrefix + "PsbSetSubcatsRows();");
}

function CommonPsbResetMainSynchronizatorParameter() {
	sCommonsPsbMainSynchronizator = "";
}

function CommonPsbConstructTBody(sTableInnerSource) {
	
	var p1 = sTableInnerSource.search(/<table[^>]*>/);
	
	while(p1>=0) {
		p2 = sTableInnerSource.search(/<\/table>/);
		if(p2==-1) break;
		s = sTableInnerSource.substr(p1, p2-p1+8);
		if(s=="") break;
		
		iCommonInterTablesIndex++;
		
		sTableInnerSource = sTableInnerSource.substr(0, p1)
			+ "<p id='BigPsbInterTable"+iCommonInterTablesIndex+"'>Inter table " + iCommonInterTablesIndex + "</p>"
			+ sTableInnerSource.substr(p2+8);
		
		s = s.replace(/<[\/]*table[^>]*>/g, "");
		var oNewTBody = CommonPsbConstructTBody(s);
		
		aCommonInterTables[iCommonInterTablesIndex] = document.createElement("TABLE");
		aCommonInterTables[iCommonInterTablesIndex].appendChild(oNewTBody);
		aCommonInterTables[iCommonInterTablesIndex].cellSpacing = "0";
		
		p1 = sTableInnerSource.search(/<table[^>]*>/);
	}
		
	var oNewTBody = document.createElement("TBODY");
	
	var aRows = sTableInnerSource.split(/<TR/i);
	if(aRows && aRows.length) for(r in aRows) {
		if(r==0 || aRows[r]=="") continue;
		p = aRows[r].search(/>/);
		sRowAttributes = p>0 ? aRows[r].substr(0, p) : "";
		sRowInnerHtml = p>=0 ? aRows[r].substr(p+1) : "";
		oRow = document.createElement("TR");
		res = sRowAttributes.match(/id\=\"([^\"]+)\"/);
		if(res && res[1]) oRow.id = res[1];
		res = sRowAttributes.match(/onmouseover\=\"([^\"]+)\"/);
		if(res && res[1]) eval("oRow.onmouseover = function() { " + res[1] + "; }");
		res = sRowAttributes.match(/onmouseout\=\"([^\"]+)\"/);
		if(res && res[1]) eval("oRow.onmouseout = function() { " + res[1] + "; }");
		aCells = sRowInnerHtml.split(/<TD/i);
		if(aCells && aCells.length) for(c in aCells) {
			if(c==0 || aCells[c]=="") continue;
			oCell = document.createElement("TD");
			p = aCells[c].search(/>/);
			sCellAttributes = p>0 ? aCells[c].substr(0, p) : "";
			sCellInnerHtml = p>=0 ? aCells[c].substr(p+1) : "";
			x = sCellInnerHtml.split(/<\/TD>/i);
			oCell.innerHTML = x[0];
			
			res = sCellAttributes.match(/colspan\=\"([0-9]+)\"/);
			if(res && res[1]) oCell.colSpan = res[1];
			res = sCellAttributes.match(/style\=\"([^\"]+)\"/);
			if(res && res[1]) oCell.style.cssText = res[1];
			res = sCellAttributes.match(/onclick\=\"([^\"]+)\"/);
			if(res && res[1]) eval("oCell.onclick = function() { " + res[1] + "; }");
			res = sCellAttributes.match(/width\=\"([^\"]+)\"/);
			if(res && res[1]) oCell.width = res[1];
			oRow.appendChild(oCell);
			
		}
		oNewTBody.appendChild(oRow);
	}
	
	return oNewTBody;
}



