/******************************************************************
 * JAWJS.FORM.FieldHelp - Field help module for form(s)
 * Copyright (c) Ja-Web.com
 ******************************************************************/

JAWJS.registerNS("JAWJS.FORM");JAWJS.FORM.FieldHelp=function(userConfig){var config={sRefId:"",sInfoPrefix:"fldh-",sInfoClass:"fldhelp",sInfoHideClass:"fldhelp-hide",sInfoShowClass:"fldhelp-show",sHlpLinkShowTxt:"[ ? ]",sHlpLinkShowClass:"fldhelplink-show",sHlpLinkShowTitleAttr:"Vis hjelp for skjemafelt: ",sHlpLinkHideTxt:"[ x ]",sHlpLinkHideClass:"fldhelplink-hide",sHlpLinkHideTitleAttr:"Skjul hjelp for skjemafelt: ",bUseLabelTxt:true,sJsSpecialClass:"js-enabled",sJsSpecialInsertId:""};JAWJS.TOOLS.setUserConfig(config,userConfig);this.getConfigOpt=function(userConfig){return JAWJS.TOOLS.getConfig(config,userConfig);};this.getConfigObj=function(){var oConfig=config;return oConfig;};};JAWJS.FORM.FieldHelp.prototype={init:function(){if(!JAWJS.DOM.get(this.getConfigOpt("sRefId"))||!this.getConfigOpt("sInfoClass")){return;}
JAWJS.DOM.jsSpecial(this.getConfigOpt("sJsSpecialInsertId"),this.getConfigOpt("sJsSpecialClass"));this.initFieldHelp();},initFieldHelp:function(){var dom=JAWJS.DOM,addEvent=JAWJS.EVENT.add,get=JAWJS.DOM.get,configOpt=this.getConfigOpt,create=JAWJS.DOM.create;var refHlpElm,refHlpElmFx,singelLabelFx,hlpSpanElm,oHlpEls,hlpLinkElm;oHlpEls=dom.getElementsByClass(configOpt("sInfoClass"),'',get(configOpt("sRefId")));for(i=0;i<oHlpEls.length;i++){dom.css('add',oHlpEls[i],configOpt("sInfoHideClass"));(function(hi){refHlpElm=get(oHlpEls[hi].id.substring(configOpt("sInfoPrefix").length));if(configOpt("bUseLabelTxt")===true&&configOpt("sHlpLinkShowTitleAttr")!==''){singelLabel=dom.getLabelAttr(get(configOpt("sRefId")),'for',refHlpElm.id,true)[0];hlpLinkElm=create('a','',{href:'#',title:configOpt("sHlpLinkShowTitleAttr")+dom.innerTxt(singelLabel),className:configOpt("sHlpLinkShowClass")});}else{if(configOpt("sHlpLinkShowTitleAttr")==""){hlpLinkElm=create('a','',{href:'#',className:configOpt("sHlpLinkShowClass")});}else{hlpLinkElm=create('a','',{href:'#',title:configOpt("sHlpLinkShowTitleAttr"),className:configOpt("sHlpLinkShowClass")});}}
hlpSpanElm=create('span',configOpt("sHlpLinkShowTxt"));dom.add(hlpSpanElm,hlpLinkElm);dom.insertAfter(hlpLinkElm,refHlpElm);addEvent(hlpLinkElm,'click',function(e){dom.css('swap',oHlpEls[hi],configOpt("sInfoHideClass"),configOpt("sInfoShowClass"));if(configOpt("bUseLabelTxt")===true&&configOpt("sHlpLinkShowTitleAttr")!==''&&configOpt("sHlpLinkHideTitleAttr")!==''){refHlpElmFx=get(oHlpEls[hi].id.substring(configOpt("sInfoPrefix").length));singelLabelFx=dom.getLabelAttr(get(configOpt("sRefId")),'for',refHlpElmFx.id,true)[0];if(dom.innerTxt(this)==configOpt("sHlpLinkShowTxt")){dom.firstCh(this.getElementsByTagName('span')[0]).nodeValue=configOpt("sHlpLinkHideTxt");dom.attr(this,'title',configOpt("sHlpLinkHideTitleAttr")+dom.innerTxt(singelLabelFx));dom.css('swap',this,configOpt("sHlpLinkShowClass"),configOpt("sHlpLinkHideClass"));}else{dom.firstCh(this.getElementsByTagName('span')[0]).nodeValue=configOpt("sHlpLinkShowTxt");dom.attr(this,'title',configOpt("sHlpLinkShowTitleAttr")+dom.innerTxt(singelLabelFx));dom.css('swap',this,configOpt("sHlpLinkHideClass"),configOpt("sHlpLinkShowClass"));}}else{if(dom.innerTxt(this)==configOpt("sHlpLinkShowTxt")){dom.firstCh(this.getElementsByTagName('span')[0]).nodeValue=configOpt("sHlpLinkHideTxt");dom.attr(this,'title',configOpt("sHlpLinkHideTitleAttr"));dom.css('swap',this,configOpt("sHlpLinkShowClass"),configOpt("sHlpLinkHideClass"));}else{dom.firstCh(this.getElementsByTagName('span')[0]).nodeValue=configOpt("sHlpLinkShowTxt");dom.attr(this,'title',configOpt("sHlpLinkShowTitleAttr"));dom.css('swap',this,configOpt("sHlpLinkHideClass"),configOpt("sHlpLinkShowClass"));}}
dom.stopDef(e);});hlpLinkElm=null;hlpSpanElm=null;})(i);}}};