

//MooTools, My Object Oriented Javascript Tools. Copyright (c) 2006-2007 Valerio Proietti, <http://mad4milk.net>, MIT Style License.

var MooTools={version:"1.11"};function $defined(A){return(A!=undefined);}function $type(B){if(!$defined(B)){return false;}if(B.htmlElement){return"element";
}var A=typeof B;if(A=="object"&&B.nodeName){switch(B.nodeType){case 1:return"element";case 3:return(/\S/).test(B.nodeValue)?"textnode":"whitespace";}}if(A=="object"||A=="function"){switch(B.constructor){case Array:return"array";
case RegExp:return"regexp";case Class:return"class";}if(typeof B.length=="number"){if(B.item){return"collection";}if(B.callee){return"arguments";}}}return A;
}function $merge(){var C={};for(var B=0;B<arguments.length;B++){for(var E in arguments[B]){var A=arguments[B][E];var D=C[E];if(D&&$type(A)=="object"&&$type(D)=="object"){C[E]=$merge(D,A);
}else{C[E]=A;}}}return C;}var $extend=function(){var A=arguments;if(!A[1]){A=[this,A[0]];}for(var B in A[1]){A[0][B]=A[1][B];}return A[0];};var $native=function(){for(var B=0,A=arguments.length;
B<A;B++){arguments[B].extend=function(C){for(var D in C){if(!this.prototype[D]){this.prototype[D]=C[D];}if(!this[D]){this[D]=$native.generic(D);}}};}};
$native.generic=function(A){return function(B){return this.prototype[A].apply(B,Array.prototype.slice.call(arguments,1));};};$native(Function,Array,String,Number);
function $chk(A){return !!(A||A===0);}function $pick(B,A){return $defined(B)?B:A;}function $random(B,A){return Math.floor(Math.random()*(A-B+1)+B);}function $time(){return new Date().getTime();
}function $clear(A){clearTimeout(A);clearInterval(A);return null;}var Abstract=function(A){A=A||{};A.extend=$extend;return A;};var Window=new Abstract(window);
var Document=new Abstract(document);document.head=document.getElementsByTagName("head")[0];window.xpath=!!(document.evaluate);if(window.ActiveXObject){window.ie=window[window.XMLHttpRequest?"ie7":"ie6"]=true;
}else{if(document.childNodes&&!document.all&&!navigator.taintEnabled){window.webkit=window[window.xpath?"webkit420":"webkit419"]=true;}else{if(document.getBoxObjectFor!=null){window.gecko=true;
}}}window.khtml=window.webkit;Object.extend=$extend;if(typeof HTMLElement=="undefined"){var HTMLElement=function(){};if(window.webkit){document.createElement("iframe");
}HTMLElement.prototype=(window.webkit)?window["[[DOMElement.prototype]]"]:{};}HTMLElement.prototype.htmlElement=function(){};if(window.ie6){try{document.execCommand("BackgroundImageCache",false,true);
}catch(e){}}var Class=function(B){var A=function(){return(arguments[0]!==null&&this.initialize&&$type(this.initialize)=="function")?this.initialize.apply(this,arguments):this;
};$extend(A,this);A.prototype=B;A.constructor=Class;return A;};Class.empty=function(){};Class.prototype={extend:function(B){var C=new this(null);for(var D in B){var A=C[D];
C[D]=Class.Merge(A,B[D]);}return new Class(C);},implement:function(){for(var B=0,A=arguments.length;B<A;B++){$extend(this.prototype,arguments[B]);}}};Class.Merge=function(C,D){if(C&&C!=D){var B=$type(D);
if(B!=$type(C)){return D;}switch(B){case"function":var A=function(){this.parent=arguments.callee.parent;return D.apply(this,arguments);};A.parent=C;return A;
case"object":return $merge(C,D);}}return D;};var Chain=new Class({chain:function(A){this.chains=this.chains||[];this.chains.push(A);return this;},callChain:function(){if(this.chains&&this.chains.length){this.chains.shift().delay(10,this);
}},clearChain:function(){this.chains=[];}});var Events=new Class({addEvent:function(B,A){if(A!=Class.empty){this.$events=this.$events||{};this.$events[B]=this.$events[B]||[];
this.$events[B].include(A);}return this;},fireEvent:function(C,B,A){if(this.$events&&this.$events[C]){this.$events[C].each(function(D){D.create({"bind":this,"delay":A,"arguments":B})();
},this);}return this;},removeEvent:function(B,A){if(this.$events&&this.$events[B]){this.$events[B].remove(A);}return this;}});var Options=new Class({setOptions:function(){this.options=$merge.apply(null,[this.options].extend(arguments));
if(this.addEvent){for(var A in this.options){if($type(this.options[A]=="function")&&(/^on[A-Z]/).test(A)){this.addEvent(A,this.options[A]);}}}return this;
}});Array.extend({forEach:function(C,D){for(var B=0,A=this.length;B<A;B++){C.call(D,this[B],B,this);}},filter:function(D,E){var C=[];for(var B=0,A=this.length;
B<A;B++){if(D.call(E,this[B],B,this)){C.push(this[B]);}}return C;},map:function(D,E){var C=[];for(var B=0,A=this.length;B<A;B++){C[B]=D.call(E,this[B],B,this);
}return C;},every:function(C,D){for(var B=0,A=this.length;B<A;B++){if(!C.call(D,this[B],B,this)){return false;}}return true;},some:function(C,D){for(var B=0,A=this.length;
B<A;B++){if(C.call(D,this[B],B,this)){return true;}}return false;},indexOf:function(C,D){var A=this.length;for(var B=(D<0)?Math.max(0,A+D):D||0;B<A;B++){if(this[B]===C){return B;
}}return -1;},copy:function(D,C){D=D||0;if(D<0){D=this.length+D;}C=C||(this.length-D);var A=[];for(var B=0;B<C;B++){A[B]=this[D++];}return A;},remove:function(C){var B=0;
var A=this.length;while(B<A){if(this[B]===C){this.splice(B,1);A--;}else{B++;}}return this;},contains:function(A,B){return this.indexOf(A,B)!=-1;},associate:function(C){var D={},B=Math.min(this.length,C.length);
for(var A=0;A<B;A++){D[C[A]]=this[A];}return D;},extend:function(C){for(var B=0,A=C.length;B<A;B++){this.push(C[B]);}return this;},merge:function(C){for(var B=0,A=C.length;
B<A;B++){this.include(C[B]);}return this;},include:function(A){if(!this.contains(A)){this.push(A);}return this;},getRandom:function(){return this[$random(0,this.length-1)]||null;
},getLast:function(){return this[this.length-1]||null;}});Array.prototype.each=Array.prototype.forEach;Array.each=Array.forEach;function $A(A){return Array.copy(A);
}function $each(C,B,D){if(C&&typeof C.length=="number"&&$type(C)!="object"){Array.forEach(C,B,D);}else{for(var A in C){B.call(D||C,C[A],A);}}}Array.prototype.test=Array.prototype.contains;
String.extend({test:function(A,B){return(($type(A)=="string")?new RegExp(A,B):A).test(this);},toInt:function(){return parseInt(this,10);},toFloat:function(){return parseFloat(this);
},camelCase:function(){return this.replace(/-\D/g,function(A){return A.charAt(1).toUpperCase();});},hyphenate:function(){return this.replace(/\w[A-Z]/g,function(A){return(A.charAt(0)+"-"+A.charAt(1).toLowerCase());
});},capitalize:function(){return this.replace(/\b[a-z]/g,function(A){return A.toUpperCase();});},trim:function(){return this.replace(/^\s+|\s+$/g,"");
},clean:function(){return this.replace(/\s{2,}/g," ").trim();},rgbToHex:function(B){var A=this.match(/\d{1,3}/g);return(A)?A.rgbToHex(B):false;},hexToRgb:function(B){var A=this.match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/);
return(A)?A.slice(1).hexToRgb(B):false;},contains:function(A,B){return(B)?(B+this+B).indexOf(B+A+B)>-1:this.indexOf(A)>-1;},escapeRegExp:function(){return this.replace(/([.*+?^${}()|[\]\/\\])/g,"\\$1");
}});Array.extend({rgbToHex:function(D){if(this.length<3){return false;}if(this.length==4&&this[3]==0&&!D){return"transparent";}var B=[];for(var A=0;A<3;
A++){var C=(this[A]-0).toString(16);B.push((C.length==1)?"0"+C:C);}return D?B:"#"+B.join("");},hexToRgb:function(C){if(this.length!=3){return false;}var A=[];
for(var B=0;B<3;B++){A.push(parseInt((this[B].length==1)?this[B]+this[B]:this[B],16));}return C?A:"rgb("+A.join(",")+")";}});Function.extend({create:function(A){var B=this;
A=$merge({"bind":B,"event":false,"arguments":null,"delay":false,"periodical":false,"attempt":false},A);if($chk(A.arguments)&&$type(A.arguments)!="array"){A.arguments=[A.arguments];
}return function(E){var C;if(A.event){E=E||window.event;C=[(A.event===true)?E:new A.event(E)];if(A.arguments){C.extend(A.arguments);}}else{C=A.arguments||arguments;
}var F=function(){return B.apply($pick(A.bind,B),C);};if(A.delay){return setTimeout(F,A.delay);}if(A.periodical){return setInterval(F,A.periodical);}if(A.attempt){try{return F();
}catch(D){return false;}}return F();};},pass:function(A,B){return this.create({"arguments":A,"bind":B});},attempt:function(A,B){return this.create({"arguments":A,"bind":B,"attempt":true})();
},bind:function(B,A){return this.create({"bind":B,"arguments":A});},bindAsEventListener:function(B,A){return this.create({"bind":B,"event":true,"arguments":A});
},delay:function(B,C,A){return this.create({"delay":B,"bind":C,"arguments":A})();},periodical:function(A,C,B){return this.create({"periodical":A,"bind":C,"arguments":B})();
}});Number.extend({toInt:function(){return parseInt(this);},toFloat:function(){return parseFloat(this);},limit:function(B,A){return Math.min(A,Math.max(B,this));
},round:function(A){A=Math.pow(10,A||0);return Math.round(this*A)/A;},times:function(B){for(var A=0;A<this;A++){B(A);}}});var Element=new Class({initialize:function(D,C){if($type(D)=="string"){if(window.ie&&C&&(C.name||C.type)){var A=(C.name)?' name="'+C.name+'"':"";
var B=(C.type)?' type="'+C.type+'"':"";delete C.name;delete C.type;D="<"+D+A+B+">";}D=document.createElement(D);}D=$(D);return(!C||!D)?D:D.set(C);}});var Elements=new Class({initialize:function(A){return(A)?$extend(A,this):this;
}});Elements.extend=function(A){for(var B in A){this.prototype[B]=A[B];this[B]=$native.generic(B);}};function $(B){if(!B){return null;}if(B.htmlElement){return Garbage.collect(B);
}if([window,document].contains(B)){return B;}var A=$type(B);if(A=="string"){B=document.getElementById(B);A=(B)?"element":false;}if(A!="element"){return null;
}if(B.htmlElement){return Garbage.collect(B);}if(["object","embed"].contains(B.tagName.toLowerCase())){return B;}$extend(B,Element.prototype);B.htmlElement=function(){};
return Garbage.collect(B);}document.getElementsBySelector=document.getElementsByTagName;function $$(){var D=[];for(var C=0,B=arguments.length;C<B;C++){var A=arguments[C];
switch($type(A)){case"element":D.push(A);case"boolean":break;case false:break;case"string":A=document.getElementsBySelector(A,true);default:D.extend(A);
}}return $$.unique(D);}$$.unique=function(G){var D=[];for(var C=0,A=G.length;C<A;C++){if(G[C].$included){continue;}var B=$(G[C]);if(B&&!B.$included){B.$included=true;
D.push(B);}}for(var F=0,E=D.length;F<E;F++){D[F].$included=null;}return new Elements(D);};Elements.Multi=function(A){return function(){var D=arguments;
var B=[];var G=true;for(var E=0,C=this.length,F;E<C;E++){F=this[E][A].apply(this[E],D);if($type(F)!="element"){G=false;}B.push(F);}return(G)?$$.unique(B):B;
};};Element.extend=function(A){for(var B in A){HTMLElement.prototype[B]=A[B];Element.prototype[B]=A[B];Element[B]=$native.generic(B);var C=(Array.prototype[B])?B+"Elements":B;
Elements.prototype[C]=Elements.Multi(B);}};Element.extend({set:function(A){for(var C in A){var B=A[C];switch(C){case"styles":this.setStyles(B);break;case"events":if(this.addEvents){this.addEvents(B);
}break;case"properties":this.setProperties(B);break;default:this.setProperty(C,B);}}return this;},inject:function(C,A){C=$(C);switch(A){case"before":C.parentNode.insertBefore(this,C);
break;case"after":var B=C.getNext();if(!B){C.parentNode.appendChild(this);}else{C.parentNode.insertBefore(this,B);}break;case"top":var D=C.firstChild;if(D){C.insertBefore(this,D);
break;}default:C.appendChild(this);}return this;},injectBefore:function(A){return this.inject(A,"before");},injectAfter:function(A){return this.inject(A,"after");
},injectInside:function(A){return this.inject(A,"bottom");},injectTop:function(A){return this.inject(A,"top");},adopt:function(){var A=[];$each(arguments,function(B){A=A.concat(B);
});$$(A).inject(this);return this;},remove:function(){return this.parentNode.removeChild(this);},clone:function(C){var B=$(this.cloneNode(C!==false));if(!B.$events){return B;
}B.$events={};for(var A in this.$events){B.$events[A]={"keys":$A(this.$events[A].keys),"values":$A(this.$events[A].values)};}return B.removeEvents();},replaceWith:function(A){A=$(A);
this.parentNode.replaceChild(A,this);return A;},appendText:function(A){this.appendChild(document.createTextNode(A));return this;},hasClass:function(A){return this.className.contains(A," ");
},addClass:function(A){if(!this.hasClass(A)){this.className=(this.className+" "+A).clean();}return this;},removeClass:function(A){this.className=this.className.replace(new RegExp("(^|\\s)"+A+"(?:\\s|$)"),"$1").clean();
return this;},toggleClass:function(A){return this.hasClass(A)?this.removeClass(A):this.addClass(A);},setStyle:function(B,A){switch(B){case"opacity":return this.setOpacity(parseFloat(A));
case"float":B=(window.ie)?"styleFloat":"cssFloat";}B=B.camelCase();switch($type(A)){case"number":if(!["zIndex","zoom"].contains(B)){A+="px";}break;case"array":A="rgb("+A.join(",")+")";
}this.style[B]=A;return this;},setStyles:function(A){switch($type(A)){case"object":Element.setMany(this,"setStyle",A);break;case"string":this.style.cssText=A;
}return this;},setOpacity:function(A){if(A==0){if(this.style.visibility!="hidden"){this.style.visibility="hidden";}}else{if(this.style.visibility!="visible"){this.style.visibility="visible";
}}if(!this.currentStyle||!this.currentStyle.hasLayout){this.style.zoom=1;}if(window.ie){this.style.filter=(A==1)?"":"alpha(opacity="+A*100+")";}this.style.opacity=this.$tmp.opacity=A;
return this;},getStyle:function(C){C=C.camelCase();var A=this.style[C];if(!$chk(A)){if(C=="opacity"){return this.$tmp.opacity;}A=[];for(var B in Element.Styles){if(C==B){Element.Styles[B].each(function(F){var E=this.getStyle(F);
A.push(parseInt(E)?E:"0px");},this);if(C=="border"){var D=A.every(function(E){return(E==A[0]);});return(D)?A[0]:false;}return A.join(" ");}}if(C.contains("border")){if(Element.Styles.border.contains(C)){return["Width","Style","Color"].map(function(E){return this.getStyle(C+E);
},this).join(" ");}else{if(Element.borderShort.contains(C)){return["Top","Right","Bottom","Left"].map(function(E){return this.getStyle("border"+E+C.replace("border",""));
},this).join(" ");}}}if(document.defaultView){A=document.defaultView.getComputedStyle(this,null).getPropertyValue(C.hyphenate());}else{if(this.currentStyle){A=this.currentStyle[C];
}}}if(window.ie){A=Element.fixStyle(C,A,this);}if(A&&C.test(/color/i)&&A.contains("rgb")){return A.split("rgb").splice(1,4).map(function(E){return E.rgbToHex();
}).join(" ");}return A;},getStyles:function(){return Element.getMany(this,"getStyle",arguments);},walk:function(A,C){A+="Sibling";var B=(C)?this[C]:this[A];
while(B&&$type(B)!="element"){B=B[A];}return $(B);},getPrevious:function(){return this.walk("previous");},getNext:function(){return this.walk("next");},getFirst:function(){return this.walk("next","firstChild");
},getLast:function(){return this.walk("previous","lastChild");},getParent:function(){return $(this.parentNode);},getChildren:function(){return $$(this.childNodes);
},hasChild:function(A){return !!$A(this.getElementsByTagName("*")).contains(A);},getProperty:function(D){var B=Element.Properties[D];if(B){return this[B];
}var A=Element.PropertiesIFlag[D]||0;if(!window.ie||A){return this.getAttribute(D,A);}var C=this.attributes[D];return(C)?C.nodeValue:null;},removeProperty:function(B){var A=Element.Properties[B];
if(A){this[A]="";}else{this.removeAttribute(B);}return this;},getProperties:function(){return Element.getMany(this,"getProperty",arguments);},setProperty:function(C,B){var A=Element.Properties[C];
if(A){this[A]=B;}else{this.setAttribute(C,B);}return this;},setProperties:function(A){return Element.setMany(this,"setProperty",A);},setHTML:function(){this.innerHTML=$A(arguments).join("");
return this;},setText:function(B){var A=this.getTag();if(["style","script"].contains(A)){if(window.ie){if(A=="style"){this.styleSheet.cssText=B;}else{if(A=="script"){this.setProperty("text",B);
}}return this;}else{this.removeChild(this.firstChild);return this.appendText(B);}}this[$defined(this.innerText)?"innerText":"textContent"]=B;return this;
},getText:function(){var A=this.getTag();if(["style","script"].contains(A)){if(window.ie){if(A=="style"){return this.styleSheet.cssText;}else{if(A=="script"){return this.getProperty("text");
}}}else{return this.innerHTML;}}return($pick(this.innerText,this.textContent));},getTag:function(){return this.tagName.toLowerCase();},empty:function(){Garbage.trash(this.getElementsByTagName("*"));
return this.setHTML("");}});Element.fixStyle=function(E,A,D){if($chk(parseInt(A))){return A;}if(["height","width"].contains(E)){var B=(E=="width")?["left","right"]:["top","bottom"];
var C=0;B.each(function(F){C+=D.getStyle("border-"+F+"-width").toInt()+D.getStyle("padding-"+F).toInt();});return D["offset"+E.capitalize()]-C+"px";}else{if(E.test(/border(.+)Width|margin|padding/)){return"0px";
}}return A;};Element.Styles={"border":[],"padding":[],"margin":[]};["Top","Right","Bottom","Left"].each(function(B){for(var A in Element.Styles){Element.Styles[A].push(A+B);
}});Element.borderShort=["borderWidth","borderStyle","borderColor"];Element.getMany=function(B,D,C){var A={};$each(C,function(E){A[E]=B[D](E);});return A;
};Element.setMany=function(B,D,C){for(var A in C){B[D](A,C[A]);}return B;};Element.Properties=new Abstract({"class":"className","for":"htmlFor","colspan":"colSpan","rowspan":"rowSpan","accesskey":"accessKey","tabindex":"tabIndex","maxlength":"maxLength","readonly":"readOnly","frameborder":"frameBorder","value":"value","disabled":"disabled","checked":"checked","multiple":"multiple","selected":"selected"});
Element.PropertiesIFlag={"href":2,"src":2};Element.Methods={Listeners:{addListener:function(B,A){if(this.addEventListener){this.addEventListener(B,A,false);
}else{this.attachEvent("on"+B,A);}return this;},removeListener:function(B,A){if(this.removeEventListener){this.removeEventListener(B,A,false);}else{this.detachEvent("on"+B,A);
}return this;}}};window.extend(Element.Methods.Listeners);document.extend(Element.Methods.Listeners);Element.extend(Element.Methods.Listeners);var Garbage={elements:[],collect:function(A){if(!A.$tmp){Garbage.elements.push(A);
A.$tmp={"opacity":1};}return A;},trash:function(D){for(var B=0,A=D.length,C;B<A;B++){if(!(C=D[B])||!C.$tmp){continue;}if(C.$events){C.fireEvent("trash").removeEvents();
}for(var E in C.$tmp){C.$tmp[E]=null;}for(var F in Element.prototype){C[F]=null;}Garbage.elements[Garbage.elements.indexOf(C)]=null;C.htmlElement=C.$tmp=C=null;
}Garbage.elements.remove(null);},empty:function(){Garbage.collect(window);Garbage.collect(document);Garbage.trash(Garbage.elements);}};window.addListener("beforeunload",function(){window.addListener("unload",Garbage.empty);
if(window.ie){window.addListener("unload",CollectGarbage);}});var Event=new Class({initialize:function(C){if(C&&C.$extended){return C;}this.$extended=true;
C=C||window.event;this.event=C;this.type=C.type;this.target=C.target||C.srcElement;if(this.target.nodeType==3){this.target=this.target.parentNode;}this.shift=C.shiftKey;
this.control=C.ctrlKey;this.alt=C.altKey;this.meta=C.metaKey;if(["DOMMouseScroll","mousewheel"].contains(this.type)){this.wheel=(C.wheelDelta)?C.wheelDelta/120:-(C.detail||0)/3;
}else{if(this.type.contains("key")){this.code=C.which||C.keyCode;for(var B in Event.keys){if(Event.keys[B]==this.code){this.key=B;break;}}if(this.type=="keydown"){var A=this.code-111;
if(A>0&&A<13){this.key="f"+A;}}this.key=this.key||String.fromCharCode(this.code).toLowerCase();}else{if(this.type.test(/(click|mouse|menu)/)){this.page={"x":C.pageX||C.clientX+document.documentElement.scrollLeft,"y":C.pageY||C.clientY+document.documentElement.scrollTop};
this.client={"x":C.pageX?C.pageX-window.pageXOffset:C.clientX,"y":C.pageY?C.pageY-window.pageYOffset:C.clientY};this.rightClick=(C.which==3)||(C.button==2);
switch(this.type){case"mouseover":this.relatedTarget=C.relatedTarget||C.fromElement;break;case"mouseout":this.relatedTarget=C.relatedTarget||C.toElement;
}this.fixRelatedTarget();}}}return this;},stop:function(){return this.stopPropagation().preventDefault();},stopPropagation:function(){if(this.event.stopPropagation){this.event.stopPropagation();
}else{this.event.cancelBubble=true;}return this;},preventDefault:function(){if(this.event.preventDefault){this.event.preventDefault();}else{this.event.returnValue=false;
}return this;}});Event.fix={relatedTarget:function(){if(this.relatedTarget&&this.relatedTarget.nodeType==3){this.relatedTarget=this.relatedTarget.parentNode;
}},relatedTargetGecko:function(){try{Event.fix.relatedTarget.call(this);}catch(A){this.relatedTarget=this.target;}}};Event.prototype.fixRelatedTarget=(window.gecko)?Event.fix.relatedTargetGecko:Event.fix.relatedTarget;
Event.keys=new Abstract({"enter":13,"up":38,"down":40,"left":37,"right":39,"esc":27,"space":32,"backspace":8,"tab":9,"delete":46});Element.Methods.Events={addEvent:function(C,B){this.$events=this.$events||{};
this.$events[C]=this.$events[C]||{"keys":[],"values":[]};if(this.$events[C].keys.contains(B)){return this;}this.$events[C].keys.push(B);var A=C;var D=Element.Events[C];
if(D){if(D.add){D.add.call(this,B);}if(D.map){B=D.map;}if(D.type){A=D.type;}}if(!this.addEventListener){B=B.create({"bind":this,"event":true});}this.$events[C].values.push(B);
return(Element.NativeEvents.contains(A))?this.addListener(A,B):this;},removeEvent:function(C,B){if(!this.$events||!this.$events[C]){return this;}var F=this.$events[C].keys.indexOf(B);
if(F==-1){return this;}var A=this.$events[C].keys.splice(F,1)[0];var E=this.$events[C].values.splice(F,1)[0];var D=Element.Events[C];if(D){if(D.remove){D.remove.call(this,B);
}if(D.type){C=D.type;}}return(Element.NativeEvents.contains(C))?this.removeListener(C,E):this;},addEvents:function(A){return Element.setMany(this,"addEvent",A);
},removeEvents:function(A){if(!this.$events){return this;}if(!A){for(var B in this.$events){this.removeEvents(B);}this.$events=null;}else{if(this.$events[A]){this.$events[A].keys.each(function(C){this.removeEvent(A,C);
},this);this.$events[A]=null;}}return this;},fireEvent:function(C,B,A){if(this.$events&&this.$events[C]){this.$events[C].keys.each(function(D){D.create({"bind":this,"delay":A,"arguments":B})();
},this);}return this;},cloneEvents:function(C,A){if(!C.$events){return this;}if(!A){for(var B in C.$events){this.cloneEvents(C,B);}}else{if(C.$events[A]){C.$events[A].keys.each(function(D){this.addEvent(A,D);
},this);}}return this;}};window.extend(Element.Methods.Events);document.extend(Element.Methods.Events);Element.extend(Element.Methods.Events);Element.Events=new Abstract({"mouseenter":{type:"mouseover",map:function(A){A=new Event(A);
if(A.relatedTarget!=this&&!this.hasChild(A.relatedTarget)){this.fireEvent("mouseenter",A);}}},"mouseleave":{type:"mouseout",map:function(A){A=new Event(A);
if(A.relatedTarget!=this&&!this.hasChild(A.relatedTarget)){this.fireEvent("mouseleave",A);}}},"mousewheel":{type:(window.gecko)?"DOMMouseScroll":"mousewheel"}});
Element.NativeEvents=["click","dblclick","mouseup","mousedown","mousewheel","DOMMouseScroll","mouseover","mouseout","mousemove","keydown","keypress","keyup","load","unload","beforeunload","resize","move","focus","blur","change","submit","reset","select","error","abort","contextmenu","scroll"];
Function.extend({bindWithEvent:function(B,A){return this.create({"bind":B,"arguments":A,"event":Event});}});Elements.extend({filterByTag:function(A){return new Elements(this.filter(function(B){return(Element.getTag(B)==A);
}));},filterByClass:function(A,C){var B=this.filter(function(D){return(D.className&&D.className.contains(A," "));});return(C)?B:new Elements(B);},filterById:function(C,B){var A=this.filter(function(D){return(D.id==C);
});return(B)?A:new Elements(A);},filterByAttribute:function(B,A,D,E){var C=this.filter(function(F){var G=Element.getProperty(F,B);if(!G){return false;}if(!A){return true;
}switch(A){case"=":return(G==D);case"*=":return(G.contains(D));case"^=":return(G.substr(0,D.length)==D);case"$=":return(G.substr(G.length-D.length)==D);
case"!=":return(G!=D);case"~=":return G.contains(D," ");}return false;});return(E)?C:new Elements(C);}});function $E(A,B){return($(B)||document).getElement(A);
}function $ES(A,B){return($(B)||document).getElementsBySelector(A);}$$.shared={"regexp":/^(\w*|\*)(?:#([\w-]+)|\.([\w-]+))?(?:\[(\w+)(?:([!*^$]?=)["']?([^"'\]]*)["']?)?])?$/,"xpath":{getParam:function(B,D,E,C){var A=[D.namespaceURI?"xhtml:":"",E[1]];
if(E[2]){A.push('[@id="',E[2],'"]');}if(E[3]){A.push('[contains(concat(" ", @class, " "), " ',E[3],' ")]');}if(E[4]){if(E[5]&&E[6]){switch(E[5]){case"*=":A.push("[contains(@",E[4],', "',E[6],'")]');
break;case"^=":A.push("[starts-with(@",E[4],', "',E[6],'")]');break;case"$=":A.push("[substring(@",E[4],", string-length(@",E[4],") - ",E[6].length,' + 1) = "',E[6],'"]');
break;case"=":A.push("[@",E[4],'="',E[6],'"]');break;case"!=":A.push("[@",E[4],'!="',E[6],'"]');}}else{A.push("[@",E[4],"]");}}B.push(A.join(""));return B;
},getItems:function(B,E,G){var F=[];var A=document.evaluate(".//"+B.join("//"),E,$$.shared.resolver,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);for(var D=0,C=A.snapshotLength;
D<C;D++){F.push(A.snapshotItem(D));}return(G)?F:new Elements(F.map($));}},"normal":{getParam:function(A,C,E,B){if(B==0){if(E[2]){var D=C.getElementById(E[2]);
if(!D||((E[1]!="*")&&(Element.getTag(D)!=E[1]))){return false;}A=[D];}else{A=$A(C.getElementsByTagName(E[1]));}}else{A=$$.shared.getElementsByTagName(A,E[1]);
if(E[2]){A=Elements.filterById(A,E[2],true);}}if(E[3]){A=Elements.filterByClass(A,E[3],true);}if(E[4]){A=Elements.filterByAttribute(A,E[4],E[5],E[6],true);
}return A;},getItems:function(A,B,C){return(C)?A:$$.unique(A);}},resolver:function(A){return(A=="xhtml")?"http://www.w3.org/1999/xhtml":false;},getElementsByTagName:function(D,C){var E=[];
for(var B=0,A=D.length;B<A;B++){E.extend(D[B].getElementsByTagName(C));}return E;}};$$.shared.method=(window.xpath)?"xpath":"normal";Element.Methods.Dom={getElements:function(A,H){var C=[];
A=A.trim().split(" ");for(var E=0,D=A.length;E<D;E++){var F=A[E];var G=F.match($$.shared.regexp);if(!G){break;}G[1]=G[1]||"*";var B=$$.shared[$$.shared.method].getParam(C,this,G,E);
if(!B){break;}C=B;}return $$.shared[$$.shared.method].getItems(C,this,H);},getElement:function(A){return $(this.getElements(A,true)[0]||false);},getElementsBySelector:function(A,E){var D=[];
A=A.split(",");for(var C=0,B=A.length;C<B;C++){D=D.concat(this.getElements(A[C],true));}return(E)?D:$$.unique(D);}};Element.extend({getElementById:function(C){var B=document.getElementById(C);
if(!B){return false;}for(var A=B.parentNode;A!=this;A=A.parentNode){if(!A){return false;}}return B;},getElementsByClassName:function(A){return this.getElements("."+A);
}});document.extend(Element.Methods.Dom);Element.extend(Element.Methods.Dom);Element.extend({getValue:function(){switch(this.getTag()){case"select":var A=[];
$each(this.options,function(B){if(B.selected){A.push($pick(B.value,B.text));}});return(this.multiple)?A:A[0];case"input":if(!(this.checked&&["checkbox","radio"].contains(this.type))&&!["hidden","text","password"].contains(this.type)){break;
}case"textarea":return this.value;}return false;},getFormElements:function(){return $$(this.getElementsByTagName("input"),this.getElementsByTagName("select"),this.getElementsByTagName("textarea"));
},toQueryString:function(){var A=[];this.getFormElements().each(function(D){var C=D.name;var E=D.getValue();if(E===false||!C||D.disabled){return ;}var B=function(F){A.push(C+"="+encodeURIComponent(F));
};if($type(E)=="array"){E.each(B);}else{B(E);}});return A.join("&");}});Element.extend({scrollTo:function(A,B){this.scrollLeft=A;this.scrollTop=B;},getSize:function(){return{"scroll":{"x":this.scrollLeft,"y":this.scrollTop},"size":{"x":this.offsetWidth,"y":this.offsetHeight},"scrollSize":{"x":this.scrollWidth,"y":this.scrollHeight}};
},getPosition:function(A){A=A||[];var B=this,D=0,C=0;do{D+=B.offsetLeft||0;C+=B.offsetTop||0;B=B.offsetParent;}while(B);A.each(function(E){D-=E.scrollLeft||0;
C-=E.scrollTop||0;});return{"x":D,"y":C};},getTop:function(A){return this.getPosition(A).y;},getLeft:function(A){return this.getPosition(A).x;},getCoordinates:function(B){var A=this.getPosition(B);
var C={"width":this.offsetWidth,"height":this.offsetHeight,"left":A.x,"top":A.y};C.right=C.left+C.width;C.bottom=C.top+C.height;return C;}});Element.Events.domready={add:function(B){if(window.loaded){B.call(this);
return ;}var A=function(){if(window.loaded){return ;}window.loaded=true;window.timer=$clear(window.timer);this.fireEvent("domready");}.bind(this);if(document.readyState&&window.webkit){window.timer=function(){if(["loaded","complete"].contains(document.readyState)){A();
}}.periodical(50);}else{if(document.readyState&&window.ie){if(!$("ie_ready")){var C=(window.location.protocol=="https:")?"://0":"javascript:void(0)";document.write('<script id="ie_ready" defer src="'+C+'"><\/script>');
$("ie_ready").onreadystatechange=function(){if(this.readyState=="complete"){A();}};}}else{window.addListener("load",A);document.addListener("DOMContentLoaded",A);
}}}};window.onDomReady=function(A){return this.addEvent("domready",A);};window.extend({getWidth:function(){if(this.webkit419){return this.innerWidth;}if(this.opera){return document.body.clientWidth;
}return document.documentElement.clientWidth;},getHeight:function(){if(this.webkit419){return this.innerHeight;}if(this.opera){return document.body.clientHeight;
}return document.documentElement.clientHeight;},getScrollWidth:function(){if(this.ie){return Math.max(document.documentElement.offsetWidth,document.documentElement.scrollWidth);
}if(this.webkit){return document.body.scrollWidth;}return document.documentElement.scrollWidth;},getScrollHeight:function(){if(this.ie){return Math.max(document.documentElement.offsetHeight,document.documentElement.scrollHeight);
}if(this.webkit){return document.body.scrollHeight;}return document.documentElement.scrollHeight;},getScrollLeft:function(){return this.pageXOffset||document.documentElement.scrollLeft;
},getScrollTop:function(){return this.pageYOffset||document.documentElement.scrollTop;},getSize:function(){return{"size":{"x":this.getWidth(),"y":this.getHeight()},"scrollSize":{"x":this.getScrollWidth(),"y":this.getScrollHeight()},"scroll":{"x":this.getScrollLeft(),"y":this.getScrollTop()}};
},getPosition:function(){return{"x":0,"y":0};}});var Fx={};Fx.Base=new Class({options:{onStart:Class.empty,onComplete:Class.empty,onCancel:Class.empty,transition:function(A){return -(Math.cos(Math.PI*A)-1)/2;
},duration:500,unit:"px",wait:true,fps:50},initialize:function(A){this.element=this.element||null;this.setOptions(A);if(this.options.initialize){this.options.initialize.call(this);
}},step:function(){var A=$time();if(A<this.time+this.options.duration){this.delta=this.options.transition((A-this.time)/this.options.duration);this.setNow();
this.increase();}else{this.stop(true);this.set(this.to);this.fireEvent("onComplete",this.element,10);this.callChain();}},set:function(A){this.now=A;this.increase();
return this;},setNow:function(){this.now=this.compute(this.from,this.to);},compute:function(B,A){return(A-B)*this.delta+B;},start:function(B,A){if(!this.options.wait){this.stop();
}else{if(this.timer){return this;}}this.from=B;this.to=A;this.change=this.to-this.from;this.time=$time();this.timer=this.step.periodical(Math.round(1000/this.options.fps),this);
this.fireEvent("onStart",this.element);return this;},stop:function(A){if(!this.timer){return this;}this.timer=$clear(this.timer);if(!A){this.fireEvent("onCancel",this.element);
}return this;},custom:function(B,A){return this.start(B,A);},clearTimer:function(A){return this.stop(A);}});Fx.Base.implement(new Chain,new Events,new Options);
Fx.CSS={select:function(B,C){if(B.test(/color/i)){return this.Color;}var A=$type(C);if((A=="array")||(A=="string"&&C.contains(" "))){return this.Multi;
}return this.Single;},parse:function(C,D,A){if(!A.push){A=[A];}var F=A[0],E=A[1];if(!$chk(E)){E=F;F=C.getStyle(D);}var B=this.select(D,E);return{"from":B.parse(F),"to":B.parse(E),"css":B};
}};Fx.CSS.Single={parse:function(A){return parseFloat(A);},getNow:function(C,B,A){return A.compute(C,B);},getValue:function(C,A,B){if(A=="px"&&B!="opacity"){C=Math.round(C);
}return C+A;}};Fx.CSS.Multi={parse:function(A){return A.push?A:A.split(" ").map(function(B){return parseFloat(B);});},getNow:function(E,D,C){var A=[];for(var B=0;
B<E.length;B++){A[B]=C.compute(E[B],D[B]);}return A;},getValue:function(C,A,B){if(A=="px"&&B!="opacity"){C=C.map(Math.round);}return C.join(A+" ")+A;}};
Fx.CSS.Color={parse:function(A){return A.push?A:A.hexToRgb(true);},getNow:function(E,D,C){var A=[];for(var B=0;B<E.length;B++){A[B]=Math.round(C.compute(E[B],D[B]));
}return A;},getValue:function(A){return"rgb("+A.join(",")+")";}};Fx.Style=Fx.Base.extend({initialize:function(B,C,A){this.element=$(B);this.property=C;
this.parent(A);},hide:function(){return this.set(0);},setNow:function(){this.now=this.css.getNow(this.from,this.to,this);},set:function(A){this.css=Fx.CSS.select(this.property,A);
return this.parent(this.css.parse(A));},start:function(C,B){if(this.timer&&this.options.wait){return this;}var A=Fx.CSS.parse(this.element,this.property,[C,B]);
this.css=A.css;return this.parent(A.from,A.to);},increase:function(){this.element.setStyle(this.property,this.css.getValue(this.now,this.options.unit,this.property));
}});Element.extend({effect:function(B,A){return new Fx.Style(this,B,A);}});Fx.Styles=Fx.Base.extend({initialize:function(B,A){this.element=$(B);this.parent(A);
},setNow:function(){for(var A in this.from){this.now[A]=this.css[A].getNow(this.from[A],this.to[A],this);}},set:function(C){var A={};this.css={};for(var B in C){this.css[B]=Fx.CSS.select(B,C[B]);
A[B]=this.css[B].parse(C[B]);}return this.parent(A);},start:function(C){if(this.timer&&this.options.wait){return this;}this.now={};this.css={};var E={},D={};
for(var B in C){var A=Fx.CSS.parse(this.element,B,C[B]);E[B]=A.from;D[B]=A.to;this.css[B]=A.css;}return this.parent(E,D);},increase:function(){for(var A in this.now){this.element.setStyle(A,this.css[A].getValue(this.now[A],this.options.unit,A));
}}});Element.extend({effects:function(A){return new Fx.Styles(this,A);}});Fx.Elements=Fx.Base.extend({initialize:function(B,A){this.elements=$$(B);this.parent(A);
},setNow:function(){for(var C in this.from){var F=this.from[C],E=this.to[C],B=this.css[C],A=this.now[C]={};for(var D in F){A[D]=B[D].getNow(F[D],E[D],this);
}}},set:function(G){var B={};this.css={};for(var D in G){var F=G[D],C=this.css[D]={},A=B[D]={};for(var E in F){C[E]=Fx.CSS.select(E,F[E]);A[E]=C[E].parse(F[E]);
}}return this.parent(B);},start:function(D){if(this.timer&&this.options.wait){return this;}this.now={};this.css={};var I={},J={};for(var E in D){var G=D[E],A=I[E]={},H=J[E]={},C=this.css[E]={};
for(var B in G){var F=Fx.CSS.parse(this.elements[E],B,G[B]);A[B]=F.from;H[B]=F.to;C[B]=F.css;}}return this.parent(I,J);},increase:function(){for(var C in this.now){var A=this.now[C],B=this.css[C];
for(var D in A){this.elements[C].setStyle(D,B[D].getValue(A[D],this.options.unit,D));}}}});Fx.Scroll=Fx.Base.extend({options:{overflown:[],offset:{"x":0,"y":0},wheelStops:true},initialize:function(B,A){this.now=[];
this.element=$(B);this.bound={"stop":this.stop.bind(this,false)};this.parent(A);if(this.options.wheelStops){this.addEvent("onStart",function(){document.addEvent("mousewheel",this.bound.stop);
}.bind(this));this.addEvent("onComplete",function(){document.removeEvent("mousewheel",this.bound.stop);}.bind(this));}},setNow:function(){for(var A=0;A<2;
A++){this.now[A]=this.compute(this.from[A],this.to[A]);}},scrollTo:function(B,F){if(this.timer&&this.options.wait){return this;}var D=this.element.getSize();
var C={"x":B,"y":F};for(var E in D.size){var A=D.scrollSize[E]-D.size[E];if($chk(C[E])){C[E]=($type(C[E])=="number")?C[E].limit(0,A):A;}else{C[E]=D.scroll[E];
}C[E]+=this.options.offset[E];}return this.start([D.scroll.x,D.scroll.y],[C.x,C.y]);},toTop:function(){return this.scrollTo(false,0);},toBottom:function(){return this.scrollTo(false,"full");
},toLeft:function(){return this.scrollTo(0,false);},toRight:function(){return this.scrollTo("full",false);},toElement:function(B){var A=this.element.getPosition(this.options.overflown);
var C=$(B).getPosition(this.options.overflown);return this.scrollTo(C.x-A.x,C.y-A.y);},increase:function(){this.element.scrollTo(this.now[0],this.now[1]);
}});Fx.Slide=Fx.Base.extend({options:{mode:"vertical"},initialize:function(B,A){this.element=$(B);this.wrapper=new Element("div",{"styles":$extend(this.element.getStyles("margin"),{"overflow":"hidden"})}).injectAfter(this.element).adopt(this.element);
this.element.setStyle("margin",0);this.setOptions(A);this.now=[];this.parent(this.options);this.open=true;this.addEvent("onComplete",function(){this.open=(this.now[0]===0);
});if(window.webkit419){this.addEvent("onComplete",function(){if(this.open){this.element.remove().inject(this.wrapper);}});}},setNow:function(){for(var A=0;
A<2;A++){this.now[A]=this.compute(this.from[A],this.to[A]);}},vertical:function(){this.margin="margin-top";this.layout="height";this.offset=this.element.offsetHeight;
},horizontal:function(){this.margin="margin-left";this.layout="width";this.offset=this.element.offsetWidth;},slideIn:function(A){this[A||this.options.mode]();
return this.start([this.element.getStyle(this.margin).toInt(),this.wrapper.getStyle(this.layout).toInt()],[0,this.offset]);},slideOut:function(A){this[A||this.options.mode]();
return this.start([this.element.getStyle(this.margin).toInt(),this.wrapper.getStyle(this.layout).toInt()],[-this.offset,0]);},hide:function(A){this[A||this.options.mode]();
this.open=false;return this.set([-this.offset,0]);},show:function(A){this[A||this.options.mode]();this.open=true;return this.set([0,this.offset]);},toggle:function(A){if(this.wrapper.offsetHeight==0||this.wrapper.offsetWidth==0){return this.slideIn(A);
}return this.slideOut(A);},increase:function(){this.element.setStyle(this.margin,this.now[0]+this.options.unit);this.wrapper.setStyle(this.layout,this.now[1]+this.options.unit);
}});Fx.Transition=function(B,A){A=A||[];if($type(A)!="array"){A=[A];}return $extend(B,{easeIn:function(C){return B(C,A);},easeOut:function(C){return 1-B(1-C,A);
},easeInOut:function(C){return(C<=0.5)?B(2*C,A)/2:(2-B(2*(1-C),A))/2;}});};Fx.Transitions=new Abstract({linear:function(A){return A;}});Fx.Transitions.extend=function(A){for(var B in A){Fx.Transitions[B]=new Fx.Transition(A[B]);
Fx.Transitions.compat(B);}};Fx.Transitions.compat=function(A){["In","Out","InOut"].each(function(B){Fx.Transitions[A.toLowerCase()+B]=Fx.Transitions[A]["ease"+B];
});};Fx.Transitions.extend({Pow:function(B,A){return Math.pow(B,A[0]||6);},Expo:function(A){return Math.pow(2,8*(A-1));},Circ:function(A){return 1-Math.sin(Math.acos(A));
},Sine:function(A){return 1-Math.sin((1-A)*Math.PI/2);},Back:function(B,A){A=A[0]||1.618;return Math.pow(B,2)*((A+1)*B-A);},Bounce:function(D){var C;for(var B=0,A=1;
1;B+=A,A/=2){if(D>=(7-4*B)/11){C=-Math.pow((11-6*B-11*D)/4,2)+A*A;break;}}return C;},Elastic:function(B,A){return Math.pow(2,10*--B)*Math.cos(20*B*Math.PI*(A[0]||1)/3);
}});["Quad","Cubic","Quart","Quint"].each(function(B,A){Fx.Transitions[B]=new Fx.Transition(function(C){return Math.pow(C,[A+2]);});Fx.Transitions.compat(B);
});var Drag={};Drag.Base=new Class({options:{handle:false,unit:"px",onStart:Class.empty,onBeforeStart:Class.empty,onComplete:Class.empty,onSnap:Class.empty,onDrag:Class.empty,limit:false,modifiers:{x:"left",y:"top"},grid:false,snap:6},initialize:function(B,A){this.setOptions(A);
this.element=$(B);this.handle=$(this.options.handle)||this.element;this.mouse={"now":{},"pos":{}};this.value={"start":{},"now":{}};this.bound={"start":this.start.bindWithEvent(this),"check":this.check.bindWithEvent(this),"drag":this.drag.bindWithEvent(this),"stop":this.stop.bind(this)};
this.attach();if(this.options.initialize){this.options.initialize.call(this);}},attach:function(){this.handle.addEvent("mousedown",this.bound.start);return this;
},detach:function(){this.handle.removeEvent("mousedown",this.bound.start);return this;},start:function(C){this.fireEvent("onBeforeStart",this.element);
this.mouse.start=C.page;var A=this.options.limit;this.limit={"x":[],"y":[]};for(var D in this.options.modifiers){if(!this.options.modifiers[D]){continue;
}this.value.now[D]=this.element.getStyle(this.options.modifiers[D]).toInt();this.mouse.pos[D]=C.page[D]-this.value.now[D];if(A&&A[D]){for(var B=0;B<2;B++){if($chk(A[D][B])){this.limit[D][B]=($type(A[D][B])=="function")?A[D][B]():A[D][B];
}}}}if($type(this.options.grid)=="number"){this.options.grid={"x":this.options.grid,"y":this.options.grid};}document.addListener("mousemove",this.bound.check);
document.addListener("mouseup",this.bound.stop);this.fireEvent("onStart",this.element);C.stop();},check:function(A){var B=Math.round(Math.sqrt(Math.pow(A.page.x-this.mouse.start.x,2)+Math.pow(A.page.y-this.mouse.start.y,2)));
if(B>this.options.snap){document.removeListener("mousemove",this.bound.check);document.addListener("mousemove",this.bound.drag);this.drag(A);this.fireEvent("onSnap",this.element);
}A.stop();},drag:function(A){this.out=false;this.mouse.now=A.page;for(var B in this.options.modifiers){if(!this.options.modifiers[B]){continue;}this.value.now[B]=this.mouse.now[B]-this.mouse.pos[B];
if(this.limit[B]){if($chk(this.limit[B][1])&&(this.value.now[B]>this.limit[B][1])){this.value.now[B]=this.limit[B][1];this.out=true;}else{if($chk(this.limit[B][0])&&(this.value.now[B]<this.limit[B][0])){this.value.now[B]=this.limit[B][0];
this.out=true;}}}if(this.options.grid[B]){this.value.now[B]-=(this.value.now[B]%this.options.grid[B]);}this.element.setStyle(this.options.modifiers[B],this.value.now[B]+this.options.unit);
}this.fireEvent("onDrag",this.element);A.stop();},stop:function(){document.removeListener("mousemove",this.bound.check);document.removeListener("mousemove",this.bound.drag);
document.removeListener("mouseup",this.bound.stop);this.fireEvent("onComplete",this.element);}});Drag.Base.implement(new Events,new Options);Element.extend({makeResizable:function(A){return new Drag.Base(this,$merge({modifiers:{x:"width",y:"height"}},A));
}});Drag.Move=Drag.Base.extend({options:{droppables:[],container:false,overflown:[]},initialize:function(B,A){this.setOptions(A);this.element=$(B);this.droppables=$$(this.options.droppables);
this.container=$(this.options.container);this.position={"element":this.element.getStyle("position"),"container":false};if(this.container){this.position.container=this.container.getStyle("position");
}if(!["relative","absolute","fixed"].contains(this.position.element)){this.position.element="absolute";}var D=this.element.getStyle("top").toInt();var C=this.element.getStyle("left").toInt();
if(this.position.element=="absolute"&&!["relative","absolute","fixed"].contains(this.position.container)){D=$chk(D)?D:this.element.getTop(this.options.overflown);
C=$chk(C)?C:this.element.getLeft(this.options.overflown);}else{D=$chk(D)?D:0;C=$chk(C)?C:0;}this.element.setStyles({"top":D,"left":C,"position":this.position.element});
this.parent(this.element);},start:function(C){this.overed=null;if(this.container){var A=this.container.getCoordinates();var B=this.element.getCoordinates();
if(this.position.element=="absolute"&&!["relative","absolute","fixed"].contains(this.position.container)){this.options.limit={"x":[A.left,A.right-B.width],"y":[A.top,A.bottom-B.height]};
}else{this.options.limit={"y":[0,A.height-B.height],"x":[0,A.width-B.width]};}}this.parent(C);},drag:function(A){this.parent(A);var B=this.out?false:this.droppables.filter(this.checkAgainst,this).getLast();
if(this.overed!=B){if(this.overed){this.overed.fireEvent("leave",[this.element,this]);}this.overed=B?B.fireEvent("over",[this.element,this]):null;}return this;
},checkAgainst:function(B){B=B.getCoordinates(this.options.overflown);var A=this.mouse.now;return(A.x>B.left&&A.x<B.right&&A.y<B.bottom&&A.y>B.top);},stop:function(){if(this.overed&&!this.out){this.overed.fireEvent("drop",[this.element,this]);
}else{this.element.fireEvent("emptydrop",this);}this.parent();return this;}});Element.extend({makeDraggable:function(A){return new Drag.Move(this,A);}});
var XHR=new Class({options:{method:"post",async:true,onRequest:Class.empty,onSuccess:Class.empty,onFailure:Class.empty,urlEncoded:true,encoding:"utf-8",autoCancel:false,headers:{}},setTransport:function(){this.transport=(window.XMLHttpRequest)?new XMLHttpRequest():(window.ie?new ActiveXObject("Microsoft.XMLHTTP"):false);
return this;},initialize:function(A){this.setTransport().setOptions(A);this.options.isSuccess=this.options.isSuccess||this.isSuccess;this.headers={};if(this.options.urlEncoded&&this.options.method=="post"){var B=(this.options.encoding)?"; charset="+this.options.encoding:"";
this.setHeader("Content-type","application/x-www-form-urlencoded"+B);}if(this.options.initialize){this.options.initialize.call(this);}},onStateChange:function(){if(this.transport.readyState!=4||!this.running){return ;
}this.running=false;var A=0;try{A=this.transport.status;}catch(B){}if(this.options.isSuccess.call(this,A)){this.onSuccess();}else{this.onFailure();}this.transport.onreadystatechange=Class.empty;
},isSuccess:function(A){return((A>=200)&&(A<300));},onSuccess:function(){this.response={"text":this.transport.responseText,"xml":this.transport.responseXML};
this.fireEvent("onSuccess",[this.response.text,this.response.xml]);this.callChain();},onFailure:function(){this.fireEvent("onFailure",this.transport);},setHeader:function(A,B){this.headers[A]=B;
return this;},send:function(A,C){if(this.options.autoCancel){this.cancel();}else{if(this.running){return this;}}this.running=true;if(C&&this.options.method=="get"){A=A+(A.contains("?")?"&":"?")+C;
C=null;}this.transport.open(this.options.method.toUpperCase(),A,this.options.async);this.transport.onreadystatechange=this.onStateChange.bind(this);if((this.options.method=="post")&&this.transport.overrideMimeType){this.setHeader("Connection","close");
}$extend(this.headers,this.options.headers);for(var B in this.headers){try{this.transport.setRequestHeader(B,this.headers[B]);}catch(D){}}this.fireEvent("onRequest");
this.transport.send($pick(C,null));return this;},cancel:function(){if(!this.running){return this;}this.running=false;this.transport.abort();this.transport.onreadystatechange=Class.empty;
this.setTransport();this.fireEvent("onCancel");return this;}});XHR.implement(new Chain,new Events,new Options);var Ajax=XHR.extend({options:{data:null,update:null,onComplete:Class.empty,evalScripts:false,evalResponse:false},initialize:function(B,A){this.addEvent("onSuccess",this.onComplete);
this.setOptions(A);this.options.data=this.options.data||this.options.postBody;if(!["post","get"].contains(this.options.method)){this._method="_method="+this.options.method;
this.options.method="post";}this.parent();this.setHeader("X-Requested-With","XMLHttpRequest");this.setHeader("Accept","text/javascript, text/html, application/xml, text/xml, */*");
this.url=B;},onComplete:function(){if(this.options.update){$(this.options.update).empty().setHTML(this.response.text);}if(this.options.evalScripts||this.options.evalResponse){this.evalScripts();
}this.fireEvent("onComplete",[this.response.text,this.response.xml],20);},request:function(A){A=A||this.options.data;switch($type(A)){case"element":A=$(A).toQueryString();
break;case"object":A=Object.toQueryString(A);}if(this._method){A=(A)?[this._method,A].join("&"):this._method;}return this.send(this.url,A);},evalScripts:function(){var B,A;
if(this.options.evalResponse||(/(ecma|java)script/).test(this.getHeader("Content-type"))){A=this.response.text;}else{A=[];var C=/<script[^>]*>([\s\S]*?)<\/script>/gi;
while((B=C.exec(this.response.text))){A.push(B[1]);}A=A.join("\n");}if(A){(window.execScript)?window.execScript(A):window.setTimeout(A,0);}},getHeader:function(A){try{return this.transport.getResponseHeader(A);
}catch(B){}return null;}});Object.toQueryString=function(B){var C=[];for(var A in B){C.push(encodeURIComponent(A)+"="+encodeURIComponent(B[A]));}return C.join("&");
};Element.extend({send:function(A){return new Ajax(this.getProperty("action"),$merge({data:this.toQueryString()},A,{method:"post"})).request();}});var Cookie=new Abstract({options:{domain:false,path:false,duration:false,secure:false},set:function(C,D,B){B=$merge(this.options,B);
D=encodeURIComponent(D);if(B.domain){D+="; domain="+B.domain;}if(B.path){D+="; path="+B.path;}if(B.duration){var A=new Date();A.setTime(A.getTime()+B.duration*24*60*60*1000);
D+="; expires="+A.toGMTString();}if(B.secure){D+="; secure";}document.cookie=C+"="+D;return $extend(B,{"key":C,"value":D});},get:function(A){var B=document.cookie.match("(?:^|;)\\s*"+A.escapeRegExp()+"=([^;]*)");
return B?decodeURIComponent(B[1]):false;},remove:function(B,A){if($type(B)=="object"){this.set(B.key,"",$merge(B,{duration:-1}));}else{this.set(B,"",$merge(A,{duration:-1}));
}}});var Json={toString:function(C){switch($type(C)){case"string":return'"'+C.replace(/(["\\])/g,"\\$1")+'"';case"array":return"["+C.map(Json.toString).join(",")+"]";
case"object":var A=[];for(var B in C){A.push(Json.toString(B)+":"+Json.toString(C[B]));}return"{"+A.join(",")+"}";case"number":if(isFinite(C)){break;}case false:return"null";
}return String(C);},evaluate:function(str,secure){return(($type(str)!="string")||(secure&&!str.test(/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/)))?null:eval("("+str+")");
}};Json.Remote=XHR.extend({initialize:function(B,A){this.url=B;this.addEvent("onSuccess",this.onComplete);this.parent(A);this.setHeader("X-Request","JSON");
},send:function(A){return this.parent(this.url,"json="+Json.toString(A));},onComplete:function(){this.fireEvent("onComplete",[Json.evaluate(this.response.text,this.options.secure)]);
}});var Asset=new Abstract({javascript:function(C,B){B=$merge({"onload":Class.empty},B);var A=new Element("script",{"src":C}).addEvents({"load":B.onload,"readystatechange":function(){if(this.readyState=="complete"){this.fireEvent("load");
}}});delete B.onload;return A.setProperties(B).inject(document.head);},css:function(B,A){return new Element("link",$merge({"rel":"stylesheet","media":"screen","type":"text/css","href":B},A)).inject(document.head);
},image:function(C,B){B=$merge({"onload":Class.empty,"onabort":Class.empty,"onerror":Class.empty},B);var D=new Image();D.src=C;var A=new Element("img",{"src":C});
["load","abort","error"].each(function(E){var F=B["on"+E];delete B["on"+E];A.addEvent(E,function(){this.removeEvent(E,arguments.callee);F.call(this);});
});if(D.width&&D.height){A.fireEvent("load",A,1);}return A.setProperties(B);},images:function(D,C){C=$merge({onComplete:Class.empty,onProgress:Class.empty},C);
if(!D.push){D=[D];}var A=[];var B=0;D.each(function(F){var E=new Asset.image(F,{"onload":function(){C.onProgress.call(this,B);B++;if(B==D.length){C.onComplete();
}}});A.push(E);});return new Elements(A);}});var Hash=new Class({length:0,initialize:function(A){this.obj=A||{};this.setLength();},get:function(A){return(this.hasKey(A))?this.obj[A]:null;
},hasKey:function(A){return(A in this.obj);},set:function(A,B){if(!this.hasKey(A)){this.length++;}this.obj[A]=B;return this;},setLength:function(){this.length=0;
for(var A in this.obj){this.length++;}return this;},remove:function(A){if(this.hasKey(A)){delete this.obj[A];this.length--;}return this;},each:function(A,B){$each(this.obj,A,B);
},extend:function(A){$extend(this.obj,A);return this.setLength();},merge:function(){this.obj=$merge.apply(null,[this.obj].extend(arguments));return this.setLength();
},empty:function(){this.obj={};this.length=0;return this;},keys:function(){var A=[];for(var B in this.obj){A.push(B);}return A;},values:function(){var A=[];
for(var B in this.obj){A.push(this.obj[B]);}return A;}});function $H(A){return new Hash(A);}Hash.Cookie=Hash.extend({initialize:function(B,A){this.name=B;
this.options=$extend({"autoSave":true},A||{});this.load();},save:function(){if(this.length==0){Cookie.remove(this.name,this.options);return true;}var A=Json.toString(this.obj);
if(A.length>4096){return false;}Cookie.set(this.name,A,this.options);return true;},load:function(){this.obj=Json.evaluate(Cookie.get(this.name),true)||{};
this.setLength();}});Hash.Cookie.Methods={};["extend","set","merge","empty","remove"].each(function(A){Hash.Cookie.Methods[A]=function(){Hash.prototype[A].apply(this,arguments);
if(this.options.autoSave){this.save();}return this;};});Hash.Cookie.implement(Hash.Cookie.Methods);var Color=new Class({initialize:function(B,D){D=D||(B.push?"rgb":"hex");
var C,A;switch(D){case"rgb":C=B;A=C.rgbToHsb();break;case"hsb":C=B.hsbToRgb();A=B;break;default:C=B.hexToRgb(true);A=C.rgbToHsb();}C.hsb=A;C.hex=C.rgbToHex();
return $extend(C,Color.prototype);},mix:function(){var A=$A(arguments);var C=($type(A[A.length-1])=="number")?A.pop():50;var B=this.copy();A.each(function(D){D=new Color(D);
for(var E=0;E<3;E++){B[E]=Math.round((B[E]/100*(100-C))+(D[E]/100*C));}});return new Color(B,"rgb");},invert:function(){return new Color(this.map(function(A){return 255-A;
}));},setHue:function(A){return new Color([A,this.hsb[1],this.hsb[2]],"hsb");},setSaturation:function(A){return new Color([this.hsb[0],A,this.hsb[2]],"hsb");
},setBrightness:function(A){return new Color([this.hsb[0],this.hsb[1],A],"hsb");}});function $RGB(C,B,A){return new Color([C,B,A],"rgb");}function $HSB(C,B,A){return new Color([C,B,A],"hsb");
}Array.extend({rgbToHsb:function(){var B=this[0],C=this[1],J=this[2];var G,F,H;var I=Math.max(B,C,J),E=Math.min(B,C,J);var K=I-E;H=I/255;F=(I!=0)?K/I:0;
if(F==0){G=0;}else{var D=(I-B)/K;var A=(I-C)/K;var L=(I-J)/K;if(B==I){G=L-A;}else{if(C==I){G=2+D-L;}else{G=4+A-D;}}G/=6;if(G<0){G++;}}return[Math.round(G*360),Math.round(F*100),Math.round(H*100)];
},hsbToRgb:function(){var C=Math.round(this[2]/100*255);if(this[1]==0){return[C,C,C];}else{var A=this[0]%360;var E=A%60;var F=Math.round((this[2]*(100-this[1]))/10000*255);
var D=Math.round((this[2]*(6000-this[1]*E))/600000*255);var B=Math.round((this[2]*(6000-this[1]*(60-E)))/600000*255);switch(Math.floor(A/60)){case 0:return[C,B,F];
case 1:return[D,C,F];case 2:return[F,C,B];case 3:return[F,D,C];case 4:return[B,F,C];case 5:return[C,F,D];}}return false;}});var Scroller=new Class({options:{area:20,velocity:1,onChange:function(A,B){this.element.scrollTo(A,B);
}},initialize:function(B,A){this.setOptions(A);this.element=$(B);this.mousemover=([window,document].contains(B))?$(document.body):this.element;},start:function(){this.coord=this.getCoords.bindWithEvent(this);
this.mousemover.addListener("mousemove",this.coord);},stop:function(){this.mousemover.removeListener("mousemove",this.coord);this.timer=$clear(this.timer);
},getCoords:function(A){this.page=(this.element==window)?A.client:A.page;if(!this.timer){this.timer=this.scroll.periodical(50,this);}},scroll:function(){var A=this.element.getSize();
var D=this.element.getPosition();var C={"x":0,"y":0};for(var B in this.page){if(this.page[B]<(this.options.area+D[B])&&A.scroll[B]!=0){C[B]=(this.page[B]-this.options.area-D[B])*this.options.velocity;
}else{if(this.page[B]+this.options.area>(A.size[B]+D[B])&&A.scroll[B]+A.size[B]!=A.scrollSize[B]){C[B]=(this.page[B]-A.size[B]+this.options.area-D[B])*this.options.velocity;
}}}if(C.y||C.x){this.fireEvent("onChange",[A.scroll.x+C.x,A.scroll.y+C.y]);}}});Scroller.implement(new Events,new Options);var Slider=new Class({options:{onChange:Class.empty,onComplete:Class.empty,onTick:function(A){this.knob.setStyle(this.p,A);
},mode:"horizontal",steps:100,offset:0},initialize:function(D,A,B){this.element=$(D);this.knob=$(A);this.setOptions(B);this.previousChange=-1;this.previousEnd=-1;
this.step=-1;this.element.addEvent("mousedown",this.clickedElement.bindWithEvent(this));var C,F;switch(this.options.mode){case"horizontal":this.z="x";this.p="left";
C={"x":"left","y":false};F="offsetWidth";break;case"vertical":this.z="y";this.p="top";C={"x":false,"y":"top"};F="offsetHeight";}this.max=this.element[F]-this.knob[F]+(this.options.offset*2);
this.half=this.knob[F]/2;this.getPos=this.element["get"+this.p.capitalize()].bind(this.element);this.knob.setStyle("position","relative").setStyle(this.p,-this.options.offset);
var E={};E[this.z]=[-this.options.offset,this.max-this.options.offset];this.drag=new Drag.Base(this.knob,{limit:E,modifiers:C,snap:0,onStart:function(){this.draggedKnob();
}.bind(this),onDrag:function(){this.draggedKnob();}.bind(this),onComplete:function(){this.draggedKnob();this.end();}.bind(this)});if(this.options.initialize){this.options.initialize.call(this);
}},set:function(A){this.step=A.limit(0,this.options.steps);this.checkStep();this.end();this.fireEvent("onTick",this.toPosition(this.step));return this;
},clickedElement:function(B){var A=B.page[this.z]-this.getPos()-this.half;A=A.limit(-this.options.offset,this.max-this.options.offset);this.step=this.toStep(A);
this.checkStep();this.end();this.fireEvent("onTick",A);},draggedKnob:function(){this.step=this.toStep(this.drag.value.now[this.z]);this.checkStep();},checkStep:function(){if(this.previousChange!=this.step){this.previousChange=this.step;
this.fireEvent("onChange",this.step);}},end:function(){if(this.previousEnd!==this.step){this.previousEnd=this.step;this.fireEvent("onComplete",this.step+"");
}},toStep:function(A){return Math.round((A+this.options.offset)/this.max*this.options.steps);},toPosition:function(A){return this.max*A/this.options.steps;
}});Slider.implement(new Events);Slider.implement(new Options);var SmoothScroll=Fx.Scroll.extend({initialize:function(B){this.parent(window,B);this.links=(this.options.links)?$$(this.options.links):$$(document.links);
var A=window.location.href.match(/^[^#]*/)[0]+"#";this.links.each(function(D){if(D.href.indexOf(A)!=0){return ;}var C=D.href.substr(A.length);if(C&&$(C)){this.useLink(D,C);
}},this);if(!window.webkit419){this.addEvent("onComplete",function(){window.location.hash=this.anchor;});}},useLink:function(B,A){B.addEvent("click",function(C){this.anchor=A;
this.toElement(A);C.stop();}.bindWithEvent(this));}});var Sortables=new Class({options:{handles:false,onStart:Class.empty,onComplete:Class.empty,ghost:true,snap:3,onDragStart:function(A,B){B.setStyle("opacity",0.7);
A.setStyle("opacity",0.7);},onDragComplete:function(A,B){A.setStyle("opacity",1);B.remove();this.trash.remove();}},initialize:function(D,B){this.setOptions(B);
this.list=$(D);this.elements=this.list.getChildren();this.handles=(this.options.handles)?$$(this.options.handles):this.elements;this.bound={"start":[],"moveGhost":this.moveGhost.bindWithEvent(this)};
for(var C=0,A=this.handles.length;C<A;C++){this.bound.start[C]=this.start.bindWithEvent(this,this.elements[C]);}this.attach();if(this.options.initialize){this.options.initialize.call(this);
}this.bound.move=this.move.bindWithEvent(this);this.bound.end=this.end.bind(this);},attach:function(){this.handles.each(function(B,A){B.addEvent("mousedown",this.bound.start[A]);
},this);},detach:function(){this.handles.each(function(B,A){B.removeEvent("mousedown",this.bound.start[A]);},this);},start:function(C,B){this.active=B;
this.coordinates=this.list.getCoordinates();if(this.options.ghost){var A=B.getPosition();this.offset=C.page.y-A.y;this.trash=new Element("div").inject(document.body);
this.ghost=B.clone().inject(this.trash).setStyles({"position":"absolute","left":A.x,"top":C.page.y-this.offset});document.addListener("mousemove",this.bound.moveGhost);
this.fireEvent("onDragStart",[B,this.ghost]);}document.addListener("mousemove",this.bound.move);document.addListener("mouseup",this.bound.end);this.fireEvent("onStart",B);
C.stop();},moveGhost:function(A){var B=A.page.y-this.offset;B=B.limit(this.coordinates.top,this.coordinates.bottom-this.ghost.offsetHeight);this.ghost.setStyle("top",B);
A.stop();},move:function(E){var B=E.page.y;this.previous=this.previous||B;var A=((this.previous-B)>0);var D=this.active.getPrevious();var C=this.active.getNext();
if(D&&A&&B<D.getCoordinates().bottom){this.active.injectBefore(D);}if(C&&!A&&B>C.getCoordinates().top){this.active.injectAfter(C);}this.previous=B;},serialize:function(A){return this.list.getChildren().map(A||function(B){return this.elements.indexOf(B);
},this);},end:function(){this.previous=null;document.removeListener("mousemove",this.bound.move);document.removeListener("mouseup",this.bound.end);if(this.options.ghost){document.removeListener("mousemove",this.bound.moveGhost);
this.fireEvent("onDragComplete",[this.active,this.ghost]);}this.fireEvent("onComplete",this.active);}});Sortables.implement(new Events,new Options);var Tips=new Class({options:{onShow:function(A){A.setStyle("visibility","visible");
},onHide:function(A){A.setStyle("visibility","hidden");},maxTitleChars:30,showDelay:100,hideDelay:100,className:"tool",offsets:{"x":16,"y":16},fixed:false},initialize:function(B,A){this.setOptions(A);
this.toolTip=new Element("div",{"class":this.options.className+"-tip","styles":{"position":"absolute","top":"0","left":"0","visibility":"hidden"}}).inject(document.body);
this.wrapper=new Element("div").inject(this.toolTip);$$(B).each(this.build,this);if(this.options.initialize){this.options.initialize.call(this);}},build:function(B){B.$tmp.myTitle=(B.href&&B.getTag()=="a")?B.href.replace("http://",""):(B.rel||false);
if(B.title){var C=B.title.split("::");if(C.length>1){B.$tmp.myTitle=C[0].trim();B.$tmp.myText=C[1].trim();}else{B.$tmp.myText=B.title;}B.removeAttribute("title");
}else{B.$tmp.myText=false;}if(B.$tmp.myTitle&&B.$tmp.myTitle.length>this.options.maxTitleChars){B.$tmp.myTitle=B.$tmp.myTitle.substr(0,this.options.maxTitleChars-1)+"&hellip;";
}B.addEvent("mouseenter",function(D){this.start(B);if(!this.options.fixed){this.locate(D);}else{this.position(B);}}.bind(this));if(!this.options.fixed){B.addEvent("mousemove",this.locate.bindWithEvent(this));
}var A=this.end.bind(this);B.addEvent("mouseleave",A);B.addEvent("trash",A);},start:function(A){this.wrapper.empty();if(A.$tmp.myTitle){this.title=new Element("span").inject(new Element("div",{"class":this.options.className+"-title"}).inject(this.wrapper)).setHTML(A.$tmp.myTitle);
}if(A.$tmp.myText){this.text=new Element("span").inject(new Element("div",{"class":this.options.className+"-text"}).inject(this.wrapper)).setHTML(A.$tmp.myText);
}$clear(this.timer);this.timer=this.show.delay(this.options.showDelay,this);},end:function(A){$clear(this.timer);this.timer=this.hide.delay(this.options.hideDelay,this);
},position:function(A){var B=A.getPosition();this.toolTip.setStyles({"left":B.x+this.options.offsets.x,"top":B.y+this.options.offsets.y});},locate:function(B){var D={"x":window.getWidth(),"y":window.getHeight()};
var A={"x":window.getScrollLeft(),"y":window.getScrollTop()};var C={"x":this.toolTip.offsetWidth,"y":this.toolTip.offsetHeight};var G={"x":"left","y":"top"};
for(var E in G){var F=B.page[E]+this.options.offsets[E];if((F+C[E]-A[E])>D[E]){F=B.page[E]-this.options.offsets[E]-C[E];}this.toolTip.setStyle(G[E],F);
}},show:function(){if(this.options.timeout){this.timer=this.hide.delay(this.options.timeout,this);}this.fireEvent("onShow",[this.toolTip]);},hide:function(){this.fireEvent("onHide",[this.toolTip]);
}});Tips.implement(new Events,new Options);var Group=new Class({initialize:function(){this.instances=$A(arguments);this.events={};this.checker={};},addEvent:function(B,A){this.checker[B]=this.checker[B]||{};
this.events[B]=this.events[B]||[];if(this.events[B].contains(A)){return false;}else{this.events[B].push(A);}this.instances.each(function(C,D){C.addEvent(B,this.check.bind(this,[B,C,D]));
},this);return this;},check:function(C,A,B){this.checker[C][B]=true;var D=this.instances.every(function(F,E){return this.checker[C][E]||false;},this);if(!D){return ;
}this.checker[C]={};this.events[C].each(function(E){E.call(this,this.instances,A);},this);}});var Accordion=Fx.Elements.extend({options:{onActive:Class.empty,onBackground:Class.empty,display:0,show:false,height:true,width:false,opacity:true,fixedHeight:false,fixedWidth:false,wait:false,alwaysHide:false},initialize:function(){var C,E,F,B;
$each(arguments,function(I,H){switch($type(I)){case"object":C=I;break;case"element":B=$(I);break;default:var G=$$(I);if(!E){E=G;}else{F=G;}}});this.togglers=E||[];
this.elements=F||[];this.container=$(B);this.setOptions(C);this.previous=-1;if(this.options.alwaysHide){this.options.wait=true;}if($chk(this.options.show)){this.options.display=false;
this.previous=this.options.show;}if(this.options.start){this.options.display=false;this.options.show=false;}this.effects={};if(this.options.opacity){this.effects.opacity="fullOpacity";
}if(this.options.width){this.effects.width=this.options.fixedWidth?"fullWidth":"offsetWidth";}if(this.options.height){this.effects.height=this.options.fixedHeight?"fullHeight":"scrollHeight";
}for(var D=0,A=this.togglers.length;D<A;D++){this.addSection(this.togglers[D],this.elements[D]);}this.elements.each(function(H,G){if(this.options.show===G){this.fireEvent("onActive",[this.togglers[G],H]);
}else{for(var I in this.effects){H.setStyle(I,0);}}},this);this.parent(this.elements);if($chk(this.options.display)){this.display(this.options.display);
}},addSection:function(E,C,G){E=$(E);C=$(C);var F=this.togglers.contains(E);var B=this.togglers.length;this.togglers.include(E);this.elements.include(C);
if(B&&(!F||G)){G=$pick(G,B-1);E.injectBefore(this.togglers[G]);C.injectAfter(E);}else{if(this.container&&!F){E.inject(this.container);C.inject(this.container);
}}var A=this.togglers.indexOf(E);E.addEvent("click",this.display.bind(this,A));if(this.options.height){C.setStyles({"padding-top":0,"border-top":"none","padding-bottom":0,"border-bottom":"none"});
}if(this.options.width){C.setStyles({"padding-left":0,"border-left":"none","padding-right":0,"border-right":"none"});}C.fullOpacity=1;if(this.options.fixedWidth){C.fullWidth=this.options.fixedWidth;
}if(this.options.fixedHeight){C.fullHeight=this.options.fixedHeight;}C.setStyle("overflow","hidden");if(!F){for(var D in this.effects){C.setStyle(D,0);
}}return this;},display:function(A){A=($type(A)=="element")?this.elements.indexOf(A):A;if((this.timer&&this.options.wait)||(A===this.previous&&!this.options.alwaysHide)){return this;
}this.previous=A;var B={};this.elements.each(function(E,D){B[D]={};var C=(D!=A)||(this.options.alwaysHide&&(E.offsetHeight>0));this.fireEvent(C?"onBackground":"onActive",[this.togglers[D],E]);
for(var F in this.effects){B[D][F]=C?0:E[this.effects[F]];}},this);return this.start(B);},showThisHideOpen:function(A){return this.display(A);}});Fx.Accordion=Accordion;


// JavaScript Document
var loading = new Array();
var section = document.location.href.replace(/^.*(&|\?)section=([^&]*).*$/g, '$2');
var module  = document.location.href.replace(/^.*(&|\?)module=([^&]*).*$/g, '$2');

window.addEvent('load', function(){
	try {
		loading.forEach(eval);
	} catch (e) {}	
});

listLatEdited = 1;
function nifty(name, option)
{
	var divlist = $$(name);	
	var div = new Array();
	
	option = option ? option : {};
	option.n = option.n ? option.n : 9;

	for(var i=0; i<divlist.length; i++){
		var main = divlist[i];
		if(main.niftilized) continue;
		main.niftilized = true;
		var niftyClass = name.replace(/^[^\.]*\.(.+)$/i, '$1');
		
		for (var j=0; j<option.n; j++) {
			div[j] = new Element('div');
			if(j){
				div[j].addClass('div'+j);
				div[j-1].adopt(div[j]);
			} else {
				div[0].addClass(niftyClass);
			}
		}
		
		main.replaceWith(div[0]);
		div[option.n-1].adopt(main);
		main.removeClass(niftyClass);
		div[0].setStyles(
			{
				width:main.getSize().size.x+'px',
				height:main.getSize().size.y+'px'
			});
		
		if(!option.fixStyle) {
			main.setStyle('border', '0');
		}
	}
}

// new ajax(url, {update:myObj}).request();
var ajax = Ajax.extend({
		xAjaxOptions: function(){
		return {										//change this values on site change
			loading: '../images/loading.gif',
			onError: function(tr){alert('Error in Ajax')},
			retry: 1,
			method: 'get',
			evalScripts: true,
			
			update: null,
			Tupdate: null,
			retryCount: 0
		};
	},

	initialize: function(url, options){
		this.addEvent('onFailure', this.onError);
		this.setOptions(this.xAjaxOptions(), options);
		this.parent(url, this.options);
	},

	onError: function(){
		if(this.retryCount>0) {
			this.request.delay(20, this, [true]);	
		} else {
			if(this.options.loading && $(this.options.update)) {
				$(this.options.update).replaceWith(this.Tupdate);
			}
			this.fireEvent('onError', [this.transport], 20);
		}
	},
	
	request: function(retry){
		if(!retry && this.url && this.options.loading && $(this.options.update)){
			this.Tupdate = $(this.options.update).clone();
			$(this.options.update).setHTML('');
			if(this.options.loading.test(/\.gif|png|jpg|jpeg$/i)) {
				var img = new Element('img');
				img.setProperty('id', 'loadingimg');
				img.setProperty('src', this.options.loading);
				$(this.options.update).adopt(img);
			} else {
				$(this.options.update).appendText(this.options.loading);
			}
		}
		this.retryCount = retry ? this.retryCount-1 : this.options.retry;
		var data = null;
		switch ($type(this.options.postBody)){
			case 'element': data = $(this.options.postBody).toQueryString(); break;
			case 'object': data = Object.toQueryString(this.options.postBody); break;
			case 'string': data = this.options.postBody;
		}
		if (this._method) data = (data) ? [this._method, data].join('&') : this._method;
		var url = this.url+(this.url.test(/^.+\?.+/) ? '&' : '?')+'_r_='+$random(1, 1000000);
		return this.send(url, data);
	}
});

function cover(obj, parent, id)
{
	if (Window.ie && !Window.ie7)
	{
		var style = {
						position: 'absolute',
						height: $(obj).getSize().size.y+'px',
						width: $(obj).getSize().size.x+'px',
						top: $(obj).getTop()+'px',
						left: $(obj).getLeft()+'px'
					 };
		var ziropos = {border:0, margin:0, padding:0, top:0, left:0, bakground:'transparent'};			
					 
		var div = new Element('div');
		div.setStyles(style);
		
		var iframe = new Element('iframe');
		iframe.setProperties({
								src: "javascript:false;",
								frameBorder: "0",
								scrolling: "no"
							 	});
		
		$(obj).setStyles(ziropos);
		div.injectInside(parent ? $(parent) : document.body);
		iframe.setStyles(style);
		iframe.setStyles(ziropos);		
		iframe.setStyle('z-index', '-1');
		iframe.injectInside(div);
		$(obj).injectInside(div);	
		if($(id)) $(id).id = '';
		div.id = id;
		
		return div;
	} 	
	return $(obj);
}

function setSub(parent, child, first, selected)
{										// any lang of parent options must set to somthing like this: <option lang="2=CD||5=DVD" ...
										// SELECT xgroup1id, xgroup1, GROUP_CONCAT( CONCAT(xgroup2id, '=', xgroup2) ORDER BY xgroup2 SEPARATOR '||' ) AS xgroup2 FROM xxgroup2 NATURAL LEFT JOIN xxgroup1 GROUP BY xgroup1id ORDER BY xgroup1
	parent = $(parent);
	child = $(child);
	if(!parent || !child) return;
	first = parseInt(first);
	var sel = parent.selectedIndex != -1 ? parent.options[parent.selectedIndex] : null;
	if(!sel) return;
	
	while(child.options[first]) {
		child.options[first] = null;							  	
	}
	if(sel.lang) {
		sel.lang.split('||').each(function(el){
										 	el = el.split('=', 2);
										   	child.options[first ? first : child.options.length] = new Option(el[1], el[0]);
											first = 0;
										   });	
	}
	if(selected) child.value = selected;
}

function validateForm(frm)
{
	validateInput = function(frm, data, format)
	{
		format = format.split('#');
		for(var i=0; i<format.length; i++){
			var fmt = format[i];
			if(fmt.charAt(0) == '/'){
				//alert('testing: '+fmt+' on '+data);
				fmt=eval(fmt);
				if(!fmt.test(data))
					return false;
			} else {
				fmt = fmt.split('_');
				fmt[1] = fmt[1].test(/^-?[\d]+$/g) ? fmt[1] : document.getElementsByName(fmt[1])[0].value;
				//alert('checking: '+data+' '+fmt[0]+' '+fmt[1]);
				switch(fmt[0]){
					case 'eq': if(data==fmt[1]) continue; else return false;
					case 'ne': if(data!=fmt[1]) continue; else return false;
					case 'gr': if(data >fmt[1]) continue; else return false;
					case 'ge': if(data>=fmt[1]) continue; else return false;
					case 'lr': if(data< fmt[1]) continue; else return false;
					case 'le': if(data>=fmt[1]) continue; else return false;
				};
				alert('Syntax Error.');
			}
		}
		return true;
	};
	
	var list = $$('#'+frm+' INPUT, #'+frm+' SELECT, #'+frm+' TEXTAREA, #'+frm+' CHECKBOX');
	for(var i=0; i<list.length; i++){
		var el = list[i];
		if(el.lang){
			if(!validateInput(frm, el.value, el.lang)) {
				el.focus();
				el.alt = el.alt ? el.alt : el.title;
				alert(el.alt ? el.alt : 'Please enter correct data.');
				return false;
			}
		}	
	};
}

function saveForm(frm, loc, duration)
{
	Cookie.set(loc, $(frm).toQueryString(), {duration: duration});
}

function loadForm(frm, loc)
{
	frm = $(frm);
	var savedVal = Cookie.get(loc) ? '&'+Cookie.get(loc)+'&' : '';
	if(frmid = frm.id){
		var list = $$('#'+frmid+' INPUT, #'+frmid+' SELECT, #'+frmid+' TEXTAREA');
		for(var i=0; i<list.length; i++){
			var ch = list[i];
			if(ch.type && ch.type.test(/button|submit|reset|file|image|hidden/ig) || !ch.name) continue;
			//alert(ch.type+ch.type.test(/password|button|submit|reset|file|image|hidden/ig));
			var reg = new RegExp('^.*&'+encodeURIComponent(ch.name)+'=([^&]*)&.*$');
			var val = decodeURIComponent(savedVal.replace(reg, '$1'));
			val = val.charAt(0)=='&' ? '' : val;
			//alert(reg + '\n' + val);
			if(val){
				if(ch.type && (ch.type=='checkbox' || ch.type=='radio')){
					ch.checked = (ch.value == val);
				} else {
					ch.value = val;
				}
			}
		}
	}
}

function checkBoxes(fmobj)
{
	for(var i = 0; i < fmobj.elements.length; i ++)
	{

		var e = fmobj.elements[i];
		if((e.type == 'checkbox') && (e.type == 'checkbox') && (e.checked == true))
		{
			return true;
		}
	}	
}

function checkAll(fmobj)
{
	for(var i = 0; i < fmobj.elements.length; i ++)
	{
		var e = fmobj.elements[i];
		if((e.name != 'allbox') && (e.type == 'checkbox') && (!e.disabled))
		{
			e.checked = fmobj.allbox.checked;
		}
	}
}

function checkCheckedAll(fmobj)
{	
	var TotalBoxes = 0;
	var TotalOn = 0;
	for(var i = 0; i < fmobj.elements.length; i ++)
	{
		var e = fmobj.elements[i];
		if((e.name != 'allbox') && (e.type == 'checkbox'))
		{
			TotalBoxes ++;
			if(e.checked)
			{
				TotalOn ++;
			}
		}
	}
	
	if (TotalBoxes == TotalOn)
	{
		fmobj.allbox.checked = true;
		return -1;		// all of them checked
	}
	else
	{
		fmobj.allbox.checked = false;
		return TotalOn;	// none of them checked=0 else some of them checked
	}
}

//------------ mail module ---------
function saveMail(id)
{
	$('cmd').value = 'save';
	if(id){		
		$('id').value = id;
	}
	$('form1').submit();
}

function sendMail(type)
{
	$('cmd').value = 'send';
	if(type){		
		$('type').value = type;
	}
	$('form1').submit();	
}
//------------/mail module ---------

function ajaxDelete(action, objName, sender)
{
	new ajax(action).request();
	if(objName && sender) {
		while(sender = sender.parentNode){
			if(sender.className == objName || sender.id == objName || sender.name == objName){
				sender.style.display = 'none';
				if(sender.tagName=="TR") {
					sender.parentNode.deleteRow(sender.sectionRowIndex);
				}
				return true;
			}
		}
	}
	return false;
}

function trace(val, obj)
{
	if(obj) {
		var res = [];
		res.push(val);
		var el;
		for (el in val) {
			res.push(el+' = '+val[el]);
		}
		res = res.join('<br>\n');
	} else {
		res = val;
	}
//	alert(val);
	var div = new Element('div');
	div.innerHTML = res;
	div.injectInside(document.body);
}

var Base64 = {

    // private property
    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

    // public method for encoding
    encode : function (input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;

        input = Base64._utf8_encode(input);

        while (i < input.length) {

            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);

            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;

            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }

            output = output +
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

        }

        return output;
    },

    // public method for decoding
    decode : function (input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        input = input ? input.replace(/[^A-Za-z0-9\+\/\=]/g, "") : '';

        while (i < input.length) {

            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));

            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;

            output = output + String.fromCharCode(chr1);

            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }

        }

        output = Base64._utf8_decode(output);

        return output;

    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}

