 	/***************************************************\
	**   DatsoGallery - A Joomla! Gallery Component    **
	**   Copyright (C) 2006-2008  by Andrey Datso      **
	**   Version    : 1.6                              **
	**   Homepage   : http://www.datso.fr              **
	**   License    : Copyright, don't distribute      **
	\***************************************************/

function dginit(){
	dgcomments=dginit.arguments;
	for(i=0;i<dgcomments.length;i++){
		var corps=document.body.innerHTML;
        var dgimgdir = 'components/com_datsogallery/images/bbcode/';
		html  = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
        html += "<tr>";
        html += "<td valign=\"top\">";
        html += "<img src="+dgimgdir+"text_bold.gif width=\"20\" height=\"20\" onclick=\"iserttag('b','"+dgcomments[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="+dgimgdir+"text_underline.gif width=\"20\" height=\"20\" onclick=\"iserttag('u','"+dgcomments[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="+dgimgdir+"text_italic.gif width=\"20\" height=\"20\" onclick=\"iserttag('i','"+dgcomments[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="+dgimgdir+"link_add.gif width=\"20\" height=\"20\" onclick=\"isertlink('"+dgcomments[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="+dgimgdir+"text_list.gif width=\"20\" height=\"20\" onclick=\"iserttag('list','"+dgcomments[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="+dgimgdir+"quote.gif width=\"20\" height=\"20\" onclick=\"iserttag('quote','"+dgcomments[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="+dgimgdir+"smile.gif width=\"20\" height=\"20\" onclick=\"emotions('[sm1]','"+dgcomments[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="+dgimgdir+"grin.gif width=\"20\" height=\"20\" onclick=\"emotions('[sm2]','"+dgcomments[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="+dgimgdir+"tongue.gif width=\"20\" height=\"20\" onclick=\"emotions('[sm3]','"+dgcomments[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="+dgimgdir+"wink.gif width=\"20\" height=\"20\" onclick=\"emotions('[sm4]','"+dgcomments[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="+dgimgdir+"waii.gif width=\"20\" height=\"20\" onclick=\"emotions('[sm5]','"+dgcomments[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="+dgimgdir+"unhappy.gif width=\"20\" height=\"20\" onclick=\"emotions('[sm6]','"+dgcomments[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="+dgimgdir+"surprised.gif width=\"20\" height=\"20\" onclick=\"emotions('[sm7]','"+dgcomments[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 += "<td valign=\"top\">";
        html += "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
        html += "<tr>";
        html += "<td style=\"padding:0;margin:0\">";
        html += "<img src="+dgimgdir+"bullet_toggle_minus.gif width=\"20\" height=\"9\"  onclick=\"dgtminus('"+dgcomments[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=\"Reduce Textarea\">";
        html += "</td>";
        html += "</tr>";
        html += "<tr>";
        html += "<td style=\"padding:1px 0 1px 0;margin:0\">";
        html += "<img src="+dgimgdir+"bullet_toggle_plus.gif width=\"20\" height=\"9\" id=\"plus\"  onclick=\"dgtplus('"+dgcomments[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=\"Increase Textarea\">";
        html += "</td>";
        html += "</tr>";
        html += "</table>";
        html += "</td>";
        html += "</tr>";
        html += "</table>";
        html += "<textarea style=\"padding:0;margin:0\" name=\""+dgcomments[i]+"\" cols=\"55\" rows=\"5\" id=\""+dgcomments[i]+"\">";

        dgown="<textarea+[^>]*"+dgcomments[i]+"+[^<]+";
		dgowner = new RegExp(dgown,"i");
		coincidences=new Array();
		coincidences=corps.match(dgowner);
		if (coincidences != null) {
		for(j=0;j<coincidences.length;j++){
			result=new Array();
			result=coincidences[j].match(/\s+id=[^>\s]+/g);
			result[0]=result[0].split('"').join('');
			result[0]=result[0].split('id=').join(''); 
			result[0]=result[0].split(' ').join('');
			if(result[0]==dgcomments[i]){
				value = new Array();
				value2 = '';
				value = coincidences[j].split('>');
				if(value.length>1){
						for(k=1; k<value.length; k++){
							value2+=value[k];
						}
					}
				corps2=corps.split(coincidences[j]);
			}
		}
		document.body.innerHTML=corps2[0]+html+value2+corps2[1];
		}
	}
}
function iserttag(tag,dgc){
	var input = document.getElementById(dgc);
		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(dgc){
	var input = document.getElementById(dgc);
		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(dgc) {
    var input = document.getElementById(dgc);
    var my_mail = prompt("Add EMAIL:","");
    if (my_mail != "") {
	input.value+=" [email]" + my_mail + "[/email]";
    return;
    }
}

function insertlist(dgc) {
    var input = document.getElementById(dgc);
    var my_list = prompt("Add LIST:","");
    if (my_list != "") {
	input.value+=" [list]" + my_list + "[/list]";
    return;
    }
}

var reng=5;

function dgtplus(area){
	document.getElementById('plus').disabled=false;
	reng=reng+5;
	document.getElementById(area).rows=reng;
}
function dgtminus(area){
	reng=reng-5;
		if(reng<6){reng=5;
		}
	document.getElementById(area).rows=reng;
}
function emotions(s){
    document.commentform.cmttext.value = document.commentform.cmttext.value+s;
    document.commentform.cmttext.focus();
}
