<!--

var koi2utf={
163:1105,
179:1025,
192:1102,
193:1072,
194:1073,
195:1094,
196:1076,
197:1077,
198:1092,
199:1075,
200:1093,
201:1080,
202:1081,
203:1082,
204:1083,
205:1084,
206:1085,
207:1086,
208:1087,
209:1103,
210:1088,
211:1089,
212:1090,
213:1091,
214:1078,
215:1074,
216:1100,
217:1099,
218:1079,
219:1096,
220:1101,
221:1097,
222:1095,
223:1098
};

var last_visit_time = 0;
var first_time = 0;
var first_time_epoch = 0;
var d = new Date();
var nowtime=parseInt(d.getTime()/1000);
if (typeof raw_nowtime != "undefined"){
    nowtime=raw_nowtime;
}

var lv0 = GetCookie2('lastvisit');
var lv = new Array();
if (lv0 != null){
    lv = lv0.split('.');
}
if (lv.length != 2 || isNaN(parseInt(lv[0])) || isNaN(parseInt(lv[1])) ){
    lv[0]=nowtime;
    lv[1]=nowtime;
}else{
    lv[0]=parseInt(lv[0]);
    lv[1]=parseInt(lv[1]);
}

if (nowtime - lv[1] > 1800){
    lv[0] = lv[1];
}



function koi2unicode (str){
     if (str == null){ return null;}
     var result = "";
     var o_code = "";
     var i_code = "";
     for (var I=0; I < str.length; I++){
        i_code = str.charCodeAt(I);
	
	if (koi2utf[i_code] != null){
	    o_code = koi2utf[i_code]; 
	} else if (i_code > 223 && koi2utf[i_code-32] != null){
	    o_code = koi2utf[i_code-32]-32;
	} else {	    
	    o_code = i_code;
	}
	result = result + String.fromCharCode(o_code);
     }
     
     return result;  
}

function GetCookie2 (name) {
     var arg = name + "=";
     var alen = arg.length;
     var clen = document.cookie.length;
     var endstr = 0;  
     var i = 0;
     while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg){
             endstr = document.cookie.indexOf (";", j);
             if (endstr == -1){
	        endstr = document.cookie.length;
	     }
	     return unescape(document.cookie.substring(j, endstr));
	}
	i = document.cookie.indexOf(" ", i) + 1;
	if (i == 0) { break; }
     }
     return null;
}	          

var g_user_name = koi2unicode(GetCookie2("user_name"));

function setup_nick(){
	document.charset='koi8-r';
	var name = g_user_name;
	var email = GetCookie2("from_email");
	if (name == null || name.length == 0){
	    name = "Аноним";
	}
	document.comment.name.value=name;
	if (email != null && email.length > 3){ 
	    document.comment.email.value=email;
	}
	return 0;
}   

function TxtResize(fr){
    fr.form.body.cols=80;
    fr.form.body.rows=15;
}

function s_n_raw(msg_time, forumid, outtype, cur_user_name){

    var last_visit_epoch=lv[0]-3600*2;
    var day = new Date((last_visit_epoch + 3 * 3600 )* 1000);
    last_visit_time = ((day.getUTCFullYear() - 1997) * 372 * 86400) + ((day.getUTCMonth() + 1) * 31 * 86400) + (day.getUTCDate() * 86400) + (day.getUTCHours() * 3600) + (day.getUTCMinutes() * 60) + day.getUTCSeconds(); 

    var out_data='';
    if ((outtype != 2 && msg_time > last_visit_time && first_time < last_visit_time) || (outtype == 2 && msg_time > last_visit_epoch && first_time_epoch < last_visit_epoch)){
	out_data= '<img src="/openforum/Images/newmark.gif" alt="!*!">';
//document.write(msg_time +':'+ last_visit_epoch +':'+ first_time_epoch);
    }
    if (g_user_name != null && g_user_name != '' && g_user_name != 'Аноним'){
	if (g_user_name == cur_user_name){
	    out_data = out_data + '<img src="/openforum/Images/mymark.gif">';
	    //out_data = out_data + '<!-- '+g_user_name+'/'+cur_user_name+' -->';
	}
	
    }

    if (outtype != 1){
        document.write(out_data);
    } else {
        return out_data;
    }
}

function s_n_repl(text, msg_time, forumid,cur_user_name){
    if (first_time == 0){
	first_time = msg_time;
    }
    return s_n_raw(msg_time, forumid, 1,cur_user_name);
}
function s_n_epoch(msg_time,cur_user_name){
    if (first_time_epoch == 0){
	first_time_epoch = msg_time;
    }
    return s_n_raw(msg_time, 'vsluhforumID3', 2,cur_user_name);
}
function s_n(msg_time, forumid, cur_user_name){
    s_n_raw(msg_time, forumid, 0, cur_user_name);
}

 
function set_lastload(path){
    document.cookie='lastvisit='+ lv[0] + '.' + nowtime + '; path=' + path + '; expires=Thu, 19-May-2011 10:38:47 GMT';
}

function o_vote(id, vote){

	var x;
	var res='p>+1';
	if (vote == -1) res='m>-1';
	var item=document.getElementById('vt_' + id);
	if (item){
		item.innerHTML='<span class=vt_'+res+'</span>';
	}
	if(typeof XMLHttpRequest != "undefined"){
	    x = new XMLHttpRequest();
	    x.open("GET", "/cgi-bin/openforum/ajax2.cgi?rs=vote&id=" + escape(id) + "&vote=" + escape(vote), true);
	    x.onreadystatechange = function() {
		if (x.readyState != 4) return;
	    }
	    x.send(null);
	}
	return false;
}
function load_topnews(){

    var hdr='<table class=thdr><tr><td>Лента</td></tr></table><table class=tlist>';
    var ftr='</table>';
    var s=''
    var f=0;
    for (var i in topnews){
        f = topnews[i]['l'];
	if (f == '-2'){s='&lt;&lt;';}
	if (f == '-1'){s='&lt;';}
	if (f == '1'){s='&gt;';}
	if (f == '2'){s='&gt;&gt;';}
	if (f == '0'){
	    var item=document.getElementById('social_link');
	    if (item){
		item.innerHTML= '<a href="http://twitter.com/home?status=' + encodeURI(topnews[i]['t']) + ':+http%3A%2F%2Fopennet.ru%2F' + topnews[i]['n'] + '%2F" target="_blank" title="Отправить в Twitter"><img src="/twitter.png" height="16" width="16" border="0"></a>' + '&nbsp;<a href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fopennet.ru%2F' + topnews[i]['n'] + '%2F&t=' + encodeURI(topnews[i]['t']) + '" target="_blank" title="Отправить в Facebook"><img src="/img/facebook.gif" height="16" width="16" border="0"></a>' + '&nbsp;<a href="http://identi.ca/?action=newnotice&status_textarea=' + encodeURI(topnews[i]['t']) + ':+http%3A%2F%2Fopennet.ru%2F' + topnews[i]['n'] + '%2F" target="_blank" title="Отправить в identi.ca"><img src="/identica.png" height="16" width="16" border="0"></a>';
	    }
	} else {
	    hdr = hdr + '<tr><td>'+s+' <a href="?num=' + topnews[i]['n']+ '">' + topnews[i]['t']+'</a></td></tr>';
	}
    } 
    if (f != 0){
	document.write(hdr+ftr);
    }
}
   
// -->
