/****************************** Document info Auth : RedCat Project : Location : /jscss Filename : lib.common.js Update : 2004-02-23 Updater : 김인호(tree92@joy1004.com) Comment : ******************************/ //document.domain = "newsk.com"; if (document.layers){ var wb = 'ns4'; } else if (document.all){ var wb = 'ie'; } else if (document.getElementById){ var wb = 'ns6'; } //############################################################################################### // 작성자 : 김인호(tree92@webax.pe.kr) // 작성일 : 2004년 2월 19일 // 설 명 : 문자열이 알파벳과 숫자로만 구성되어 있는지 확인 // pCheckID = 1 : 아이디 검사로 이용 // 사용예 : checkAlpa("_AAAA", 1) => return false function checkAlpaNum(pValue, pCheckID) { //일반형태의 ID는 alphanumeric만 가능. var regExpr = /^[a-zA-Z0-9]+$/; var regExpr2= /^[a-zA-Z]+$/; if (regExpr.test(pValue)) //alphanumeric으로만 구성되어 있으면 OK! { return true; } else //한글과 alphanumeric인지 검사. { var chrOrig; if(pCheckID = 1) { if ( !regExpr2.test(pValue.substring(0, 1)) ) { alert("아이디의 첫글자는 알파벳이어야합니다."); return false; } } for( var intinx = 0; intinx <= pValue.length -1 ; intinx++ ) { chrOrig = pValue.substring(intinx,intinx+1); if (!regExpr.test(chrOrig)) { alert ("문자는 알파벳, 숫자로만 구성되어야 합니다."); return false; } } } return true; } //############################################################################################### //숫자,알파벳만////////////////////////////////////////////// function chkAlNum(pValue) { for(var i=0; i="A" && pCh <="Z") continue; if(pCh >="0" && pCh <="9") continue; if(pCh =" ") continue; return false; } } //공백체크//////////////////////////////////////////////////// function chkSpace(pValue) { if (pValue.indexOf(" ")>=0) { return true; }else { return false; } } //한글체크//////////////////////////////////////////////////// function chkHan(pValue) { for(i=0;i 128) { return true; }else{ return false; } } } //숫자체크//////////////////////////////////////////////////// function chkNum(x){ var x; var anum=/(^\d+$)|(^\d+\.\d+$)/ if (anum.test(x)) return true; else{ return false; } } //주민등록번호체크////////////////////////////////////////// function chkJumin(p_jumin1,p_jumin2) { errfound = false; var p_jumin1; var p_jumin2; var checkImg=''; var i3=0 for (var i=0;i'9') { i3=i3+1 } } if ((p_jumin1 == '') || ( i3 != 0 )) { return false; } var i4=0 for (var i=0;i'9') { i4=i4+1 } } if ((p_jumin2 == '') || ( i4 != 0 )) { return false; } // 출생년도 검사 if(p_jumin1.substring(0,1) < 0) { return false; } // 남녀 성별 확인 if(p_jumin2.substring(0,1) > 4) { return false; } if((p_jumin1.length > 7) || (p_jumin2.length > 8)) { return false; } if ((p_jumin1 == '72') || ( p_jumin2 == '18')) { return false; } var f1=p_jumin1.substring(0,1) var f2=p_jumin1.substring(1,2) var f3=p_jumin1.substring(2,3) var f4=p_jumin1.substring(3,4) var f5=p_jumin1.substring(4,5) var f6=p_jumin1.substring(5,6) var hap=f1*2+f2*3+f3*4+f4*5+f5*6+f6*7 var l1=p_jumin2.substring(0,1) var l2=p_jumin2.substring(1,2) var l3=p_jumin2.substring(2,3) var l4=p_jumin2.substring(3,4) var l5=p_jumin2.substring(4,5) var l6=p_jumin2.substring(5,6) var l7=p_jumin2.substring(6,7) hap=hap+l1*8+l2*9+l3*2+l4*3+l5*4+l6*5 hap=hap%11 hap=11-hap hap=hap%10 if (hap != l7) { return false; } var i9=0 if (!errfound) return true; } //이메일체크///////////////////////////////////////// function chkMail(pValue) { if(chkSpace(pValue)){ //alert ("E메일 주소에서 공란을 빼주십시오"); return false; }else if (pValue.indexOf("/")!=-1 || pValue.indexOf(";") !=-1 || chkHan(pValue)) { //alert("E-Mail형식이 잘못되었습니다.\n 다시한번 확인바랍니다."); return false; }else if ((pValue.length != 0) && (pValue.search(/(\S+)@(\S+)\.(\S+)/) == -1)) { //alert("E-Mail형식이 잘못되었습니다..\n 다시한번 확인바랍니다."); return false; }else{ return true; } } //trim////////////////////////////////////////////////// function trim(ment){ var start; var end; for(i=0;i -1; i--){ mentcnt = ment.substring(i,i+1); if (mentcnt != ' ') { end=i; break } } str = ment.substring(start,end+1); if (str == ' ') { str = ''; } return str; } // 콤마 넣기 ////////////////////////////////////////// function setComma(values) { var rtn = ""; var val = ""; var j = 0; x = values.length; for(i=x; i>0; i--) { if(values.substring(i,i-1) != ",") { val = values.substring(i,i-1)+val; } } x = val.length; for(i=x; i>0; i--) { if(j%3 == 0 && j!=0) { rtn = val.substring(i,i-1)+","+rtn; }else { rtn = val.substring(i,i-1)+rtn; } j++; } return rtn; } // 콤마 삭제 //////////////////////////////////////// function srtipComma(frm){ var val=''; x = frm.length; for(i=x; i>0; i--) { if(frm.substring(i,i-1) != ",") { val = frm.substring(i,i-1)+val; } } return val; } // 문서내 id = imgID 인 이미지 크기 조절 /////////////////////// function reSetImgSize(mxw, mxh, imgID) { mxw = mxw?mxw:400; mxh = mxh?mxh:300; var maxheight = mxh; var maxwidth = mxw; var img_properties = new Array(); if(wb == 'ns6') { var imgs = document.getElementById[imgID]; } else if (wb == 'ie') { var imgs = document.all.imgID; } else if (wb == 'ns4') { var imgs = document.layers[imgID]; } else { return false; } alert(typeof(imgs)); if (imgs.length == 0) { return false; } for(i=0; i 0 && maxheight >0) { img_properties[0] = imgs[i].width; img_properties[1] = imgs[i].height; if(img_properties[0]>maxwidth||img_properties[1]>maxheight) { height = (maxwidth*img_properties[1])/img_properties[0]; width = maxwidth; if(height > maxheight) { width = (maxheight*img_properties[0])/img_properties[1]; height = maxheight; } }else { height = img_properties[1]; width = img_properties[0]; } }else { height = img_properties[1]; width = img_properties[0]; } imgs[i].width = width; imgs[i].height = height; imgs[i].style.cursor = "hand"; } } //########################################################################################## //새창열기///////////////////////////////////////////// function openWindow(pUrl, pTarget, pWidth, pHeight, pScroll, pToolbar, pResizable, pStatus) { var pLeftPos= (screen.width - pWidth) / 2; var pTopPos = (screen.height - pHeight) / 2; pToolbar = pToolbar?pToolbar:"no"; pResizable = pResizable?pResizable:"no"; pStatus = pStatus?pStatus:"no"; pScroll = pScroll?pScroll:"yes"; window.open(pUrl, pTarget, "top="+pTopPos+",left="+pLeftPos+',width='+pWidth+',height='+pHeight+',toolbar='+ pToolbar+',resizable='+pResizable+',scrollbars='+pScroll+',status='+pStatus); } function openWindow2(pURL, pName, pWidth, pHeight, pResizable, pScrollbars) { var winWidth = pWidth; // 새창 너비 var winHeight = pHeight; // 새창 높이 var winURL = pURL; // 새창으로 띄울 URL var winName = pName; // 새창의 창이름 var winPosLeft = (screen.width - winWidth) / 2; // 새창 Y 좌표 var winPosTop = (screen.height - winHeight) / 2; // 새창 X 좌표 var winMenubar = 0; //메뉴바를 보여주거나 숨깁니다 var winScrollbars = pScrollbars; //스크롤바를 보여주거나 숨깁니다 var winStatus = 1; //상태표시줄을 보여주거나 숨깁니다 var winResizable = pResizable; //팝업윈도우의 크기를 사용자가 임의로 수정할 수 있는지 여부를 지정합니다 var winLocation = 0; //주소표시줄을 보여주거나 숨깁니다 var winToolbar = 0; //도구막대를 보여주거나 숨깁니다 var winDirectories = 0; //디렉토리바를 보여주거나 숨깁니다 var winOpt = "width="+winWidth+",height="+winHeight+",top="+winPosTop+",left="+winPosLeft; window.open(winURL, winName, winOpt + ""); } //-------------------------------------------------------------------------------- // 보이는 창에서 프로세스 처리 //-------------------------------------------------------------------------------// function openFormWindow(pUrl, pTarget, pWidth, pHeight, pResizable, pScroll, pToolbar, pStatus){ var pLeftPos = (screen.width - pWidth) / 2; var pTopPos = (screen.height - pHeight) / 2; pToolbar = pToolbar?pToolbar:"no"; pResizable = pResizable?pResizable:"no"; pStatus = pStatus?pStatus:"yes"; pScroll = pScroll?pScroll:"yes"; var pWinStyle = "width="+pWidth+",height="+pHeight+",location=no,directories=no,menubar=no,toolbar="+pToolbar+",status="+pStatus+",scrollbars="+pScroll+",resizable="+pResizable+",top="+pTopPos+",left="+pLeftPos; var showWindow = window.open(pUrl, pTarget, pWinStyle); try { showWindow.focus(); } catch (e) { } } function openFormWindow2(pUrl, pTarget, pLeft, pTop, pWidth, pHeight, pResizable, pScroll, pToolbar, pStatus, pCenter){ pLeftPos = pLeft pTopPos = pTop if(pCenter) { var pLeftPos = (screen.width - pWidth) / 2; var pTopPos = (screen.height - pHeight) / 2; } pToolbar = pToolbar?pToolbar:"no"; pResizable = pResizable?pResizable:"no"; pStatus = pStatus?pStatus:"yes"; pScroll = pScroll?pScroll:"yes"; var pWinStyle = "width="+pWidth+",height="+pHeight+",location=no,directories=no,menubar=no,toolbar="+pToolbar+",status="+pStatus+",scrollbars="+pScroll+",resizable="+pResizable+",top="+pTopPos+",left="+pLeftPos; var showWindow = window.open(pUrl, pTarget, pWinStyle); try { showWindow.focus(); } catch (e) { } } //---------------------------------------------------------------------------- // 폼값(Post값)을 팝업창에 전송 //---------------------------------------------------------------------------// function sendFormWindow(oForm, pUrl, pTarget, pWidth, pHeight, pResizable, pScroll, pToolbar, pStatus) { oForm.action = pUrl; oForm.target = "openFormWindow"; openFormWindow(pUrl, pTarget, pWidth, pHeight, pResizable, pScroll, pToolbar, pStatus); oForm.submit(); } //########################################################################################## //########################################################################################## // 함수명 : checkFromElement // 인 자 : 폼객체(f, pEscElements) // 내 용 : 모든폼을 체크해 줍니다. (제외될 구성요소 : "name1,name2,name3,...") // 반환값 : // 작성자 : 권연현 // 작성일 : 2003년 10월 22일 수요일 function checkFromElement(f, pEscElements) { //-- 체크하지 않을 녀석들의 이름을 넣는다 //-- "이름1,이름2,이름3,..." 형태를 취한다. var pFilter = pEscElements; for (var i=0; i < f.elements.length; i++) { //-- 체크하지 않을 녀석인가를 알아본다. if ( pFilter.indexOf(f.elements[i].name) >= 0) continue; var k=0; if (f.elements[i].type == "radio" || f.elements[i].type == "checkbox") { for(var j=0; j < eval("f."+ f.elements[i].name +".length"); j++) { if (eval("f."+ f.elements[i].name +"[j].checked")) k++; } if (k < 1) { alert("필수입력사항입니다."); f.elements[i].focus(); return false; } } else if (f.elements[i].type == "image" || f.elements[i].type == "button" || f.elements[i].type == "submit" || f.elements[i].type == "reset") { } else { if (!f.elements[i].value) { alert("필수입력사항입니다."); f.elements[i].focus(); return false; } } } return true; } //########################################################################################## //########################################################################################## // 쿠키값 가져오기 function getCookie( name ) { var nameOfCookie = name + "="; 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 getCookie(Name) { var search = Name + "=" var returnvalue = ""; if (document.cookie.length > 0) { offset = document.cookie.indexOf(search) if (offset != -1) { // 쿠키가 있다면 offset += search.length end = document.cookie.indexOf("&", offset); if (end == -1) end = document.cookie.length; returnvalue=unescape(document.cookie.substring(offset, end)) } } return returnvalue; } */ //########################################################################################## //########################################################################################## // 오늘날짜 얻기 function getToday(sSpliter){ var sToday = "", sDate, sMonth = "", sDay = ""; sDate = new Date(); //Date 개체를 만듭니다. sMonth = sDate.getMonth() + 1; sDay = sDate.getDate(); if(parseInt(sMonth) < 10) { sMonth = "0"+sMonth; } if(parseInt(sDay) < 10) sDay = "0"+sDay; sToday += sDate.getYear() + sSpliter; //연도를 가져옵니다. sToday += sMonth + sSpliter; //월을 가져옵니다. sToday += sDay; //일을 가져옵니다. return(sToday); } //########################################################################################## // --------- --------- --------- --------- --------- function stripTag(value) //태그벗기기 { var sTag = value.replace(/[<][^>]*[>]/gi,"") sTag = sTag.replace(/ /gi,"") return sTag } // --------- --------- --------- --------- --------- // --------- --------- --------- --------- --------- function objectViewer(oObject) { document.write(document.getElementById(oObject).value); } function swfObjectViewer(src, width, height){ object = ''; object += ''; object += ''; object += '<\/embed>'; object += '<\/object>'; document.write(object); } // --------- --------- --------- --------- --------- // --------- --------- --------- --------- --------- function getFileExt(fileName) { if (!fileName) return; fileExt = fileName.substr(fileName.lastIndexOf(".") + 1); fileExt = fileExt.toLowerCase(); return fileExt; } // --------- --------- --------- --------- ---------