//###공용모듈###
//----------------------------------------------------------------------------------
function ViewCss2(css) {
	document.write("\<link rel=\"stylesheet\" type=\"text/css\" href=\"" + css + "\">");
}



//공백체크
function CheckSpaces(str,m) {
    var flag=true;
    var strValue = str.value;

    if (strValue!=" ") {
       for (var i=0; i < strValue.length; i++) {
          if (strValue.charAt(i) != " ") {
             flag=false;
             break;
          }
       }
    }
	if(flag == true) {
       alert( m + "을(를) 입력하십시요.");
       str.focus();
    }

   
    return flag;
}


function Digit(str) {
	var flag = false;

	if (str.value == "" ) {
		alert("금액을 입력하여주세요");
		str.focus();
		flag = true;

	}else {
		for(i=0; i < str.value.length; i++){
			var tmp_chr = str.value.charAt(i);

			if(/^[0-9]/.test(tmp_chr) == false) {
				alert("금액에는 숫자만 입력이 가능합니다");
				str.value="";
				str.focus();
				flag = true;
				break;
			}
		}
	}
	return flag;
}

//숫자 체크
function Number( str, m ) {
   var flag = false;
   var Digit= "1234567890";
  
   if ( CheckSpaces(str,m) == false) {
	   for(i=0; i<str.value.length;i++) {

		 if(Digit.indexOf(str.value.substring(i, i+1)) == -1){	
			alert(m + "은(는) 숫자만 사용하실 수 있습니다.");
			str.value = "";
			str.focus();	
			flag = true;
			break;
		  }
		  
		}
   } else {
	 flag = true; 
   }
	return flag;
   
}   

function SetNum(obj){			//숫자만 입력
	val=obj.value;
	re=/[^0-9]/gi;
	obj.value=val.replace(re,"");
}


function RateDigit(str) {
	var flag = false;

	for(i=0; i < str.value.length; i++){
			var tmp_chr = str.value.charAt(i);
			if(/^[0-9]/.test(tmp_chr) == false) {
				alert("완료율 입력은 숫자만 가능합니다");
				str.value = "";
				str.focus();
				flag = true;
				break;
			}
	}
	return flag;
}

//영문,숫자 체크
function alphaDigit( str, m ) {
   var flag = false;
   var alphaDigit= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  
   for(i=0; i<str.value.length;i++) {

	 if(alphaDigit.indexOf(str.value.substring(i, i+1)) == -1){	
		alert(m + "은(는) 영문/숫자만 사용하실 수 있습니다.");
		str.focus();	
		flag = true;
		break;
	  }
	  
    }
    return flag;
   
}  

//길이 체크
function CheckLen( str, start, end ) {
	var flag = false;

	if ( str.value.length < start && str.value.length < end ) {
			alert(start + "~" + end + "자 이내로 입력하여 주십시오");
			str.focus();	
			flag = true;
   }

   return flag;
}




function jumin_chk(jumin1,jumin2){

		var jstr=(jumin1.value) + (jumin2.value)+"";
		var dummy = new Array("2","3","4","5","6","7","8","9","2","3","4","5");
		var tot;
		var tmp, chksum;


		tmp = jstr.charAt(2);
		tmp = tmp + jstr.charAt(3);
		if(tmp > 12){
				alert("잘못된 주민등록번호입니다.");  
				return true;
		}

		tmp = jstr.charAt(4);
		tmp = tmp + jstr.charAt(5);
		if(tmp > 31){
				alert("잘못된 주민등록번호입니다.");
				return true;
		}

		  tmp = jstr.charAt(6);
		if(tmp > 4){
				alert("잘못된 주민등록번호입니다.");
				return true;
		}

	   if(jstr.length != 13){
				alert("주민등록번호 자릿수가 맞지 않습니다.");
		jumin1.focus();
				return true;
		}

		tot = 0;
		tmp = 0;
		chksum = 0;

		for(var i=0; i<12; i++){
				tot = tot + (jstr.charAt(i) * dummy[i]);
		}

		tmp = tot%11;
		chksum = 11 - tmp;
		tmp = chksum%10;

		if( jstr.charAt(12) != tmp ){
				alert("잘못된 주민등록번호입니다.");
				return true;
		}

		 return false;

} 




function CheckEqual( str1, str2, m ) {
	var flag = false;

	if ( str1.value !=  str2.value ) {
		alert(m + "가 같지 않습니다");
		str2.value="";
		str2.focus();
		flag = true;
	}
	 return flag;
}


//----------------------------------------------------------------------------------


function number_chk1(){

	var sMoney = event.srcElement.value.replace(/,/g,"");	
		if(isNaN(sMoney)){
		alert("숫자로 입력하세요");        
		event.srcElement.value = "";
		event.srcElement.focus();
		return;
	}

}





