function check(uncheck){
el=document.getElementById('files_form');
for(i=0;i<el.elements.length;i++){
if(uncheck==0)
el.elements[i].checked=true;
else if(uncheck==1)
el.elements[i].checked=false;
}
}

function url(url){
frames['frame'].location=url;
}


function textarea_small(name, limit, html, style){
var html=(html==null)?'':html;
var style=(style==null)?'width:240px;height:50px;':style;
document.write('<textarea name="'+name+'" id="'+name+'" style="'+style+'" onkeydown="if(this.value.length>'+limit+')this.value=this.value.substring(0, '+limit+');">'+html+'</textarea>');
}

function parentRefresh(){
position=parent.document.URL.indexOf('#');
if(position>0)
parent.document.location=parent.document.URL.substring(0, position);
else
parent.document.location=parent.document.location;
}

///
function insert_text(open, close){
msgfield=document.getElementById('text');
// IE support
if (document.selection && document.selection.createRange){
msgfield.focus();
sel=document.selection.createRange();
sel.text=open + sel.text + close;
msgfield.focus();
}
// Moz support
else if (msgfield.selectionStart || msgfield.selectionStart == '0'){
var startPos=msgfield.selectionStart;
var endPos=msgfield.selectionEnd;


msgfield.value=msgfield.value.substring(0, startPos) + open + msgfield.value.substring(startPos, endPos) + close + msgfield.value.substring(endPos, msgfield.value.length);
msgfield.selectionStart=msgfield.selectionEnd=endPos + open.length + close.length;
msgfield.focus();
}
//Fallback support for other browsers
else{
msgfield.value+=open+close;
msgfield.focus();
}
}


function textarea(limit, html, more){
var html=(html==null)?'':html.replace(/\n /g, "\n");
var more=(more==null)?0:1;

document.write('<div class="editor" id="comment">');
document.write('<img src="img/editor/centre.gif" title="Tekstas centre" onclick="insert_text(\'<center>\',\'</center>\')" class="editorImg" onmousedown="this.className=\'editorImgDown\'" onmouseup="this.className=\'editorImg\'">');
document.write('<img src="img/editor/right.gif" title="Tekstas dešinėje" onclick="insert_text(\'<right>\',\'</right>\')" class="editorImg" onmousedown="this.className=\'editorImgDown\'" onmouseup="this.className=\'editorImg\'">');
document.write('<img src="img/editor/bold.gif" title="Paryškintas" onclick="insert_text(\'<b>\',\'</b>\')" class="editorImg" onmousedown="this.className=\'editorImgDown\'" onmouseup="this.className=\'editorImg\'">');
document.write('<img src="img/editor/italic.gif" title="Pakreiptas" onclick="insert_text(\'<i>\',\'</i>\')" class="editorImg" onmousedown="this.className=\'editorImgDown\'" onmouseup="this.className=\'editorImg\'">');
document.write('<img src="img/editor/underline.gif" title="Pabrauktas" onclick="insert_text(\'<u>\',\'</u>\')" class="editorImg" onmousedown="this.className=\'editorImgDown\'" onmouseup="this.className=\'editorImg\'">');
document.write('<img src="img/editor/strike.gif" title="Perbrauktas" onclick="insert_text(\'<s>\',\'</s>\')" class="editorImg" onmousedown="this.className=\'editorImgDown\'" onmouseup="this.className=\'editorImg\'">');
document.write('<img src="img/editor/hyperlink.gif" title="Nuoroda" onclick="insert_link()" class="editorImg" onmousedown="this.className=\'editorImgDown\'" onmouseup="this.className=\'editorImg\'">');
document.write('<img src="img/editor/image.gif" title="Paveikslėlis" onclick="insert_img()" class="editorImg" onmousedown="this.className=\'editorImgDown\'" onmouseup="this.className=\'editorImg\'">');
document.write('<img src="img/editor/flash.gif" title="Flash filmukas" onclick="showhide(\'flashDlg\')" class="editorImg" onmousedown="this.className=\'editorImgDown\'" onmouseup="this.className=\'editorImg\'">');
document.write('<img src="img/editor/quote.gif" title="Citata" onclick="insert_text(\'<q>\',\'</q>\')" class="editorImg" onmousedown="this.className=\'editorImgDown\'" onmouseup="this.className=\'editorImg\'">');

if(more==1)
document.write('<img src="img/editor/more.gif" title="Skirti tekstą" onclick="insert_text(\'[MORE]\', \'\')" class="editorImg" onmousedown="this.className=\'editorImgDown\'" onmouseup="this.className=\'editorImg\'">');

document.write(' <select onchange="if(this.value!=0)insert_text(\'<size=\'+this.value+\'>\', \'</size>\');" style="margin-bottom:5px">');
document.write('<option value="0">Dydis</option>');
document.write('<option value="1">Mažas</option>');
document.write('<option value="4">Didelis</option>');
document.write('<option value="6">Baisus</option></select>');

document.write('<div id="flashDlg" class="editor_win" style="display:none;width:250px;height:150px">Suvesk filmuko puslapyje gautą HTML kodą<br>');
document.write('<textarea id="flash_code" style="width:242px;height:100px"></textarea>');
document.write('<input type="button" class="button" onclick="insertFlash();showhide(\'flashDlg\');document.getElementById(\'flash_code\').value=\'\'" value="Įterpti"></div>');

document.write('<br />');
document.write('<textarea name="text" id="text" autocomplete="off" style="height:300px" onkeypress="document.getElementById(\'preview\').disabled=false;">'+html+'</textarea>');

document.write('<input type="submit" style="display:none" onclick="return false">');
document.write('<input type="submit" class="button" name="preview" id="preview" value="Pažiūrėti"></div>');
document.write('<div class="editor" id="prev_win" style="display:none;padding:3px;"></div>');
}

function insert_img(){
img=prompt('Įvesk paveikslėlio adresą', 'http://');
insert_text('<img src="'+img, '" />');
}

function insert_link(){
if(link=prompt('Įvesk nuorodą', 'http://')){
title='';
if((document.selection && document.selection.createRange().text=='') || (document.getElementById('text').selectionStart>0 && document.getElementById('text').selectionStart==document.getElementById('text').selectionEnd))
title=prompt('Įvesk antraštę', 'Nuroda');

insert_text('<a href="'+link+'">', title+'</a>');
}
else
return false;
}


function insertFlash(){
flash=document.getElementById('flash_code').value.match(/src="http:\/\/(.*?)"/);

insert_text('', '[flash]'+flash[1]+'[/flash]');
}

function showhide(element){
if(parent.document.getElementById(element).style.display=="none")
parent.document.getElementById(element).style.display="";
else
parent.document.getElementById(element).style.display="none";
}
