siemens.formTools=true;var FormTools=Class.create();FormTools.getInstance=function(){if(!FormTools.instance){FormTools.instance=new FormTools();}return FormTools.instance;};FormTools.prototype={initialize:function(){$$(".form-if-selected").each(function(elmSelect){var elm=$(elmSelect);var hiddenFormElm=FormTools.resetIfSelect(elmSelect);var selectedOption=(hiddenFormElm.split('-')).last();$(elm).onchange=function(e){FormTools.toggleIfSelected(elm,hiddenFormElm,selectedOption);};});$$(".maxcount").each(function(txtArea){var limit;var checkclass=$w($(txtArea).className).find(function(elmclass){var split=elmclass.split('-');if(split&&(split.size()>1)&&(split.first()==="maxcount")){limit=parseFloat(split.last());}});var parent=$(txtArea).parentNode;var label=$(parent).down('label');var counterClass;var counterTxt=Builder.node('span',{className:'text-limits'},['(',Builder.node('em',siemens.Locals.characterCount),Builder.node('span',{className:'counter'},'0/'+limit),')']);label.appendChild($(counterTxt));var counterElm=label.down('.counter');$(txtArea).observe("keyup",function(e){FormTools.charCount(e,counterElm,limit);}.bindAsEventListener($(txtArea)));$(txtArea).observe("keydown",function(e){FormTools.charCount(e,counterElm,limit);}.bindAsEventListener($(txtArea)));FormTools.charCount(txtArea,counterElm,limit);});$$(".field-help-wrapper").each(function(formHelp){var linkID=Helper.getUniqueId();var formHelpInfo=$(formHelp).down().next();var formHelpTitle=$(formHelp).down();var linkTitle=Builder.node('a',{className:formHelpTitle.className,href:'#'+linkID},formHelpTitle.down());linkTitle.title="select to show help information";linkTitle.linkID=linkID;$(formHelp).replaceChild($(linkTitle),$(formHelp.down()));if(siemens.msieBrowser&&siemens.msieBrowser<8){linkTitle.down().alt="select to show help information";}var originalInfo=$(formHelpInfo).cloneNode(true);originalInfo.className="field-help-info";var helpInfoTitle=Builder.node('em',{className:'field-help-info-title'},siemens.Locals.helpInfo);var extraspan=Builder.node('span',{className:'field-help-pointer'},'');$(helpInfoTitle).appendChild($(extraspan));while($(formHelpInfo).firstChild){$(formHelpInfo).removeChild($(formHelpInfo).firstChild);}$(formHelpInfo).appendChild(helpInfoTitle);$(formHelpInfo).appendChild(originalInfo);$(formHelpInfo).className="field-help-hide";$(linkTitle).observe("click",function(e){FormTools.getInstance().open(e);}.bindAsEventListener($(linkTitle)));});},open:function(e){var helpLink,helpLinkIcon;if(Event.element(e).match('img')){helpLink=Event.element(e).parentNode;helpLinkIcon=Event.element(e);}else if(Event.element(e).match('a')){helpLink=Event.element(e);helpLinkIcon=Event.element(e).down();}var helpInfo=helpLink.next();helpInfo.id=helpLink.linkID;$A($$("span.field-help-display")).findAll(function(helpDisplay){if($(helpDisplay).id!==helpInfo.id){FormTools.getInstance().close(helpDisplay);}});helpLink.title=helpLink.title=='select to show help information'?'select to hide help information':'select to show help information';if(siemens.msieBrowser&&siemens.msieBrowser<8){helpLinkIcon.alt=helpLinkIcon.alt=='select to show help information'?'select to hide help information':'select to show help information';}helpInfo.className=helpInfo.className=='field-help-hide'?'field-help-display':'field-help-hide';Event.stop(e);},close:function(e){var helpLink=$(e).previous();helpLink.title=helpLink.title=='select to show help information'?'select to hide help information':'select to show help information';var helpInfo=$(e);helpInfo.className=helpInfo.className=='field-help-hide'?'field-help-display':'field-help-hide';}};FormTools.toggleIfSelected=function(formElement,formBlock,formelmCriteria){if($F(formElement)===formelmCriteria){$(formBlock).show();}else{$(formBlock).hide();}};FormTools.resetIfSelect=function(elm){elm=$(elm);var hiddenElmId;var selectedOption;var checkclass=$w(elm.className).find(function(elmclass){var split=elmclass.split('-');if(split&&(split.size()>2)&&(split.first()==="form")&&(split[1]==="select")){selectedOption=split.last();hiddenElmId=elm.id+"-"+selectedOption;}});if($(hiddenElmId).down(".required-if")){$(hiddenElmId).down(".required-if").select('span').each(function(formSpan){$(formSpan).hide();});}FormTools.toggleIfSelected(elm,hiddenElmId,selectedOption);return hiddenElmId;};FormTools.charCount=function(e,counterElm,limit){var txtArea;if(e.type.toLowerCase()==="textarea"){txtArea=$(e);}else{txtArea=$(Event.element(e));}if($F(txtArea).length>=limit){if($(counterElm).hasClassName('counter')){$(counterElm).removeClassName('counter');$(counterElm).addClassName('counter-limit');}}else{if($(counterElm).hasClassName('counter-limit')){$(counterElm).removeClassName('counter-limit');$(counterElm).addClassName('counter');}}$(counterElm).update($F(txtArea).length+'/'+limit);};FormTools.resetMaxCount=function(elm){elm=$(elm);var counter,limit;var checkclass=$w(elm.className).find(function(elmclass){var split=elmclass.split('-');if(split&&(split.size()>1)&&(split.first()==="maxcount")){limit=parseFloat(split.last());}});if(elm.parentNode.down('.counter')){counter=elm.parentNode.down('.counter');}else if(elm.parentNode.down('.counter-limit')){counter=elm.parentNode.down('.counter-limit');}FormTools.charCount(elm,counter,limit);};FormTools.focusFunction=function(elm){var elmID;if($(elm).id){if($(elm).href!=="javascript:void(0);"){$(elm).href="javascript:void(0);";}elmID=$(elm).id.split("-").last();$(elmID).focus(elmID);}else{$(elm).focus();}};siemens.formValidation=true;var Validator=Class.create();var Validation=Class.create();Validation.getInstance=function(form,options){if(!Validation.instance){Validation.instance=new Validation(form,options);}return Validation.instance;};Validator.prototype={initialize:function(className,error,test,options){if(typeof test=='function'){this.options=$H(options);this._test=test;}else{this.options=$H(test);this._test=function(){return true;};}this.error=error||'Validation failed.';this.className=className;},test:function(v,elm){return(this._test(v,elm)&&this.options.all(function(p){return Validator.methods[p.key]?Validator.methods[p.key](v,elm,p.value):true;}));}};Validator.methods={pattern:function(v,elm,opt){return Validation.get('IsEmpty').test(v)||opt.test(v);},minLength:function(v,elm,opt){return v.length>=opt;},maxLength:function(v,elm,opt){return v.length<=opt;},min:function(v,elm,opt){return v>=parseFloat(opt);},max:function(v,elm,opt){return v<=parseFloat(opt);},notOneOf:function(v,elm,opt){return $A(opt).all(function(value){return v!=value;});},oneOf:function(v,elm,opt){return $A(opt).any(function(value){return v==value;});},is:function(v,elm,opt){return v==opt;},isNot:function(v,elm,opt){return v!=opt;},equalToField:function(v,elm,opt){return v==$F(opt);},notEqualToField:function(v,elm,opt){return v!=$F(opt);},include:function(v,elm,opt){return $A(opt).all(function(value){return Validation.get(value).test(v,elm);});}};Validation.prototype={initialize:function(form,options){this.options=Object.extend({onSubmit:true,stopOnFirst:false,immediate:false,focusOnError:true,useTitles:false,onFormValidate:function(result,form){},onElementValidate:function(result,elm){}},options||{});this.form=$(form);if(this.options.onSubmit){$(this.form.down('.button-submit')).observe('click',this.onSubmit.bind(this),false);}if($(this.form.down('.button-reset'))){$(this.form.down('.button-reset')).observe('click',function(e){Validation.getInstance().reset();}.bindAsEventListener($(this.form.down('.button-reset'))));}if(this.options.immediate){var useTitles=this.options.useTitles;var callback=this.options.onElementValidate;Form.getElements(this.form).each(function(input){Event.observe(input,'blur',function(ev){Validation.validate(Event.element(ev),{useTitle:useTitles,onElementValidate:callback});});});}},onSubmit:function(ev){var uri,dir,page;if(!this.validate()){Event.stop(ev);}else{uri=document.location.href;dir=uri.substring(0,uri.lastIndexOf('\/'));page=uri.substring(dir.length+1,uri.length+1);if(page.split('.aspx').length>1){page=(page.split('.aspx')).first()+".aspx";}else{page=(page.split('.html')).first()+".aspx";}submitAction(this.form.id,page,"post");}},validate:function(){var result=false,useTitles=this.options.useTitles,callback=this.options.onElementValidate,listErrorBox,errrorNum,reviewButton,formalname=this.form.id,txtListErrorBox=this.form.id+'-list-error-box';$$(".form-error-details").each(function(theelm){$(theelm).remove();});if(this.options.stopOnFirst){result=Form.getElements(this.form).all(function(elm){return Validation.validate(elm,{useTitle:useTitles,onElementValidate:callback});});}else{result=Form.getElements(this.form).collect(function(elm){return Validation.validate(elm,{useTitle:useTitles,onElementValidate:callback});}).all();}if(!result&&this.options.focusOnError){errrorNum=($$(".validation-failed").size());if(errrorNum>1){if($$(".validation-failed")){listErrorBox=Builder.node('div',{className:'form-error-details',id:txtListErrorBox},[Builder.node('h3',siemens.Locals.submitionError),Builder.node('p',siemens.Locals.reviewErrors.gsub('#',errrorNum)),Builder.node('ol')]);this.form.down('.form-container').insert({top:listErrorBox});if(!$(this.form.id+'review-button')){reviewButton=Builder.node('a',{id:this.form.id+'review-button',className:'button',href:'#'+txtListErrorBox},[Builder.node('span',{className:'button-wrapper'},[Builder.node('span',{className:'button-inner-wrapper'},[Builder.node('span',{className:'button-content'},siemens.Locals.reviewButton)])])]);this.form.down('.formaction').appendChild($(reviewButton));}window.location.hash="#"+txtListErrorBox;}Form.getElements(this.form).findAll(function(elm){var listItem,msg,elmLabel,p,elmName,innerElmLabel,elmLabelId,elmLabelValue,pLegend;if($(elm).hasClassName('validation-failed')){if(elm.type.toLowerCase()==="checkbox"||elm.type.toLowerCase()==="radio"){p=$(elm).parentNode.parentNode.parentNode;pLegend=p.parentNode.parentNode.previous().down();elmName=$(elm).parentNode.parentNode.down().down().id;if(p.down().down().firstChild.nodeValue){elmLabelValue=p.down().down().firstChild.nodeValue;}else{elmLabelValue=p.down().down().firstChild.cloneNode(true);}}else if(elm.hasClassName('validate-specify-chkrdo')){p=$(elm).parentNode.parentNode.parentNode;pLegend=p.parentNode.parentNode.previous().down();elmLabelValue="Other";elmName=$(elm).name;}else{p=$(elm).parentNode;pLegend=p.parentNode.previous().down();elmName=$(elm).name;if($(elm).parentNode.hasClassName("multi-inputs")&&($(elm).id===$(elm).parentNode.down('.multi-input-label').readAttribute('for'))){elmLabelValue=p.down('.multi-input-label').firstChild.nodeValue;}else{elmLabelValue=p.down().firstChild.nodeValue;}}if(pLegend.firstChild.nodeValue){pLegend=pLegend.firstChild.nodeValue;}else{pLegend=pLegend.down().firstChild.nodeValue;}elmLabelId="label"+elmName;if($(elmLabelId)){elmLabel=$(elmLabelId).cloneNode(true);elmLabel.id="error-"+elmLabel.id;}else{elmLabel=elmLabelValue;}msg=p.down(".validation-error-message").firstChild.nodeValue;msg=msg.slice(0,msg.length-1)+siemens.Locals.concatField;msg=msg+pLegend+" ";listItem=Builder.node('li',[Builder.node('span',msg),Builder.node('a',{className:'anchor',href:'javascript: FormTools.focusFunction("'+elmName+'");'},elmLabel)]);$(listErrorBox).down('ol').appendChild($(listItem));return $(elm).hasClassName('validation-failed');}});}else{window.location.hash="#"+txtListErrorBox;Form.getElements(this.form).findAll(function(elm){if($(elm).hasClassName('validation-failed')){if(elm.type.toLowerCase()==="checkbox"||elm.type.toLowerCase()==="radio"){$(elm).parentNode.parentNode.down('input').focus();}else{$(elm).focus();}}});}}this.options.onFormValidate(result,this.form);return result;},reset:function(){$(this.form.id).reset();$(this.form.id).select(".form-if-selected").each(function(elm){FormTools.resetIfSelect(elm);});this.form.select('.maxcount').each(FormTools.resetMaxCount);Form.getElements(this.form).each(Validation.reset);if($(this.form.id+'-list-error-box')){$(this.form.id+'-list-error-box').remove();$(this.form.id+'review-button').remove();}}};Object.extend(Validation,{validate:function(elm,options){options=Object.extend({useTitle:false,onElementValidate:function(result,elm){}},options||{});elm=$(elm);var cn=elm.classNames();return cn.all(function(value){var test=Validation.test(value,elm,options.useTitle);options.onElementValidate(test,elm);return test;});},test:function(name,elm,useTitle){var v=Validation.get(name);var prop='__advice'+name.camelize();var advice,errorMsg,labelOrLegend,labelOrLegendError;try{if(Validation.isVisible(elm)&&!v.test($F(elm),elm)){if(!elm[prop]){if(elm.type.toLowerCase()==='checkbox'||elm.type.toLowerCase()==='radio'){labelOrLegend=$(elm).parentNode.parentNode.parentNode.down('legend');}else if(elm.hasClassName('validate-specify-chkrdo')){labelOrLegend=$(elm).parentNode.parentNode.parentNode.down('legend');}else{if($(elm).parentNode.hasClassName("multi-inputs")&&($(elm).id===$(elm).parentNode.down('.multi-input-label').readAttribute('for'))){labelOrLegend=$(elm).parentNode.down('.multi-input-label');}else{labelOrLegend=$(elm).parentNode.down('label');}}labelOrLegendError=labelOrLegend.down(".validation-error");if(labelOrLegendError){labelOrLegendError.remove();}advice=Validation.getAdvice(name,elm);if(advice===null){errorMsg=useTitle?((elm&&elm.title)?elm.title:v.error):v.error;advice='<strong class="validation-error" id="advice-'+name+'-'+Validation.getElmID(elm)+'" style="display:none">'+siemens.Locals.error+'<span class="validation-error-message">'+errorMsg+'</span></strong>';switch(elm.type.toLowerCase()){case'checkbox':case'radio':if(labelOrLegend){Insertion.Bottom(labelOrLegend,advice);}else{Insertion.After(elm.parentNode.down(),advice);}break;default:if(elm.hasClassName('validate-specify-chkrdo')){Insertion.Bottom(labelOrLegend.down(),advice);}else{Insertion.Bottom(labelOrLegend,advice);}}advice=Validation.getAdvice(name,elm);}if(typeof Effect==='undefined'){advice.style.display='block';}else{Effect.Appear(advice,{duration:1});}}elm[prop]=true;elm.removeClassName('validation-passed');elm.addClassName('validation-failed');if(siemens.msieBrowser&&siemens.msieBrowser<7){if(elm.type.toLowerCase()==='checkbox'||elm.type.toLowerCase()==='radio'){return false;}else{elm.addClassName('input-text-error');}}return false;}else{advice=Validation.getAdvice(name,elm);if(advice!==null){advice.hide();}elm[prop]='';elm.removeClassName('validation-failed');elm.addClassName('validation-passed');if(siemens.msieBrowser&&siemens.msieBrowser<7){if(elm.type.toLowerCase()==='checkbox'||elm.type.toLowerCase()==='radio'){return true;}else{elm.removeClassName('input-text-error');}}return true;}}catch(e){throw(e);}},isVisible:function(elm){while(elm.tagName!='BODY'){if(!$(elm).visible()){return false;}elm=elm.parentNode;}return true;},getAdvice:function(name,elm){return $('advice-'+name+'-'+Validation.getElmID(elm))||$('advice-'+Validation.getElmID(elm));},getElmID:function(elm){return elm.id?elm.id:elm.name;},reset:function(elm){elm=$(elm);var cn=elm.classNames();cn.each(function(value){var prop='__advice'+value.camelize();if(elm[prop]){var advice=Validation.getAdvice(value,elm);advice.hide();elm[prop]='';}elm.removeClassName('validation-failed');elm.removeClassName('validation-passed');});},add:function(className,error,test,options){var nv={};nv[className]=new Validator(className,error,test,options);Object.extend(Validation.methods,nv);},addAllThese:function(validators){var nv={};$A(validators).each(function(value){nv[value[0]]=new Validator(value[0],value[1],value[2],(value.length>3?value[3]:{}));});Object.extend(Validation.methods,nv);},get:function(name){return Validation.methods[name]?Validation.methods[name]:Validation.methods._LikeNoIDIEverSaw_;},methods:{'_LikeNoIDIEverSaw_':new Validator('_LikeNoIDIEverSaw_','',{})}});Validation.add('IsEmpty','',function(v){return((v===null)||(v.strip().length===0)||v==='enter info'||v===' ');});Validation.addAllThese([['validate-required',siemens.Locals.validRequire,function(v){return!Validation.get('IsEmpty').test(v);}],['validate-number',siemens.Locals.validNumber,function(v){return Validation.get('IsEmpty').test(v)||(!isNaN(v)&&!/^\s+$/.test(v));}],['validate-digits',siemens.Locals.validDigits,function(v){return Validation.get('IsEmpty').test(v)||!/[^\d]/.test(v);}],['validate-alpha',siemens.Locals.validAlpha,function(v){return Validation.get('IsEmpty').test(v)||/^[a-zA-Z]+$/.test(v);}],['validate-alphanum',siemens.Locals.validAlphaNum,function(v){return Validation.get('IsEmpty').test(v)||!/\W/.test(v);}],['validate-numhyph',siemens.Locals.validNumHyph,function(v){return Validation.get('IsEmpty').test(v)||/^([0-9\s+\(+\)+-])*$/.test(v);}],['validate-usphone',siemens.Locals.validUsPhone,function(v){return Validation.get('IsEmpty').test(v)||/\(?\s?[2-9][0-9]{2}[(\s?\)?\s?)\-\.]{1,3}[0-9]{3}[\s\-\.]{1,3}[0-9]{4}/.test(v);}],['validate-date',siemens.Locals.validDate,function(v){var test=new Date(v);return Validation.get('IsEmpty').test(v)||!isNaN(test);}],['validate-year',siemens.Locals.validYear,function(v){return Validation.get('IsEmpty').test(v)||/^(\d{4})$/.test(v);}],['validate-range-year',siemens.Locals.validRangeYear,function(v){if(Validation.get('IsEmpty').test(v)){return true;}var regex=/^(\d{4})$/;if(!regex.test(v)){return false;}var d=new Date();if(v>d.getFullYear()||v<1800){return false;}else{return true;}}],['validate-email',siemens.Locals.validEmail,function(v){return Validation.get('IsEmpty').test(v)||/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test(v);}],['validate-url',siemens.Locals.validURL,function(v){return Validation.get('IsEmpty').test(v)||/^((https?|ftp):\/\/)?(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/?/i.test(v);}],['validate-maxcount',siemens.Locals.validMaxCount,function(v,elm){var getClasses=elm.className;var limit=parseFloat(getClasses.slice(((getClasses.search('maxcount-'))+9),getClasses.length));if($F($(elm)).length>limit){return false;}else{return true;}}],['validate-date-au',siemens.Locals.validDateAu,function(v){if(Validation.get('IsEmpty').test(v)){return true;}var regex=/^(\d{2})\/(\d{2})\/(\d{4})$/;if(!regex.test(v)){return false;}var d=new Date(v.replace(regex,'$2/$1/$3'));return(parseInt(RegExp.$2,10)==(1+d.getMonth()))&&(parseInt(RegExp.$1,10)==d.getDate())&&(parseInt(RegExp.$3,10)==d.getFullYear());}],['validate-currency-dollar',siemens.Locals.validCurrency,function(v){return Validation.get('IsEmpty').test(v)||/^\$?\-?([1-9]{1}[0-9]{0,2}(\,[0-9]{3})*(\.[0-9]{0,2})?|[1-9]{1}\d*(\.[0-9]{0,2})?|0(\.[0-9]{0,2})?|(\.[0-9]{1,2})?)$/.test(v);}],['validate-selection',siemens.Locals.validSelection,function(v,elm){return elm.options?elm.selectedIndex>0:!Validation.get('IsEmpty').test(v);}],['validate-one-required',siemens.Locals.validOneRequire,function(v,elm){var p=elm.parentNode.parentNode.parentNode;var elmClassName;if(elm.type.toLowerCase()==='checkbox'){elmClassName='checkbox';}else if(elm.type.toLowerCase()==='radio'){elmClassName='radio';}var options=p.getElementsByClassName(elmClassName);return $A(options).any(function(elm){return $F(elm);});}],['validate-specify-chkrdo',siemens.Locals.validOther,function(v,elm){var p=elm.parentNode.down();if(p.getValue()==="Other:"){if(Validation.get('IsEmpty').test(v)||(v==='specify')){return false;}else{return true;}}else{return true;}}]]);

