// package search panel

var oPsbSel = new Array();
var bPsbChangeInProcess = false;
var sPsbIgnoredValue = 0;
var sPsbAjaxScript = "/inc/sitespecific/danubius/modul1/getform_packages_ajaxhandler.php";
var iCommonPsbTimeOut = sOcms_BrowserName!="MSIE" ? 50 : (sOcms_BrowserVersionMajor<=6 ? 100 : 75);
var sPsbWaitingText = ""; //"in process...";
var sPsbNullText = "-- all --";
var aPsbSetIndexTo1 = new Array();
var sPsbSubcatAll = "-- all --";
var sPsbSubcatSelected = "My selected categories";
var iPsbCatsOpen = 0;
var aPsbSubcatsChecked = new Array();
var oPsbCatsDiv = null;
var iPsbSavedCity = 0;
var aPsbCheckedSubcats = new Array();
var sPsbMyPrefix = "danupackagebox_";
var bPsbForm19Loaded = false;
var bPsbDblClick = false;


function PsbInit(sLang, sWaitingText, sNullText, sSubcatAll, sSubcatSelected, sMustOneSubcat, sMustCityOrHotel) {
	oPsbSel["countries"] = document.getElementById("danupackagebox_countries");
	oPsbSel["cities"] = document.getElementById("danupackagebox_cities");
	oPsbSel["hotels"] = document.getElementById("danupackagebox_hotels");
	oPsbSel["pcats"] = document.getElementById("danupackagebox_pcats");
	
	aPsbSetIndexTo1["countries"] = false;
	aPsbSetIndexTo1["cities"] = false;
	aPsbSetIndexTo1["hotels"] = false;
	
	sPsbWaitingText = sWaitingText;
	sPsbNullText = sNullText;
	sPsbSubcatAll = sSubcatAll;
	sPsbSubcatSelected = sSubcatSelected;
	sPsbMustOneSubcat = sMustOneSubcat;
	sPsbMustCityOrHotel = sMustCityOrHotel;
	
	sPsbAjaxScript += "?callerlang=" + sLang + "&change=";
	
	aAjaxModul_specialFinisher["danupackagebox_countries"] = "PsbFinisherCountries";
	aAjaxModul_specialFinisher["danupackagebox_cities"] = "PsbFinisherCities";
	aAjaxModul_specialFinisher["danupackagebox_hotels"] = "PsbFinisherHotels";
	
	sAjaxModul_otherReceiver["danupackagebox_pcats"] = "PsbReceiverForSubcats";
	
	AjaxModul_init("AjaxModul_receiverForSelectBox");
}

function PsbFinisherGlobal(sMyID) {
	if(oPsbSel[sMyID] && oPsbSel[sMyID].tagName=="TABLE") return;
	oPsbSel[sMyID].options[0].text = sPsbNullText;
	if(aPsbSetIndexTo1[sMyID]) {
		if(oPsbSel[sMyID].options.length==2) PsbSetSelectedIndex(oPsbSel[sMyID], 1);
		else if(sMyID=="countries") {
			setTimeout("PsbChangeCountries_ifSetToOneButCant()", iCommonPsbTimeOut);
		}
		aPsbSetIndexTo1[sMyID] = false;
	}
	oPsbSel[sMyID].style.color = "#000000";
	PsbSynchronizePsb();
}

function PsbFinisherCountries() { PsbFinisherGlobal("countries"); }
function PsbFinisherCities() { PsbFinisherGlobal("cities"); }
function PsbFinisherHotels() { PsbFinisherGlobal("hotels"); }

