
       var videoInformation = null;    
       var embedManager = null;    
       var videoInfoDataObject = null;
       var embedId = null;
       var embedId;
       var overrideTimeLimit;
       var confPost='';
       document.observe("dom:loaded", initPage);        
   
        
        function initPage() 
        {
            pageLocation = window.location.href;
            params = pageLocation.toQueryParams();
            embedId = getStringParamValue("embedid", window.location.href, params);
            videoInformation = new VideoInformation();
            videoInfoDataObject = videoInformation.getById("e" + embedId);
            if (videoInfoDataObject != null) {
                
                if (getStringParamValue("confirm", window.location.search.substring(1), params) == 'true') {

                    
                    sendMailDeleteCookie = ''
                    new Ajax.Request('/Embed/ApproveEmbed.htm?eid=' + embedId, {
                        method: 'post',
                        asynchronous: false,
                        onSuccess: function(transport) {
                        
                            sendMailDeleteCookie = transport.responseText;
                            showError("embedConfirmed");
                            
                        },
                        onFailure: function(transport) {
                            sendMailDeleteCookie = ''
                            showError("cantConfirm");
                           
                        }
                    });
                }
                strippedVidId = embedId.replace(/-/g,'');
                embedManager = new EmbedManager($('video'), "http://www.subply.com/en/YouTube/embed.htm");
                embedManager.setPlayerUrl("http://services.plymedia.com/players/" + videoInfoDataObject.Domain + "/embed/e" + strippedVidId);
                
                updateDisplay(embedManager.getEmbedCode(), embedManager.getEmbedCode(), embedManager.getPageDirectLink(embedId),videoInfoDataObject.Subtitles) 
              
                confPost = {"cssURL":"/WildFire/Samples/PTMP/BubblePly/bubblePly.css", "defaultContent":"txaEmbed"}; 
                Wildfire.initPost("BubblePly","divWildfire",400,120,confPost);           
                
                if (videoInfoDataObject.Subtitles && videoInfoDataObject.Subtitles.size() > 0) {
                    showDownload = false;
                    videoInfoDataObject.Subtitles.each( function(subtitle) {
                        if (subtitle.LanguageCode.toLowerCase() == 'eng') {
                            showDownload = true;
                        }
                    });
                    if (showDownload) {
                        $('downloadCaptions').show();
                        $('hrefDownload').href = '/Embed/GetSRT.htm?oid=e' + embedId;
                    }                        
                    
                }
                    
            }       
            
                   
        }
        
        function changeSize(dims) {
            embedManager.setEmbedSize(dims);
            $('txaEmbed').value = embedManager.getEmbedCode();    
            Wildfire.initPost("BubblePly","divWildfire",400,120,confPost);  
        }
        
        function updateDisplay(embedText, embedCode, embedUrlonSubPLY, subList) {
            
            if(subList != "")
                subList = createSubsList(subList);
            else
                subList = "<br>No available subtitles."
            $('txaEmbed').value = embedText;    
            $('video').update(embedCode);                
            $('txtEmbedUrl').value = embedUrlonSubPLY;
            $('curSubs').update(subList);
        }
        
        function showError(errCode) 
        {
            $('fdErros').childElements().each(function(item){
                item.hide();
            });
            $(errCode.toLowerCase()).show();
            $('divErrors').show();
        }
      
        
