//**************************************
// 드림위버에서 제공하는 함수라이브러리
//**************************************


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.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  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 MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//trim객체
String.prototype.trim = function(){
	return this.replace(/(^[ \f\n\r\t]*)|([ \f\n\r\t]*$)/g, "");
}
//주민번호 검사
function juminCheck(jumin){
	if(jumin.length != 13)
		return false;


	total = 0;
	temp = new Array(13);
	for(i = 1; i <= 13; i++){
		temp[i] = jumin.charAt(i-1);
	}
	for(i = 1; i<=12; i++){
		k = i+1;
		if(k >=10)
			k = k % 10 + 2;
		total = total + temp[i] * k;
	}
	mm = temp[3] + temp[4];
	dd = temp[5] + temp[6];
	totalmod = total % 11;
	chd = (11 - totalmod)%10;
	if(chd == temp[13] && mm < 13 && dd < 32 && (temp[7] == 1 || temp[7] == 2|| temp[7] == 3|| temp[7] == 4))
		return true;

	return false;
}
//사업자번호 검사
function isBusiNo(NUM) {
	var sum = 0;
	var checknum = 0;
	var anum = new Array(10);
	var chknum = new Array("1","3","7","1","3","7","1","3","5");
	for(var i=0;i<10;i++){ anum[i]=NUM.substring(i,i+1); }
	for(var i=0;i< 9;i++){ sum += anum[i]*chknum[i]; }
	sum += parseInt((anum[8]*5)/10);
	checknum = (10 - sum % 10) %10;
	if(checknum != anum[9]){
		return false;
	} else {
		return true;
	}
}

//하이퍼 링크 부분에 <a href="javascript:catalog_open('카달로그 이름');"> 을 작성
function catalog_open(ecatalog_name){
	var win = window.open("http://www.n-catalog.com/album_db/main_album.htm?ecatalog_name="+ecatalog_name,"wCatalog","width=1024,height=768,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no");	
	win.focus();
}


//해당 이미지를 새창 띄우는 스크립트 사용법 : onclick=OpenImage(this.src)
function OpenImage(s){
	srcImg = new Image();
	clientWidth = screen.width;
	clientHeight = screen.height;
	srcImg.src = s;
	
	// 열려는 파일을 이름
	var srcFileName = srcImg.src.substr(srcImg.src.lastIndexOf("/")+1, srcImg.src.length);

	// 새창 띄우고 이미지 삽입
	win = window.open("","","width=15,height=15,scrollbars=no,resizable=no,left="+(clientWidth/2-15)+",top="+(clientHeight/2-15)+"");
	win.document.writeln("<html>");
	win.document.writeln("<head>");
	win.document.writeln("<title>"+document.title+" ["+srcFileName+"]</title>");
	win.document.writeln("</head>");
	win.document.writeln("<body style='margin:0px;' bgcolor='#333333'>");
	win.document.writeln("<table border='0' cellpadding='0' cellspacing='0' style='cursor:hand' onclick='self.close()'>");
	win.document.writeln(" <tr>");
	win.document.writeln("  <td align='center'><img src="+s+" name='winImg' style='cursor:hand' onclick='self.close()' alt='클릭하면 사라집니다'></td>");
	win.document.writeln(" </tr>");
	win.document.writeln("</table>");
	win.document.writeln("</body>");
	win.document.writeln("</html>");

	srcImg = win.document.winImg;

	// 이미지가 모두 로딩될때까지 기다림
	while(true)
			if(srcImg.readyState == "complete")
					break;
	
	// 새창의 크기 설정
	var winWidth = srcImg.width+10;
	var winHeight = srcImg.height+29;

	// 새창이 띄워질 위치 설정
	var left = (clientWidth/2)-(srcImg.width/2);
	var top = (clientHeight/2)-(srcImg.height/2);

	// 이미지의 크기 overflow 확인후 새창의 크기와 위치 재설정
	if(clientWidth <= srcImg.width){
			winWidth = clientWidth;
			left = 0;
			win.document.body.scroll = "auto";
	}
	if(clientHeight <= srcImg.height){
			winHeight = clientHeight-30;
			top = 0;
			win.document.body.scroll = "auto";
	}
	// 이미지로딩이 끝났음으로 이미지의 크기를 사용할수 있다.
	// 해당 이미지의 사이즈에 맞게 윈도우를 재설정한다.
	win.moveTo(left, top);
	win.resizeTo(winWidth, winHeight);
}

function adminOpen(){
	var win = window.open("/admin/login.htm","Admin","width=990,height=800,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no");	
	win.focus();
}

//우편번호찾기
function getPostInfo(return_post1,return_post2,return_addr1){
	var f = document.frm;
	var pop_add = '/core_post/bin/pop_adresscheck.htm?return_post1='+return_post1+'&return_post2='+return_post2+'&return_addr1='+return_addr1;

	window.open(pop_add,"post_search_pop","toolbar=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=1, width=400, height=183,top=300,left=400").focus();
}

// num check
function input_num_check(obj){
	var str = obj.value;
	if(!checkNUM(str)){
		alert("숫자만 입력 가능합니다.");

		while (!checkNUM(str)) {				
			str = str.substring(0,str.length-1);
			obj.value = str;
		}					
		obj.focus();
	}
}

// num check
function checkNUM(str){ 
	var check = '0123456789';
	var temp; 
	for (var i=0; i<str.length; i++) { 
		temp = '' + str.substring(i, i+1); 
		if (check.indexOf(temp) == '-1'){ 
			return false;
		}
	} 
	return true;
}

// num check
function inputNext(trtObj,nxtObj,length){
	if(trtObj.value.length == length){
		nxtObj.focus();
	}                                     
}
