var _browser='',sys='win';
function browser() {

	if(_browser!='') return _browser;
	else if(document.layers) _browser='ns4';
	else if(navigator.appName.indexOf('Netscape'   )!=-1) _browser='ns6';
	else if(navigator.userAgent.indexOf('Gecko'    )!=-1) _browser='ns6';
	else if(navigator.userAgent.indexOf('Opera'    )!=-1) _browser='op';
	else if(navigator.appVersion.indexOf('MSIE 6.0')!=-1) _browser='ie6';
	else {_browser='ie';}

	if(navigator.platform.indexOf('Win')==-1&&navigator.platform.indexOf('win')==-1)sys='mac';

/*
var browser='ns4',sys='win',main='"index2.htm?browser=';
if(navigator.platform.indexOf('Win')==-1&&navigator.platform.indexOf('win')==-1)sys='mac';
if(navigator.appName.indexOf('Microsoft')!=-1)browser='ie';
*/
	return _browser;
}

function o_browser(){
    this.ver=navigator.appVersion
    this.agent=navigator.userAgent.toLowerCase()
    this.dom=document.getElementById?1:0
    this.op5=(this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1) && window.opera
  this.op6=(this.agent.indexOf("opera 6")>-1 || this.agent.indexOf("opera/6")>-1) && window.opera
  this.ie5 = (this.agent.indexOf("msie 5")>-1 && !this.op5 && !this.op6)
  this.ie55 = (this.ie5 && this.agent.indexOf("msie 5.5")>-1)
  this.ie6 = (this.agent.indexOf("msie 6")>-1 && !this.op5 && !this.op6)
    this.ie4=(this.agent.indexOf("msie")>-1 && document.all &&!this.op5 &&!this.op6 &&!this.ie5&&!this.ie6)
  this.ie = (this.ie4 || this.ie5 || this.ie6)
    this.mac=(this.agent.indexOf("mac")>-1)
    this.ns6=(this.agent.indexOf("gecko")>-1 || window.sidebar)
    this.ns4=(!this.dom && document.layers)?1:0;
    this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.op5 || this.op6)
  this.usedom= this.ns6//Use dom creation
  this.reuse = this.ie||this.usedom //Reuse layers
  this.px=this.dom&&!this.op5?"px":""
    return this
}

var bw=new o_browser();

function browser_isNS() {
	if(browser()=='ns' || browser()=='ns6' || browser()=='ns4') return true;
	return false;
}

function browser_isNS4() {
	if(browser()=='ns4') return true;
	return false;
}

function browser_isIE() {
	if(browser()=='ie' || browser()=='ie6') return true;
	return false;
}
function browser_isIE6() {
	if(browser()=='ie6') return true;
	return false;
}
function browser_div() {
	if(browser()=='ie' || browser()=='ie6') return "div";
	return "div";
}

function dfind(name) {
	if(typeof(name)=="string") {
		switch(browser())
		{
			case'ie6':
			case'ie': {return document.all[name];           break;}
			case'ns4':{return eval('document.'+name);       break;}
			case'ns6':{return document.getElementById(name);break;}
		}
	} else return name;
	return null;
}

function dstyle(name) {
    if(browser()!='ns4') return dfind(name).style;
	else return dfind(name);
}

function getX(name) // gibt den x-wert eines layers zurück
{
	if(browser()=='ie') return dstyle(name).pixelLeft;
	else if(browser()=='ie') return dstyle(name).pixelLeft;
	else return parseInt(dstyle(name).left)
}

function getY(name) // gibt den y-wert eines layers zurück
{
//	alert(name);
	if(browser()=='ie')return dstyle(name).pixelTop;
	else if(browser()=='ie6')return dstyle(name).pixelTop;
	else return parseInt(dstyle(name).top)
}

function setX(name,value) {
	(_browser=='ie'||_browser=='ie6')?dstyle(name).pixelLeft=value:dstyle(name).left=value;
} // setzt den x-wert eines layers

function setY(name,value) {
	(browser=='ie'||browser=='ie6')?dstyle(name).pixelTop=value:dstyle(name).top=value;
} // setzt den y-wert eines layers

