

function XslClassLib()
{
    this.XMLDoc = null;
    this.browser = null;
    this.title = "";
    this.assetId;
    this.assetTypeId;
    this.layoutFolderId;
    this.languageId;
    this.customer;
    this.transcodeDestinationId;
    this.targetmediaformatid;
    this.metafieldLabelId;
    this.EDLDestinationId = "26";
    this.EDLFormatId = "46";
    this.AssetCountList;
}

if( document.implementation.hasFeature("XPath", "3.0") )
{  
// prototying the XMLDocument  
XMLDocument.prototype.selectNodes = function(cXPathString, xNode)  {     
if( !xNode ) { xNode = this; }      
var oNSResolver = this.createNSResolver(this.documentElement)     
var aItems = this.evaluate(cXPathString, xNode, oNSResolver,                   
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)     
var aResult = [];     
for( var i = 0; i < aItems.snapshotLength; i++)     {        
aResult[i] =  aItems.snapshotItem(i);     }     
return aResult;  }  // prototying the Element  
Element.prototype.selectNodes = function(cXPathString)  {     
if(this.ownerDocument.selectNodes)     {        
return this.ownerDocument.selectNodes(cXPathString, this);     }     
else{throw "For XML Elements Only";}  }}

// check for XPath implementation
if( document.implementation.hasFeature("XPath", "3.0") ){  
// prototying the XMLDocument  
XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode)  {     
if( !xNode ) { xNode = this; }      
var xItems = this.selectNodes(cXPathString, xNode);     
if( xItems.length > 0 )     {        
return xItems[0];     }     else     {        
return null;     }  }    // prototying the Element  
Element.prototype.selectSingleNode = function(cXPathString)  {         
if(this.ownerDocument.selectSingleNode)     {        
return this.ownerDocument.selectSingleNode(cXPathString, this);     }    
 else{throw "For XML Elements Only";}  }}        

XslClassLib.prototype.SetMediaUrlInPlayer = function()
{    
    
    try
    {
        var EDLXMLDOC = this.getEdlList();
        var soapFunction = "GetAssetQuality";
	    var soapAction = SOAP_DZFRONTEND_NAMESPACE_URL + "/" + soapFunction;
	    var soapRequest = "";
	    var result = "";
	    //FMC-special
	    if (parseInt(this.targetmediaformatid) == 26)
	    {
	        this.transcodeDestinationId = 27;
	        oldvideoBasePath = videoBasePath;
	        videoBasePath=videoBasePath1mb;
	    }
	    else
	    {
	        videoBasePath = oldvideoBasePath;
	    }
    	
	    soapRequest = "<GetAssetQuality xmlns=\"DigiZuite\" >"+
	     "<p_assetid>"+this.assetId+"</p_assetid>"+
	     "<p_layoutfolderId>"+this.layoutFolderId+"</p_layoutfolderId>"+
	     "<p_languageId>"+this.languageId+"</p_languageId>"+
	     "<p_customer>"+this.customer+"</p_customer>"+
	     "<p_transcodedestinationid>"+this.transcodeDestinationId+"</p_transcodedestinationid>"+
	     "<p_targetmediaformatid>"+this.targetmediaformatid+"</p_targetmediaformatid>"+
	     "</GetAssetQuality>";

        

	    result = SoapInvoke(WS_URL, soapAction, soapRequest, soapFunction);

	    if(result['GetAssetQualityResult'])
	    {
	        if(result['GetAssetQualityResult'].xml)
	            result = new Array(result['GetAssetQualityResult'].xml);	        
	        else
	            result = result['GetAssetQualityResult'];	        	    
	    }	   
       
       
          
       this.setXmlDoc(result);
       
      
       
       if(VideoTitle != null)
       {
            VideoTitle = this.title
       }
        
        if (this.browser == "firefox"){
            if (!isMac){            
                loadMovie(this.XMLDoc.getElementsByTagName("outputname")[0].childNodes[0].nodeValue,EDLXMLDOC,this);
            }else{
                var mediaURL = videoBasePath + this.XMLDoc.getElementsByTagName("outputname")[0].childNodes[0].nodeValue;
                document.getElementById('MediaURL').value = mediaURL;
                ExternalPlayEvent('MainPlayerPlayer', mediaURL);           
            }
        }else{
            if (!isMac){    
                loadMovie(this.XMLDoc.selectSingleNode('//outputname').text,EDLXMLDOC,this);
            }else{
                var mediaURL = videoBasePath + this.XMLDoc.selectSingleNode('//outputname').text;
                document.getElementById('MediaURL').value = mediaURL;
                ExternalPlayEvent('MainPlayerPlayer', mediaURL);
            }
        }
    }catch(e)
    {
        toggleVideoLayer("");
        toggleBuffering("none");
    }  

}

