////////////////////////////////////////////////////////////////////
//                      JavaScript Functions                          //
//                            ver. 2.0                              //
//                        Author: Alex Kvak                          //
////////////////////////////////////////////////////////////////////

// initializing a browser
var aks_isIE=0,aks_isNN=0, aks_isMF=0;
if (navigator.userAgent.indexOf("Firefox")!=-1) aks_isMF=1;
if    (document.all) 
    aks_isIE=1;
else 
    if(document.layers) 
        aks_isNN=1;
var aks_isOpera = (navigator.userAgent.indexOf("Opera") > 0);
///////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////
/*
    Sets active OPTION in SELECT element
    @param tag_id     id of the SELECT element
    @param value     value of OPTION element to be selected
*/
//////////////////////////////////////////////////////////////////////////////////////////
function aks_set_select_value(tag_id,value)
{
    if (!(obj = $(tag_id))) return false;
    var lo_len = obj.options.length;
    var lo = obj.options;

    for(i=lo_len-1;i>=0;i--)
        if (lo[i].value == value)
        {
            lo[i].selected = true;
            break;
        }
    return true;
}
//////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
function aks_suredelete(obj)
{
    val_ = confirm(suredelete_confirm);
    if (val_== false) return false;
    obj.action_.value='delete';
    return true;
}
///////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
function aks_suredelete_rubrik(obj)
{
    return confirm(suredelete2_confirm);
}
///////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
function aks_sureoben(obj)
{
    val_ = confirm(sureoben_confirm);
    if (val_== false) return false;
    obj.action_.value='oben';
    return true;
}
///////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
function aks_sureunten(obj)
{
    val_ = confirm(sureunten_confirm);
    if (val_== false) return false;
    obj.action_.value='unten';
    return true;
}
///////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
// return Element by Id 
function aks_getElement(n)
{
   if (typeof document.getElementById(n) != "undefined")
       return document.getElementById(n);
   else
          return false;
}
///////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
// return Element by Id 
function $(n)
{
   return aks_getElement(n);
}
///////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
// creates a popUp
function aks_popupWnd(url,title,width,height,scrollbars)
{
   if (title == "random")
        title = "wnd"+(Math.random() * 10).toString();
     
   var options = "status,menubar=off,height="+height+",width="+width;
   var xtop = (screen.height-height)/2, xleft = (screen.width-width)/2;
   options += ",top="+xtop+",left="+xleft;
   
   if (scrollbars)
       options += ",scrollbars=1";
   else
       options += ",scrollbars=0";
   
   var popup = window.open(url,title,options); 
   popup.document.close();
}
///////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
// changes the CheckBox flag of Element num
function aks_changeCheck(num)
{
    if (obj = aks_getElement(num))
        obj.checked = !obj.checked;
}
///////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
// set the display property of Element num
function aks_setView(num, show)
{
    var obj = aks_getElement(num);
    obj.style.display = (show) ? 'block':'none';
}
///////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
// set the visibility of Element num    
function aks_setVisibility(num, show)
{
    var obj = aks_getElement(num);
    obj.style.visibility = (show) ? "visible":"hidden";
}
///////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
// returns the display property of Element num            
function aks_getView(num)
{
    var obj = aks_getElement(num);
    return obj.style.display;
}
///////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
// changes the visibility ogf Element num        
function aks_changeView(num)
{
    visibility_ = aks_getView(num);
    show = (visibility_ == 'none') ? true : false;
    aks_setView(num, show);
    return true;
}
///////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
// sets the color farbe to all cells of table row obj
function aks_setFarbe(obj,farbe)
{
    theCells = obj.cells;
    var rowCellsCnt = theCells.length;
    for (c = 0; c < rowCellsCnt; c++) 
        theCells[c].style.backgroundColor=farbe;
}
///////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
// sets the color farbe to specified cell obj
function aks_setFarbeCell(obj,farbe)
{
     obj.style.backgroundColor = farbe;
}
///////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
// sets the color farbe to specified cell obj
function aks_goToURL(url)
{
     location.href = url;
}
///////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
// creates a new popUp window for changing color 
// @param editor_id     id of the editor's iframe
// @param txthtml_id     id of the editor's textarea
// @param is_textarea    indicates whether is the opener a textarea  
function aks_farbePopUp(editor_id,txthtml_id,command)
{
    aks_popupWnd("../includes/libraries/colorpicker.php?command="+command+"&param1="+editor_id+"&param2="+txthtml_id,"colorPickerPopUp",310,250,false);
}
///////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////
// creates a new popUp window for inserting an image 
// @param editor_id     id of the editor's iframe
// @param txthtml_id     id of the editor's textarea
// @param id             id of the record in DB
// @param feld             feld in DB
function aks_insertImagePopUp(editor_id,txthtml_id,id,feld)
{
    aks_popupWnd("../includes/libraries/texteditor/insertimage.php?id="+id+
    "&param1="+editor_id+"&param2="+txthtml_id+"&feld="+feld,
    "insertImagePopUp",650,650,true);
}
//////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////
// creates a new popUp window for inserting a Link 
// @param editor_id     id of the editor's iframe
// @param txthtml_id     id of the editor's textarea
function aks_insertLinkPopUp(editor_id,txthtml_id,id)
{
    aks_popupWnd("../includes/libraries/texteditor/insertlink.php?id="+id+
        "&param1="+editor_id+"&param2="+txthtml_id,
        "insertLinkPopUp",530,200,false);
}
//////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////
// creates a new popUp window for inserting a Table 
// @param editor_id     id of the editor's iframe
// @param txthtml_id     id of the editor's textarea
function aks_insertTablePopUp(editor_id,txthtml_id)
{
    if (aks_isMF) 
        aks_popupWnd("../includes/libraries/texteditor/inserttable.php?"+
        "param1="+editor_id+"&param2="+txthtml_id,
        "insertTablePopUp",300,200,false);
    else
        alert("Only for Mozilla Firefox");
}
////////////////////////////////////////////////////////////////////////////////////////// 

function aks_showMenu(id_)
{
    var i = 1;
    while (aks_getElement("sub_menu"+i))
    {
        //alert("sub_menu"+i);
        aks_setView("sub_menu"+i,false);
        i++;
    }
    if (id_ != 0) 
    {
        aks_setView(id_,true);
        aks_setFarbeCell(aks_getElement(id_),'#F0EEEE');
    }
}

//////////////////////////////////////////////////////////////////////////////////////////

/* CROSS-BROWSER EVENT HANDLER */
    function addEvent(obj, evType, fn){
         if (obj.attachEvent){
             var r = obj.attachEvent("on"+evType, fn);
            return r;
         } else if (obj.addEventListener){
             obj.addEventListener(evType, fn, true);
             return true;
         } else {
            return false;
         }
    }

