//왼쪽 메뉴 다루기
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
	//menuOnOff(3);//메인서브메뉴 끄기
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//오른쪽 배너 호출
function load_right_banner(){
		
	b = document.getElementById("right_banner");
	if(b)
		follow_banner("right_banner", b.style.top.toInteger(), b.style.top.toInteger() + 110,50);
	else
		return false;
}


//빈값 체크
function isEmptyValue(check_str){
	
	if(check_str=="" || check_str==null)
		return true;
	else
		return false;
}

//페이지 이동
function move_page(target_url){
	location.href=target_url;
}

//특정 이름을 가진 특정 엘리먼트가 존재하는지 체크
function check_tag_special_name(tagName,searchName){
	
	obj=document.getElementsByTagName(tagName);

	for(var i=0;i<obj.length;i++){
		if(obj[i].name==searchName)
			return true;
		else
			continue;
	}

	return false;
}

//다운로드 할 파일이름 셋팅
function setting_download_filename(filename){
	document.upfile_download.saved_filename.value=filename;
	document.upfile_download.submit();
}

//빈 값을 제외한 객체 길이 리턴
function return_not_null_count(obj){
	
	var counter=0;
	for(var i=0;i<obj.length;i++){
		if(!isEmptyValue(obj[i].value))
			counter++;
		else
			continue;
	}

	return counter;
}

//문자열에서 공백제거한 길이
function return_strlength(checkStr){
	
	checkStr=checkStr.split(" ").join("");//공백제거

	return checkStr.length;
}

//빈값인지 아닌지
function isEmptyValue(chkValue){
	
	if(chkValue=="" || chkValue==null)
		return true;
	else
		return false;
}

//좌우여백 제거 trim
String.prototype.trim=function(){
	return this.replace(/(^\s*)|(\s*$)/gi,"");
}

//체크박스-체크된 갯수 리턴
function return_checkbox_checked(obj){
	
	var checked_counter=0;
	for(var i=0;i<obj.length;i++){
		if(obj[i].checked==true)
			checked_counter++;
		else
			continue;
	}

	return checked_counter;
}

//체크박스-체크된 갯수 리턴
function return_checkbox_checked_byName(obj_name){
	
	obj=document.getElementsByName(obj_name);

	var checked_counter=0;
	for(var i=0;i<obj.length;i++){
		if(obj[i].checked==true)
			checked_counter++;
		else
			continue;
	}

	return checked_counter;
}

//파일입력 input 추가 지정, div 이름은 upfile_area으로 함.
function insert_upfile_input(){
	
	var obj=document.getElementById("upfile_area");
	var upfile_str="<br/><input type=\"file\" name=\"upfile[]\" class=\"upfile_style\">";

	obj.innerHTML+=upfile_str;
}

//div 열고 닫기
function div_display(obj_name){

	this_obj=document.getElementById(obj_name);
	
	if(this_obj){
		if(isEmptyValue(this_obj.style.display) || this_obj.style.display=="none")
			this_obj.style.display="block";
		else
			this_obj.style.display="none";
	}else
		return false;
}

//div 열고 닫기
function div_display_byname(obj_name){

	this_obj=document.getElementsByName(obj_name);
	
	if(this_obj){
		if(isEmptyValue(this_obj.style.display) || this_obj.style.display=="none")
			this_obj.style.display="block";
		else
			this_obj.style.display="none";
	}else
		return false;
}

//div 닫기
function div_close(obj_name){

	this_obj=document.getElementById(obj_name);

	this_obj.style.display="none";
}

//배경색 지정
function set_mouseover(obj){
	obj.style.textDecoration="underline";
	obj.style.cursor="pointer";
}
function set_mouseout(obj){
	obj.style.textDecoration="none";
}


//지정된 모든 체크박스 check or uncheck
function set_all_checkbox_select(check_value,obj_name){
	
	obj=document.getElementsByName(obj_name);
	
	for(var i=0;i<obj.length;i++)
		obj[i].checked=check_value;
}

//이메일입력체크. 맞으면 true
function check_valid_email(email){
	/*
	if(isEmptyValue(email))	return false;
	else if(email.indexOf("@")==-1 || email.indexOf(".")==-1) return false;
	else return true;
	*/

	var preg=/^[_a-zA-Z0-9\-\.]+@[\._a-zA-Z0-9\-]+\.[a-zA-Z]{2,}/;

	if(preg.test(email))
		return true;
	else
		return false;

}

//지정된 사이즈로 지정된 페이지 팝업 열기
function open_window(width,height,filepath){
	window.open(filepath,'new','resizable=no width='+width+' height='+height+' scrollbars=yes');
	return false;
}

//지정된 사이즈로 지정된 페이지 팝업 열기(resize yes)
function open_resize_window(width,height,filepath){
	window.open(filepath,'new','resizable=yes width='+width+' height='+height+' scrollbars=yes');
	return false;
}

//form값을 지정한 action으로 열어줌
function open_newpage_submit(action){
	document.open_newpage.action=action;
	document.open_newpage.submit();
}

//main search submit
function main_search_submit(){
	
	if(isEmptyValue(document.main_search.keyword.value)){
		alert("Please input keyword!");
		return false;
	}else
		return true;
}

//disable check,uncheck
function change_objAble(checkStatus,objName){
	
	obj=document.getElementsByName(objName);
	
	if(obj){

		if(checkStatus)
			obj[0].disabled=false;
		else{
			obj[0].value="";
			obj[0].disabled=true;
		}

		return true;

	}else
		return false;

}

//오른쪽 배너 호출
setTimeout("load_right_banner()",2000);