// Copyright (c) 2000-2009 N.Mikhailov, mn@ixbt.com, http://forum.iXBT.com

var dateformat		= "dd.mm.yyyy"
var ampmtimeformat	= ""
var language 		= "ru"
var privatetopics	= "1"
var topicauthorregdate	= ""

var forum_number 	= 0
var topic_number	= 0 
var topic_name	= ""
var topic_note	= "" 
var pages_line	= "" 
var action_line	= ""

var table_class 	= "t2"
var old_action 		= ""
var paste_user_name 	= ""
var selected_name 	= ""
var selection 		= ""

var IE5 		= (navigator.userAgent.indexOf('MSIE')!=-1) && (navigator.userAgent.indexOf('Opera')==-1)
var Opera7 		= (navigator.userAgent.indexOf('Opera')!=-1) && (get_browser_ver('Opera')>=7);
var Gecko 		= (navigator.userAgent.indexOf('Gecko')!=-1)

var language_cookie = getCookie('language')
if (language_cookie!=null) language=language_cookie;
document.writeln('<script language="javascript" src="/lang_'+language+'.js"></script>');

function p1(text){ 
if (text!="") paste("[b]"+unescape(text)+"[/b]\n", 1)
}

function p2(text){ 
if (text!="") {
	paste_user_name=unescape(paste_user_name)
	if ((paste_user_name!="") && (paste_user_name!="undefined") && (document.postform.message.value.indexOf("[b]"+paste_user_name+"[/b]")==-1)) {
		if (document.postform.message.value!='') paste("\n", 0)
		paste("[b]"+paste_user_name+"[/b]\n", 0)
	} else {
		if (document.postform.message.value!='') paste("\n", 0)
	}
	paste("[i]"+text+"[/i]\n", 0)
	paste_user_name=""
}
}

function paste(text, flag){ 
if ((document.selection)&&(flag)) {
	document.postform.message.focus()
	document.postform.document.selection.createRange().text = text
} else if ((typeof eval(document.postform.message.selectionStart) != "undefined")&&(flag)) {
	d = document.postform.message;
	d.focus();
	pos = d.selectionStart+text.length;
	d.value = d.value.substring(0, d.selectionStart) + text + d.value.substring(d.selectionStart,d.value.length)
	d.selectionEnd = pos;
} else document.postform.message.value += text
}

function get_selection() {
if (document.getSelection){
	selection = document.getSelection();
	if ((!Opera7) && (!Gecko)){
		selection = selection.replace(/\r\n\r\n/gi, "_doublecaret_");
		selection = selection.replace(/\r\n/gi, " ");
		while (selection.indexOf("  ") !=-1) selection = selection.replace(/  /gi, ""); 
		selection = selection.replace(/_doublecaret_/gi, "\r\n\r\n");
	}
} else if (window.getSelection){
	selection = window.getSelection().toString();
} else {
      selection = document.selection.createRange().text;
}
}

function hide_float_paste_form(){ 
if (!confirm(language_text[110])) return
setup_cookie = getCookie('setup');
if (setup_cookie) setup_cookie=setup_cookie.replace(/Q/gi, "");
setup_cookie+="Q";
document.cookie="setup="+setup_cookie+"; expires=Sun, 01-Jan-2034 00:00:00 GMT; path=/;";
document.onmouseup = null;
}

