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 sidCheck()
{
	var jumin1,jumin2,a,b,c,d,e,f,g,h,i,j,k,l,sum,pivot,modulus,endnumber;
	jumin1 = document.frm.mem_sid1.value;
	jumin2 = document.frm.mem_sid2.value;
		a = jumin1.substring(0,1)
			aa = a * 2;
		b = jumin1.substring(1,2)
			bb = b * 3;
		c = jumin1.substring(2,3)
			cc = c * 4;
		d = jumin1.substring(3,4)
			dd = d * 5;
		e = jumin1.substring(4,5)
			ee = e * 6;
		f = jumin1.substring(5,6)
			ff = f * 7;
		g = jumin2.substring(0,1)
			gg = g * 8;
		h = jumin2.substring(1,2)
			hh = h * 9;
		i = jumin2.substring(2,3)
			ii = i * 2;
		j = jumin2.substring(3,4)
			jj = j * 3;
		k = jumin2.substring(4,5)
			kk = k * 4;
		l = jumin2.substring(5,6)
			ll = l * 5;

	pivot = jumin2.substring(6,7)
		sum = aa+bb+cc+dd+ee+ff+gg+hh+ii+jj+kk+ll;
		modulus = sum % 11
		endnumber = 11 - modulus

		if(endnumber ==11)
			endnumber = 1;
		else if(endnumber ==10)
			endnumber = 0;
		else
			endnumber = endnumber;
		
		return (pivot != endnumber); //두값이 다르다면 true반환(비정상 주민번호이다.)
}

//주민번호 자동으로 다음칸으로 커서 옮기기
function check1() 
{
  var str = document.frm.mem_sid1.value.length;
  if(str == 6)
    document.frm.mem_sid2.focus();
}    

//주민번호 자동으로 다음칸으로 커서 옮기기
function check2()  
{
  var str = document.frm.mem_sid2.value.length;
  if(str == 7) {
	//주민번호가 번호인지 검사
	if(isNum(document.frm.mem_sid1.value + document.frm.mem_sid2.value)) {
	    document.frm.mem_mail.focus();
		}
	else {
		alert("주민등록번호가 잘못되었습니다. 다시 입력해 주십시요!");
		document.frm.mem_sid1.value=""
		document.frm.mem_sid2.value=""
		document.frm.mem_sid1.focus();
		return false;
		}
	}
}

//로그인
function login()
{
	if(document.frm.mem_id.value.replace(/ /g, "").length == 0) {
		alert("아이디를 입력하세요");
		document.frm.mem_id.focus();
		return false;
	}
	if(document.frm.mem_password.value.replace(/ /g, "").length == 0) {
		alert("패스워드를 입력하세요");
		document.frm.mem_password.focus();
		return false;
	}

}
//공백제거
function fnTrim(chStr)
{
	var vSource;
	var nStrCheck;
 
	vSource = chStr;
	nStrCheck = chStr.indexOf(" ");
 
	while( nStrCheck != -1 )
	{
		chStr = chStr.replace(" ", "");
		nStrCheck = chStr.indexOf(" ");
	}
	return chStr;
}

//한글 사용여부 체크 함수
function isHangul(s) 
{
     var len = s.length;
     for (var i = 0; i < len; i++)  {
         if (s.charCodeAt(i) != 32 && (s.charCodeAt(i) < 44032 || s.charCodeAt(i) > 55203))
             return false;
     }
     return true;
}

//영문 숫자 사용여부 체크
function engnumCheck(word) 
{
	var str="abcdefghijklmnopqrstuvwxyz1234567890";
	for(i=0; i<word.length; i++) {
		chkword=word.charAt(i);
		if((str.indexOf(chkword)) == -1) { return false; }
	}
	return true;
}

//숫자 확인
function isNum(num)
{
	var str="1234567890";
	for(i=0; i<num.length; i++) {
		chknum=num.charAt(i);
		if((str.indexOf(chknum)) == -1) { return false; }
	}
	return true;
}

//메일주소 확인
function checkemail(str)
{	
	if (str.value.indexOf("@") != -1 &&
		str.value.indexOf(".") != -1 &&
		str.value.replace(/ /g, "").length > 5)
		return true;
	else
		return false;	
}

