Санаа авхаар зарим нэг script үүд байна
//=======================================================
// 입력값 검사 관련 함수
//
function isNumeric(el){var pattern=/^(-{0,1})([0-9]+)(\.{0,1})([0-9]*)$/;return (pattern.test(el.value)) ? true : doError(el,"숫자형식을 입력하세요.");}
function isEnglish(el){var pattern=/^([a-zA-Z ]+)$/;return (pattern.test(el.value)) ? true : doError(el,"영문자를 입력하세요.");}
function isEngNumeric(el){var pattern=/^([0-9a-zA-Z ]+)$/;return (pattern.test(el.value)) ? true : doError(el,"영문자와 숫자를 입력하세요.");}
function isNotNull(el,msg){return (el.value.replace(/ /g, "").length>0) ? true : doError(el,msg);}
function isGoodID(el){var pattern=/^[a-zA-Z]{1}[_a-zA-Z0-9-]{3,}$/;return (pattern.test(el.value)) ? true : doError(el,"아이디는 영문자로 시작하고 영숫자, 하이픈(-), 언더바(_)를 조합하여 4자이상으로 입력하세요.");}
function isGoodPass(el){var pattern=/^[_a-zA-Z0-9!#$%&()*+\.:;<=>?@{|}~-]{4,}$/;return (pattern.test(el.value)) ? true : doError(el,"비밀번호는 영숫자와 특수문자(!#$%&()*+-.:;<=>?@^_{|}~)를 조합하여 4자이상으로 입력하세요.");}
function isEmail(el){var pattern=/^[_a-zA-Z0-9-\.]+@[\.a-zA-Z0-9-]+\.[a-zA-Z]+$/;return (pattern.test(el.value)) ? true : doError(el,"올바른 메일주소를 입력하세요.");}
function isDomain(el){var pattern=/^(http:\/\/)?(www\.)?([_가-힝a-zA-Z0-9-]+\.)+[a-zA-Z]{2,3}(\/[_가- 힝a-zA-Z0-9-]+)*/i;return (pattern.test(el.value)) ? true : doError(el,"올바른 URL을 입력하세요.");}
function isPhone(el, value){var pattern=/^([0]{1}[0-9]{1,3})-?([1-9]{1}[0-9]{2,3})-?([0-9]{4})$/; var num=value?value:el.value;if(pattern.test(num)){return true;}else{return doError(el,"올바른 전화번호를 입력하세요.");}}
function isRadioChecked(el, msg){var b=false;if(el.length){for(var i=0; i<el.length; i++)if(el[i].checked){b=true; break}}else b=el.checked; return b ? true : doError(el,msg);}
function isSelected(el, msg, n){if(!n)n=0; return el.selectedIndex>n ? true : doError(el,msg);}
//-------------------------------------------------------
function doError(el,msg){alert(msg);try{el.value="";el.focus();}catch(e){} return false;}
function numOnly(e){var key = (window.event) ? event.keyCode : (e.keyCode!=0 ? e.keyCode : e.charCode); if((key!=8&&key!=9&&key!=13&&key!=46&&key<48)||(key>57)){ if(window.event) e.returnValue=false; else e.preventDefault(); }}
function nextInput(e1,e2,m){if(e1.value.length==m) e2.focus();}
//-------------------------------------------------------
function isJumin(el,value){var pattern=/^([0-9]{6})-?([0-9]{7})$/;var num=value?value:el.value;var msg="올바른 주민등록번호를 입력하세요.";
if(!pattern.test(num)) return doError(el,msg);num=RegExp.$1+RegExp.$2;var sum=0;var last=num.charCodeAt(12)-0x30;var bases="234567892345";
for(var i=0;i<12;i++){if(isNaN(num.substring(i,i+1))) return doError(el,msg);sum+=(num.charCodeAt(i)-0x30)*(bases.charCodeAt(i)-0x30);}
var mod=sum%11;return ((11-mod)%10==last) ? true : doError(el,msg);}
function checkJumin(e1,e2){if(e1.value.length>0 && e2.value.length>0){if(!isJumin(e1,e1.value+e2.value)){e2.value="";return false;} else return true;} else return false;}
//-------------------------------------------------------
function isBusinessNum(el,value){var pattern=/^([0-9]{3})-?([0-9]{2})-?([0-9]{5})$/;var num=value?value:el.value;var msg = "올바른 사업자등록번호를 입력하세요.";
if(!pattern.test(num)) return doError(el,msg);num=RegExp.$1+RegExp.$2+RegExp.$3;
var sum=0;var getlist=new Array(10);var chkvalue=new Array("1","3","7","1","3","7","1","3","5");
for(var i=0;i<10;i++){getlist[i]=num.substring(i,i+1);} for(var i=0;i<9;i++){sum+=getlist[i]*chkvalue[i];}
sum=sum+parseInt((getlist[8]*5)/10);sidliy=sum%10;sidchk=0;if(sidliy!=0){sidchk=10-sidliy;}else{sidchk=0;}
return (sidchk==getlist[9]) ? true : doError(el,msg);}
//-------------------------------------------------------
function isForeignNum(el,value){var pattern=/^([0-9]{6})-?([0-9]{7})$/;var num=value?value:el.value;var msg = "올바른 외국인등록번호를 입력하세요.";
if(!pattern.test(num)) return doError(el,msg);num=RegExp.$1+RegExp.$2;
if((num.charAt(6)=="5")||(num.charAt(6)=="6")) birthYear="19"; else if((num.charAt(6)=="7")||(num.charAt(6)=="8")) birthYear="20";
else if((num.charAt(6)=="9")||(num.charAt(6)=="0")) birthYear="18"; else return doError(el, msg);
birthYear+=num.substr(0,2); birthMonth=num.substr(2,2)-1; birthDate=num.substr(4,2); birth=new Date(birthYear, birthMonth, birthDate);
if(birth.getYear()%100!=num.substr(0,2)||birth.getMonth()!=birthMonth||birth.getDate()!=birthDate) return doError(el,msg);
var sum=0;var odd=0;var buf=new Array(13);for(i=0;i<13;i++){buf[i]=parseInt(num.charAt(i));}
odd=buf[7]*10+buf[8];if(odd%2!=0) return doError(el,msg);if((buf[11]!=6)&&(buf[11]!=7)&&(buf[11]!=8)&&(buf[11]!=9)) return doError(el,msg);
multipliers=[2,3,4,5,6,7,8,9,2,3,4,5];for(i=0,sum=0;i<12;i++){sum+=(buf[i]*=multipliers[i]);}
sum=11-(sum%11);if(sum>=10) sum-=10; sum+=2;if(sum>=10) sum-=10; return (sum==buf[12]) ? true : doError(el,msg);}
//-------------------------------------------------------
function isEmailList(el){el.value=el.value.replace(/ /g,'').replace(/(,)+/g,',').replace(/^,/,'').replace(/,$/,'');
var pattern=/^[_a-zA-Z0-9-\.]+@[\.a-zA-Z0-9-]+\.[a-zA-Z]+$/; if(el.value.length>0){var emails = el.value.split(",");
for(var i=0; i<emails.length; i++){if(!pattern.test(emails[i])){alert(emails[i] + " 는 올바른 메일주소가 아닙니다."); el.focus(); return false;}} return true;}return true;}
//-------------------------------------------------------
function isValidExt(el, p){var pt = "," + p.replace(/ /g,'') + ",";if(!el || el.value.replace(/ /g,'').length==0) return false;
var ext = el.value.toLowerCase().substring(el.value.lastIndexOf(".")+1);
if(pt.indexOf("," + ext + ",")<0){alert("올바른 파일형식이 아닙니다."); el.select();
if(window["getSelection"]){if(Browser.safari){window.getSelection().collapse();}else{window.getSelection().removeAllRanges();}}
else if((document.selection)&&(document.selection.clear)){document.selection.clear();} return false;} else return true;}
//-------------------------------------------------------
function isImageExt(el){return isValidExt(el, "jpg,jpeg,gif,png");}
function trim(s){return s ? s.replace(/ +$/,'').replace(/^ +/g,'') : '';}
//=======================================================
// 이미지 관련 함수
//
function imageReSize(el,maxWidth,maxHeight, fit){var width=el.width;var height=el.height;
if(maxWidth<0)maxWidth=0;if(maxHeight<0)maxHeight=0;
if(maxWidth==0&&maxHeight>0&&height>maxHeight){height=height/maxHeight;width=width/(height/maxHeight);}
else if(maxHeight==0&&maxWidth>0&&width>maxWidth){width=width/maxWidth;height=height/(width/maxWidth);}
else if(maxWidth>0&&maxHeight>0){if(width>maxWidth){height=height/(width/maxWidth);width=maxWidth;}
if(height>maxHeight){width=width/(height/maxHeight);height=maxHeight;}
if(fit && width<maxWidth && height<maxHeight){
if(maxWidth>maxHeight){width=width*(maxHeight/height);height=maxHeight;}
else{height=height*(maxWidth/width);width=maxWidth;}
if(width>maxWidth){height=height/(width/maxWidth);width=maxWidth;}
if(height>maxHeight){width=width/(height/maxHeight);height=maxHeight;}}}el.width=width;el.height=height;}
//=======================================================
// Form 관련 함수
//
function getRequestURI(){var u=location.href; return u.indexOf('?')>0 ? u.substring(u.lastIndexOf('/')+1, u.indexOf('?')) : u.substring(u.lastIndexOf('/')+1);}
function setSelectBox(id, value){var el = document.getElementById(id);
if(!el){var els=document.getElementsByName(id);if(els && els.length) el=els[0];}
if(el&&el.length){for(var i=0; i<el.length; i++) el[i].selected=(el[i].value==value);}}
function setRadio(id, value){var el = document.getElementsByName(id);
if(el&&el.length){for(var i=0; i<el.length; i++) el[i].checked=(el[i].value==value);}}
function getRadio(el){if(el.length){for(var i=0;i<el.length;i++)if(el[i].checked){return el[i].value;}}else if(el.checked) return el.value; return '';}
function setCheckbox(id, value){var el = document.getElementById(id);
if(!el){var els=document.getElementsByName(id);if(els && els.length) el=els[0];}
if(el){el.checked=(el.value==value);}}
function setBgColor(el,c){el.style.backgroundColor=c;}
function setBgColorOver(el,c){if(c&&c.length>0)el.style.cursor='pointer'; el.style.backgroundColor=c;}
function deleteAll(query) {
var str = "";
var checkIdxs = document.getElementsByName("checkIdx");
for(var i=0; i<checkIdxs.length; i++) { if(checkIdxs[i].checked) str = str + "," + checkIdxs[i].value; }
if(str.length>1) {
if(confirm("삭제하시겠습니까?")) location.href = getRequestURI() + query + "&mode=delete&idxs=" + str.substr(1);
} else alert("삭제할 항목을 먼저 선택하세요.");
}
function deleteItem(query, idx) {
if(confirm("삭제하시겠습니까?")) location.href = getRequestURI() + query + "&mode=delete&idx=" + idx;
}
function checkAll(el) {
if(el.name=="checkIdxAll") {
var b = el.checked;
var c = el.form.checkIdx; if(!c) return;
if(c.length) { for(var i=c.length-1; i>=0; i--) c[i].checked = b;
} else c.checked = b;
} else if(!el.checked && el.form.checkIdxAll) el.form.checkIdxAll.checked = false;
}
function checkEnter(e, fn) {
var key = window.event ? event.keyCode : e.keyCode;
if(key==13) {
var el = window.event ? event.srcElement : e.target;
if(el && el.value.replace(/ /g,'').length>0) eval(fn);
if(window.event) event.returnValue=false; else e.preventDefault();
}
}
//=======================================================
// 배너 스크롤 처리 함수
//
var isBannerScroll = true;
var bannerFirstScrollY = new Array();
var bannerLastScrollY = new Array(0, 0, 0, 0, 0);
function bannerLayerScroll(n, s) {
if(n<0 || n>=bannerLastScrollY.length) return;
obj = (document.getElementById) ? document.getElementById(s) : (document.all) ? document.all[s] : document.layers[s];
if(!obj) return;
if (typeof window.pageYOffset != 'undefined') {
diffY = window.pageYOffset;
diffH = window.scrollMaxY ? window.innerHeight + window.scrollMaxY : document.body.scrollHeight;
} else if (document.compatMode && document.compatMode != 'BackCompat') {
diffY = document.documentElement.scrollTop;
diffH = document.documentElement.scrollHeight;
} else {
diffY = document.body.scrollTop;
diffH = document.body.scrollHeight;
}
if(obj.offsetParent&&obj.offsetParent.scrollHeight>0) diffH = obj.offsetParent.scrollHeight;
if(!bannerFirstScrollY[n]) bannerFirstScrollY[n] = document.all ? obj.style.pixelTop : parseInt(obj.style.top);
if(!isBannerScroll) diffY = bannerFirstScrollY[n];
if(diffY<0) diffY = 0;
if(diffY != bannerLastScrollY[n]) {
percent = .1 * (diffY-bannerLastScrollY[n]);
if(percent>0) percent = Math.ceil(percent); else percent = Math.floor(percent);
if(diffH>(obj.offsetTop+ obj.offsetHeight + percent)) {
if(document.all) obj.style.pixelTop += percent;
else obj.style.top = (parseInt(obj.style.top) + percent) + 'px';
bannerLastScrollY[n] = bannerLastScrollY[n] + percent;
}
}
}
//=======================================================
// 클립보드 처리
//
function copyClip(meintext) {
if (window.clipboardData) { // IE일 경우
window.clipboardData.setData("Text", meintext);
} else if (window.netscape) { // NS일 경우
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
if (!clip) return false;
var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
if (!trans) return false;
trans.addDataFlavor('text/unicode');
var str = new Object(); var len = new Object();
var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
var copytext = meintext; // 로컬변수에 복사
str.data = copytext;
trans.setTransferData("text/unicode",str,copytext.length*2);
var clipid = Components.interfaces.nsIClipboard;
if (!clipid) return false;
clip.setData(trans,null,clipid.kGlobalClipboard);
}
alert("저장되었습니다.\n원하는곳에 붙여넣기를 하세요.");
return false;
}
//=======================================================
// 포커스 처리
//
var mouseOverColor = "#666666";
var mouseOverBgColor = "#FFFFFF";
var nowFocusEl = '';
function inputIn(e) { oSrc=(window.event) ? event.srcElement : e.target;
if(oSrc && isFocusElement(oSrc)){nowFocusEl=oSrc.name;oSrc.style.color=mouseOverColor;oSrc.style.backgroundColor=mouseOverBgColor;}}
function inputOut(e) { oSrc=(window.event) ? event.srcElement : e.target;
if(oSrc && isFocusElement(oSrc)){nowFocusEl='';oSrc.style.color="";oSrc.style.backgroundColor="";}}
if(document.all){document.onfocusin = inputIn; document.onfocusout = inputOut;}
function mouseIn(e) { oSrc=(window.event) ? event.srcElement : e.target;
if(oSrc && isFocusElement(oSrc)){oSrc.style.color=mouseOverColor;oSrc.style.backgroundColor=mouseOverBgColor;}
if(oSrc=hasClassName(oSrc,"mouse")) oSrc.style.backgroundColor=mouseOverBgColor;}
function mouseOut(e) { oSrc=(window.event) ? event.srcElement : e.target;
if(oSrc && isFocusElement(oSrc) && nowFocusEl!=oSrc.name){oSrc.style.color="";oSrc.style.backgroundColor="";}
if(oSrc=hasClassName(oSrc,"mouse")) oSrc.style.backgroundColor="";}
function hasClassName(el, n){while(el){if(el.className==n) return el;el=el.parentNode;} return false;}
function isFocusElement(el){
return el.type=="text" || el.type=="password" || el.type=="file" || el.tagName=="TEXTAREA" || el.tagName=="SELECT";
}
// 포커스처리 이벤트 시작
//if(document.all){document.onmouseover = mouseIn; document.onmouseout = mouseOut;}
//=======================================================
// 기타
//
function printWindow() {
window.open("/common/print.php", "printWindow", "width=700, height=500, status=no, scrollbars=yes");
}
function IFramResize(d) {
var el = document.getElementById(d);
if(el && el.tagName=="IFRAME") {
var oDoc = el.contentDocument || el.contentWindow.document;
el.height = oDoc.body.scrollHeight + 30;
}
}
function setCookie(name, value, expiredays) {
var todayDate = new Date();
todayDate.setDate(todayDate.getDate() + expiredays);
document.cookie = name + "=" + escape(value) + "; path=/; expires=" + todayDate.toGMTString() + ";";
}
make flash
function MakeFlash(Url,Width,Height){
var s = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' "
+ "codebase='https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' "
+ "width='" + Width + "' height='" + Height + "'>\n"
+ "<param name='movie' value='" + Url + "'>\n"
+ "<param name='quality' value='high' />\n"
+ "<param name='menu' value='false'>\n"
+ "<param name='wmode' value='transparent'>\n"
+ "<embed src='" + Url + "' quality='high' pluginspage='https://www.macromedia.com/go/getflashplayer' "
+ "type='application/x-shockwave-flash' wmode='transparent' width='" + Width + "' height='" + Height + "'></embed>\n"
+ "</object>";
document.writeln(s);
}
check userAgent
var Browser = new Object();
Browser.win=(navigator.appVersion.indexOf('Win')!=-1);
Browser.mac=(navigator.appVersion.indexOf('Mac')!=-1);
Browser.lin=(navigator.userAgent.indexOf('Linux')!=-1);
if(!document.layers){
Browser.opera=(navigator.userAgent.indexOf('Opera')!=-1);
Browser.konq=(navigator.userAgent.indexOf('Konqueror')!=-1);
Browser.safari=(navigator.userAgent.indexOf('Safari')!=-1);
Browser.mozilla=(navigator.userAgent.indexOf('Gecko')!=-1&&!Browser.safari&&!Browser.konq);
Browser.ie=(document.all&&!Browser.opera);
Browser.ie4=(Browser.ie&&!document.getElementById);
Browser.ie5x=(document.all&&document.getElementById);
Browser.ie5mac=(Browser.mac&&Browser.ie5x);
Browser.ie5xwin=(Browser.win&&Browser.ie5x);
}
Get Selection
var
textarea = document.getElementById(
"textarea"
);
// code for IE
if
(document.selection)
{
textarea.focus();
var
sel = document.selection.createRange();
// alert the selected text in textarea
alert(sel.text);
// Finally replace the value of the selected text with this new replacement one
sel.text =
'<b>'
+ sel.text +
'</b>'
;
} else {
// code for Mozilla
var
len = textarea.value.length;
var
start = textarea.selectionStart;
var
end = textarea.selectionEnd;
var
sel = textarea.value.substring(start, end);
// This is the selected text and alert it
alert(sel);
var
replace =
'<b>'
+ sel +
'<b>'
;
// Here we are replacing the selected text with this one
textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len);
}
No comments:
Post a Comment