Object.toQueryString = function(source){
	var queryString = [];
	for (var property in source) if(source[property]!='') queryString.push(encodeURIComponent(property)+'='+encodeURIComponent(source[property]));
	return queryString.join('&');
};

//loading.push('addStandardClass()');
function addStandardClass(parent)
{
	parent = parent ? parent+' ' : '';
	var list = $$(parent+'input');
	for(var i=0; i<list.length; i++) {
		var input = list[i];
		var type = input.getProperty('type') ? input.getProperty('type') : 'text';
		input.addClass('input_'+type);	
	}
}

function goto(idx, force)
{
	var cur = parseInt($('offset').value);
	var last = $('offset').options[$('offset').options.length-1].value;
	switch(idx) {
			case 'first': 
				idx = 1;
				break;
			case 'previous': 
				idx = cur==1 ? 1 : cur-1;
				break;
			case 'last': 
				idx = last;
				break;
			case 'next': 
				idx = cur==last ? cur :  cur+1;
				break;
			default:
				idx = Math.min(Math.max(idx, 1), last);
	}
	if(cur!=idx || force) {
		//if($('searchform')) $('searchform').reset();
		if($('offset')) $('offset').value = idx;
		loadList();	
	}
}

function loadList()
{
	var query1 = $('searchform') ? '&'+$('searchform').toQueryString() : '';
	var query2 = $('sortform')   ? '&'+$('sortform').toQueryString()   : '';
	var query3 = $('listform')   ? '&'+$('listform').toQueryString()   : '';
	var url = document.location.href.replace(/&cmd=[^&]*/, '').replace(/#.*/, '')+'&cmd=list'+query1+query2+query3;
	while (url.match(/(&|\?)[^=]+=(undefined)?(&|$)/ig))
		url = url.replace(/(&|\?)[^=]+=(undefined)?(&|$)/ig, '$3');
	new ajax(url, {update:'listdiv'}).request();
}

function saveToCookie(obj)
{
	var name = $pick($(obj).getProperty('id'), $(obj).getProperty('name'));
	var path = section + '/' + module + '/' + name;
	Cookie.set(encodeURI(path), $(obj).value, {});
}

function printTo(port, content)
{
	switch(port) {
		case 'prn':
			$each($(document.body).getChildren(), function(el){el.addClass('hidden');});
			printdiv = $(content).clone();
			printdiv.setStyles({
								height: Window.getSize().size.y+'px',
								background: '#FFFFFF',
								margin: '0',
								padding: '0'
						 		});
			printdiv.injectInside(document.body);
			printdiv.id="printdiv";
			var tdiv = new Element('div');
			tdiv.id = 'tdiv';			
			$each($$('#printdiv .noprint'), function(el){
				el.remove();
			});	
			
			$each($$('#printdiv .title'), function(el){
				el.setStyle('margin', '0 0 10px 0');
			});
			
			tdiv.setHTML('<div style="margin:20px; " class="noprint"><input type="button" value="Return" onclick="printTo(\'return\')"></div>');
			tdiv.injectBefore(printdiv.getFirst());
			setTimeout('window.print()', 10);
			break;	

		case 'return':
			$each(document.body.getChildren(), function(el){el.removeClass('hidden');});
			printdiv.remove();
			break;
	}
}

function openNewWindow(url, w, h)
{
	w = (w==null) ? 600 : w;
	h = (h==null) ? 450 : h;
	var target = url.test(/^index\.php.*/i) ? 'popup' : '_blank';
	var aWindow = makePopup(url, target, w, h, 'yes', 'yes');
}

function makePopup(pageURL, pageName, w, h, pageScroll, pageCenter)
{
	if(pageCenter == 'no')	{
		LeftPosition = 10;
		TopPosition = 10;
	} else {
		LeftPosition = (screen.width) ? (screen.width-w) / 2 : 0;
		TopPosition = (screen.height) ? (screen.height-h) / 2 : 0;
	}

	var pageConfig = 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=' + pageScroll + ', resizable=yes, width=' + (w + 18) + ', height=' + (h + 18) + ', left=' + LeftPosition + ', top=' + TopPosition;
	var popup = window.open(pageURL.replace(/&popup=[^&]*/,'')+'&popup=1', pageName, pageConfig);
	popup.focus();
	return popup;
}

function findID(obj)
{	
	if(obj = $(obj)) {
		while(obj = obj.getParent()) {
			if(obj.id) {
				var id =  parseInt(obj.id.replace(/^list_row_(\d)+$/ig, '$1'));
				if(id){				
					return id;
				}
			}
		}
	}
	return false;
}

function hideLoading()
{
	$('loading').addClass('hidden');	
}

function doDelete(obj, id)
{
	var id = id ? id : findID(obj);
	new ajax('index.php?section='+section+'&module='+module+'&cmd=delete&id='+id, { onComplete:loadList }).request();
	
}

function doEdit(obj, id)
{
	if( typeof(a_window) != 'undefined') a_close(a_window, 'edit_box');
	var cmd = id ? 'edit' : 'new';
	var id = id ? id : findID(obj);
	$('edit_box').style.top =  window.getSize().scroll.y+4+'px';
	$('edit_box').style.left = Math.max((window.getSize().size.x-$('edit_box').getSize().size.x)/2, 8)+'px';
	$('loading').removeClass('hidden');
	var url = document.location.href.replace(/&cmd=[^&]*/, '').replace(/#.*/, '')+'&cmd='+cmd+'&id='+id;
	
	//new ajax('index.php?section='+section+'&module='+module+'&cmd='+cmd+'&id='+id, { update:'edit_box', loading:null, onComplete:hideLoading }).request();
	new ajax(url, { update:'edit_box', loading:null, onComplete:hideLoading }).request();
}
function doSetcooki(obj, league)
{
	var league = league ? league: findLeague(obj);
	Cookie.set("league", Base64.encode(league));
	document.location.reload();

}
function doSubmit(frm, iframe)
{
	if($('a_submit').value == 'Saving...') return false;
	
	var oDoc = $('myframe').contentWindow || $('myframe').contentDocument;
	if (oDoc.document) {
		oDoc = oDoc.document;
	}
	oDoc.body.innerHTML = '';
	doSubmit.submitOK = function(res){
		var script, regexp = /<script[^>]*>([\s\S]*?)<\/script>/gi;
		while ((script = regexp.exec(res))) eval(script[1]);
		if(res.indexOf('[[error]]')>-1) {
			alert('Error in saving.');
			$('a_submit').value = $('a_submit').pre_value;
		} else if(res.indexOf('[[fault]]')>-1) {// error with php message
			$('a_submit').value = $('a_submit').pre_value;	
		} else {	
			a_close('edit_box');	
			loadList();	
		}
	};
	
	doSubmit.check = function(){
		var oDoc = $('myframe').contentWindow || $('myframe').contentDocument;
		if (oDoc.document) {
			oDoc = oDoc.document;
		}
		var txt = oDoc.body ? oDoc.body.innerHTML : '';
		if(txt!='' && txt!='false') {
			doSubmit.submitOK(txt);	
			//doSubmit.myframe.remove();
		} else {
			doSubmit.check.delay(500);
		}
	};
	
	if(iframe) {
		doSubmit.check.delay(500);
	} else {
		var a = new ajax(null, { evalScripts:true, onComplete:this.submitOK, method:'post' });
		a.setHeader('Content-type', 'multipart/form-data; charset=utf8');
		a.send('index.php', $('adminform').toQueryString());
	}
	$('a_submit').pre_value = $('a_submit').value;
	$('a_submit').value = 'Saving...';
	return iframe;
}

function doDeleteImage(dir, id)
{
	doDeleteImage.removeImage = function()
	{
		$('imageBox') && $('imageBox').remove();
	}
	new ajax('index.php?section='+section+'&module='+module+'&cmd=deleteimage&id='+id, {onComplete:doDeleteImage.removeImage, update:'imageBox'}).request();
}

function a_close(obj, newid)
{
	$(obj).setHTML('');
	if(newid) $(obj).id = newid;
}

function a_minimize(sender, obj)
{
	$(obj).t_height = $(obj).getSize().size.y;
	
	var style = {
					height: '23px',
					overflow: 'hidden' 
				};				
	$(obj).setStyles(style);
	$(sender).addClass('hidden');
	$(sender).getNext().removeClass('hidden');
}

function a_restore(sender, obj)
{
	var style = {
					height: $(obj).t_height,
					overflow: 'visible' 
				};
	$(obj).setStyles(style);
	sender.addClass('hidden');
	sender.getPrevious().removeClass('hidden');
}

function setGroupName(selobj, inpobj, imgobj, group)
{
	if($(selobj)) {
		$(inpobj).value=$(selobj).options[$(selobj).selectedIndex].text;	
		$(imgobj).src = 'showpic.php??mw=64&mh=64&dir='+group+'&pic='+$(selobj).value;
	}
}

function doNewGroup(rowobj, cmdobj, txtobj)
{
	$(cmdobj).value = 'insert';
	$(rowobj).remove();
	$(txtobj).value='';
}

function doDeleteGroup(cmdobj)
{
	if(confirm('Do you want to delete this group?')) {
		$(cmdobj).value = 'delete';
		$(cmdobj).form.submit();
	}
}

function addRecord(sender, obj)
{
	obj = $(obj);
	var clone = obj.clone();
	clone.injectBefore($(sender));
	clone.id = 'temp_cloned';
	$$('#temp_cloned INPUT, #temp_cloned SELECT, #temp_cloned TEXTAREA').each(function(el){
		el.name = el.name.replace(/^~/, '');
	});
	clone.id = null;
	clone.removeClass('hidden');
}

function resetRows(id)
{
	$$('tr.ron').each(function(el){el.removeClass('ron');});
	if(typeof(id) != "undefined")
		listLatEdited = id;
}

function printForm()
{
	var nw = window.open('', 'PrintWindow', 'width=720px,height=500px,scrollbars=yes');
	nw.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'+
	'<html>'+
	'<head>'+
	'<link type="text/css" rel="stylesheet" href="../+style/ms-admin-print.css" />'+
	'<link type="text/css" rel="stylesheet" media="print" href="../+style/print.css" />'+
	'<title></title>'+
	'<script language="javascript" type="text/javascript" src="../+script/class.js"></script>'+
	'<script language="javascript" type="text/javascript">'+
	'function printWindow(){'+
		'document.body.innerHTML = window.opener.document.getElementById("edit_main").innerHTML;'+
		'window.opener.hideProductDetail();'+
		'setTimeout("window.print();", 200);'+
	'}'+
	'</script>'+
	'<style type="text/css">'+
		'.button, .noprint{'+
			'display:none;'+
		'}'+
	'</style>'+
	'</head>'+
	'<body dir="rtl" onload="window.printWindow();"></body></html>');
	nw.document.close();
}

function getContent(url, query, cmd, cmdOnError, method, retry)				
{
	if(typeof(cmdOnError)=='undefined')
		cmdOnError = ';';
	if(typeof(method)=='undefined')
		method = 'GET';
	else
		method = method.toUpperCase();
	retry  = (retry || 0);
	if(retry > 5){
		try{
			eval(cmdOnError);
		} catch(e){}
		return;
	}
	var A = createAjax();
	if(method == "GET")
		A.open(method, url+'?'+query+'&_r_=done'+Math.random(), true);
	else
		A.open(method, url, true);

	var onreadystatechange = function(){
			if(A.readyState==4)
				if(A.status==200 || A.status == 304){
					Contents = A.responseText;
					var ScriptCode, regexp = /<script[^>]*>([\s\S]*?)<\/script>/gi;
					while (ScriptCode = regexp.exec(Contents))
						try{
							eval(ScriptCode[1]);
						}catch(e){}
					// do the finish CMD
					try{
						eval(cmd);
					} catch(e){}
				}else {
					getContent(url, query, cmd, cmdOnError, method, (retry+1));
					}
			};
	A.onreadystatechange = onreadystatechange;
	if(method == "GET")
		A.send(null);
	else{
		var contentType = "application/x-www-form-urlencoded; charset=UTF-8";
		A.setRequestHeader("Content-Type", contentType);
		A.send(query+'&_r_=done'+Math.random());
	}
}
function xMakeVisible(obj, d)												
{
	if(typeof(d) == "undefined")
		d = false;
	if(typeof(obj) != "object")
		obj = $(obj);
	if(!d)
		obj.style.display	= '';
	obj.style.visibility = "visible";
}
function xMakeHidden(obj, d)												
{
	if(typeof(d) == "undefined")
		d = false;
	if(typeof(obj) != "object")
		obj = $(obj);
	if(!d)
		obj.style.display	= 'none';
	obj.style.visibility = "hidden";
}												
function createAjax() 														
{
	try { return new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e) {}
	try { return new ActiveXObject("Microsoft.XMLHTTP"); }
		catch (e) {}
	try { return new XMLHttpRequest(); }
		catch(e) {}
	return null;
}
/*
var $ =	function (eName)													
	{
		return document.getElementById(eName);	
	};
*/	
function xFindPosX(obj)														
{
	var curleft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
			}
		}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}
