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

var mode  = 2
var offset_y = 0

if (getCookie("setup")!=null){
	if (getCookie("setup").indexOf("I") != -1) var no_instruments=true
	if (getCookie("setup").indexOf("S") != -1) var no_smilies=true
}

function insertcodes1(show_always, hide_attach){
if (show_always){
	no_instruments=""
	no_smilies=""
}
if ((no_instruments == true) && (no_smilies == true)) return
document.writeln('<table border=0 cellpadding=0 cellspacing=1 width=100%>');
if (no_instruments != true) {
	var attach_text = (hide_attach==null) ? '<area shape="rect" coords="446,0,461,18" href="javascript:;" onclick="if (forums_array[forum_number][4]!=\'\') {document.getElementById(\'attach\').style.display=\'\'} else {alert(language_text[201])}" title="'+language_text[202]+'">' : '';
	var paste_text = ((document.selection && document.selection.createRange) || document.getSelection) ? '<a href="javascript:p2(selection)" onMouseOver="get_selection()"><img border=0 src="/paste.gif" title="'+language_text[205]+'"></a>' : '';
	document.writeln(
		'<map name="codes">'+
		'<area shape="rect" coords="0,0,18,18"    href="javascript:do_preview()" title="'+language_text[200]+'">'+
		'<area shape="rect" coords="23,0,40,18"   href="javascript:c1(0)"  title="'+codes_array[0][1]+'">'+
		'<area shape="rect" coords="41,0,58,18"   href="javascript:c1(1)"  title="'+codes_array[1][1]+'">'+
		'<area shape="rect" coords="59,0,76,18"   href="javascript:c1(2)"  title="'+codes_array[2][1]+'">'+
		'<area shape="rect" coords="77,0,98,18"   href="javascript:c1(3)"  title="'+codes_array[3][1]+'">'+
		'<area shape="rect" coords="99,0,111,18 " href="javascript:c1(4)"  title="'+codes_array[4][1]+'">'+
		'<area shape="rect" coords="112,0,128,18" href="javascript:c1(5)"  title="'+codes_array[5][1]+'">'+
		'<area shape="rect" coords="129,0,145,18" href="javascript:c1(6)"  title="'+codes_array[6][1]+'">'+
		'<area shape="rect" coords="146,0,167,18" href="javascript:c1(7)"  title="'+codes_array[7][1]+'">'+
		'<area shape="rect" coords="168,0,186,18" href="javascript:c1(8)"  title="'+codes_array[8][1]+'">'+
		'<area shape="rect" coords="187,0,209,18" href="javascript:c1(9)"  title="'+codes_array[9][1]+'">'+
		'<area shape="rect" coords="210,0,230,18" href="javascript:c1(10)" title="'+codes_array[10][1]+'">'+
		'<area shape="rect" coords="239,0,259,18" href="javascript:c2(11)" title="'+codes_array[11][1]+'">'+
		'<area shape="rect" coords="260,0,279,18" href="javascript:c2(12)" title="'+codes_array[12][1]+'">'+
		'<area shape="rect" coords="289,0,307,18" href="javascript:c1(13)" title="'+codes_array[13][1]+'">'+
		'<area shape="rect" coords="308,0,326,18" href="javascript:c1(14)" title="'+codes_array[14][1]+'">'+
		'<area shape="rect" coords="327,0,345,18" href="javascript:c1(15)" title="'+codes_array[15][1]+'">'+
		'<area shape="rect" coords="346,0,364,18" href="javascript:c1(16)" title="'+codes_array[16][1]+'">'+
		'<area shape="rect" coords="365,0,382,18" href="javascript:c1(17)" title="'+codes_array[17][1]+'">'+
		'<area shape="rect" coords="383,0,401,18" href="javascript:c1(18)" title="'+codes_array[18][1]+'">'+
		'<area shape="rect" coords="402,0,420,18" href="javascript:c1(19)" title="'+codes_array[19][1]+'">'+
		'<area shape="rect" coords="421,0,434,18" href="javascript:c1(20)" title="'+codes_array[20][1]+'">'+
		attach_text+
		'<area shape="rect" coords="462,0,477,18" href="javascript:;" onclick="if (document.getElementById(\'smiliesmap\').style.display==\'none\') {document.getElementById(\'smiliesmap\').style.display=\'\'} else {document.getElementById(\'smiliesmap\').style.display=\'none\'}" title="'+language_text[203]+'">'+
		'<area shape="rect" coords="478,0,497,18" href="javascript:c1(21)" title="'+codes_array[21][1]+'">'+
		'<area shape="rect" coords="498,0,514,18" href="javascript:do_help()" title="'+language_text[204]+'">'+
		'</map>'+
		'<tr><td class=s valign=center><nobr>'+paste_text+'<img border=0 src="/codesmap.gif" usemap="#codes"> </nobr><select name="select" class=s onChange="select_onchange(this.options[this.selectedIndex].value)"><option value="1">'+language_text[206]+'<option value="2" selected>'+language_text[207]+'<option value="3">'+language_text[208]+'</select></td></tr>'
	);
	var testform_cookie = getCookie('setup2')
	if ((testform_cookie!=null)){ 
		form_cookie=testform_cookie.split("|")
		if (form_cookie[8]!=null) {
			document.postform.select.selectedIndex=form_cookie[8]
			mode=document.postform.select.selectedIndex+1;
		}
	}
}
document.writeln('<tr><td class=s>')
}


