

function XslClassLib()
{
    this.XMLDoc = null;
    this.XSLDoc = null;
    this.browser = null;
    this.title;
    this.assetId;
    this.layoutFolderId;
    this.languageId;
    this.customer;
    this.keyword;
    this.fieldid;
    this.transcodeDestinationId;
    this.basketIdentifier;
    this.targetmediaformatid;
    this.metafieldLabelId;
    this.EDLDestinationId = "26";
    this.EDLFormatId = "43";
    this.ToolTipArray = new Array();
}

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()
{    
    //var EDLXMLDOC = this.getEdlList();
    
    var soapFunction = "GetAssetQuality";
	var soapAction = SOAP_DZFRONTEND_NAMESPACE_URL + "/" + soapFunction;
	var soapRequest = "";
	var result = "";
	
	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);
   
    // FireFox
    if (this.browser == "firefox"){
        loadMovie(this.XMLDoc.getElementsByTagName("outputname")[0].childNodes[0].nodeValue,EDLXMLDOC,this)
    }else{
    //alert(soapRequest);
        window.frames.videoFrame.changeVideo('VideoName',this.assetId,this.XMLDoc.selectSingleNode('//outputname').text)
        //loadMovie(this.XMLDoc.selectSingleNode('//outputname').text,EDLXMLDOC,this);  
    }  
  
   // test.loadXML(result) 
	//document.write(result)
	//return result;
}

XslClassLib.prototype.PlayMediaUrl = function()
{    
    
    var soapFunction = "GetAssetQuality";
	var soapAction = SOAP_DZFRONTEND_NAMESPACE_URL + "/" + soapFunction;
	var soapRequest = "";
	var result = "";
	
	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>";
	//alert(WS_URL+"\n\n"+ soapAction+"\n\n"+ soapRequest+"\n\n"+ soapFunction)
	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);
   try{
        this.LoadFilmInStandardPlayer(this.XMLDoc.selectSingleNode('//outputname').text);  
   }catch(e)
   {
        this.LoadFilmInStandardPlayer(this.XMLDoc.getElementsByTagName('outputname').innerHTML)            
   }
  
}

XslClassLib.prototype.LoadFilmInStandardPlayer = function(audioUrl)
{
   // alert(audioUrl)
    document.location.href= "download.aspx?video=true&mid=" + this.targetmediaformatid + "&Aid=" + this.assetId + "&basepath=" + this.audioBasePath + "&AudioUrl=" + audioUrl;
}

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.LayoutFolderContentSearch = function()
{
    document.getElementById('TXTLayoutFolderID').value = this.layoutFolderId;
    document.getElementById('TXTThemeName').value = this.title;
    document.getElementById('TemaSubmit').click();  
}

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.setXslDoc = function(url)
{
   
    var parser
    var XMLResult
    
	try{
        parser = new DOMParser()
        this.XSLDoc = parser.parseFromString(url,"text/xml");
        this.XSLDoc.async = false;
        this.browser = "firefox";
    }
    catch(e){
        try{
           this.XSLDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
           this.XSLDoc.async = false;
           this.XSLDoc.load(url)
        }
        catch(e)
        {
            try{
                this.XSLDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
               this.XSLDoc.async = false;
                this.XSLDoc.load(url)
            }
            catch(e){
                this.XSLDoc = new ActiveXObject("Microsoft.XmlDOM");
                this.XSLDoc.async = false;
                this.XSLDoc.load(url)
            }
        }
        if (document.implementation && document.implementation.createDocument) {
            this.XSLDoc = document.implementation.createDocument("","doc",null);
            this.XSLDoc.async = false;
            this.XSLDoc.load(url) 
        }
        
        this.browser = "ie";
    }    
}

XslClassLib.prototype.GetAssetQuality = function()
{    
    var soapFunction = "GetAssetQuality";
	var soapAction = SOAP_DZFRONTEND_NAMESPACE_URL + "/" + soapFunction;
	var soapRequest = "";
	var result = "";
	
	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);
   
   return this.XMLDoc;
}
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;
}

