var publicTypeStatusNo = ["", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10"];
var publicTypeStatusOn = [false, false, false, false, false, false, false, false, false, false, false];
var publicTypeStatusCheck = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
var publicTypeCode = ["", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J"];

var publicTypeImageUrl1 = "/images/main/main_option_";
var publicTypeImageUrl2 = ".gif";
var publicTypeImageId = "publicTypeButton_";

var publicTypeOptionDiv = "divPublicType_";

var publicTypeConatiner = "publicTypeDiv";
var publicTypeContainerButton = "openPublicTP";

/**
 * 선택된 PublicType 이 있는지 확인한다.
 * 하나라도 선택된 것이 있으면 true 없으면 false
 * @return
 */
function checkPublicTypeStatus(){
	for(var i=1; i<=10; i++) {
		if(publicTypeStatusCheck[i]>0) return true;
	}

	return false;
}

function clickPublicTypeButton(n) {
	var no = publicTypeStatusNo[n];
	publicTypeStatusOn[n] = !publicTypeStatusOn[n];

	changePublicTypeButton(n);

	if (publicTypeStatusOn[n]) {
		$j("#" + publicTypeOptionDiv + no).show();
		showPublicTypeContainer();
	} else {
		$j("#" + publicTypeOptionDiv + no).hide();
	}
}

function clickPublicTypeCheck(obj, n) {
	if (obj.checked) {
		publicTypeStatusCheck[n] += 1;
	} else {
		publicTypeStatusCheck[n] -= 1;
	}
	changePublicTypeButton(n);
}

function changePublicTypeButton(n) {
	var no = publicTypeStatusNo[n];
	var objImg = getRef(publicTypeImageId + no);
	var src = publicTypeImageUrl1;
	src += publicTypeStatusNo[n];

	if (publicTypeStatusOn[n]) {
		src +=  "_on";
	}
	if (publicTypeStatusCheck[n] > 0) {
		src += "_check";
	}
	src += publicTypeImageUrl2;
	objImg.src = src;
}

function clickPublicTypeAll(obj, n){
	var tf;
	if (obj.alt == "전체해제") {
		obj.src = "/images/btn_select_all.gif";
		obj.alt = "전체선택";
		tf = false;
	} else {
		obj.src = "/images/btn_deselect_all.gif";
		obj.alt = "전체해제";
		tf = true;
	}

    var allItem = getPublicType();

	var cnt = 0;
	for(var i=0; i < allItem.length; i++){
		chkValue = allItem[i].value;
		if(publicTypeCode[n] == chkValue.charAt(0)) {
			allItem[i].checked = tf;
			cnt++;
		}
	}

	if (tf) {
		publicTypeStatusCheck[n] = cnt;
	} else {
		publicTypeStatusCheck[n] = 0;
	}

	changePublicTypeButton(n);
}

function getPublicType() {
	var allItem;
	if (document.all) {
	   allItem = document.all["publicType"];
	} else {
	   allItem = document.getElementsByName("publicType");
	}
	return allItem;
}

function initPublicTypeCount() {
	var allItem = getPublicType();
	for(var i=1; i<=10; i++) {
		publicTypeStatusCheck[i] = getCountPublicTypeChecked(i);
		changePublicTypeButton(i);
	}
}

function getCountPublicTypeChecked(n) {
	var allItem = getPublicType();
	var cnt = 0;
	for(var i=0; i < allItem.length; i++){
		chkValue = allItem[i].value;
		if(publicTypeCode[n] == chkValue.charAt(0) && allItem[i].checked) {
			cnt++;
		}
	}
	return cnt;
}

function checkPublicTypeByValue(value, tf, n) {
	var form = obj.form;
	var arrayTarget = $j(form).find(":checkbox[value='" + value + "']");
	for(var i=0; i<arrayTarget.length; i++) {
		clickPublicTypeCheck(arrayTarget[i], n);
		arrayTarget[i].checked = tf;
	}
}

function checkD000(obj) {
	var values = ["D001","D002","D003","D004","D005","D006","D007","D008"];
	var form = obj.form;
	for(var i=0; i<values.length; i++) {
		var findArray = $j(form).find(":checkbox[value='" + values[i] + "']");
		for(var j=0; j<findArray.length; j++) {
			if (obj.checked && !findArray[j].checked) {
				findArray[j].checked = true;
				publicTypeStatusCheck[2] += 1;
			} else if (!obj.checked && findArray[j].checked) {
				findArray[j].checked = false;
				publicTypeStatusCheck[2] -= 1;
			}
		}
	}
	changePublicTypeButton(2);
}

function checkD000Child(obj) {
	var form = obj.form;
	var findArray = $j(form).find(":checkbox[value='D000']");
	for(var i=0; i<findArray.length; i++) {
		//findArray[i].check
	}
}

/**
 * 공시유형 div를 열거나 닫는다.
 */
function openPublicTpAll(obj){
	var div = document.getElementById("publicTypeDiv");
	if(obj.src.indexOf("/images/icon_option_open.gif") > 1 ) {
		showPublicTypeContainer();
	} else if(obj.src.indexOf("/images/icon_option_close.gif") > 1) {
		hidePublicTypeContainer();
	}
}

function showPublicTypeContainer(obj) {
	$j("#"+ publicTypeConatiner).show();
	$j("#"+ publicTypeContainerButton).attr("src", "/images/icon_option_close.gif");
}

function hidePublicTypeContainer() {
	$j("#"+ publicTypeConatiner).hide();
	$j("#"+ publicTypeContainerButton).attr("src", "/images/icon_option_open.gif");
}




/**
 * 펀드공시 상세검색에 사용되는 공시유형선택
 * 2009. 02. 03 / 김영일
 */
function clickPublicFundTypeAll(obj, n){
	var tf;
	if (obj.alt == "전체해제") {
		obj.src = "/images/btn_select_all.gif";
		obj.alt = "전체선택";
		tf = false;
	} else {
		obj.src = "/images/btn_deselect_all.gif";
		obj.alt = "전체해제";
		tf = true;
	}

    var allItem = getPublicType();

	var cnt = 0;
	for(var i=0; i < allItem.length; i++){
		chkValue = allItem[i].value;
		if(publicTypeCode[n] == chkValue.charAt(0)) {
			allItem[i].checked = tf;
			cnt++;
		}
	}

	if (tf) {
		publicTypeStatusCheck[n] = cnt;
	} else {
		publicTypeStatusCheck[n] = 0;
	}
}

function clickPublicFundTypeCheck(obj, n) {
	if (obj.checked) {
		publicTypeStatusCheck[n] += 1;
	} else {
		publicTypeStatusCheck[n] -= 1;
	}
}