function PsbCallAjax(sToChange, sCountry, sCity, sHotel, sPcats) {
	if(!oPsbSel[sToChange]) return;
	PsbClearSelect(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 = sPsbAjaxScript + sToChange + sParams;
	AjaxModul_call(sUrl, "AjaxModul_receiverForSelectBox", "danupackagebox_");
}

function PsbClearSelect(sMyID) {
	if(oPsbSel[sMyID] && oPsbSel[sMyID].tagName=="TABLE") {
		document.getElementById("catsel_selectebox").options[0].text = sPsbWaitingText;
		document.getElementById("catsel_selectebox").style.color = "#cbcbcb";
		return;
	}
	for(var i=oPsbSel[sMyID].options.length-1; i>0; i--) oPsbSel[sMyID].options[i] = null;
	oPsbSel[sMyID].options[0].text = sPsbWaitingText;
	oPsbSel[sMyID].style.color = "#cbcbcb";
}

function PsbResetAll() {
	if(bPsbChangeInProcess) return;
	bPsbChangeInProcess = true;
	
	var x = new Array("countries", "cities", "hotels");
	
	if(bPsbForm19Loaded) {
		for(var i in x) {
			oSource = oBigPsbSel[x[i]];
			if(oSource.tagName=="SELECT" && oSource.options[0].text==sPsbWaitingText) {
				// valaki túl gyorsan nyomta meg a resetet egymás után!!!
				bPsbChangeInProcess = false;
				return false;
			}
		}
	}
	
	for(var i in x) {
		oSource = oPsbSel[x[i]];
		if(oSource && oSource.tagName=="SELECT" && oSource.options[0].text==sPsbWaitingText) {
			setTimeout("PsbResetAll()", iCommonPsbTimeOut);
			return false;
		}
	}
	
	
	
	PsbPreparePsb();
	
	PsbClearSelect("countries");
	PsbClearSelect("cities");
	PsbClearSelect("hotels");
	PsbCallAjax("countries");
	PsbCallAjax("cities");
	PsbCallAjax("hotels");
	
	PsbSetSubcatsToUnchecked();
	PsbCallAjax("pcats");
	PsbSetSubcatsRows();
	
	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) PsbSetSelectedIndex(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";
	
	bPsbChangeInProcess = false;
	
	var oSel = document.getElementById("catsel_selectebox");
	if(oSel) oSel.style.color = "#000000";
	
	PsbSynchronizePsb();
	
	return false;
}

function PsbResetCats() {
	if(bPsbChangeInProcess) return;
	bPsbChangeInProcess = true;
	
	PsbSetSubcatsToUnchecked();
	
	bPsbChangeInProcess = false;
	PsbChangePcats();
	
	return false;
}

function PsbChangeCountries() {
	if(bPsbChangeInProcess) return;
	bPsbChangeInProcess = true;
	
	PsbPreparePsb();
	
	PsbClearSelect("cities");
	PsbClearSelect("hotels");
	if(oPsbSel["countries"].selectedIndex<=0) PsbCallAjax("countries");
	PsbCallAjax("cities", oPsbSel["countries"].value);
	PsbCallAjax("hotels", oPsbSel["countries"].value);
	PsbCallAjax("pcats", oPsbSel["countries"].value);
	
	bPsbChangeInProcess = false;
}

function PsbChangeCountries_ifSetToOneButCant() {
	if(oPsbSel["cities"].options[0].text==sPsbWaitingText) {
		setTimeout("PsbChangeCountries_ifSetToOneButCant()", iCommonPsbTimeOut);
		return;
	}
	var sCountry = oPsbSel["cities"].options[oPsbSel["cities"].selectedIndex].id;
	if(oPsbSel["countries"]!=sCountry) {
		for(var i=0; i<oPsbSel["countries"].options.length; i++) {
			if(oPsbSel["countries"].options[i].text==sCountry) {
				PsbSetSelectedIndex(oPsbSel["countries"], i);
				break;
			}
		}
	}
}

function PsbChangeCities() {
	if(bPsbChangeInProcess) return;
	bPsbChangeInProcess = true;
	
	PsbPreparePsb();
	
	if(oPsbSel["cities"].selectedIndex>0) {
		sCountryOfTheCity = oPsbSel["cities"].options[oPsbSel["cities"].selectedIndex].id;
		if(sCountryOfTheCity!=oPsbSel["countries"].options[oPsbSel["countries"].selectedIndex].text) {
			PsbClearSelect("hotels");
			aPsbSetIndexTo1["countries"] = true;
			PsbCallAjax("countries", 0, oPsbSel["cities"].value);
		}
		PsbCallAjax("hotels", sPsbIgnoredValue, oPsbSel["cities"].value);
		PsbCallAjax("pcats", sPsbIgnoredValue, oPsbSel["cities"].value);
	}
	else {
		PsbClearSelect("countries");
		PsbCallAjax("countries", sPsbIgnoredValue);
		PsbCallAjax("cities", sPsbIgnoredValue);
		PsbCallAjax("hotels", sPsbIgnoredValue);
		PsbCallAjax("pcats", sPsbIgnoredValue);
	}
	bPsbChangeInProcess = false;
}

function PsbChangeHotels() {
	if(bPsbChangeInProcess) return;
	bPsbChangeInProcess = true;
	
	PsbPreparePsb();
	
	PsbClearSelect("countries");
	iPsbSavedCity = oPsbSel["cities"].value;
	if(oPsbSel["hotels"].value==0) iPsbSavedCity = 0;
	PsbClearSelect("cities");
	aPsbSetIndexTo1["countries"] = true;
	PsbCallAjax("countries", sPsbIgnoredValue, sPsbIgnoredValue, oPsbSel["hotels"].value);
	setTimeout("PsbChangeHotels_Step2()", iCommonPsbTimeOut);
}

function PsbChangeHotels_Step2() {
	if(oPsbSel["countries"].options[0].text==sPsbWaitingText) {
		setTimeout("PsbChangeHotels_Step2()", iCommonPsbTimeOut);
		return;
	}
	aPsbSetIndexTo1["cities"] = true;
	PsbCallAjax("cities", sPsbIgnoredValue, sPsbIgnoredValue, oPsbSel["hotels"].value);
	setTimeout("PsbChangeHotels_Step3()", iCommonPsbTimeOut);
}

function PsbChangeHotels_Step3() {
	if(oPsbSel["cities"].options[0].text==sPsbWaitingText) {
		setTimeout("PsbChangeHotels_Step3()", iCommonPsbTimeOut);
		return;
	}
	
	if(oPsbSel["hotels"].selectedIndex<=0 && iPsbSavedCity) {
		if(oPsbSel["cities"].value!=iPsbSavedCity) {
			for(var i=0; i<oPsbSel["cities"].options.length; i++) {
				if(oPsbSel["cities"].options[i].value==iPsbSavedCity) {
					//oPsbSel["cities"].selectedIndex = i;
					PsbSetSelectedIndex(oPsbSel["cities"], i);
					break;
				}
			}
		}
		iPsbSavedCity = 0;
	}
	
	PsbCallAjax("pcats", sPsbIgnoredValue, oPsbSel["cities"].options[oPsbSel["cities"].selectedIndex].value, oPsbSel["hotels"].value);
	
	bPsbChangeInProcess = false;
}

function PsbChangePcats() {
	if(bPsbChangeInProcess) return;
	bPsbChangeInProcess = true;
	var a = PsbGetSubcatCheckboxesCheckeds();
	sSubacts = "";
	aPsbCheckedSubcats = new Array();
	var j = -1;
	if(a && a.length) for(var i in a) if(a[i] && a[i].value) {
		sSubacts += (sSubacts ? "," : "") + a[i].value;
		if(a[i].checked || a[i].getAttribute("checked")) {
			j++;
			aPsbCheckedSubcats[j] = a[i];
		}
	}
	
	PsbSetSubcatsRows();
	
	if(oPsbSel["countries"] && oPsbSel["countries"].selectedIndex<=0) {
		PsbCallAjax("countries", sPsbIgnoredValue, sPsbIgnoredValue, sPsbIgnoredValue, sSubacts);
		setTimeout("PsbChangePcats_Step2('" + sSubacts + "')", iCommonPsbTimeOut);
		return;
	}
	else if(oPsbSel["cities"] && oPsbSel["cities"].selectedIndex<=0) {
		PsbCallAjax("cities", oPsbSel["countries"].value, sPsbIgnoredValue, sPsbIgnoredValue, sSubacts);
		setTimeout("PsbChangePcats_Step3('" + sSubacts + "')", iCommonPsbTimeOut);
		return;
	}
	else if(oPsbSel["hotels"] && oPsbSel["hotels"].selectedIndex<=0) {
		PsbCallAjax("hotels", sPsbIgnoredValue, oPsbSel["cities"].value, sPsbIgnoredValue, sSubacts);
		PsbSynchronizePsb();
		bPsbChangeInProcess = false;
	}
	
	
}

function PsbChangePcats_Step2(sSubacts) {
	if(oPsbSel["countries"] && oPsbSel["countries"].options[0].text==sPsbWaitingText) {
		setTimeout("PsbChangePcats_Step2('" + sSubacts + "')", iCommonPsbTimeOut);
		return;
	}
	PsbCallAjax("cities", oPsbSel["countries"].value, sPsbIgnoredValue, sPsbIgnoredValue, sSubacts);
	setTimeout("PsbChangePcats_Step2_2('" + sSubacts + "')", iCommonPsbTimeOut);
}

function PsbChangePcats_Step2_2(sSubacts) {
	if(oPsbSel["cities"] && oPsbSel["cities"].options[0].text==sPsbWaitingText) {
		setTimeout("PsbChangePcats_Step2_2('" + sSubacts + "')", iCommonPsbTimeOut);
		return;
	}
	PsbCallAjax("hotels", oPsbSel["countries"].value, oPsbSel["cities"].value, sPsbIgnoredValue, sSubacts);
	PsbSynchronizePsb();
	bPsbChangeInProcess = false;
}

function PsbChangePcats_Step3(sSubacts) {
	if(oPsbSel["cities"] && oPsbSel["cities"].options[0].text==sPsbWaitingText) {
		setTimeout("PsbChangePcats_Step3('" + sSubacts + "')", iCommonPsbTimeOut);
		return;
	}
	PsbCallAjax("hotels", oPsbSel["countries"].value, oPsbSel["cities"].value, sPsbIgnoredValue, sSubacts);
	PsbSynchronizePsb();
	bPsbChangeInProcess = false;
}

function PsbGetSubcatCheckboxes() {
	var aSubcatCheckboxes = new Array();
	var j = -1;
	var oSubcatCheckbox = null;
	a = document.packagesearchform.getElementsByTagName("INPUT");
	if(a && a.length) for(i in a) {
		oSubcatCheckbox = null;
		if(sOcms_BrowserName=="MSIE" && i.search(/^\_ufh\[20016\]\[([0-9]+)\]/)!=-1) {
			var reg = /^\_ufh\[20016\]\[([0-9]+)\]/;
			b = i.match(reg);
			oSubcatCheckbox = document.getElementById("pcats_" + b[1]);
		}
		else if(a[i] && a[i].id && a[i].id.search(/^pcats\_/)!=-1) {
			oSubcatCheckbox = a[i];
		}
		if(oSubcatCheckbox) {
			j++;
			aSubcatCheckboxes[j] = oSubcatCheckbox;
		}
	}
	return aSubcatCheckboxes;
}

function PsbGetSubcatCheckboxesCheckeds() {
	var a = PsbGetSubcatCheckboxes();
	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 PsbSetSubcatsToUnchecked() {
	var a = PsbGetSubcatCheckboxesCheckeds();
	if(a && a.length) for(var i in a) if(a[i]) a[i].checked = false;
	aPsbCheckedSubcats = new Array();
}

function PsbSetSubcatsRows() {
	var oSel = document.getElementById("catsel_selectebox");
	if(!oSel) return;
	var aCheckeds = PsbGetSubcatCheckboxesCheckeds();
	oSel.options[0].text = aCheckeds && aCheckeds.length>0 ? sPsbSubcatSelected : sPsbSubcatAll;
	
	var aCats = PsbGetSubcatCheckboxes();
	if(aCats && aCats.length) for(i in aCats) {
		sRowColor = aCats[i].checked ? '#8eb2db' : '#487fbc';
		oRow = document.getElementById("row_subcat_" + aCats[i].id.replace(/^pcats\_/, ""));
		if(oRow) {
			for(i in oRow.cells) if(oRow.cells[i] && oRow.cells[i].tagName=="TD") {
				oRow.cells[i].style.backgroundColor = sRowColor;
			}
		}
	}
	
}

function PsbSubcatOver(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 ? '#719bca' : '#2367b3';
	}
}

function PsbubcatOut(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 ? '#8eb2db' : '#487fbc';
	}
}