XslClassLib.prototype.AddToBasket = function()
{    
    
    var soapFunction = "AddToBasket";
	var soapAction = SOAP_DZFRONTEND_NAMESPACE_URL + "/" + soapFunction;
	var soapRequest = "";
	var result = "";
	
	if(GetCookie('basketid') != null && GetCookie('basketid') != this.basketIdentifier)
	{
	    this.basketIdentifier = String(GetCookie('basketid'));
	    DelCookie('basketid');
	}
	
	soapRequest = "<AddToBasket xmlns=\"DigiZuite\" >"+
     "<p_basketidentifier>"+this.basketIdentifier+"</p_basketidentifier>"+
	 "<p_assetid>"+this.assetId+"</p_assetid>"+
	 "<p_layoutfolderId>"+this.layoutFolderId+"</p_layoutfolderId>"+
	 "<p_customer>"+this.customer+"</p_customer>"+
	 "</AddToBasket>";

	result = SoapInvoke(WS_URL, soapAction, soapRequest, soapFunction);
	
	if(result.AddToBasketResult)
	{
	    if(result.AddToBasketResult.xml)
	        result = new Array(result.AddToBasketResult.xml);	        
	    else
	        result = result.AddToBasketResult;	        	    
	}	   
    
    this.setXmlDoc(result);
    
    return this.XMLDoc;
}

XslClassLib.prototype.EmptyBasket = function()
{    
    var soapFunction = "EmptyBasket";
	var soapAction = SOAP_DZFRONTEND_NAMESPACE_URL + "/" + soapFunction;
	var soapRequest = "";
	var result = "";
	
	if(GetCookie('basketid') != null && GetCookie('basketid') != this.basketIdentifier)
	{
	    this.basketIdentifier = String(GetCookie('basketid'));
	    DelCookie('basketid');
	}
	
	soapRequest = "<EmptyBasket xmlns=\"DigiZuite\" >"+
     "<p_basketidentifier>"+this.basketIdentifier+"</p_basketidentifier>"+
	 "<p_customer>"+this.customer+"</p_customer>"+
	 "</EmptyBasket>";
	 
	result = SoapInvoke(WS_URL, soapAction, soapRequest, soapFunction);
	
	if(result.EmptyBasketResult)
	{
	    if(result.EmptyBasketResult.xml)
	        result = new Array(result.EmptyBasketResult.xml);	        
	    else
	        result = result.EmptyBasketResult;	        	    
	}	   
    
    this.setXmlDoc(result);
    
    return this.XMLDoc;
}

XslClassLib.prototype.RemoveFromBasket = function()
{    
    var soapFunction = "RemoveFromBasket";
	var soapAction = SOAP_DZFRONTEND_NAMESPACE_URL + "/" + soapFunction;
	var soapRequest = "";
	var result = "";
	
	if(GetCookie('basketid') != null && GetCookie('basketid') != this.basketIdentifier)
	{
	    this.basketIdentifier = String(GetCookie('basketid'));
	    DelCookie('basketid');
	}
	
	soapRequest = "<RemoveFromBasket xmlns=\"DigiZuite\" >"+
     "<p_basketidentifier>"+this.basketIdentifier+"</p_basketidentifier>"+
	 "<p_customer>"+this.customer+"</p_customer>"+
	 "<p_assetid>"+this.assetId+"</p_assetid>"+
	 "</RemoveFromBasket>";
	 
	result = SoapInvoke(WS_URL, soapAction, soapRequest, soapFunction);
	
	if(result.RemoveFromBasketResult)
	{
	    if(result.RemoveFromBasketResult.xml)
	        result = new Array(result.RemoveFromBasketResult.xml);	        
	    else
	        result = result.RemoveFromBasketResult;	        	    
	}	   
    
    this.setXmlDoc(result);
    
    return this.XMLDoc;
}

