/*
========================================
===> [ Copyright © Swarm Media Ltd ] <==
========> All rights reserved. <========
========================================
#::- This code was written by Swarm -::#
========================================
====> RETAIN THIS COPYRIGHT NOTICE! <===
=======> http://www.swarmuk.com <=======
========================================
*/

function incHeight(elementid){
	myheight = parseInt(document.getElementById(elementid).style.height);
	if (myheight < 1000){
		document.getElementById(elementid).style.height = (myheight + 100) + "px";
	}
}

function decHeight(elementid){
	myheight = parseInt(document.getElementById(elementid).style.height);
	if (myheight > 100){
		document.getElementById(elementid).style.height = (myheight - 100) + "px";
	}
}

function divToggle(id) {
	var e = document.getElementById(id);
	if(e.style.display == 'block') {
		e.style.display = 'none';
	} else {
		e.style.display = 'block';
	}
}

function divScrollToggle(id) {
	var e = document.getElementById(id);
	if(e.style.overflow == 'auto') {
		e.style.overflow = 'hidden';
	} else {
		e.style.overflow = 'auto';
	}
}

function divShow(id) {
	var e = document.getElementById(id);
	e.style.display = 'block';
}

function divHide(id) {
	var e = document.getElementById(id);
	e.style.display = 'none';
}

function btnShow(id) {
	var e = document.getElementById(id);
	e.style.display = 'inline';
}

function btnHide(id) {
	var e = document.getElementById(id);
	e.style.display = 'none';
}

function checkBox(id) {
	var e = document.getElementById(id);
	e.checked = 'true';
}

function confirmMsgBox(message) {
	var response = confirm(message);

	if (response) {
		return true;
	} else {
		return false;
	}
}

function addTag(tag, field_name) {
	field=document.getElementById(field_name);

	if(tag=='b' || tag=='i' || tag=='u' || tag == 'php' || tag == 'code') {

		if (document.selection) {
			field.focus();
			var selected = document.selection.createRange().text;
			sel = document.selection.createRange();
			sel.text = '[' + tag + ']' + selected + '[/' + tag+']';

		// MOZILLA/NETSCAPE/SAFARI support
		} else if (field.selectionStart || field.selectionStart == 0) {
			var startPos = field.selectionStart;
			var endPos = field.selectionEnd;
			var selected = field.value.substring(startPos, endPos);
			field.focus();
			//field.value = field.value.substring(0, startPos) + '[' + tag + '][/' + tag +']' + field.value.substring(endPos, field.value.length);
			field.value = field.value.substring(0, startPos) + '[' + tag + ']' + selected + '[/' + tag +']' + field.value.substring(endPos, field.value.length);

		}

	} else if(tag == 'img') {
		var path = prompt('Enter image path', 'http://');

		if(!path) {
			return;
		}

		if (document.selection) {
			field.focus();
			sel = document.selection.createRange();
			sel.text = '[' + tag + ']' + path + '[/' + tag+']';

		// MOZILLA/NETSCAPE/SAFARI support
		} else if (field.selectionStart || field.selectionStart == 0) {
			var startPos = field.selectionStart;
			var endPos = field.selectionEnd;
			field.focus();
			field.value = field.value.substring(0, startPos)
			+ '[' + tag + ']' + path + '[/' + tag+']'
			+ field.value.substring(endPos, field.value.length);

		}

	} else if(tag == 'url') {

		var url = prompt('Enter link URL', 'http://');
		var linkText = prompt('Enter link text', '');

		if(!url || !linkText) {
			return;
		}

		if (document.selection) {
			field.focus();
			sel = document.selection.createRange();
			sel.text = '[' + tag + '='+url+']' + linkText + '[/' + tag+']';

		// MOZILLA/NETSCAPE/SAFARI support
		} else if (field.selectionStart || field.selectionStart == 0) {
			var startPos = field.selectionStart;
			var endPos = field.selectionEnd;
			field.focus();
			field.value = field.value.substring(0, startPos)
			+ '[' + tag + '='+url+']' + linkText + '[/' + tag+']'
			+ field.value.substring(endPos, field.value.length);

		}

	}

}
