/**=======================================================================================
*				The APMSOFT Template AJAX SOLUTION License, version 1.0
*			Copyright (c) 2006 김종관(ApmSoft.net). All rights reserved......
*
*=============+================+===========================+=============================+
*    개발자   |     연락처     |          홈페이지         |            Editor           |
*-------------+----------------+---------------------------+-----------------------------+
*    김종관   |  011-726-7046  |   http://www.apmsoft.net  | EditPlus 굴림체 Regular 9pt |
*-------------+----------------+---------------------------+-----------------------------+
* ▣ 사용목적
* = 체크박스 다중선택 및 해제 기능
* = utf-8
* = Ex :7, Opera : 9.10, FF : 2.x
* = update :
-----------------------------------------------------------------------------------------*/
var button = {};
button.ApmSoftNet = {};

// cource : 내부함수, field:네임명, chkmd:체크모드, min:최소선택갯수, max:최대갯수, method:외부함수명, mode='delete,modify'
button.ApmSoftNet.CHECKBOX = function(cource ,field, chkmd, min,max, method,mode,params)
{
	this.cource		= cource;
	this.name		= field;
	this.chkmode	= chkmd;
	this.chkmin		= parseInt(min);
	this.chkmax		= parseInt(max);
	this.call		= method;
	this.md			= mode;
	this.params		= params;
	this.send();
}

button.ApmSoftNet.CHECKBOX.prototype =
{
	send : function (){
		switch(this.cource){
			case 'chkboxCheckAll' :	this.chkboxCheckAll();break;
			case 'chkboxChsCheck' : this.chkboxChsCheck();	break;
		}
	},

	// checkbox 메뉴 전체선택, 해제
	chkboxCheckAll : function ()
	{
		//if( document.getElementsByName(this.chkmode)[0].checked==true ){ var chkmd = 1; }
		//else{ var chkmd = 0; }

		var objChk = document.getElementsByName(this.chkmode);
		if( objChk[0].checked==true ){ var chkmd =0 ; }
		else{ var chkmd=1; }

		var chkboxlen = document.getElementsByName(this.name).length;
		for(i=0 ; i<chkboxlen; i++)	{
			if (chkmd == 1)	{
				if (document.getElementsByName(this.name)[i].disabled == false){
					document.getElementsByName(this.name)[i].checked=false;
				}
			}
			if (chkmd == 0){
				if (document.getElementsByName(this.name)[i].disabled == false){
					document.getElementsByName(this.name)[i].checked=true;
				}
			}
		}
	},


	// 다중 체크박스 선택 옵션 참인지 체크
	chkboxChsCheck : function()
	{
		var chkboxv = '';
		var flag = 0;
		var chkboxcnt = document.getElementsByName(this.name).length;

		for( var i=0; i<chkboxcnt; i++ ){
			if(document.getElementsByName(this.name)[i].checked==true){
				flag++;
				v = document.getElementsByName(this.name)[i].value;
				chkboxv +=  v+',';
			}
		}

		// min alert
		if ( flag<this.chkmin ){
			alert(this.chkmin+'개 이상 선택하세요');
			return;
		}

		// max alert
		if ( this.chkmax && flag > this.chkmax ){
			alert(this.chkmax+'개 이상 선택할 수 없습니다');
			return;
		}

		if(this.params){ this.call(this.md,chkboxv+'&'+this.params); }
		else{ this.call(this.md,chkboxv); }
	}
}