//달력입력
function calendar_onSelectDate() {
   	setTime( getCalCaller(), 1, getCalTime() )
}

//파일크기 구하기
function getFileSize(path)
{
	var img = new Image();
	img.dynsrc = path;
	return img.fileSize;
}

//이미지 보기
function changeImgOver(img) {
	
	var vImg = img;

	var imgSize = new Image();
	imgSize.src=vImg;
	
	imgwidth=imgSize.width;        // 이미지의 넓이
	imgheight=imgSize.height;      // 이미지의 높이

	var defaultwidth = "650";
	var defaultheight = "520";

	if( imgwidth > defaultwidth  ){
		frm.BigImg.width = defaultwidth;
		var ratio = defaultwidth/imgwidth;
		frm.BigImg.height = imgheight * ratio;
	}else{
		frm.BigImg.width = imgwidth;
	}

	if(imgheight > defaultheight){
		frm.BigImg.height=defaultheight;
		var ratio = defaultheight/imgheight;
		frm.BigImg.width=imgwidth*ratio;	
	}else{
		frm.BigImg.height=imgheight;
	}
	frm.BigImg.src = imgSize.src;
}

//파일체크
function fileCheck(formName, type, i)
{	
	if(chk_extension($("#"+formName).val(), type) == false && $("#"+formName).val().replace(/ /g, "").length != 0) {
		alert("첨부파일("+(++i)+"): 첨부파일이 첨부허용되지않는 파일입니다.");
		//validateNumber(fileName);
		return false;
	}

	if(fnCheckSpace($("#"+formName).val()) == false && $("#"+formName).val().replace(/ /g, "").length != 0) {
		alert("첨부파일 ("+(++i)+"): 첨부파일이름에 공백이있습니다 공백을 제거해주십시요.");
		//validateNumber(fileName);
		return false;
	}
	return true;
}

function fileCheckOrg(formName, type, i)
{	
	if(chk_extension(formName.value, type) == false && formName.value.replace(/ /g, "").length != 0) {
		alert("첨부파일("+(++i)+"): 첨부파일이 첨부허용되지않는 파일입니다.");
		//validateNumber(fileName);
		return false;
	}

	if(fnCheckSpace(formName.value) == false && formName.value.replace(/ /g, "").length != 0) {
		alert("첨부파일 ("+(++i)+"): 첨부파일이름에 공백이있습니다 공백을 제거해주십시요.");
		//validateNumber(fileName);
		return false;
	}
	return true;
}

//파일 공백체크하기
function fnCheckSpace(chChar) {
 var aChar = chChar.split("\\");
 var chr;
 chChar = aChar[aChar.length-1];
 
 
 if((/[\s]/).test(chChar)) {
 //alert("x");
  return false;
 } else {
 //alert("o");
  return true;
 }
}

//확장자 검사
function chk_extension(str, type) {
	// 확장자 비교 
	if(type == 1 || type == 6) {//이미지자료
		compStr = new Array("gif","jpg","jpeg","bmp");
	}else if(type == 2) {//동영상 vod
		compStr = new Array("wmv","asf");
	}else if(type == 3) {//플래시
		compStr = new Array("swf");
	}else if(type == 4) {//입체사진
		compStr = new Array("gif");
	}else if(type == 5) {//VR자료
		compStr = new Array("mov","jpg","jpeg");
	}else if(type == 9) {//일반자료
		compStr = new Array("gif","jpg","jpeg","zip","rar","alz","hwp","doc","xls","ppt","mov","pdf","txt"); 
	}

	// 확장자 가져오기 
	idx = str.lastIndexOf('.'); 
	if( idx != -1 ) { 
		ext = str.substring( idx+1); 
	} else { 
		ext = ""; 
	} 
	
	isSubmit = false; 
	if(ext != "") {
		for (var i = 0; i < compStr.length; i++) {
			if (compStr[i] == ext.toLowerCase()) { 
				isSubmit = true;
				//return true; 
				break; 
			}
		}
	}

	if(isSubmit) {
		return true; 
	}else{
		return false;
	}

}