function setV(name,mode){
	mode==1?dstyle(name).visibility='visible':dstyle(name).visibility='hidden';
} // macht abhängig vom browsertyp einen layer sichtbar/unsichtbar; mode 1=visible 0=hidden

function setClipping(name,top,right,bottom,left) {
	if(typeof(name)=="string") ref=dstyle(name);
	else ref=name;
	if((browser()=='ie')||(browser()=='ie6')) {
		ref.clip="rect("+top+" "+right+" "+bottom+" "+left+")";
	} else {
		setClip(ref,'t',top);
		setClip(ref,'r',right);
		setClip(ref,'b',bottom);
		setClip(ref,'l',left);
	}
}

function setClip(name,mode,value) // setzt den clip-wert für einen layer; mode=t(top),b(bottom),l(left),r(right)
{
	var ref;
	if(typeof(name)=="string") ref=dstyle(name);
	else ref=name;
	switch(mode)
	{
		case't':{_browser=='ns4'?ref.clip.top=value:ref.clip   ='rect('+value+'px auto auto auto)';break;}
		case'r':{_browser=='ns4'?ref.clip.right=value:ref.clip ='rect(auto '+value+'px auto auto)';break;}
		case'b':{_browser=='ns4'?ref.clip.bottom=value:ref.clip='rect(auto auto '+value+'px auto)';break;}
		case'l':{_browser=='ns4'?ref.clip.left=value:ref.clip  ='rect(auto auto auto '+value+'px)';break;}
	}
}

function unFocus(obj){
	if(obj.blur) obj.blur();
}


function reverse(name) {
	if(dstyle(name+"_ON").display=="") {
		dstyle(name+"_ON").display="none";
		dstyle(name+"_OFF").display="";
		dfind(name+"_Value").value=name+"_OFF";
	} else {
		dstyle(name+"_ON").display="";
		dstyle(name+"_OFF").display="none";
		dfind(name+"_Value").value=name+"_ON";
	}
}

function visible(name) {
	if(!dfind(name)) {
		alert("can't find '"+name+"'");
    } else {
 		if(dstyle(name).display=="") dstyle(name).display="none"
		else                         dstyle(name).display="";
	}
}

function show_info(obj,show_div) {
	var info="info "+typeof(obj);
	var crlf="\n";
	if(show_div) crlf="<br>\n";
	info+=crlf;
	for(var i in obj) {
		try {
			info+=""+i+"='"+obj[i]+"'"+crlf;
		} catch(e) {info+=""+i+"=error\n";};
	}
	if(show_div) show_div.innerHTML=info;
	else alert(info);
	return true;
}

