function initCmtBox(){
	sgcomments=initCmtBox.arguments;
	var sgimgdir = sg_livesite+'components/com_simgallery/images/bbcode/';
	for(i=0;i<sgcomments.length;i++){
		var corps=document.body.innerHTML;
		html  = "<table id=\"bbcode_table\">";
        html += "<tr>";
        html += "<td valign=\"bottom\">";
        html += "<img src="+sgimgdir+"text_bold.gif width=\"20\" height=\"20\" onclick=\"iserttag('b','"+sgcomments[i]+"')\" onmouseover=\"this.style.border='solid 1px #DCDCDC';this.style.background='#FFFFE0'\"; onmouseout=\"this.style.border='solid 1px #EEEEEE';this.style.background='#fff'\" style=\"border:solid 1px #EEEEEE;background:#fff\" title=\"Tag Text Bold\">&nbsp;";
        html += "<img src="+sgimgdir+"text_underline.gif width=\"20\" height=\"20\" onclick=\"iserttag('u','"+sgcomments[i]+"')\" onmouseover=\"this.style.border='solid 1px #DCDCDC';this.style.background='#FFFFE0'\" onmouseout=\"this.style.border='solid 1px #EEEEEE';this.style.background='#fff'\" style=\"border:solid 1px #EEEEEE;background:#fff\" title=\"Tag Text Underline\">&nbsp;";
        html += "<img src="+sgimgdir+"text_italic.gif width=\"20\" height=\"20\" onclick=\"iserttag('i','"+sgcomments[i]+"')\" onmouseover=\"this.style.border='solid 1px #DCDCDC';this.style.background='#FFFFE0'\" onmouseout=\"this.style.border='solid 1px #EEEEEE';this.style.background='#fff'\" style=\"border:solid 1px #EEEEEE;background:#fff\" title=\"Tag Text Italic\">&nbsp;";
        html += "<img src="+sgimgdir+"link_add.gif width=\"20\" height=\"20\" onclick=\"isertlink('"+sgcomments[i]+"')\" onmouseover=\"this.style.border='solid 1px #DCDCDC';this.style.background='#FFFFE0'\" onmouseout=\"this.style.border='solid 1px #EEEEEE';this.style.background='#fff'\" style=\"border:solid 1px #EEEEEE;background:#fff\" title=\"Add Link\">&nbsp;";
        html += "<img src="+sgimgdir+"text_list.gif width=\"20\" height=\"20\" onclick=\"iserttag('list','"+sgcomments[i]+"')\" onmouseover=\"this.style.border='solid 1px #DCDCDC';this.style.background='#FFFFE0'\" onmouseout=\"this.style.border='solid 1px #EEEEEE';this.style.background='#fff'\" style=\"border:solid 1px #EEEEEE;background:#fff\" title=\"Tag Text List\" />&nbsp;";
        html += "<img src="+sgimgdir+"quote.gif width=\"20\" height=\"20\" onclick=\"iserttag('quote','"+sgcomments[i]+"')\" onmouseover=\"this.style.border='solid 1px #DCDCDC';this.style.background='#FFFFE0'\" onmouseout=\"this.style.border='solid 1px #EEEEEE';this.style.background='#fff'\" style=\"border:solid 1px #EEEEEE;background:#fff\" title=\"Tag Quote\">&nbsp;";
        html += "<img src="+sgimgdir+"smile.gif width=\"20\" height=\"20\" onclick=\"emotions(':)','"+sgcomments[i]+"')\" onmouseover=\"this.style.border='solid 1px #DCDCDC';this.style.background='#FFFFE0'\" onmouseout=\"this.style.border='solid 1px #EEEEEE';this.style.background='#fff'\" style=\"border:solid 1px #EEEEEE;background:#fff\" title=\"Emoticon Smile\">&nbsp;";
        html += "<img src="+sgimgdir+"grin.gif width=\"20\" height=\"20\" onclick=\"emotions(':D','"+sgcomments[i]+"')\" onmouseover=\"this.style.border='solid 1px #DCDCDC';this.style.background='#FFFFE0'\" onmouseout=\"this.style.border='solid 1px #EEEEEE';this.style.background='#fff'\" style=\"border:solid 1px #EEEEEE;background:#fff\" title=\"Emoticon Grin\">&nbsp;";
        html += "<img src="+sgimgdir+"tongue.gif width=\"20\" height=\"20\" onclick=\"emotions(':P','"+sgcomments[i]+"')\" onmouseover=\"this.style.border='solid 1px #DCDCDC';this.style.background='#FFFFE0'\" onmouseout=\"this.style.border='solid 1px #EEEEEE';this.style.background='#fff'\" style=\"border:solid 1px #EEEEEE;background:#fff\" title=\"Emoticon Tongue\">&nbsp;";
        html += "<img src="+sgimgdir+"wink.gif width=\"20\" height=\"20\" onclick=\"emotions(';D','"+sgcomments[i]+"')\" onmouseover=\"this.style.border='solid 1px #DCDCDC';this.style.background='#FFFFE0'\" onmouseout=\"this.style.border='solid 1px #EEEEEE';this.style.background='#fff'\" style=\"border:solid 1px #EEEEEE;background:#fff\" title=\"Emoticon Wink\">&nbsp;";
        html += "<img src="+sgimgdir+"waii.gif width=\"20\" height=\"20\" onclick=\"emotions(':}','"+sgcomments[i]+"')\" onmouseover=\"this.style.border='solid 1px #DCDCDC';this.style.background='#FFFFE0'\" onmouseout=\"this.style.border='solid 1px #EEEEEE';this.style.background='#fff'\" style=\"border:solid 1px #EEEEEE;background:#fff\" title=\"Emoticon Waii\">&nbsp;";
        html += "<img src="+sgimgdir+"unhappy.gif width=\"20\" height=\"20\" onclick=\"emotions(':(','"+sgcomments[i]+"')\" onmouseover=\"this.style.border='solid 1px #DCDCDC';this.style.background='#FFFFE0'\" onmouseout=\"this.style.border='solid 1px #EEEEEE';this.style.background='#fff'\" style=\"border:solid 1px #EEEEEE;background:#fff\" title=\"Emoticon Unhappy\">&nbsp;";
        html += "<img src="+sgimgdir+"surprised.gif width=\"20\" height=\"20\" onclick=\"emotions(':o','"+sgcomments[i]+"')\" onmouseover=\"this.style.border='solid 1px #DCDCDC';this.style.background='#FFFFE0'\" onmouseout=\"this.style.border='solid 1px #EEEEEE';this.style.background='#fff'\" style=\"border:solid 1px #EEEEEE;background:#fff\" title=\"Emoticon Surprised\">&nbsp;";
        html += "</td>";
        html += "</tr>";
        html += "</table>";
		document.getElementById('bbcode_div').innerHTML = html;
	}
}
function iserttag(tag,sgc){
	if ($('cmttext').hasClass('blurfield')) {
		$('cmttext').set('value', '');
		$('cmttext').removeClass('blurfield');
		$('flext-button-div').setStyle('display', 'block');
	}
	var input = document.getElementById(sgc);
		if(typeof document.selection != 'undefined' && document.selection) {
			var str = document.selection.createRange().text;
			input.focus();
			var sel = document.selection.createRange();
			sel.text = "[" + tag + "]" + str + "[/" +tag+ "]";
			sel.select();
			return;
		}
		else if(typeof input.selectionStart != 'undefined'){
				if(typeof input.scrollTop != 'undefined'){
					var st=input.scrollTop;
					var sl=input.scrollTop;
				}
			var start = input.selectionStart;
			var end = input.selectionEnd;
			var insText = input.value.substring(start, end);
			input.value = input.value.substr(0, start) + '['+tag+']' + insText + '[/'+tag+']'+ input.value.substr(end);
			input.focus();
			if(typeof input.scrollTop != 'undefined'){
					input.scrollTop=st;
					input.scrollTop=sl;
			}
			input.setSelectionRange(start+2+tag.length+insText.length+3+tag.length,start+2+tag.length+insText.length+3+tag.length);
			return;
		}
		else{
			input.value+=' ['+tag+']Replace this text[/'+tag+']';
			return;
		}
}
function isertlink(sgc){
	if ($('cmttext').hasClass('blurfield')) {
		$('cmttext').set('value', '');
		$('cmttext').removeClass('blurfield');
		$('flext-button-div').setStyle('display', 'block');
	}
	var input = document.getElementById(sgc);
		if(typeof document.selection != 'undefined' && document.selection) {
			var str = document.selection.createRange().text;
			input.focus();
			var my_link = prompt("Enter URL:","http://");
				if (my_link != null) {
					if(str.length==0){
						str=my_link;
					}
					var sel = document.selection.createRange();
					sel.text = "[url=" + my_link + "]" + str + "[/url]";
					sel.select();
					}
			return;
		}else if(typeof input.selectionStart != 'undefined'){
				if(typeof input.scrollTop != 'undefined'){
					var st=input.scrollTop;
					var sl=input.scrollTop;
				}		
					var start = input.selectionStart;
					var end = input.selectionEnd;
					var insText = input.value.substring(start, end);
					var my_link = prompt("Enter URL:","http://");
                    var my_text = prompt("Add description:","");
						if (my_link != null) {
							if(insText.length==0){
								insText=my_text;
							}
							input.value = input.value.substr(0, start) +"[url=" + my_link +"]" + insText  + "[/url]"+ input.value.substr(end);
							input.focus();
							if(typeof input.scrollTop != 'undefined'){
								input.scrollTop=st;
								input.scrollTop=sl;
							}
							input.setSelectionRange(start+11+my_link.length+insText.length+4,start+11+my_link.length+insText.length+4);
						}
			return;
		}else{
			var my_link = prompt("Add URL:","http://");
			var my_text = prompt("Add description:","");
			input.value+=" [url=" + my_link +  "]" + my_text + "[/url]";
			return;
		}
}

function insertemail(sgc) {
    var input = document.getElementById(sgc);
    var my_mail = prompt("Add EMAIL:","");
    if (my_mail != "") {
	input.value+=" [email]" + my_mail + "[/email]";
    return;
    }
}

function insertlist(sgc) {
    var input = document.getElementById(sgc);
    var my_list = prompt("Add LIST:","");
    if (my_list != "") {
	input.value+=" [list]" + my_list + "[/list]";
    return;
    }
}

var reng=5;

function sgtplus(area){
	document.getElementById('plus').disabled=false;
	reng=reng+5;
	document.getElementById(area).rows=reng;
}
function sgtminus(area){
	reng=reng-5;
		if(reng<6){reng=5;
		}
	document.getElementById(area).rows=reng;
}
function emotions(s){
	if ($('cmttext').hasClass('blurfield')) {
		$('cmttext').set('value', '');
		$('cmttext').removeClass('blurfield');
		$('flext-button-div').setStyle('display', 'block');
	}
    document.commentform.cmttext.value = document.commentform.cmttext.value+s;
    document.commentform.cmttext.focus();
}

