/*global window, document, navigator*/
var flashinstalled = 0,
	flashversion = 0,
	MSDetect = "false";


function M(){
		var D = "undefined",
			S = "Shockwave Flash",
			W = "ShockwaveFlash.ShockwaveFlash",
			q = "application/x-shockwave-flash",
			R = "SWFObjectExprInst",
			x = "onreadystatechange",
			O = window,
			r = "object",
			aa = typeof document.getElementById != D && typeof document.getElementsByTagName != D && typeof document.createElement != D, 
			ah = navigator.userAgent.toLowerCase(), 
			Y = navigator.platform.toLowerCase(), 
			ae = Y ? /win/.test(Y) : /win/.test(ah), 
			ac = Y ? /mac/.test(Y) : /mac/.test(ah), 
			af = /webkit/.test(ah) ? parseFloat(ah.replace(/^.*webkit\/(\d+(\.\d+)?).*$/, "$1")) : false, 
			X = !+"\v1", T,
			ag = [0, 0, 0], 
			ab = null;
		
        if (typeof navigator.plugins != D && typeof navigator.plugins[S] == r) {
            ab = navigator.plugins[S].description;
            if (ab && !(typeof navigator.mimeTypes != D && navigator.mimeTypes[q] && !navigator.mimeTypes[q].enabledPlugin)) {
                T = true;
                X = false;
                ab = ab.replace(/^.*\s+(\S+\s+\S+$)/, "$1");
                ag[0] = parseInt(ab.replace(/^(.*)\..*$/, "$1"), 10);
                ag[1] = parseInt(ab.replace(/^.*\.(.*)\s.*$/, "$1"), 10);
                ag[2] = /[a-zA-Z]/.test(ab) ? parseInt(ab.replace(/^.*[a-zA-Z]+(.*)$/, "$1"), 10) : 0;
            }
        }
        else {
            if (typeof O.ActiveXObject != D) {
                try {
                    var ad = new ActiveXObject(W);
                    if (ad) {
                        ab = ad.GetVariable("$version");
                        if (ab) {
                            X = true;
                            ab = ab.split(" ")[1].split(",");
                            ag = [parseInt(ab[0], 10), parseInt(ab[1], 10), parseInt(ab[2], 10)];
                        }
                    }
                } 
                catch (Z) {
                }
            }
        }
        return {
            pv: ag,
            ie: X
        }
    }
    function F(Z){	
        var Y = M().pv,
			X = Z.toString().split(".");
        X[0] = parseInt(X[0], 10);
        X[1] = parseInt(X[1], 10) || 0;
        X[2] = parseInt(X[2], 10) || 0;
        return (Y[0] > X[0] || (Y[0] == X[0] && Y[1] > X[1]) || (Y[0] == X[0] && Y[1] == X[1] && Y[2] >= X[2])) ? true : false;
    }

function insFl(v,fl,gif,lnk,w,h,flash_vars) {	
	var d=' width='+w+' height='+h,
		flash;
	if (F(v)) {
		flash = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+d+'><param name="wmode" value="transparent"/><param name="movie" value="'+fl+'"/>';
		 if(flash_vars){
			flash += '<param name="flashvars" value="'+flash_vars+'"/>';
		 }
		flash += '<embed src="'+fl+'" quality=high'+d+' wmode="transparent"';
		if(flash_vars){
			flash += ' flashvars="'+flash_vars+'" ';
		}
		flash += '></embed></object>';
		
		document.write(flash);
	} else {	
		if (gif != '') {
			document.write('<a href='+lnk+'><img src='+gif+d+' border=0></a>')
		}
		else if(M().pv[0]>6){
			document.write("<div id='noFlash'></div>");
			var txt;
			if(M().ie){
				txt = '<object width="310" height="137" id="SWFObjectExprInst" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param name="flashvars" value="MMplayerType=ActiveX"/><param name="movie" value="/images/expressInstall.swf"/></object>';
			}else{
				txt = '<object width=300 height=120 type="application/x-shockwave-flash" data="/images/expressInstall.swf" id="SWFObjectExprInst"><param name="flashvars" value=""/></object>';
			}
				document.write(txt);
		}
		else{
			document.write(noFlash)
		}
	}
}

var swfobject = {
	expressInstallCallback: function(){
		document.getElementById("SWFObjectExprInst").parentNode.removeChild(document.getElementById("SWFObjectExprInst"));
		document.getElementById("noFlash").innerHTML = noFlash;
		}
	}

var noFlash = "<div style='text-align:center;padding:10px'><noindex><div style='width:400px;margin:0 auto;'><h2 style='text-decoration:none'><img width='16' height='16' alt='Внимание' src='/images/alert.gif'/> Внимание</h2><p>Чтобы посмотреть содержимое страницы, должен быть включен JavaScript, и установлена последняя версия Adobe Flash Player.</p><p class='caption'><a target='_blank' href='http://get.adobe.com/flashplayer/'>Скачать Flash Player!</a></p><a target='_blank' href='http://get.adobe.com/flashplayer/'><img  alt='Скачать Flash Player' src='/images/get_flash_player.gif'/></a></div></noindex></div>";

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 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,
			st = obj_ta.scrollTop,
			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 scrolling = getBodyScrollTop(body)
	var body = document.getElementsByTagName("body")[0];
    var over = body.appendChild(document.createElement('div'));
 	over.id = "over";
    var h = document.getElementById("conteiner").offsetHeight;
	if(h>(scrolling+height+40))
	over.style.height = h+"px"
	else
	over.style.height = scrolling+height+40+"px"
 	var conteiner = body.appendChild(document.createElement('div'));
 	conteiner.id = "conteinerimg";
	var inside = conteiner.appendChild(document.createElement('div'));
	inside.id = "inside";
	inside.style.width = width+"px";
	inside.style.height = height+"px";
	inside.style.marginLeft = "auto";
	inside.style.marginRight = "auto";
    inside.style.marginTop = scrolling+"px";
	var image = inside.appendChild(document.createElement('img'));
	image.width=width;
	image.height=height;
	image.title="Закрыть";
	var descr = inside.appendChild(document.createElement('p'));
   	image.setAttribute("src", "/"+url);
//   	image.setAttribute("src", url);

	descr.appendChild(document.createElement('span')).innerHTML = alt;

	//////////////////////////////////////////


	image.onclick = function() {
		over.parentNode.removeChild(over);
		conteiner.parentNode.removeChild(conteiner);
	}
}

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;
}

var jsReady = false;
function isReady() {
 return jsReady;
}
function pageInit() {
 jsReady = true;
 document.forms["form1"].output.value += "\n" + "JavaScript is ready.\n";
}
function thisMovie(movieName) {
 if (navigator.appName.indexOf("Microsoft") != -1) {
     return window[movieName];
 } else {
     return document[movieName];
 }
}
function getXY(value) {
 document.getElementById("coords").value = value;
}

function getNoFlash(){
	if(!F("9.1.15")){
		document.getElementById("noflashhead").style.display = "block";
	}
}