function load_html(id,html) {
	if(document.readyState!="complete") setTimeout('load_html("'+id+'","'+html+'")',500);
	else dfind(id).innerHTML=html;
}
function load_image(id,src) {
	if(document.readyState!="complete") setTimeout('load_image("'+id+'","'+src+'")',500);
	else dfind(id).src=src;
}
function image_open(img_src,width,height,alt) {
	var html="";
	var win2;
//	alert("open for '"+img_src+"'");
	html+="<html>\n";
	html+="<head>\n";
	html+="<meta http-equiv=\"content-type\" content=\"text/html; charset=windows-1251\">\n";
	html+="<title>"+alt+"</title>\n";
	html+="</head>\n";
	html+="<body topmargin=\"0\" leftmargin=\"0\" marginheight=\"0\" marginwidth=\"0\" bgcolor=#BBBBBB>\n";

	if(img_src.indexOf("/")==-1) {
		obj=dfind(img_src);
		if(obj.nodeName=="SELECT") {
			if(obj.selectedIndex>=0) {
				img_src=obj.options[obj.selectedIndex].text;
			} else {
				alert("called for SELECT '"+img_src+"' obj.value="+obj.selectedIndex); // èìåííî id_sample
				return null;
			}
		}
	}

	if((img_src.indexOf(" ")!=-1) && (img_src.indexOf("/")>=0)) {
		var s,tab; // =String.fromCharCode(9);
		tab=" - "; //  '\t';
		// alert("try to decode\n' x '="+img_src.indexOf(" x ")+"\ntab="+img_src.indexOf(tab)+"\ntab='"+tab+"'\nimg_src='"+img_src+"'");
		if((img_src.indexOf(" x ")>0) && (img_src.indexOf(tab)>0)) {
			// alert("0");
			width=img_src.substr(0,img_src.indexOf(" ")); // alert("==='"+s+"'"); width=parseInt(s);
			// alert("1");
			img_src=img_src.substr(img_src.indexOf(" x ")+3);
			// alert("2");
			height=img_src.substr(0,img_src.indexOf(tab)); // height=s.parseInt();
			// alert("3");
			img_src=img_src.substr(img_src.indexOf(tab)+tab.length);
			// alert("url='"+img_src+"'\nwidth="+width+"\nheight="+height);
		} else {
	        img_src=img_src.substr(img_src.indexOf("/"));
        }
    } else if(img_src.indexOf(" ")!=-1) {
		alert("can't view image with space inside '"+img_src+"'");
		return null;
	}

    if(img_src=="") { alert("empty url"); return null; }
	return okno(img_src,width,height);

	if((width>0)&& (height>0))
		html+="<img src=\""+img_src+"\" width=\""+width+"\" height=\""+height+"\" alt=\""+alt+"\">\n";
	else
		html+="<img src=\""+img_src+"\" alt=\""+alt+"\">\n";

	// alert("image="+img_src);
	html+="</body>\n";
	html+="</html>\n";
//	win2=window.open('/php/view_members.php?id_item='+id_item,'',"scrollbars=yes,status=no,width=366,height=470");
	if((width>0)&& (height>0))
		win2=window.open("","","scrollbars=no,status=no,width="+width+",height="+height);
	else
		win2=window.open("","","scrollbars=no,status=no");
	if(win2) {
	    // window.status="window open";
		win2.document.open();
		win2.document.writeln(html);
		win2.document.close();
		// win2.open();
		// win2.writeln(html);
		// win2.close();
		// win2.innerHTML=html;
	} else show_info(win2);
	return win2;
}

function test_shablon(id_item,_params) {
	var url='/php/test_shablon.php?id_item=';
	url=url+id_item+'&'+_params;
	win2=window.open(url,'',"scrollbars=yes,status=yes,width=566,height=510");
}

function window_open(url,width,height) {
//    width =width ||800;
//    height=height||600;
//	width =Math.min(width ,800);
//	height=Math.min(height,600);
//	win2=window.open(url,'',"menubar=yes,scrollbars=yes,status=yes,width="+width+",height="+height+"");
	okno(url,width,height);
}

function okno(str,x,y)
{

  if(y < (screen.availHeight - 20) )str3="scrollbars=no,status=no,resizable=yes,width="+x+",height="+y+",left="+(screen.availWidth-x)/2+",top="+(screen.availHeight-y)/2;
  else str3="scrollbars= yes,width="+ (x + 20) +",height="+ (screen.availHeight - 50)  +",left="+(screen.availWidth-x)/2+",top= 10";

  newWindow = window.open("","newWindow",str3);
  newWindow.document.open();
  newWindow.document.write('<html><title> ÔÎÒÎ </title><body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0"  onBlur="self.close()" onClick="self.close()">');
  newWindow.document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" valign="middle" height="100%"><tr><td align=center>');
  newWindow.document.write('<img src="'+str+'" width="'+x+'" height="'+y+'" alt="ÇÀÊÐÛÒÜ" align=center valign=middle>');
  newWindow.document.write('</td></tr></table></body></html>');
  newWindow.document.close();
  newWindow.focus();

}

var _ActionSubmitted=false;
function PostAction(id_item,action,value) {
	if(_ActionSubmitted) {
	} else {
		id_item = id_item || 0;
		action  = action  || "";
		value   = value   || "";
		document.forms('action').item('id_item').value=id_item;
		document.forms('action').item('action').value=action;
		// alert("id_item="+id_item+"\naction="+action+"\nvalue="+value);
		document.forms('action').item('value').value=value;
		document.forms('action').submit();
		_ActionSubmitted=true;
	}
	return false;
}