// JavaScript Document



function emot(emot,field) {

var txtarea = document.getElementById(field);
var selStart = txtarea.selectionStart;
var selEnd = txtarea.selectionEnd;
var length = ((txtarea.value).substring(selStart, selEnd)).length;


	// IE
	if (document.selection) {

		var theSelection = document.selection.createRange().text;

	if (theSelection.length == 0) {



		if (!theSelection)
			theSelection=theSelection;
			txtarea.focus();
		if (theSelection.charAt(theSelection.length - 1) == " ") {
			theSelection = theSelection.substring(0, theSelection.length - 1);
			document.selection.createRange().text = ' ' + emot + ' ' + " ";
		} else {
			document.selection.createRange().text = ' ' + emot + ' ';
		}


	} else {
		alert('Nie możesz mieć zaznaczonego tekstu!');
	}

	// Mozilla
	} else if(txtarea.selectionStart || txtarea.selectionStart == '0') {

		if (length == 0) {


			document.getElementById(field).value = (txtarea.value).substring(0,selStart) + ' ' + emot + ' ' + (txtarea.value).			 					 			substring(selEnd,txtarea.value.length);


		} else {
			alert('Nie możesz mieć zaznaczonego tekstu!');
		}

	}


document.getElementById(field).focus();

}


















function Bold(id) {

var txtarea = document.getElementById(id);
var selStart = txtarea.selectionStart;
var selEnd = txtarea.selectionEnd;
var length = ((txtarea.value).substring(selStart, selEnd)).length;



	// IE
	if (document.selection) {

		var theSelection = document.selection.createRange().text;
	
	if (theSelection.length >= 1) {
		if (!theSelection)
			theSelection=theSelection;
			txtarea.focus();
		if (theSelection.charAt(theSelection.length - 1) == " ") {
			theSelection = theSelection.substring(0, theSelection.length - 1);
			document.selection.createRange().text = '[b]' + theSelection + '[/b]' + " ";
		} else {
			document.selection.createRange().text = '[b]' + theSelection + '[/b]';
		}
	
	} else {
		alert('Musisz zaznaczyć tekst!');
	}

	// Mozilla
	} else if(txtarea.selectionStart || txtarea.selectionStart == '0') {

		if (length >= 1) {
			document.getElementById(id).value = (txtarea.value).substring(0,selStart) + "[b]" +
			(txtarea.value).substring(selStart, selEnd) + "[/b]" + (txtarea.value).substring(selEnd,txtarea.value.length);
		} else {
			alert('Musisz zaznaczyc tekst!');
		}

	}


document.getElementById(id).focus();

}








function Underline(id) {

var txtarea = document.getElementById(id);
var selStart = txtarea.selectionStart;
var selEnd = txtarea.selectionEnd;
var length = ((txtarea.value).substring(selStart, selEnd)).length;



	// IE
	if (document.selection) {

		var theSelection = document.selection.createRange().text;
	
	if (theSelection.length >= 1) {
		if (!theSelection)
			theSelection=theSelection;
			txtarea.focus();
		if (theSelection.charAt(theSelection.length - 1) == " ") {
			theSelection = theSelection.substring(0, theSelection.length - 1);
			document.selection.createRange().text = '[u]' + theSelection + '[/u]' + " ";
		} else {
			document.selection.createRange().text = '[u]' + theSelection + '[/u]';
		}
	
	} else {
		alert('Musisz zaznaczyć tekst!');
	}

	// Mozilla
	} else if(txtarea.selectionStart || txtarea.selectionStart == '0') {

		if (length >= 1) {
			document.getElementById(id).value = (txtarea.value).substring(0,selStart) + "[u]" +
			(txtarea.value).substring(selStart, selEnd) + "[/u]" + (txtarea.value).substring(selEnd,txtarea.value.length);
		} else {
			alert('Musisz zaznaczyc tekst!');
		}

	}


document.getElementById(id).focus();

}










function Italics(id) {

var txtarea = document.getElementById(id);
var selStart = txtarea.selectionStart;
var selEnd = txtarea.selectionEnd;
var length = ((txtarea.value).substring(selStart, selEnd)).length;



	// IE
	if (document.selection) {

		var theSelection = document.selection.createRange().text;
	
	if (theSelection.length >= 1) {
		if (!theSelection)
			theSelection=theSelection;
			txtarea.focus();
		if (theSelection.charAt(theSelection.length - 1) == " ") {
			theSelection = theSelection.substring(0, theSelection.length - 1);
			document.selection.createRange().text = '[i]' + theSelection + '[/i]' + " ";
		} else {
			document.selection.createRange().text = '[i]' + theSelection + '[/i]';
		}
	
	} else {
		alert('Musisz zaznaczyć tekst!');
	}

	// Mozilla
	} else if(txtarea.selectionStart || txtarea.selectionStart == '0') {

		if (length >= 1) {
			document.getElementById(id).value = (txtarea.value).substring(0,selStart) + "[i]" +
			(txtarea.value).substring(selStart, selEnd) + "[/i]" + (txtarea.value).substring(selEnd,txtarea.value.length);
		} else {
			alert('Musisz zaznaczyc tekst!');
		}

	}


document.getElementById(id).focus();

}










