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


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;
}

//하이퍼 링크 부분에 <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/pop_adresscheck.php?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=283,top=300,left=400").focus();
}


//**************************************
// 메인메뉴용 스크립트 Start
//**************************************
var m1_timerID;
var d1,d2,d3,d4,mid;

function m1_mouseout(){
    m1_timerID = setTimeout("call()",500)

}

function m1_mouseover(){ 
    clearTimeout(m1_timerID)
}

function call(){
 if(d1 == "00") {
  //this.src = this.src.replace("_on.gif", "_off.gif"); 
  var topnav = document.getElementById("navi");
  var topEl2 = topnav.getElementsByTagName("li");
  for(i = 0 , seq = 1; i < topEl2.length ; i++){
   if(topEl2[i].id.substring(0,8) == "top-menu") {
    initTopMenu(topEl2[i],d1);
   }
  }
 }
 initTopmenuByMenuId(d1,d2,d3,d4,mid);
}

function initTopMenu(el,depth1) {

	topMenuOut(el,depth1,el.getElementsByTagName("img").item(0));
	
	if(el.id == "top-menu" + depth1) {
		topMenuOver(el.getElementsByTagName("img").item(0));
	}
}

function topMenuOut(el,depth1,img) {
	img.src = img.src.replace("_on.gif", "_off.gif");		
}

function topMenuOver(img) {
	img.src = img.src.replace("_off.gif", "_on.gif");
}

function initTopmenuByMenuId(depth1, depth2, depth3, depth4, menuId) {
	d1 = depth1;
	d2 = depth2;
	d3 = depth3;
	d4 = depth4;
	mid = menuId;
	var selectDepth1 = "top-" + depth1 + "-" + depth2;
	var selectDepth2 = "top-" + depth1 + "-" + depth2 + "-" + depth3;
	var selectDepth3 = "top-" + depth1 + "-" + depth2 + "-" + depth3 + "-" + depth4;
	var topnav = document.getElementById("navi");
	if(!topnav) return;
	var topEl = topnav.getElementsByTagName("ul");
	for(var i = 0 ; i < topEl.length ; i++){
		if(topEl[i].id.substring(0,12) == "top-sub-menu") {
			topEl[i].style.display = "none";
		}
	}
	
	var topEl2 = topnav.getElementsByTagName("a");

	for(i = 0, seq = 0 ; i < topEl2.length ; i++){
		if(topEl2[i].id.substring(0,13) == "top-menu-head") {
			topEl2[i].onmouseover =  selectTopmenuByMenuId;
			topEl2[i].onfocus = selectTopmenuByMenuId;
			if ( topEl2[i].id.substring(13) == depth1) {
				topEl2[i].onmouseover();
			}
			seq++;
		}
	}
	
	var nav = document.getElementById("top-" + menuId);
	if(!nav) return;
	nav.style.display = "block";
	menuEl = nav.getElementsByTagName("li");
	for(i = 0; i < menuEl.length; i++) {
		var menuElItm = menuEl.item(i);
		var imgEl = menuElItm.getElementsByTagName("img");
		if(imgEl == null || imgEl.length == 0)  {
			var aEl = menuElItm.getElementsByTagName("a");
			var itm = aEl.item(0);
			if (menuElItm.id == selectDepth1 || menuElItm.id == selectDepth2  || menuElItm.id == selectDepth3  ) {
				itm.className = "on";
			}
		} else {
			var itm = imgEl.item(0);
			if (menuElItm.id == selectDepth1 || menuElItm.id == selectDepth2  || menuElItm.id == selectDepth3  ) {
				itm.src = itm.src.replace("_off.gif", "_on.gif");
				itm.onmouseover = null;
				itm.onmouseout = null;
				itm.onfocus = null;
				itm.onblur = null;
			}
			else {
				itm.onmouseover = menuOver;
				itm.onmouseout = menuOut;
				itm.onfocus = menuOver;
				itm.onblur = menuOut;
			}
		}
	}
}

function selectTopmenuByMenuId() {
	var depth1 = this.id.substring("top-menu-head".length,this.id.length);
	var menuId = "sub-menu" + depth1;		
	var selectDepth1 = "top-" + depth1 + "-1";
	var topnav = document.getElementById("navi");
	if(!topnav) return;
	var topEl = topnav.getElementsByTagName("ul");
	for(i = 0 ; i < topEl.length ; i++){
		if(topEl[i].id.substring(0,12) == "top-sub-menu") {
			topEl[i].style.display = "none";
		}
	}
	var topEl2 = topnav.getElementsByTagName("li");
	for(i = 0 , seq = 1; i < topEl2.length ; i++){
		if(topEl2[i].id.substring(0,8) == "top-menu") {
			initTopMenu(topEl2[i],depth1);
		}
	}
	
	var nav = document.getElementById("top-" + menuId);
	if(!nav) return;
	nav.style.display = "block";
	menuEl = nav.getElementsByTagName("li");
	for(i = 0; i < menuEl.length; i++) {
		var imgEl = menuEl.item(i).getElementsByTagName("img")
		if(imgEl != null && imgEl.length>0) {
			imgEl.item(0).onmouseover = menuOver;
			imgEl.item(0).onmouseout = menuOut;
			imgEl.item(0).onfocus = menuOver;
			imgEl.item(0).onblur = menuOut;
		}
	}
} 


function menuOver() {
	var s = this.src;
	s = s.replace("_on.gif", "_off.gif");
	this.src = s.replace("_off.gif", "_on.gif");
}

function menuOut() {
	this.src = this.src.replace("_on.gif", "_off.gif");	
}

function menuOverS() {
	var s = this.src;
	s = s.replace("_on.gif", "_off.gif");
	this.src = s.replace("_off.gif", "_on.gif");
	//this.parentNode.parentNode.style.backgroundImage = 'url(/Image/common/bul/bl_arr02.gif)';
}

function menuOutS() {
	this.src = this.src.replace("_on.gif", "_off.gif");	
	//this.parentNode.parentNode.style.backgroundImage = 'url(/Image/common/bul/bl_arr01.gif)';
}
//**************************************
// 메인메뉴용 스크립트 End
//**************************************