function select_onchange(number){
mode=number
var testform_cookie = getCookie('setup2')
if (testform_cookie!=null) {form_cookie=testform_cookie.split("|")} else {form_cookie = new Array()}
form_cookie[8]=mode-1
document.cookie="setup2="+form_cookie.join("|")+"; expires=Sun, 01-Jan-2034 00:00:00 GMT; path=/;";
}

function do_help(){ 
window.open("/help/code.html", "_blank")
}

function p3(text){ 
if (text!="") paste(text, 1)
}

function p4(text1, text2){ 
if ((document.selection)) {
	document.postform.message.focus()
	document.postform.document.selection.createRange().text = text1+document.postform.document.selection.createRange().text+text2
} else document.postform.message.value += text1+text2
}

function c1(num) {
line1 = "["+codes_array[num][0]+"]"
line2 = "[/"+codes_array[num][0]+"]"
if (num==18) {
	line1 = "[table][tr][td]"
	line2 = "[/td][/tr][/table]"
}
if (num==20) line2 = ""
if (mode==1) alert(codes_array[num][1])
	else if (mode==3) p4(line1, line2)
	else {
		if (codes_array[num][2] == null) p3(line1)
		else if (codes_array[num][3] == null) {
			txt=prompt(codes_array[num][2],"")
			if (txt!=null) p3(line1+txt+line2)
		} else {
			txt2=prompt(codes_array[num][3],"")
			if (txt2!=null) {
				txt=prompt(codes_array[num][2],"")
				if (txt!=null) {				
					if (txt2=="") p3(line1+txt+line2) 
						else 	if (codes_array[num][4] != null) p3("["+codes_array[num][0]+"="+txt+"]"+txt2+"[/"+codes_array[num][0]+"]")
											else p3("["+codes_array[num][0]+"="+txt2+"]"+txt+"[/"+codes_array[num][0]+"]")
				}			
			}
		}
	}
}

function c2(num) {
if (num == 11) line1 = "[list=1]" 
    else line1 = "[list][*]"
line2 = "\n[/list]"

if (mode==1) alert(codes_array[num][1])
	else if (mode==3) p4(line1+"[*]", line2)
	else {
		txt="1"
		list=""
		while ((txt!="") && (txt!=null)) {
			txt=prompt(codes_array[num][2],"")
			if (txt!="") list+="[*]"+txt+"\r"
			if (txt==null) return 
		} 
		p3(line1+list+"[/list]")
	}
}

function insert_quote(){
if ((no_instruments == true) && (navigator.userAgent.indexOf("Opera") == -1)) 
document.writeln('<br><br><a class=small3 href="javascript:p2(selection)" onMouseDown="get_selection()">'+language_text[205]+'</a>')
if (IE5 || Opera7){
	document.writeln('<br><br><div id=float_link><a class=small3 href="javascript:do_float(1)">'+language_text[209]+'</a></div>')
	window.onscroll = on_scroll;
}
}

