
var dom = document.getElementById?1:0;
var ie4 = document.all && document.all.item;
var opera = window.opera; //Opera
var ie5 = dom && ie4 && !opera; 
var nn4 = document.layers; 
var nn6 = dom && !ie5 && !opera;
var vers=parseInt(navigator.appVersion);

function document_write($text)
{
	document.write($text);
	return false;
}

function swap(num)
{
//    var obj=document.getElement("re"+num);
	var obj=document.getElementById("re"+num);
	
	if(obj.style.visibility=='visible')
	{
		obj.style.display='none';
		obj.style.visibility='hidden';
	}
	else
	{
		obj.style.display='block';
		obj.style.visibility='visible';
	}
	return false;
}

function swap2(num)
{
    var obj=document.getElementById(num);
    var imgobj=document.getElementById('img' + num);
	
    if(obj.style.visibility=='hidden'){
          obj.style.display='';
          obj.style.visibility='visible';
		  if (imgobj!=null) imgobj.src = "http://static.diary.ru/images/-.gif";
    }else{
          obj.style.display='none';
          obj.style.visibility='hidden';
		  if (imgobj!=null) imgobj.src = "http://static.diary.ru/images/+.gif";
    }
	return false;
}

function hide(id){return HideDiv(id);}
function HideDiv(id)
{
	var obj=document.getElementById(id);
	
	obj.style.display='none';
	obj.style.visibility='hidden';
	return false;
}  

function show(id){return ShowDiv(id);}
function ShowDiv(id)
{
	var obj=document.getElementById(id);
	
	obj.style.display='block';
	obj.style.visibility='visible';
	return false;
}  

function swapMore(oid){
	
	swap2('more'+oid);
	swap2('linkmore'+oid);

	return false;
}
function swapMore2(oid){
	
	var obj=document.getElementById('more' + oid);
	if(obj.innerHTML == ''){
		obj.innerHTML = '<span style="text-decoration:inherit;color:red;"><b>[загрузка...]</b><span>';
		loadV('?post='+oid);
	}
	swap2('more'+oid);
	swap2('linkmore'+oid);

	return false;
}
  
function clUploadData ()
{
        this.type = "text/javascript";
		this.oldScript  = document.createElement("SCRIPT");
        this.oldScript.type = "text/javascript";
//	this.callId = 0;

//	document.body.appendChild(this.oldScript);
	document.getElementsByTagName('body')[0].appendChild(this.oldScript);
	this.upload = function ( theparams ) 
	{
//		this.callId += 1 + Math.random();
	
                var newScript = document.createElement("SCRIPT");
                newScript.type = "text/javascript";
		newScript.src  = theparams || "";
//		newScript.src  += "&callid=" + String(this.callId);
//		var temp = document.getElementById('temp');
//		if(temp!=null) document.all["temp"].value = 'http://pay.diary.ru/mod/pay/' + newScript.src;

//		document.body.replaceChild(newScript,this.oldScript);
		document.getElementsByTagName('body')[0].replaceChild(newScript,this.oldScript);
                this.oldScript = newScript;
        }
}

if(document.body == null) document.write("<body></body>");
var uploadObject = new clUploadData();

function loadV(theparams)
{
//	window.status = 'загрузка...';
	uploadObject.upload(theparams);
}

function loadV2(link){
//	window.status = 'загрузка...';
	var script = document.createElement('script');
		script.defer = false;
		script.src = link;
	document.body.appendChild(script);
}

function checkResult()
{
	try
	{
		result = NewContentFrame.document.getElementById("result");
			if(result == null) showMsg("alert","Ошибка","Неизвестная ошибка,<br> попробуйте через 20 секунд");
		else
		{
			if(result.value==1)
			{
				obj=document.getElementById('message');
				if(obj!=null) obj.value = "";
			}
		}
	}
	catch(err)
	{
		showMsg("alert","Ошибка","<b>Описание:</b> " + err.description);
	}
}

function showMsg(type,title,text)
{
	var obj;
	obj = document.getElementById("msgWin");
	
	if(obj==null)
	{
		if (document.getElementById("message")!=null)
		{
			var ndiv = document.createElement('div');
			ndiv.innerHTML = '<div id="msgWin"><table id="msgTitle"><tr><td id="msgTitleText">+шибка<td style="width:1%;padding:3px;"><input type="button" id="msgWinCloseBt" onclick="hide(\'msgWin\');" class="submit" value="X" style="font-size:70%;width:15px;heigth:15px;margin:-1px;padding:0;"/></table></strong><em id="msgText"></em></div>';
			document.getElementsByTagName('body')[0].appendChild(ndiv);

//			document.getElementsByTagName('body')[0].innerHTML = '<div id="msgWin"><table id="msgTitle"><tr><td id="msgTitleText">+шибка<td style="width:1%;padding:3px;"><input type="button" id="msgWinCloseBt" onclick="hide(\'msgWin\');" class="submit" value="X" style="font-size:70%;width:15px;heigth:15px;margin:-1px;padding:0;"/></table></strong><em id="msgText"></em></div>' + document.getElementsByTagName('body')[0].innerHTML;
			obj = document.getElementById("msgWin");
		}
	}

	if(obj!=null)
	{
		document.getElementById("msgTitleText").innerHTML = "&nbsp;" + title;
		document.getElementById("msgText").innerHTML = text;
		
		if(type == 'alert') document.getElementById("msgText").className = "msgErr";
		else  document.getElementById("msgText").className = "";
		
		if (navigator.userAgent.indexOf("MSIE 6") != -1 || navigator.userAgent.indexOf("MSIE 5") != -1) obj.style.top = document.documentElement.scrollTop + 200 + "px";
		obj.style.visibility = "visible";
		obj.style.display = "block";
		document.getElementById("msgWinCloseBt").focus();
	}
	else alert(text.replace( "<br>", "\r\n" ));
}

