//--------------------------------------------------------------------------------------------------------
//  utility
//--------------------------------------------------------------------------------------------------------

var d = document;

function hide(divH){
	d.getElementById(divH).style.display = 'none';
}
function show(divS){
	d.getElementById(divS).style.display = 'block';
}

function init(){
	if (!document.getElementsByTagName){ return; }
	var buttons = document.getElementsByTagName("input");

	// loop through all div tags
	for (var i=0; i<buttons.length; i++){
		var objButton =buttons[i];

		if (objButton.type == "submit"){ 
			objButton.onclick = function () {this.value='loading...'}
		}
	}

}
	
window.onload = function(){
	init();
}



//--------------------------------------------------------------------------------------------------------
//  text format
//--------------------------------------------------------------------------------------------------------

var id = 'textarea';

function erase(){
	d.getElementById(id).value = "";
}

function title(){
	var txt= prompt('Insert title', '');
	var oldTxt = d.getElementById(id).value;
	var newTxt = oldTxt + '[title]' + txt + '[/title] ';
	if (( txt !=' ' ) && (txt != null)){ 
		d.getElementById(id).value = newTxt;
		}
}

function subTitle(){
	var txt= prompt('Insert subTitle', '');
	var oldTxt = d.getElementById(id).value;
	var newTxt = oldTxt + '[subTitle]' + txt + '[/subTitle] ';
	if (( txt !=' ' ) && (txt != null)){ 
		d.getElementById(id).value = newTxt;
		}
}

function bold(){
	var txt= prompt('Insert bold text', '');
	var oldTxt = d.getElementById(id).value;
	var newTxt = oldTxt + '[b]' + txt + '[/b] ';
	if (( txt !=' ' ) && (txt != null)){ 
		d.getElementById(id).value = newTxt;
		}
}

function underlined(){
	var txt= prompt('Insert underlined text', '');
	var oldTxt = d.getElementById(id).value;
	var newTxt = oldTxt + '[u]' + txt + '[/u] ';
	if ( (txt != ' ') && (txt != null) ) { 
		d.getElementById(id).value = newTxt;
		}
}

function italic(){
	var txt= prompt('Insert italic text', '');
	var oldTxt = d.getElementById(id).value;
	var newTxt = oldTxt + '[i]' + txt + '[/i] ';
	if ( (txt != ' ') && (txt != null) ) { 
		d.getElementById(id).value = newTxt;
		}
}

function link(){
	var aUrl = prompt('Insert the link Url', 'http://');
	var txt = prompt('Insert link text', '');
	var target = window.confirm("Open in a new window?");
	if (target) target = '_blank'; 
	else target = '_self'; 
	var oldTxt = d.getElementById(id).value;
	var newTxt = oldTxt + '[link=' + aUrl + ' target=' + target + ']' + txt + '[/link] ';
	if ( (txt != ' ') && (txt != null) ) { 
		d.getElementById(id).value = newTxt;
		}
}

function img(){
	var txt = prompt('Insert image', 'db/images/...');
	var oldTxt = d.getElementById(id).value;
	var newTxt = oldTxt + '[img='+ txt + ']';
	if ( (txt != ' ') && (txt != null) ) { 
		d.getElementById(id).value = newTxt;
		}
}

function imgBox(){
	var aUrl = prompt('Insert image name', '');
	var num = prompt('How much?', '');
	var oldTxt = d.getElementById(id).value;
	var newTxt = oldTxt + '[imgBox='+ aUrl + ' num=' + num + '] ';
	if ( (num != ' ') && (num != null) && (aUrl != ' ') && (aUrl != null)) { 
		d.getElementById(id).value = newTxt;
		}
}

function addImg(obj){
	var oldImg = d.getElementById(id).value;
	var newImg = oldImg + '[img=db/images/'+ obj.value + ']';
	d.getElementById(id).value = newImg;
}

function addPageLink(obj){
	d.getElementById('url').value = 'page.php?q=' + obj.value;
}
function del(){ 
	var handle = confirm("really want to delete?");
	if(handle) return true;
	else return false;
}