
function SubmitForm(formid)
{
	var tr = document.getElementById(formid);
	
	tr.submit();
}

function switch_panel(newpanel)
{	
	if( newpanel == lastshowedpanel ) return;
	
	var trn = document.getElementById(newpanel);
	var tro = document.getElementById(lastshowedpanel);
	
	if(tro) tro.style.display = "none";
	if(trn) trn.style.display = "";
	
	var trnm = document.getElementById(newpanel+"_panel");
	var trom = document.getElementById(lastshowedpanel+"_panel");
	
//	burl = getElementStyle(newpanel,'backgroundImage');
	
	//trnm.style.borderBottom = '1px solid #9FC6D9';
	//trnm.style.MozBorderImage = burl;	
	
	if(trnm) trnm.style.borderBottom = '1px solid #BBE0FB';
	if(trom) trom.style.borderBottom = "1px solid white";
	
	if(trnm) trnm.style.backgroundImage = 'url(http://ccl.hu/pics/tab.png)';
	if(trom) trom.style.backgroundImage = 'url(http://ccl.hu/pics/tab-tr.png)';

	if(trnm) trnm.style.textDecoration = "none";
	if(trom) trom.style.textDecoration = "underline";
	
	location.hash = "#"+newpanel.substring(5);
	
	lastshowedpanel = newpanel;
	
}

function ChangeSyntax(element,base)
{	
	//var stitle = element.options[element.selectedIndex].text;

	window.location.href = base + '/?syntax=' + element.value;
}

function php_urlencode (str) {
	str = escape(str);
	return str.replace(/[*+\/@]|%20/g,
		function (s) {
			switch (s) {
				case "*": s = "%2A"; break;
				case "+": s = "%2B"; break;
				case "/": s = "%2F"; break;
				case "@": s = "%40"; break;
				case "%20": s = "+"; break;
			}
			return s;
		}  );			
}


function incrementFS()
{
	var tr = document.getElementById('main_text_container');	
	var fs = parseInt(tr.style.fontSize);	
	var fsDefault = parseInt(Get_Cookie('text_fontsize'));	
	if ( fs < 8 || isNaN(fs) ) fs = fsDefault;	
	fs += 1;	
	if(fs > 24) fs = 24;	
	tr.style.fontSize = fs + 'px';	
	Set_Cookie('text_fontsize',fs,'/');
}

function decrementFS()
{
	var tr = document.getElementById('main_text_container');	
	var fs = parseInt(tr.style.fontSize);	
	var fsDefault = parseInt(Get_Cookie('text_fontsize'));	
	if ( fs < 8 || isNaN(fs) ) fs = fsDefault;	
	fs -= 1;	
	if(fs < 8) fs = 8;	
	tr.style.fontSize = fs + 'px';	
	Set_Cookie('text_fontsize',fs,'/');
}

function ChangeColor(element)
{
	var c = element.value;
	
	var contel = document.getElementById('main_text_container');
	
	contel.style.backgroundColor = c;
	
	Set_Cookie('text_bgcolor',c,'/');
}



function setSelectionRange(input, selectionStart, selectionEnd) {
 if (input.setSelectionRange) {
   input.focus();
   input.setSelectionRange(selectionStart, selectionEnd);
 }
 else if (input.createTextRange) {
   var range = input.createTextRange();
   range.collapse(true);
   range.moveEnd('character', selectionEnd);
   range.moveStart('character', selectionStart);
   range.select();
 }
}


/* Code contributed by Paul Brennan */
   
// replace the text area contents with original plus our new TAB
function replaceSelection (input, replaceString) {
   if (input.setSelectionRange) {
       var selectionStart = input.selectionStart;
       var selectionEnd = input.selectionEnd;
       input.value = input.value.substring(0, selectionStart)+replaceString + input.value.substring(selectionEnd);

       if (selectionStart != selectionEnd){
           setSelectionRange(input, selectionStart, selectionStart + replaceString.length);
       }else{
           setSelectionRange(input, selectionStart + replaceString.length, selectionStart + replaceString.length);
       }

   }else if (document.selection) {
       var range = document.selection.createRange();

       if (range.parentElement() == input) {
           var isCollapsed = range.text == '';
           range.text = replaceString;

            if (!isCollapsed)  {
               range.moveStart('character', -replaceString.length);
               range.select();
           }
       }
   }
}

// We are going to catch the TAB key so that we can use it
// edit by: skyboy.	 
function catchTab(item, e) {
    if (navigator.userAgent.match("Gecko")) {
        c = e.which;
    } else {
        c = e.keyCode;
    }
    if (c == 9) {
        var scrollCurrent = item.scrollTop;
        replaceSelection(item, String.fromCharCode(9));
        stopEvent(e);
        item.scrollTop = scrollCurrent;
        return false;
    }
}
function stopEvent(e) {
        if (e.preventDefault) {
            e.preventDefault();
        }
        if (e.stopPropagation) {
            e.stopPropagation();
        }
        e.stopped = true;
}

function show_text(id,isshow)
{
	var tr = document.getElementById(id);
	if (tr==null) { return; }	
	tr.style.display = (isshow ? '': 'none');
}


