﻿      var _category = 0;
      var _portalId;
      var _tt='t2';
      var xmlHttp = null;      
      //xmlHttp = createRequestObject();
      
      function createRequestObject()
      {
        var Http=null;
        try
        {
        // Firefox, Opera 8.0+, Safari
        Http=new XMLHttpRequest();
        }
        catch (e)
        {
        // Internet Explorer
          try
          {
            Http=new ActiveXObject("Msxml2.XMLHTTP");
          }
          catch (e)
          {
            Http=new ActiveXObject("Microsoft.XMLHTTP");
          }               
        }
        return Http;
      }
        
      function PlayerVideo(vid,width,height)
      { 
        xmlHttp= createRequestObject();
              
        loading = "<div style='height:100%' align='center'><img border='0' src='/DesktopModules/AG.Video/Images/loading.jpg'></img></div>";
        _obj = document.getElementById("dnn_ctr_VideoDetail_pnlMedia");
        if(_obj) _obj.innerHTML= loading; 
        
        if(xmlHttp == null)
        {
          alert("Your browser not support ajax");
          return;
        }
        var url = "/DesktopModules/AG.Video/viewPlayer.aspx?Vid=" + vid + "&w=" + width + "&h=" + height;                
        xmlHttp.onreadystatechange = MediaStateChanged;
        xmlHttp.open("GET", url, true);
        xmlHttp.send(null);
      }
                 
      function MediaStateChanged() 
      { 
          if (xmlHttp.readyState==4)
          { 
              if (xmlHttp.status == 200) {                  
                  _obj = document.getElementById("dnn_ctr_VideoDetail_pnlMedia");
                  if(_obj) 
                  _obj.innerHTML = xmlHttp.responseText;                                      
              }
          }
      }           
      
      function PlayerVideo(vid,width,height,autostart)
      { 
        xmlHttp= createRequestObject();
              
        loading = "<div style='height:100%' align='center'><img border='0' src='/DesktopModules/AG.Video/Images/loading.jpg'></img></div>";
        _obj = document.getElementById("dnn_ctr_VideoDetail_pnlMedia");
        if(_obj) _obj.innerHTML= loading; 
        
        if(xmlHttp == null)
        {
          alert("Your browser not support ajax");
          return;
        }
        var url = "/DesktopModules/AG.Video/viewPlayer.aspx?Vid=" + vid + "&w=" + width + "&h=" + height + "&autostart=" + autostart;                
        xmlHttp.onreadystatechange = MediaStateChanged;
        xmlHttp.open("GET", url, true);
        xmlHttp.send(null);
      }
      
      function GetVideoCounter(videoId)
      {
        xmlHttp = createRequestObject();
        if(xmlHttp == null)
        {
            alert("Your browser not support ajax");
            return;
        }
        var url = "/DesktopModules/AG.Video/viewCounter.aspx?Vid=" + videoId ;
        xmlHttp.onreadystatechange = function()
        {
            if(xmlHttp.readyState == 4)
            {
                if(xmlHttp.status == 200){
                    return xmlHttp.responseText;
                }
            }
        }
      }
            
      function GetURLParamValue(param,d){
 	      var _url = document.location.href.toLowerCase();
	      var i = _url.indexOf('/'+param+'/');
	      //if URL have URLrewrite style
	      if(i>=0){
		      _url = _url.substring(i+param.length+2,_url.length);
		      i = _url.indexOf('/');
		      if(i>=0){_url = _url.substring(0,i);return _url;}
	      } else {
		      //If URL have ? style
		      i = _url.indexOf(param+'=');
		      if(i>=0){
			      _url = _url.substring(i+param.length+1,_url.length);
			      i = _url.indexOf('&');
			      if(i>=0)_url = _url.substring(0,i);
			      return _url;
		      }
	      }
	      return d;
      }               
      
      function GetVideoList(listId,p,tt)
      {                    
        _category = listId;
        _portalId = p;
        _tt = tt;          
        xmlHttp = createRequestObject();
            
        if(xmlHttp == null)
        {
          alert("Your browser not support ajax");
          return;
        }
        var url = "/DesktopModules/AG.Video/viewCategoryList.aspx?list=" + listId + "&p=" + p + "&tt=" + tt ;                         
        xmlHttp.onreadystatechange = CategoryListStateChanged;
        xmlHttp.open("GET", url, false);
        xmlHttp.send(null);               
      }

      function CategoryListStateChanged() 
      {                     
          if(xmlHttp.readyState == 1) 
          {
            _obj = document.getElementById("dnn_ctr_VideoDetail_pnlCategoryList");
            if(_obj) 
                _obj.innerHTML = "<div style='height:100%' align='center'><img border='0' src='/DesktopModules/AG.Video/Images/loading.jpg'></img></div>";                            
          }                    
          if (xmlHttp.readyState==4)          
          {                                                                                   
              if (xmlHttp.status == 200) {                                        
                  _obj = document.getElementById("dnn_ctr_VideoDetail_pnlCategoryList");
                  if(_obj) 
                  _obj.innerHTML = xmlHttp.responseText;                                                                           
              }
          }
      }   
      
