var flashinstalled = 0;
var flashversion = 0;
MSDetect = "false";
if (navigator.plugins && navigator.plugins.length)
{
    x = navigator.plugins["Shockwave Flash"];
    if (x)
    {
        flashinstalled = 2;
        if (x.description)
        {
            y = x.description;
            flashversion = parseInt(y.slice(16));
        }
    }
    else
        flashinstalled = 1;
    if (navigator.plugins["Shockwave Flash 2.0"])
    {
        flashinstalled = 2;
        flashversion = 2;
    }
}
else if (navigator.mimeTypes && navigator.mimeTypes.length)
{
    x = navigator.mimeTypes['application/x-shockwave-flash'];
    if (x && x.enabledPlugin)
        flashinstalled = 2;
    else
        flashinstalled = 1;
}
else
    MSDetect = "true";

if (MSDetect == "true") {
  	document.write('<SCRIPT LANGUAGE=VBScript\> \n');
  	document.write('on error resume next \n');
	document.write('For i = 4 to 9 \n');
	document.write('If Not(IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & i))) Then \n');
	document.write('Else \n');
	document.write('flashinstalled = 2 \n');
	document.write('flashversion = i \n');
	document.write('End If \n');
	document.write('Next \n');
	document.write('If flashinstalled = 0 Then \n');
	document.write('flashinstalled = 1 \n');
	document.write('End If \n');
	document.write('<\/SCRIPT\> \n');  
}

function insFl(v,fl,gif,lnk,w,h,bg) {
	var d=' width='+w+' height='+h;
	if (flashinstalled > 0 && flashversion >= v) {
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+d+'><param name=wmode value=transparent><param name=movie value='+fl+'><param name="bgcolor" value="bg" /><embed src='+fl+' quality=high'+d+' bgcolor="'+bg+'" wmode=transparent></embed></object>')
	} else {
		if (gif != '') {
			document.write('<a href='+lnk+'><img src='+gif+d+' border=0></a>')
		}
	}
}

/*
function ShowPhoto(url, width, height) {
	var scroll = (screen.width < 1000) ? "yes" : "no";
	
	var left = (self.screen.width >> 1) - (width >> 1);
	var top = (self.screen.height >> 1) - (height >> 1);
	var param = 'left='+left+',top='+top+',width='+width+',height='+height+',';
	
	window.open(url, '_blank', param+'menubar=no, scrollbars=' + scroll + ', status=no');
}
*/

function ShowPhoto(url, width, height) {
	var scroll = (screen.width < 1000) ? "yes" : "no";
	
	var left = 0;
	var top = 0;
	var param = 'left='+left+',top='+top+',width='+screen.width+',height='+screen.height+',';
	
	window.open(url, '_blank', param+'menubar=no, scrollbars=' + scroll + ', status=no');
}

function emoticon(theSmilie)
{
	doInsert(" " + theSmilie + " ", "", false);
}

function doInsert(ibTag, ibClsTag, isSingle)
{
	var isClose = false;
	var obj_ta = document.post.message;
	
	//----------------------------------------
	// It's IE!
	//----------------------------------------
	if ( (ua_vers >= 4) && is_ie && is_win)
	{
		if (obj_ta.isTextEdit)
		{
			obj_ta.focus();
			var sel = document.selection;
			var rng = sel.createRange();
			rng.colapse;
			if((sel.type == "Text" || sel.type == "None") && rng != null)
			{
				if(ibClsTag != "" && rng.text.length > 0)
					ibTag += rng.text + ibClsTag;
				else if(isSingle)
					isClose = true;
	
				rng.text = ibTag;
			}
		}
		else
		{
			if(isSingle)
			{
				isClose = true;
			}
			
			obj_ta.value += ibTag;
		}
	}
	//----------------------------------------
	// It's MOZZY!
	//----------------------------------------
	
	else if ( obj_ta.selectionEnd )
	{ 
		var ss = obj_ta.selectionStart;
		var st = obj_ta.scrollTop;
		var es = obj_ta.selectionEnd;
		
		if (es <= 2)
		{
			es = obj_ta.textLength;
		}
		
		var start  = (obj_ta.value).substring(0, ss);
		var middle = (obj_ta.value).substring(ss, es);
		var end    = (obj_ta.value).substring(es, obj_ta.textLength);
		
		//-----------------------------------
		// text range?
		//-----------------------------------
		
		if (obj_ta.selectionEnd - obj_ta.selectionStart > 0)
		{
			middle = ibTag + middle + ibClsTag;
		}
		else
		{
			middle = ibTag + middle;
			
			if (isSingle)
			{
				isClose = true;
			}
		}
		
		obj_ta.value = start + middle + end;
		
		var cpos = ss + (middle.length);
		
		obj_ta.selectionStart = cpos;
		obj_ta.selectionEnd   = cpos;
		obj_ta.scrollTop      = st;


	}
	//----------------------------------------
	// It's CRAPPY!
	//----------------------------------------
	else
	{
		if (isSingle)
		{
			isClose = true;
		}
		
		obj_ta.value += ibTag;
	}
	
	obj_ta.focus();

	return isClose;
}	

