/* 
------------------------------------------
	Flipbox written by CrappoMan
	simonpatterson@dsl.pipex.com
------------------------------------------
*/
function flipBox(who) {
	var tmp; 
	if (document.images['b_' + who].src.indexOf('_on') == -1) { 
		tmp = document.images['b_' + who].src.replace('_off', '_on');
		document.getElementById('box_' + who).style.display = 'none';
		document.images['b_' + who].src = tmp;
	} else { 
		tmp = document.images['b_' + who].src.replace('_on', '_off');
		document.getElementById('box_' + who).style.display = 'block';
		document.images['b_' + who].src = tmp;
	} 
}

function addText(elname, wrap1, wrap2) {
	if (document.selection) { // for IE 
		var str = document.selection.createRange().text;
		document.forms['inputform'].elements[elname].focus();
		var sel = document.selection.createRange();
		sel.text = wrap1 + str + wrap2;
		return;
	} else if ((typeof document.forms['inputform'].elements[elname].selectionStart) != 'undefined') { // for Mozilla
		var txtarea = document.forms['inputform'].elements[elname];
		var selLength = txtarea.textLength;
		var selStart = txtarea.selectionStart;
		var selEnd = txtarea.selectionEnd;
		var oldScrollTop = txtarea.scrollTop;
		//if (selEnd == 1 || selEnd == 2)
		//selEnd = selLength;
		var s1 = (txtarea.value).substring(0,selStart);
		var s2 = (txtarea.value).substring(selStart, selEnd)
		var s3 = (txtarea.value).substring(selEnd, selLength);
		txtarea.value = s1 + wrap1 + s2 + wrap2 + s3;
		txtarea.selectionStart = s1.length;
		txtarea.selectionEnd = s1.length + s2.length + wrap1.length + wrap2.length;
		txtarea.scrollTop = oldScrollTop;
		txtarea.focus();
		return;
	} else {
		insertText(elname, wrap1 + wrap2);
	}
}

function insertText(elname, what) {
	if (document.forms['inputform'].elements[elname].createTextRange) {
		document.forms['inputform'].elements[elname].focus();
		document.selection.createRange().duplicate().text = what;
	} else if ((typeof document.forms['inputform'].elements[elname].selectionStart) != 'undefined') { // for Mozilla
		var tarea = document.forms['inputform'].elements[elname];
		var selEnd = tarea.selectionEnd;
		var txtLen = tarea.value.length;
		var txtbefore = tarea.value.substring(0,selEnd);
		var txtafter =  tarea.value.substring(selEnd, txtLen);
		var oldScrollTop = tarea.scrollTop;
		tarea.value = txtbefore + what + txtafter;
		tarea.selectionStart = txtbefore.length + what.length;
		tarea.selectionEnd = txtbefore.length + what.length;
		tarea.scrollTop = oldScrollTop;
		tarea.focus();
	} else {
		document.forms['inputform'].elements[elname].value += what;
		document.forms['inputform'].elements[elname].focus();
	}
}

function insertMagnet(elname) {
	link=prompt('Введите magnet-ссылку:','');
	if (link=='') {
		alert('Вы ввели пустую ссылку!');
		return;
	}
	name=prompt('Введите наименование ссылки:','Новая ссылка');
	insertText(elname,'[magnet='+link+']'+name+'[/magnet]');
}

function insertURL(elname) {
	link=prompt('Введите URL-ссылку:','');
	if (link=='') {
		alert('Вы ввели пустую ссылку!');
		return;
	}
	name=prompt('Введите наименование ссылки:','Новая ссылка');
	insertText(elname,'[url='+link+']'+name+'[/url]');
}

function insertSize(elname) {
	link=prompt('Введите размер шрифта:','');
	if (link=='') {
		alert('Вы не ввели размер!');
		return;
	}
	name=prompt('Введите текст:','Новый текст');
	insertText(elname,'[size='+link+']'+name+'[/size]');
}


function show_hide(msg_id) {
	msg_id.style.display = msg_id.style.display == 'none' ? 'block' : 'none';
}

function doBlink() {
	var blink = document.all.tags("BLINK")
	for (var i=0; i<blink.length; i++)
		blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : "" 
}

function startBlink() {
	if (document.all)
		setInterval("doBlink()",500)
}
window.onload = startBlink;

//based on TinyMce color map plugin - modified by wooya
function showMapColor(color, mapId) {
    document.getElementById("selectedMapColor" + mapId).style.backgroundColor = color;
    document.getElementById("selectedMapColorBox" + mapId).value = color;
}

