function bookmark( url, title ) {

     if( title == undefined ) title = document.title;
     if( url  == undefined )  url   = top.location.href;

     if( window.sidebar ) { // Firefox
          window.sidebar.addPanel( title, url, '' );
     } else if( window.opera && window.print ) { // Opera
          window.external.AddBookmark( url, title );
     } else if( window.external ) { // IE
          window.external.AddFavorite( url, title );
     }
     return false;
}

function mouseMove(obj){
obj.style.border = "1px solid #e96baa";
}

function mouseOut(obj){
obj.style.border = "1px solid #000000";
}

function get( name ) { return document.getElementById(name); }

function loadframe( name ) { return get(name).contentWindow.document.body.innerHTML; }

function request( page, send, item ) {
	var req = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
	req.onreadystatechange = function() {
		if( req.readyState==4 ) {
			if( item && item.value ) item.value=req.responseText;
			else if( item && item.innerHTML ) item.innerHTML=req.responseText;
			else alert(req.responseText);
		}
	}
	req.open( "GET", "/"+page+".php?"+send, true );
	req.send( null );
}

function loadflash( frame, flash, data, id, w, h ) {
	var frame	= get( frame );
	var flash	= get( flash );
	var html	= frame.contentWindow.document.body.innerHTML;
	pos1 = html.indexOf( "/*" );
	pos2 = html.indexOf( "*/" );
	html = html.substr( pos1+2, pos2-pos1-2 );
	html = html.replace( /\{\#l1\}/, data );
	html = html.replace( /\{\#l2\}/, data );
	html = html.replace( /\{\#w1\}/, w );
	html = html.replace( /\{\#w2\}/, w );
	html = html.replace( /\{\#h1\}/, h );
	html = html.replace( /\{\#h2\}/, h );
	html = html.replace( /\{\#n1\}/, id );
	html = html.replace( /\{\#n2\}/, id );
	flash.innerHTML = html;
}

function getsize() {
	var x, y;
	if( self.innerHeight ) {
		x = self.innerWidth;
		y = self.innerHeight;
	} else if( document.documentElement && document.documentElement.clientHeight ) {
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	} else if( document.body ) {
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	} return { "width":x, "height":y };
}

function getscroll() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == "number" ) {
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	} return { "top":scrOfY, "left":scrOfX };
}

function resize( name, w, h, t, l, step ) {
	var obj=document.getElementById( name );
	var obj_w=obj.offsetWidth, obj_h=obj.offsetHeight;
	var obj_l=obj.offsetLeft, obj_t=obj.offsetTop;
	obj.style.width = (w-obj_w) / step + obj_w + "px";
	obj.style.height = (h-obj_h) / step + obj_h + "px";
	if( t>0 && l>0 ) {
		obj.style.top = (t-obj_t) / step + obj_t + "px";
		obj.style.left = (l-obj_l) / step + obj_l + "px";
	} if( step>1 ) setTimeout( "resize('" +name+ "'," +w+ "," +h+ "," +t+ "," +l+ "," +(step-1)+ ");", 30 );
}

function win_stat( name ) {
	var obj = get(name);
	if( obj.offsetHeight==0 ) {
		resize( name, obj.offsetWidth, obj.scrollHeight, 0, 0, 20 );
	} else if( obj.offsetHeight==obj.scrollHeight ) {
		resize( name, obj.offsetWidth, 0, 0, 0, 20 );
	}
}

function getAbsolutePos( item ) {
	var data = { "x":item.offsetLeft, "y":item.offsetTop };
	if( item.offsetParent ) {
		var temp = getAbsolutePos( item.offsetParent );
		data.x += temp.x; data.y += temp.y;
	}
	return data;
}

function win_open( item, html, w, h ) {
	var root=get("root"), bak=get("win_back"), obj=get("win_data");
	var s=getsize(), c=getscroll();
	var t=c.top+(s.height-h)/2, l=c.left+(s.width-w)/2;
	var i=getAbsolutePos(item);
	bak.style.display = obj.style.display ="";
	obj.style.width = item.offsetWidth+"px";
	obj.style.height = item.offsetHeight+"px";
	obj.style.top = i.y +"px";
	obj.style.left = i.x +"px";
	bak.style.width = root.offsetWidth+"px";
	bak.style.height = root.offsetHeight+"px";
	obj.innerHTML = html;
	resize( "win_data", w, h, t>1?t:1, l>1?l:1, 20 );
}

function win_drop() {
	get( "win_back" ).style.display = "none";
	get( "win_data" ).style.display = "none";
}

function image( item, src, w, h ) {
	var html = '<div id="image_temp"></div>';
	var temp = '<img src="/'+src+'" onclick="win_drop()" title="Закрыть изображение" />';
	win_open( item.parentNode, html, w, h );
	setTimeout("alpha('image_temp',1,10,10);get('image_temp').innerHTML='"+temp+"'",20*30+100);
}

function alpha( name, mode, step, full ) {
	var item = get(name);
	item.style.filter="alpha(opacity="+((mode?100:0)-step/(full/100))+");";
	item.style.opacity=(mode?1:0)-step/(full/1);
	if(step>0) setTimeout( "alpha('"+name+"',"+mode+","+(step-1)+","+full+")", 30 );
}