function PsbReceiverForSubcats(sReturnValue) {
	var oTable = document.getElementById("danupackagebox_pcats");
	if(!oTable) return;
	
	document.getElementById("catsel_selectebox").style.color = "#000000";
	
	var sSeparator0 = "¨˙¨";
	var aX = sReturnValue.split(sSeparator0);
	
	if(aX[1].search(/id=\"Bigdanupackagebox\_pcats\_firstrow/)!=-1) {
		// this is a wrong table!
		// do not receive it!
		AjaxModul_waitingObjectState["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;
			}
		}
		var oNewTBody = document.createElement("TBODY");
		
		var aRows = aX[1].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);
		}
		oTable.replaceChild(oNewTBody, oOldTBody);
	}
	else {
		oTable.innerHTML = aX[1]; // row index = 721.
	}
	AjaxModul_waitingObjectState["pcats"] = "finished";
	PsbSetSubcatsRows();
}

function PsbCheckSubcats(oAhref, iMaincatID, sSubcatIds) {
	oAhref.blur();
	if(!sSubcatIds) return false;
	aPsbSubcatsChecked[iMaincatID] = aPsbSubcatsChecked[iMaincatID] ? false : true;
	var a = sSubcatIds.split(",");
	if(a && a.length) for(var i in a) {
		oCheckbox = document.getElementById("pcats_" + a[i]);
		if(oCheckbox) oCheckbox.checked = aPsbSubcatsChecked[iMaincatID];
	}
	
	PsbSynchronizePsb();
	bPsbChangeInProcess = false;
	
	PsbSetSubcatsRows();
	return false;
}

