
var allcheckbox = false;
function checkAllCheckbox( form, box_name )
{
	allcheckbox = !allcheckbox;
	
	for( var i = 0; i < form.length; i++ )
	{
		var e = form.elements[i];

		if(e.name == box_name)
		{
			e.checked = allcheckbox;
		}
	}

	return;
}


 
 
function checkForm( form, checkElement, checkMsg )
{
	for( var i = 0; i < form.length; i++ )
	{
		for( var j = 0; j < checkElement.length; j++ )
		{
			if( form[i].name == checkElement[j] && form[i].value == "" )
			{
				alert( checkMsg[j] );
				form[i].focus();
				return false;
			}
		}
	}
	
	return true;
}



function submit_form( form, url )
{
 
	form.action = url; 
	form.submit();
}

 
function submitForm( form, url, checkId, checkMsg, targetFrame )
{

	if( !checkForm( form, checkId, checkMsg ) )
	{
		return;
	}

	if( targetFrame == null || targetFrame == "" )
	{
		targetFrame = "_self";
	}

	form.target = targetFrame;	
	form.action = url;
	form.submit();

}

 
 
 
/*
* ¸®½ºÆ® Ã¼Å© ¹Ú½º °Ë»ç
*/
function checkListCheckBox( form, box_name, check_limit ){
	var box_count = 0;
	var check_nums = form.elements.length;

	for( var i = 0; i < check_nums; i++ )
	{
		if( form.elements[i].checked == true && form.elements[i].name == box_name)
		{
			box_count++; 
		}
	}

	//## ¼±ÅÃ °³¼ö Á¦ÇÑ
	if(box_count > check_limit && check_limit > 0)
	{ 
		alert( check_limit+"°³¸¸ ¼±ÅÃÇÏ¼¼¿ä." ); 
		return false; 
	} 

	//## ¼±ÅÃ °³¼ö Ã¼Å©
	if( box_count <= 0 ){
		return false; 
	}
	else
	{
		return true;
	}
}


 
function submitMultiCheckboxForm( form, url, boxName, noSelMsg, confirmMsg )
{
	var flag = checkListCheckBox( form, boxName, 0 );
	if( !flag  ){
		alert( noSelMsg );	}
	else{
 
		if(confirmMsg!="" && !confirm( confirmMsg ) ){
			return;
		}
 
		form.action = url;
		form.submit();
	}
}


 
 
function addOptionToSelect( selectBox, text, value )
{
	var form = selectBox.form;
	
	// »õ·Î¿î Option »ý¼º
    var newOpt = document.createElement('OPTION');
    newOpt.text = text;
	newOpt.value = value;
	
    form.elements[selectBox.name].add(newOpt);	
}

 
 
 

function checkNum()
{
	if( event.keyCode < 48 || event.keyCode > 57 )
	{
		event.keyCode = '';
		alert('¼ýÀÚ¿Ü ´Ù¸¥ ¹®ÀÚ´Â ÀÔ·ÂÇÒ ¼ö ¾ø½À´Ï´Ù.');
		return;
	}
}

 
 
 
 
var new_win=0;
function open_window(url, width, height ){
	var a = screen.width;
	var b = screen.height;
	var aleft = a/2 - 416/2;
	var atop = b/2 - 300/2;
 
	if(new_win)
		if(!new_win.closed) new_win.close();

	new_win = open( url, "window_id", 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+aleft+', top='+atop+',screenX='+aleft+',screenY='+atop+'');
	new_win.focus();
}
var new_win2=0;
function open_window2(url, width, height ){
	var a = screen.width;
	var b = screen.height;
	var aleft = a/2 - 416/2;
	var atop = b/2 - 300/2; 

	if(new_win2)
		if(!new_win2.closed) new_win2.close();

	new_win2 = open( url, "diary_id", 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=1,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+aleft+', top='+atop+',screenX='+aleft+',screenY='+atop+'');
	new_win2.focus();
} 
function open_window3(url, width, height ){
	var a = screen.width;
	var b = screen.height;
	var aleft = a/2 - 416/2;
	var atop = b/2 - 300/2; 

	if(new_win)
		if(!new_win.closed) new_win.close();

	new_win = open( url, "window_id", 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=1,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+aleft+', top='+atop+',screenX='+aleft+',screenY='+atop+'');
	new_win.focus();
}

 
function spacexf(obj){
	if (obj.value == "" || obj.value.replace(/(^ +)|( +$)/g,'') == "" ){
		obj.value = "";
		return false;
	}
	return true;
}	

 
function checkChr(code) {   
    if((code<48) || (code > 57)){   
        event.returnValue = false; 
    }  
} 