function setup_postform(enablefocus){
link='<a id="idpaste" href="javascript:p2(selection); hide_paste_window();" onMouseOver="get_selection()" onMouseUp="float_paste.style.top=-50;" class=small3><font color=black>';
if (IE5 || Opera7 || Gecko) document.writeln('<div id=float_paste style="position: absolute; display: none; width: 170px; filter=progid:DXImageTransform.Microsoft.shadow(direction=135,color=#505050,strength=4);"><style>.box1, .box2, .box3, .box4, .box5, .box6 {display: block; height: 1px; overflow: hidden; font-size: 1px; background-color: #FFFFE1}.box6 {margin: 0 5px; background-color: #000000}.box5 {margin: 0 3px; border-left: 3px black solid; border-right: 3px black solid}.box4 {margin: 0 2px; border-left: 2px black solid; border-right: 2px black solid}.box3 {margin: 0 1px; border-left: 2px black solid; border-right: 2px black solid}.box2 {margin: 0 1px; border-left: 1px black solid; border-right: 1px black solid}.box1 {margin: 0 0px; border-left: 2px black solid; border-right: 2px black solid}.box  {padding: 0 0.3em; background-color: #FFFFE1; border-left: 1px black solid; border-right: 1px black solid}</style><b class="box6"></b><b class="box5"></b><b class="box4"></b><b class="box3"></b><b class="box2"></b><b class="box1"></b><div class="box"><table border=0 cellpadding=0 cellspacing=0 bgcolor=#FFFFE1><tr><td>'+link+'<img src="/paste.gif" style="margin: 0 3px" border=0></font></a></td><td>'+link+language_text[214]+'</font></a></td><td valign=top align=right><a href="javascript:;" onclick="hide_float_paste_form()"><img border=0 style="margin-left: 15px" src="/close.gif"></a></td></tr></table></div><b class="box1"></b><b class="box2"></b><b class="box3"></b><b class="box4"></b><b class="box5"></b><b class="box6"></b></div>');

if (enablefocus) {document.postform.UserName.focus()}
var testUserName = getCookie("user")
var testPassword = getCookie("pass")
if ((document.cookie)&&(testUserName != null)) {
	document.postform.UserName.value = testUserName
	if (testPassword!=null) {document.postform.Password.value = testPassword}
	if (enablefocus) {
		if (document.postform.thread_subject != null) {document.postform.thread_subject.focus()} else {document.postform.message.focus()}
	}
}
if (getCookie("setup")!=null){
	if (getCookie("setup").indexOf("D") != -1) {document.postform.without_smilies.checked = true}
}
if ((!enablefocus)&&(document.postform.message.style!=null)){ 
	var testform_cookie = getCookie('setup2')
	if (testform_cookie!=null){
		form_cookie=testform_cookie.split("|");
		if ((form_cookie[3] != null)&&(form_cookie[3]>=20)&&(form_cookie[3]<=250)) {document.postform.message.cols=form_cookie[3]} else {document.postform.message.style.width="100%"};
		if ((form_cookie[4] != null)&&(form_cookie[4]>=5)&&(form_cookie[4]<=100)) document.postform.message.rows=form_cookie[4]
		if ((form_cookie[5] != null)&&(form_cookie[5]>=0)) document.postform.message.style.fontSize=form_cookie[5]
		if ((form_cookie[6] != null)&&(form_cookie[6]!='')) document.postform.message.accessKey=form_cookie[6]
		if ((form_cookie[7] != null)&&(form_cookie[7]>50)&&(IE5 || Opera7 || Gecko)) document.postform.message.style.height=form_cookie[7]
	} else {document.postform.message.style.width="100%"}
}

switch(navigator.appName) {
   case "Microsoft Internet Explorer":
      Key = "event.ctrlKey && event.keyCode == 13";
      document.onkeydown = get_key;
      break;
   case "Netscape":
      Key = "(e.modifiers == 2 && e.which == 10) || (e.ctrlKey && e.which == 13)";
      document.captureEvents(Event.KEYDOWN);
      document.onkeydown = get_key;
      break;
}
}

function get_key(e) {
if (eval(Key)) {
	if (check_postform()){
		check_submit();
		document.postform.submit();
		submit_once(document.postform);
	} else {return false}
}
}


function setup_loginform(){
var testUserName = getCookie("user")
var testPassword = getCookie("pass")
if ((document.cookie)&&(testUserName != null)) {
	document.loginform.UserName.value = testUserName
	if (testPassword!=null) {document.loginform.Password.value = testPassword}
	}
}

function check_postform(){
var max = 42000
if (document.postform.message.value.length == 0){
	alert(language_text[100]);
	return false;
}
if (document.postform.message.value.length > max){
	alert(language_text[101]+(document.postform.message.value.length-max)+language_text[102]);
	return false;
}
if (document.postform.UserName.value.length == 0){
	alert(language_text[103]);
	return false;
}
//if (document.postform.disabled) return false;
return true;
}


function check_loginform(){
if ((document.loginform.UserName.value.length == 0)||(document.loginform.Password.value.length == 0)){
	alert(language_text[104])
	return false;
 }
return true;
}

function check_submit() {
if (old_action!="") document.postform.id.value=old_action
document.postform.target="_self";
}

function submit_once(theform){
if (theform.target=="preview") {return}
if (document.all||document.getElementById){
for (i=0;i<theform.length;i++){
var tempobj=theform.elements[i]
if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset") {tempobj.disabled=true}
}
}
}

function getCookie(name) {
var prefix = name + "="
var StartIndex = document.cookie.indexOf(prefix)
if (StartIndex == -1)
return null
var EndIndex = document.cookie.indexOf(";", StartIndex + prefix.length)
if (EndIndex == -1)
EndIndex = document.cookie.length
return unescape(document.cookie.substring(StartIndex + prefix.length, EndIndex))
}