function xFindPosY(obj)														
{
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
			}
		}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
function xRemovePX(strNum)													
{
	return strNum.substr(0, strNum.length - 2) * 1;
}
//-------------------------------//Image Loader//----------------------------------
var xImages = new Array();
var _xImages = new Array();
function _xloadImages() 													
{
	var i,key;
	for (i=0; i<_xloadImages.arguments.length; i++) {
		if (typeof(_xloadImages.arguments[i]) == 'string') {
			_xImages.push(document.createElement('img'));
			_xImages[_xImages.length-1].src = _xloadImages.arguments[i];
			}
		else if (typeof(_xloadImages.arguments[i]) == 'object')
			for(key in _xloadImages.arguments[i])
				if(typeof(_xloadImages.arguments[i][key]) != 'function') {
					_xImages.push(document.createElement('img'));
					_xImages[_xImages.length-1].src = _xloadImages.arguments[i][key];
					}
		}
}
function xloadImages()														
{
	var i,key;
	if (xloadImages.arguments.length == 0) {
		_xloadImages(xImages);
		return true;
		}
//	if (pageLoaded) {
//		for (i=0; i<xloadImages.arguments.length; i++)
//			_xloadImages(xloadImages.arguments[i]);
//		return true;
//		}
	for (i=0; i<xloadImages.arguments.length; i++){
		if (typeof(xloadImages.arguments[i]) == 'string') {
			xImages.push(xloadImages.arguments[i]);
			}
		else if (typeof(xloadImages.arguments[i]) == 'object') 
			for(key in xloadImages.arguments[i])
				if(typeof(xloadImages.arguments[i][key]) != 'function') {
					xImages.push(xloadImages.arguments[i][key]);
					}
		}
}
function xBtnCreate(obj, cmd, cmd2, type)									
{
	if(typeof(cmd2) == "undefined")
		cmd2 = "";
	if(typeof(type) == "undefined")
		type = "normal";
	if(type == "check"){
		oName = (obj.name)?obj.name:obj.id;
		if(oName.length < 1)
			oName = "rcoId"+Math.round(Math.random()*9999);
		var Obj = document.createElement('input');
		Obj.type = 'hidden';
		Obj.name = oName+"IN";
		Obj.id = oName+"IN";
		Obj.value = 0;
		obj.parentNode.appendChild(Obj);
		if(!obj.id)
			obj.id = oName;
	}
	var img = new Array();
	var tmp = obj.src.split('/images/');
	img['path'] = tmp[0]+"/images/";
	tmp = tmp[1].split('.');
	img['img'] = tmp[0];
	img['ext']  = tmp[1];
	if(typeof(img['img']) == 'undefined' || img['img'] == 'undefined' )
		return;
	_xloadImages (img['path']+img['img']+"."+	img['ext'],
				 img['path']+img['img']+"-over"+"."+img['ext'],
				 img['path']+img['img']+"-down"+"."+img['ext']
				);
	obj.style.cursor = "pointer";
	doWhileUp		= function(OBJid, CMD, targetV1, targetV2){
						try{
							OBJ = $(OBJid);
							if(OBJ.src != targetV1 && OBJ.src != targetV2){
								eval(CMD);
								setTimeout("doWhileUp('"+OBJid+"', '"+CMD+"', '"+targetV1+"', '"+targetV2+"')", 50);
								}
							}
						catch(e){}
						};
	obj.onmouseover	= function(){
							if(obj.src == img['path']+img['img']+"-down."+img['ext'])
								obj.src=img['path']+img['img']+"-down-over."+img['ext'];
							else
								obj.src=img['path']+img['img']+"-over."+img['ext'];
						};
	obj.onmouseout	= function(){
							if(obj.src == img['path']+img['img']+"-down-over."+img['ext'])
								obj.src=img['path']+img['img']+"-down."+img['ext'];
							else
								obj.src=img['path']+img['img']+"."+img['ext'];
						};
	obj.onmouseup 	= function(){
							if(type == "check"){
								if ($(obj.id+"IN").value == '0')
									obj.src=img['path']+img['img']+"-down-over."+img['ext'];
								else
									obj.src=img['path']+img['img']+"-over."+img['ext'];
								$(obj.id+"IN").value = ($(obj.id+"IN").value == '1')?0:1;
							}else							
								obj.src=img['path']+img['img']+"-over."+img['ext'];
						};
	obj.onmousedown = function(){
							obj.src=img['path']+img['img']+"-down."+img['ext'];
							if(typeof(cmd2) != "undefined" && cmd2.length > 0)
								doWhileUp(obj.id, cmd2, img['path']+img['img']+"-over."+img['ext'], img['path']+img['img']+"."+img['ext']);
						};
	obj.onclick		= function(){
							try{
								eval(cmd);
							} catch(e){}
						};
						
	obj.onload		= function(){
						};
	obj.ondblclick	= function(){
							obj.src=img['path']+img['img']+"."+img['ext'];
						};
}