function autoCommaObj(cls) {
	var moneyorg = cls.value
	var moneyorglen = moneyorg.length;      
	if (moneyorg.substr(0,1) == "0"){
		moneyorg = moneyorg.substr(1,moneyorglen);
	}      
	moneyorglen--;
	money = "";
	var moyo = "";
	var y = 0;
	for (var x=moneyorglen; x>=0; x--){
		moyo = moneyorg.charAt(x);
		if (moyo != ","){
			if (y%3 == 0 && y != 0){
				money = moyo + "," + money;
				y++;
			} 
			else {
				money = moyo + money;
				y++;
			}
		}
	} 
	cls.value = money; 
} 
 
 

function deleteOptions(id) {
    var models = document.getElementById(id);
    while(models.childNodes.length > 0) {
        models.removeChild(models.childNodes[0]);
    }
}
 

function resizeFrame(iframeObj) { 
  var innerBody = iframeObj.contentWindow.document.body; 
  var innerHeight = innerBody.scrollHeight + (innerBody.offsetHeight - innerBody.clientHeight); 
  var innerWidth = innerBody.scrollWidth + (innerBody.offsetWidth - innerBody.clientWidth); 
  iframeObj.style.height = innerHeight;
  iframeObj.style.width = innerWidth;
 
}



function get_Emement_Count(form,box_name){
	 
	var box_count = 0;
	var check_nums = form.elements.length;

	for( var i = 0; i < check_nums; i++ )
	{
		if( form.elements[i].name == box_name)
		{
			box_count++; 
		}
	}
	return box_count;
}

var study_open=0; 
function lecture_reader_open(lecture_idx){
	var url = "/lecture/gate.php?lecture_idx="+lecture_idx;
	var width = 980;
	var height = 580;
	var a = screen.width;
	var b = screen.height;
	var aleft = a/2 - width/2;
	var atop = b/2 - height/2; 

	if(study_open)
		if(!study_open.closed) study_open.close();

	study_open = open( url, "study_open", 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=0,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+aleft+', top='+atop+',screenX='+aleft+',screenY='+atop+'');
	study_open.focus();
}

function object_str_cut(message, maximum)
{
	   var inc = 0;
	   var nbytes = 0;
	   var msg = "";
	   var msglen = message.length;

	   for (i=0; i<msglen; i++) 
	   {
	   	   var ch = message.charAt(i);
	   	   if (escape(ch).length > 4) 
	   	   {
	   	   	   inc = 2;
	   	   } 
	   	   else if (ch == '\n')
	   	   {
	   	   	   if (message.charAt(i-1) != '\r')
	   	   	   {
	   	   	   	   inc = 1;
	   	   	   }
	   	   } 
	   	   else if (ch == '<' || ch == '>') 
	   	   {
	   	   	   inc = 4;
	   	   } 
	   	   else 
	   	   {
	   	   	   inc = 1;
	   	   }
	   	   if ((nbytes + inc) > maximum) 
	   	   {
	   	   	   break;
	   	   }
	   	   nbytes += inc;
	   	   msg += ch;
	   } 
	   return msg;
}