function do_float(isfloat){
if (isfloat) {
	post.style.position="absolute"
	post.style.border="2px black solid"
	post.style.backgroundColor="white"
	select_list.style.display="none"
	float_link.innerHTML='<a class=small3 href="javascript:do_float(0)">'+language_text[210]+'</a>'
	setTimeout("post.style.top=document.body.scrollTop+document.body.offsetHeight-post.offsetHeight-5", 10);
} else {
	post.style.position=""
	post.style.border=""
	post.style.backgroundColor="white"
	select_list.style.display=""
	float_link.innerHTML='<a class=small3 href="javascript:do_float(1)">'+language_text[209]+'</a>'
}
}

function on_scroll(){
if (document.postform != null) 
	if (post.style.position != "") setTimeout('post.style.top=document.body.scrollTop+document.body.offsetHeight-post.offsetHeight-5', 50)
}

function message_resize_onmousemove() {
newheigth=document.postform.message.offsetHeight-offset_y+window.event.clientY;
if (newheigth>50) {
	document.postform.message.style.height=newheigth
	offset_y=window.event.clientY
}
return false
}

function message_resize_onmousedown() {
document.onmousemove = message_resize_onmousemove
document.onmouseup = message_resize_onmouseup
offset_y = window.event.clientY
return false
}

function message_resize_onmouseup() {
document.onmousemove = null
document.onmouseup = null
var testform_cookie = getCookie('setup2')
if (testform_cookie!=null) {form_cookie=testform_cookie.split("|")} else {form_cookie = new Array()}
form_cookie[7]=document.postform.message.offsetHeight
document.cookie="setup2="+form_cookie.join("|")+"; expires=Sun, 01-Jan-2034 00:00:00 GMT; path=/;";
return false
}

function insertcodes2(hide_attach){
if ((IE5) || (Opera7)) document.writeln('<img src="/blank.gif" onmousedown="message_resize_onmousedown()" width=100% height=5 style="cursor: move"><br>')
if ((no_instruments == true) && (no_smilies == true)) return;
var tempstyle = (no_smilies) ? ' style="display:none"' : '';
var text = '</td></tr><map name=smilies>';
for (i=0; i<smilies_array.length; i++) {
	text += '<area shape="rect" coords="'+smilies_array[i][0]+'"    href="javascript:p3(\''+smilies_array[i][1]+'\')" title="'+smilies_array[i][2]+'">';
}
text += '</map><tr id=smiliesmap'+tempstyle+'><td class=s><img src="/smileymap.gif" border=0 usemap="#smilies"></td></tr></table>';
document.writeln(text);

if (hide_attach==null){
	if (forums_array[forum_number][4]!=''){
		document.writeln('</td></tr><tr id=attach style="display:none" class='+table_class+'><td class=n align=right width=18%>'+language_text[211]+':<div class=small3>('+forums_array[forum_number][4]+' '+language_text[212]+' '+ forums_array[forum_number][5]+' '+language_text[213]+')</div></td><td class=s valign=top>');
		var event = (Opera7) ? "onChange" : "onClick";
		for (i=1; i<=attach_max; i++) {
			var tmp1 = (i==1) ? '': 'style="display:none"';
			var tmp2 = (i==attach_max) ? '': event+'="document.getElementById(\'attach'+(i+1)+'\').style.display=\'\';"'
			document.writeln('<div id=attach'+i+' '+tmp1+'>'+i+': <input type="file" name="attachfile'+i+'" value="" size=40 maxlength=200 class=s '+tmp2+'></div>');
		}
	}
}
}

function do_preview(){
if (document.postform.id.value.indexOf("preview")==-1) old_action=document.postform.id.value;
id_array=document.postform.id.value.split(":");
document.postform.id.value='preview:'+id_array[1];
window.open("", "preview", "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes, resizable=yes, top=0, left=0");   
document.postform.target="preview";   
document.postform.submit();  
}

function pip(ipn){
document.ip.elements[0].value=ipn
document.ip.elements[0].focus()
}
