var frameid;
var NoEvent;

function js_common_AutosizeIframe()
{
    ffver = navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1];
    addheight = parseFloat(ffver) >= 0.1 ? 16 : 0;
    
    $$('iframe').each(function(objFrame) {
        if(objFrame && !window.opera)
        {
            objFrame.style.display = "block";
        
            if(objFrame.contentDocument && objFrame.contentDocument.body && objFrame.contentDocument.body.offsetHeight)
            {
                objFrame.height = objFrame.contentDocument.body.offsetHeight + addheight;
            }
            else if(objFrame.Document && objFrame.Document.body && objFrame.Document.body.scrollHeight)
            {
                objFrame.height = objFrame.Document.body.scrollHeight;
            }
        }
    });
    
    if(window.AutosizeHelper)
    {
        window.AutosizeHelper();
    }
}




function js_common_DoSearch(objSearch, objLimit, objWindow, p, f)
{
    var searchtext = $(objSearch).getValue();
    
    var limittext = objLimit ? $(objLimit).getValue() : '';
    if(isNaN(limittext))
    {
        limittext = '';
    }
    else
    {
        limittext = '&limit=' + limittext;
    }
    
    if(arguments[5])
    {
        var extraurl = arguments[5];
    }
    else
    {
        var extraurl = "";
    }
    
    objWindow.location.href = '?p=' + p + '&f=' + f + '&q=' + searchtext + limittext + extraurl;
}





function js_common_GetKey(e)
{
    if(NoEvent)
    {
        return null;
    }
    else if(e.ctrlKey || e.altKey)
    {
        return null;
    }
    else if(window.event)
    {
        return window.event.keyCode;
    }
    else if(e)
    {
        return e.which;
    }
    else
    {
        return null;
    }
}




function js_common_setDetails(ID, aperms, eperms)
{
    if(arguments[4])
    {
        frames['details'].location.href = '?f=contentdetails&ID=' + ID + '&' + arguments[3] + '=' + arguments[4];
    }
    else if(arguments[3])
    {
        frames['details'].location.href = '?f=details&ID=' + ID + '&parentID=' + arguments[3];
    }
    else
    {
        frames['details'].location.href = '?f=details&ID=' + ID;
    }

    js_common_setButton(ID, aperms, eperms);
}




function js_common_SynchronizeSelect(objFrom, objTo)
{
    while(objTo.options.length > 0)
    {
        objTo.options[0] = null;
    }

    for(i = 0; i < objFrom.length; i++)
    {
        if(objFrom.options[i].selected == true)
        {
            nextIndex = objTo.options.length;
            objTo.options[nextIndex] = new Option(objFrom.options[i].value, objFrom.options[i].value);
            objTo.options[nextIndex].selected = true;
        }
    }
}



function js_common_SetDisplay(arrRowIds, display)
{
    for(i = 0; i < arrRowIds.length; i++)
	{
	    var rowElement = document.getElementById(arrRowIds[i]);
		rowElement.style.display = display;
	}
}



function js_common_RowClick(barName, arrRowIds)
{
    var objImg = $(barName + 'image');

    if(objImg)
    {
        objImg.src = (objImg.src.endsWith('plus.gif')) ? imagePath + '/minus.gif' : imagePath + '/plus.gif';
    }

    for(i = 0; i < arrRowIds.length; i++)
    {
        var rowElement = document.getElementById(arrRowIds[i]);

        if(rowElement)
        {
            rowElement.style.display = ((rowElement.style.display == '') ? 'none' : '');
        }
    }
  
    js_common_AutosizeIframe();
}