var popupStatus = 'none';
var popupLastPage = '';

function popupWin(cmd, txt, page)						
{
	var popupWidth={
					"news-detail":600
					};
	if(typeof(page) == "undefined")
		page = 'en';
	if(typeof(txt) == "undefined")
		txt = 0;
	switch(cmd){
		case "create":		
			var Obj = document.createElement('div');
			Obj.id = "popupWinHolder";
			Obj.style.position = "absolute";
			document.getElementsByTagName('body')[0].appendChild(Obj);
			$("popupWinHolder").innerHTML =	'<table border="0" cellpadding="0" cellspacing="0" style="width:100%;">'+
													'<tr>'+
														'<td style="background:url(/images/them/Gray90_cornner.gif) no-repeat top left; width:15px; height:15px"></td>'+
														'<td style="background:url(/images/them/bgGray90.gif) repeat ;height:15px"></td>'+
														'<td style="background:url(/images/them/Gray90_cornner.gif) no-repeat top right; width:15px; height:15px"></td>'+
													'</tr>'+
													'<tr style="background:url(/images/them/bgGray90.gif) repeat ;">'+
														'<td style="width:15px"></td>'+
														'<td>'+
															'<div class="liveReportWin">'+
																'<div style="width:100%;height:23px;background:url(/images/them/liveRepWinHeaderBig.gif) repeat-x top;border:1px solid #969696;border-bottom:0;">'+
																	'<img src="/images/them/xwinBtnClose.gif" width="19" height="19" alt="" title="" style="margin:2px 4px 2px 2px; float:right" onLoad="xBtnCreate(this, \'popupWin(\\\'hide\\\')\')" />'+
																	'<img src="/images/them/xwinBtnMin.gif" id="popupBtnMinimize" width="19" height="19" alt="" title="" style="margin:2px; float:right" onLoad="xBtnCreate(this, \'popupWin(\\\'minimize\\\')\')" />'+
																	'<img src="/images/them/xwinBtnMax.gif" id="popupBtnMaximize" width="19" height="19" alt="" title="" style="margin:2px; float:right; display:none;" onLoad="xBtnCreate(this, \'popupWin(\\\'maximize\\\')\')" />'+
																'</div>'+
																'<div style="width:100%; background:#FFFFFF;border:1px solid #969696; border-bottom:0;">'+
																	'<table id="popupwinMainTable" border="0" cellpadding="0" cellspacing="5" style="width:100%;; background:#F4F3F3">'+
																		'<tr>'+
																			'<td id="popupWinContainer">'+
																			'</td>'+
																		'</tr>'+
																	'</table>'+
																'</div>'+
																'<div style="width:100%;height:20px;background:#FFFFFF url(/images/them/liveRepWinStratus.gif) no-repeat bottom left;text-align:right;border:1px solid #969696;color:#666666;" id="popupWinStatus"></div>'+
															'</div>'+
														'</td>'+
														'<td style="width:15px"><div style="display:none"><input type="hidden" id="popupwinPage" /><input type="hidden" id="popupwinText" /><input type="hidden" id="popupwinDirectUrl" /></div></td>'+
													'</tr>'+
													'<tr>'+
														'<td style="background:url(/images/them/Gray90_cornner.gif) no-repeat bottom left; width:15px; height:15px"></td>'+
														'<td style="background:url(/images/them/bgGray90.gif) repeat ;height:15px"></td>'+
														'<td style="background:url(/images/them/Gray90_cornner.gif) no-repeat bottom right; width:15px; height:15px"></td>'+
													'</tr>'+
												'</table>';	
			popupStatus = 'created';
			break;
		case "show":		
			i = 0;
			if(popupStatus == 'none')
				popupWin('create', txt, page);
			popupWin('maximize');
			$("popupWinHolder").style.width = 650 +"px";
//			if(eval("popupLastPage != '"+page+"#"+txt+"';"))
//			{
			popupWin('loading', txt, page);
			if(txt.length < 4)
				txt =  "news-detail&id=" + txt;
			popupWin('fetch', txt, page);
//			}
			popupLastPage = page+"#"+txt;
			var sw = document.getElementsByTagName("body")[0].clientWidth || screen.width;
			var sl = Math.round((sw - 650 )/2);
			st = 250+document.documentElement.scrollTop*1;
			$("popupWinHolder").style.top = st + 'px';
			$("popupWinHolder").style.left = sl + 'px';
			xMakeVisible("popupWinHolder");
			popupStatus = 'visible';
			break;
		case "hide":		
			if(popupStatus == 'none')
				break;
			xMakeHidden("popupWinHolder");
			popupStatus = 'hidden';
			break;
		case "minimize":	
			xMakeHidden('popupwinMainTable');
			xMakeHidden('popupBtnMinimize');
			xMakeVisible('popupBtnMaximize');
			break;
		case "maximize":	
			xMakeVisible('popupwinMainTable');
			xMakeVisible('popupBtnMinimize');
			xMakeHidden('popupBtnMaximize');
			break;
		case "fetch":		
			popupWin("status", "درحال بارگزاری...", page);
			getContent(
						txt,
							'',//'section=guest&module='+txt+'&lang='+page,
								'$("popupWinContainer").innerHTML = Contents;'+
								'popupWin("status", "انجام شد", "'+page+'");',
									'popupWin("status", "بارگزاری مجدد...", "'+page+'");'+
									'popupWin("error", "'+txt+'", "'+page+'")',
										'GET'
					);
			break;
		case "loading":		
			$("popupWinContainer").innerHTML =	'<div style="margin:0;background:#FFFFFF;width:300px; margin:0 auto;">'+
													'<table border="0" cellpadding="0" cellspacing="5" width="100" style="margin:0 auto; direction:ltr	">'+
													  '<tr><td><br><br><br><br><br><br></td></tr>'+
													  '<tr>'+
														'<td width="80%" style="text-align:right">لطفاً صبر کنيد</td>'+
														'<td width="20%" style="text-align:left"><img src="/images/them/loading.gif" width="16" height="16" alt="" /></td>'+
													  '</tr>'+
													  '<tr><td><br><br><br><br><br><br></td></tr>'+
													'</table>'+
												'</div>';
			break;
		case "reload":		
			if($('popupwinPage')){
				popupWin('loading');
				popupWin('fetch', $('popupwinText').value, $('popupwinPage').value);
			}
			break;
		case "error":		
			popupWin("status", "اشکال در دريافت اطلاعات!", page);
			$("popupWinContainer").innerHTML =	'<div class="whiteBoxHolder" style="margin:0;  width:300px;text-align:left">'+
													'<div class="BoxHeader"><div></div></div>'+
													'<div class="BoxContent" style="margin:0; padding:100px 0;">'+
													'<table border="0" cellpadding="0" cellspacing="0" width="100px" style="margin:0 auto">'+
													  '<tr>'+
														'<td>دريافت اطلاعات با مشکل مواجه شد. لطفاً بعد از بررسی ارتباط خود با اينترنت دوباره سعی کنيد</td>'+
														'<td><img src="/images/them/iconTimeout.gif" width="24" height="24" alt="" /></td>'+
													  '</tr>'+
													'</table>'+
													'</div>'+
													'<div class="BoxFooter""><div></div></div>'+
												'</div>';
			break;
		case "status":
			$("popupWinStatus").innerHTML = "<div style='direction:rtl'>&nbsp;&nbsp;&nbsp;" + txt + "&nbsp;&nbsp;&nbsp;</div>";
			break;
	}
}


