    function isArray(v)
    {
        return v&&typeof v.pop=="function";
    }
    function urlEncode(o)
    {
        if(!o)
        {
            return"";
        }
        var buf=[];
        for(var key in o)
        {
            var ov=o[key],k=encodeURIComponent(key);
            var type=typeof ov;
            if(type=="undefined")
            {
                buf.push(k,"=&")
            }
            else
            {
                if(type!="function"&&type!="object")
                {
                    buf.push(k,"=",encodeURIComponent(ov),"&")
                }
                else
                {                    
                    if(isArray(ov))
                    {
                        if(ov.length)
                        {
                            for(var i=0,len=ov.length;i<len;i++)
                            {
                                buf.push(k,"=",encodeURIComponent(ov[i]===undefined?"":ov[i]),"&")
                            }
                        }
                        else
                        {
                            buf.push(k,"=&")
                        }
                    }
                }
            }
        }
        buf.pop();
        return buf.join("");
    }

    function getIcon(basePath, fileUrl, mediaType, iconUrl)
    {
        return (mediaType == 1 /*ConfigServlet.MEDIATYPE_IMAGE*/ ? fileUrl : (iconUrl && iconUrl.length > 0 ? iconUrl : (mediaType == 1 /*ConfigServlet.MEDIATYPE_IMAGE*/  ? fileUrl : basePath + "/common/playbutton_60x60.png")));
    }
    
    function getEntryHtml(videoId, videoWidth, videoHeight, imgWidth, imgHeight, fileUrl, basePath, mediaType, imgAttributes, isIcon, iconUrl, updateProgress, allowFullScreen)
    {
        var html = null;
        if(isIcon /*&& mediaType != 1*/ /*ConfigServlet.MEDIATYPE_IMAGE*/ /*&& mediaType != 2*//*ConfigServlet.MEDIATYPE_VIDEO*/)
        {
            fileUrl = getIcon(basePath, fileUrl, mediaType, iconUrl);
            mediaType = 1 /*ConfigServlet.MEDIATYPE_IMAGE*/;
        }
        if(mediaType == 2 /*ConfigServlet.MEDIATYPE_VIDEO*/)
        {
            //var flashvars = "skinurl=" + basePath + "/common/smpskin.swf" +
            //    "&isIcon="+ (isIcon ? "true" : "false") + "&autoPlay="+(isIcon ? "false" : "true") + "&videourl=" + fileUrl;        
            var flashvars="file=" + fileUrl;
            // for the "no show in IE problem" from http://www.jeroenwijering.com/?thread=6585
            flashvars = flashvars + "&width=" + videoWidth + "&height=" + videoHeight;            
            var url = basePath + "/common/mediaplayer1.swf?" + flashvars;
            var fileParam = null;
            html = getPlayerHtml(videoId, videoWidth, videoHeight, url, fileParam, isIcon, flashvars, updateProgress, allowFullScreen);
        }
        else if(mediaType == 4 /*ConfigServlet.MEDIATYPE_APP*/)
        {
            var url = fileUrl;
            var fileParam = null;
            html = getPlayerHtml(videoId, videoWidth, videoHeight, url, fileParam, isIcon, "");
        }
        else
        {
            html = "<img border='0' src='" + fileUrl + "'" + 
                (imgWidth ? " width='" + imgWidth+ "'" :"") + 
                (imgHeight ? " height='" + imgHeight+ "'":"") + " " +
                (imgAttributes ? imgAttributes : "")  +
                "></img>";
        }
        //alert(html);
        return html;
    }

    function getPlayerHtml(idObject, width, height, url, fileParam, isIcon, flashvars, appendFileUrl, updateProgress, allowFullScreen)
    {
        if(fileParam != null)
        {
            url = url + ((url.indexOf('?') == -1) ? "?" : "&") + "file=" + fileParam;
        }
        else if(appendFileUrl)
        {
            url = url + ((url.indexOf('?') == -1) ? "?" : "&") + appendFileUrl;
        }

        var updateProgressStr = (updateProgress && updateProgress == true ? "&updateprogress=true" : '');
        var allowFullScreenStr = (allowFullScreen  && allowFullScreen == true ? "&allowfullscreen=true" : '');
        var allowFullScreenTag = (allowFullScreen  && allowFullScreen == true ? "<PARAM NAME='allowfullscreen' VALUE='true'>" : '');
        
        var autoplay = (isIcon ? "false" : "true");
        var html = "<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' " +
            "codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0' " +
            "WIDTH='"+width+"' " +
            "HEIGHT='"+height+"' " +
            "autoplay='"+autoplay+"' " +
            "id='"+idObject+"'  " +
            (fileParam ? "        file='"+fileParam+"'  " :"")+
            "ALIGN='middle'> " +
            "<PARAM NAME='movie' " +
            "VALUE='"+url+"'>" +
            "<PARAM NAME='FlashVars' " +
            "VALUE='"+flashvars+updateProgressStr+allowFullScreenStr+"'>" +
            "<PARAM NAME='quality' VALUE='high'> " +
            "<PARAM NAME='bgcolor' VALUE='#000000'> " +
            allowFullScreenTag+
            "<PARAM NAME='wmode' VALUE='transparent'> " +
            "<PARAM NAME='allowScriptAccess' VALUE='always'> " +
            " <EMBED src='"+url+updateProgressStr+allowFullScreenStr+"'"+
            " quality='high' bgcolor='#000000' WIDTH='"+width+
            " FlashVars='"+flashvars+
            "' HEIGHT='"+height+"' autoplay='" + autoplay + "' NAME='"+idObject+(fileParam ? "' file='"+fileParam:"") +
            "' wmode='transparent' allowScriptAccess='always' "+(allowFullScreenStr.length > 1 ? allowFullScreenStr.substring(1) : allowFullScreenStr)+" TYPE='application/x-shockwave-flash' PLUGINSPAGE='http://www.macromedia.com/go/getflashplayer'>" +
            " </EMBED>" +
            "</OBJECT>";
     //   alert(html);
        return html;
    }

    function getEntryEnclosure(fileUrl, basePath, mediaType, mediaContentType)
    {
        var url, type;
        if(mediaType == 2 /*ConfigServlet.MEDIATYPE_VIDEO*/)
        {
            //var flashvars = "skinurl=" + basePath + "/common/smpskin.swf" +
            //    "&isIcon=false&autoPlay=false&videourl=" + fileUrl;        
            var flashvars="file=" + fileUrl;
            url = basePath + "/common/mediaplayer1.swf?" + flashvars;
            type = "application/x-shockwave-flash"; //ConfigServlet.CTYPE_SWF;
        }
        else
        {
            url = fileUrl;
            type = mediaContentType;
        }
        return [url, type];
    }

    function getFlashMovieObject(movieName)
    {
        //alert('gfo:' + movieName);
        var flashObj = null;
        if (window.document[movieName]) 
        {
            flashObj = window.document[movieName];
        }
        else if (navigator.appName.indexOf("Microsoft Internet")==-1)
        {
            if (document.embeds && document.embeds[movieName])
                flashObj = document.embeds[movieName]; 
        }
        else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
        {
            flashObj = document.getElementById(movieName);
        }
        return flashObj;
    }

    function htmlEncode(strHtml)
    {
        return xhtmlEncode(strHtml, true);
    }

    function xmlEncode(s)
    {
        return xhtmlEncode(s, false);
    }

    function xhtmlEncode(s, isHtml)
    {
        var str = null;
        if(s)
        {
            var strBuf = null;
            var c, ic;
            for(var i = 0; i < s.length; i++)
            {
                c = s.charAt(i);
                ic = s.charCodeAt(i);
                if(c == '&' || c == '"' || c == '\'' || c == '<' ||c == '>' || c =='?' || ic> 127 || ic < 32)
                {
                    if(strBuf == null) // ok we found a character to encode, so create it now
                    {
                        strBuf = s.substring(0, i);
                    }
                    
                    if(c == '&')
                    {
                        strBuf += "&amp;";
                    }
                    else if(c == '"')
                    {
                        strBuf += "&quot;";
                    }
                    else if(c == '\'')
                    {
                        //strBuf += isHtml ? "&#39;" : "&apos;");
                        strBuf += "&#39;";
                    }
                    else if(c == '<')
                    {
                        strBuf += "&lt;";
                    }
                    else if(c == '>')
                    {
                        strBuf += "&gt;";
                    }
                    else if(c == '?')
                    {
                        strBuf += "&#63;";
                    }
                    else if(ic > 127 || ic < 32)
                    {
                        strBuf += "&#";
                        strBuf += ic;
                        strBuf += ';';
                    }
                        
                }
                else if(strBuf != null)
                {
                    strBuf += c;
                }
            }
            str = (strBuf == null ? s : strBuf);
        }
        return str;
    }