XslClassLib.prototype.getEdlList = function()
{
    var soapFunction = "GetEdlList";
    var soapAction = SOAP_DZFRONTEND_NAMESPACE_URL + "/" + soapFunction;
	var soapRequest = "";
	var result = "";
  
    soapRequest = "<GetEdlList xmlns=\"DigiZuite\" >"+
	 "<p_assetId>"+this.assetId+"</p_assetId>"+ 
	 "<p_metafieldLabelId>"+this.metafieldLabelId+"</p_metafieldLabelId>"+	 
	 "<p_formatId>"+this.EDLFormatId+"</p_formatId>"+
     "<p_transcodeDestinationId>"+this.EDLDestinationId+"</p_transcodeDestinationId>"+	 
	 "<p_customer>"+this.customer+"</p_customer>"+	 
	 "</GetEdlList>";	  
	
	 result = SoapInvoke(WS_URL, soapAction, soapRequest, soapFunction);
	
	if(result.GetEdlListResult)
	{
	    if(result.GetEdlListResult.xml)
	        result = new Array(result.GetEdlListResult.xml);	        
	    else
	        result = result.GetEdlListResult;	        	    
	}	 
	 //alert(result)
	 this.setXmlDoc(result)
     return this.XMLDoc 
}
XslClassLib.prototype.SetMediaUrlInPlayerWithReference = function()
{
    try
    {
        var soapFunction = "GetReferences";
        var soapAction = SOAP_DZFRONTEND_NAMESPACE_URL + "/" + soapFunction;
        var soapRequest = "";
        var result = "";

        soapRequest = "<GetReferences xmlns=\"DigiZuite\" >"+
        "<p_assetId>"+this.assetId+"</p_assetId>"+  
        "<p_customer>"+this.customer+"</p_customer>"+	 
        "</GetReferences>";

        result = SoapInvoke(WS_URL, soapAction, soapRequest, soapFunction);
    	 
        if(result.GetReferencesResult)
        {
            if(result.GetReferencesResult.xml)
                result = new Array(result.GetReferencesResult.xml);	        
            else
                result = result.GetReferencesResult;	        	    
        }	 
	    this.setXmlDoc(result);
    	
	    if (this.browser == "firefox"){
	        this.assetId = this.XMLDoc.getElementsByTagName("target_dataid")[0].childNodes[0].nodeValue;
	        this.layoutFolderId = this.XMLDoc.getElementsByTagName("layoutfolderid")[0].childNodes[0].nodeValue;
        }else{
            this.assetId = this.XMLDoc.selectSingleNode('//target_dataid').text;
	        this.layoutFolderId = this.XMLDoc.selectSingleNode('//layoutfolderid').text;
        }
        this.SetMediaUrlInPlayer();
        
    }catch(e)
    {
        toggleBuffering("none");
        doStop();
        document.getElementById('afspilningDiv').innerHTML = "Mangler link til film";
        toggleTeaser("");
    } 
}

