var toggleBoxCheck=false;var Cube={};Element.extend({setValue:function(C){var B="";var G="";var E="";var A=0;function F(I,H){switch(I.type){case"textarea":case"text":case"hidden":I.value=H;break;case"checkbox":if(I.value==H){I.checked=true}break;case"select-one":for(A=I.length-1;A>=0;A--){if(I[A].value==H){I[A].selected=true;break}}break;case"select-multiple":for(A=I.options.length-1;A>=0;A--){if(H.toString().match(new RegExp("\\["+I.options[A].value+"\\]",""))){I.options[A].selected=true}}break;default:if($chk(I.length)){for(A=I.length-1;A>=0;A--){if(H.toString().match(/\[/)){if(H.toString().match(new RegExp("\\["+I[A].value+"\\]",""))){I[A].checked=true}else{I[A].checked=false}}else{if(I[A].value==H){I[A].checked=true;break}}}}break}}if($chk(C)&&$type(C)=="object"){for(var D in C){E=C[D];B="";if($chk(E)&&$type(E)=="string"){E=E.toString().nl2br2("write");B=$type(E)}if(B=="string"||B=="number"){G=this.elements[D];if(!$chk(G)){G=this.elements[D+"[]"]}if($chk(G)&&$type(G)!="string"){F(G,E)}}}}else{F(this,C)}},toggleBox:function(C){toggleBoxCheck=toggleBoxCheck?false:true;if(C){toggleBoxCheck=(C=="off")?false:true}if(this.isTag("form")){for(var B=0;B<this.elements.length;B++){if($(this.elements[B]).isTag("input")&&this.elements[B].type=="checkbox"&&this.elements[B].name.toString().match(/\[/i)){this.elements[B].checked=toggleBoxCheck}}}else{if(this.isTag("select")&&this.type=="select-multiple"){for(var A=0;A<this.options.length;A++){this.options[A].selected=toggleBoxCheck}}}},check:function(N){var K="";var H="";var J="";var B="";var D="";var A="";var C="";var E="";var I=0;var M=0;var L=0;var G="";var F=0;if($chk(N)&&$type(N)=="object"){for(K in N){if($chk(this.elements[K])&&$type(this.elements[K])!="string"){B=this.elements[K];B=$(B);D=B.getValue();A=$chk(B.name)?B.name:B[0].name;A=$chk(N[K]["name"])?N[K]["name"]:A;if(!$chk(N[K]["is_not"])&&!D){C+="["+A+"] 의 값을 입력해 주세요\n"}if($type(N[K])=="object"){for(H in N[K]){J=N[K][H];L=(D)?D.getLength():0;switch(H){case"min":if(L<J){C+="["+A+"] 의 최소 길이는 "+J+"bytes(영문 1byte, 한글 2byte) 이상 이어야 합니다. (현재 "+L+"bytes)\n"}break;case"max":if(L>J){C+="["+A+"] 의 최대 길이는 "+J+"bytes(영문 1byte, 한글 2byte) 이하 이어야 합니다. (현재 "+L+"bytes)\n"}break;case"type":switch(J){case"mail":if(!D.toString().match(/[a-z0-9\.\-\_\+]+\@[a-z0-9\.\-\_]+/ig)||!D.toString().match(/\@/i)||L<5||!D.toString().match(/\./i)){C+="["+A+"] 의 형식이 올바르지 않습니다\n"}break;case"homepage":if(D.toString().match(/[ \t\n\r]/i)){C+="["+A+"] 의 형식이 올바르지 않습니다\n"}break;case"jumin":D=D.toString().replace(/\-/g,"");L=D.getLength();if(L!=13||D.toString().match(/[^0-9]/ig)){C+="["+A+"] 의 형식이 올바르지 않습니다\n"}I=0;E="234567892345";for(F=0;F<12;F++){I+=parseInt(D.charAt(F))*parseInt(E.charAt(F))}M=((11-(I%11))==10)?0:1;if(M!=D.charAt(12)){C+="["+A+"] 가 유효하지 않습니다\n"}break;case"co_num":D=D.toString().replace(/\-/g,"");L=D.getLength();if(L!=10||D.toString().match(/[^0-9]/ig)){C+="["+A+"] 의 형식이 올바르지 않습니다\n"}I=0;E="137137135";for(F=0;F<9;F++){I+=parseInt(D.charAt(F))*parseInt(E.charAt(F))}I+=((parseInt(D.charAt(8))*5)/10);I=Math.floor(I);M=(I%10!=0)?(10-I%10)%10:0;if(M!=parseInt(D.charAt(9))){C+="["+A+"] 가 유효하지 않습니다\n"}break;case"cp":D=D.toString().replace(/\-/g,"");L=D.getLength();if(D){if(L!=10&&L!=11){C+="["+A+"] 는 10자리 혹은 11자리만 가능합니다\n"}switch(D.toString().substring(0,3)){case"010":case"011":case"016":case"017":case"018":case"019":break;default:C+="["+A+"] 의 앞번호가 올바르지 않습니다\n"}}break;case"id":if(D.toString().match(/[^0-9a-z\_]/ig)){C+="["+A+"] 형식은 숫자, 영어, 언더바(_)만 허용 합니다\n"}break;case"pass":if(D.toString().match(/[^0-9a-z\!\@\#\$\%\^\&\*\(\)\_\+\-\=\[\]\;\,\.\/\{\}\:\<\>\?]/ig)){C+="["+A+"] 형식은 숫자, 영어, 기호(묶음제외)만 허용 합니다\n"}break;case"num":if(D.toString().match(/[^0-9\-]/ig)){C+="["+A+"] 형식은 숫자만 허용 합니다\n"}break;case"regexp":if($chk(N[K]["regexp"])&&$type(N[K]["regexp"])=="regexp"){if(D.toString().match(N[K]["regexp"])){C+="["+A+"] 형식이 올바르지 않습니다\n"}}else{C+="RegExp 형식 체크에 정규식이 없습니다"}break}break}}}}}if(C){error(C.nl2br());return false}else{return true}}return false},setForm:function(A){this.addEvent("submit",function(C){new Event(C).stop();var B=1;if(!isEnter){if($chk(A)){A.bind(this).attempt()}else{this.submitAction()}}})},ajaxCheck:function(B){var A=this;if(!B){B=""}A.addEvent("blur",function(){var D=1;if(this.name=="jumin"){if(this.value&&!$(this.form).check({jumin:{name:"주민등록번호",type:"jumin"}})){D=0}}if(this.name=="co_num"){if(this.value&&!$(this.form).check({co_num:{name:"사업자등록번호",type:"co_num"}})){D=0}}if(D){var F="";var C="";try{F=id}catch(E){}try{C=group}catch(E){}if(A.value){ajaxForm({url:miniDir+"ajax.php",onError:function(G){error(G.msg,{target:A,className:"iiAjaxCheck",opacity:0.7});A.focus()},onComplete:function(G){error(G.msg,{target:A,styles:{backgroundColor:"#32CD32"},className:"iiAjaxCheck",opacity:0.7})},onFailure:function(){},values:{mode:B+A.name,value:A.value,id:F,group:C}})}}})},setMail:function(){this.ajax({url:miniDir+"ajax.php",mode:"mail",width:"200px",height:"150px",funcList:function(A){return"@"+A},funcClick:function(A){this.focus();this.value=this.value.toString().replace(/\@.*$/i,"@"+A)}})},setAddress:function(A){if(!$chk(use_not_address)){this.ajax({url:miniDir+"ajax.php",mode:"address",width:"400px",height:"150px",funcList:function(B){return"["+B.zipcode+"] "+B.address},funcClick:function(B){if($chk(A)){A.value=B.zipcode}this.focus();this.value=B.address}})}},setChat:function(){this.ajax({url:miniDir+"ajax.php",mode:"chat",width:"160px",height:"150px",funcList:function(A){return A},funcClick:function(A){this.focus();this.value=A}})},secure:function(A){var B="";if(this.value!==""){switch(A){case"md5":B=hex_md5(this.value);break;case"sha1":B=hex_sha1(this.value);break;case"mixed":B=hex_sha1(hex_md5(this.value));break;default:B=this.value}}return B},secureLogin:function(A){var B="";if(this.value!==""){switch(A){case"md5":B=hex_md5(this.value);break;case"sha1":B=hex_sha1(this.value);break;case"mixed":B=hex_sha1(hex_md5(this.value));break;default:B=this.value}}return B},setCube:function(D){var C=$("cubeDiv");var A=0;if($chk(C)){Cube.Obj=this;if($chk(this.nodeName)&&this.nodeName.toString().match(/form/i)){Cube.mode="form";Cube.onComplete=this.submitAction.bind(this);if(this.elements.mode.value!="modify"&&(!$chk(this.elements.cube)||!this.elements.cube.value)){A=1}}else{Cube.mode="url";Cube.onComplete=D;if(!$chk(Cube.value)||Cube.value){A=1}}if(A){C.toggle("show");var B=C.getSize().size;C.toggle("hide");iiPopup.init({mode:"div",target:C.clone(),width:B.x,height:B.y+16});error("키워드에 맞는 이미지를 선택해 주세요");return false}}return true}});function setAutoFocus(B,A){$(B).addEvent("keyup",function(D){var C=setEvent(D);if(this.value.length==this.maxLength&&((C.code>=48&&C.code<=57)||(C.code>=96&&C.code<=105))){A.focus()}})}function setTextarea(){$$("textarea").each(function(B){if(!B.name.toString().match(/sms/i)){var A=new Element("DIV",{title:"더블클릭하면 원래크기로 돌아갑니다"}).setStyles({background:'#efefef url("'+miniDir+'admin/image/n-resize.gif") no-repeat center',fontSize:0,height:"7px",width:B.getStyle("width"),cursor:"n-resize"}).addEvent("dblclick",function(){B.setStyle("height","80px")}).injectAfter(B);B.makeResizable({handle:A,modifiers:{x:false,y:"height"},limit:{y:[80,1000]}})}})}function setSMS(A){A.addEvent("keydown",function(C){var B=setEvent(C);if(B.key!="left"&&B.key!="right"&&B.key!="up"&&B.key!="down"&&B.key!="backspace"&&B.key!="delete"&&this.value.toString().getLength()>=80){error("80bytes(한글 40자) 만 입력하실 수 있습니다.");A.blur();A.focus();return false}})}function cubeSel(A){if(Cube.mode=="form"){if(!$chk(Cube.Obj.elements.cube)){new Element("INPUT",{type:"hidden",name:"cube"}).inject(Cube.Obj)}Cube.Obj.elements.cube.value=A;iiPopup.close();Cube.onComplete()}else{if(Cube.mode=="url"){Cube.value=A;iiPopup.close();Cube.onComplete.attempt([],Cube)}}}function ajaxForm(A){if(!$chk(A.json)){A.json=1}if(!$chk(A.form)){A.form=1}if(!$chk(A.loading)){A.loading=1}if(!$chk(A.onRequest)){A.onRequest=new Function()}if(!$chk(A.onFailure)){A.onFailure=function(){error("폼 전송에 실패했습니다")}}if($chk(A.Obj)){A.onFailure.bind(A.Obj)}var B=$("loading");if($chk(A.url)){if(A.loading){B.toggle("show");B.center()}new Ajax(A.url,{onRequest:A.onRequest,onComplete:function(C){if(A.loading){B.toggle("hide")}if($chk(C)){if(A.json){data=setJSON(C);if($type(data)=="object"){if($chk(A.onError)&&$chk(data.error)&&data.error==1){A.onError.attempt(data)}else{if($chk(A.onComplete)){A.onComplete.attempt(data)}}}else{if($chk(A.onFailure)){A.onFailure()}}}else{if($chk(A.onComplete)){A.onComplete.attempt(C)}}}else{A.onFailure()}},onFailure:function(){if(A.loading){B.toggle("hide")}A.onFailure.attempt(A.Obj)}}).send(A.url,Object.toQueryString(A.values))}else{if($chk(A.Obj)){if(A.loading){B.toggle("show");B.center()}if(A.form){A.Obj.setStyle("visibility","hidden")}if($chk(A.action)){A.Obj.action=A.action}if($chk(A.target)){A.Obj.target=A.target}if($chk(A.values)){A.Obj.setValue(A.values)}A.Obj.send({onRequest:A.onRequest.bind(A.Obj),onComplete:(function(C){if(A.loading){B.toggle("hide")}if(A.form){A.Obj.setStyle("visibility","visible")}if($chk(C)){if(A.json){data=setJSON(C);if($type(data)=="object"){if($chk(A.onError)&&$chk(data.error)&&data.error==1){A.onError.attempt(data)}else{if($chk(A.onComplete)){A.onComplete.attempt(data)}}}else{if($chk(A.onFailure)){A.onFailure()}}}else{if($chk(A.onComplete)){A.onComplete.attempt(C)}}}else{A.onFailure()}}).bind(A.Obj),onFailure:function(){if(A.loading){B.toggle("hide")}if(A.form){A.Obj.setStyle("visibility","visible")}A.onFailure.attempt(A.Obj)}})}else{error("ajaxForm 사용시 Obj나 url이 설정되어 있지 않습니다")}}};