

var bodytext = "";
var clientPC = navigator.userAgent.toLowerCase(); 
var clientVer = parseInt(navigator.appVersion); 

var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
var is_nav = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1)
                && (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1)
                && (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1));
var is_moz = 0;

var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
var is_mac = (clientPC.indexOf("mac")!=-1);

function mozWrap(txtareat, open, close)
{
	var selLength = txtareat.textLength;
	var selStart = txtareat.selectionStart;
	var selEnd = txtareat.selectionEnd;
	if (selEnd == 1 || selEnd == 2)
		selEnd = selLength;

	var s1 = (txtareat.value).substring(0,selStart);
	var s2 = (txtareat.value).substring(selStart, selEnd)
	var s3 = (txtareat.value).substring(selEnd, selLength);
	txtareat.value = s1 + open + s2 + close + s3;
	return;
}


function setfocus() {
  document.postform.body.focus();
}

function addQuote() {
	if (document.postform.quote.value!="") {
		AddText(document.postform.quote.value);
		document.postform.quote.value = "";
	}
}

function getActiveText(selectedtext) {

	var dob = document.postform.body
	bodytext = (document.selection) ? document.selection.createRange().text : "";
	
	if (selectedtext.createTextRange) {
		selectedtext.caretPos = document.selection.createRange().duplicate();
	} 
	else if (dob.setSelectionRange) {
		bodytext = dob.value.substring(dob.selectionStart,dob.selectionEnd);
	} 
	
}

function AddText(NewCode) {
	var dob = document.postform.body;
	if (dob.createTextRange && dob.caretPos) {
		var caretPos = dob.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? NewCode + ' ' : NewCode;
	}
	else if (dob.setSelectionRange) {
		dob.value = dob.value.substring(0,dob.selectionStart) + NewCode + dob.value.substring(dob.selectionEnd,dob.value.length);
	}
	else {
		dob.value += NewCode;
	}
	setfocus();
	bodytext = "";
}



function bold() {
    //blackcodes start here
    var txtarea = document.postform.body;
    if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection) {
			
			document.selection.createRange().text = "[b]" + theSelection + "[/b]";
			txtarea.focus();
			theSelection = '';
			return;
		}
		else
		{
		AddTxt="[b]"+bodytext+"[/b]";
	    AddText(AddTxt);
		}
	}
	else //if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, "[b]", "[/b]");
		return;
	}
    //blackcodes ends here
	//AddTxt="[b]"+bodytext+"[/b]";
	//AddText(AddTxt);	
	
	
}
function dhtuber() {
	
	//blackcodes start here
    var txtarea = document.postform.body;
    if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection) {
			
			document.selection.createRange().text = "[DHTUBE=" + theSelection + "]";
			txtarea.focus();
			theSelection = '';
			return;
		}
		else
		{
		AddTxt="[DHTUBE="+bodytext+"]";
	    AddText(AddTxt);
		}
	}
	else //if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, "[DHTUBE=", "]");
		return;
	}
    //blackcodes ends here
	
	//AddTxt="[DHTUBE="+bodytext+"]";
	//AddText(AddTxt);
}
function dhvideo() {
	
	//blackcodes start here
    var txtarea = document.postform.body;
    if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection) {
			
			document.selection.createRange().text = "[DHVideo=" + theSelection + "]";
			txtarea.focus();
			theSelection = '';
			return;
		}
		else
		{
		AddTxt="[DHVideo="+bodytext+"]";
	    AddText(AddTxt);
		}
	}
	else //if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, "[DHVideo=", "]");
		return;
	}
    //blackcodes ends here
	
	//AddTxt="[DHVideo="+bodytext+"]";
	//AddText(AddTxt);
}
function italicize() {
	
	//blackcodes start here
    var txtarea = document.postform.body;
    if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection) {
			
			document.selection.createRange().text = "[i]" + theSelection + "[/i]";
			txtarea.focus();
			theSelection = '';
			return;
		}
		else
		{
		AddTxt="[i]"+bodytext+"[/i]";
	    AddText(AddTxt);
		}
	}
	else //if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, "[i]", "[/i]");
		return;
	}
    //blackcodes ends here
	
	//AddTxt="[i]"+bodytext+"[/i]";
	//AddText(AddTxt);
}

function underline() {
	
	//blackcodes start here
    var txtarea = document.postform.body;
    if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection) {
			
			document.selection.createRange().text = "[u]" + theSelection + "[/u]";
			txtarea.focus();
			theSelection = '';
			return;
		}
		else
		{
		AddTxt="[u]"+bodytext+"[/u]";
	    AddText(AddTxt);
		}
	}
	else //if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, "[u]", "[/u]");
		return;
	}
    //blackcodes ends here
	
	//AddTxt="[u]"+bodytext+"[/u]";
	//AddText(AddTxt);
}

