var TimeoutRetVal=null;
var event_x, event_y;

function RTrim(s) {return s.replace(/ +$/,'');}
function LTrim(s) {return s.replace(/^ +/,'');}
function Trim(s) {return RTrim(LTrim(s));}

var trans = [];
for (var i = 0x410; i <= 0x44F; i++)
	trans[i] = i - 0x350; // А-Яа-я

trans[0x401] = 0xA8;    // Ё
trans[0x451] = 0xB8;    // ё


function RegExpPreparePattern(sStr){
var res;

res = sStr.replace(/(\\)|(\^)|(\$)|(\*)|(\+)|(\?)|(\{)|(\})|(\))/gim, '\\$1$2$3$4$5$6$7$8$9');
res = res.replace(/(\()|(\[)|(\])|(\,)|(\.)|(\!)|(\|)|(\-)|(\:)/gim, '\\$1$2$3$4$5$6$7$8$9');
res = res.replace(/(\@)|(\#)|(\%)|(\&)|(\_)|(\=)|(\/)|(\")|(\;)/gim, '\\$1$2$3$4$5$6$7$8$9');
res = res.replace(/(\<)|(\>)|(\')|(\`)|(\~)/gim, '\\$1$2$3$4$5');

return res;
}

//кодироует строку заменяю < > & " на соответствующие эквиваленты
function HTMLEncode(istr)
{
	istr = istr.replace(/</gi, '&lt;');
	istr = istr.replace(/>/gi, '&gt;');
	istr = istr.replace(/\&/gi, '&amp;');
	istr = istr.replace(/\"/gi, '&quot;');
	return istr;
}


//кодироует строку заменяю 8-ми битные символы на %##
function UrlEncode(istr)
{
	if (istr!=null && istr.length>0)
	{
		var i, tmpstr, chcod;
		tmpstr='';
		for(i=0; i<istr.length; i++)
		{
			chcod = istr.charCodeAt(i);
			
			if (typeof trans[chcod] != 'undefined')
				chcod = trans[chcod];
				
			if (chcod <= 0xFF)
				tmpstr+=String.fromCharCode(chcod);
		}
		return escape(tmpstr);
	}
return '';
}
// заменя getElementById для 4 эксплорера
function findElementById(elmid){
var i, obj=null;
	for (i=0; i<document.all.length; i++){
		if (document.all[i].id.toLowerCase()==elmid.toLowerCase()){
			obj = document.all[i]; break
		}
	}
return obj;
}

//
function GetBrowser() 
{
var userAgent = navigator.userAgent;
var res1 = userAgent.match(/MSIE\s*(\d+\.\d+)/gi);
var res2 = userAgent.match(/opera/gi);

var iever, BrowserName;
var mayBehavior=false;

if (res1!=null){
 	if (res2==null){
			if (document.charset){
				BrowserName = 'ie';
				iever = res1.toString().match(/(\d+\.\d+)/gi);
				if (iever!=null){
					iever = parseFloat(iever);
					if (iever>=5)
						mayBehavior=true;
				}	
			}else
				BrowserName = 'notie';
	}else
		BrowserName = 'notie';
}else
	BrowserName = 'notie';

var my_array = new Array(BrowserName, iever, mayBehavior);
return my_array;
}
/*==*/
function SubmitForm(iFormName) {
var obj=eval('document.' + iFormName);
obj.submit();
}
/*==*/
function OneSelect(checkbox)
{
	if (typeof(checkbox)=='object' && typeof(checkbox.form)=='object' && checkbox.type == 'checkbox' && checkbox.checked){
		var checkedName = checkbox.name;
		var checkedVal = checkbox.value;
		var element, i;
		for (i=0; i<checkbox.form.elements.length; i++)		{
			element = checkbox.form.elements[i];
			if (typeof(element)=='object' && 
				element.type == 'checkbox' && 
				element.name==checkedName && 
				element.value!=checkedVal && 
				element.checked)
				element.checked = false;
}}}
//
function ShowPhoto(url, evtObj){
if (document.images['photosTag'])
	{
		if (window.event){
			event_x = window.event.x+window.document.body.scrollLeft; 
			event_y = window.event.y+window.document.body.scrollTop;
		}
		else{event_x = evtObj.firstChild.x; event_y = evtObj.firstChild.y;}

		var obj= document.getElementById('photosTag');
		
		if (obj)
		{
			window.clearTimeout(TimeoutRetVal);
			
			if (obj.src!=url)
			{
				document.getElementById('photos').style.display = 'none';
				obj.src=url;
				if (navigator.userAgent.match(/opera/gi)) 
					ShowPhotoWindow();
			}
			else
				ShowPhotoWindow();
			return false;
		}
	}
OnW(url, 'photowin', 'no' , 'no', 300, 300);
return false;}
//
function ShowPhotoWindow(){
var obj;
	obj = document.getElementById('photos');
	
	if (obj.style.display.match(/none/gi)){
		var imgObj = document.getElementById('photosTag');
		var x = event_x + 50;
		var y = event_y + 30;

		var winH = window.document.body.scrollTop+document.body.clientHeight
		var winW = window.document.body.scrollLeft+document.body.clientWidth
		
		if (document.charset) obj.style.display = 'block';
		
		x = ((imgObj.width+x+24)>document.body.clientWidth)?document.body.clientWidth-imgObj.width-24:x
		y = ((imgObj.height+y+24)>winH)?winH-imgObj.height-24:y

		x = (x<window.document.body.scrollLeft)?window.document.body.scrollLeft:x
		y = (y<window.document.body.scrollTop)?window.document.body.scrollTop:y

		obj.style.left = x;
		obj.style.top  = y;
		
		if (obj.style.display.match(/none/gi)) obj.style.display = 'block';
	}
	//TimeoutRetVal = window.setTimeout('document.getElementById(\'photos\').style.display = \'none\';', 15000);
return false;}
//
function OnW(url, name, scr, fullscr, w, h){ 
var PL, PT, ww, wh;

if (w > window.screen.width) w=window.screen.width;
if (h > window.screen.height) h=window.screen.height;
PL = (window.screen.width-w)/2;
PT = (window.screen.height-h)/2;

if (fullscr.toLowerCase()=='yes') 
	name = window.open(url, name, 'top=0,left=0,toolbar=no,location=no,status=no,menubar=no,resizable=yes,directories=no,scrollbars='+scr+',width='+window.screen.availWidth+',height='+window.screen.availHeight+'');
else 
	name = window.open(url, name, 'top='+PT+',left='+PL+',toolbar=no,location=no,status=no,menubar=no,resizable=yes,directories=no,scrollbars='+scr+',width='+w+',height='+h+'');
if (!name.closed) name.focus();
return false;
}
//
function OnWNoRS(url, name, scr, fullscr, w, h){ 
var PL, PT, ww, wh;
if (w > window.screen.width) w=window.screen.width;
if (h > window.screen.height) h=window.screen.height;
PL = (window.screen.width-w)/2;
PT = (window.screen.height-h)/2;

if (fullscr.toLowerCase()=='yes') 
	name = window.open(url, name, 'top=0,left=0,toolbar=no,location=no,status=no,menubar=no,resizable=no,directories=no,scrollbars='+scr+',fullscreen=yes');
else 
	name = window.open(url, name, 'top='+PT+',left='+PL+',toolbar=no,location=no,status=no,menubar=no,resizable=no,directories=no,scrollbars='+scr+',width='+w+',height='+h+'');
if (!name.closed) name.focus();
return name;
}
//
function OnPM(th) {
//style="background: url(http://colibri.ru/pic/p.gif) no-repeat center; width: 10px;" title="Раскрыть"
var obj;
	if (th)
	{
		if (th.style.backgroundImage.indexOf('url')!=-1)
		{
		
			if (th.style.backgroundImage.indexOf('p.gif')==-1)
			{
				th.style.backgroundImage = 'url(/pic/p.gif)'
				th.title='Раскрыть';
			}
			else
			{
				th.style.backgroundImage = 'url(/pic/m.gif)'
				th.title='Cкрыть';
			}
			
		}
		else
		{
			var pic=th.src;
			if (pic.indexOf('p.gif')==-1)
			{
				th.src='pic/p.gif';
				th.alt='Раскрыть';
			}
			else
			{ 
				th.src='pic/m.gif';
				th.alt='Cкрыть'; 
			}
		}
	
		obj=(document.getElementById)?document.getElementById('d_'+th.id):findElementById('d_'+th.id);
		
		if (obj.style.display=='none')
			obj.style.display='block';
		else
			obj.style.display='none';
	}
}
//
function GoAll(iCod) {
var N, tmp, tmpObj;
stok.style.display='none';
for (N=0; N < document.all.length; N++) {
	tmpObj=document.all[N];
	tmp=tmpObj.id;
	if (tmp != '') {
		if (tmp.indexOf('Srp_')==0)
			if (iCod > 0) document.all[N].src='pic/m.gif'; else document.all[N].src='pic/p.gif';
		else
			if (tmp.indexOf('d_Srp_')!=-1)
				if (iCod > 0) document.all[N].style.display='block'; else document.all[N].style.display='none';
		}
	}
stok.style.display='block';
}
//
function ChangePict(obj, BPict, SPict){
var ID, SZ, tmpstr, pictID, PictObj, i, Flag=false;
if (obj.id==null) {
	if (obj!=null)	{
		tmpstr = obj+'';
		if (tmpstr.indexOf('photos/')>0) return OnW(tmpstr, 'Bigphotos', 'no', '', 250, 375);
		else return true; } 
	else return true;}

tmpstr = obj.id;
if (tmpstr.indexOf('_')>0){	ID = tmpstr.substring(tmpstr.indexOf('_')+1, tmpstr.length); SZ = tmpstr.substring(0, tmpstr.indexOf('_')).toLowerCase();} 
else return true;
if ((BPict!='') && (SPict=='')) {SPict=BPict;}
if ((BPict=='') && (SPict!='')) {SPict=''; BPict='';}
tmpstr = ''; pictID = 'pict'+ID; 
for (i=0; i<obj.childNodes.length; i++){
	tmpstr = obj.childNodes.item(i).id
	if (tmpstr!=null){
		if (tmpstr.toLowerCase()==pictID.toLowerCase()) {PictObj = obj.childNodes.item(i); break;}
}	}
if (BPict=='')  BPict = PictObj.src;	if (SPict=='')  SPict = PictObj.src;
if (SZ=='s'){
	tmpstr = '<img src="' + BPict + '" alt="уменьшить" id="' + pictID +'" border="0"><br><img src="pic/p_zm.gif" border="0" width="25" height="20" vspace="10" align="center"><span class="textboldunderline">уменьшить</span>';
	obj.id='b_' + ID;	}
else{
	tmpstr = '<img src="' + SPict + '" alt="увеличить" id="' + pictID +'" width="70" border="1"><br><img src="pic/p_zm.gif" border="0" width="25" height="20" vspace="10" align="center"><span class="textboldunderline">увеличить</span>';
	obj.id='s_' + ID;	}
obj.innerHTML =tmpstr;
return false;}
//
function  ChSize(p1,p2,p3) {
var tmpStr, h, w, sz, sId, ln;
sId=window.event.srcElement.id;
ln=sId.length;
if (sId.substr(ln-2)=='!b')
	sz=0;
else 
	sz=1;
sId=sId.substr(0,ln-2);
ln=sId.length;
switch (p1) {
	case 2:
		w=50; 	h=70;
		if (sz==0)
			tmpStr='<img src=' + p2 + ' id=' + sId + '!s border=1 width=' + w +' height='+ h +' alt=Увеличить>' ;
		else
			tmpStr='<img src=' + p2 + ' id=' + sId + '!b border=0 alt=Уменьшить>' ;
		break;
	case 3:
		w=70; h=100;
		if (sId.substr(ln-2)=='_t' || sId.substr(ln-2)=='_g')
			sId=sId.substr(0,ln-2);
		if (sz==0)
			tmpStr='<img src=' + p2 + ' id=' + sId + '!s border=1 width=' + w + ' height=' + h + ' alt=Увеличить><br><img id=' + sId + '_g!s src=pic/p_zm.gif border=0 width=25 height=20 vspace=10 align=middle><span id=' + sId + '_t!s class=textboldunderline>увеличить</span>' ;
		else
			tmpStr='<img src=' + p2 + ' id=' + sId + '!b border=0 alt=Уменьшить><br><img id=' + sId + '_g!b src=pic/p_zm.gif border=0 width=25 height=20 vspace=10 align=middle><span id=' + sId + '_t!b class=textboldunderline>уменьшить</span>' ;
		break;
	case 4:
		w=70;
		if (sId.substr(ln-2)=='_t' || sId.substr(ln-2)=='_g')
			sId=sId.substr(0,ln-2);
		if (sz==0)
			tmpStr='<img src=' + p2 + ' id=' + sId + '!s border=1 width=' + w + ' alt=Увеличить><br><img id=' + sId + '_g!s src=pic/p_zm.gif border=0 width=25 height=20 vspace=10 align=middle><span id=' + sId + '_t!s class=textboldunderline>увеличить</span>' ;
		else
			tmpStr='<img src=' + p2 + ' id=' + sId + '!b border=0 alt=Уменьшить><br><img id=' + sId + '_g!b src=pic/p_zm.gif border=0 width=25 height=20 vspace=10 align=middle><span id=' + sId + '_t!b class=textboldunderline>уменьшить</span>' ;
		break;
}
if (tmpStr!='' && p3!='')
	document.all(p3).innerHTML=tmpStr;
}