//레이어 팝업(iframe)_blockUI
function popupLayer(action, width, height) {
	var obj = "<iframe src='" + action + "' width='100%' height='100%' frameborder='0' marginheight='0' marginwidth='0' scrolling='no'/>";
	var posTop;
	var posLeft;

	//IE
	if ($.browser.msie) {
		posTop = (document.documentElement.offsetHeight - height) / 2;
		posLeft = (document.documentElement.offsetWidth - width) / 2;
	} else {
		posTop = (window.innerHeight - height) / 2;
		posLeft = (window.innerWidth - width) / 2;
	}

	if (posTop < 0) {
		posTop = 0;
	}

	if (posLeft < 0) {
		posLeft = 0;
	}

	$.blockUI({
		message: $(obj),
		css: {
			width: width + "px",
	 		height: height + "px",
	   		top: posTop + "px",
	  		left: posLeft + "px",
	  		border : '5px solid #8AC4DE'
	  	}
	});
}

//레이어 팝업 다중
function popupLayerMulti(action, width, height, top, left, popIdx) {
	var obj = "<iframe src='" + action + "&popIdx=" + popIdx + "' width='100%' height='100%' frameborder='0' marginheight='0' marginwidth='0' scrolling='no'/>";
	var posTop = top;
	var posLeft = left;

	//IE
	if ($.browser.msie) {
		if (posTop == "") {
			posTop = (document.documentElement.offsetHeight - height) / 2;
		}
		if (posLeft == "") {
			posLeft = (document.documentElement.offsetWidth - width) / 2;
		}
	} else {
		if (posTop == "") {
			posTop = (window.innerHeight - height) / 2;
		}
		if (posLeft == "") {
			posLeft = (window.innerWidth - width) / 2;
		}
	}

	if (posTop < 0) {
		posTop = 0;
	}

	if (posLeft < 0) {
		posLeft = 0;
	}

	obj = "<div class='layerPopup" + popIdx + "' style='z-index:99;background-color: #ffffff; position: absolute; top: " + top + "px; left: " + left + "px; width: " + width + "px; height: " + height + "px;'>" + obj + "</div>";
	
	//$("body").html($("body").html() + obj);
	$("body").append(obj);
}

//레이어 팝업(object)
function popupLayerByObject(obj, width, height) {
	var posTop;
	var posLeft;

	//IE
	if ($.browser.msie) {
		posTop = (document.documentElement.offsetHeight - height) / 2;
		posLeft = (document.documentElement.offsetWidth - width) / 2;
	} else {
		posTop = (window.innerHeight - height) / 2;
		posLeft = (window.innerWidth - width) / 2;
	}

	if (posTop < 0) {
		posTop = 0;
	}

	if (posLeft < 0) {
		posLeft = 0;
	}

	$.blockUI({
		message: obj,
		css: {
			width: width + "px",
	 		height: height + "px",
	   		top: posTop + "px",
	  		left: posLeft + "px",
	  		border : '5px solid #8AC4DE'
	  	}
	});
}

//레이어 팝업(object) - 투명
function popupLayerByObjectTransparent(obj, width, height) {
	var posTop;
	var posLeft;

	//IE
	if ($.browser.msie) {
		posTop = (document.documentElement.offsetHeight - height) / 2;
		posLeft = (document.documentElement.offsetWidth - width) / 2;
	} else {
		posTop = (window.innerHeight - height) / 2;
		posLeft = (window.innerWidth - width) / 2;
	}

	if (posTop < 0) {
		posTop = 0;
	}

	if (posLeft < 0) {
		posLeft = 0;
	}

	$.blockUI({
		message: obj,
		css: {
			width: width + "px",
	 		height: height + "px",
	   		top: posTop + "px",
	  		left: posLeft + "px",
	  		border : '5px solid #8AC4DE'
	  	},
		overlayCSS:  {
			backgroundColor: '#000',
			opacity:	  	 0,
			cursor:		  	 'wait'
		}
	});
}