function setRows()
{
	resetRows();
	if(listLatEdited){
		try{
			$(listLatEdited).addClass('ron');
		}catch(e){}
	}	
}
setRows();


function formatInt(num)
{
	if(typeof(num) == "undefined" || String(num).trim() == '')
		return '';
	var sep = ',';
	var cnt = 3;
	num = String(num).replace(/٫/, '.');
	num = String(num).replace(/[^0-9۰۱۲۳۴۵۶۷۸۹.٫]+/g, '');
	var part = num.split('.', 2);
	num = part[0];
	if(!num) num = '0';
	var res = '';
	var mod = num.length % cnt;
	for(var i=0; i<num.length; i++) {
		res += num.charAt(i);
		if((i+1)%cnt==mod && i+1!=num.length)
			res += sep;
	}
	res = res+(enInt(0+part[1])!=0 ? '.'+part[1] : '');
	return res;
}

function E_(num)
{
	num = String(num);
	num = (num).replace(/٫/g, '.');
	num = (num).replace(/۰/g, '0');
	num = (num).replace(/۱/g, '1');
	num = (num).replace(/۲/g, '2');
	num = (num).replace(/۳/g, '3');
	num = (num).replace(/۴/g, '4');
	num = (num).replace(/۵/g, '5');
	num = (num).replace(/۶/g, '6');
	num = (num).replace(/۷/g, '7');
	num = (num).replace(/۸/g, '8');
	num = (num).replace(/۹/g, '9');
	
	num = (num).replace(/٤/g, '4');
	num = (num).replace(/٥/g, '5');
	num = (num).replace(/٦/g, '6');
	return num;
}