function delete_cookies(only_name){ 
if (document.cookie == "") {
	alert(language_text[109])
	return;
}
if (only_name){
	if (!confirm(language_text[105])) return
	document.cookie = "user=; expires=Thu, 01-Jan-1970 00:00:00 GMT; path=/;"
	document.cookie = "pass=; expires=Thu, 01-Jan-1970 00:00:00 GMT; path=/;"
	alert(language_text[107])
} else{
	if (!confirm(language_text[106])) return
	cookies = document.cookie.split(";")
	for (i=0; i<cookies.length; i++) document.cookie = cookies[i].split("=")[0] + "=; expires=Thu, 01-Jan-1970 00:00:00 GMT; path=/;"
	alert(language_text[108])
}
}

function twosym(number){
if (number>9) {return number} else {return "0"+number}
}

function getdate(in_datetime){
temp_date=new Date(in_datetime*1000);
post_date=dateformat;
post_date=post_date.replace(/dd/ig, twosym(temp_date.getUTCDate()));
post_date=post_date.replace(/mmmm/ig, months[temp_date.getUTCMonth()]);
post_date=post_date.replace(/mm/ig, twosym(temp_date.getUTCMonth()+1));
post_date=post_date.replace(/yyyy/ig, temp_date.getUTCFullYear());
post_date=post_date.replace(/yy/ig, temp_date.getUTCFullYear().toString().substring(1, 2));
return post_date
}

function gettime(in_datetime){
temp_date=new Date(in_datetime*1000);
hour=temp_date.getUTCHours();
ampm = "";
if (ampmtimeformat==1){
	if (hour < 12) ampm = "AM";
	if (hour > 12) {
		hour = hour - 12;
		ampm = "PM";
	}  	
	if (hour == 12) ampm = "PM";
	if (hour == 0) hour = "12";
	hour = twosym(hour);
	ampm = " "+ampm;
} 
return twosym(hour)+':'+twosym(temp_date.getUTCMinutes())+ampm;
}

function get_browser_ver(browser_id){
var ua = navigator.userAgent;
var offset = ua.indexOf(browser_id);
ua = ua.substring(offset+browser_id.length+1, ua.length);
var end = ua.search(/;| |,|$/);
return parseFloat(ua.substring(0, end));
}

function f_assign(style, t_forum_number) {
forum_number = t_forum_number
document.writeln('<link rel=stylesheet type="text/css" href="/style.css">')
document.writeln('<link rel="shortcut icon" href="/favicon.ico">')
document.writeln('<script language="javascript" src="/list.js"></script>')
document.writeln('<script language="javascript" src="/forum.js"></script>')
}

function t_assign(style, t_forum_number, t_topic_number, t_topic_name, t_topic_note, t_pages_line, t_action_line) {
forum_number	= t_forum_number
topic_number	= t_topic_number 
topic_name	= t_topic_name 
topic_note	= t_topic_note
pages_line	= t_pages_line 
action_line	= t_action_line
document.writeln('<link rel=stylesheet type="text/css" href="/style'+style+'.css">');
document.writeln('<link rel="shortcut icon" href="/favicon.ico">');
document.writeln('<script language="javascript" src="/list.js"></script>');
document.writeln('<script language="javascript" src="/post.js"></script>');
document.writeln('<script language="javascript" src="/topic.js"></script>');
}

function print_rc_fotkidepo(){
txt='';
for (i=0; i<fotkidepo_data.length; i++) {
	txt+='<area shape="rect" coords="'+fotkidepo_data[i][0]+'" href="http://foto.ixbt.com/?id=photo:'+fotkidepo_data[i][1]+'&e=1" target="_blank" title="'+fotkidepo_data[i][2]+'">';
}
document.writeln('<div class=rc_title><a href="http://fotkidepo.ru/" target="_blank">Новые фото на fotkidepo.ru</a></div>');
document.writeln('<div style="padding: 3px 0px 0px 0px; margin-top: 0px">');
document.writeln('<map name="photos" onMouseOver="print_rc_fotkidepo_so(10)" onMouseOut="print_rc_fotkidepo_so(9)">'+txt+'<img src="/js/'+fotkidepo_file+'" usemap="#photos" id="pmap" style="border:0; filter:alpha(opacity=90); opacity:0.9" onMouseOver="print_rc_fotkidepo_so(10)" onMouseOut="print_rc_fotkidepo_so(9)"></map>');
document.writeln('</div>');
}

function print_rc_fotkidepo_so(value){
document.getElementById('pmap').style.opacity=value/10; document.getElementById('pmap').style.filter='alpha(opacity='+value*10+')';
}

function print_rc_komok(){
document.writeln('<div class=rc_title><a href="http://www.komok.com/" target="_blank">Предложения на komok.com</a></div><table class=rc_news>'+komok_data+'</table>');
}

