// JavaScript Document
/*
*	modello框架
**
*	author 贺博
*	version 2007-8-14
**
*	收藏id的管理器，用来批处理时进行记录
*/
WebFavIdManager = Class.create();
WebFavIdManager.register("com.duxiu.js.WebFavIdManager");

WebFavIdManager.construct = function($self, $class){
	
	var arrId = [];
	
	this.initialize=function(){}
	
	this.onChange = function( check_box_obj ){
		if(check_box_obj.checked){
			add(check_box_obj.value);		
		}
		else{
			remove(check_box_obj.value);
		}		
	}
	//重新设置状态
	this.resetState = function(){
		var checkbox = document.getElementsByName('favid');

		for(var i= 0 ; i< checkbox.length ; i++){
			resetState(checkbox[i]);
		}
		g('check_b').checked = false;
	}
	
	this.getIds = function(){
		return arrId.join(",");
	}
	
	this.getCount = function(){
		return arrId.length;		
	}
	
	this.clear = function(){		
		arrId = [];
		
		var checkbox = document.getElementsByName('favid');

		for(var i= 0 ; i< checkbox.length ; i++){
			checkbox[i].checked = false;
		}		
		
		g('check_b').checked = false;
	}
	
	var add = function( value ){
		if(!contain(value)){
			arrId[arrId.length] = value;
		}
	}
	
	var remove = function( value ){
		var v = contain( value );
		if(v){
			arrId.splice(v.index , 1);			
		}		
	}
	
	var contain = function( value ){
		for(var i = 0 ; i<arrId.length ; i++){
			if(arrId[i]==value){
				return {index:i , id : value};			
			}
		}
		return null;
	}
	
	var resetState = function( check_box_obj ){
		if( contain( check_box_obj.value ) != null){
			check_box_obj.checked = true;
		}
	}
}