var BPF={debug:false};BPF.log=function(msg){if(!BPF.debug){return;}if(!!(window.attachEvent&&!window.opera)){alert(msg);}else{console.log(msg);}};BPF.alert=function(msg,ctl,title){alert(msg);if(ctl&&typeof ctl.type!="undefined"&&ctl.type!="radio"&&ctl.type!="checkbox"&&ctl.type!="hidden"){if($(ctl).visible()){ctl.focus();}}};BPF.confirm=function(msg,fn){Ext.MessageBox.confirm("Confirm",msg.replace(/\n/gi,"<br>"),function(btn){alert("btn1:"+btn);if(btn=="yes"){fn();}});};BPF.DataBinder=function(el){if(el){this.topElement=$(el);}else{this.topElement=document.body;}};BPF.DataBinder.bind=function(el){var binder=new BPF.DataBinder($(el));binder.bind();};BPF.DataBinder.prototype={bind:function(element){var el=null;if(typeof element=="undefined"){el=this.topElement;}else{el=element;}if(el.nodeType!=1){return;}if(el.childNodes.length){for(var i=0;i<el.childNodes.length;i++){this.bind(el.childNodes[i]);}}this.set(el);},set:function(el){if(el.getAttribute("dataid")==null){return;}var data=eval(el.getAttribute("dataid"));if(typeof data=="undefined"||typeof data[el.getAttribute("name")]=="undefined"||data[el.getAttribute("name")]==null){return;}switch(el.tagName){case"INPUT":eval(BPF.DataBinder.Element[el.tagName+"_"+el.type]).set(el,data);break;case"SELECT":case"TEXTAREA":eval(BPF.DataBinder.Element[el.tagName]).set(el,data);break;default:BPF.DataBinder.Element.Div.set(el,data);break;}}};BPF.DataBinder.Element={SELECT:"BPF.DataBinder.Element.ComboBox",TEXTAREA:"BPF.DataBinder.Element.TextBox",INPUT_text:"BPF.DataBinder.Element.TextBox",INPUT_hidden:"BPF.DataBinder.Element.TextBox",INPUT_password:"BPF.DataBinder.Element.TextBox",INPUT_radio:"BPF.DataBinder.Element.InputArray",INPUT_checkbox:"BPF.DataBinder.Element.InputArray",DIV:"BPF.DataBinder.Element.Div"};BPF.DataBinder.Element.Div={set:function(el,data){var d=data[el.getAttribute("name")];if(!d||d==""){d="&nbsp;";}el.innerHTML=d;}};BPF.DataBinder.Element.TextBox={set:function(el,data){el.value=data[el.name];}};BPF.DataBinder.Element.ComboBox={text:"text",value:"value",selectedIndex:0,init:function(el){this.text="text";this.value="value";if(el.getAttribute("textcol")!=null){this.text=el.getAttribute("textcol");}if(el.getAttribute("valuecol")!=null){this.value=el.getAttribute("valuecol");}if(el.getAttribute("defaultidx")!=null){this.selectedIndex=parseInt(el.getAttribute("defaultidx"));}},set:function(el,data){this.init(el);var label="";var length=data[el.name].length;if(length){for(var i=0;i<length;i++){label=data[el.name][i][this.text];if(typeof label=="undefined"||label==null||label==""){label=data[el.name][i][this.value];}el.options[el.options.length]=new Option(label,data[el.name][i][this.value]);}}el.selectedIndex=this.selectedIndex;if(el.getAttribute("selectedid")==null){return;}var checkedId=el.getAttribute("selectedid");try{var data=eval(checkedId);}catch(e){return;}el.value=data;}};BPF.DataBinder.Element.InputArray={text:"text",value:"value",init:function(el){this.text="text";this.value="value";if(el.getAttribute("textcol")!=null){this.text=el.getAttribute("textcol");}if(el.getAttribute("valuecol")!=null){this.value=el.getAttribute("valuecol");}},set:function(el,data){this.init(el);var parent=el.parentNode;if(data[el.name].length>0){el.value=data[el.name][0][this.value];var label=data[el.name][0][this.text];if(typeof label=="undefined"||label==null||label==""){label=data[el.name][0][this.value];}var txt=document.createTextNode(label);parent.appendChild(txt);var data2=data[el.name];var length=data2.length;var blank=document.createTextNode(" ");for(var i=1;i<length;i++){parent.appendChild(blank.cloneNode(false));var el2=el.cloneNode(false);el2.removeAttribute("dataid");el2.removeAttribute("checkedid");el2.removeAttribute("id");el2.value=data2[i][this.value];label=data2[i][this.text];if(typeof label=="undefined"||label==null||label==""){label=data2[i][this.value];}txt=document.createTextNode(label);parent.appendChild(el2);parent.appendChild(txt);}this.check(el);}},check:function(el){var ctl=el.form[el.name];if(el.getAttribute("checkedid")==null){return;}var checkedId=el.getAttribute("checkedid");var data=eval(checkedId);if(typeof data=="undefined"){return;}switch(typeof data){case"string":if(!ctl.length){if(ctl.value==data){ctl.checked=true;}}else{for(var i=0;i<ctl.length;i++){if(ctl[i].value==data){ctl[i].checked=true;break;}}}break;case"object":if(!ctl.length){if(data){for(var i=0;i<data.length;i++){if(ctl.value==data[i].value){ctl.checked=true;break;}}}}else{for(var j=0;j<ctl.length;j++){if(data.length){for(var i=0;i<data.length;i++){if(ctl[j].value==data[i].value){ctl[j].checked=true;break;}}}}}break;}}};BPF.Ajax={request:function(uri,obj,callbackSuccess,callbackFailure,loading){var params=null;loading=(typeof loading=="undefined"?true:loading);if(obj){if($(obj)&&$(obj).tagName&&$(obj).tagName=="FORM"){params=Form.serialize(obj);}else{params=obj;}}var success=this.success.bind(this,callbackSuccess,callbackFailure,loading);var fail=this.fail.bind();var config={parameters:params,onSuccess:success,onFailure:function(httpResponseObj){fail(callbackFailure);}};if(loading){cfActiveLoadingBlock();}new Ajax.Request(uri,config);},success:function(callbackSuccess,callbackFailure,loading,httpResponseObj){var data=null;try{data=httpResponseObj.responseText.evalJSON();}catch(e){data=httpResponseObj.responseText;}if(typeof data=="object"&&data!=null&&typeof data.error!="undefined"&&eval(data.error)){return this.fail(callbackFailure,data);}if(callbackSuccess){callbackSuccess(httpResponseObj);}if(loading){cfDeactiveLoadingBlock();}},fail:function(callbackFailure,err){if(!callbackFailure){if(typeof err!="undefined"){if(err.message=="EHRD_NO_SESSION"){alert("시간이 오래 경과되어 세션이 종료되었습니다.\n\n다시 로그인하여 주시기 바랍니다.");top.location.href="/index.jsp";}else{var frmId=BPF.Json.jsonToForm(err,"ERROR__FORM");var frm=eval("document."+frmId);frm.action="/ehrd/common/error";cfSubmit(frm);}}else{top.location.href="/ehrd/common/error";}}else{callbackFailure();}cfDeactiveLoadingBlock();},requestToDiv:function(uri,obj,div){this.request(uri,obj,function(httpResponseObj){var scripts=[];httpResponseObj.responseText.scan(/\<script[^>]*>([\S\s]*?)<\/script>/,function(match){if(match[1]){scripts.push(match[1]);}});$(div).update(httpResponseObj.responseText.replace(/^\s*/,"").stripScripts());$A(scripts).each(function(s){eval(s);});});}};BPF.ResultProcess={REDIRECT_TYPE_HREF:1,REDIRECT_TYPE_REPLACE:2,TARGET_SELF:1,TARGET_TOP:2,TARGET_OPENER:3,Type:{ALERT:"BPF.ResultProcess.Alert",RELOAD:"BPF.ResultProcess.Reload",REDIRECT:"BPF.ResultProcess.Redirect",CLOSE:"BPF.ResultProcess.Close",CALLBACK:"BPF.ResultProcess.Callback"}};BPF.ResultProcessJob=function(jobs){this.jobs=jobs;};BPF.ResultProcessJob.prototype={execute:function(){if(this.jobs){for(var i=0;i<this.jobs.length;i++){eval(BPF.ResultProcess.Type[this.jobs[i].type]).execute(this.jobs[i]);}}}};BPF.ResultProcess.Alert={execute:function(obj){alert(obj.message);}};Object.extend(BPF.ResultProcess.Alert,BPF.ResultProcess);BPF.ResultProcess.Reload={execute:function(obj){if(obj.target==this.TARGET_SELF||obj.target==this.TARGET_TOP){return;}if(top.opener){top.opener.location.reload();}else{if(BPF.Popup.getPoppyId()){if(BPF.Popup.Stack["ROOT"].top.$("manage_main_frame")){top.manage_main_frame.location.reload();}else{top.location.reload();}}}}};Object.extend(BPF.ResultProcess.Reload,BPF.ResultProcess);BPF.ResultProcess.Redirect={execute:function(obj){var target="self.";switch(obj.target){case this.TARGET_SELF:target="self.";break;case this.TARGET_TOP:target="top.";break;case this.TARGET_OPENER:target="opener.";break;}var poppyId;if(poppyId=BPF.Popup.getPoppyId()){obj.uri=BPF.Popup.appendPoppyId(obj.uri,poppyId);if(obj.target==this.TARGET_OPENER){if(top.manage_main_frame){target="top.manage_main_frame.";}else{target="top.";}}}if(obj.redirectType==this.REDIRECT_TYPE_HREF){eval(target+"location.href = '"+obj.uri+"';");}else{eval(target+"location.replace('"+obj.uri+"');");}}};Object.extend(BPF.ResultProcess.Redirect,BPF.ResultProcess);BPF.ResultProcess.Close={execute:function(obj){if(obj.target==this.TARGET_OPENER){if(opener){opener.close();}}else{if(BPF.Popup.getPoppyId()){BPF.Popup.close();}else{if(window.top.opener){window.top.opener.focus();}window.top.close();}}}};Object.extend(BPF.ResultProcess.Close,BPF.ResultProcess);BPF.ResultProcess.Callback={execute:function(obj){var data;if(obj&&obj.data){if(typeof obj.data=="object"){data=obj.data;}else{data=obj.data.evalJson();}}BPF.Popup.callback(data);BPF.Popup.close();}};Object.extend(BPF.ResultProcess.Callback,BPF.ResultProcess);BPF.Popup=Class.create({initialize:function(conf){this.id="poppy";if(conf&&conf.instance){var dt=new Date();this.id=this.id+dt.getHours()+dt.getMinutes()+dt.getSeconds()+dt.getMilliseconds();}BPF.Popup.Stack["ROOT"].top.BPF.Popup.Stack[this.id]={popup:this,params:conf.params,data:conf.data};if(conf.modal){BPF.Popup.Stack["ROOT"].top.BPF.Popup.Stack[this.id].modal=conf.modal;}if(conf.callback){BPF.Popup.Stack["ROOT"].top.BPF.Popup.Stack[this.id].callback=conf.callback;}},create:function(conf){var width=conf.width+10||100+10;var height=(conf.height?conf.height+124:100+124);var left=conf.left||null;var top=conf.top||null;var nearBy=conf.nearBy||null;var uri=conf.uri||"/aboutblank.jsp";uri=this.appendPoppyIdToUri(uri,this.id);var physical_body_object=$("physical_body");if(physical_body_object){leftPos=(BPF.Popup.Stack["ROOT"].top.$("physical_body").getWidth()-width)/2;topPos=(BPF.Popup.Stack["ROOT"].top.$("physical_body").getHeight()-height)/2;}else{leftPos=(BPF.Popup.Stack["ROOT"].top.document.body.offsetWidth-width)/2;topPos=(BPF.Popup.Stack["ROOT"].top.document.body.offsetHeight-height)/2;}var ifrm=BPF.Popup.Stack["ROOT"].top.$("manage_main_frame");if(!ifrm){width=conf.width+64;height=conf.height+87;if(width>1000){width=1000;}}if(nearBy){var offset=nearBy.cumulativeOffset();leftPos=offset.left+5;topPos=offset.top+5;var poppyId=BPF.Popup.getPoppyId();if(poppyId!=null){if(BPF.Popup.Stack["ROOT"].top.$("poppy")){var poppyOffset=BPF.Popup.Stack["ROOT"].top.$("poppy").cumulativeOffset();leftPos+=poppyOffset.left;topPos+=poppyOffset.top;}else{var poppyOffset=BPF.Popup.Stack["ROOT"].top.$(poppyId).cumulativeOffset();leftPos+=poppyOffset.left;topPos+=poppyOffset.top;}}else{if(ifrm){offset=ifrm.cumulativeOffset();leftPos+=offset.left;topPos+=offset.top;topPos-=document.body.scrollTop;if((height+topPos)>document.body.clientHeight){topPos-=(height+topPos-document.body.clientHeight);}}}}else{if(!ifrm){topPos+=BPF.Popup.Stack["ROOT"].top.document.body.scrollTop;}}if(leftPos<0){leftPos=50;}if(topPos<0){topPos=50;}if(left){leftPos=left;}if(top){topPos=top;}var poppy=BPF.Popup.Stack["ROOT"].top.$(this.id);if(conf.modal){if(BPF.Popup.Stack["ROOT"].top.$("dialog_page_block")){if(conf.instance){BPF.Popup.Stack["ROOT"].top.$("dialog_page_block").style.zIndex=++BPF.Popup.Stack["ROOT"].top.BPF.Popup.Stack.zIndex;}BPF.Popup.Stack["ROOT"].top.$("dialog_page_block").style.display="block";}else{BPF.Popup.Stack["ROOT"].top.document.body.insertAdjacentHTML("beforeEnd",'<div id="dialog_page_block" style="z-index:'+(++BPF.Popup.Stack["ROOT"].top.BPF.Popup.Stack.zIndex)+"; display:'block';\">&nbsp;</div>");}BPF.Popup.Stack["ROOT"].top.$("dialog_page_block").setStyle({height:BPF.Popup.Stack["ROOT"].top.document.body.scrollHeight});}if(poppy==null){if(conf.formObj!=undefined&&conf.formObj.tagName=="FORM"){BPF.Popup.Stack["ROOT"].top.document.body.insertAdjacentHTML("beforeEnd","<IFRAME id='"+this.id+"' name='"+this.id+"' style='cursor:move; position:absolute; "+"z-index: "+(++BPF.Popup.Stack["ROOT"].top.BPF.Popup.Stack.zIndex)+";left:"+leftPos+"px; top:"+topPos+"px; width:"+width+"; height:"+height+"; overflow: 'hidden'"+"' frameborder='0' "+" scrolling='no'"+" ALLOWTRANSPARENCY='true'></IFRAME>");try{conf.formObj.target=this.id;conf.formObj.action=uri;conf.formObj.submit();}catch(ex){alert(ex);}}else{BPF.Popup.Stack["ROOT"].top.document.body.insertAdjacentHTML("beforeEnd","<IFRAME id='"+this.id+"' name='"+this.id+"' style='cursor:move; position:absolute; "+"z-index: "+(++BPF.Popup.Stack["ROOT"].top.BPF.Popup.Stack.zIndex)+";left:"+leftPos+"px; top:"+topPos+"px; width:"+width+"; height:"+height+"; overflow: 'hidden'"+"' frameborder='0' src='"+uri+"' scrolling='no'"+" ALLOWTRANSPARENCY='true'></IFRAME>");}}else{poppy.src="/aboutblank.jsp";poppy.setStyle({left:leftPos,top:topPos,width:width,height:height,zIndex:(++BPF.Popup.Stack["ROOT"].top.BPF.Popup.Stack.zIndex)});if(conf.formObj!=undefined&&conf.formObj.tagName=="FORM"){conf.formObj.target=this.id;conf.formObj.action=uri;conf.formObj.submit();}else{poppy.src=uri;}setTimeout(function(){poppy.style.visibility="visible";},250);}},appendPoppyIdToUri:function(uri,poppyId){var params={};if(uri.indexOf("?")>-1){params=uri.substring(uri.indexOf("?")).toQueryParams();uri=uri.substring(0,uri.indexOf("?"));}params.poppyId=poppyId;uri=uri+"?"+$H(params).toQueryString();return uri;}});BPF.Popup.appendPoppyId=BPF.Popup.prototype.appendPoppyIdToUri;BPF.Popup.Stack={};BPF.Popup.Stack.zIndex=100;if(typeof BPF.Popup.Stack["ROOT"]=="undefined"){var win=window;var cnt=0;while(win!=null&&win!=window.top){win=window.parent;if(typeof win!="undefined"&&typeof win.BPF!="undefined"&&typeof win.BPF.Popup.Stack["ROOT"]!="undefined"&&win.BPF.Popup.Stack.isRoot==true){BPF.Popup.Stack["ROOT"]=win.BPF.Popup.Stack["ROOT"];break;}cnt++;if(cnt>20){break;}}if(typeof BPF.Popup.Stack["ROOT"]=="undefined"){BPF.Popup.Stack["ROOT"]={};BPF.Popup.Stack.isRoot=true;BPF.Popup.Stack["ROOT"].top=window;}}Object.extend(BPF.Popup,{create:function(config){var pop=null;try{pop=new BPF.Popup(config);}catch(e){pop=new BPF.Popup();}pop.create(config);},callback:function(data){var id=location.search.toQueryParams().poppyId;var stack=BPF.Popup.Stack["ROOT"].top.BPF.Popup.Stack[id];if(stack&&stack.callback){return stack.callback(data,stack.params);}},close:function(){if(BPF.Popup.Stack["ROOT"].top.$("dialog_page_block")){BPF.Popup.Stack["ROOT"].top.$("dialog_page_block").style.zIndex=(BPF.Popup.Stack["ROOT"].top.BPF.Popup.Stack.zIndex-=2);}cfActiveLoadingBlock({alpha:0.999,bgColor:"#DEEBFC"});var id=location.search.toQueryParams().poppyId;$$(".FCKeditor").invoke("remove");parent.$(id).style.visibility="hidden";var stack=parent.BPF.Popup.Stack[id];delete parent.BPF.Popup.Stack[id];var remain=false;$H(parent.BPF.Popup.Stack).values().each(function(o){if(!remain&&o.modal){remain=true;}});if(!remain&&stack&&stack.modal){parent.$("dialog_page_block").style.display="none";}},getPoppyId:function(){try{return location.search.toQueryParams().poppyId;}catch(e){return null;}},getData:function(){return BPF.Popup.Stack["ROOT"].top.BPF.Popup.Stack[this.getPoppyId()].data;}});BPF.Json=Class.create();Object.extend(BPF.Json,{jsonToForm:function(json,frmId,method){var frm=this.createForm(frmId,method);if(Object.isArray(json)){var item=null;if(json){for(var i=0,size=json.size();i<size;i++){this.appendHashToForm($H(json[i]),frm);}}}else{this.appendHashToForm($H(json),frm);}return frmId;},createForm:function(frmId,method){var frm=$(frmId);method=method?method:"post";if(!frm){$(document.body).insert('<form id="#{frmId}" name="#{frmId}" method="#{method}">'.interpolate({frmId:frmId,method:method}));frm=$(frmId);}return frm;},appendHashToForm:function(h,frm){h.each(function(pair){frm.insert('<input type="hidden" name="#{key}" value="#{value}" class="fromJson">'.interpolate({key:pair.key,value:pair.value}));});},removeFormElements:function(frmId){$$("#"+frmId+" INPUT.fromJson").invoke("remove");}});function cfJsonPropertyToForm(data,frmId){var frm=$(frmId);var hash=$H(data);hash.each(function(pair){if(pair.value){for(i=0;i<pair.value.length;i++){frm.insert('<input type="hidden" name="#{key}" value="#{value}" class="fromJson">'.interpolate({key:pair.key,value:pair.value[i]}));}}});}