//based on TinyMce color map plugin - modified by wooya
function ColorMap(elname, formname) {
	var html = "";
	var colors = new Array(
	   "#000000","#000033","#000066","#000099","#0000cc","#0000ff","#330000","#330033",
	   "#330066","#330099","#3300cc","#3300ff","#660000","#660033","#660066","#660099",
	   "#6600cc","#6600ff","#990000","#990033","#990066","#990099","#9900cc","#9900ff",
	   "#cc0000","#cc0033","#cc0066","#cc0099","#cc00cc","#cc00ff","#ff0000","#ff0033",
	   "#ff0066","#ff0099","#ff00cc","#ff00ff","#003300","#003333","#003366","#003399",
	   "#0033cc","#0033ff","#333300","#333333","#333366","#333399","#3333cc","#3333ff",
	   "#663300","#663333","#663366","#663399","#6633cc","#6633ff","#993300","#993333",
	   "#993366","#993399","#9933cc","#9933ff","#cc3300","#cc3333","#cc3366","#cc3399",
	   "#cc33cc","#cc33ff","#ff3300","#ff3333","#ff3366","#ff3399","#ff33cc","#ff33ff",
	   "#006600","#006633","#006666","#006699","#0066cc","#0066ff","#336600","#336633",
	   "#336666","#336699","#3366cc","#3366ff","#666600","#666633","#666666","#666699",
	   "#6666cc","#6666ff","#996600","#996633","#996666","#996699","#9966cc","#9966ff",
	   "#cc6600","#cc6633","#cc6666","#cc6699","#cc66cc","#cc66ff","#ff6600","#ff6633",
	   "#ff6666","#ff6699","#ff66cc","#ff66ff","#009900","#009933","#009966","#009999",
	   "#0099cc","#0099ff","#339900","#339933","#339966","#339999","#3399cc","#3399ff",
	   "#669900","#669933","#669966","#669999","#6699cc","#6699ff","#999900","#999933",
	   "#999966","#999999","#9999cc","#9999ff","#cc9900","#cc9933","#cc9966","#cc9999",
	   "#cc99cc","#cc99ff","#ff9900","#ff9933","#ff9966","#ff9999","#ff99cc","#ff99ff",
	   "#00cc00","#00cc33","#00cc66","#00cc99","#00cccc","#00ccff","#33cc00","#33cc33",
	   "#33cc66","#33cc99","#33cccc","#33ccff","#66cc00","#66cc33","#66cc66","#66cc99",
	   "#66cccc","#66ccff","#99cc00","#99cc33","#99cc66","#99cc99","#99cccc","#99ccff",
	   "#cccc00","#cccc33","#cccc66","#cccc99","#cccccc","#ccccff","#ffcc00","#ffcc33",
	   "#ffcc66","#ffcc99","#ffcccc","#ffccff","#00ff00","#00ff33","#00ff66","#00ff99",
	   "#00ffcc","#00ffff","#33ff00","#33ff33","#33ff66","#33ff99","#33ffcc","#33ffff",
	   "#66ff00","#66ff33","#66ff66","#66ff99","#66ffcc","#66ffff","#99ff00","#99ff33",
	   "#99ff66","#99ff99","#99ffcc","#99ffff","#ccff00","#ccff33","#ccff66","#ccff99",
	   "#ccffcc","#ccffff","#ffff00","#ffff33","#ffff66","#ffff99","#ffffcc","#ffffff"
	);
	
	html += '<table border="0" cellspacing="1" cellpadding="0" class="tbl"><tr>';
	for (var i=0; i<colors.length; i++) {
	   if (formname == undefined) {
			html += "<td class='tbl1' style='width:10px;height:10px;cursor:crosshair;background-color:" + colors[i] + "' onClick=\"addText('" + elname + "', '[color=" + colors[i] + "]', '[/color]');\" onFocus=\"showMapColor('" + colors[i] +  "', '" + elname + "');\" onMouseOver=\"showMapColor('" + colors[i] + "', '" + elname + "');\">"
		} else {
			html += "<td class='tbl1' style='width:10px;height:10px;cursor:crosshair;background-color:" + colors[i] + "' onClick=\"addText('" + elname + "', '[color=" + colors[i] + "]', '[/color]', '" + formname + "');\" onFocus=\"showMapColor('" + colors[i] +  "', '" + elname + "');\" onMouseOver=\"showMapColor('" + colors[i] + "', '" + elname + "');\">"
		}
		html += '</td>';
		if ((i+1) % 18 == 0)	html += '</tr><tr>';
	}
	html += '<tr><td colspan="18">'
	+ '<table width="100%" border="0" cellspacing="0" cellpadding="0">'
	+ '<tr><td id="selectedMapColor' + elname + '" width="50%" height="16">'
	+ '</td><td width="50%">'
	+ '<input id="selectedMapColorBox' + elname + '" name="selectedMapColorBox' + elname + '" type="text" size="7" maxlength="7" style="text-align:center;font-weight:bold;width:100%" class="textbox" value="" />'
	+ '</td></tr>'
	+ '</table>'
	+ '</td></tr>'
	+ '</table>';

	document.write(html);
}

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=900,height=500,left = 190,top = 262');");
}