//윈도우 팝업
function popupWin(url, width, height, target, centerYn, top, left) {
	var posTop;
	var posLeft;

	if (centerYn == "Y") {
		//IE
		if ($.browser.msie) {
			posTop = (document.documentElement.offsetHeight - height) / 2;
			posLeft = (document.documentElement.offsetWidth - width) / 2;
		} else {
			posTop = (window.innerHeight - height) / 2;
			posLeft = (window.innerWidth - width) / 2;
		}

		if (posTop < 0) {
			posTop = 0;
		}

		if (posLeft < 0) {
			posLeft = 0;
		}
	} else {
		posTop = top;
		posLeft = left;
	}

	window.open(url
							, target
							, "top=" + posTop
								+ ", left=" + posLeft
								+ ", width=" + width
								+ ", height=" + height
								+ ", toolbar=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
}

//아이디 패스워드 체크(영문,숫자 조합)
function idPassCheck(param) {
	chk1 = /^[a-z\d]{6,20}$/i;  //a-z와 0-9이외의 문자가 있는지 확인
	chk2 = /[a-z]/i;  //적어도 한개의 a-z 확인
	chk3 = /\d/;  //적어도 한개의 0-9 확인
	return chk1.test(param) && chk2.test(param) && chk3.test(param);
}

//페이징
function fnc_goPage(page){
	var url = location.href.split("?");
	var loc;
	if (url.length >1) {
		loc = url[0];
	} else {
		loc = url;
	}
	
	location.href = loc + "?page=" + page;
}
//페이징
function fnc_goPage2(page,option){
	var url = location.href.split("?");
	var loc;
	if (url.length >1) {
		loc = url[0];
	} else {
		loc = url;
	}
	
	location.href = loc + "?page=" + page + option;
}
//페이징
function fnc_goPage3(page,region,search_text,ca){
	var url = location.href.split("?");
	var loc;
		
	location.href = "?page=" + page +"&region=" + region + "&search_text=" +search_text+"&ca="+ca;
}
/*
 * 숫자열을 3자리마다 "," 표 찍기
 */
function formatMoney(strNumber,mode){
    var nLength=strNumber.length;
    var i=0,j=0;
    var strResult='';
    if(mode=='INSERT'){
        var j=0;
        for(i=nLength-1;i>=0;i--){
            j++;
            strResult=strNumber.substring(i,i+1)+strResult;
            if(j%3==0 && i>0){
                strResult=','+strResult;
            }
        }
    }else if( mode=='DELETE'){
        for(i=nLength-1;i>=0;i--){
            if(strNumber.substring(i,i+1)!=','){
                strResult=strNumber.substring(i,i+1)+strResult;
            }
        }
    }
    return strResult;
}

//날짜 더하기
function addDate(date, num) {
	var sp = "/";
	var d1 = date.split(sp);
	var d2 = new Date(d1[0], d1[1] - 1, d1[2]);
	d2.setDate(d2.getDate() + parseInt(num));
	
	return d2.getFullYear() + sp + (d2.getMonth() + 1 < 10 ? "0" + (d2.getMonth() + 1) : (d2.getMonth() + 1))
		+ sp + (d2.getDate() < 10 ? "0" + d2.getDate() : d2.getDate())
}
 
//두 날짜 비교
function compareDate(startDate,endDate) {
	var start_dates = startDate.split("/");
	var end_dates = endDate.split("/");
 
	var date1 = new Date(start_dates[0],start_dates[1] - 1,start_dates[2]).valueOf();
	var date2 = new Date(end_dates[0],end_dates[1] - 1,end_dates[2]).valueOf();
 
	return (date2 - date1) / 1000 / 60 / 60 / 24;
}

//Request 파라메터 취득
function Request(valuename) {
	var rtnval = "";
	var nowAddress = unescape(location.href);
	var parameters = (nowAddress.slice(nowAddress.indexOf("?")+1,nowAddress.length)).split("&");
	
	for(var i = 0 ; i < parameters.length ; i++){
		var varName = parameters[i].split("=")[0];
		if(varName.toUpperCase() == valuename.toUpperCase())
		{
			rtnval = parameters[i].split("=")[1];
			break;
		}
	}
	return rtnval;
}

//쿠키설정
function setCookie(name, value, expiredays) {
   var todayDate = new Date();
   
   if(expiredays !=null){
   todayDate.setDate( todayDate.getDate() + expiredays );
   document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
   }else{
	   document.cookie = name + "=" + escape( value ) + ";"
   }
   
}

//쿠키 가져오기
function getCookie(strName){
	var strArg = new String(strName + "="); 
	var nArgLen, nCookieLen, nEnd;
	var i = 0, j;
     
	nArgLen    = strArg.length;
	nCookieLen = document.cookie.length;
     
	if(nCookieLen > 0) {
     
		while(i < nCookieLen) {
			j = i + nArgLen;

			if(document.cookie.substring(i, j) == strArg) {
				nEnd = document.cookie.indexOf (";", j);

				if(nEnd == -1) nEnd = document.cookie.length;

				return unescape(document.cookie.substring(j, nEnd));
			}

			i = document.cookie.indexOf(" ", i) + 1;
			if (i == 0) break;
		}
	}
     
	return("");
}

//보안이미지 문자 가져오기
function refreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}