function spoiler(randomint) {
	var randomic = "";
	for(i=1;i<=10;i++)
	{
	    randomic = randomic + Math.floor(Math.random() * 10)
	}
    var txtarea = document.postform.body;
    if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection) {
			
			document.selection.createRange().text = "[spoiler=" + randomic + "]" + theSelection + "[/spoiler]";
			txtarea.focus();
			theSelection = '';
			return;
		}
		else
		{
		AddTxt="[u]"+bodytext+"[/u]";
	    AddText(AddTxt);
		}
	}
	else
	{
		mozWrap(txtarea, "[spoiler=" + randomic + "]", "[/spoiler]");
		return;
	}
}

function quotte() {
    
    //blackcodes start here
    var txtarea = document.postform.body;
    if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection) {
			
			document.selection.createRange().text = "[quote]" + theSelection + "[/quote]";
			txtarea.focus();
			theSelection = '';
			return;
		}
		else
		{
		AddTxt="[quote]"+bodytext+"[/quote]";
	    AddText(AddTxt);
		}
	}
	else //if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, "[quote]", "[/quote]");
		return;
	}
    //blackcodes ends here

    
	//AddTxt="[quote]"+bodytext+"[/quote]";
	//AddText(AddTxt);
}

function showcolor(bs216) { //new changes in here
	//AddTxt="[color="+bs216+"]"+bodytext+"[/color]";
	//AddText(AddTxt);
	
	 //blackcodes start here
    var txtarea = document.postform.body;
    if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection) {
			
			document.selection.createRange().text = "[color="+bs216+"]" + theSelection + "[/color]";
			txtarea.focus();
			theSelection = '';
			return;
		}
		else
		{
		AddTxt="[color="+bs216+"]"+bodytext+"[/color]";
		AddText(AddTxt);
		}
	}
	else //if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, "[color="+bs216+"]", "[/color]");
		return;
	}
    //blackcodes ends here
	
}
/*
function hyperlink() {

     //blackcodes start here
    var txtarea = document.postform.body;
    if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection) {
			
			document.selection.createRange().text = "[link=]" + theSelection + "[/link]";
			txtarea.focus();
			theSelection = '';
			return;
		}
		else
		{
		AddTxt="[link=]"+bodytext+"[/link]";
	    AddText(AddTxt);
		}
	}
	else //if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, "[link=]", "[/link]");
		return;
	}
    //blackcodes ends here


	//AddTxt="[link=]"+bodytext+"[/link]";
	//AddText(AddTxt);
}
*/
function image() {

     //blackcodes start here
    var txtarea = document.postform.body;
    if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection) {
			
			document.selection.createRange().text = "[image]" + theSelection + "[/image]";
			txtarea.focus();
			theSelection = '';
			return;
		}
		else
		{
		AddTxt="[image]"+bodytext+"[/image]";
	    AddText(AddTxt);
		}
	}
	else //if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, "[image]", "[/image]");
		return;
	}
    //blackcodes ends here

	//AddTxt="[image]"+bodytext+"[/image]";
	//AddText(AddTxt);
}
function simage() {

     //blackcodes start here
    var txtarea = document.postform.body;
    if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection) {
			
			document.selection.createRange().text = "[simage]" + theSelection + "[/simage]";
			txtarea.focus();
			theSelection = '';
			return;
		}
		else
		{
		AddTxt="[simage]"+bodytext+"[/simage]";
	    AddText(AddTxt);
		}
	}
	else //if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, "[simage]", "[/simage]");
		return;
	}
    //blackcodes ends here

	//AddTxt="[simage]"+bodytext+"[/simage]";
	//AddText(AddTxt);
}
function showcode() {
      //blackcodes start here
    var txtarea = document.postform.body;
    if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection) {
			
			document.selection.createRange().text = "[code]" + theSelection + "[/code]";
			txtarea.focus();
			theSelection = '';
			return;
		}
		else
		{
		AddTxt="[code]"+bodytext+"[/code]";
	    AddText(AddTxt);
		}
	}
	else //if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, "[code]", "[/code]");
		return;
	}
    //blackcodes ends here


	//AddTxt="[code]"+bodytext+"[/code]";
	//AddText(AddTxt);
}

function list() {

      //blackcodes start here
    var txtarea = document.postform.body;
    if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection) {
			
			document.selection.createRange().text = "[ul]\r[*] " + theSelection + "\r[*] \r[*] \r[/ul]";
			txtarea.focus();
			theSelection = '';
			return;
		}
		else
		{
		AddTxt = "[ul]\r[*] "+bodytext+"\r[*] \r[*] \r[/ul]";
	    AddText(AddTxt);
		}
	}
	else //if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, "[ul]\r[*] ", "\r[*] \r[*] \r[/ul]");
		return;
	}
    //blackcodes ends here


	//AddTxt = "[ul]\r[*] "+bodytext+"\r[*] \r[*] \r[/ul]";
	//AddText(AddTxt);	
}