//필터링단어 체크
function chkFilterWord(formName) {
	var str	="";
	
	if(formName == "subject") {
		str = document.frm.bod_subject.value;
	}else if(formName == "content") {
		str = document.frm.con_content.value;
	}else if(formName == "comment") {
		str = document.frm.com_content.value;
	}

	var filter		=document.frm.binf_filterWord.value;
	var filterWord	= filter.split(",");

	if(filterWord != "") {
		for(i=0; i < filterWord.length; i++) {
			if(str.indexOf(filterWord[i]) != -1) {
				return false;
			}
		}
	}
	return true;
}


function imgSize(which){
    var width = eval("document."+which+".width");
    var height = eval("document."+which+".height");
    var temp = 0; 
    var max_width= 600;   // 이미지의 최대 크기     
    
    if ( width > max_width ) {  // 이미지가 600보다 크다면 너비를 600으로 맞우고 비율에 맞춰 세로값을 변경한다.      
       height = height/(width / max_width);
       eval("document."+which+".width = max_width");     
       eval("document."+which+".height = height");
    }     
}

//우편번호 찾기
function searchZipcode() {
	window.open("/common/etc/searchZipcode.jsp", "_searchZipcode", "width=507,height=415,scrollbars=no");
}

//이력관리 우편번호 찾기
function TrcsearchZipcode() {
	window.open("/trace/common/etc/zip_list.jsp", "_searchZipcode", "width=470,height=350,scrollbars=yes");
}

//이력관리 우편번호 찾기
function TrcsearchZipcode2() {
	window.open("/trace/common/etc/zip_list1.jsp", "_searchZipcode", "width=470,height=350,scrollbars=yes");
}

//이력관리 원산지 찾기
function TrcsearchZipcode3() {
	window.open("/trace/common/etc/zip_list2.jsp", "_searchZipcode", "width=470,height=350,scrollbars=yes");
}

//이력관리 원산지 찾기검색
function TrcsearchZipcode4() {
	window.open("/trace/common/etc/zip_list3.jsp", "_searchZipcode", "width=470,height=350,scrollbars=yes");
}


var old = "";
var oldImgID ="";
function viewMenu(menuID) 
{
	var form	= eval("MNU_"+menuID);
	if(old != form) {
		if(old != "") {
			old.style.display = "none";
			offImgOnMenu(oldImgID);
		}
		form.style.display = "block";
		onImgMenu(menuID);
		old			= form;
		oldImgID	= menuID;
	} else {
		form.style.display = "none";
		offImgOnMenu(oldImgID);
		old = "";
	}

	

}
function changeImgOut(img) {	
	var vImg = img;
	frm.BigImg.src = vImg;
}

function onImgMenu(menuID) {	
	var imgPath = "../images/menu/menu_"+menuID+"_on.gif";
	var form = eval("document.all.IMG_"+menuID);
	form.src = imgPath;
}

function offImgOnMenu(menuID) {	
	var imgPath = "../images/menu/menu_"+menuID+"_off.gif";
	var form = eval("document.all.IMG_"+menuID);
	form.src = imgPath;
}

//라디오박스 체크
function ValidateForm(theForm)
{
	is_checked = true;

	if(theForm.length > 1) {
		for (i=0;i<theForm.length;i++) {
			if (theForm[i].checked) {
				is_checked = false;
				break;
			}
		} 
	}else{
			if (theForm.checked) {
				is_checked = false;
			}
	}
	if (is_checked){
	//alert('선택사항을 한개 이상 선택해 입력해 주십시요');
		return false;
	}
}

// 그냥 n millis 동안 멈추기
function pause(numberMillis) {
     var now = new Date();
     var exitTime = now.getTime() + numberMillis;

     while (true) {
          now = new Date();
          if (now.getTime() > exitTime)
              return;
     }
}


// 모달창 띄우면서 n millis 동안 멈추기
function pauseWithModal(numberMillis) {
        var dialogScript = 
           'window.setTimeout(' +
           ' function () { window.close(); }, ' + numberMillis + ');';
        var result = 
        // IE
         window.showModalDialog(
           "");

        // NN
        /* openDialog(
           "");
        */
}

// Portal => ShopMall 로그인
function shopLogin(form){
	shopWinDoc = window.open("","shopWin","");
	form.target = "shopWin";
	form.submit();
	
}