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( link, save, id, w, h ) {	get(save).innerHTML = '<iframe src="/root/flash.html" id="frame_'+id+'" style="display:none" '+
		'onload=\'loadflash_frame("frame_'+id+'","'+save+'","'+link+'","'+id+'","'+w+'","'+h+'")\'></iframe>';
}

function loadflash_frame( 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 content(item,mode) {	if( item.title=="" ) {		item.title = item.value;
	} if( item.value=="" && !mode ) {
		item.className = "input_none";
		item.value = item.title;
	} else if( item.value==item.title && mode ) {		item.className = "input_norm";
		item.value = "";
	}
}

function checkbox(item,mode) {
	for( var x=0; x<item.childNodes.length; x++ ) {
		var temp = item.childNodes[x];
		if( temp && temp.tagName=="INPUT" ) temp.checked=mode;
		else if( temp.childNodes.length ) checkbox(temp,mode);
	}
}

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 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 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_open( item, html, w, h ) {	ie6_select(document,false);
	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() {	ie6_select(document,true);
	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 = '<div style="background-image:url(/'+src+');" onclick="win_drop()" title="Закрыть изображение"><div class="ic_drop" style="width:'+w+'px;height:'+h+'px;"></div></div>';
	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 );
}

function ie6_select(root,mode) {	for( var x=0; x<root.childNodes.length; x++ ) {
		var temp = root.childNodes[x];
		if( temp && temp.tagName=="SELECT" ) temp.style.display=mode?"":"none";
		else if( temp.childNodes.length ) ie6_select(temp,mode);
	}}

function bookmark( link, name ) {
	if( name==undefined ) name = document.title;
	if( link==undefined ) link = top.location.href;
	if( window.sidebar ) window.sidebar.addPanel(name,link,'');
	else if( window.opera && window.print ) window.external.AddBookmark(link,name);
	else if( window.external ) window.external.AddFavorite(link,name);
}

function homepage( link ) {
	if( link==undefined ) link = top.location.href;
	if( navigator.appName.indexOf('Microsoft')!=-1 ) {
		document.body.style.behavior = 'url(#default#homepage)';
		document.body.setHomePage(link);
	}
}