function PsbHideCats() {
	var oDiv = document.getElementById("catsel_canvas");
	if(!oDiv) return false;
	if(iPsbCatsOpen==2) oDiv.style.display = "none";
	iPsbCatsOpen = 2;
}

function PsbBlurCats() {
	var bDoMagic = false;
	switch(sOcms_BrowserName) {
		case "Firefox": // do nothing
			break;
		case "MSIE":
			if(sOcms_BrowserVersionMajor<=6) {
				var oDiv = document.getElementById("catsel_canvas");
				if(!oDiv) return false;
				oSel = document.getElementById("catsel_selectebox");
				if(!oSel) return false;
				oSel.blur();
				oSel = document.getElementById("danupackagebox_countries");
				if(!oSel) return false;
				oSel.focus();
				//if(oDiv.style.display!="block") bDoMagic = true;
			}
			break;
		default:
			bDoMagic = true;
			break;
	}
	
	if(bDoMagic) {
		if(sOcms_BrowserName=="MSIE" && sOcms_BrowserVersionMajor<=6) {
			oWindow = window.open('','ForBlur','width=20,height=20,Left=0,Top=0,screenX=0,screenY=0');
			if(oWindow) {
				oWindow.focus();
				oWindow.close();
			}
		}
		else {
			window.blur();
			window.focus();
		}
	}
}

