function insertAtCursor(myField, myValue, bbCode1, bbCode2, endOfLine) {
var bbb;
if(bbCode1=='[url=null]') { bbCode1=''; bbCode2=''; }
if(bbCode1=='[imgs]' && myValue==null) { bbCode1=''; bbCode2=''; myValue=''; }

if (document.selection) {
//IE support
var str = document.selection.createRange().text;
myField.focus();
sel = document.selection.createRange();
sel.text = bbCode1 + myValue + bbCode2 + endOfLine;
if(myValue=='') { bbb=bbCode2.length; sel.moveStart('character',-bbb); sel.moveEnd('character',-bbb); }
sel.select();
return;
}
//MOZILLA/NETSCAPE support
else if (myField.selectionStart || myField.selectionStart == '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
var bbb2, bbV;
if(myValue=='') myValue = myField.value.substring(startPos, endPos);
myField.value = myField.value.substring(0, startPos) + bbCode1 + myValue + bbCode2 + endOfLine + myField.value.substring(endPos, myField.value.length);
if(myValue=='') { bbb=bbCode1.length; myField.selectionStart=startPos+bbb; myField.selectionEnd=endPos+bbb; }
else { bbb=bbCode1.length; bbb2=bbCode2.length; bbV=myValue.length; myField.selectionStart=startPos+bbV+bbb+bbb2; myField.selectionEnd=startPos+bbV+bbb+bbb2; } 
myField.focus();
return;
} else {
myField.value += myValue;
return;
}
}

function paste_strinL(strinL, isQuote, bbCode1, bbCode2, endOfLine){ 
if((isQuote==1 || isQuote==2) && strinL=='') alert(l_quoteMsgAlert);
else{
if (isQuote==1) {
bbCode1='[i]'; bbCode2='[/i]'; endOfLine='\n';
}
if (isQuote==2) {
bbCode1='[b]'; bbCode2='[/b]'; endOfLine='\n';
}
var isForm=document.forms["postMsg"];
if (isForm) {
var input=document.forms["postMsg"].elements["postText"];
insertAtCursor(input, strinL, bbCode1, bbCode2, endOfLine);
}
else alert(l_accessDenied);
}
}

function pasteSel() { 
if(document.getSelection) selection=document.getSelection(); 
else if(document.selection) selection=document.selection.createRange().text; 
else if(window.getSelection) selection=window.getSelection(); 
else selection=''; 
}
//preview 
function previewMessage(){
var modeChs;

window.open('', 'cWin2', 'resizable=yes, scrollbars=yes, width=500, height=300, top=0, left=300');
document.forms['postMsg'].target='cWin2';
document.forms['postMsg'].elements['prevForm'].value=1;
if(document.forms['postMsg'].elements['mode']) {
document.forms['postMsg'].elements['mode'].value='';
modeChs=true;
}
var prevEnc=document.forms['postMsg'].encoding;
if(prevEnc=='multipart/form-data') document.forms['postMsg'].encoding='application/x-www-form-urlencoded';
document.forms['postMsg'].submit();
document.forms['postMsg'].target='_self';
if(prevEnc=='multipart/form-data') document.forms['postMsg'].encoding=prevEnc;
document.forms['postMsg'].elements['prevForm'].value=0;
if(modeChs) document.forms['postMsg'].elements['mode'].value='login';
return;
}
//disable anonymous postings solution //
var names=new Array('anon', 'guest', '@', '.com', '.net', 'org');

function checkIt(){
var ret=true;
var pf=document.forms['postMsg'];
var nLow, sLow, a;

if (pf.elements['user_usr']!=undefined){
if (pf.elements['user_usr'].value.length>2 && pf.elements['user_usr'].value.length<15){

var nLn=names.length;
strL=pf.elements['user_usr'].value.length;
sLow=pf.elements['user_usr'].value.toLowerCase();

for (var i=0; i<nLn; i++){

nLnL=names[i].length; 
nLow=names[i].toLowerCase(); 

if(nLnL>strL) {}
else{

if(sLow.indexOf(nLow)>=0) {
ret=false;
break;
}

}

}

}
else ret=false;
}
if(!ret) {
alert('Noredami dalyvauti diskusijoje prasome irasyti savo slapyvardi');
pf.elements['user_usr'].focus();
}
return ret;
}
// eof disable anonymous postings solution //
//eof preview
