/*
	JS functions to create bbcode
###################################################################
#  myBTMBlog v 1
###################################################################
#  Web Developer -- BY THE MOON
#  Author/Design -- Dara Pressley dara@bythemoon.com
#  Copyright © 2004 Dara Pressley
###################################################################
*/
function NewWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function createList(){
	type = window.prompt("Enter 1 for numbered list, 2 for alpha list, 3 for roman numerals, or leave blank for bullets", "");
	if(type == 1){
		tag1 = '[ol1]';
		tag2 = '[/ol]';
	}
	if(type == 2){
		tag1 = '[ol2]';
		tag2 = '[/ol]';
	}
	if(type == 3){
		tag1 = '[ol3]';
		tag2 = '[/ol]';
	}
	if(type == ""){
		tag1 = '[ul]';
		tag2 = '[/ul]';
	}
	var cache = document.blog.text.value;
	var blah = 1;
	var x = new Array();
	var i = 0;
	while((blah!=null) && (blah!="")){
		blah = window.prompt("Enter Text \nleave blank to exit or cancel","")
		x[i++] = "[li]" + blah + "[/li]\n"
	}
	
	document.blog.text.value =  cache + tag1 + '\n';
	for(i=0;i<x.length-1;i++){
	//tag += x[i];
		document.blog.text.value += x[i];
	}
	document.blog.text.value += tag2 ;
}

function writeLink(){
	url = window.prompt('Enter the full url', 'http://');
	text = window.prompt('Enter link text (optional)','');
	target = window.prompt('Enter 1 to open in new window,\n 2 to open in parent frame,\n or leave blank','');
	var cache = document.blog.text.value;
	if(target == 1){
		if(text == ""){
			text = url;
		}
		code = ' [url target=_blank href=' + url +  ']' + text + '[/url]';
	}
	else if(target == 2){
		if(text == ""){
			text = url;
		}
		code = ' [url target=_parent href=' + url +  ']' + text + '[/url]';
	} else if(text == ""){
		code = ' [url]' + url + '[/url]';
	}  else {
		code = ' [url=' + url +  ']' + text + '[/url]';
	}
	document.blog.text.value = cache + code;
	document.blog.text.focus();
	
}

function writeEmail(){
	email = window.prompt('Enter email address', '');
	text = window.prompt('Enter email text (optional)', '');
	var cache = document.blog.text.value;
	if(text == ""){
		code = ' [email]' + email +  '[/email]';
	} else {
		code = ' [email=' + email + ']' + text + '[/email]';
	}
	document.blog.text.value = cache + code;
	document.blog.text.focus();
}

function writeCode(tag){
	var cache = document.blog.text.value;
	this.tag = tag;
	if(tag == "code"){
		type = window.prompt('Code Type', '');
	} else {
		type = tag;
	}
	text = window.prompt('Enter Text', '');
	code = ' [code=' + type + ']' + text + '[/code]';
	document.blog.text.value = cache + code;
	document.blog.text.focus();
}

function writeColor(){
	text = window.prompt('Enter text','');
	var cache = document.blog.text.value;
	var obj = document.bbcodeform.color;
	var sel = obj.selectedIndex;
	color = obj.options[sel].value;
	code = ' [color=' + color + ']' + text + '[/color]';
	document.blog.text.value = cache + code;
	document.blog.text.focus();
}

function writeSize(){
	text = window.prompt('Enter text','');
	var cache = document.blog.text.value;
	var obj = document.bbcodeform.size;
	var sel = obj.selectedIndex;
	size = obj.options[sel].value;
	code = ' [size=' + size + ']' + text + '[/size]';
	document.blog.text.value = cache + code;
	document.blog.text.focus();
}

function writeFont(){
	text = window.prompt('Enter text','');
	var cache = document.blog.text.value;
	var obj = document.bbcodeform.font;
	var sel = obj.selectedIndex;
	font = obj.options[sel].value;
	code = ' [font=' + font + ']' + text + '[/font]';
	document.blog.text.value = cache + code;
	document.blog.text.focus();
}

function writeText(tag){
	text = window.prompt('Enter text', '');
	var cache = document.blog.text.value;
	this.tag = tag;
	code = '[' + tag + ']' + text + '[/' + tag +']';
	document.blog.text.value = cache + code;
	document.blog.text.focus();
}

function writeFloat(tag){
	text = window.prompt('Enter text', '');
	var cache = document.blog.text.value;
	this.tag = tag;
	code = '[float=' + tag + ']' + text + '[/float]';
	document.blog.text.value = cache + code;
	document.blog.text.focus();
}

function writeSmiley(tag){
	var cache = document.blog.text.value;
	this.tag = tag;
	document.blog.text.value = cache + tag;
	document.blog.text.focus();
}

function writeFlickr(){
	link = window.prompt('Enter album name', '');
	image = window.prompt('Enter Flickr url of image', 'http://static.flickr.com/');
	var cache = document.blog.text.value;
	code = '[flickr img=' + image + ' link=' + link + ']';
	document.blog.text.value = cache + code;
	document.blog.text.focus();
}