// Проверяем знает ли браузер про HTMLElement.
if (typeof(HTMLElement) != "undefined" && !opera) {
    var _emptyTags = {
       "IMG": true,
       "BR": true,
       "INPUT": true,
       "META": true,
       "LINK": true,
       "PARAM": true,
       "HR": true
    };
    
    HTMLElement.prototype.__defineGetter__("outerHTML", function () {
       var attrs = this.attributes;
       var str = "<" + this.tagName;
       for (var i = 0; i < attrs.length; i++) str += " " + attrs[ i ].name + "=\"" + attrs[ i ].value + "\"";
    
       if (_emptyTags[this.tagName]) return str + ">";
    
       return str + ">" + this.innerHTML + "</" + this.tagName + ">";
    });
    
    HTMLElement.prototype.__defineSetter__("outerHTML", function (sHTML) {
       var r = this.ownerDocument.createRange();
       r.setStartBefore(this);
       var df = r.createContextualFragment(sHTML);
       this.parentNode.replaceChild(df, this);
    });
}

// date - экземпляр объекта Date
// * все экземпляры объекта Date передаются этой функции "для
// ремонта"
function fixDate(date) {
	var base = new Date(0);
	var skew = base.getTime();
	if (skew > 0)
		date.setTime(date.getTime() - skew);
}

//Устанавливает cookie
// name - имя cookie
// value - значение cookie
// [expires] - дата окончания действия cookie (по умолчанию - конец текущей  //  сессии)
// [path] - путь, где cookie верны (по умолчанию - путь к текущему документу)
// [domain] - домен, где cookie верны (по умолчанию - домен вызываемого 
// документа)
// [secure] - бинарная переменная, показывающая, что cookie должны
// передаваться через защищённое соединение
// * по умолчанию аргументу присвоено значение null
// * нулевое значение не требуется присваивать пропущенным переменным
function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
	document.cookie = curCookie;
}

// name - имя cookie
// * строка возврата содержит значения необходимого cookie или null при
// его отсутствии
function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else
		begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
		end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}

// name - имя cookie
// [path] - путь, где cookie верны (должен быть тем же, что и путь при
// создании cookie)
// [domain] - домен, где cookie верны (должен быть тем же, что и домен при
// создании cookie
// * путь и домен по умолчанию присвоены в null и не требуется
// присваивать этого значения
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
	document.cookie = name + "=" + 
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	"; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

var open_win_img = null;
function openWinImg( vkl ){
if( open_win_img != null )
{
       try
       {
         if( open_win_img.document !=null) open_win_img.focus();
         else if( vkl ==1 ) open_win_img = window.open('/diary.php?module=photolib&act=plist&va=1', this.target, 'width=800, height=650, location=0, toolbar=0, menubar=0, status=0, scrollbars=1, resizable=1');
         else open_win_img = window.open('/diary.php?module=photolib&act=plist&va=2', this.target, 'width=800, height=650, location=0, toolbar=0, menubar=0, status=0, scrollbars=1, resizable=1');
       }
       catch(ex){
         if( vkl ==1 ) open_win_img = window.open('/diary.php?module=photolib&act=plist&va=1', this.target, 'width=800, height=650, location=0, toolbar=0, menubar=0, status=0, scrollbars=1, resizable=1');
         else open_win_img = window.open('/diary.php?module=photolib&act=plist&va=2', this.target, 'width=800, height=650, location=0, toolbar=0, menubar=0, status=0, scrollbars=1, resizable=1');
       }
}
else{
		if( vkl ==1 ){
			open_win_img = window.open('/diary.php?module=photolib&act=plist&va=1', this.target, 'width=800, height=650, location=0, toolbar=0, menubar=0, status=0, scrollbars=1, resizable=1');
		}else{
			open_win_img = window.open('/diary.php?module=photolib&act=plist&va=2', this.target, 'width=800, height=650, location=0, toolbar=0, menubar=0, status=0, scrollbars=1, resizable=1');
	    }
	}
}

var open_win_smile = null;

function openWinSmile()
{
	if (open_win_smile != null)
	{
		try
		{
			if (open_win_smile.document != null) open_win_smile.focus();
			else open_win_smile = window.open('/smile.php', this.target, 'width=500, height=400, location=0, toolbar=0, menubar=0, status=0, scrollbars=1, resizable=0');
		}
		catch(ex)
		{
			open_win_smile = window.open('/smile.php', this.target, 'width=500, height=400, location=0, toolbar=0, menubar=0, status=0, scrollbars=1, resizable=0');
		}
	}
	else
	{
		open_win_smile = window.open('/smile.php', this.target, 'width=500, height=400, location=0, toolbar=0, menubar=0, status=0, scrollbars=1, resizable=0');
	}
}

// определение ширины области записи для sImg --------------------------------------------------------
var postW = 100;

function setSImg(img)
{
	if (img.width + 120 > postW)
		img.parentNode.className="img_div";
}

function setPostW(obj)
{
	if (postW == 100) postW = obj.width;
	obj.style.display = 'none';
	obj.style.visibility = 'hidden';
}

function ChangeRecordCoutn(value)
{
	var obj = document.getElementById('record_num');
	
	if (value) obj.innerHTML = Number(obj.innerHTML) + 1;
	else obj.innerHTML = Number(obj.innerHTML) - 1;
}
//----------------------------------------------------------------------------------------------------
