var tmp,settings,divErrMsgs,tmp2;var browser="ie",placement="right";var ua=window.navigator.userAgent;var msie=ua.indexOf("MSIE ");InitializeErrorHandling();function InitializeErrorHandling(){settings=document.getElementById("settings");if(settings!=null){tmp=settings.getAttribute("placement");tmp2=settings.getAttribute("divMSG");if(tmp2!=null){divErrMsgs=document.getElementById(tmp2)}if(tmp.length>0){placement=tmp}}if(msie>0){browser="ie"}else{if(ua.indexOf("Chrome")>0){browser="ch"}else{if(ua.indexOf("Firefox")>0){browser="ff"}}}}function validateForm(a){for(k=0;k<document.forms.length;k++){return validateFormByForm(a,document.forms[k])}}function validateFormByForm(o,g){if(!g){return true}var f,c,a,h,e;var m=true;resetForm(o);if(divErrMsgs==null){InitializeErrorHandling()}divErrMsgs.innerHTML="";for(f=0;f<g.elements.length;f++){c=g.elements[f].type;curfield=g.elements[f];if(curfield.getAttribute("frmtype")==o){var l=true;if(curfield.getAttribute("parentID")!=null){if(document.getElementById(curfield.getAttribute("parentID")).style.display=="none"){l=false}}if(l){var e=curfield.getAttribute("validate");var b=curfield.getAttribute("vdisabled");if(b){var d=b.split(";")}l=true;var n=e.split(";");for(k=0;k<n.length;k++){if(b){if(d.length>k){if(d[k]=="true"){l=false}}}if(l){if(!isValid(curfield,n[k])){h=curfield.getAttribute("errmsg");a=createErrorDiv(curfield,o);ShowDIV(a,curfield,"&nbsp;"+h.split(";")[k]);addToErrDIV(divErrMsgs,curfield.id,"&nbsp;"+h.split(";")[k]);m=false}else{if(n[k]=="phone"){FormatPhone(curfield)}}}}}}}divErrMsgs.innerHTML+="<br><br>";return m}function addToErrDIV(a,c,b){a.innerHTML+="<li>"+b+"</li>"}function isValid(obj,validateType){var rtn=true;var val=obj.value;var disabled=obj.getAttribute("disabled");if(disabled){if(disabled=="true"){return rtn}}if(obj.style.display!="none"){if(validateType=="required"&&val.length==0){rtn=false;var relatedControl=obj.getAttribute("relatedControl");if(relatedControl){var tmpID=relatedControl.split(";");for(j=0;j<tmpID.length;j++){if(document.getElementById(tmpID[j])){if(document.getElementById(tmpID[j]).value.length>0){rtn=true}}}}}else{if(validateType=="email"&&!isValidEmail(val)){rtn=false}else{if(validateType=="numeric"&&!isValidNumber(val)){rtn=false}else{if(validateType=="phone"&&!isValidPhone(val)){rtn=false}else{if(validateType=="money"&&!isValidMoney(val)){rtn=false}else{if(validateType=="custom"){rtn=eval(obj.getAttribute("custom_function"))}else{if(validateType=="regexp"){if(obj.value!=""){var pattern=obj.getAttribute("pattern2");var regex=new RegExp(pattern);if(regex.exec(obj.value)==null){rtn=true}else{rtn=false}}}else{if(validateType=="message"){if(obj.getAttribute("valid")){if(obj.getAttribute("valid")=="true"){rtn=true}else{rtn=false}}}else{if(validateType=="length"&&!isValidlength(obj)){rtn=false}}}}}}}}}}return rtn}AddValidationEvent();function isValidlength(c){var d=c.value;var a=c.getAttribute("lengthRequired");var b=true;if(d.length<a){b=false}return b}function isValidMoney(c){var b=true;if(c!=""){var a=new RegExp("^\\$?([1-9]{1}[0-9]{0,2}(\\,[0-9]{3})*(\\.[0-9]{0,2})?|[1-9]{1}[0-9]{0,}(\\.[0-9]{0,2})?|0(\\.[0-9]{0,2})?|(\\.[0-9]{1,2})?)$");if(a.exec(c)==null){b=false}else{b=true}}return b}function AddValidationEvent(){for(k=0;k<document.forms.length;k++){AddValidationEventByForm(document.forms[k])}}function AddValidationEventByForm(c){for(i=0;i<c.elements.length;i++){var b=c.elements[i];var a=b.getAttribute("validate");if(a){if(!b.getAttribute("NoChangeEvent")){b.onchange=OnChangeEvent}}}}function OnChangeEvent(b){var c;if(browser=="ff"||browser=="ch"){c=b.target}else{c=window.event.srcElement}var a=c.getAttribute("validate");if(a.indexOf("message")>=0){c.setAttribute("validate","true")}ValidateMe(c)}function GetPlacement(b){var a=b.getAttribute("placement");if(a){return a}else{return placement}}function ValidateMe(c){validateType=c.getAttribute("validate");var b=validateType.split(";");if(c.className=="txtErr"){if(GetPlacement(c)=="popup"){c.title=""}c.className="";var a=document.getElementById("Err"+c.id);if(a){if(browser=="ie"){a.removeNode(true)}if(browser=="ff"||browser=="ch"){a.parentNode.removeChild(a)}}}for(k=0;k!=b.length;k++){if(b[k]!="required"){if(!isValid(c,b[k])){errMsg=c.getAttribute("errmsg");newDiv=createErrorDiv(c,"default");ShowDIV(newDiv,c,"&nbsp;"+errMsg.split(";")[k]);addToErrDIV(divErrMsgs,c.id,"&nbsp;"+errMsg.split(";")[k]);rtn=false}else{if(b[k]=="phone"){FormatPhone(c)}}}}}function FormatPhone(c){if(isValidPhone(c.value)){var a=c.value;a=a.replace(".","");a=a.replace(" ","");a=a.replace(" ","");a=a.replace(" ","");a=a.replace(" ","");a=a.replace(" ","");a=a.replace(" ","");a=a.replace("-","");a=a.replace("(","");a=a.replace(")","");var b=a.split("");if(a.length==10){c.value="("+b[0]+b[1]+b[2]+")"+b[3]+b[4]+b[5]+"-"+b[6]+b[7]+b[8]+b[9]}if(a.length==11){c.value="("+b[1]+b[2]+b[3]+")"+b[4]+b[5]+b[6]+"-"+b[7]+b[8]+b[9]+b[10]}}}function isValidPhone(b){if(b.length==0){return true}var a=b.replace(".","");a=a.replace(" ","");a=a.replace(" ","");a=a.replace(" ","");a=a.replace(" ","");a=a.replace(" ","");a=a.replace(" ","");a=a.replace("-","");a=a.replace("(","");a=a.replace(")","");if((a.length==10||a.length==11)){return isValidNumber(a)}else{return false}}function isValidEmail(c){if(c.length==0){return true}var a,b=true;a=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;if(!a.test(c)){b=false}return b}function isValidNumber(c){if(c.length==0){return true}var a,b=true;a=/^([\d\.])+$/;if(!a.test(c)){b=false}return b}function createErrorDiv(a,c){var d=document.createElement("div");var b="Err"+a.id;d.id=b;d.name=b;d.setAttribute("frmtype",c);if(a.getAttribute("parentID")){document.getElementById(a.getAttribute("parentID")).style.position="relative";document.getElementById(a.getAttribute("parentID")).appendChild(d)}else{document.body.appendChild(d)}return d}function ShowDIV(c,a,b){var e,d,f=getElementPosition(a);setPos(c,a,f,GetPlacement(a));if(a.getAttribute("ErrorCSS")){c.className=a.getAttribute("ErrorCSS")}else{c.className="divErr"}a.className="txtErr";c.innerHTML=b;if(GetPlacement(a)=="popup"){a.title=b}}var PreMessageObj=null;function ShowErrorDIV(b){var c;if(browser=="ff"||browser=="ch"){c=b.target}else{c=window.event.srcElement}var a=document.getElementById("Err"+c.id);if(a){a.style.display="block"}}function HidenErrorDIV(a){var c;if(browser=="ff"||browser=="ch"){c=a.target}else{c=window.event.srcElement}c.style.display="none";var d=document.getElementById(c.id.substring(3));d.style.display="block";if(d){try{d.focus()}catch(b){}}}function HidenErrorDIV2(a){var b;if(browser=="ff"||browser=="ch"){b=a.target}else{b=window.event.srcElement}var c=document.getElementById("Err"+b.id);if(c){c.style.display="none"}}function setPos(c,b,f,d){var e=0,a=b.clientHeight;if(d=="above"){c.style.left=f.left+"px";c.style.top="0px";c.style.width=b.getAttribute("errWidth");c.style.height=20+"px"}else{if(d=="inside"){c.style.left=f.left+"px";c.style.top=f.top+"px";if(b.getAttribute("errWidth")){c.style.width=b.getAttribute("errWidth")}else{c.style.width=parseInt(b.style.width)+"px"}if(b.type=="select-one"){if(b.getAttribute("errHeight")){c.style.height=b.getAttribute("errHeight")}else{c.style.height="20px"}}else{if(b.getAttribute("errHeight")){c.style.height=b.getAttribute("errHeight")}else{if(b.clientHeight>2){c.style.height=b.clientHeight+"px"}else{c.style.height="21px"}}}c.onclick=HidenErrorDIV;if(!b.getAttribute("NoBlurEvent")){b.onblur=ShowErrorDIV}if(!b.getAttribute("NoFocusEvent")){b.onfocus=HidenErrorDIV2}}else{if(d=="popup"){c.style.display="none"}else{if(browser=="ff"){e=-4;a=b.offset+b.clientHeight}else{if(b.nodeName.toLowerCase()=="select"&&browser=="ie"&&d=="right"){e=10}else{if(browser=="ch"){e=4}}}if(d=="right"){c.style.left=(f.left+b.clientWidth+0+e)+"px";if(browser=="ch"){c.style.top=(f.top+1)+"px"}else{c.style.top=(f.top+0)+"px"}if(b.getAttribute("errWidth")!=null){c.style.width=b.getAttribute("errWidth")}else{c.style.width="150px"}c.style.height=(b.offsetHeight)+"px"}else{c.style.left=(f.left+1)+"px";if(browser=="ch"){c.style.top=(f.top+a+6+e)+"px"}else{c.style.top=(f.top+a+5+e)+"px"}c.style.width=b.offsetWidth+"px";c.style.height=b.offsetHeight+"px"}}}}}function HideDIV(a,b){var c;c=document.getElementById(b);if(c!=null){a.className="";c.display="none";document.body.removeChild(c)}}function resetForm(a){for(k=0;k<document.forms.length;k++){resetFormByForm(a,document.forms[k])}}function resetFormByForm(c,f){var b,a,d,e;d=document.getElementsByTagName("*");a=d.length-1;for(b=a;b>=0;b--){e=d[b];if(e.getAttribute("frmtype")==c){e.className="";if(GetPlacement(e)=="popup"){e.title=""}}if(e.id.substring(0,3).toLowerCase()=="err"&&e.getAttribute("frmtype")==c){if(browser=="ie"){e.removeNode(true)}if(browser=="ff"||browser=="ch"){e.parentNode.removeChild(e)}}}}function getElementPosition(a){var d=0;var c=0;var b=a;while(a){d+=a.offsetLeft;c+=a.offsetTop;a=a.offsetParent;if(a&&b.getAttribute("parentID")){if(a.id==b.getAttribute("parentID")){break}}}if(navigator.userAgent.indexOf("Mac")!=-1&&typeof document.body.leftMargin!="undefined"){d+=document.body.leftMargin;c+=document.body.topMargin}return{left:d,top:c}}function Resized(){if(typeof MoveWindow=="function"){MoveWindow()}};
