/* toggle share */
function toggle(){
	var div1 = document.getElementById('sharebuttons')

	if (div1.style.display == 'none') {
		div1.style.display = 'block'
	}
	else {
		div1.style.display = 'none'
	}
}
function lengthcounter(posttext, max) {
 if (posttext.value.length > max) {
	posttext.value = posttext.value.substring(0, max);
	alert('Viestin maksipituus on saavutettu');
 }
}
function quote(textarea, quotestring) {
	textarea.value = "[quote]"+ quotestring.replace(/\\n/g, String.fromCharCode(10)) + "[/quote]" + textarea.value + "\n\n";
    textarea.focus();
}

function tag(textarea, tag) {

	if(navigator.userAgent.toLowerCase().indexOf("gecko/") != -1){
        textarea.value = (textarea.value).substring(0, textarea.selectionStart) + "["+tag+"]" + (textarea.value).substring(textarea.selectionStart, textarea.selectionEnd) + "[/"+tag+"]" + (textarea.value).substring(textarea.selectionEnd, textarea.textLength);
	}
	else{
		((document.selection.createRange().parentElement().tagName == 'TEXTAREA')?selected = document.selection.createRange().text:selected = "")

		if(selected.length >1){	
			document.selection.createRange().text = "["+tag+"]"+selected+"[/"+tag+"]";	
		}
		else{ 
			textarea.value += "["+tag+"]" + selected + "[/"+tag+"]"; 
		}
	}
	textarea.focus()
	return;
}