function changesize(s) {

    //blackcodes start here
    var txtarea = document.postform.body;
    if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection) {
			
			document.selection.createRange().text = "[size="+s+"]" + theSelection + "[/size]";
			txtarea.focus();
			theSelection = '';
			return;
		}
		else
		{
		AddTxt="[size="+s+"]"+bodytext+"[/size]";
	    AddText(AddTxt);
		}
	}
	else //if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, "[size="+s+"]", "[/size]");
		return;
	}
    //blackcodes ends here

	//AddTxt="[size="+s+"]"+bodytext+"[/size]";
	//AddText(AddTxt);
}

function adjustright() { 

    //blackcodes start here
    var txtarea = document.postform.body;
    if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection) {
			
			document.selection.createRange().text = "[right]" + theSelection + "[/right]";
			txtarea.focus();
			theSelection = '';
			return;
		}
		else
		{
		AddTxt="[right]"+bodytext+"[/right]"; 
	    AddText(AddTxt);
		}
	}
	else //if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, "[right]", "[/right]");
		return;
	}
    //blackcodes ends here

	//AddTxt="[right]"+bodytext+"[/right]"; 
	//AddText(AddTxt); 
} 

function adjustcenter() { 

    //blackcodes start here
    var txtarea = document.postform.body;
    if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection) {
			
			document.selection.createRange().text = "[center]" + theSelection + "[/center]";
			txtarea.focus();
			theSelection = '';
			return;
		}
		else
		{
		AddTxt="[center]"+bodytext+"[/center]"; 
	    AddText(AddTxt); 
		}
	}
	else //if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, "[center]", "[/center]");
		return;
	}
    //blackcodes ends here
    
	//AddTxt="[center]"+bodytext+"[/center]"; 
	//AddText(AddTxt); 
} 

function adjustleft() { 

    //blackcodes start here
    var txtarea = document.postform.body;
    if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection) {
			
			document.selection.createRange().text = "[left]" + theSelection + "[/left]";
			txtarea.focus();
			theSelection = '';
			return;
		}
		else
		{
		AddTxt="[left]"+bodytext+"[/left]"; 
	    AddText(AddTxt); 
		}
	}
	else //if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, "[left]", "[/left]");
		return;
	}
    //blackcodes ends here


	//AddTxt="[left]"+bodytext+"[/left]"; 
	//AddText(AddTxt); 
} 

/*
New changes starts here
*/

function fontface() {
	
	//blackcodes start here
    var txtarea = document.postform.body;
    if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection) {
			
			document.selection.createRange().text = "[font=\"\"]" + theSelection + "[/font]";
			txtarea.focus();
			theSelection = '';
			return;
		}
		else
		{
		AddTxt="[font=\"\"]"+bodytext+"[/font]"; 
	    AddText(AddTxt);
		}
	}
	else //if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, "[font=\"\"]", "[/font]");
		return;
	}
    //blackcodes ends here
	
	//AddTxt="[font=\"\"]"+bodytext+"[/font]"; 
	//AddText(AddTxt);
}

function embeding() {

//blackcodes start here
    var txtarea = document.postform.body;
    if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection) {
			
			document.selection.createRange().text = "[embed]" + theSelection + "[/embed]";
			txtarea.focus();
			theSelection = '';
			return;
		}
		else
		{
		AddTxt="[embed]"+bodytext+"[/embed]"; 
	    AddText(AddTxt);
		}
	}
	else //if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, "[embed]", "[/embed]");
		return;
	}
    //blackcodes ends here
	//AddTxt="[embed]"+bodytext+"[/embed]"; 
	//AddText(AddTxt);
}

function changeface(s) {

    //blackcodes start here
    var txtarea = document.postform.body;
    if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text;
		if (theSelection) {
			
			document.selection.createRange().text = "[font=\""+s+"\"]" + theSelection + "[/font]";
			txtarea.focus();
			theSelection = '';
			return;
		}
		else
		{
		AddTxt="[font=\""+s+"\"]"+bodytext+"[/font]";
	    AddText(AddTxt);
		}
	}
	else //if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, "[font=\""+s+"\"]", "[/font]");
		return;
	}
    //blackcodes ends here
    
	//AddTxt="[font=\""+s+"\"]"+bodytext+"[/font]";
	//AddText(AddTxt);
}

/*
Additional Helper functions - don't change below this line
*/

function changefontsize(s) {
	if (s.selectedIndex != 0) {
	changesize(s.options[s.selectedIndex].value);
	s.selectedIndex = 0;
	return false;
	}
}

function changefontface(s) {
	if (s.selectedIndex != 0) {
	changeface(s.options[s.selectedIndex].value);
	s.selectedIndex = 0;
	return false;
	}
}