function Url(id) {

var txtarea = document.getElementById(id);
var selStart = txtarea.selectionStart;
var selEnd = txtarea.selectionEnd;
var length = ((txtarea.value).substring(selStart, selEnd)).length;


	// IE
	if (document.selection) {

		var theSelection = document.selection.createRange().text;

	if (theSelection.length == 0) {

		var em1 = prompt('Podaj adres odsyłacza (bez http://):','');
		var em2 = prompt('Podaj treść odsyłacza:','');
		if (em1 != null && em1 != '' && em2 != null && em2 != '') {

			if (!theSelection)
				theSelection=theSelection;
				txtarea.focus();
			if (theSelection.charAt(theSelection.length - 1) == " ") {
				theSelection = theSelection.substring(0, theSelection.length - 1);
				document.selection.createRange().text = '[url=' + em1 + ']' + em2 + '[/url]' + " ";
			} else {
				document.selection.createRange().text = '[url=' + em1 + ']' + em2 + '[/url]';
			}

		} else {
			alert('Musisz podać dane do odsyłacza!');
		}

	} else {

		var em = prompt('Podaj adres odsyłacza (bez http://):','');
		if (em != null && em != '') {

			if (!theSelection)
				theSelection=theSelection;
				txtarea.focus();
			if (theSelection.charAt(theSelection.length - 1) == " ") {
				theSelection = theSelection.substring(0, theSelection.length - 1);
				document.selection.createRange().text = '[url=' + em + ']' + theSelection + '[/url]' + " ";
			} else {
				document.selection.createRange().text = '[url=' + em + ']' + theSelection + '[/url]';
			}

		} else {
			alert('Musisz podać dane do odsyłacza!');
		}

	}

	// Mozilla
	} else if(txtarea.selectionStart || txtarea.selectionStart == '0') {

		if (length == 0) {

		var em1 = prompt('Podaj adres odsyłacza (bez http://):','');
		var em2 = prompt('Podaj treść odsyłacza :','');
		if (em1 != null && em1 != '' && em2 != null && em2 != '') {
				document.getElementById(id).value = (txtarea.value).substring(0,selStart) + '[url=' + em1 + ']' + em2 + '[/url]' + (txtarea.value).substring(selEnd,txtarea.value.length);
			} else {
				alert('Musisz podać dane do odsyłacza!');
			}

		} else {

		var em = prompt('Podaj adres odsyłacza (bez http://):','');
		if (em != null && em != '') {
				document.getElementById(id).value = (txtarea.value).substring(0,selStart) + '[url=' + em + ']' + (txtarea.value).substring(selStart,selEnd) + '[/url]' + (txtarea.value).substring(selEnd,txtarea.value.length);
			} else {
				alert('Musisz podać adres odsyłacza!');
			}

		}

	}


document.getElementById(id).focus();

}











