function risizeTable()
{
	var centerTD = document.getElementById('centerTD');
	var listingTable = document.getElementById('listingTable');

	var oldEtalonHeigh = centerTD.clientHeight;
	var oldListing = listingTable.clientHeight;
	if (centerTD && listingTable)
	{
		if (listingTable.clientHeight<2000)
		{
			listingTable.style.height = centerTD.offsetHeight + "px";
		
			if (listingTable.clientHeight > oldEtalonHeigh)
				listingTable.style.height = oldEtalonHeigh/(listingTable.clientHeight/oldEtalonHeigh) + "px";
		}
			//listingTable.style.height = "100px";
	}
}

function goToSelectUrl(selectObj)
{
	var index = selectObj.selectedIndex;
	
	if (selectObj[index].value)
		window.document.location = selectObj[index].value; 
}

function applyFiltr(formId,selectId)
{
	var formObj = document.getElementById(formId);
	var selectObj = document.getElementById(selectId);
	if (formObj == null || selectObj == null)
		return;

	index = selectObj.selectedIndex 
	if (selectObj[index] == 0)
		return;
		
	formObj.submit();
}

function  ShowHide(id)
{
	var obj = document.getElementById(id);
	if (obj != null)
	{
		switch (obj.style.display)
		{
			case "none":
				obj.style.display = "block";
				break;
				
			case "block":
				obj.style.display = "none";
				break;
		}
	}
}

function  ShowHideVoteResults(idVote, idResults)
{
	var obj1 = document.getElementById(idVote);
	var obj2 = document.getElementById(idResults);
	if (obj1 != null && obj2 != null)
	{
		switch (obj2.style.display)
		{
			case "none":
				obj2.style.display = "block";
				obj1.style.display = "none";
				break;
				
			case "block":
				obj2.style.display = "none";
				obj1.style.display = "block";
				break;
		}
	}
}

function clearValue(obj)
{
	if (obj)
		obj.value = "";
}

function popupW(url,w,h,id) 
{
	w=w+16;
	h=h+20;
	window.open(url,'popupWindow'+id,'width='+w+',height='+h+',toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,screenX=150,screenY=150,top=150,left=150');
}  

function searchLife(thisObj,hotel_page,otel_page,sanator_page,kvartir_page,global_page)
{
	var selectIndex = thisObj.options.selectedIndex;
	var selectValue = thisObj.options[selectIndex].value;
	
	var searchLifeForm = document.getElementById('searchLife');
	
	if (searchLifeForm && selectValue)
	{
		selectValue = selectValue.split("_");
		
		var url = "";
		switch (selectValue[0])
		{
			case '0':
				url = global_page;
				break;
				
			case '6':
				url = hotel_page;
				break;
				
			case '7':
				url = otel_page;
				break;
				
			case '77':
				url = kvartir_page;
				break;				

			case '8':
				url = sanator_page;
				break;
		}
		
		thisObj.options[selectIndex].value = selectValue[1];
		searchLifeForm.action = url;
	}
	
}

function ConcatURL(baseURL,concatURL)
{
	var res = String(baseURL), toConcat=String(concatURL);
	if(toConcat.length>0 && toConcat!="" && toConcat!="undefined") {
		var app_sign = (res.indexOf("?")!=-1) ? "&" : "?";
		if ((toConcat.charAt(0) == "?") || (toConcat.charAt(0) == '&'))
			toConcat = toConcat.substring(1,toConcat.length);

		res += app_sign + toConcat;
	};
	return res;
};

function fnSearchForm_ChangeRegion(regioncode,lang,url,formName)
{
	RequestData(ConcatURL(url+'index.php?p=ajaxWork&subP=Regions&callback=_fillObl&lang='+lang+'&formName='+formName,'regioncode='+regioncode));
	
	if (selected_obl)
	{
		RequestData(ConcatURL(url+'index.php?p=ajaxWork&subP=Regions&callback=_fillCity&lang='+lang+'&formName='+formName,'oblcode='+selected_obl+'&regioncode='+regioncode));
	}
	else
	{
		RequestData(ConcatURL(url+'index.php?p=ajaxWork&subP=Regions&callback=_fillCity&lang='+lang+'&formName='+formName,'regioncode='+regioncode));		
	}
}

function fnSearchForm_ChangeObl(oblid,lang,url,formName)
{	
	var c = document.forms[formName]['region[0]'];
	if (c && c.value && c.value!="")
	{
		RequestData(ConcatURL(url+'index.php?p=ajaxWork&subP=Regions&callback=_fillCity&lang='+lang+'&formName='+formName,'oblcode='+oblid+'&regioncode='+c.value));
	}
	else
	{
		RequestData(ConcatURL(url+'index.php?p=ajaxWork&subP=Regions&callback=_fillCity&lang='+lang+'&formName='+formName,'oblcode='+oblid));
	}
	
}