function imgResize(img, width, height){//이미지객체, 가로, 세로

var obj = new Image();
obj.src = img.src;
//인자로 받는 이미지객체의 가로세로값을 구하면 가끔씩 0을 반환하는 버그가 난다.
//그래서 경로를 받아서 함수내에서 별개의 이미지 객체를 생성해서 가로세로값을 구한다.

var w = obj.width;
var h = obj.height;

if(width == ''){width = w;}
if(height == ''){height = h;}

var maxWidth = width;
var maxHeight = height;

if(w > maxWidth || h > maxHeight){
if(w > maxWidth){
nw = maxWidth;
if(Math.round((h*nw)/w) > maxHeight){
 nh = maxHeight;
 nw = Math.round((w*nh)/h);
}else{
 nh = Math.round((h*nw)/w);
}
}else if(h > maxHeight){
nh = maxHeight;
if(Math.round((w*nh)/h) > maxWidth){
 nw = maxWidth;
 nh = Math.round((h*nw)/w);
}else{
 nw = Math.round((w*nh)/h);
}
}
}
else{
nw = w;
nh = h;
}
img.width = nw;
img.height = nh;
}




function zipcode(){
	window.open("/manager/content/01info/zipcode_search.asp?","zipcode","scrollbars=yes,toolbar=no,directories=no,menubar=no,resizable=no,status=no,width=468,height=300'");
}


function page_go1(url){
	location.href = url;
}


function page_go2(url){
	window.open(url);
}


//자주쓰는 메뉴에 추가
function mf_chk(mf_ct_idx){
	
	var url = "/manager/content/01favorites/write_ok2.asp?mm_ct_idx=";

	if (confirm('현재 메뉴를 자주쓰는 메뉴에 추가 하시겠습니까?'))	{
		
		page_go1(url+mf_ct_idx);

	}else{
		
		return ;
	
	}

}


function loading_st(val){

	if(val==1){
		
		//document.getElementById('loading_layer').style.display='block'; 
	}else{
		//document.getElementById('loading_layer').style.display='none'; 
	}
}



//관리자UI
function dialog_open(subject, action, formdata){
	$("#dialog").dialog({
		autoOpen: false,
		width: 850,
		height: 700,
		modal: true,
		title: subject
	});

	$("#dialogContent").html("<img style='padding-top:200px' src='/common/js/jquery_ui_images/ajax_loding1_fbisk.gif'>");

/*
	$.ajax({
		url: action,
		cashe: false,
		type: "POST",
		data: formdata,
		success:function(html){
			setTimeout(function(){ $("#dialogContent").html(html); }, 500);
		}
	});
	$('#dialog').dialog('open');
*/


	$.ajax({
		type: "POST",
		url: action,
		//data: ({ b_l_num:num }),
		data: formdata,
		dataType:"html",
		async:false,
		beforeSend:function(){//통신시작할때 처리
			$('#dialog').dialog('open');
		},
		complete:function(){//통신완료후 처리
		},
		error:function(request, status, error){
			alert("code:"+status+"\nmessage:"+request.responseText);
		},
		success: function(html){
			setTimeout(function(){ $("#dialogContent").html(html); }, 500);
		}
	});

}

function dialogFrame_open(subject, action, formdata){
	var url = "";
	$("#dialog").dialog({
		autoOpen: false,
		width: 850,
		height: 700,
		modal: true,
		title: subject
	});
	url = action;
	if(formdata != ""){
		url = url+"?"+formdata;
	}
	$("#dialogContent").html("<iframe id='dialogFrame' style='width:100%;height:650px' frameborder='0' src='"+url+"'></iframe>");

	$('#dialog').dialog('open');
}


//모달창 닫기
function dialog_close()
{
	$("#dialogContent").html("");
	$("#dialog").dialog("close");
}


function setCookie(cookieName, cookieValue, expireDate, httponly){
	var cookie_str = "";
	var expire = new Date();
	expire.setDate(expire.getDate() + parseInt(expireDate) );

	cookie_str = cookieName+"="+escape(cookieValue)+"; expires=" +  expire.toGMTString()+ "; path=/";
	if(httponly != null, httponly != ""){
		//cookie_str += ";httpOnly";
	}

	document.cookie = cookie_str;
}

function getCookie(name){
	var nameOfCookie=name+"=";
	//alert(nameOfCookie);
	var x=0;
	while(x<=document.cookie.length){
		var y=(x+nameOfCookie.length)
		if(document.cookie.substring(x,y)==nameOfCookie){
			if((endOfCookie=document.cookie.indexOf(";",y))==-1)
			endOfCookie=document.cookie.length;
			return unescape(document.cookie.substring(y,endOfCookie));
		}
		x=document.cookie.indexOf(" ",x) +1;
		if(x==0)
		break;
	}
	return "";
}

function deleteCookie(cookieName){
	var expire = new Date();
	expire.setDate(expire.getDate()-1 );
	document.cookie = cookieName+"=''; expires=" +  expire.toGMTString()+ "; path=/";
}