function preload() {
  if (document.images) {
    var imgsrc = preload.arguments;
    arr=new Array(imgsrc.length);
    for (var j=0; j<imgsrc.length; j++) {
      arr[j] = new Image;
      arr[j].src = imgsrc[j];
    }
  }
}
function setMetroList(string, values)
{
	document.getElementById("metroList").innerText = string;
	document.getElementById("subway").value = values;

	if(values.length>0)
		document.getElementById("clearSubway").style.display = 'inline';
	else
		document.getElementById("clearSubway").style.display = 'none';	   
}

	function IsOpera()
	{
		return (navigator.userAgent.toLowerCase().indexOf('opera') != -1);
	}
	popup=function(url, width, height)
	{
		var w = screen.width, h = screen.height;
		if(IsOpera())
		{
			w = document.body.offsetWidth;
			h = document.body.offsetHeight;
		}
		c=window.open(url, 'popup', 'status=no,scrollbars=yes,resizable=yes,width='+(width+30)+',height='+(height+30)+',top='+Math.floor((h - height)/2-14)+',left='+Math.floor((w - width)/2-5));
		c.focus();
	}


/*popup=function(url, w, h) {
	window.open(url, 'popup', "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=no,width="+(w+30)+",height="+(h+30));
}
*/
popupimage=function(url, width, height, caption)
	{
		var w = screen.width, h = screen.height;
		if(IsOpera())
		{
			w = document.body.offsetWidth;
			h = document.body.offsetHeight;
		}
		window.open("popup.php?image="+url+"&caption="+caption, 'popup', 'status=no,scrollbars=yes,resizable=yes,width='+(width+10)+',height='+(height+10)+',top='+Math.floor((h - height)/2-14)+',left='+Math.floor((w - width)/2-5));
	}
/*popupimage=function(url, w, h, caption) {
	window.open("popup.php?image="+url+"&caption="+caption,"popup","toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width="+(w+10)+",height="+(h+30));
}*/

oldevent='';
window.ajaxSend=function (vardata) {
	var eqv=true;
	for (var i in vardata) {
		if (typeof(oldevent[i])=='undefined' || vardata[i]!=oldevent[i]) eqv=false;
	}
	if (eqv) return;
//alert(vardata.type+'\n'+oldevent.type);
	oldevent=vardata;
	document.status='Загружается';
//	alert(vardata.loader);
	if (typeof(vardata.loader)!='undefined') document.getElementById(vardata.loader).innerHTML='<div style="text-align:center; padding:20px;"><img src="/images/indicator.gif"></div>';
	var req = new JsHttpRequest();
	req.onreadystatechange = function() {
		window.processRequest(req);
	};
	req.caching =false;
	req.open("POST", ajaxpath, true);
	req.send(vardata);
//		document.getElementById('statusLineText').innerHTML='Загрузка данных... src="<div style="text-align:center; padding:20px;"><?=$_SETTINGS['system']['rootdir']?>/backend/images/loading.gif"></div>';
	return void(0);
};

window.processRequest=function(req) {
	document.status='Загружается';
	if (req.readyState == 4) {
//			document.getElementById('statusLineText').innerHTML='Загружено';
		document.status='Загружено';
		if (typeof(oldevent.loader)!='undefined') document.getElementById(oldevent.loader).innerHTML='';
		if (req.responseText) alert(req.responseText);
		if (req.responseJS) {
			if ( req.responseJS.script) {
				eval(req.responseJS.script);
			}
			if ( req.responseJS.beforescript) {
				eval(req.responseJS.beforescript);
			}
			for (var i in req.responseJS.html) {
				document.getElementById(i).innerHTML=req.responseJS.html[i];
			};
			if ( req.responseJS.afterscript) {
				eval(req.responseJS.afterscript);
			}
		}
//			document.getElementById('debug').innerHTML = req.responseText;

	};
};

var activeTab = 1;

//window.tout=0;
window.selectCell=function(cell, en, ev) {
    preload('/images/hz3.gif', '/images/hz3.gif');
  cell.className='top item act';
     if (cell.firstChild.className=='top item act') cell.firstChild.className='top item';
     for (var i=0;i<cell.parentNode.cells.length; i++) 
     {
          if (cell.parentNode.cells[i]!=cell && cell.parentNode.cells[i].className=='top item act') {
               if(i==cell.parentNode.cells.length-1) cell.parentNode.cells[i].className='top item last';
               else if(i==0) cell.parentNode.cells[i].className='top item first'; 
               else cell.parentNode.cells[i].className='top item';

          }
          
     }
/*     if(en && en!=activeTab) {
          var atab = document.getElementById('tab'+activeTab); atab.className = 'hide';
          activeTab = en;
          var tab = document.getElementById('tab'+en); tab.className = '';
     }
*/
     if (typeof(ev)!='undefined') {
		 window.newajax=ev;
		 clearTimeout(window.tout);
		 window.tout=setTimeout('ajaxSend(window.newajax)', 500);
	 }
}

window.unSelectCell=function(cell, en) {
//  cell.className='top item';
//          if (cell.parentNode.cells[en-1]!=cell && cell.parentNode.cells[en-1].className=='top item act') {
               if(en==cell.parentNode.cells.length) cell.parentNode.cells[en-1].className='top item last';
               else if(en==1) cell.parentNode.cells[0].className='top item first';
               else cell.parentNode.cells[en-1].className='top item';

//          }
/*		if(activeTab==cell.parentNode.cells.length) cell.parentNode.cells[(activeTab-1)].className='top item act last';
		else if(activeTab==1) cell.parentNode.cells[0].className='top item act first';
		else 
		*/
		cell.parentNode.cells[(activeTab-1)].className='top item act';
          
/*     if(en && en!=activeTab) {
          var atab = document.getElementById('tab'+activeTab); atab.className = 'hide';
          activeTab = en;
          var tab = document.getElementById('tab'+en); tab.className = '';
     }
*/
}