

var currentFontSize = 3;

function addFavorite(){
	window.external.AddFavorite('http://korea.go.kr','´ëÇÑ¹Î±¹ÀüÀÚÁ¤ºÎ');
}	

function badLink(str) {
	var flag = confirm('¿ÜºÎ ¸µÅ©¸¦ Çã¿ëÇÏÁö ¾Ê´Â »çÀÌÆ®ÀÔ´Ï´Ù. \n\r[' + str + ']·Î ÀÌµ¿ÇÏ½Ã°Ú½À´Ï±î?');
	if (flag) {
		location.href="http://" + str;
	}
}

function fullTextCheck111() {
	if (document.search.fullSearchChk.checked == true) {
		document.search.elements['fullSearch'].value = "Y";
	} else {
		document.search.elements['fullSearch'].value = "N";
	}
}

////================Ãß°¡=====================//

function proviso(source){
	var id = document.getElementById(source);
	if( id.style.display  =="none"){
		id.style.display = '';
	}else{
		id.style.display = 'none';
	}
} 

/*---------------------------------------------------------------------------
	Description   : ÁÖ¾îÁø leng ±æÀÌ¸¸Å­ numÀÇ ¾Õ¿¡ 0À» Ã¤¿öÁØ´Ù.
-----------------------------------------------------------------------------*/
function padZero(num, leng) {
	var zero=leng-(""+num).length;
	if (typeof(num)=="number" && zero>0) {
		var tmp="";
		for (var i=0; i<zero; i++) tmp+="0";
		return tmp+num;
	} else return num;
}


