// Глобальная переменная findarr - нужна для корректной работы поисковика
// В ней содержатся значения параметров поиска по различным полям, которые задал пользователь
/*var findarr = new Array();
findarr['tipp'] = '';
findarr['tip'] = '';

findarr['tipzd'] = '';
findarr['tipd'] = '';
findarr['etag'] = '';
findarr['metro'] = '';
findarr['ulitca'] = '';
findarr['gorod'] = '';
findarr['rajon'] = '';
findarr['tipzd_except'] = '';
findarr['tipd_except'] = '';
findarr['etag_except'] = '';*/

var windowmoreinfo;
var windowmultis;
var findarr= new Array();		
		function showfindp()
		{
			var ddiv=document.getElementById('divfindp');
			if (ddiv != null)
			{
				var sff=getAbsolutePos(document.getElementById('bfind'));
				ddiv.style.left=sff.x+'px';
				ddiv.style.top=sff.y+'px';
				ddiv.style.width = '190px';
				ddiv.style.height = '88px';
				ddiv.style.visibility='visible';
			}
			else
				doOnSearch();
		}
		function doOnSearch1()
		{
			var div=document.getElementById('divfindp');
			if (div != null)
			{
				div.style.visibility='hidden';
				doOnSearch();
			}
		}
		function doOnReset1()
		{
			var div=document.getElementById('divfindp');
			if (div != null)
			{
				div.style.visibility = 'hidden';
				div.style.width = '0px';
				div.style.height = '0px';
				doOnReset();
			}
		}
		function chCheckbox(cb)
		{
			cb.value = cb.checked ? 'yes' : '';
		}
		
		
		
		
function getClientWidth()
{
	return (document.compatMode=='CSS1Compat' && !window.opera)?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight()
{
	return (document.compatMode=='CSS1Compat' && !window.opera)?document.documentElement.clientHeight:document.body.clientHeight;
}

// function showfindtip(tipp)
// Показывает на экране диалоговое окно выбора назначения

function showfindtip(tip)
{
/*	var inv_='';
	glval_=inv_;*/
	var height_=185;
	var width=515;
	if (tip=='Магазин')
		height_=560;
	if (tip=='Склад')
		height_=340;
	if (tip=='Участок')
		height_=300;
	var urlContent = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='100%' height='100%' name='klient_findtip' id='klient_findtip'  codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' >"+
			"<param name='movie' value='http://www.747.ru/paranoya/flash/klient_findtip.swf'  />"+
			"<param name='quality' value='high' />"+
			"<param name='menu' value='true' />"+
			"<param name='allowScriptAccess' value='always' />"+			
			"<param name='flashvars' value='inis=."+tip+"' />"+
			"<embed name='klient_findtip'  allowScriptAccess='always' width='100%' height='100%' id='klient_findtip'"+ 
"src='http://www.747.ru/paranoya/flash/klient_findtip.swf' flashvars=\"inis="+tip+"\"  wmode=''"+
		"quality='high' menu='true' pluginspage='http://www.macromedia.com/go/getflashplayer'"+
 			"type='application/x-shockwave-flash' ></embed></object>";
	var title='Форма множественного выбора назначений';
	var left = Math.max(Math.ceil((getClientWidth()-width)/2), 0);
	var top = Math.max(Math.ceil((getClientHeight()-height_)/2), 0);
	windowmultis=dhtmlwindow.open(title, 'inline',urlContent, title, 'top='+top+'px,left='+left+'px,width='+width+'px,height='+height_+'px,resize=1,scrolling=1,center=0', 'recal');
	if (tip == 'ofis')
		tip = 'office';
	findarr['tip'] = tip;
	return false;
}

function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName];
    } else {
        return document[movieName];
    }
}

function initmetro()
{
	var a=document.getElementById('metro');
    if (a!=null)
    {
    	return a.value;
    }  
    else
    {
    	return('Not field metro');
    }
	
}

function closemetro(metro)
{
    var a=document.getElementById('metro');
    if (a!=null)
    {
    	a.value=metro;
    }  
    else
    {
    	alert('Not field metro');
    }
    dhtmlwindow.close(windowmultis);
	
}

function closemetrof()
{
    dhtmlwindow.close(windowmultis);
}


function initfindtip()
{
//	alert(thisMovie('klient_findtip').sendFromJS('value'));
	var a=document.getElementById('tipp');
    var out='rrrrr';
    out = findarr['tip']+'|'+findarr['tipp'];
    if (a!=null)
    {
    	return out;
    }  
    else
    {
    	return('Not field tipp');
    }
}

function closefindtip(tip)
{
    var a=document.getElementById('tipp');
    if (a!=null)
    {
    	if (tip == "")
   		{
        	a.value=findarr['tip'];
    		
   		}
    	else
    		a.value=tip;
        findarr['tipp']=tip;
   	
    }  
    else
    {
    	alert('Not field tipp');
    }
    dhtmlwindow.close(windowmultis);

}