function enInt(num)
{
	if(!num) num = '0';
	num = E_(num);	
	num = num.replace(/[,]+/g, '');
	if(!num) num = '0';
	return num;
}

function F_(num)
{
	num = String(num);
	num = (num).replace(/0/g, '۰');
	num = (num).replace(/1/g, '۱');
	num = (num).replace(/2/g, '۲');
	num = (num).replace(/3/g, '۳');
	num = (num).replace(/4/g, '۴');
	num = (num).replace(/5/g, '۵');
	num = (num).replace(/6/g, '۶');
	num = (num).replace(/7/g, '۷');
	num = (num).replace(/8/g, '۸');
	num = (num).replace(/9/g, '۹');
	return num;
}

function faInt(num)
{
	return F_(num);
}

function localAct(action, obj, id, intparam, extraId)
{
	switch(action) {
		case 'detail' :
			if( typeof(a_window) != 'undefined') a_close(a_window, 'edit_box');			
			var id = id ? id : findID(obj);
			$('edit_box').style.top =  window.getSize().scroll.y+4+'px';
			$('edit_box').style.left = Math.max((window.getSize().size.x-$('edit_box').getSize().size.x)/2, 8)+'px';
			$('loading').removeClass('hidden');
			if(!intparam)
				new ajax('index.php?section='+section+'&module='+module+'&cmd=detail&id='+id, { update:'edit_box', loading:null, onComplete:hideLoading }).request();
			else if(intparam == 1)
				new ajax('index.php?section='+section+'&module='+module+'&cmd=sameproductlist&id='+id+'&'+extraId, { update:'edit_box', loading:null, onComplete:hideLoading }).request();
			else if(intparam == 2)
				new ajax('index.php?section='+section+'&module='+module+'&cmd=productreview&id='+id, { update:'edit_box', loading:null, onComplete:hideLoading }).request();
			else if(intparam == 3)
				new ajax('index.php?section='+section+'&module='+module+'&cmd=samearticlelist&id='+id, { update:'edit_box', loading:null, onComplete:hideLoading }).request();
			break;
		case 'msg' :
		case 'replay' :
		case 'forward' :
			if( typeof(a_window) != 'undefined') a_close(a_window, 'edit_box');			
			var id = id ? id : findID(obj);
			$('edit_box').style.top =  window.getSize().scroll.y+4+'px';
			$('edit_box').style.left = Math.max((window.getSize().size.x-$('edit_box').getSize().size.x)/2, 8)+'px';
			$('loading').removeClass('hidden');
			new ajax('index.php?section='+section+'&module='+module+'&cmd=edit&btn='+action+'&id='+id, { update:'edit_box', loading:null, onComplete:hideLoading }).request();
			break;
	}
}

function duplicateRow(classname)
{
    //clone the row
	var obj = $$('.'+classname);
	if(!obj) alert('error');
	obj = $(obj[obj.length-1]);
	var baby = obj.clone();
    
    //reset values
    
	//set name and ids
    cnt = 1;
	$$('.'+classname).each(function(el){
		el.lang = cnt;
        el.getElementsBySelector('SELECT, INPUT, TEXTAREA').each(function(elp){
            elp.name = elp.name.replace(/\[row\d+\]/, '[row'+cnt+']');
            elp.id = elp.name;
        }); 
        el.id = 'reg_'+cnt;
		cnt++;
    });
	
	baby.id = 'reg_'+cnt;
	
	baby.getElementsBySelector('SELECT, INPUT, TEXTAREA').each(function(el){
		el.name = el.name.replace(/\[row\d+\]/, '[row'+cnt+']');
		el.id = el.name;
		switch(el.tagName){
			case 'SELECT':
				el.selectedIndex = 0;
				break;
			case 'TEXTAREA':
				el.value = null;
				break;
			case 'INPUT':
				if(el.type=='text') el.value = '';
				if(el.type=='file') el.value = '';
				if(el.type=='checkbox') el.checked = false;
				if(el.type=='radio') el.checked = false;
				if(el.type=='hidden' && el.hasClass('reset')) el.value = '';
				if(el.type=='radio' && el.getParent()) {
					el.getParent().innerHTML = el.getParent().innerHTML.replace(/\[row\d+\]/g, '[row'+cnt+']');
				}
				break;
		}
	}); 
	
	if(baby.getElementsBySelector('.rem')) {
		baby.getElementsBySelector('.rem').each(function(el){
			el.href = "javascript:void(0);";											 
		});
	}
	
	if(baby.getElementsBySelector('.imagebox')) {
		baby.getElementsBySelector('.imagebox').each(function(el){
			el.src = '../images/blank.gif';											 
		});
	}
	
	baby.removeClass('hidden');
	
    baby.injectAfter(obj);
	
	normalizeRows(classname);   
}

function removeRow(obj,className)
{
	var parent = findParent(obj,className);
	parent.remove();
	
	normalizeRows(className);
}

function normalizeRows(classname)
{
	var cnt = 0;
	
	var rows = $$('.'+classname);
	var rowscount = rows.length;
	
	rows.each(function(el){
		cnt++;
		el.getElementsBySelector('.addBut, .remBut, .rem, .counterNum').each(function(elp){
			if(elp.hasClass('addBut')){
				if(cnt<rowscount)
					elp.addClass('invisible');
				else
					elp.removeClass('invisible');
			}else if(elp.hasClass('remBut') || elp.hasClass('rem')){
				if(rowscount<=1)
					elp.addClass('invisible');
				else
					elp.removeClass('invisible');
			}else if(elp.hasClass('counterNum')){
				if(lang='fa')
					elp.innerHTML = F_(cnt);
				else
					elp.innerHTML = cnt;
			}
		});
	});
}

