function open_image(imgID,imgWidth,imgHeight,lang)
{
   if(!lang) lang = 'ru'
   winTop=(screen.height-imgHeight)/2;
   winLeft=(screen.width-imgWidth)/2;
   if(imgHeight > screen.height) imgHeight = screen.height;
   if(imgWidth > screen.width) imgWidth = screen.width;
   window.open("/open_image.php?lang="+lang+"&file="+imgID,"new_image","toolbar=0,menubar=0,location=0,status=0,statusbar=0,scrollbars=0,directories=0,resizable=0,copyhistory=0,top="+winTop+",left="+winLeft+",width="+imgWidth+",height="+imgHeight);
}

function ajax(div,url,pars,meth,func)
{
	var reg = new RegExp("^/");
	var reg2 = new RegExp("^http");
	url = url.replace(reg,"");
	if(!reg2.test(url)) url = '/' + url;
	if(!meth) meth = "get";

	if(meth == 'get')
	{
		if(!func) $.get(url,pars,function(data){ $('#'+div).attr('innerHTML',data) });
		else $.get(url,pars,function(data){ $('#'+div).attr('innerHTML',data);eval(func);});
	}
	else
	{
		if(!func) $.post(url,pars,function(data){ $('#'+div).attr('innerHTML',data) });
		else $.post(url,pars,function(data){ $('#'+div).attr('innerHTML',data);eval(func);});
	}
}

function insert_selection(str,obj)
{
	if(!obj) obj = document.forms['guest'].elements['text'];
	if (isIE)
	{
		if (obj.isTextEdit)
		{
			obj.focus();
			var sel = document.selection;
			var rng = sel.createRange();
			rng.colapse;
			if((sel.type == "Text" || sel.type == "None") && rng != null) rng.text = str;
		}
		else obj.value += str;
	}
	else if ( obj.selectionEnd )
	{ 
		var ss = obj.selectionStart;
		var st = obj.scrollTop;
		var es = obj.selectionEnd;
		
		if (es <= 2) es = obj.textLength;
		
		var start  = (obj.value).substring(0, ss);
		var middle = (obj.value).substring(ss, es);
		var end    = (obj.value).substring(es, obj.textLength);
		
		middle = str + middle;

		obj.value = start + middle + end;
		
		var cpos = ss + (middle.length);
		
		obj.selectionStart = cpos;
		obj.selectionEnd   = cpos;
		obj.scrollTop      = st;
	}
	else obj.value += str;
	obj.focus();
	void(0);
}	
