// tmLib 1.0.0--theMechanism's general code library
// Copyright 2008 Jeffrey Barke (themechanism.com)
// Dual licensed under the MIT (MIT-LICENSE.txt)
//	and GPL (GPL-LICENSE.txt) licenses.

// Dependencies:
	// Prototype 1.6.0
	// Scriptaculous 1.8.0: Builder
var tmLib={charNum2NumArr:function(str){return str.match(/\d+\.?\d*/g);},lnkExternalLaunch:function(strHref){objNewWin=window.open(strHref,'newwin');objNewWin.focus();},lnkPopupLaunch:function(href){objNewWin=window.open(href,'newwin','height=600,width=550,location=false,menubar=false');objNewWin.focus();},lnkExternalPrep:function(){if(!document.getElementsByTagName){return false;}
$$('a[rel="external"]','a.link-external').each(function(obj){obj.onclick=function(){tmLib.lnkExternalLaunch(this.getAttribute('href'));return false;}});$$('a[rel="nonWebFile"]','a.nonWebFile').each(function(obj){obj.onclick=function(){tmLib.lnkExternalLaunch(this.getAttribute('href'));return false;}});$$('a[rel="popup"]','a.popup').each(function(obj){obj.onclick=function(){tmLib.lnkPopupLaunch(this.getAttribute('href'));return false;}});},lnkJumpNav:function(strHref){window.location.href=strHref;},frmAddHelpers:function(){$$('input[type=image]').each(function(obj){obj.onclick=function(){if(this.disabled){return false;}else{$(this).addClassName('input-disabled');return true;}}});$$('.input').each(function(obj){Event.observe(obj,'focus',tmLib._frmFocus,false);Event.observe(obj,'blur',tmLib._frmBlur,false);});},checkForm:function(objForm){var blnError=false;var objFirst=null;var arrLabels=objForm.getElementsByTagName('label');for(var i=0;i<arrLabels.length;i++){if(Element.hasClassName(arrLabels[i],'required')){if(arrLabels[i].htmlFor){var objInput=$(arrLabels[i].htmlFor);}else{var objInput=Element.down(arrLabels[i],'input');}
var strErrorText=null;if(objInput!=null){strErrorText=tmLib.frmValidate(objInput,arrLabels[i]);if(strErrorText!=null){if(objFirst==null){objFirst=objInput;}
blnError=true;tmLib._writeCorrection(arrLabels[i],strErrorText);tmLib._addLiveCorrect(objInput);}else{tmLib._writeCorrection(arrLabels[i]);}}}}
if(blnError){objFirst.focus();return false;}else{return true;}},checkValidity:function(e){var objInput=$(Event.element(e));var strErrorText=null;var arrLabels=document.getElementsByTagName('label');var intLen=arrLabels.length;for(var i=0;i<intLen;i++){if(arrLabels[i].htmlFor==objInput.id){var objLabel=$(arrLabels[i]);break;}else if(arrLabels[i]==objInput.parentNode){var objLabel=$(arrLabels[i]);}}
strErrorText=tmLib.frmValidate(this,objLabel);if(strErrorText!=null){tmLib._writeCorrection(objLabel,strErrorText);}else{tmLib._writeCorrection(objLabel);}},frmValidate:function(objInput,objLabel){if(objInput.value.strip()==''){return'Please enter your '+objLabel.firstChild.data.toLowerCase().strip().replace(/:/,'').replace(/\*/,'').stripTags()+'.';}else if(Element.hasClassName(objLabel,'requiredEmail')&&!tmLib.validEmail(objInput.value)){return'Please supply a valid email address';}},validEmail:function(strEmail){if(strEmail.match(/^[\w\.\-]+@([\w\-]+\.)+[a-zA-Z]+$/)){return true;}
return false;},_frmBlur:function(e){Event.element(e).removeClassName('active');},_frmFocus:function(e){obj=$(Event.element(e));obj.addClassName('active');if(obj.nodeName=='TEXTAREA'||obj.type=='text'){obj.select();}},_addLiveCorrect:function(objInput){if(objInput.nodeName.toLowerCase()=='input'&&(objInput.getAttribute('type')=='text')){Event.observe(objInput,'keyup',tmLib.checkValidity,false);}else if(objInput.nodeName.toLowerCase()=='textarea'){Event.observe(objInput,'keyup',tmLib.checkValidity,false);}else if(objInput.nodeName.toLowerCase()=='select'){Event.observe(objInput,'change',tmLib.checkValidity,false);}else if(objInput.nodeName.toLowerCase()=='input'&&(objInput.getAttribute('type')=='file')){Event.observe(objInput,'change',tmLib.checkValidity,false);}},_removeError:function(objLabel){if(objLabel.htmlFor){var objInput=$(objLabel.htmlFor);}else{var objInput=Element.down(objLabel,'input');}
var objPar=$(objInput.parentNode);var arrErr=objPar.select('.errorNotice');if(arrErr.length>0){objPar.removeChild(arrErr[0]);};},_writeCorrection:function(objLabel,strText,blnCorrect){if(objLabel.htmlFor){var objInput=$(objLabel.htmlFor);}else{var objInput=Element.down(objLabel,'input');}
var objImage=objLabel.parentNode.getElementsByTagName('img')[0];if(!strText){if(objImage!=null){}
Element.removeClassName(objInput,'correctionText');tmLib._removeError(objLabel);}else{if(objImage==null){var objImg=Builder.node('img',{className:'correctionIcon'});}
tmLib._removeError(objLabel);var objP=Builder.node('p',{className:'errorNotice'},strText);objInput.parentNode.appendChild(objP);Element.addClassName(objInput,'correctionText');}
return true;}}
Event.observe(window,'load',tmLib.lnkExternalPrep.bindAsEventListener(tmLib),false);Event.observe(window,'load',tmLib.frmAddHelpers.bindAsEventListener(tmLib),false);