function findParent(obj,className)
{
	if($(obj))
		obj=$(obj);
	else
		return false;
	
	while(!obj.getParent().hasClass(className)){
		obj = obj.getParent();
	}
	
	return obj.getParent();
}

function delFile(id)
{
	var conf = confirm('آیا از حذف این فایل اطمینان دارید؟');
	if(!conf) return;
	new ajax('index.php?section='+section+'&module='+module+'&cmd=delfile&id='+id).request();
}

function setSubGroup(obj, data, first)
{	
	obj = $(obj);
	first = first ? first : 0;
	try {
		var src = $$('.group1')[0];
		var des = $$('.group2')[0];
	} catch(e){};
	if(!src || !des || !data) return;
	while(des.options[first]){
		des.options[first] = null;
	};
	data = data[src.value];
	for(el in data){
		des.options[des.options.length] = new Option(data[el], el);					
	};
}
/*function setSubGroup(obj, data)
{	
	obj = $(obj);
	try {
		var src = $$('.group1')[0];
		var des = $$('.group2')[0];
	} catch(e){};
	if(!src || !des || !data) return;
	while(des.options[0]){
		des.options[0] = null;
	};
	data = data[src.value];
	for(el in data){
		des.options[des.options.length] = new Option(data[el], el);					
	};
}*/
function setSubProduct(obj, data)
{	
	obj = $(obj);
	try {
		var src = $$('.group1')[0];
		var des = $$('.group3')[0];
	} catch(e){};
	if(!src || !des || !data) return;
	while(des.options[0]){
		des.options[0] = null;
	};
	data = data[src.value];
	for(el in data){
		/*console.log('%s : %s', typeof(data[el]), data[el]);*/
		if(typeof(data[el])!='string')
			continue;
		des.options[des.options.length] = new Option(data[el], el);					
	};
}

function companyImage(clname)
{
	try {
	$$('TR.'+clname).each(function(el){
		var id = el.getElementsBySelector('.compId')[0].value;
		el.getElementsBySelector('.compImage').each(function(el){
			el.src = el.src.replace(/pic=\d+/,'pic='+id);
		});
	});
	}catch(e){};
}

function openDetail(id)
{
	var name = "pdetail_"+id;
	$$('.productDetail').each(function(el){
		if(el == $(name)) {
			el.myfx.toggle();
		}else {
			el.myfx.slideOut();
		}
	});
}

function hideProductDetail()
{
	$$('.productDetail').each(function(el){
		if(!el.myfx)								
			el.myfx = new Fx.Slide(el);
		el.myfx.hide();
	});
}

// For Print Form
function showProductDetail()
{
	$$('.productDetail').each(function(el){
		if(!el.myfx)								
			el.myfx = new Fx.Slide(el);
		el.myfx.show();
	});
}

function changeDisplayImage(imagecontainer, imagehref, imageid)
{
	$(imagecontainer).src = $(imagecontainer).src.replace(/pic=\d*/, 'pic='+imageid);
	$(imagehref).href = $(imagehref).href.replace(/pic=\d*/, 'pic='+imageid);
}

function internalgoto(idx, force)
{	
	var cur = parseInt($('offset1').value);
	var last = $('offset1').options[$('offset1').options.length-1].value;
	switch(idx) {
			case 'first': 
				idx = 1;
				break;
			case 'previous': 
				idx = cur==1 ? 1 : cur-1;
				break;
			case 'last': 
				idx = last;
				break;
			case 'next': 
				idx = cur==last ? cur :  cur+1;
				break;
			default:
				idx = Math.min(Math.max(idx, 1), last);
	}
	if(cur!=idx || force) {
		if($('offset1')) $('offset1').value = idx;
		internalloadList();	
	}
}

function internalloadList()
{	
	var query = $('searchform').toQueryString();
	var path = document.location.href.replace(/^.*\/([^\/]+)$/, '$1');	
	path = encodeURI(decodeURI(path));
	var url = document.location.href.replace(/^(.*\/)[^\/]+$/, '$1')+path+'?'+query+'&page='+parseInt($('offset1').value);
	new ajax(url, {update:'listdiv'}).request();
}

function listgoto(idx, force)
{
	var cur = parseInt($('offset').value);
	var last = $('offset').options[$('offset').options.length-1].value;
	switch(idx) {
			case 'first': 
				idx = 1;
				break;
			case 'previous': 
				idx = cur==1 ? 1 : cur-1;
				break;
			case 'last': 
				idx = last;
				break;
			case 'next': 
				idx = cur==last ? cur :  cur+1;
				break;
			default:
				idx = Math.min(Math.max(idx, 1), last);
	}
	if(cur!=idx || force) {
		if($('offset')) $('offset').value = idx;
		listloadList();	
	}
}

function listloadList()
{
	var query = $('listpagingform').toQueryString();
	var path = document.location.href.replace(/^.*\/([^\/]+)$/, '$1');	
	path = encodeURI(decodeURI(path));
	var url = document.location.href.replace(/^(.*\/)[^\/]+$/, '$1')+path+'?'+query+'&page='+parseInt($('offset').value);
	new ajax(url, {update:'listpagingdiv'}).request();
}

function changeCap(obj)									
{
	var RAND = Math.floor(Math.random()*99999999);
	obj.src = '../images/blank.gif';
	obj.style.background = 'url(captcha'+RAND+'.gif)';
	obj.src = 'captcha'+RAND+'.gif';
}

function setLoading(obj,size)
{
	if(!$(obj))
		return;
	if(typeof(size)=='undefined')
		size = 'large';
	switch(size){
		case 'large':
			loadhtml= '<table border="0" cellpadding="0" cellspacing="0" width="100px" style="margin:0 auto">'+
						  '<tr><td><br /><br /></td></tr>'+
						  '<tr>'+
							'<td>لطفاً صبر کنيد</td>'+
							'<td><img src="../images/them/loading.gif" width="16" height="16" alt="" /></td>'+
						  '</tr>'+
						  '<tr><td><br /><br /></td></tr>'+
						'</table>';
			break;
			
		case 'oneline':
			loadhtml = '<img src="../images/them/loading.gif" />&nbsp;لطفا صبر کنید';
			break;
	};
	
	$(obj).innerHTML = loadhtml;
}

function reparationRequest()
{
	popupWin('show', '/global/index.php?section=patronage&module=reparation&cmd=new&', 'fa');
}

function reparationRequestSend()
{
	var values = $('reparationrequestform').toQueryString();
	var url = '/global/index.php';
	var el = null;
	
	var fields = $$('.reparationList INPUT, .reparationList SELECT');
	for(i in fields){
		el = fields[i];
		if(typeof(el)!='object')
			continue;
		if(!el.value){
			alert('لطفا تمامی فیلدها را پر نمائید.');
			el.focus();
			return false;
		}
	}
	
	setLoading('reparationLoad');
	var req = new ajax(url, {update: 'reparationLoad', loading: null, method: 'post'});
	req.send(url, values);
	
}

function reparationRequestDetail(id)
{
	popupWin('show', '/global/index.php?section=patronage&module=reparation&cmd=detail&id='+id+'&', 'fa');
}

function patronageRequest(id)
{
	popupWin('show', '/global/index.php?section=patronage&module=patronage&cmd=new&', 'fa');
}

function patronageRequestSend()
{
	var values = $('patronagerequestform').toQueryString();
	var url = '/global/index.php';
	var el = null;
	
	var fields = $$('.patronageList INPUT, .patronageList SELECT');
	for(i in fields){
		el = fields[i];
		if(typeof(el)!='object')
			continue;
		if(!el.value){
			alert('لطفا تمامی فیلدها را پر نمائید.');
			el.focus();
			return false;
		}
	}
	
	setLoading('patronageLoad');
	var req = new ajax(url, {update: 'patronageLoad', loading: null, method: 'post'});
	req.send(url, values);
}

function productConfirmCheck()
{
	var form = $('listform').toQueryString();
	new ajax('/global/index.php?section='+section+'&module='+module+'&cmd=productcheckconfirm&'+form, {evalScripts:true}).request();	
}

function opacity(Oid, opacStart, opacEnd, millisec, cmd)					
{
	var speed = Math.round(millisec / 100);
	var timer = 0;

	if(typeof(cmd) == "undefined")
		cmd = ";";
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--){
			setTimeout("changeOpac(" + i + ",'" + Oid + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd){
		for(i = opacStart; i <= opacEnd; i++){
			setTimeout("changeOpac(" + i + ",'" + Oid + "')",(timer * speed));
			timer++;
		}
	}
	setTimeout("try{"+cmd+"}catch(e){};",(timer * speed));
}

function changeOpac(opacity, Oid)											
{
	try{
		var object = $(Oid);
	}catch(e){}
	if(typeof(object) != "object")
		return;
	object = object.style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

// Node object
function Node(id, pid, name, url, title, target, icon, iconOpen, open) {this.id = id;this.pid = pid;this.name = name;this.url = url;this.title = title;this.target = target;	this.icon = icon;this.iconOpen = iconOpen;this._io = open || false;this._is = false;this._ls = false;this._hc = false;this._ai = 0;this._p;};
// Tree object
function dTree(objName) {	this.config = {	target: null,folderLinks: true,	useSelection: true,	useCookies	: true,	useLines: true,	useIcons: true,	useStatusText: false,closeSameLevel: false,	inOrder: false};	this.icon = {root	: '/images/dtree/root.gif',	folder: '/images/dtree/folder.png',	folderOpen: '/images/dtree/folderopen.gif',	node: '/images/dtree/user_3.gif',empty: '/images/dtree/empty.gif',line: '/images/dtree/line.gif',join: '/images/dtree/join.gif',joinBottom: '/images/dtree/joinbottom.gif',	plus: '/images/dtree/plus.gif',	plusBottom: '/images/dtree/plusbottom.gif',	minus: '/images/dtree/minus.gif',minusBottom		: '/images/dtree/minusbottom.gif',	nlPlus: '/images/dtree/nolines_plus.gif',nlMinus: '/images/dtree/nolines_minus.gif'	};	this.obj = objName;	this.aNodes = [];this.aIndent = [];this.root = new Node(0);this.selectedNode = null;	this.selectedFound = false;	this.completed = false;};
// Adds a new node to the node array
dTree.prototype.add = function(id, pid, name, icon, url, title, target, iconOpen, open) {this.aNodes[this.aNodes.length] = new Node(id, pid, name, url, title, target, icon, icon/*Open*/, open);};
// Open/close all nodes
dTree.prototype.openAll = function() {	this.oAll(true);};dTree.prototype.closeAll = function() {this.oAll(false);};
// Outputs the tree to the page
dTree.prototype.toString = function() {	var str = '<div class="dtree">\n';	if (document.getElementById) {if (this.config.useCookies) this.selectedNode = this.getSelected();	str += this.addNode(this.root);	} else str += 'Browser not supported.';	str += '</div>';if (!this.selectedFound) this.selectedNode = null;	this.completed = true;return str;};
// Creates the tree structure
dTree.prototype.addNode = function(pNode) {var str = '';var n=0;if (this.config.inOrder) n = pNode._ai;	for (n; n<this.aNodes.length; n++) {if (this.aNodes[n].pid == pNode.id) {	var cn = this.aNodes[n];cn._p = pNode;	cn._ai = n;	this.setCS(cn);	if (!cn.target && this.config.target) cn.target = this.config.target;if (cn._hc && !cn._io && this.config.useCookies) cn._io = this.isOpen(cn.id);if (!this.config.folderLinks && cn._hc) cn.url = null;	if (this.config.useSelection && cn.id == this.selectedNode && !this.selectedFound) {	cn._is = true;	this.selectedNode = n;	this.selectedFound = true;	}	str += this.node(cn, n);if (cn._ls) break;	}}return str;};
// Creates the node icon, url and text
dTree.prototype.node = function(node, nodeId) {	var imgstr = '';var str = '<div class="dTreeNode">' + this.indent(node, nodeId);if (this.config.useIcons) {	if (!node.icon) node.icon = (this.root.id == node.pid) ? this.icon.root : ((node._hc) ? this.icon.folder : this.icon.node);if (!node.iconOpen) node.iconOpen = (node._hc) ? this.icon.folderOpen : this.icon.node;if (this.root.id == node.pid) {node.icon = this.icon.root;	node.iconOpen = this.icon.root;	}imgstr += '<img border="0" id="i' + this.obj + nodeId + '" src="' + ((node._io) ? node.iconOpen : node.icon) + '" alt="" />';}if (node.url) {str += '<a id="s' + this.obj + nodeId + '" class="' + ((this.config.useSelection) ? ((node._is ? 'nodeSel' : 'node')) : 'node') + '" href="' + node.url + '"';	if (node.title) str += ' title="' + node.title + '"';if (node.target) str += ' target="' + node.target + '"';if (this.config.useStatusText) str += ' onmouseover="window.status=\'' + node.name + '\';return true;" onmouseout="window.status=\'\';return true;" ';	if (this.config.useSelection && ((node._hc && this.config.folderLinks) || !node._hc))str += ' onclick="javascript: ' + this.obj + '.s(' + nodeId + ');"';	str += '>';}else if ((!this.config.folderLinks || !node.url) && node._hc && node.pid != this.root.id)	str += '<a href="javascript: ' + this.obj + '.low(' + nodeId + ');" class="node">';str +=  imgstr + node.name;if (node.url || ((!this.config.folderLinks || !node.url) && node._hc)) str += '</a>';	str += '</div>';if (node._hc) {	str += '<div id="d' + this.obj + nodeId + '" class="clip" style="display:' + ((this.root.id == node.pid || node._io) ? 'block' : 'none') + ';">';str += this.addNode(node);	str += '</div>';}this.aIndent.pop();return str;};
// Adds the empty and line icons
dTree.prototype.indent = function(node, nodeId) {	var str = '';if (this.root.id != node.pid) {for (var n=0; n<this.aIndent.length; n++)str += '<img src="' + ( (this.aIndent[n] == 1 && this.config.useLines) ? this.icon.line : this.icon.empty ) + '" alt="" />';	(node._ls) ? this.aIndent.push(0) : this.aIndent.push(1);if (node._hc) {str += '<span onclick=" ' + this.obj + '.o(' + nodeId + ');"><img id="j' + this.obj + nodeId + '" src="';if (!this.config.useLines) str += (node._io) ? this.icon.nlMinus : this.icon.nlPlus;	else str += ( (node._io) ? ((node._ls && this.config.useLines) ? this.icon.minusBottom : this.icon.minus) : ((node._ls && this.config.useLines) ? this.icon.plusBottom : this.icon.plus ) );	str += '" alt="" /></span>';} else str += '<img src="' + ( (this.config.useLines) ? ((node._ls) ? this.icon.joinBottom : this.icon.join ) : this.icon.empty) + '" alt="" />';}return str;};
// Checks if a node has any children and if it is the last sibling
dTree.prototype.setCS = function(node) {var lastId;	for (var n=0; n<this.aNodes.length; n++) {		if (this.aNodes[n].pid == node.id) node._hc = true;	if (this.aNodes[n].pid == node.pid) lastId = this.aNodes[n].id;	}	if (lastId==node.id) node._ls = true;};
// Returns the selected node
dTree.prototype.getSelected = function() {	var sn = this.getCookie('cs' + this.obj);	return (sn) ? sn : null;};
// Highlights the selected node
dTree.prototype.s = function(id) {	if (!this.config.useSelection) return;	var cn = this.aNodes[id];	if (cn._hc && !this.config.folderLinks) return;	if (this.selectedNode != id) {if (this.selectedNode || this.selectedNode==0) {	eOld = document.getElementById("s" + this.obj + this.selectedNode);	eOld.className = "node";}eNew = document.getElementById("s" + this.obj + id);	eNew.className = "nodeSel";	this.selectedNode = id;	if (this.config.useCookies) this.setCookie('cs' + this.obj, cn.id);	}};
// Toggle Open or close
dTree.prototype.o = function(id) {	var cn = this.aNodes[id];	this.nodeStatus(!cn._io, id, cn._ls);	cn._io = !cn._io;	if (this.config.closeSameLevel) this.closeLevel(cn);	if (this.config.useCookies) this.updateCookie();};
// Toggle Open or close
dTree.prototype.low = function(id) {var cn = this.aNodes[id];	this.nodeStatus(!cn._io, id, cn._ls);cn._io = !cn._io;	if (this.config.closeSameLevel) this.closeLevel(cn);if (this.config.useCookies) this.updateCookie();	};
// Open or close all nodes
dTree.prototype.oAll = function(status) {	for (var n=0; n<this.aNodes.length; n++) {	if (this.aNodes[n]._hc && this.aNodes[n].pid != this.root.id) {	this.nodeStatus(status, n, this.aNodes[n]._ls);	this.aNodes[n]._io = status;}}	if (this.config.useCookies) this.updateCookie();};// Opens the tree to a specific node
dTree.prototype.openTo = function(nId, bSelect, bFirst) {if (!bFirst) {	for (var n=0; n<this.aNodes.length; n++) {	if (this.aNodes[n].id == nId) {	nId=n;	break;}}}var cn=this.aNodes[nId];if (cn.pid==this.root.id || !cn._p) return;cn._io = true;cn._is = bSelect;	if (this.completed && cn._hc) this.nodeStatus(true, cn._ai, cn._ls);if (this.completed && bSelect) this.s(cn._ai);	else if (bSelect) this._sn=cn._ai;	this.openTo(cn._p._ai, false, true);};// Closes all nodes on the same level as certain node
dTree.prototype.closeLevel = function(node) {	for (var n=0; n<this.aNodes.length; n++) {if (this.aNodes[n].pid == node.pid && this.aNodes[n].id != node.id && this.aNodes[n]._hc) {this.nodeStatus(false, n, this.aNodes[n]._ls);	this.aNodes[n]._io = false;	this.closeAllChildren(this.aNodes[n]);	}}};
// Closes all children of a node
dTree.prototype.closeAllChildren = function(node) {	for (var n=0; n<this.aNodes.length; n++) {	if (this.aNodes[n].pid == node.id && this.aNodes[n]._hc) {	if (this.aNodes[n]._io) this.nodeStatus(false, n, this.aNodes[n]._ls);this.aNodes[n]._io = false;this.closeAllChildren(this.aNodes[n]);	}}};
// Change the status of a node(open or closed)
dTree.prototype.nodeStatus = function(status, id, bottom) {eDiv	= document.getElementById('d' + this.obj + id);	eJoin	= document.getElementById('j' + this.obj + id);if (this.config.useIcons) {	eIcon	= document.getElementById('i' + this.obj + id);	eIcon.src = (status) ? this.aNodes[id].iconOpen : this.aNodes[id].icon;	}eJoin.src = (this.config.useLines)?	((status)?((bottom)?this.icon.minusBottom:this.icon.minus):((bottom)?this.icon.plusBottom:this.icon.plus)):	((status)?this.icon.nlMinus:this.icon.nlPlus);	eDiv.style.display = (status) ? 'block': 'none';};
// [Cookie] Clears a cookie
dTree.prototype.clearCookie = function() {	var now = new Date();	var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);	this.setCookie('co'+this.obj, 'cookieValue', yesterday);	this.setCookie('cs'+this.obj, 'cookieValue', yesterday);};
// [Cookie] Sets value in a cookie
dTree.prototype.setCookie = function(cookieName, cookieValue, expires, path, domain, secure) {	document.cookie =		escape(cookieName) + '=' + escape(cookieValue)		+ (expires ? '; expires=' + expires.toGMTString() : '')	+ (path ? '; path=' + path : '')+ (domain ? '; domain=' + domain : '')	+ (secure ? '; secure' : '');};
// [Cookie] Gets a value from a cookie
dTree.prototype.getCookie = function(cookieName) {	var cookieValue = '';	var posName = document.cookie.indexOf(escape(cookieName) + '=');if (posName != 0) {	var posValue = posName + (escape(cookieName) + '=').length;	var endPos = document.cookie.indexOf(';', posValue);if (endPos != 0) cookieValue = unescape(document.cookie.substring(posValue, endPos));else cookieValue = unescape(document.cookie.substring(posValue));	}return (cookieValue);};
// [Cookie] Returns ids of open nodes as a string
dTree.prototype.updateCookie = function() {	var str = '';	for (var n=0; n<this.aNodes.length; n++) {	if (this.aNodes[n]._io && this.aNodes[n].pid != this.root.id) {if (str) str += '.';	str += this.aNodes[n].id;	}}this.setCookie('co' + this.obj, str);};
// [Cookie] Checks if a node id is in a cookie
dTree.prototype.isOpen = function(id) {	var aOpen = this.getCookie('co' + this.obj).split('.');	for (var n=0; n<aOpen.length; n++)	if (aOpen[n] == id) return true;	return false;};// If Push and pop is not implemented by the browser
if (!Array.prototype.push) {Array.prototype.push = function array_push() {	for(var i=0;i<arguments.length;i++)	this[this.length]=arguments[i];	return this.length;	}};if (!Array.prototype.pop) {	Array.prototype.pop = function array_pop() {		lastElement = this[this.length-1];	this.length = Math.max(this.length-1,0);return lastElement;}};