function getBodyScrollTop() {
  return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}

function ShowPhotoHere(url, alt, width, height) {
var fragment = document.createDocumentFragment(),
		scrolling = getBodyScrollTop(body),
		body = document.getElementsByTagName("body")[0],
	    over = document.createElement('div'),
		h,
		conteiner = document.createElement('div'),
		inside = document.createElement('div'),
		style,
		image = document.createElement('img'),
		descr = document.createElement('p');
		 
		
 	over.id = "over";  	         
 	conteiner.id = "conteinerimg";             
	inside.id = "inside"; 
	inside.style.width = width+"px";
	inside.style.height = height+"px";
	inside.style.margin = scrolling+"px auto 0 auto";    
	
	h = document.getElementById("conteiner").offsetHeight;
	h = (scrolling + height>h)?(scrolling + height+ 20):h;
	h = (h > getlnsideWindowHeight()) ? h : getlnsideWindowHeight();
	over.style.height = h+"px";       
	
	image.width=width;
	image.height=height;
	image.title="Закрыть";
	image.src = "/"+url;
	                                         
	descr.appendChild(document.createElement('span')).innerHTML = alt;
	
	inside.appendChild(image);
	inside.appendChild(descr);
    conteiner.appendChild(inside);
	fragment.appendChild(over);
	fragment.appendChild(conteiner); 
	//////////////////////////////////////////
	image.onclick = function() {
		over.parentNode.removeChild(over);
		conteiner.parentNode.removeChild(conteiner);
	}
	body.appendChild(fragment);
}

function getlnsideWindowHeight() {
	if (window.innerHeight) {
		return window.innerHeight;
	} else {
		return document.body.parentElement.clientHeight;
	}
	return 0;
}

function getBrowserInfo() {
	var t,v = undefined;
	if (window.opera) t = 'Opera';
	else if (document.all) {
		t = 'IE';
		var nv = navigator.appVersion;
		var s = nv.indexOf('MSIE')+5;
		v = nv.substring(s,s+1);
	}
	else if (navigator.appName) t = 'Netscape';
	return {type:t,version:v};
}
 
function bookmark(a){
	var url = window.document.location;
	var title = window.document.title;
	var b = getBrowserInfo();
	if (b.type == 'IE' && 8 > b.version && b.version >= 4) window.external.AddFavorite(url,title);
	else if (b.type == 'Opera') {
		a.href = url;
		a.rel = "sidebar";
		a.title = url+','+title;
		return true;
	}
	else if (b.type == "Netscape") window.sidebar.addPanel(title,url,"");
	else alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
	return false;
}

function getClients(){
	var tooltip = document.getElementById("tooltip");
	var toolA = document.getElementById("toolA");
	if(!tooltip)
		return;
	var all = document.getElementById("cl").getElementsByTagName("img");
	document.getElementById("head").onmouseover = function(){tooltip.style.display = "none"}
	document.getElementById("foot").onmouseover = function(){tooltip.style.display = "none"}
	var tooltip = document.getElementById("tooltip");
	var txt = document.getElementById("txt");  
	for(var i=0; i<all.length;i++){
		initImg(all[i])
	}
	function initImg(img){
		img.onmouseover = function(){showTooltip(img,img.alt)};
		//img.onmouseout = hideTooltip;
	}
	function showTooltip(img,text){    
		 var num = 38;
		 var h = 103;
		 var delta = 0;
		 var cell = img.parentNode;
		 var href = "";
		 if(cell.tagName!="td"){	
			 if(cell.tagName=="A"){	
				href = cell.href;				
			}
		 	cell = cell.parentNode;
		}
		
			 
		 delta = Math.floor(text.length/38);
		 txt.innerHTML = text;
		 tooltip.style.display = "block";
		 tooltip.style.height = h + delta*11 + "px";
		 tooltip.style.top = cell.offsetTop - delta*11 +"px";
		 tooltip.style.left = cell.offsetLeft+"px";	
		 toolA.href = href;		 
	}
	function hideTooltip(){   
		setTimeout(function(){tooltip.style.display = "none"},20)
	}  
} 

function getlnsideWindowHeight() {
	if (window.innerHeight) {
		return window.innerHeight;
	} else {
		return document.body.parentElement.clientHeight;
	}
	return 0;
}

function setCenterLine(){
  var line = document.getElementById("line");
  line.style.marginTop = (getlnsideWindowHeight() - 53)/2 + "px";
}