function Email(id) {

var txtarea = document.getElementById(id);
var selStart = txtarea.selectionStart;
var selEnd = txtarea.selectionEnd;
var length = ((txtarea.value).substring(selStart, selEnd)).length;


	// IE
	if (document.selection) {

		var theSelection = document.selection.createRange().text;

	if (theSelection.length == 0) {

		var em1 = prompt('Podaj adres e-mail:','');
		var em2 = prompt('Podaj opis odsyłacza pocztowego:','');
		if (em1 != null && em1 != '' && em2 != null && em2 != '') {

			if (!theSelection)
				theSelection=theSelection;
				txtarea.focus();
			if (theSelection.charAt(theSelection.length - 1) == " ") {
				theSelection = theSelection.substring(0, theSelection.length - 1);
				document.selection.createRange().text = '[email=' + em1 + ']' + em2 + '[/email]' + " ";
			} else {
				document.selection.createRange().text = '[email=' + em1 + ']' + em2 + '[/email]';
			}

		} else {
			alert('Musisz podać dane do odsyłacza pocztowego!');
		}

	} else {

		var em = prompt('Podaj adres e-mail:','');
		if (em != null && em != '') {

			if (!theSelection)
				theSelection=theSelection;
				txtarea.focus();
			if (theSelection.charAt(theSelection.length - 1) == " ") {
				theSelection = theSelection.substring(0, theSelection.length - 1);
				document.selection.createRange().text = '[email=' + em + ']' + theSelection + '[/email]' + " ";
			} else {
				document.selection.createRange().text = '[email=' + em + ']' + theSelection + '[/email]';
			}

		} else {
			alert('Musisz podać dane do odsyłacza pocztowego!');
		}

	}

	// Mozilla
	} else if(txtarea.selectionStart || txtarea.selectionStart == '0') {

		if (length == 0) {

		var em1 = prompt('Podaj adres e-mail:','');
		var em2 = prompt('Podaj opis odsyłacza pocztowego:','');
		if (em1 != null && em1 != '' && em2 != null && em2 != '') {
				document.getElementById(id).value = (txtarea.value).substring(0,selStart) + '[email=' + em1 + ']' + em2 + '[/email]' + (txtarea.value).substring(selEnd,txtarea.value.length);
			} else {
				alert('Musisz podać dane do odsyłacza pocztowego!');
			}

		} else {

		var em = prompt('Podaj adres e-mail:','');
		if (em != null && em != '') {
				document.getElementById(id).value = (txtarea.value).substring(0,selStart) + '[email=' + em + ']' + (txtarea.value).substring(selStart,selEnd) + '[/email]' + (txtarea.value).substring(selEnd,txtarea.value.length);
			} else {
				alert('Musisz podać dane do odsyłacza pocztowego!');
			}

		}

	}


document.getElementById(id).focus();

}










function Align(id,id2) {

var txtarea = document.getElementById(id);
var selStart = txtarea.selectionStart;
var selEnd = txtarea.selectionEnd;
var align = document.getElementById(id2).value;
var length = ((txtarea.value).substring(selStart, selEnd)).length;



	// IE
	if (document.selection) {

		var theSelection = document.selection.createRange().text;
	
	if (theSelection.length >= 1) {
		if (!theSelection)
			theSelection=theSelection;
			txtarea.focus();
		if (theSelection.charAt(theSelection.length - 1) == " ") {
			theSelection = theSelection.substring(0, theSelection.length - 1);
			document.selection.createRange().text = '[align=' + align + ']' + theSelection + '[/align]' + " ";
		} else {
			document.selection.createRange().text = '[align=' + align + ']' + theSelection + '[/align]';
		}
	
	} else {
		alert('Musisz zaznaczyć tekst!');
	}

	// Mozilla
	} else if(txtarea.selectionStart || txtarea.selectionStart == '0') {

		if (length >= 1) {
			document.getElementById(id).value = (txtarea.value).substring(0,selStart) + "[align=" + align + "]" +
			(txtarea.value).substring(selStart, selEnd) + "[/align]" + (txtarea.value).substring(selEnd,txtarea.value.length);
		} else {
			alert('Musisz zaznaczyc tekst!');
		}

	}

document.getElementById(id2).value='';
document.getElementById(id).focus();

}













function Color(id,id2) {

var txtarea = document.getElementById(id);
var selStart = txtarea.selectionStart;
var selEnd = txtarea.selectionEnd;
var color = document.getElementById(id2).value;
var length = ((txtarea.value).substring(selStart, selEnd)).length;



	// IE
	if (document.selection) {

		var theSelection = document.selection.createRange().text;
	
	if (theSelection.length >= 1) {
		if (!theSelection)
			theSelection=theSelection;
			txtarea.focus();
		if (theSelection.charAt(theSelection.length - 1) == " ") {
			theSelection = theSelection.substring(0, theSelection.length - 1);
			document.selection.createRange().text = '[color=' + color + ']' + theSelection + '[/color]' + " ";
		} else {
			document.selection.createRange().text = '[color=' + color + ']' + theSelection + '[/color]';
		}
	
	} else {
		alert('Musisz zaznaczyć tekst!');
	}

	// Mozilla
	} else if(txtarea.selectionStart || txtarea.selectionStart == '0') {

		if (length >= 1) {
			document.getElementById(id).value = (txtarea.value).substring(0,selStart) + "[color=" + color + "]" +
			(txtarea.value).substring(selStart, selEnd) + "[/color]" + (txtarea.value).substring(selEnd,txtarea.value.length);
		} else {
			alert('Musisz zaznaczyc tekst!');
		}

	}

document.getElementById(id2).value='';
document.getElementById(id).focus();

}