﻿function Favorites(list,status,addInBtn,addInPanel,okBtn,isInMsg,insertID)
{
	this.CategoryList = document.getElementById(list);
	this.Status = document.getElementById(status);
	this.AddInBtn = document.getElementById(addInBtn);
	this.AddInPanel = document.getElementById(addInPanel);
	this.OKBtn = document.getElementById(okBtn);
	this.IsInMsg = document.getElementById(isInMsg);
	this.InsertID = insertID;
};

Favorites.prototype.ShowMsg = function (msg)
{
	alert(msg);
};
Favorites.prototype.AddToFavorites = function()
{
	if(!addTagAjax.IsLogin().value)
	{
		this.ShowMsg("请登录!!");
		return false;
	}
	if(!addTagAjax.IsInFavorites(this.InsertID).value)
	{
		this.FShowAndHide(this.AddInBtn,false);
		this.FShowAndHide(this.AddInPanel,true);
		this.BindCategoryList();
	}
	else
	{
		this.ChangeState();
	}
};
Favorites.prototype.InsertFavorites = function()
{
	if(addTagAjax.IsLogin().value)
	{
		this.Processing("<img src=http://image.top100.cn/webimg/GaryBox/SendStatus.gif>",true);
		var v = addTagAjax.InsertFavorites(this.CategoryList.value,this.InsertID).value;
		this.IsSuccess(v);
		
	}
	else
	{
		this.ShowMsg("请登录!!");
	}
};
Favorites.prototype.IsSuccess = function(v)
{
	if(v)
	{
		this.ChangeState();
	}
	else
	{
		this.ShowMsg("操作失败!!");
		this.Processing("",false);
	}
}
Favorites.prototype.InsertFavoritesSinger = function()
{
	if(addTagAjax.IsLogin().value)
	{
		this.Processing("<img src=http://image.top100.cn/webimg/GaryBox/SendStatus.gif>",true);
		var v = addTagAjax.InsertFans(this.CategoryList.value,parseInt(this.InsertID)).value;
		this.IsSuccess(v);
	}
	else
	{
		this.ShowMsg("请登录!!");
	}
};

Favorites.prototype.AddToFavorites_Fans = function()
{
	if(!addTagAjax.IsLogin().value)
	{
		this.ShowMsg("请登录!!");
		return false;
	}
	
	if(!addTagAjax.IsInFavoritesFans(this.InsertID).value)
	{
		this.FShowAndHide("AddInButton_Fans",false);
		this.FShowAndHide("AddInPanel_Fans",true);
		this.BindCategoryList();
	}
	else
	{
		this.ChangeState();
	}
};
Favorites.prototype.BindCategoryList = function()
{
	var ds = addTagAjax.GetCategoryList().value;
	if(ds!=null && typeof(ds) == "object" && ds != null)
		{
			//clearOption();
			for(var i=0;i<  ds.Tables[0].Rows.length;i++)
			{
			var optionItem = new Option();
			optionItem.value = ds.Tables[0].Rows[i].TYPEID;
			optionItem.text  = ds.Tables[0].Rows[i].TYPENAME;	
			this.CategoryList.options.add(optionItem);
			}
		}
};

Favorites.prototype.clearOption = function ()
{
  for (var i = this.CategoryList.length - 1; i>= 0; i--) {
      this.CategoryList.remove(i);
  }
};
Favorites.prototype.Processing = function (msg,flag)
{
	 this.Status.innerHTML = msg;
	 this.CategoryList.disabled = flag;
	 this.OKBtn.disabled = flag;
};
Favorites.prototype.ChangeState = function ()
{
	this.FShowAndHide(this.AddInBtn,false);
	this.FShowAndHide(this.IsInMsg,true);
	this.FShowAndHide(this.AddInPanel,false);
	return false;
};
Favorites.prototype.FShowAndHide = function (obj,visible)
{
   if (visible) 
   { 
      obj.style.display="block"; //show element 
   } 
   else 
   { 
      obj.style.display="none"; //hide element 
   } 
};