mesa.WebUtils={};mesa.WebUtils._AGENT=navigator.userAgent.toLowerCase();mesa.WebUtils.isIE=function(){return/msie/.test(mesa.WebUtils._AGENT)&&!/opera/.test(mesa.WebUtils._AGENT)};mesa.WebUtils.isIE6=function(){return/msie 6/.test(mesa.WebUtils._AGENT)&&!/opera/.test(mesa.WebUtils._AGENT)};mesa.WebUtils.isIE7=function(){return/msie 7/.test(mesa.WebUtils._AGENT)&&!/opera/.test(mesa.WebUtils._AGENT)};mesa.WebUtils.isIE8=function(){var b=-1;var a=new RegExp("trident/([0-9]{1,}[.0-9]{0,})");if(a.exec(mesa.WebUtils._AGENT)!=null){b=parseFloat(RegExp.$1)}return(b==4)};mesa.WebUtils.isFF=function(){return/firefox/.test(mesa.WebUtils._AGENT)};mesa.WebUtils.isFF2=function(){return/firefox\/2/.test(mesa.WebUtils._AGENT)};mesa.WebUtils.isFF3=function(){return/firefox\/3/.test(mesa.WebUtils._AGENT)};mesa.WebUtils.isChrome=function(){return/chrome/.test(mesa.WebUtils._AGENT)};mesa.WebUtils.isMozilla=function(){return/mozilla/.test(mesa.WebUtils._AGENT)&&!/(compatible|webkit)/.test(mesa.WebUtils._AGENT)};mesa.WebUtils.isMac=function(){return/mac/.test(mesa.WebUtils._AGENT)};mesa.WebUtils.isSafari=function(){return/safari/.test(mesa.WebUtils._AGENT)};mesa.WebUtils.detectFlash=function(){if(mesa.WebUtils.isIE()){for(var b=10;b>0;--b){try{new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+b);return b}catch(c){}}}else{if(navigator.plugins&&navigator.plugins.length){var a=navigator.plugins["Shockwave Flash"];if(a){return/Shockwave Flash (\d+)\..+/.exec(a.description)[1]}}}return 0};mesa.WebUtils.getFlashScript=function(e,d,b,a,c){if(!c){c=new Object()}if(!c.allowScriptAccess){c.allowScriptAccess="sameDomain"}if(!c.quality){c.quality="high"}if(!c.wmode){c.wmode="transparent"}return mesa.WebUtils.applyTemplate("flash",{id:e,movieUrl:d,width:b,height:a,params:c})};mesa.WebUtils.writeFlashScript=function(e,d,b,a,c){document.write(mesa.WebUtils.getFlashScript(e,d,b,a,c))};mesa.WebUtils.getFlashObject=function(a){return mesa.WebUtils.isIE()?$(a):document[a]};mesa.WebUtils.findElementPosition=function(b,a){if(typeof(a)=="string"){a=$(a)}var c=curtop=0;for(;b.offsetParent;b=b.offsetParent){if(a&&b==a){break}c+=b.offsetLeft;curtop+=b.offsetTop}return{x:c,y:curtop}};mesa.WebUtils.getWindowSize=function(){if(mesa.WebUtils.isIE()){return{w:document.documentElement.clientWidth||document.body.clientWidth,h:document.documentElement.clientHeight||document.body.clientHeight}}else{return{w:window.innerWidth,h:window.innerHeight}}};mesa.WebUtils.getPageSize=function(){return{w:Math.max(document.body.scrollWidth,document.documentElement.scrollWidth),h:Math.max(document.body.scrollHeight,document.documentElement.scrollHeight)}};mesa.WebUtils.getPageOffset=function(){if(mesa.WebUtils.isIE()){return{x:document.body.scrollLeft||document.documentElement.scrollLeft,y:document.body.scrollTop||document.documentElement.scrollTop}}else{return{x:window.pageXOffset,y:window.pageYOffset}}};mesa.WebUtils.getParameter=function(a){try{if(location.search){var c=location.search.substring(1).toQueryParams();if(typeof(c[a])=="string"){return c[a]}}}catch(b){}return null};mesa.WebUtils.setParameter=function(a,b){var c=new Object();c[a]=b;mesa.WebUtils.setParameters(c)};mesa.WebUtils.setParameters=function(c){var b=$H(c);var a="";if(location.search){a=location.search.substring(1);b.each(function(d){a=mesa.WebUtils.removeUrlParam(a,d.key)})}b.each(function(d){if(a.length>0){a+="&"}a+=encodeURIComponent(d.key)+"="+encodeURIComponent(d.value)});location.search=a};mesa.WebUtils.removeUrlParam=function(){var a=arguments[0];for(var b=1;b<arguments.length;++b){a=a.replace(new RegExp(arguments[b]+"=[^&]*&*"),"")}if(a.charAt(a.length-1)=="&"){a=a.substring(0,a.length-1)}return a};mesa.WebUtils.setRadioButtonValue=function(d,b,e){var a=d[b];if(a.length){for(var c=0;c<a.length;++c){if(a[c].value==e){a[c].checked=true;return}}}else{if(a.value&&a.value==e){a.checked=true}}};mesa.WebUtils.getRadioButtonValue=function(d,b){var a=d[b];if(a.length){for(var c=0;c<a.length;++c){if(a[c].checked){return a[c].value}}}else{if(a.checked&&a.value){return a.value}}return null};mesa.WebUtils.setSelectValue=function(b,d){var a=b.options;for(var c=0;c<a.length;++c){if(a[c].value==d){a[c].selected=true;return true}}return false};mesa.WebUtils.setSelectOptions=function(d,c,a){var b=d.options;b.length=0;for(var e=0;e<c.length;++e){b[e]=new Option(c[e].text,c[e].value);if(b[e].value==a){b[e].selected=true}}};mesa.WebUtils.readCookie=function(b){var e=b+"=";var a=document.cookie.split(";");for(var d=0;d<a.length;d++){var f=a[d];while(f.charAt(0)==" "){f=f.substring(1,f.length)}if(f.indexOf(e)==0){return f.substring(e.length,f.length)}}return null};mesa.WebUtils.createCookie=function(c,d,f,e){if(f){var b=new Date();if(0>=f){b.setTime(0)}else{b.setTime(b.getTime()+(f*24*60*60*1000))}var a="; expires="+b.toGMTString()}else{var a=""}if(!e){e="/"}document.cookie=c+"="+d+a+"; path="+e};mesa.WebUtils.reload=function(){mesa.WebUtils.setParameter("_timestamp",new Date().getTime())};mesa.WebUtils.nl2br=function(a){if(!a){return a}return a.replace(/(\r\n|\r|\n)/g,"<br/>")};mesa.WebUtils.initSelect=function(b,a,e,f){if(typeof(b)=="string"){b=$(b)}if(!f){f=new Object()}if(!f.name){f.name="value"}b.options.length=0;if(f.allowNull){b.options[0]=new Option("Choose "+f.name+"..","")}for(var d=0;d<a.length;++d){if(a[d].text&&a[d].value){b.options[b.options.length]=new Option(a[d].text,a[d].value)}else{b.options[b.options.length]=new Option(a[d],a[d])}}for(var d=0;d<b.options.length;++d){if(b.options[d].value==e){b.selectedIndex=d;break}}if(f.allowNew){b.options[b.options.length]=new Option("Create New..","");var c=b.onchange;b.onchange=function(){var g=b.selectedIndex;if(g==b.options.length-1){mesa.Popup.prompt("Enter "+f.name+":",function(h){b.options[g]=new Option(h,h);b.options[b.options.length]=new Option("Create New..","");b.selectedIndex=g;if(c){c()}},function(){b.selectedIndex=0},f.maxLength,"","Create a New "+f.name)}else{if(c){c()}}}}};mesa.WebUtils.readRemoteFile=function(a){var b;if(window.XMLHttpRequest){b=new XMLHttpRequest()}else{if(window.ActiveXObject){b=new ActiveXObject("Microsoft.XMLHTTP")}}b.open("GET",a,false);b.send(null);if(b.status==200){return b.responseText}else{return null}};mesa.WebUtils.applyTemplate=function(h,b){var c=siteConfig.template;var a="{template "+h+"}";var d="{/template}";var f=c.indexOf(a);if(f>=0){var e=c.indexOf(d,f);if(e>f){var g=c.substring(f+a.length,e);var i=TrimPath.parseTemplate(g).process(b);i=i.replace(/\s+/gi," ").strip();return i}}throw"Template "+h+" not available"};mesa.WebUtils.declareMouseExitHandler=function(a,b){a=$(a);a.onmouseout=function(c){c=c||window.event;for(var d=c.relatedTarget||c.toElement;d&&d!=document.documentElement;d=d.parentNode){if(d==a){return}}b(c)}};mesa.WebUtils.declareClickAwayHandler=function(c,d){var e=[];if(c.length){for(var b=0;b<c.length;++b){e.push($(c[b]))}}else{e.push($(c))}var a=function(f){for(var h=Event.element(f);h!=null;h=h.parentNode){for(var g=0;g<e.length;++g){if(h==e[g]){return}}}d(f)};Event.observe(document,"click",a)};mesa.WebUtils.trackPageview=function(a){try{pageTracker._trackPageview(a)}catch(b){}};mesa.WebUtils.injectJS=function(c,d){var b=document.createElement("script");b.setAttribute("type","text/javascript");b.setAttribute("src",c);document.getElementsByTagName("head")[0].appendChild(b);var a=false;if(d){b.onload=b.onreadystatechange=function(){if(!a&&(!this.readyState||this.readyState=="loaded"||this.readyState=="complete")){a=true;d()}}}};mesa.WebUtils.initInputText=function(b,a){b.value=a;b.onfocus=function(){if(this.value==a){this.value=""}};b.onblur=function(){if(this.value.strip()==""){this.value=a}}};mesa.WebUtils.CustomDropDown=function(f,m,d,h,a){function g(i){f.innerHTML=a?a(i):i}var j;var b=f.scrollWidth;var k=f.scrollHeight;var c=document.createElement("div");c.className="dropPanel";c.style.width=b+"px";c.style.display="none";c.innerHTML=mesa.WebUtils.applyTemplate("dropDownMenu",{options:m});$A(c.getElementsByTagName("div")).each(function(i){i.onclick=function(){if(this.getAttribute("value")!=j){j=this.getAttribute("value");g(this.getAttribute("text"));d(j)}c.hide()}});document.body.appendChild(c);f.onclick=function(){var i=mesa.WebUtils.findElementPosition(f);c.style.left=i.x+"px";c.style.top=i.y+k+"px";c.show()};mesa.WebUtils.declareClickAwayHandler([f,c],function(){c.hide()});var l=false;for(var e=0;e<m.length;++e){if((h&&m[e].value==h)||(!h&&e==0)){j=m[e].value;g(m[e].text);l=true;break}}if(!l&&m.length>0){j=m[0].value;g(m[0].text)}this.getValue=function(){return j};this.setValue=function(o){for(var n=0;n<m.length;++n){if(m[n].value==o){j=m[n].value;g(m[n].text);break}}}};mesa.WebUtils.initInputs=function(){$$("input[default], textarea[default]").each(function(a){var b=a.getAttribute("default");Event.observe(a,"focus",function(){if(a.value.strip()==b){a.value=""}});Event.observe(a,"blur",function(){if(a.value.strip()==""){a.value=b}});if(a.value.strip()==""){a.value=b}a.getValue=function(){var c=a.value.strip();return c==b?"":c};if(a.getAttribute("maxlength")&&a.tagName.toLowerCase()=="textarea"){Event.observe(a,"keyup",function(){if(a.value.length>parseInt(a.getAttribute("maxlength"))){a.value=a.value.substring(0,parseInt(a.getAttribute("maxlength")))}})}})};