function PsbShowCats(oSel, oEvent) {
	oSel.blur();
	var oDiv = document.getElementById("catsel_canvas");
	if(!oDiv) return false;
	oPsbCatsDiv = oDiv;
	if(oDiv.style.display=="block") {
		oDiv.style.display = "none";
		iPsbCatsOpen = 0;
		oSel.blur();
		return;
	}
	
	var iLeft = 0;
	var iTop = 0;
	
	var oParentNode = oSel;
	while(oParentNode) {
		iLeft += oParentNode.offsetLeft;
		iTop += oParentNode.offsetTop;
		oParentNode = oParentNode.offsetParent;
	};
	
	oDiv.left = iLeft + "px";
	oDiv.style.left = (iLeft + 1) + "px";
	oDiv.top = iTop + "px";
	oDiv.style.width = "" + 1*(oSel.offsetWidth - 2) + "px";
	if(document.all) {
		oDiv.style.left = (iLeft + 3) + "px";
		oDiv.style.top = (iTop + 1 + oSel.offsetHeight) + "px";
	}

	//oSel.style.zIndex = 901;
	oDiv.style.display = "block";
	oDiv.focus();
	oDiv.blur();
	
	
	iPsbCatsOpen = 1;

}

function PsbSetSelectedIndex(oSel, iIndex) {
	if(!oSel) return;
	if(sOcms_BrowserName=="MSIE") {
		if(oSel.options[iIndex]) oSel.options[iIndex].setAttribute('selected',true);
	}
	else {
		oSel.selectedIndex = iIndex;
	}
}