XslClassLib.prototype.ViewToolTip = function()
{
	// shows the tooltip after delay-time ### Time Skal defineres i siteconfig
	
	//showdelaytip("assetTooltip"+ assetid + '@' + mediaFormatId ,false,700)	
	
	if(this.ToolTipArray[String(this.assetId)] == null)
	{
	   //  alert("her: "+String(this.assetId))
	     this.setXmlDoc(this.generatToolTipHTML());
	}
	else
	{
	   // alert(String(this.assetId))
	    this.setXmlDoc(this.ToolTipArray[String(this.assetId)])
	}

	if (!tipobj)
	{
	    tipobj = document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""
	}
	
	// Load the XSL
    //var xsl = new ActiveXObject("Msxml2.DOMDocument.4.0")
    //xsl.async = false
    this.setXslDoc("includes/ToolTip.xslt")
	//alert(xsl.text)
	// var tempHTML = this.XMLDoc.transformNode(this.XSLDoc)
	var tempHTML = this.XsltTranform()
	tipobj.innerHTML = tempHTML;
	showdelaytip("assetTooltip",false,700)
	
}

XslClassLib.prototype.MoreLikeThis = function()
{
    var soapFunction = "GetMetafieldValues";
	var soapAction = SOAP_DZFRONTEND_NAMESPACE_URL + "/" + soapFunction;
	var soapRequest = "";
	var result = "";
    
    soapRequest = "<GetMetafieldValues xmlns=\"DigiZuite\" >"+
     "<p_assetId>"+this.assetId+"</p_assetId>"+
	 "<p_customer>"+this.customer+"</p_customer>"+
	 "</GetMetafieldValues>";
   
    result = SoapInvoke(WS_URL, soapAction, soapRequest, soapFunction);
	
	if(result.GetMetafieldValuesResult)
	{
	    if(result.GetMetafieldValuesResult.xml)
	        result = new Array(result.GetMetafieldValuesResult.xml);	        
	    else
	        result = result.GetMetafieldValuesResult;	        	    
	}	   
   
   this.setXmlDoc(result)
   
   setFieldData(this.XMLDoc);    
}

XslClassLib.prototype.FillInKeyword = function()
{
   setKeywordField(this.fieldid, this.keyword);
}

XslClassLib.prototype.generatToolTipHTML = function()
{
    var soapFunction = "GetMetafieldValues";
	var soapAction = SOAP_DZFRONTEND_NAMESPACE_URL + "/" + soapFunction;
	var soapRequest = "";
	var result = "";
    
    soapRequest = "<GetMetafieldValues xmlns=\"DigiZuite\" >"+
     "<p_assetId>"+this.assetId+"</p_assetId>"+
	 "<p_customer>"+this.customer+"</p_customer>"+
	 "<p_languageId>"+this.languageId+"</p_languageId>"+
	 "</GetMetafieldValues>";

    result = SoapInvoke(WS_URL, soapAction, soapRequest, soapFunction);

	if(result.GetMetafieldValuesResult)
	{
	    if(result.GetMetafieldValuesResult.xml)
	        result = new Array(result.GetMetafieldValuesResult.xml);	        
	    else
	        result = result.GetMetafieldValuesResult;	        	    
	}	   
    
    /*try {
        this.setXmlDoc(result);
    }
    catch(e)
    {
        alert(result) 
    }
    */
    
    this.ToolTipArray[String(this.assetId)] = result;
    return result;                
}

XslClassLib.prototype.HideToolTip = function()
{
    try{
        hideddrivetip();
       }
       catch(e){}
}
XslClassLib.prototype.XsltTranform = function(){
  var control = ""
  var xml = this.XMLDoc
  var xsl = this.XSLDoc
 // var oXslDom = document.implementation.createDocument("","doc",null)
  
  if (!window.XSLTProcessor){ // ie method 
    control = xml.transformNode(xsl);
  }else{ // MOZZILA method
   /* var processor = new XSLTProcessor(); 
    oXslDom.load("includes/ToolTip.xslt")
    processor.importStylesheet(oXslDom); 
  
    var html = processor.transformToFragment(xml,document);
    var div = document.createElement('div');
    div.appendChild(html); 
    control = HtmlDecode(div.innerHTML); 
    */
  } 
  return control
}

/*
function SetCookie(sName, sValue)
{
  var date = new Date();
  date.setFullYear(date.getFullYear()+1);
  document.cookie = sName + "=" + escape(sValue) + "; expires=" + date.toGMTString();
}
*/

function GetCookie(sName)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return null;
}

function DelCookie(sName)
{
  document.cookie = sName + "=" + escape('') + "; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}