/*---------------------------------------------------------------------------
	Description   : ³¯Â¥ÀÇ ¼±ÅÃ¿¡¼­ ±â°£À» ¼±ÅÃÇÏ¸é
					³¯Â¥ÀÇ Á÷Á¢ÀÔ·Â ÅØ½ºÆ® ¹Ú½º¿¡ ³¯Â¥¸¦ ³Ö¾îÁØ´Ù.
-----------------------------------------------------------------------------*/
function date_select(type){
	var today = new Date();
	var today_year = today.getFullYear();
	var today_month = today.getMonth()+1;
	var today_date = today.getDate();
	var from;
	var to;
	if(type == 1){//1ÁÖÀÏ
		var year = today_year;
		var month = today_month;
		var date = today_date-7;
		var month_len = [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
		month_len[1] = (((today_year%100!=0)&&(today_year%4==0))||(today_year%400==0))?29:28;
		if(date <= 0){
			if(month == 1){
				date = month_len[11]+date;
				month = 12;
				year = year-1;
			}
			else{
				date = month_len[month-2]+date;
				month = month-1;
			}
		}
		from = year + "/" + padZero(month, 2) + "/" + padZero(date, 2);
		to = today_year + "/" + padZero(today_month, 2) + "/" + padZero(today_date, 2);
	}
	else if(type == 2){//1°³¿ù
		var year = today_year;
		var month = today_month - 1;
		if(month == 0){
			month = 12;
			year = year-1;
		}
		from = year + "/" + padZero(month, 2) + "/" + padZero(today_date, 2);
		to = today_year + "/" + padZero(today_month, 2) + "/" + padZero(today_date, 2);
	}
	else if(type == 3){//6°³¿ù
		var year = today_year;
		var month = today_month - 6;
		if(month == 0){
			month = 12;
			year = year-1;
		}
		else if(month < 0){
			month = month+12;
			year = year-1;
		}
		from = year + "/" + padZero(month, 2) + "/" + padZero(today_date, 2);
		to = today_year + "/" + padZero(today_month, 2) + "/" + padZero(today_date, 2);
	}
	else if(type == 4){//1³â
		var year = today_year-1;
		from = year + "/" + padZero(today_month, 2) + "/" + padZero(today_date, 2);
		to = today_year + "/" + padZero(today_month, 2) + "/" + padZero(today_date, 2);
	}
	document.search.fromDate.value = from;
	document.search.toDate.value = to;
}


function date_select_all(){
	document.search.fromDate.value = "";
	document.search.toDate.value = "";
}

function chkCheckboxField(obj){
	var objCheckBox = eval("document.search."+obj.name);
	var objlen = objCheckBox.length;
	
   if(obj.id=="0"){
	 if(obj.checked) {
		for(idx=1;idx<objlen;idx++){
			objCheckBox[idx].checked = false;
		}
	  } else {
			var bAll = true;
			for(idx=1;idx<objlen;idx++){
				if(objCheckBox[idx].checked)	{
					bAll = false;
					break;                
				}
			}      
			if(bAll)	objCheckBox[0].checked = true;
	  }
	}else if(obj.id == "1"){
		if(!obj.checked) {
			//var chk = false;
			var bAll = true;
			for(idx=1;idx<objlen;idx++){
				if(objCheckBox[idx].checked)	{
					bAll = false;
					break;                
				}
			}
			if(bAll)	objCheckBox[0].checked = true;
		} else if(obj.checked) {
			var bAll = true;
			//var chk = true;
			for(idx=1;idx<objlen;idx++){
				if(!objCheckBox[idx].checked)	{
					bAll = false;
					break;                
				} 
			}
			if(bAll)	{
				objCheckBox[0].checked = true;
				for(idx=1;idx<objlen;idx++)	objCheckBox[idx].checked = false;
			} else {
				objCheckBox[0].checked = false;
			}
		 }
	}
}

function orderCol(col,sort){
	document.search.collection.value=col;
	document.search.sort.value=sort;
	document.search.submit();
}


function goSearchTop(key) {
	document.search.query.value=key;
	document.search.submit();
}
function goSearch(key) {
	document.search.query.value = key;
	search();
}
	
function search() {
	document.search.elements["currentPage"].value = "1";
	document.search.submit();
}
function specialSetQuery(query) {
	try	{
		$("query").value = query;
		search();
	} catch (e) {}
}

function initQuery() {
	if (document.search.reSearch.checked == true) {
		if (document.search.hiddenQuery.value == "") {
			document.search.hiddenQuery.value = document.search.query.value;
		}
		document.search.query.value = "";
		document.search.query.focus();
	} else {
		document.search.query.value = document.search.hiddenQuery.value;
		document.search.query.select();
	}
}
function fullTextCheck() {
	if (document.search.elements['fullSearch'].checked == true) {
		document.search.elements['fullSearch'].value = "Y";
	} else {
		document.search.elements['fullSearch'].value = "N";
	}
}
function setCollectionName(collection) {
	if (collection == "all") {
		document.search.elements['collectionName'].value = "";
	} else if (collection == "colDIR") {
		document.search.elements['collectionName'].value = "¼­ºñ½º";
	} else if (collection == "colSITE") {
		document.search.elements['collectionName'].value = "»çÀÌÆ®";
	} else if (collection == "colCIV") {
		document.search.elements['collectionName'].value = "¹Î¿ø";
	} else if (collection == "colWEB") {
		document.search.elements['collectionName'].value = "°ø°ø±â°ü";
	} else if (collection == "colNEW") {
		document.search.elements['collectionName'].value = "±¹Á¤ºê¸®ÇÎ";
	} else if (collection == "colNEW2") {
		document.search.elements['collectionName'].value = "ºÎÃ³¼Ò½Ä";
	} else if (collection == "colBBS") {
		document.search.elements['collectionName'].value = "Á¤Ã¥°Ô½ÃÆÇ";
	} else if (collection == "colOPEN") {
		document.search.elements['collectionName'].value = "¿­¸°Áö½Ä";
	} else if (collection == "colOPENINFO") {
		document.search.elements['collectionName'].value = "¿­¸°Á¤º¸";
	} else if (collection == "colDIC") {
		document.search.elements['collectionName'].value = "¹é°ú»çÀü";
	} else if (collection == "data") {
		document.search.elements['collectionName'].value = "Àü¹®ÀÚ·á";
	} else if (collection == "new") {
		document.search.elements['collectionName'].value = "»õ¼Ò½Ä";
	}
}
function goPage(pageNumber) {
	document.search.elements['currentPage'].value = pageNumber;
	document.search.submit();
}
/*	±ÛÀÚÈ®´ëÃà¼Ò */
function zoomUtil(state, e){
	var idx;
	var arrFontSize = new Array();

	arrFontSize[0] = "65%";
	arrFontSize[1] = "75%";
	arrFontSize[2] = "85%";
	arrFontSize[3] = "100%";
	arrFontSize[4] = "110%";
	arrFontSize[5] = "120%";
	arrFontSize[6] = "130%";
	arrFontSize[7] = "140%";
	arrFontSize[8] = "150%";


	var e = e || window.event;
	if (e) {
		if (state == "plus") {
			if (currentFontSize < 8 ) {
				idx = currentFontSize + 1;
				currentFontSize = idx;
			}else{
				idx = 8;
				currentFontSize = idx;
			}
		} else if (state == "default") {
			idx = 3;
			currentFontSize = idx;
		} else if (state == "minus") {
			if ( currentFontSize >= 1) {
				idx = currentFontSize - 1;
				currentFontSize = idx;
			}else{
				idx = 0;
				currentFontSize = idx;
			}
		}
	}
	document.body.style.fontSize = arrFontSize[idx];
	return false;
}




function checkOnSubmit() {
	var temp = document.search.elements['query'].value;
	if (trim(temp) == "") {
		alert("°Ë»ö¾î¸¦ ÀÔ·ÂÇÏ¼¼¿ä.");
		return false;
	}
	if (temp.length > 50 ) {
		alert("°Ë»ö¾î´Â 50ÀÚ¸¦ ³ÑÀ»¼ö¾ø½À´Ï´Ù.");
		return false;
	}
	//document.search.elements['collection'].value = document.search.elements['collection_type'].value;
	document.search.elements['collection'].value = document.search.elements['collection_type'].value;
	document.search.elements["currentPage"].value = "1";
	setCollectionName(document.search.elements['collection'].value);
	return true;
}
function trim(str) {
	return str.replace(/(\s*)|(\s*$)/gi, "");
}