var formArray = new Array('filtr_tur2','filtr_tur3','filtr_tur4','add_msg');
var selected_region = '';
function _fillRegions(formName,arr,flag)
{
	if (!document.forms[formName])
		return;
		
	var c = document.forms[formName]['region[0]'];
	if (!c)
		return;
		
	//alert(c);
	c.disabled = true;

	var value = (selected_region!="") ? selected_region : "";
	//selected_region = "";
	var selected = -1;
	c.options.length = 0;
	//AddOption(c,"","-- Все страны --");
	var priority = 0, pos = 0;
	for (var i = 0; i < arr.length; i++)
	{
		if (i != 0 && priority != arr[i].priority)
		{
			AddOption(c,"","-----------------");
			pos++;
		}
		priority = arr[i].priority;
		AddOption(c,arr[i].regioncode,arr[i].name);
		if (value == arr[i].regioncode && value!="") selected = pos;
		pos++;
	}

	if (selected != -1) c.selectedIndex = selected;
	
	c.disabled = false;
	
	if (!flag)
		for (var i = 0; i < formArray.length; i++)
		{
			_fillRegions(formArray[i],arr,1);
		}	
}

var selected_obl = '';
function _fillObl(formName,arr,flag)
{
	if (!document.forms[formName])
		return;
		
	var c = document.forms[formName]['region[1]'];
	if (!c)
		return;
		
	var value = (selected_obl != "") ? selected_obl : "";

	c.disabled = true;

	//selected_obl = "";
	var selected = -1;
	c.options.length = 0;
	//AddOption(c,"","-- Все курорты --");
	var priority = 0, pos = 0;
	for (var i = 0; i < arr.length; i++)
	{
		//if (i != 0 && priority != arr[i].priority)
		//{
			//AddOption(c,"","-----------------");		
		//}
		priority = arr[i].priority;
		AddOption(c,arr[i].oblid,arr[i].name);
		if (value == arr[i].oblid && value!="") selected = pos;
		pos++;
	}

	//alert(value);alert(selected);
	if (selected != -1) c.selectedIndex = selected;
	
	c.disabled = false;
	
	if (!flag)
		for (var i = 0; i < formArray.length; i++)
		{
			_fillObl(formArray[i],arr,1);
		}	
}

var selected_city = '';
function _fillCity(formName,arr,flag)
{
	if (!document.forms[formName])
		return;
		
	var c = document.forms[formName]['region[2]'];
	
	if (!c)
		return;
		
	//alert(selected_city);	
	var value = (selected_city!="") ? selected_city : "";
	
	c.disabled = true;
	
	//selected_city = "";
	var selected = -1;
	c.options.length = 0;
	//AddOption(c,"","-- Все типы отдыха --");
	//alert(value);
	for (var i = 0; i < arr.length; i++)
	{
		AddOption(c,arr[i].cityid,arr[i].name);
		//alert(arr[i].cityid);
		if (value == arr[i].cityid && value!="") selected = i;
	}
	//alert(selected);
	if (selected != -1) c.selectedIndex = selected;
	
	c.disabled = false;
	
	if (!flag)
		for (var i = 0; i < formArray.length; i++)
		{
			_fillCity(formArray[i],arr,1);
		}	
}


function AddOption(sel,value,text)
{
	var opt = document.createElement('OPTION');
	opt.value = value;
	opt.text = text;
	sel.options.add(opt);
}

function selectAllCB(elemName)
{
	var c = null;
	
	switch (elemName)
	{
		case "es1":
			if (esJs1)
				for (var i = 0; i < esJs1.length; i++)
				{
					c = document.forms['filtr_tur2'][elemName+'['+esJs1[i]+']'];
					c.checked = (c.checked)?false:true;
					c = document.forms['filtr_tur4'][elemName+'['+esJs1[i]+']'];
					c.checked = (c.checked)?false:true;					
				}
			break;
			
		case "es2":
			if (esJs2)
				for (var i = 0; i < esJs2.length; i++)
				{
					c = document.forms['filtr_tur2'][elemName+'['+esJs2[i]+']'];
					c.checked = (c.checked)?false:true;
					c = document.forms['filtr_tur4'][elemName+'['+esJs2[i]+']'];
					c.checked = (c.checked)?false:true;					
				}
			break;
			
		case "es3":
			if (esJs3)
				for (var i = 0; i < esJs3.length; i++)
				{
					c = document.forms['filtr_tur2'][elemName+'['+esJs3[i]+']'];
					c.checked = (c.checked)?false:true;
					c = document.forms['filtr_tur4'][elemName+'['+esJs3[i]+']'];
					c.checked = (c.checked)?false:true;					
				}
		
			break;		
	}
}