XslClassLib.prototype.setXmlDoc = function(result)
{
  
    var parser
    var XMLResult
     
	try{
        parser = new DOMParser()
        this.XMLDoc = parser.parseFromString(result,"text/xml")
        this.browser = "firefox";
    }
    catch(e){
        try{
           this.XMLDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
           this.XMLDoc.loadXML(result)
        }
        catch(e)
        {
            try{
                this.XMLDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
                this.XMLDoc.loadXML(result)
            }
            catch(e){
                this.XMLDoc = new ActiveXObject("Microsoft.XmlDOM");
                this.XMLDoc.loadXML(result)
            }
        }
        if (document.implementation && document.implementation.createDocument) {
            this.XMLDoc = document.implementation.createDocument("","doc",null);
            this.XMLDoc.load(result) 
        }
        this.browser = "ie";          
    }    
}

XslClassLib.prototype.GetAssetQualities = function()
{    
    var soapFunction = "GetAssetQualities";
	var soapAction = SOAP_DZFRONTEND_NAMESPACE_URL + "/" + soapFunction;
	var soapRequest = "";
	var result = "";
	
	soapRequest = "<GetAssetQualities xmlns=\"DigiZuite\" >"+
	 "<p_assetid>"+this.assetId+"</p_assetid>"+
	 "<p_layoutfolderId>"+this.layoutFolderId+"</p_layoutfolderId>"+
	 "<p_languageId>"+this.languageId+"</p_languageId>"+
	 "<p_customer>"+this.customer+"</p_customer>"+
	 "<p_transcodedestinationid>"+this.transcodeDestinationId+"</p_transcodedestinationid>"+
	 "</GetAssetQualities>";
		 
	result = SoapInvoke(WS_URL, soapAction, soapRequest, soapFunction);
	
	if(result.GetAssetQualitiesResult)
	{
	    if(result.GetAssetQualitiesResult.xml)
	        result = new Array(result.GetAssetQualitiesResult.xml);	        
	    else
	        result = result.GetAssetQualitiesResult;	        	    
	}	   
    
    this.setXmlDoc(result);
    
    return this.XMLDoc;
}

// Dette er FMC specifikt. SKal LAVES OM
XslClassLib.prototype.GetAssetCount = function(p_assetId, p_layoutfolderId)
{
    var soapFunction = "GetAssetCount";
	var soapAction = SOAP_DZFRONTEND_NAMESPACE_URL + "/" + soapFunction;
	var soapRequest = "";
	var result = "";
	
	soapRequest = "<GetAssetCount xmlns=\"DigiZuite\" >"+
	 "<p_layoutfolderId>"+p_layoutfolderId+"</p_layoutfolderId>"+
	 "<p_languageId>"+this.languageId+"</p_languageId>"+
	 "<p_assetTypeId>"+this.assetTypeId+"</p_assetTypeId>"+
	 "<p_customer>"+this.customer+"</p_customer>"+
	 "</GetAssetCount>";
		 
	result = SoapInvoke(WS_URL, soapAction, soapRequest, soapFunction);
	
	if(result.GetAssetCountResult)
	{
	    if(result.GetAssetCountResult.xml)
	        result = new Array(result.GetAssetCountResult.xml);	        
	    else
	        result = result.GetAssetCountResult;	        	    
	}	   
    
    this.setXmlDoc(result);
    
   setTimeout('SetAssetCount('+p_assetId+','+result+')',100)
    
}

var count=0;
function SetAssetCount(p_assetId, result)
{
    //alert('numberOfAssets_'+p_assetId)  
    
    if(count>100){
                
    }
    else if (document.getElementById('numberOfAssets_'+p_assetId))
    {
        document.getElementById('numberOfAssets_'+p_assetId).innerHTML = 'Antal emner i tema: '+result;
    }
    else
    {
       count++;
       setTimeout('SetAssetCount('+p_assetId+','+result+')',500)
    }
    
}
