Mys.Model.Item = function()
{
	Mys.Model.Item.superclass.constructor.call(this);
};

Ext.extend(Mys.Model.Item, Mys.Model,
{
	get : function(itemID, list, callback, scope)
	{
		var query = "model=item&mode=get&item_id=" + itemID;
		
		if(list)
		{
			if(list.boardID)
			{
				var boardID = typeof list.boardID == "string" ? list.boardID.split(",") : list.boardID;
				
				if(boardID instanceof Array)
					query += "&board_id[]=" + boardID.join("&board_id[]=");
				else
					query += "&board_id=" + boardID;
			}
			if(list.boardType)
			{
				if(list.boardType instanceof Array)
					query += "&board_type[]=" + list.boardType.join("&board_type[]=");
				else
					query += "&board_type=" + list.boardType;
			}
			if(list.order)
				query += "&order=" + list.order;
			if(list.dir)
				query += "&dir=" + list.dir;
			if(list.range)
				query += "&range=" + list.range;
			if(list.startDate)
				query += "&start_date=" + list.startDate;
			if(list.endDate)
				query += "&end_date=" + list.endDate;
			if(list.scriptFlag !== null && list.scriptFlag !== undefined)
				query += "&script_flag=" + (list.scriptFlag ? 1 : 0);
			if(list.keyword)
				query += "&keyword=" + list.keyword.encode();
		}
		this.ajax.request(query, callback,scope);
	},
	
	getHrd : function(boardID, serial, callback, scope)
	{
		var query = "model=item&mode=get_hrd&range=all&basis=apply_date&time_point=future&order=start_date&dir=asc&board_id=" + boardID + "&serial=" + serial;
		
		this.ajax.request(query, callback, scope);
	},
	
	getList : function(boardID, boardType, order, dir, basis, timePoint, range, startDate, endDate, property, start, limit, keyword, scriptFlag, defaultFlag, cate, callback, scope)
	{
		var query = "model=item&mode=get_list&";
	
		if(boardID)
		{
			if(boardID instanceof Array)
				query += "&board_id[]=" + boardID.join("&board_id[]=");
			else if(parseInt(boardID))
				query += "&board_id=" + boardID;
		}
		if(boardType)
		{
			if(boardType instanceof Array)
				query += "&board_type[]=" + boardType.join("&board_type[]=");
			else
				query += "&board_type=" + boardType;
		}
		if(order)
			query += "&order=" + order;
		if(dir)
			query += "&dir=" + dir;
		if(range)
			query += "&range=" + range;
		if(startDate)
			query += "&start_date=" + startDate;
		if(endDate)
			query += "&end_date=" + endDate;
		if(property)
			query += "&property=" + property;
		if(scriptFlag !== null && scriptFlag !== undefined)
			query += "&script_flag=" + scriptFlag;
		if(defaultFlag)
			query += "&default_flag=" + defaultFlag;
		if(cate)
			query += "&cate=" + cate;
		if(basis)
			query += "&basis=" + basis;
		if(timePoint)
			query += "&time_point=" + timePoint;

		query += "&start=" + start;
		query += "&limit=" + limit;
		
		if(keyword)
			query += "&keyword=" + keyword.encode();
		
		this.ajax.request(query, callback, scope);
	},
	
	getCustom : function(boardType, start, limit, order, dir, basis, timePoint, range, callback, scope)
	{
		var query = "model=item&mode=get_custom&";
		if(boardType)
		{
			if(boardType instanceof Array)
				query += "&board_type[]=" + boardType.join("&board_type[]=");
			else
				query += "&board_type=" + boardType;
		}
		if(order)
			query += "&order=" + order;
		if(dir)
			query += "&dir=" + dir;
		if(basis)
			query += "&basis=" + basis;
		if(timePoint)
			query += "&time_point=" + timePoint;
		if(range)
			query += "&range=" + range;
		
		query += "&start=" + start;
		query += "&limit=" + limit;
		
		this.ajax.request(query, callback, scope);
	},
	
	getIndexList : function(boardID, boardType, order, dir, basis, timePoint, range, start, limit, callback, scope)
	{
		var query = "model=item&mode=get_index_list";
		
		if(boardID)
		{
			if(boardID instanceof Array)
				query += "&board_id[]=" + boardID.join("&board_id[]=");
			else
				query += "&board_id=" + boardID;
		}
		if(boardType)
			query += "&board_type=" + boardType;
		if(order)
			query += "&order=" + order;
		if(dir)
			query += "&dir=" + dir;
		if(basis)
			query += "&basis=" + basis;
		if(timePoint)
			query += "&time_point=" + timePoint;
		if(range)
			query += "&range=" + range;
		
		query += "&start=" + start;
		query += "&limit=" + limit;
		
		this.ajax.request(query, callback, scope);
	},
	
	getBoardList : function(boardID, boardType, start, limit, keyword, order, callback, scope)
	{
		var query = "model=item&mode=get_board_list";
		
		if(boardID)
		{
			if(boardID instanceof Array)
				query += "&board_id[]=" + boardID.join("&board_id[]=");
			else if(parseInt(boardID))
				query += "&board_id=" + boardID;
		}
		if(boardType)
			query += "&board_type=" + boardType;
		if(order)
			query += "&order=" + order;
		
		query += "&start=" + start;
		query += "&limit=" + limit;
		
		if(keyword)
			query += "&keyword=" + keyword.encode();
		
		this.ajax.request(query, callback, scope);
	},
	
	getBlogList : function(boardID, start, limit, callback, scope){
		var query = "model=item&mode=get_blog_list&board_id=" + boardID + "&start=" + start + "&limit=" + limit;
		
		this.ajax.request(query, callback, scope);
	},
	
	getMy : function(tab, order, dir, range, start, limit, callback, scope)
	{
		var query = "model=item&mode=get_my&tab=" + tab
	},
	
	agree : function(itemID, callback, scope)
	{
		var query = "model=item&mode=agree&item_id=" + itemID;
		
		this.ajax.request(query, callback, scope);
	},
	
	scrap : function(itemID, callback, scope)
	{
		var query = "model=item&mode=scrap&item_id=" + itemID;
		
		this.ajax.request(query, callback, scope);
	},
	
	add : function(form, reset, callback, scope)
	{
		this.ajax.formRequest(form, reset, callback, scope);
	},
	
	modify : function(form, reset, callback, scope)
	{
		this.ajax.formRequest(form, reset, callback, scope);
	},
	
	del : function(itemID, callback, scope)
	{
		var query = "model=item&mode=del&item_id=" + itemID;
		
		this.ajax.request(query, callback, scope);
	},
	
	delFile : function(itemID, number, callback, scope){
		var query = "model=item&mode=del_file&item_id=" + itemID + "&number=" + number;
		
		this.ajax.request(query, callback, scope);
	},
	
	setDefault : function(itemID, defaultFlag, callback, scope)
	{
		var query = "model=item&mode=modify&item_id=" + itemID + "&default_flag=" + (defaultFlag ? 1 : 0);
		
		this.ajax.request(query, callback, scope);
	},
	
	modifyTag : function(itemID, tag, callback, scope)
	{
		var query = "model=item&mode=modify&item_id=" + itemID + "&tag=" + tag.encode();
		
		this.ajax.request(query, callback, scope);
	}
});

Global.modelItem = new Mys.Model.Item;