	/*
	written by Chris Wetherell
	http://www.massless.org
	chris [THE AT SIGN] massless.org
        Upravil a mirne opravil (IEWiev) Mab
	*/

	function mozWrap(txtarea, lft, rgt) {
		var selLength = txtarea.textLength;
		var selStart = txtarea.selectionStart;
		var selEnd = txtarea.selectionEnd;
		if (selEnd==1 || selEnd==2) selEnd=selLength;
		var s1 = (txtarea.value).substring(0,selStart);
		var s2 = (txtarea.value).substring(selStart, selEnd)
		var s3 = (txtarea.value).substring(selEnd, selLength);
		txtarea.value = s1 + lft + s2 + rgt + s3;
	}

	function IEWrap(txtarea, lft, rgt) {
		strSelection = document.selection.createRange().text;
                if (!strSelection) {strSelection="";}
		document.selection.createRange().text = lft + strSelection + rgt;
	}

	function wrapSelection(txtarea, lft, rgt) {
		if (document.all) {IEWrap(txtarea, lft, rgt);}
		else if (document.getElementById) {mozWrap(txtarea, lft, rgt);}
	}

	function wrapSelectionWithLink(txtarea) { // by se hodilo casem pouzit i tuto
		var my_link = prompt("Enter URL:","http://");
		if (my_link != null) {
			lft="<a href=\"" + my_link + "\">";
			rgt="</a>";
			wrapSelection(txtarea, lft, rgt);
		}
		return;
	}
	/* end Chris W. and Mab script */


function selall()
    {
        prisp = document.getElementById('i').value;
        for (x=1;x<=prisp;x++)
            {
                document.getElementById('x'+x).checked = 1;
            }
    }

function selnone()
    {
        prisp = document.getElementById('i').value;
        for (x=1;x<=prisp;x++)
            {
                document.getElementById('x'+x).checked = 0;
            }
    }

function selinv()
    {
        prisp = document.getElementById('i').value;
        for (x=1;x<=prisp;x++)
            {
                if (document.getElementById('x'+x).checked)
                    {
                        document.getElementById('x'+x).checked = 0;
                    }
                else
                    {
                        document.getElementById('x'+x).checked = 1;
                    }
            }
    }

function select_jump(xid,cesta)
    {
        qcx = document.getElementById(xid);
        if (qcx.options[qcx.selectedIndex].value != 0)
            {
                window.location=cesta+qcx.options[qcx.selectedIndex].value;
            }
    }

function insert_extra(xid,tag1,tag2)
    {
        pole = document.getElementById(xid);
        if (!tag2)          //   osetreni volani jen s jednim parametrem
            {
                tag2=tag1;  //   Zidane chtel, aby se pri vybranem textu...
                tag1="";    //    hazeli smajlici za ten vyber, tak prohodime.
            }
        if (pole)
            {
                pole.focus();
                wrapSelection(pole, tag1, tag2)
            }
    }

function insert_citace(xid,id_mess)
    {
        pole = document.getElementById(xid);
        if(pole)
            {
                citace = document.getElementById('prispevek_'+id_mess).value;
                pole.focus();
                pole.value += citace
            }
    }

function check_okno(text,kam)
    {
        if (confirm(text))
            {
                top.window.location=kam;
            }
    }

function fsset(selnr)
 {

    fsimg= document.getElementById('fs'+selnr).options[document.getElementById('fs'+selnr).selectedIndex].value;
    document.getElementById('img'+selnr).src = '_smiles/'+fsimg+'.gif';
}

function insert_xtra_opener(co,kam)
    {
        pole = window.opener.document.getElementById(kam);
        if(pole)
            {
                citace = window.opener.document.getElementById(kam).value;
                pole.focus();
                pole.value += co
                window.close();
            }
    }

function insert_xtra_opener_noclose(co,kam)
    {
        pole = window.opener.document.getElementById(kam);
        if(pole)
            {
                citace = window.opener.document.getElementById(kam).value;
                pole.focus();
                pole.value += co
            }
    }

function sirka_okna() {
   if (window.innerWidth)
      /* NN4 a kompatibilní prohlížeče */
      return window.innerWidth;
   else if
   (document.documentElement &&
   document.documentElement.clientWidth)
      /* MSIE6 v std. režimu - Opera a Mozilla
      již uspěly s window.innerHeight */
      return document.documentElement.clientWidth;
   else if
   (document.body && document.body.clientWidth)
      /* starší MSIE + MSIE6 v quirk režimu */
      return document.body.clientWidth;
   else
      return null;
}

function chngico()
 {
    chng_ico = document.getElementById("nast_ikona2").options[document.getElementById("nast_ikona2").selectedIndex].value;
    if (chng_ico=="") {chng_ico="default.gif";}
    document.getElementById("chng_ikona").src = '_icons/'+chng_ico;

 }

function tag_url(xid)
{
    var enterURL   = prompt("Zadejte celou adresu odkazu (např.: http://www.diskuzak.cz)", "http://");

    if (!enterURL) {
        enterURL = '';
    }
    else
        {
            var enterTITLE = prompt("Zadejte název odkazu (není nutno vyplňovat)", "");
            if (!enterTITLE) {
                enterTITLE = '';
            }

            if (enterTITLE == '') {
                insert_extra(xid,'(link,'+enterURL+')');
            }
            else {
                insert_extra(xid,'(link,'+enterURL+','+enterTITLE+')');
            }
        }
}

function tag_img(xid)
{
    var enterURL   = prompt("Zadejte celou adresu obrázku (např.: http://www.diskuzak.cz/logo.jpg)", "http://");

    if (!enterURL) {
        enterURL = '';
    }
    else
        {
            var enterURL_LINK = prompt("Zadejte celou adresu odkazu, má-li být obrázek zároveň odkazem (není nutno vyplňovat)", "");
            if (!enterURL_LINK) {
                enterURL_LINK = '';
            }

            if (enterURL_LINK == '') {
                insert_extra(xid,'(img,'+enterURL+')');
            }
            else {
                insert_extra(xid,'(img,'+enterURL+','+enterURL_LINK+')');
            }
        }
}



function PlayRadio(bitrate) {
  //window.open('http://www.abradio.cz/player.php?kod=175&quality=asx'+bitrate,'ABradio','width=395,height=250,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no');
  window.open('http://www.radio4u.cz/player4.php?bitrate='+bitrate,'Radio4U','width=468,height=290,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no');
}


function ajax(stranka, kam)
{

    var httpRequest;
    if(typeof window.ActiveXObject != 'undefined')
    {
        httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else
    {
        httpRequest = new XMLHttpRequest();
    }
    httpRequest.open("GET", stranka, true);
    httpRequest.onreadystatechange= function ()
    {
        processRequest(httpRequest, kam)
    };
    httpRequest.send(null);
}


function processRequest(httpRequest, kam)
{
    if (httpRequest.readyState == 4)
    {
        if(httpRequest.status == 200)
        {
            if (typeof kam == 'string')
            {
                document.getElementById(kam).innerHTML = httpRequest.responseText;
            }
            if (typeof kam == 'function')
            {
                kam(httpRequest.responseText);
            }
        }
        else
        {
            alert("Chyba pri nacitani stanky " + httpRequest.status +" : "+ httpRequest.statusText);
        }
    }
    else
    {
//         if (typeof kam == 'string' && kam != '')
//         {
//             document.getElementById(kam).innerHTML = 'reloading...';
//         }
    }

}
