/*
#
# Copyright (C) 2007 BBCode Parser
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation;
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# contact:soemin.mark@gmail.com
#
*/

// bbcode parser start
function parseBBCodes(obj){
		for(var k=0; k<obj.length;k++){
				var tags=document.getElementsByTagName(obj[k].tname);
				for( var i=0; i < tags.length; i++){
						var tag = tags[i];
						var html = tag.innerHTML;
						var isOK = true;
						for(var tm in obj[k].tmatch){
								if( eval("/"+tm.addSlash()+"/gi").test(tag[tm]) ){
										isOK = false;break;
								}
						}
						if(isOK){
								for( var ts in obj[k].tset ) {
										var re = eval("/"+ts.addSlash()+"/gi");
										html = html.replace(re, obj[k].tset[ts]);
								}
								tag.innerHTML = html;
						}
				}
		}
}
//bbcode parser end

//add slash start
String.prototype.addSlash=function(){
	var ret="";
	for(var i=0;i < this.length;i++){
		if("\\^$*+?{}[]().:!=|-,/".indexOf(this.charAt(i))!=-1){
			ret +="\\"+this.charAt(i);
		}else{
			ret +=this.charAt(i);
		}
	}
	return ret;
};
//add slash end