function showMoreInfo(uid)
{
	var height_ = 570;
	var width = 740;
	var left = Math.max(Math.ceil((getClientWidth()-width)/2), 0);
	var top = Math.max(Math.ceil((getClientHeight()-height_)/2), 0);

	var urlContent = "http://" + location.hostname + "/index2.php?option=com_content&task=view&id=30&Itemid=74&no_html=1&uid=" + uid;
	var title = 'Подробнее';

	windowmultis=dhtmlwindow.open(title, 'iframe',urlContent, title, 'top='+top+'px,left='+left+'px,width='+width+'px,height='+height_+'px,resize=1,scrolling=1,center=0', 'recal');

	return false;
}

function ShowWin(url,x,y,name,isscrollbars)
{
	cx=screen.width/2-(x/2);
	cy=screen.height/2-(y/2);
	isscrollbars=(isscrollbars=="no")?"no":"yes";

	window.open(url, name, "toolbar=no,status=no,directories=no,menubar=no,resizable=yes,width=" + x + ",height=" + y + ",scrollbars=" + isscrollbars + ",top=" + cy + ",left=" + cx);
}

function ShowWin2(url,x,y,name,isscrollbars)
{
	cx=screen.width/2-(x/2);
	cy=screen.height/2-(y/2);
	isscrollbars=(isscrollbars=="no")?"no":"yes";

	window.open(url, name, "toolbar=no,status=no,directories=no,menubar=no,resizable=no,width=" + x + ",height=" + y + ",scrollbars=no,top=" + cy + ",left=" + cx);
}

function showAddressChoice()
{
//	ShowWin2("http://www.infomakler.ru/metromap/index.html", 1025, 620, "");
	var width = 1000;
	var height_ = 630;
	var left = Math.max(Math.ceil((getClientWidth()-width)/2), 0);
	var top = Math.max(Math.ceil((getClientHeight()-height_)/2), 0);

	var urlContent = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='100%' height='100%' name='klient_findadress' id='klient_findadress'  codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' >"+
	"<param name='movie' value='http://www.747.ru/paranoya/flash/klient_findadress.swf?z=232'  />"+
	"<param name='quality' value='high' />"+
	"<param name='menu' value='true' />"+
	"<param name='allowScriptAccess' value='always' />"+			
	"<embed name='klient_findadress'  allowScriptAccess='always' width='100%' height='100%' id='klient_findadress'"+ 
"src='http://www.747.ru/paranoya/flash/klient_findadress.swf?z=2323'   wmode=''"+
"quality='high' menu='true' pluginspage='http://www.macromedia.com/go/getflashplayer'"+
		"type='application/x-shockwave-flash' ></embed></object>";
	var title = 'Фильтр';

	windowmultis = dhtmlwindow.open(title, 'inline', urlContent, title, 'top='+top+'px,left='+left+'px,width='+width+'px,height='+height_+'px,resize=0,scrolling=0,center=0', 'recal');

	return false;
}


function showFilterChoice()
{
	var width = 500;
	var height_ = 260;
	var left = Math.max(Math.ceil((getClientWidth()-width)/2), 0);
	var top = Math.max(Math.ceil((getClientHeight()-height_)/2), 0);

	var urlContent = "http://" + location.hostname + "/index2.php?option=com_dbkernel&no_html=1&op=dialog&act=filter";
	var title = 'Фильтр';

	windowmultis = dhtmlwindow.open(title, 'iframe', urlContent, title, 'top='+top+'px,left='+left+'px,width='+width+'px,height='+height_+'px,resize=0,scrolling=1,center=0', 'recal');

	return false;
}


// function checkAllCb(element)
// Устанавливает группе чекбоксов такое же значение checked, как и у чекбокса element

function checkAllCb(element)
{
	var el;
	for (var i = 0; el = document.getElementById('cb'+i); i++)
		el.checked = element.checked;
} // function checkAllCb(element)


function setField(field, val)
{
	var fname = field.toUpperCase();
	var aname = fiels.toLowerCase();
	var inp = document.getElementById(fname);
	if (inp)
	{
		inp.value = val;
		findarr[aname] = val;
		return true;
	}
	else
		return false;
}


// function doOnSearch()
// Обработчик нажатия кнопки 'Найти'

