Events={'form':function(){this.addEvent('submit',this.clearEmptyInputs);if(this.hasClass('disabled')){var inputs=this.$$('input, select, textarea');for(j=0;j<inputs.length;j++){inputs[j].disabled=true;}}},'textarea':function(){if(this.getAttribute('maxlength')){this.addEvent('keypress',charsLeft);this.addEvent('keyup',charsLeft);this.addEvent('change',charsLeft);this.addEvent('mousedown',charsLeft);}},'a':function(){if(this.hasClass('new-window')){this.target='_blank';if(!this.getAttribute('title')){this.title='Opens in new window';}}
if(this.hasClass('munged-email')){this.addEvent('mouseover',unmungeEmail);}
if(this.hasClass('submit')){this.href='#_submit-link';this.addEvent('click',submitLink);}},'.flash':function(){flashDiv(this.id,0);},'.toggle':function(){this.href='#_toggle-link';this.addEvent('click',this.toggle);},'.alternate':function(){this.href='#_alternate-link';this.addEvent('click',this.alternate);},'[toappear], [toenable], [toupdate]':function(){this.oncondition();this.addEvent('keyup',this.oncondition);this.addEvent('change',this.oncondition);this.addEvent('click',this.oncondition);},'[tooltip]':function(){this.addEvent('mouseover',popupTooltip);},'[eg]':function(){this.addEvent('focus',this.removeEg);this.addEvent('mousedown',this.removeEg);this.addEvent('blur',this.addEg);this.addEg();},'.focus':function(){this.focus();if(this.getAttribute('eg')){this.addEg();this.select();}},'[rollover]':function(){this.addEvent('mouseover',rollover);this.addEvent('mouseout',rollout);}};function applyClassCode(singlecomponent,obj){if(!obj)obj=document;var elems=obj.getElementsByTagName('*');for(var i=0;i<elems.length;i++){for(e in Events){if(Element.matches.call(elems[i],e,singlecomponent))Events[e].call($(elems[i]));}}}
function Element(){}
Element.methods={};Element.methods['addMethod']=function(name,func){this.methods[name]=func;this[name]=func;}
Element.addMethod=Element.methods['addMethod'];Element.addMethod('extend',function(elem){if(elem.extended)return;elem.extended=true;for(name in this.methods){elem[name]=this.methods[name];}
return elem;});Element.addMethod('updatetext',function(text){if(this.nodeType==3)this.nodeValue=text;else if(!this.lastChild||this.lastChild.nodeType!=3){elem=document.createTextNode(text);this.appendChild(elem);}
else this.firstChild.nodeValue=text;return this;});Element.addMethod('add',function(elem,contents){if(elem.substring){elem=document.createElement(elem);}
if(contents!==null){elem.appendChild(document.createTextNode(contents));}
var child=this.appendChild(elem);return $(child);});Element.addMethod('remove',function(selector){var elems=this.$$(selector);for(var i in elems){this.removeChild(elems[i]);}});Element.addMethod('show',function(){if(this._display)this.style.display=this._display;else this.style.display='block';});Element.addMethod('hide',function(){if(this.style.display!='none')this._display=this.style.display;this.style.display='none';});Element.addMethod('enable',function(){this.removeClass('disabled');this.disabled=false;});Element.addMethod('disable',function(){this.addClass('disabled');this.disabled=true;});Element.addMethod('toggle',function(){if(this.style.display=='none')this.show();else this.hide();});Element.addMethod('alternate',function(event){$(this.getAttribute('show')).show();$(this.getAttribute('hide')).hide();var focusid=this.getAttribute('focusid');if(focusid)$(focusid).focus();});Element.addMethod('topleft',function(){return[this.offsetLeft,this.offsetTop];});Element.addMethod('bottomright',function(){return[this.offsetLeft+this.offsetWidth,this.offsetTop+this.offsetHeight];});Element.addMethod('overlaps',function(other){$(other);return overlaps(this.topleft(),this.bottomright(),other.topleft(),other.bottomright());});Element.addMethod('overlapping',function(elems){var over=[];for(var i=0;i<elems.length;i++){if(this.overlaps(elems[i])){over.push(elems[i]);}}
return over;});Element.addMethod('matches',function(simple,singlecomponent,final){if(!final){var selectors=simple.split(',');for(var i=0;i<selectors.length;i++){if(Element.matches.call(this,selectors[i],singlecomponent,true))return true;}
return false;}
var comps;if(!singlecomponent)comps=components(simple);else comps=[strip(simple)];var ismatch=true;for(var i=0;i<comps.length;i++){var component=comps[i];switch(component.charAt(0)){case'[':if(this.getAttribute(component.substring(1,component.length-1)))ismatch=true;else ismatch=false;break;case'#':ismatch=this.id==component.substring(1);break;case'.':ismatch=Element.hasClass.call(this,component.substring(1));break;default:ismatch=this.nodeName.toLowerCase()==component.toLowerCase();break;}
if(component=='*')ismatch=true;if(!ismatch)break;}
return ismatch;});Element.addMethod('computedStyle',function(){if(window.getComputedStyle){return window.getComputedStyle(this,null);}
else return this.currentStyle;});Element.addMethod('contains',function(descendant){var ret;try{if(!descendant)ret=false;else if(this.contains)ret=this.contains(descendant);else if(descendant==document.body)ret=false;else if(descendant.parentNode==this)ret=true;else ret=this.contains($(descendant).parentNode);}
catch(err){ret=false;}
return ret;});Element.addMethod('ancestor',function(selector){if(!selector)selector='*';if($(this.parentNode).matches(selector))return $(this.parentNode);if(this.parentNode==document.body)return null;return $(this.parentNode).ancestor(selector);});function pointin(point,tl,br){if(point[0]<tl[0]||point[0]>br[0])return false;if(point[1]<tl[1]||point[1]>br[1])return false;return true;}
function overlaps(tl1,br1,tl2,br2){if(pointin(tl1,tl2,br2))return true;if(pointin(br1,tl2,br2))return true;if(pointin(tl2,tl1,br1))return true;if(pointin(br2,tl1,br1))return true;return false}
function gettarget(){var loc=document.location.href;return $(loc.substr(loc.lastIndexOf('#')));}
Element.addMethod('getSelection',function(){if(this.getSelection)return this.getSelection();else return this.selection.createRange().text;});function clearSelection(){selection=window.getSelection;if(selection){if(selection.collapse)selection.collapse();else if(selection.removeAllRanges)selection.removeAllRanges();}
else if(document.selection){document.selection.clear();}}
function strip(string,character){if(!character)character=' ';re=new RegExp('^'+character+'*');string=string.replace(re,'');re=new RegExp(character+'*$');return string.replace(re,'');}
function _incomponentseparator(c){if(c=='.'||c=='['||c=='#')return true;return false;}
function components(simple){var c=[];simple=strip(simple);while(simple){var i=0;while(_incomponentseparator(simple.charAt(i))){i++;if(i>=simple.length)break;}
while(!_incomponentseparator(simple.charAt(i))){i++;if(i>=simple.length)break;}
var match=simple.substring(0,i);simple=simple.substring(match.length);c.push(match);}
return c;}
function simples(selector){var s=[];while(selector){var combinator=/ *[><\+]* */.exec(selector)[0];selector=selector.substring(combinator.length);var simple;if(selector.indexOf(' ')>=0){simple=selector.substring(0,selector.indexOf(' '));selector=selector.substring(selector.indexOf(' '));}
else{simple=selector;selector='';}
combinator=strip(combinator);if(!combinator)combinator=null;s.push([combinator,simple]);}
return s;}
function $$component(component,parent,combinator){var label;var elems;Element.extend(parent);if(!component)return null;label=/[a-zA-Z0-9-\*]+/.exec(component)[0];if(combinator=='+'||combinator=='++'){elems=[$(parent.nextSibling)];if(combinator=='++'&&elems[0].nodeName.charAt(0)=='#'){elems=[$(elems[0].nextSibling)];}}
else if(combinator=='<'){elems=[$(parent.parentNode)];}
else{switch(component.charAt(0)){case'[':elems=parent.getElementsByAttribute(label);break;case'#':var elem=$(document.getElementById(label));if(elem===null)elems=[];else elems=[elem];break;case'.':elems=parent.getElementsByClassName(label);break;default:elems=[];elems_=parent.getElementsByTagName(label);for(var i=0;i<elems_.length;i++)elems.push($(elems_[i]));break;}}
return elems;}
function $$simple(simple,parent,combinator){var elems=null;Element.extend(parent);var component=components(simple)[0];elems=$$component(component,parent,combinator);elems_=[];for(var i=0;i<elems.length;i++){var drop=!elems[i].matches(component);if(combinator=='>'&&parent!=elems[i].parentNode)drop=true;if(!drop)elems_.push(elems[i]);}
elems=elems_;return elems;}
function $$single(selector,parent){var label;Element.extend(parent);if(!selector)return[];var pool=[parent];var pool_=[];var simps=simples(selector);for(var i=0;i<simps.length;i++){combinator=simps[i][0];simple=simps[i][1];pool_=[];for(var j=0;j<pool.length;j++){pool_=pool_.concat($$simple(simple,pool[j],combinator));}
pool=pool_;if(!pool)break;}
for(var i=0;i<pool.length;i++)Element.extend(pool[i]);return pool;}
function $$(selector){var parent;var elems=[];if(this.nodeType)parent=this;else parent=document;Element.extend(parent);if(selector===null)elems=[];else if(selector.nodeType){Element.extend(selector);elems=[selector];}
else if(selector.substring){var selectors=selector.split(',');for(var i=0;i<selectors.length;i++){elems=elems.concat($$single(selectors[i],parent));}}
else{throw("Unknown type of object passed to $$ function");}
return elems;}
function $(selector){var parent;if(this.nodeType)parent=this;else parent=document;Element.extend(parent);var elems=parent.$$(selector);if(elems.length>=1)return elems[0];else return null;}
Element.addMethod('$$',$$);Element.addMethod('$',$);function addGlobalEvent(obj,name,func){if(obj.attachEvent){obj.attachEvent("on"+name,func);}else if(obj.addEventListener){obj.addEventListener(name,func,false);}}
function removeGlobalEvent(obj,name,func){if(document.attachEvent){obj.detachEvent("on"+name,func);}else if(document.addEventListener){obj.removeEventListener(name,func,false);}}
function eventTarget(e){var obj;if(document.attachEvent){obj=e.srcElement;}else if(document.addEventListener){obj=e.target;}
return $(obj);}
Element.addMethod('addEvent',function(name,func,toplevel){addGlobalEvent(this,name,eventHandler);if(!this.events){this.events={};}
if(!toplevel)toplevel=this;this.events[name]=[func,toplevel];});Element.addMethod('addDeepEvent',function(name,func){var descendants=this.$$('*');this.addEvent(name,func);for(var i=0;i<descendants.length;i++){descendants[i].addEvent(name,func,this);}});Element.addMethod('removeEvent',function(name,func){removeGlobalEvent(this,name,eventHandler);this.events[name]=null;});function eventHandler(e){if(e.stopPropagation)e.stopPropagation();else window.event.cancelBubble=true;return eventTarget(e).fireEvent(e.type,e);}
Element.addMethod('fireEvent',function(name,e){if(!this.events)throw"No events defined for this object";if(!this.events[name])throw"Event '"+name+"' not defined for this object";return this.events[name][0].call(this.events[name][1],e);});Element.addMethod('classes',function(){return this.className.split(' ');});Element.addMethod('hasClass',function(cName){return new RegExp('\\b'+cName+'\\b').test(this.className);});Element.addMethod('removeClass',function(cName){if(!this.hasClass(cName)){return false;}
var rep=this.className.match(' '+cName)?' '+cName:cName;this.className=this.className.replace(rep,'');return true;});Element.addMethod('addClass',function(cName){if(!this.hasClass(cName)){this.className+=this.className?' '+cName:cName;}
return true;});Element.addMethod('getElementsByAttribute',function(attribute,tag){tag=tag||'*';var all=this.all||this.getElementsByTagName(tag);var found=[];for(var f=0;f<all.length;f++){if($(all[f]).getAttribute(attribute)){found.push(all[f]);}}
return found;});Element.addMethod('getElementsByClassName',function(className,tag){tag=tag||'*';var all=this.all||this.getElementsByTagName(tag);var found=[];for(var f=0;f<all.length;f++){if($(all[f]).hasClass(className)){found.push(all[f]);}}
return found;});var ajaxTimeout=null;var ajaxseq=0;function ajax(url,data,handler){var req=false;ajaxseq+=1;ajaxseq_=ajaxseq;if(window.XMLHttpRequest){req=new window.XMLHttpRequest();}
else if(window.ActiveXObject){try{req=new ActiveXObject("Msxml2.XMLHTTP");}
catch(err1){try{req=new ActiveXObject("Microsoft.XMLHTTP");}
catch(err2){}}}
if(!req){throw('Browser does not support Ajax!');}
if(handler!=null){req.onreadystatechange=function(){processreq(req,handler,ajaxseq_);};async=true;}
else async=false;if(data){req.open('POST',url,async);var datas=[];var i=0;var idx;for(idx in data){datas[i]=escape(idx)+'='+escape(data[idx]);i++;}
data=datas.join('&');req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');req.send(data);}
else{req.open('GET',url,async);req.send(null);}
ajaxTimeout=setTimeout(function(){timeoutHandler(req);},7000);if(async)return ajaxseq;else return processreq(req);}
function unjsonize(str){var dict;eval("dict = "+str);return dict;}
function processreq(req,handler,seq){if(req.readyState!=4)return;clearTimeout(ajaxTimeout);ajaxTimeout=null;var data;var stat;try{stat=req.status;}
catch(err1){stat=500;}
if(stat==200||stat==403){try{data=unjsonize(req.responseText);}
catch(err2){stat=777;}}
if(stat!=777){if(handler)handler(data,stat,req,seq);else return[data,stat,req];}
else throw('Ajax error: '+req.responseText);}
function timeoutHandler(req){req.abort();}
Element.addMethod('toggleother',function(){var elems=this.$$(this.getAttribute('totoggle'));for(var i=0;i<elems.length;i++){elems[i].toggle();}});Element.addMethod('clearEmptyInputs',function(){var elems=this.getElementsByTagName('*');var i;for(i=0;i<elems.length;i++){if($(elems[i]).hasClass('empty')&&elems[i].getAttribute('eg')){elems[i].value='';elems[i].removeClass('empty');}}});Element.addMethod('removeEg',function(){if(this.hasClass('empty')){if(this.hasClass('focus')){this.removeClass('focus');this.addEvent('keydown',this.removeEg);}else{this.value='';}
this.select();this.removeClass('empty');}});Element.addMethod('addEg',function(){if((this.value==this.getAttribute('eg'))||(!this.value)){this.addClass('empty');this.value=this.getAttribute('eg');}});Element.addMethod('updatevalue',function(val,changed){var updatecode=this.getAttribute('updatecode');var newvalue=val;if(updatecode){updatecode=updatecode.replace(/%v/g,'val');updatecode=updatecode.replace(/this\.[a-z0-9]*/g,'this.getAttribute("$1")');updatecode=updatecode.replace(/%c\.[a-z0-9]*/g,'changed.getAttribute("$1")');updatecode=updatecode.replace(/%c/g,'changed');newvalue=eval(updatecode);}
this.firstChild.nodeValue=newvalue;});Element.addMethod('oncondition',function(){var toupdate=this.getAttribute('toupdate');var toappear=this.getAttribute('toappear');var toenable=this.getAttribute('toenable');var runcode=this.getAttribute('runcode');var condition=this.getAttribute('condition');var match=this.getAttribute('match');var val=this.getAttribute('val');if(!val){if(this.type=='checkbox'||this.type=='radio')val=!!this.checked;else val=this.value;}
if(match){var re=new RegExp(match);condition=re.test(val);}
else if(condition){condition=condition.replace(/%v/g,'val');condition=eval(condition);}
else{condition=val;}
if(toupdate){if(condition){elems=this.$$(toupdate);for(var i=0;i<elems.length;i++){elems[i].updatevalue(val,this);}}}
if(toappear){elems=this.$$(toappear);if(condition){for(var i=0;i<elems.length;i++)elems[i].show();}
else{for(var i=0;i<elems.length;i++)elems[i].hide();}}
if(toenable){elems=this.$$(toenable);if(condition){for(var i=0;i<elems.length;i++)elems[i].enable();}
else{for(var i=0;i<elems.length;i++)elems[i].disable();}}
if(runcode)eval(runcode);});function gstcents(amount){return cents(addgst(amount));}
function addgst(amount){return amount+amount*GST;}
function cents(amount){return amount.toFixed(2);}
var currentTooltip=null;var currentKeepVisible=null;function popupTooltip(obj){var tooltip=document.getElementById(obj.getAttribute('tooltip'));currentTooltip=tooltip;var keepvisible;var vId=tooltip.getAttribute('keepvisible');if(!vId){keepvisible=obj;}else{keepvisible=document.getElementById(vId);}
currentKeepVisible=keepvisible;addGlobalEvent(keepvisible,'mouseout',hideTooltip);tooltip.style.display='block';}
function hideTooltip(e){var relatedTarget;if(e.relatedTarget){relatedTarget=e.relatedTarget;}else if(e.toElement){relatedTarget=e.toElement;}
if(contains(currentKeepVisible,relatedTarget)){return false;}
if(relatedTarget==currentKeepVisible){return false;}
currentTooltip.style.display='none';removeGlobalEvent(currentKeepVisible,'mouseout',hideTooltip);currentTooltip=null;currentKeepVisible=null;return true;}
var preloadedImages={};function preload(filename){preloadedImages[filename]=new Image();preloadedImages[filename].src=filename;}
function flashDiv(id,state){var div=document.getElementById(id);if(state==6){return;}
if(state%2==0){removeClass(div,'flash-off');removeClass(div,'flash');addClass(div,'flash');}else{removeClass(div,'flash');addClass(div,'flash-off');}
state+=1;var code='flashDiv("'+id+'", '+state+');';setTimeout(code,250);}
function unmungeEmail(anchor){if(anchor.href.indexOf('mailto:')>=0){return;}
var text=anchor.firstChild.nodeValue;var titleWords=anchor.title.split(' ');var email=titleWords[titleWords.length-1];if(text.indexOf('@')>=0){email=text.replace(/\.\.\./,email);}else{email=email.replace(/\[aht\]/,'@');}
anchor.href='mailto:'+email;anchor.title='Click to email';anchor.firstChild.nodeValue=email;}
function submitLink(obj){if(obj.nodeName.toLowerCase()!='a'){return;}
var form=ancestor(obj,'form');if(form){form.submit();}}
function rollover(obj,postfix){var img;if(obj.nodeName.toLowerCase()=='img'){img=obj;}else{img=obj.getElementsByTagName('img')[0];}
var altsrc=img.getAttribute('rollover');if(!img.origsrc){img.origsrc=img.src;}
if(!altsrc){var parts=img.origsrc.split('.');altsrc=parts[0];var j;for(j=1;j<(parts.length-1);j++){altsrc=altsrc+'.'+parts[j];}
altsrc=altsrc+postfix+'.'+parts[parts.length-1];}
img.src=altsrc;}
function rollout(obj){var img;if(obj.nodeName.toLowerCase()=='img'){img=obj;}else{img=obj.getElementsByTagName('img')[0];}
var origsrc=img.origsrc;img.src=origsrc;}
function charsLeft(textarea){var maxlength=parseInt(textarea.getAttribute('maxlength'),10);var countdown=document.getElementById(textarea.getAttribute('countdown'));textarea.value=textarea.value.substring(0,maxlength);countdown.firstChild.nodeValue=maxlength-textarea.value.length;}