function PsbCheckOnSubmit() {
	if(oPsbSel["cities"] && oPsbSel["cities"].selectedIndex<=0 && oPsbSel["hotels"].selectedIndex<=0) {
		alert(sPsbMustCityOrHotel);
		return false;
	}
	var a = PsbGetSubcatCheckboxesCheckeds();
	if(!a || a.length==0) {
		alert(sPsbMustOneSubcat);
		return false;
	}
	return true;
}

function PsbSynchronizePsb() {
	
	if(!bPsbForm19Loaded) return;

	if(sCommonsPsbMainSynchronizator=="BigSearchPage") return;
	sCommonsPsbMainSynchronizator = "BlueSearchBox";
	
	if(bPsbChangeInProcess) {
		setTimeout("PsbSynchronizePsb()", iCommonPsbTimeOut);
		return;
	}
	
	for(var i in aCommonsPsbSuffixes) {
		if(AjaxModul_waitingObjectState[sPsbMyPrefix + aCommonsPsbSuffixes[i]]=="busy") {
			setTimeout("PsbSynchronizePsb()", iCommonPsbTimeOut);
			return;
		}
	}
	
	for(var i in aCommonsPsbSuffixes) {
		oSource = oPsbSel[aCommonsPsbSuffixes[i]];
		if(oSource.tagName=="TABLE") oSel = document.getElementById("catsel_selectebox");
		else oSel = oSource;
		if(oSel.options[0].text==sPsbWaitingText) {
			setTimeout("PsbSynchronizePsb()", iCommonPsbTimeOut);
			return;
		}
	}
	
	var oTableSource = null;
	var oTableDestination = null;
	for(var i in aCommonsPsbSuffixes) {
		oSource = oPsbSel[aCommonsPsbSuffixes[i]];
		oDestination = oBigPsbSel[aCommonsPsbSuffixes[i]];
		if(oSource.tagName=="TABLE") { oTableSource = oSource; oTableDestination = oDestination; }
		else CommonPsbCopyOptions(oSource, oDestination, "Big");
	}
	if(oTableSource && oTableDestination) {
		CommonPsbCopyTable(oTableSource, oTableDestination, "Big");
	}
	
	setTimeout("CommonPsbResetMainSynchronizatorParameter()", iCommonPsbTimeOut);
}

function PsbPreparePsb() {
	if(!bPsbForm19Loaded) return;
	for(var i in aCommonsPsbSuffixes) BigPsbClearSelect(aCommonsPsbSuffixes[i]);
}

