﻿var Information_Service_Url = "http://"+document.domain+"/Information.asmx"

function ObjCategory(){this.CategoryId;this.PluginNewsId;this.Name;}
function ObjSource(){this.SourceId;this.Name;}
function ObjSourceAndExistCategories(){this.SourceId;this.CategoryIds;}

//public InformationData.DataLayer.ObjCategory[] GetNewsCategory()
function GetNewsCategory(cb){SOAPClient.invoke(Information_Service_Url,'GetNewsCategory',null,true,cb);}
//public InformationData.DataLayer.ObjSource[] GetNewsSource()
function GetNewsSource(cb){SOAPClient.invoke(Information_Service_Url,'GetNewsSource',null,true,cb);}
//public InformationData.DataLayer.ObjSourceAndExistCategories[] GetNewsSourceAndExistCategory()
function GetNewsSourceAndExistCategory(cb){SOAPClient.invoke(Information_Service_Url,'GetNewsSourceAndExistCategory',null,true,cb);}

var _Exist_Category;
var _Exist_Source;
var _Exist_Source_Category;

function getCategory_CallBack(r,rxml)
{
  if(r != null)
  {
    _Exist_Category = r;  
    _Global_Information_ErrorCode = _Global_Information_ErrorCode + 1;
  }
}
function getSource_CallBack(r,rxml)
{
  if(r != null)
  {
    _Exist_Source = r;  
    _Global_Information_ErrorCode = _Global_Information_ErrorCode + 1;
  }
}
function getSourceAndCategory_CallBack(r,rxml)
{
  if(r != null)
  {
    _Exist_Source_Category = r;  
    _Global_Information_ErrorCode = _Global_Information_ErrorCode + 1;
  }
}
GetNewsCategory(getCategory_CallBack);
GetNewsSource(getSource_CallBack);
GetNewsSourceAndExistCategory(getSourceAndCategory_CallBack);

var _Global_User_Information = null;

function GetView_CallBack(result,xmlresult)
{
 if(result != null)
 {
   _Global_User_Information = result;
   _Global_Information_ErrorCode = _Global_Information_ErrorCode + 1;   
 }
}
GetShowOrder(GetView_CallBack);


function getSelectedSource(cid)
{
  var t;
  var ret = '';
  var List = _Global_User_Information.List;
  for(t = 0 ; t < List.length ; t++)
  {
    if(List[t].CategoryId == cid)
    {
      ret = List[t].SourceId;
      t++;
      break;      
    }
  }
  
  for(; t < List.length ; t++)
  {
    if(List[t].CategoryId == cid)
      ret = ret + "," + List[t].SourceId;
  }
  return ret;
}

function Exist(val,lst)
{
  for(var i = 0 ; i < lst.length ; i++)
  {
   if(lst[i] == val)
      return true;
  }
 return false;
}

function getPluginId(cid)
{
  for(var i = 0 ; i < _Exist_Category.length ; i++)
  {
    if(_Exist_Category[i].CategoryId == cid)
      return _Exist_Category[i];
  }
  return null;
}

function MakeSelectedNavigator()
{
  var str = '';
  var mylst = new Array();
  var nobj;
  var List = _Global_User_Information.List;
  for(t = 0 ; t < List.length ; t++)
  {
    if(Exist(List[t].CategoryId,mylst) == false)
      mylst.push(List[t].CategoryId);
  }

  str = '<TABLE id=GroupNews style="HEIGHT: 100%" cellSpacing=0 cellPadding=0><TR>';
  var ccid;
  var ttid;
  for(var t = 0 ; t < mylst.length ; t++)
  {
    ccid = mylst[t];
    ttid = getPluginId(ccid);
    if(ttid != null)
    {
      str = str + '<TD class=NewsGroupItem id=category_' + ccid + '><A onclick=LoadNews(' + ttid.PluginNewsId + ',' + ccid + '); href="#">' + ttid.Name + '</A></TD>'
    }
  }
  return str + '</TR></TABLE>';
}