﻿function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

var intervalDeepLink;
var deeplink = false;
function deepLink(){
    if (deeplink){
        intervalDeepLink = setInterval('doDeepLink()',500);        
    }    
}
function doDeepLink(){
    clearInterval(intervalDeepLink);
    loadDeepLinkMovie();
}

// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}
// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}
// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}
function WindowOnloadCallContainer()
{
    if (!isMac)
    {
        var PlaceholderObj = document.getElementById('VideoLayer'); 
        var videoSource = _deepUrl;
        var assetId = document.getElementById('AssetID').value;
        var layoutFolderId = document.getElementById('LayoutFolderID').value;
        var transcodeDestinationId = document.getElementById('TranscodeDestinationID').value;

        PlaceholderObj.this_width = '320';    
        PlaceholderObj.this_height = '240';   
        PlaceholderObj.this_Id = 'VideoPlayer';
        WritePlayer(PlaceholderObj, videoSource);
        
        setPlayerObj();
        
        setTimeout('PlayerWorkingCheck()',400);
      
        if (browserType != "IE" && get_cookie("firefoxFix")=="")
        {
           document.cookie="firefoxFix=1";
        }
        
        toggleVideoLayer("none");
        toggleBuffering('');
    }
  
    whiteFlashCrawler();    
}

//Get cookie routine by Shelley Powers 
function get_cookie(Name) 
{
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    // if cookie exists
    if (offset != -1) { 
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1) end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}

var playerLoadTryCount = 0;

function PlayerWorkingCheck()
{
    
    var PlaceholderObj = document.getElementById('VideoLayer') 
    var videoSource = _deepUrl;
    if (browserType != "IE")
    {
        document.getElementById('InitPlayerWait').style.display = '';
        if(!document.getElementById('VideoPlayer').PlayState)
        {
           if (playerLoadTryCount < 15)
           {           
               PlaceholderObj.this_width = '320';    
               PlaceholderObj.this_height = '240';   
               PlaceholderObj.this_Id = 'VideoPlayer';
                              
               WritePlayer(PlaceholderObj, videoSource);
               playerLoadTryCount += 1;
               setTimeout('PlayerWorkingCheck()',600);
           }
           else
           {
               if (browserType == "Firefox" && browserVerstion == "2")
               { 
                    document.getElementById('VideoLayer').style.display = 'none';
                    document.getElementById('pluginInfo').style.display = '';
                    document.getElementById('InitPlayerWait').style.display = 'none'; 
               }
               else
               {
                    if (browserType != "Firefox")
                    {
                        alert('You must install an ActiveX plugin in order to use the functionality of forsvarskanalen.dk in a Firefox browser. Please read the instructions under the Help function.') 
                        document.getElementById('InitPlayerWait').style.display = 'none';
                    }
                    else if(browserType == "Firefox" && browserVerstion == "3")
                    {                        
                        document.getElementById('InitPlayerWait').style.display = 'none';
                    }
               }
           }
        }
        else
        {
            document.getElementById('InitPlayerWait').style.display = 'none';
        }
    }
}


function WritePlayer(PlaceholderObj, videoSource)
{
    var HtmlString = '';
    //alert(videoSource);
    
    if (browserType == "IE")
    {
        HtmlString += '<OBJECT id="'+ PlaceholderObj.this_Id +'"' + 'type="application/x-ms-wmp"' + 'width="' + PlaceholderObj.this_width +'" height="'+ PlaceholderObj.this_height +'" classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6">';
    }
    else
    {
        HtmlString += '<OBJECT id="'+ PlaceholderObj.this_Id +'"' + 'type="application/x-ms-wmp"' + 'width="' + PlaceholderObj.this_width +'" height="'+ PlaceholderObj.this_height + '"' + 'data="' + videoSource + '">';
	}

    HtmlString +='<PARAM NAME="url" VALUE="'+videoSource+'"/>'+
    '<PARAM NAME="playCount" VALUE="1"/>'+
    '<PARAM NAME="autoStart" VALUE="true"/>'+
    '<PARAM NAME="invokeURLs" VALUE="false"/>'+
    '<param name="uiMode" value="none">'+
    '</OBJECT>';
    
    PlaceholderObj.innerHTML =  HtmlString;
    
    //    '<PARAM name="WMode" value="Transparent" />'+
    //    '<PARAM NAME="rate" VALUE="1">'+
    //    '<PARAM NAME="balance" VALUE="0">'+
    //    '<PARAM NAME="currentPosition" VALUE="0">'+
    //    '<PARAM NAME="defaultFrame" VALUE="">'+
    //    '<PARAM NAME="playCount" VALUE="1">'+
    //    '<PARAM NAME="autoStart" VALUE="true">'+
    //    '<PARAM NAME="currentMarker" VALUE="0">'+
    //    '<PARAM NAME="invokeURLs" VALUE="0">'+
    //    '<PARAM NAME="baseURL" VALUE="">'+
    //    '<PARAM NAME="volume" VALUE="50">'+
    //    '<PARAM NAME="mute" VALUE="0">'+
    //    '<PARAM NAME="uiMode" VALUE="none">'+
    //    '<PARAM NAME="stretchToFit" VALUE="0">'+
    //    '<PARAM NAME="windowlessVideo" VALUE="0">'+
    //    '<PARAM NAME="enabled" VALUE="1">'+
    //    '<PARAM NAME="enableContextMenu" VALUE="0">'+
    //    '<PARAM NAME="fullScreen" VALUE="0">'+
    //    '<PARAM NAME="SAMIStyle" VALUE="">'+
    //    '<PARAM NAME="SAMILang" VALUE="">'+
    //    '<PARAM NAME="SAMIFilename" VALUE="">'+
    //    '<PARAM NAME="captioningID" VALUE="">'+
    //    '<PARAM NAME="enableErrorDialogs" VALUE="0">'+	


}

function WriteFlashObject(outputObject, source, width, height)
{                           
    var HtmlString = '';
    HtmlString +=   '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+ width +'" height="'+ height +'" id="flashObj" align="middle">'+
                    '<param name="allowScriptAccess" value="always" />' +
                    '<param name="movie" value="'+ source +'" /><param name="quality" value="high" /><param name="wmode" value="transparent"><param name="bgcolor" value="#000000" /><embed src="'+ source +'" quality="high" bgcolor="#000000" width="'+ width +'" height="'+ height +'" name="flashObj" align="middle" wmode="transparent" allowScriptAccess=""always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />' +
                    '</object>'
        
    outputObject.innerHTML =  HtmlString;
    window.flashObj = document.forms[0].flashObj;  //Så det virker inde i et form tag 		    
}


document.onkeypress = kH;
var lockEnterKey = false;
var lastFocus = "";		

function kH(e) 
{
	var pK = document.all? window.event.keyCode:e.which;
	if (pK==13)
	{	
			switch(lastFocus)
			{
			    case 'fFreeTextDesc':
			       if(document.getElementById('SearchFields_Button1'))
			       {
			            if (browserType == "IE"){
			                document.getElementById('SearchFields_Button1').click()  ;      
			               }
			       }
			    break;
			}
			lastFocus = "";
		try
		{
		    event.returnValue = false;
		    event.cancel = true;
		}
		catch(e)
		{}								
	}							
}