// JavaScript Document
TRACE_CLASS = new Class({
						
	list: [],
	
	options: {
            show: true,
			log: false,
			
			mainTraceDivStyle: {
				position: 'fixed',
				bottom: '0px',
				left: '0px',
				width: window.top.innerWidth-30+'px',//Window.getSize().size.x - 30 +'px',
				margin: '0px',
				'font-family': 'tahoma',
				cursor: 'default',
				border: '1px dashed #DDD'
			},
			nodeTraceDivStyleMin: {
				float: 'left',
				border: '1px solid #999',
				width: '150px',
				height: '21px',
				margin: '2px',
				background: '#FFFEF5',
				overflow: 'hidden',
				position: ''
			},
			nodeTraceDivStyleMax: {
				position: 'fix',
				top: '4px',
				left: '4px',
				border: '1px solid #999',
				width: window.top.innerWidth-30+'px',//Window.getSize().size.x - 30 +'px',
				margin: '2px',
				background: '#FFFEF5',
				overflow: 'hidden'
			},
			bodyTraceDivStyle: {
				'font-family': 'tahoma',
				'font-size': '12px',
				'font-weight' : 'normal',
				color: '#333',
				padding: '4px',
				overflow: 'auto',
				margin: '3px 1px 0 0'
			},
			headerTraceDivStyle: {
				height: '19px'
			},
			titleTraceDivStyle: {
				width: window.top.innerWidth+'px',//Window.getSize().size.x+'px',
				'border-bottom': '1px solid #999',
				height: '19px',
				background: '#3366CC',
				color: '#FFF',
				cursor: 'default',
				'font-size': '13px',
				padding: '2px 0 0 0'
			},
			resizeTraceDivStyle: {
				float: 'left',
				width: '15px',
				border: '1px solid #999',
				height: '15px',
				'background-color': '#000000',
				margin: '2px',
				color: '#EEE',
				'font-weight': 'bold',
				overflow: 'hidden',
				'text-align': 'center',
				cursor: 'default',
				opacity: '0.5'
			},
			closeTraceDivStyle: {
				float: 'left',
				width: '15px',
				border: '1px solid #999',
				height: '15px',
				'background-color': '#DD3333',
				margin: '2px 0 2px 2px',
				color: '#EEE',
				overflow: 'hidden',
				'text-align': 'center',
				cursor: 'default',
				opacity: '0.5'
			}
    },
	
	initialize: function()
	{
		this.mainTraceDiv = window.top.document.getElementById('mainTraceDiv');
		if(!this.mainTraceDiv) {
			this.mainTraceDiv = new Element('DIV');
			this.mainTraceDiv.setStyles(this.options.mainTraceDivStyle);
			this.mainTraceDiv.id = 'mainTraceDiv';
			this.mainTraceDiv.injectInside(window.top.document.body);
			this.mainTraceDiv.addEvent('mouseover', (function(e){
				this.mainTraceDiv.setStyle('z-index', 20000);
			}).bind(this));
			this.mainTraceDiv.addEvent('mouseout', (function(e){
				this.mainTraceDiv.setStyle('z-index', '');
			}).bind(this));
		}
	},
	
	show: function()
	{
		for(var i=0; i<this.list.length; i++) {
			
			if(typeof(console)!='undefined' && this.options.log)
				console.log(this.list[i].title+':\n'+this.list[i].value);
			if(!this.options.show)
				continue;	
				
			var nodeTraceDiv = new Element('DIV');
			var headerTraceDiv = new Element('DIV');
			var titleTraceDiv = new Element('DIV');
			var resizeTraceDiv = new Element('DIV');
			var closeTraceDiv = new Element('DIV');
			var bodyTraceDiv = new Element('DIV');
			nodeTraceDiv.setStyles(this.options.nodeTraceDivStyleMin);
			headerTraceDiv.setStyles(this.options.headerTraceDivStyle);
			bodyTraceDiv.setStyles(this.options.bodyTraceDivStyle);
			closeTraceDiv.setStyles(this.options.closeTraceDivStyle);
			resizeTraceDiv.setStyles(this.options.resizeTraceDivStyle);
			titleTraceDiv.setStyles(this.options.titleTraceDivStyle);
			
			nodeTraceDiv.injectInside(this.mainTraceDiv);
			headerTraceDiv.injectInside(nodeTraceDiv);
			bodyTraceDiv.injectInside(nodeTraceDiv);	
			closeTraceDiv.injectInside(headerTraceDiv);
			resizeTraceDiv.injectInside(headerTraceDiv);
			titleTraceDiv.injectInside(headerTraceDiv);
			
			nodeTraceDiv.addClass('nodeTraceDiv');
			headerTraceDiv.addClass('headerTraceDiv');
			bodyTraceDiv.addClass('bodyTraceDiv');
			closeTraceDiv.addClass('closeTraceDiv');
			closeTraceDiv.setStyle('float', 'left');
			resizeTraceDiv.addClass('resizeTraceDiv');
			resizeTraceDiv.setStyle('float', 'left');
			titleTraceDiv.addClass('titleTraceDiv');
			
			titleTraceDiv.setHTML(this.list[i].title);
			bodyTraceDiv.setHTML('<pre style="margin-top:2px">'+this.list[i].value+'</pre>');
			
			resizeTraceDiv.setHTML('<div style="margin:0">+</div>');
			closeTraceDiv.setHTML('<div style="margin:0">x</div>');
			
			closeTraceDiv.addEvent('click', (function(){$(this).getParent().getParent().remove()}).bind(closeTraceDiv));
			resizeTraceDiv.addEvent('click', this.restore.bind(this));
			//closeTraceDiv.onclick = function(){alert(this); this.getParent().getParent().remove()};
			
			closeTraceDiv.addEvent('mouseenter', this.btnEnter);
			resizeTraceDiv.addEvent('mouseenter', this.btnEnter);
			
			closeTraceDiv.addEvent('mouseleave', this.btnLeave);
			resizeTraceDiv.addEvent('mouseleave', this.btnLeave);
		}
	},
	
	restore: function(e){
		var e = new Event(e);
		var me = $(e.target);
		while(me.getFirst())
			me = me.getFirst();
		var nodeTraceDiv = me.getParent().getParent().getParent();
		var bodyTraceDiv = me.getParent().getParent().getNext();
		me.getParent().removeClass('maxed_resizeTraceDiv');
		
		if(me.innerHTML == '+') { //maximize
			me.innerHTML = '-';
			while(this.mainTraceDiv.getElementsBySelector('.maxed_resizeTraceDiv')[0])
				this.minimize(this.mainTraceDiv.getElementsBySelector('.maxed_resizeTraceDiv')[0].getFirst());
			me.getParent().addClass('maxed_resizeTraceDiv');
			nodeTraceDiv.setStyles(this.options.nodeTraceDivStyleMax);
			nodeTraceDiv.setStyle('height', window.top.innerHeight - this.mainTraceDiv.getSize().size.y - 30 + 'px');	
			bodyTraceDiv.setStyle('height', nodeTraceDiv.getSize().size.y - 32 + 'px');
		} else { //minimize
			me.innerHTML = '+';
			nodeTraceDiv.setStyles(this.options.nodeTraceDivStyleMin);					
		}
	},
	
	minimize: function(me){
		var nodeTraceDiv = me.getParent().getParent().getParent();
		me.getParent().removeClass('maxed_resizeTraceDiv');
		me.innerHTML = '+';
		nodeTraceDiv.setStyles(this.options.nodeTraceDivStyleMin);
	},
	
	btnEnter: function(e){		
		var e = new Event(e);
		var me = $(e.target);
		while(me.getFirst())
			me = me.getFirst();
		me = me.getParent();
		var opChange = new Fx.Style(me, 'opacity', {duration:200});
		opChange.start(0.5, 1);

	},
	
	btnLeave: function(e){	
		var e = new Event(e);
		var me = $(e.target);
		while(me.getFirst())
			me = me.getFirst();
		me = me.getParent();
		var opChange = new Fx.Style(me, 'opacity', {duration:200});
		opChange.start(1, 0.5);
	}
});

function traceLoader()
{
	if(window.traceScript && document.body) {
		eval(window.traceScript);
		window.traceScript = null;
	}
	if(window.traceLoaderTO) clearInterval(window.traceLoaderTO);
	window.traceLoaderTO = setTimeout('traceLoader();', 500);
}

traceLoader();


/**************************************************************

	Script		: Lightbox
	Version		: 1.5
	Authors		: Samuel Birch
	Desc		: Extended version of Slimbox
	Licence		: Open Source MIT Licence

**************************************************************/
var Lightbox = {

	init: function(options){
		this.options = Object.extend({
			resizeDuration: 400,
			resizeTransition: Fx.Transitions.sineInOut,
			initialWidth: 250,
			initialHeight: 250,
			animateCaption: {In:true,Out:true},
			container: document.body,
			showControls: false,
			showNumbers: true,
			descriptions: false,
			opacity: 0.8
		}, options || {});

		this.anchors = [];
		$each(document.links, function(el){
			if (el.rel && el.rel.test(/^lightbox/i)){
				el.onclick = this.click.pass(el, this);
				this.anchors.push(el);
			}
		}, this);
		this.eventKeyDown = this.keyboardListener.bindAsEventListener(this);
		this.eventPosition = this.position.bind(this);

		this.overlay = new Element('div').setProperty('id', 'lbOverlay').injectInside(this.options.container);

		this.center = new Element('div').setProperty('id', 'lbCenter').setStyles({width: this.options.initialWidth+'px', height: this.options.initialHeight+'px', marginLeft: '-'+(this.options.initialWidth/2)+'px', display: 'none'}).injectInside(this.options.container);
		this.image = new Element('div').setProperty('id', 'lbImage').injectInside(this.center);
		
		this.bottomContainer = new Element('div').setProperty('id', 'lbBottomContainer').setStyle('display', 'none').injectInside(this.options.container);
		this.bottom = new Element('div').setProperty('id', 'lbBottom').injectInside(this.bottomContainer);
		
		if(this.options.showControls){
			this.controlDiv = new Element('div').setProperty('id','lbControls').injectInside(this.bottom);
		}else{
			this.controlDiv = this.image;
		}
		this.prevLink = new Element('a').setProperties({id: 'lbPrevLink', href: '#'}).setStyle('display', 'none').injectInside(this.controlDiv);
		this.nextLink = this.prevLink.clone().setProperty('id', 'lbNextLink').injectInside(this.controlDiv);
		this.prevLink.onclick = this.previous.bind(this);
		this.nextLink.onclick = this.next.bind(this);

		this.closeButton = new Element('a').setProperties({id: 'lbCloseLink', href: '#'}).injectInside(this.bottom)
		this.closeButton.onclick = this.overlay.onclick = this.close.bind(this);
		
		this.caption = new Element('div').setProperty('id', 'lbCaption').injectInside(this.bottom);
		if(this.options.descriptions != false){
			this.options.descriptions = $$(this.options.descriptions);
			this.description = new Element('div').setProperty('id', 'lbDescription').injectInside(this.bottom);
		}
		if(this.options.showNumbers){
			this.number = new Element('div').setProperty('id', 'lbNumber').injectInside(this.bottom);
		}
		new Element('div').setStyle('clear', 'both').injectInside(this.bottom);

		var nextEffect = this.nextEffect.bind(this);
		this.fx = {
			overlay: this.overlay.effect('opacity', {duration: 500}).hide(),
			resize: this.center.effects({duration: this.options.resizeDuration, transition: this.options.resizeTransition, onComplete: nextEffect}),
			image: this.image.effect('opacity', {duration: 500, onComplete: nextEffect}),
			bottom: this.bottom.effect('margin-top', {duration: 400, onComplete: nextEffect})
		};

		this.preloadPrev = new Image();
		this.preloadNext = new Image();
	
		if(window.ie) {
			Lightbox.open([], 0);
			Lightbox.close();
		}
	},

	click: function(link){
	
		this.options.descriptions.each(function(el,i){
			if(el.hasClass(link.id)){				
				this.linkLoc = i;
			}
		},this);
				
		if (link.rel.length == 8) return this.show(link.href, link.title);

		var j, imageNum, images = [];
		this.anchors.each(function(el){
			if (el.rel == link.rel){
				for (j = 0; j < images.length; j++) if(images[j][0] == el.href) break;
				if (j == images.length){
					images.push([el.href, el.title]);
					if (el.href == link.href) imageNum = j;
				}
			}
		}, this);
		return this.open(images, imageNum);
	},

	show: function(url, title){ console.log(url);
		return this.open([[url, title]], 0);
	},

	open: function(images, imageNum){
		this.images = images;
		this.position();
		this.setup(true);
		this.top = window.getScrollTop() + (window.getHeight() / 15);
		this.window = {};
		this.window.height = window.getScrollHeight();
		this.window.width = window.getScrollWidth();
		this.window.top = window.getScrollTop();
		this.window.left = window.getScrollLeft();
		this.center.setStyles({top: this.top+'px', display: ''});
		this.fx.overlay.start(this.options.opacity);
		return this.changeImage(imageNum);
	},

	position: function(){ 
		if(this.options.container == document.body){ 
			var h = window.getScrollHeight()+'px'; 
			var w = window.getScrollWidth()+'px';
			this.overlay.setStyles({top: '0px', height: h, width: w}); 
		}else{ 
			var myCoords = $(this.options.container).getCoordinates(); 
			this.overlay.setStyles({
				top: myCoords.top+'px', 
				height: myCoords.height+'px', 
				left: myCoords.left+'px', 
				width: myCoords.width+'px'
			}); 
		} 
	},

	setup: function(open){
		var elements = $A(document.getElementsByTagName('object'));
		if (window.ie) elements.extend(document.getElementsByTagName('select'));
		elements.each(function(el){ el.style.visibility = open ? 'hidden' : ''; });
		var fn = open ? 'addEvent' : 'removeEvent';
		window[fn]('scroll', this.eventPosition)[fn]('resize', this.eventPosition);
		document[fn]('keydown', this.eventKeyDown);
		this.step = 0;
	},

	keyboardListener: function(event){
		switch (event.keyCode){
			case 27: case 88: case 67: this.close(); break;
			case 37: case 80: this.previous(); break;	
			case 39: case 78: this.next();
		}
	},

	previous: function(){
		this.linkLoc --;
		return this.changeImage(this.activeImage-1);
	},

	next: function(){
		this.linkLoc ++;
		return this.changeImage(this.activeImage+1);
	},

	changeImage: function(imageNum){
		if (this.step || (imageNum < 0) || (imageNum >= this.images.length)) return false;
		this.step = 1;
		this.activeImage = imageNum;
		if(this.options.animateCaption.In && this.bottom.offsetHeight){
			this.prevLink.style.display = this.nextLink.style.display = 'none';
			this.bottom.effect('margin-top', {duration: 300, onComplete: this.loadImage.bind(this)}).start(-this.bottom.offsetHeight);
		}else{
			this.bottomContainer.style.display = this.prevLink.style.display = this.nextLink.style.display = 'none';
			this.loadImage();
		}
		this.fx.image.hide();
		this.center.className = 'lbLoading';
		
		return false;
	},
	
	loadImage: function(){
		this.preload = new Image();
		this.preload.onload = this.nextEffect.bind(this);
		this.preload.src = this.images[this.activeImage][0];
	},

	nextEffect: function(){
		switch (this.step++){
		case 1:
			this.center.className = '';
			this.image.style.backgroundImage = 'url('+this.images[this.activeImage][0]+')';
			this.image.style.width = this.bottom.style.width = this.preload.width+'px';
			if(this.options.showControls){
				this.image.style.height = this.preload.height+'px';
			}else{
				this.image.style.height = this.prevLink.style.height = this.nextLink.style.height = this.preload.height+'px';
			}

			this.caption.setHTML(this.images[this.activeImage][1] || '');
			if(this.options.descriptions != false){
				if(this.description.getFirst()){this.description.getFirst().remove()};
				var cl = this.options.descriptions[this.linkLoc].clone();
				cl.setStyle('display', 'block').injectInside(this.description);
			}
			if(this.options.showNumbers){
				this.number.setHTML((this.images.length == 1) ? '' : 'Image '+(this.activeImage+1)+' of '+this.images.length);
			}

			if (this.activeImage) this.preloadPrev.src = this.images[this.activeImage-1][0];
			if (this.activeImage != (this.images.length - 1)) this.preloadNext.src = this.images[this.activeImage+1][0];
			if (this.center.clientHeight != this.image.offsetHeight){
				this.fx.resize.start({height: this.image.offsetHeight});
				break;
			}
			this.step++;
		case 2:
			if (this.center.clientWidth != this.image.offsetWidth){
				this.fx.resize.start({width: this.image.offsetWidth, marginLeft: -this.image.offsetWidth/2});
				break;
			}
			this.step++;
		case 3:
			this.bottomContainer.setStyles({top: (this.top + this.center.clientHeight)+'px', height: '0px', marginLeft: this.center.style.marginLeft, display: ''});
			this.fx.image.start(1);
			var extra = this.caption.getStyle('height').toInt();
			if(this.options.descriptions != false){extra += this.description.getStyle('height').toInt()}
			if(this.options.showControls){extra += this.controlDiv.getStyle('height').toInt()}
			if(this.options.showNumbers){extra += this.number.getStyle('height').toInt()}
			var num = (extra-(this.closeButton.getStyle('height').toInt()*2));
			if(num < 0){num=0}
			this.closeButton.setStyle('marginTop', num+'px');
			if(this.activeImage != 0) this.prevLink.style.display = '';
			if(this.activeImage != (this.images.length - 1)) this.nextLink.style.display = '';
			break;
		case 4:
			if (this.options.animateCaption.Out){
				this.fx.bottom.set(-this.bottom.offsetHeight);
				this.bottomContainer.style.height = '';
				this.fx.bottom.start(0);
				break;
			}
			this.bottomContainer.style.height = '';
		case 5:
			this.step = 0;
		}
	},

	close: function(){
		if (this.step < 0) return;
		this.step = -1;
		if (this.preload){
			this.preload.onload = Class.empty;
			this.preload = null;
		}
		for (var f in this.fx) this.fx[f].stop();
		this.center.style.display = this.bottomContainer.style.display = 'none';
		this.fx.overlay.chain(this.setup.pass(false, this)).start(0);
		this.overlay.setStyles({height: this.window.height+'px', width: this.window.width+'px'});
		return false;
	}

};

/*************************************************************/