function doOnSearch()
{
	var fields = 'TIP;OPP;CENAIN;CENAOUT;PL1IN;PL1OUT;TIPD;TIPZD;ETAG;TIPZD_EXCEPT;TIPD_EXCEPT;ETAG_EXCEPT;METRO;RAJON;GOROD;ULITCA;limitstart;limit;';
	var settedFields = 'TIPP;TIPZD;TIPD;ETAG;TIPZD_EXCEPT;TIPD_EXCEPT;ETAG_EXCEPT;METRO;RAJON;GOROD;ULITCA;';


	var addr = 'http://' + location.hostname;
	var thePath = '/';
	var sArr = settedFields.split(';');

	for (var i = 0; i < sArr.length; i++)
	{
		var thekey = sArr[i].toLowerCase();
		if (sArr[i] == '')
			continue;
		var inp_ = document.getElementById(sArr[i]);

		var v = findarr[thekey];
		if (inp_ != null)
			if (v)
				inp_.value = findarr[thekey];
	} // for (var i = 0; i < sArr.length; i++)


	var fArr = fields.split(';');
	for (var i = 0; i < fArr.length; i++)
	{
		if (fArr[i].toLowerCase() == 'opp')
		{
			var el = document.getElementById(fArr[i]);
			if (el)
			{
				var preg = 'rent/';
				var thePreg = new RegExp(preg);
				var path1 = thePath.replace(thePreg, '');
				preg = 'sale/';
				var thePreg1 = new RegExp(preg);
				path1 = path1.replace(thePreg1, '');
				preg = 'buy/';
				var thePreg2 = new RegExp(preg);
				path1 = path1.replace(thePreg2, '');
				preg = 'rentrequest/';
				var thePreg3 = new RegExp(preg);
				path1 = path1.replace(thePreg3, '');

				var val = el.value;
				if (val == 'Сдаю')
					val = 'rent';
				else if (val == 'Сниму')
					val = 'rentrequest';
				else if (val == 'Продаю')
					val = 'sale';
				else if (val == 'Куплю')
					val = 'buy';

				if (val)
					path1 += val + '/';
				thePath = path1;
			}
		} // if (fArr[i].toLowerCase() == 'opp')
		else if (fArr[i].toLowerCase() == 'tip')
		{
			var el = document.getElementById(fArr[i]);
			if (el)
			{
				if (findarr['tip'])
					el.value = findarr['tip'];
				var preg = 'office/';
				var thePreg = new RegExp(preg);
				var path1 = thePath.replace(thePreg, '');
				preg = 'magazin/';
				var thePreg1 = new RegExp(preg);
				path1 = path1.replace(thePreg1, '');
				preg = 'sklad/';
				var thePreg2 = new RegExp(preg);
				path1 = path1.replace(thePreg2, '');

				var val = el.value;
				if (val == 'Офис')
					val = 'office';
				else if (val == 'Склад')
					val = 'sklad';
				else if (val == 'Магазин')
					val = 'magazin';

				if (val)
					path1 += val + '/';
				thePath = path1;
			}
		} // if (fArr[i].toLowerCase() == 'tip')
		else if (fArr[i].toLowerCase() == 'tipp' && findarr['tipp'].indexOf(',') < 0)
		{
			var el = document.getElementById(fArr[i]);
			if (el)
			{
				var preg = ''+fArr[i].toLowerCase()+':([^/]*)/';
				var thePreg = new RegExp(preg);
				var path1 = thePath.replace(thePreg, '');
				var val = el.value;
				var Translit1 = new Translit;
				val = Translit1.BiDiDecode(val, 0);

				path1 += fArr[i].toLowerCase() + ':' + val + '/';
				thePath = path1;
			} // if (el)
		}
		else if (settedFields.indexOf(fArr[i] + ';') < 0)
		{
			var el = document.getElementById(fArr[i]);
			if (el)
			{
				var preg = '' + fArr[i].toLowerCase() + ':([^/]*)/';
				var thePreg = new RegExp(preg);
				var path1 = thePath.replace(thePreg, '');
				path1 += fArr[i].toLowerCase() + ':' + el.value + '/';
				thePath = path1;
			} // if (el)
		} // if-else
	} // for

	document.infoTableForm.action = addr + thePath;
	document.infoTableForm.submit();
	return false;
} // function doOnSearch()



// function doOnReset()
// Обработчик нажатия кнопки 'Очистить'

function doOnReset()
{
	for (var prop in findarr)
	{
		if (prop == 'tip' || prop == 'opp')
			continue;
		findarr[prop] = '';
		var inp = document.getElementById(prop.toUpperCase());
		if (inp)
			inp.value = '';
	}
	doOnSearch();
} // function doOnReset()


function doOnAddAd()
{
	alert('Разместить объявление');
} // function doOnAddAd()



function doOnNotepad()
{
	alert('Блокнот');
} // function doOnNotepad()


function doOnLeaveRequest()
{
	alert('Оставить заявку');
} // function doOnLeaveRequest()


function doOnAddress()
{
	showAddressChoice();
	return false;
} // function doOnAddress()


function doOnFilter()
{
	showFilterChoice();
	return false;
} // function doOnFilter()

function handleUMenu(item, what)
{

	if (!item)
		return true;

	if (what == 'in')
		item.className = 'umenu_item1';

	else if (what == 'out')
		item.className = 'umenu_item';

	return true;

} // function handleUMenu(item, what)


var imImages = new Array();
imImages['bt-umenu'] = new Image;
imImages['bt-umenu'].src = '/mambots/content/magicparcer/images/bg-umenu.png';
imImages['bt-umenu-pr'] = new Image;
imImages['bt-umenu-pr'].src = '/mambots/content/magicparcer/images/bg-umenu-active.png';
