﻿// JScript File
// version 1.2.1
//MooTools More, <http://mootools.net/more>. Copyright (c) 2006-2008 Valerio Proietti, <http://mad4milk.net>, MIT Style License.

Fx.Elements=new Class({Extends:Fx.CSS,initialize:function(B,A){this.elements=this.subject=$$(B);this.parent(A);},compute:function(G,H,I){var C={};for(var D in G){var A=G[D],E=H[D],F=C[D]={};
for(var B in A){F[B]=this.parent(A[B],E[B],I);}}return C;},set:function(B){for(var C in B){var A=B[C];for(var D in A){this.render(this.elements[C],D,A[D],this.options.unit);
}}return this;},start:function(C){if(!this.check(arguments.callee,C)){return this;}var H={},I={};for(var D in C){var F=C[D],A=H[D]={},G=I[D]={};for(var B in F){var E=this.prepare(this.elements[D],B,F[B]);
A[B]=E.from;G[B]=E.to;}}return this.parent(H,I);}});var Drag=new Class({Implements:[Events,Options],options:{snap:6,unit:"px",grid:false,style:true,limit:false,handle:false,invert:false,preventDefault:false,modifiers:{x:"left",y:"top"}},initialize:function(){var B=Array.link(arguments,{options:Object.type,element:$defined});
this.element=$(B.element);this.document=this.element.getDocument();this.setOptions(B.options||{});var A=$type(this.options.handle);this.handles=(A=="array"||A=="collection")?$$(this.options.handle):$(this.options.handle)||this.element;
this.mouse={now:{},pos:{}};this.value={start:{},now:{}};this.selection=(Browser.Engine.trident)?"selectstart":"mousedown";this.bound={start:this.start.bind(this),check:this.check.bind(this),drag:this.drag.bind(this),stop:this.stop.bind(this),cancel:this.cancel.bind(this),eventStop:$lambda(false)};
this.attach();},attach:function(){this.handles.addEvent("mousedown",this.bound.start);return this;},detach:function(){this.handles.removeEvent("mousedown",this.bound.start);
return this;},start:function(C){if(this.options.preventDefault){C.preventDefault();}this.fireEvent("beforeStart",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;}if(this.options.style){this.value.now[D]=this.element.getStyle(this.options.modifiers[D]).toInt();
}else{this.value.now[D]=this.element[this.options.modifiers[D]];}if(this.options.invert){this.value.now[D]*=-1;}this.mouse.pos[D]=C.page[D]-this.value.now[D];
if(A&&A[D]){for(var B=2;B--;B){if($chk(A[D][B])){this.limit[D][B]=$lambda(A[D][B])();}}}}if($type(this.options.grid)=="number"){this.options.grid={x:this.options.grid,y:this.options.grid};
}this.document.addEvents({mousemove:this.bound.check,mouseup:this.bound.cancel});this.document.addEvent(this.selection,this.bound.eventStop);},check:function(A){if(this.options.preventDefault){A.preventDefault();
}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){this.cancel();this.document.addEvents({mousemove:this.bound.drag,mouseup:this.bound.stop});
this.fireEvent("start",this.element).fireEvent("snap",this.element);}},drag:function(A){if(this.options.preventDefault){A.preventDefault();}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.options.invert){this.value.now[B]*=-1;
}if(this.options.limit&&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];}else{if($chk(this.limit[B][0])&&(this.value.now[B]<this.limit[B][0])){this.value.now[B]=this.limit[B][0];
}}}if(this.options.grid[B]){this.value.now[B]-=(this.value.now[B]%this.options.grid[B]);}if(this.options.style){this.element.setStyle(this.options.modifiers[B],this.value.now[B]+this.options.unit);
}else{this.element[this.options.modifiers[B]]=this.value.now[B];}}this.fireEvent("drag",this.element);},cancel:function(A){this.document.removeEvent("mousemove",this.bound.check);
this.document.removeEvent("mouseup",this.bound.cancel);if(A){this.document.removeEvent(this.selection,this.bound.eventStop);this.fireEvent("cancel",this.element);
}},stop:function(A){this.document.removeEvent(this.selection,this.bound.eventStop);this.document.removeEvent("mousemove",this.bound.drag);this.document.removeEvent("mouseup",this.bound.stop);
if(A){this.fireEvent("complete",this.element);}}});
//Element.MakeResizable
Element.implement({makeResizable:function(A){return new Drag(this,$merge({modifiers:{x:"width",y:"height"}},A));
}});Drag.Move=new Class({Extends:Drag,options:{droppables:[],container:false},initialize:function(C,B){this.parent(C,B);this.droppables=$$(this.options.droppables);
this.container=$(this.options.container);if(this.container&&$type(this.container)!="element"){this.container=$(this.container.getDocument().body);}C=this.element;
var D=C.getStyle("position");var A=(D!="static")?D:"absolute";if(C.getStyle("left")=="auto"||C.getStyle("top")=="auto"){C.position(C.getPosition(C.offsetParent));
}C.setStyle("position",A);this.addEvent("start",function(){this.checkDroppables();},true);},start:function(B){if(this.container){var D=this.element,J=this.container,E=J.getCoordinates(D.offsetParent),F={},A={};
["top","right","bottom","left"].each(function(K){F[K]=J.getStyle("padding-"+K).toInt();A[K]=D.getStyle("margin-"+K).toInt();},this);var C=D.offsetWidth+A.left+A.right,I=D.offsetHeight+A.top+A.bottom;
var H=[E.left+F.left,E.right-F.right-C];var G=[E.top+F.top,E.bottom-F.bottom-I];this.options.limit={x:H,y:G};}this.parent(B);},checkAgainst:function(B){B=B.getCoordinates();
var A=this.mouse.now;return(A.x>B.left&&A.x<B.right&&A.y<B.bottom&&A.y>B.top);},checkDroppables:function(){var A=this.droppables.filter(this.checkAgainst,this).getLast();
if(this.overed!=A){if(this.overed){this.fireEvent("leave",[this.element,this.overed]);}if(A){this.overed=A;this.fireEvent("enter",[this.element,A]);}else{this.overed=null;
}}},drag:function(A){this.parent(A);if(this.droppables.length){this.checkDroppables();}},stop:function(A){this.checkDroppables();this.fireEvent("drop",[this.element,this.overed]);
this.overed=null;return this.parent(A);}});
//Element.MakeDraggable
Element.implement({makeDraggable:function(A){return new Drag.Move(this,A);}});var Asset=new Hash({javascript:function(F,D){D=$extend({onload:$empty,document:document,check:$lambda(true)},D);
var B=new Element("script",{src:F,type:"text/javascript"});var E=D.onload.bind(B),A=D.check,G=D.document;delete D.onload;delete D.check;delete D.document;
B.addEvents({load:E,readystatechange:function(){if(["loaded","complete"].contains(this.readyState)){E();}}}).setProperties(D);if(Browser.Engine.webkit419){var C=(function(){if(!$try(A)){return ;
}$clear(C);E();}).periodical(50);}return B.inject(G.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:$empty,onabort:$empty,onerror:$empty},B);var D=new Image();var A=$(D)||new Element("img");["load","abort","error"].each(function(E){var F="on"+E;
var G=B[F];delete B[F];D[F]=function(){if(!D){return ;}if(!A.parentNode){A.width=D.width;A.height=D.height;}D=D.onload=D.onabort=D.onerror=null;G.delay(1,A,A);
A.fireEvent(E,A,1);};});D.src=A.src=C;if(D&&D.complete){D.onload.delay(1);}return A.setProperties(B);},images:function(D,C){C=$merge({onComplete:$empty,onProgress:$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,D.indexOf(F));B++;if(B==D.length){C.onComplete();
}}});A.push(E);});return new Elements(A);}});var Scroller=new Class({Implements:[Events,Options],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.listener=($type(this.element)!="element")?$(this.element.getDocument().body):this.element;
this.timer=null;this.coord=this.getCoords.bind(this);},start:function(){this.listener.addEvent("mousemove",this.coord);},stop:function(){this.listener.removeEvent("mousemove",this.coord);
this.timer=$clear(this.timer);},getCoords:function(A){this.page=(this.listener.get("tag")=="body")?A.client:A.page;if(!this.timer){this.timer=this.scroll.periodical(50,this);
}},scroll:function(){var B=this.element.getSize(),A=this.element.getScroll(),E=this.element.getPosition(),D={x:0,y:0};for(var C in this.page){if(this.page[C]<(this.options.area+E[C])&&A[C]!=0){D[C]=(this.page[C]-this.options.area-E[C])*this.options.velocity;
}else{if(this.page[C]+this.options.area>(B[C]+E[C])&&B[C]+B[C]!=A[C]){D[C]=(this.page[C]-B[C]+this.options.area-E[C])*this.options.velocity;}}}if(D.y||D.x){this.fireEvent("change",[A.x+D.x,A.y+D.y]);
}}});

String.implement({parseQueryString:function(){var b=this.split(/[&;]/),a={};
if(b.length){b.each(function(g){var c=g.indexOf("="),d=c<0?[""]:g.substr(0,c).match(/[^\]\[]+/g),e=decodeURIComponent(g.substr(c+1)),f=a;d.each(function(j,h){var k=f[j];
if(h<d.length-1){f=f[j]=k||{};}else{if($type(k)=="array"){k.push(e);}else{f[j]=$defined(k)?[k,e]:e;}}});});}return a;},cleanQueryString:function(a){return this.split("&").filter(function(e){var b=e.indexOf("="),c=b<0?"":e.substr(0,b),d=e.substr(b+1);
return a?a.run([c,d]):$chk(d);}).join("&");}});var URI=new Class({Implements:Options,options:{},regex:/^(?:(\w+):)?(?:\/\/(?:(?:([^:@\/]*):?([^:@\/]*))?@)?([^:\/?#]*)(?::(\d*))?)?(\.\.?$|(?:[^?#\/]*\/)*)([^?#]*)(?:\?([^#]*))?(?:#(.*))?/,parts:["scheme","user","password","host","port","directory","file","query","fragment"],schemes:{http:80,https:443,ftp:21,rtsp:554,mms:1755,file:0},initialize:function(b,a){this.setOptions(a);
var c=this.options.base||URI.base;if(!b){b=c;}if(b&&b.parsed){this.parsed=$unlink(b.parsed);}else{this.set("value",b.href||b.toString(),c?new URI(c):false);
}},parse:function(c,b){var a=c.match(this.regex);if(!a){return false;}a.shift();return this.merge(a.associate(this.parts),b);},merge:function(b,a){if((!b||!b.scheme)&&(!a||!a.scheme)){return false;
}if(a){this.parts.every(function(c){if(b[c]){return false;}b[c]=a[c]||"";return true;});}b.port=b.port||this.schemes[b.scheme.toLowerCase()];b.directory=b.directory?this.parseDirectory(b.directory,a?a.directory:""):"/";
return b;},parseDirectory:function(b,c){b=(b.substr(0,1)=="/"?"":(c||"/"))+b;if(!b.test(URI.regs.directoryDot)){return b;}var a=[];b.replace(URI.regs.endSlash,"").split("/").each(function(d){if(d==".."&&a.length>0){a.pop();
}else{if(d!="."){a.push(d);}}});return a.join("/")+"/";},combine:function(a){return a.value||a.scheme+"://"+(a.user?a.user+(a.password?":"+a.password:"")+"@":"")+(a.host||"")+(a.port&&a.port!=this.schemes[a.scheme]?":"+a.port:"")+(a.directory||"/")+(a.file||"")+(a.query?"?"+a.query:"")+(a.fragment?"#"+a.fragment:"");
},set:function(b,d,c){if(b=="value"){var a=d.match(URI.regs.scheme);if(a){a=a[1];}if(a&&!$defined(this.schemes[a.toLowerCase()])){this.parsed={scheme:a,value:d};
}else{this.parsed=this.parse(d,(c||this).parsed)||(a?{scheme:a,value:d}:{value:d});}}else{if(b=="data"){this.setData(d);}else{this.parsed[b]=d;}}return this;
},get:function(a,b){switch(a){case"value":return this.combine(this.parsed,b?b.parsed:false);case"data":return this.getData();}return this.parsed[a]||"";
},go:function(){document.location.href=this.toString();},toURI:function(){return this;},getData:function(c,b){var a=this.get(b||"query");if(!$chk(a)){return c?null:{};
}var d=a.parseQueryString();return c?d[c]:d;},setData:function(a,c,b){if(typeof a=="string"){data=this.getData();data[arguments[0]]=arguments[1];a=data;
}else{if(c){a=$merge(this.getData(),a);}}return this.set(b||"query",Hash.toQueryString(a));},clearData:function(a){return this.set(a||"query","");}});URI.prototype.toString=URI.prototype.valueOf=function(){return this.get("value");
};URI.regs={endSlash:/\/$/,scheme:/^(\w+):/,directoryDot:/\.\/|\.$/};URI.base=new URI(document.getElements("base[href]",true).getLast(),{base:document.location});
String.implement({toURI:function(a){return new URI(this,a);}});

//Element.Measure
Element.implement({measure:function(e){var g=function(h){return !!(!h||h.offsetHeight||h.offsetWidth);};if(g(this)){return e.apply(this);
}var d=this.getParent(),b=[],f=[];while(!g(d)&&d!=document.body){b.push(d.expose());d=d.getParent();}var c=this.expose();var a=e.apply(this);c();b.each(function(h){h();
});return a;},expose:function(){if(this.getStyle("display")!="none"){return $empty;}var a=this.style.cssText;this.setStyles({display:"block",position:"absolute",visibility:"hidden"});
return function(){this.style.cssText=a;}.bind(this);},getDimensions:function(a){a=$merge({computeSize:false},a);var d={};var c=function(f,e){return(e.computeSize)?f.getComputedSize(e):f.getSize();
};if(this.getStyle("display")=="none"){d=this.measure(function(){return c(this,a);});}else{try{d=c(this,a);}catch(b){}}return $chk(d.x)?$extend(d,{width:d.x,height:d.y}):$extend(d,{x:d.width,y:d.height});
},getComputedSize:function(a){a=$merge({styles:["padding","border"],plains:{height:["top","bottom"],width:["left","right"]},mode:"both"},a);var c={width:0,height:0};
switch(a.mode){case"vertical":delete c.width;delete a.plains.width;break;case"horizontal":delete c.height;delete a.plains.height;break;}var b=[];$each(a.plains,function(g,f){g.each(function(h){a.styles.each(function(i){b.push((i=="border")?i+"-"+h+"-width":i+"-"+h);
});});});var e={};b.each(function(f){e[f]=this.getComputedStyle(f);},this);var d=[];$each(a.plains,function(g,f){var h=f.capitalize();c["total"+h]=0;c["computed"+h]=0;
g.each(function(i){c["computed"+i.capitalize()]=0;b.each(function(k,j){if(k.test(i)){e[k]=e[k].toInt()||0;c["total"+h]=c["total"+h]+e[k];c["computed"+i.capitalize()]=c["computed"+i.capitalize()]+e[k];
}if(k.test(i)&&f!=k&&(k.test("border")||k.test("padding"))&&!d.contains(k)){d.push(k);c["computed"+h]=c["computed"+h]-e[k];}});});});["Width","Height"].each(function(g){var f=g.toLowerCase();
if(!$chk(c[f])){return;}c[f]=c[f]+this["offset"+g]+c["computed"+g];c["total"+g]=c[f]+c["total"+g];delete c["computed"+g];},this);return $extend(e,c);}});
(function(){var a=Element.prototype.position;
//Element.Position
Element.implement({position:function(r){if(r&&($defined(r.x)||$defined(r.y))){return a?a.apply(this,arguments):this;
}$each(r||{},function(t,s){if(!$defined(t)){delete r[s];}});r=$merge({relativeTo:document.body,position:{x:"center",y:"center"},edge:false,offset:{x:0,y:0},returnPos:false,relFixedPosition:false,ignoreMargins:false,allowNegative:false},r);
var b={x:0,y:0};var h=false;var c=this.measure(function(){return document.byid(this.getOffsetParent());});if(c&&c!=this.getDocument().body){b=c.measure(function(){return this.getPosition();
});h=true;r.offset.x=r.offset.x-b.x;r.offset.y=r.offset.y-b.y;}var q=function(s){if($type(s)!="string"){return s;}s=s.toLowerCase();var t={};if(s.test("left")){t.x="left";
}else{if(s.test("right")){t.x="right";}else{t.x="center";}}if(s.test("upper")||s.test("top")){t.y="top";}else{if(s.test("bottom")){t.y="bottom";}else{t.y="center";
}}return t;};r.edge=q(r.edge);r.position=q(r.position);if(!r.edge){if(r.position.x=="center"&&r.position.y=="center"){r.edge={x:"center",y:"center"};}else{r.edge={x:"left",y:"top"};
}}this.setStyle("position","absolute");var p=document.byid(r.relativeTo)||document.body;var i=p==document.body?window.getScroll():p.getPosition();var o=i.y;
var g=i.x;if(Browser.Engine.trident){var l=p.getScrolls();o+=l.y;g+=l.x;}var j=this.getDimensions({computeSize:true,styles:["padding","border","margin"]});
if(r.ignoreMargins){r.offset.x=r.offset.x-j["margin-left"];r.offset.y=r.offset.y-j["margin-top"];}var n={};var d=r.offset.y;var e=r.offset.x;var k=window.getSize();
switch(r.position.x){case"left":n.x=g+e;break;case"right":n.x=g+e+p.offsetWidth;break;default:n.x=g+((p==document.body?k.x:p.offsetWidth)/2)+e;break;}switch(r.position.y){case"top":n.y=o+d;
break;case"bottom":n.y=o+d+p.offsetHeight;break;default:n.y=o+((p==document.body?k.y:p.offsetHeight)/2)+d;break;}if(r.edge){var m={};switch(r.edge.x){case"left":m.x=0;
break;case"right":m.x=-j.x-j.computedRight-j.computedLeft;break;default:m.x=-(j.x/2);break;}switch(r.edge.y){case"top":m.y=0;break;case"bottom":m.y=-j.y-j.computedTop-j.computedBottom;
break;default:m.y=-(j.y/2);break;}n.x=n.x+m.x;n.y=n.y+m.y;}n={left:((n.x>=0||h||r.allowNegative)?n.x:0).toInt(),top:((n.y>=0||h||r.allowNegative)?n.y:0).toInt()};
if(p.getStyle("position")=="fixed"||r.relFixedPosition){var f=window.getScroll();n.top=n.top.toInt()+f.y;n.left=n.left.toInt()+f.x;}if(r.returnPos){return n;
}else{this.setStyles(n);}return this;}});})();


Fx.Move=new Class({Extends:Fx.Morph,options:{relativeTo:document.body,position:"center",edge:false,offset:{x:0,y:0}},start:function(a){return this.parent(this.element.position($merge(this.options,a,{returnPos:true})));
}});Element.Properties.move={set:function(a){var b=this.retrieve("move");if(b){b.cancel();}return this.eliminate("move").store("move:options",$extend({link:"cancel"},a));
},get:function(a){if(a||!this.retrieve("move")){if(a||!this.retrieve("move:options")){this.set("move",a);}this.store("move",new Fx.Move(this,this.retrieve("move:options")));
}return this.retrieve("move");}};
Element.implement({move:function(a){this.get("move").start(a);return this;}});

//Scroll 1.2.4.2

Fx.Scroll=new Class({Extends:Fx,options:{offset:{x:0,y:0},wheelStops:true},initialize:function(b,a){this.element=this.subject=document.byid(b);
this.parent(a);var d=this.cancel.bind(this,false);if($type(this.element)!="element"){this.element=document.byid(this.element.getDocument().body);}var c=this.element;
if(this.options.wheelStops){this.addEvent("start",function(){c.addEvent("mousewheel",d);},true);this.addEvent("complete",function(){c.removeEvent("mousewheel",d);
},true);}},set:function(){var a=Array.flatten(arguments);if(Browser.Engine.gecko){a=[Math.round(a[0]),Math.round(a[1])];}this.element.scrollTo(a[0],a[1]);
},compute:function(c,b,a){return[0,1].map(function(d){return Fx.compute(c[d],b[d],a);});},start:function(c,g){if(!this.check(c,g)){return this;}var e=this.element.getScrollSize(),b=this.element.getScroll(),d={x:c,y:g};
for(var f in d){var a=e[f];if($chk(d[f])){d[f]=($type(d[f])=="number")?d[f]:a;}else{d[f]=b[f];}d[f]+=this.options.offset[f];}return this.parent([b.x,b.y],[d.x,d.y]);
},toTop:function(){return this.start(false,0);},toLeft:function(){return this.start(0,false);},toRight:function(){return this.start("right",false);},toBottom:function(){return this.start(false,"bottom");
},toElement:function(b){var a=document.byid(b).getPosition(this.element);return this.start(a.x,a.y);},scrollIntoView:function(c,e,d){e=e?$splat(e):["x","y"];
var h={};c=document.byid(c);var f=c.getPosition(this.element);var i=c.getSize();var g=this.element.getScroll();var a=this.element.getSize();var b={x:f.x+i.x,y:f.y+i.y};
["x","y"].each(function(j){if(e.contains(j)){if(b[j]>g[j]+a[j]){h[j]=b[j]-a[j];}if(f[j]<g[j]){h[j]=f[j];}}if(h[j]==null){h[j]=g[j];}if(d&&d[j]){h[j]=h[j]+d[j];
}},this);if(h.x!=g.x||h.y!=g.y){this.start(h.x,h.y);}return this;},scrollToCenter:function(c,e,d){e=e?$splat(e):["x","y"];c=$(c);var h={},f=c.getPosition(this.element),i=c.getSize(),g=this.element.getScroll(),a=this.element.getSize(),b={x:f.x+i.x,y:f.y+i.y};
["x","y"].each(function(j){if(e.contains(j)){h[j]=f[j]-(a[j]-i[j])/2;}if(h[j]==null){h[j]=g[j];}if(d&&d[j]){h[j]=h[j]+d[j];}},this);if(h.x!=g.x||h.y!=g.y){this.start(h.x,h.y);
}return this;}});var SmoothScroll=Fx.SmoothScroll=new Class({Extends:Fx.Scroll,initialize:function(b,c){c=c||document;this.doc=c.getDocument();var d=c.getWindow();
this.parent(this.doc,b);this.links=$$(this.options.links||this.doc.links);var a=d.location.href.match(/^[^#]*/)[0]+"#";this.links.each(function(f){if(f.href.indexOf(a)!=0){return;
}var e=f.href.substr(a.length);if(e){this.useLink(f,e);}},this);if(!Browser.Engine.webkit419){this.addEvent("complete",function(){if($defined(this.anchor)){d.location.hash=this.anchor;
}},true);}},useLink:function(c,a){var b;c.addEvent("click",function(d){if(b!==false&&!b){b=document.byid(a)||this.doc.getElement("a[name="+a+"]");}if(b){d.preventDefault();
this.anchor=a;this.toElement(b).chain(function(){this.fireEvent("scrolledTo",[c,b]);}.bind(this));c.blur();}}.bind(this));}});
px.Namespace.Register("px.Templates");
// JScript File
// Also added to more for bug fixing:
// - wrap SmoothScroll.complete function with if($defined(this.anchor) { ...wrapped... }
px.Templates.dlg = '   <div class="dlg" style="position: absolute; visibility: visible;'+
'        z-index: $zindex" id="$id">'+
'        <div id="$id_HeaderSpan">'+
'        </div>'+
'        <table id="$id_table" cellpadding="0" cellspacing="0">'+
'           <tr id="$id_DragContainer" onmousedown="$id.StartDrag(this,event);" onmouseup="$id.EndDrag(this,event);" class="dlg-title draggable">' +
'                <td class="left"></td>'+
'                <td class="mid">'+
'                    <a onclick="$id.Close(px.DialogResult.Cancel);this.blur();return false;" href="javascript:void(0);"'+
'                        class="close"></a><span>$title</span>'+
'                </td>'+
'                <td class="right"></td>'+
'            </tr>'+
'            <tr class="dlg-content">'+
'                <td class="left"></td>'+
'                <td id="$id_Content" class="mid">'+
'                </td>'+
'                <td class="right"></td>'+
'            </tr>'+
'            <tr class="dlg-buttons">'+
'                <td class="left"></td>'+
'                <td class="mid" id="$id_Buttons">'+
'                </td>'+
'                <td class="right"></td>'+
'            </tr>'+
'        </table>'+
'        <div id="Editor1_ctl10_HyperlinkDialog_FooterSpan">'+
'        </div>'+
'    </div>';
// just changed below $id to $id_Content
px.Templates.dlg_modal_NoFrame = '   <div style="position: absolute; visibility: visible;'+
'        z-index: $zindex" id="$id_Backdrop"></div><div style="position: absolute; visibility: visible;'+
'        z-index: $zindex" id="$id_Content"></div>'
px.Templates.dlg_tabsShell = '            <div class="dlg-tabstrip">'+
'                <div class="left"></div>'+
'                <div id="$id_TabTemplate" class="tabs">'+
'                    <!-- example tab'+
'                    <a onclick="toggle_dialog_tab(this,$id,0);this.blur();"'+
'                        class="tab-selected" href="javascript:void(0);"><span class="link">Link</span></a>-->'+
'                   $tabs'+
'                </div>'+
'                <div class="right"></div>'+
'            </div>';
px.Templates.dlg_contentTemplate = '     <div id="$id">$content</div>';
var Zindex = 27000;
px.DialogResult = {Cancel:'Cancel',Ok:'Ok'};
px.Namespace.Register("px.UI");
px.UI.Modal = new Class({
    Implements: Events,

    ID: null,
    Tabs: [],
    Contents: [],
    Buttons: [],
    idrxs: /\$id/g,
    zindexrxs: /\$zindex/g,
    contentrxs: /\$content/g,
    titlerxs: /\$title/g,
    ClientTemplate: null,
    DomNode: null,
    OnDrag: null,
    OnDrop: null,
    Drag: null,
    di: null,
    Templates: { dlg: 'dlg', notification: 'notification' },
    Settings: new Hash({ scrollToDialog: false, useDirtyIndicator: false, bgcolor: '#fff', width: -1, height: -1, template: px.Templates.dlg, title: '', buttons: { close: true, update: false, insert: true }, position: { element: '', pos: '', edge: '' }, containerCssClass: 'Modal' }),

    Dispose: function modal_Dispose()
    {
        //document.body.removeChild(this.DomNode);
        this.DomNode.dispose();
        this.DomNode = null;

    },
    initialize: function modal_initialize(id, content, settings)
    {
        var s = new Hash(this.Settings);
        if (settings)
            this.Settings = s.merge(settings);
        this.ID = id;
        var ct = new Object();
        ct.ID = this.ID + '_ContentShell';
        var localTemplate = this.Settings.template.replace(this.idrxs, this.ID);
        this.ClientTemplate = content;
        ct.Template = localTemplate
        this.Contents.push(ct);
        window[this.ID] = this;

    },
    Update: function modal_Update()
    {
        this.OnUpdate();
    },
    Close: function modal_Close(DialogResult)
    {
        this.OnClose(DialogResult);
        if (this.DomNode)
            this.DomNode.style.display = 'none';
    },
    Open: function modal_Open()
    {
        this.EnsureChildControls();
        this.SetClean();
        this.DomNode.setStyle('display', 'block');
        this.DomNode.set('opacity', 1);
        // positioning..
        if (this.Settings.position.element != '')
        {
            var pos = '';
            var edg = '';
            if (this.Settings.position.pos != '')
                pos = this.Settings.position.pos;
            if (this.Settings.position.edge != '')
                edg = this.Settings.position.edge;
            var el = $(this.ID);
            el.position({
                relativeTo: this.Settings.position.element,
                position: pos,
                edge: edg
            });
        }
        // if there is no drag created and the modal has a bar for dragging (dlg template), create it.toTop()
        if (null == this.Drag && this.Settings.template == px.Templates.dlg)
            this.Drag = new Drag(this.ID).detach();
        if (this.Settings.scrollToDialog)
        {
            //var myFx = new Fx.SmoothScroll($(this.ID)).toTop();
            var myFx = new Fx.SmoothScroll({ offset: { x: 0, y: -100} }).toElement(this.ID);

        }
    },
    SetDirty: function modal_setdirty()
    {
        if (!this.Settings.useDirtyIndicator)
            return;
        this.di.removeClass('-clean');
        this.di.addClass('-dirty');
    },
    SetClean: function modal_setclean()
    {
        if (!this.Settings.useDirtyIndicator)
            return;
        this.di.removeClass('-dirty');
        this.di.addClass('-clean');
    },
    FadeOut: function modal_FadeOut()
    {
        var t = this;
        t.DomNode.set('morph', { duration: 800, transition: Fx.Transitions.Sine.easeOut });
        var fx = t.DomNode.get('morph');
        fx.addEvent('complete', function modal_MorphComplete() { t.fireEvent('Faded', t.DomNode); });
        t.DomNode.morph({ opacity: 0 });
    },
    Position: function modal_Position(opt)
    {
        var el = $(this.ID);
        el.position({ position: opt });
    },
    Template: null,
    CreateButtons: function modal_CreateButtons()
    {
        var ButtonContainer = $(this.ID + "_Buttons");
        if (null == ButtonContainer)
            return;
        this.Settings.buttons.getKeys().each(
        function modal_iterateStandardButtons(btn)
        {
            if (this.Settings.buttons[btn] != false)
            {
                var b = null;
                switch (btn)
                {
                    case "insert":
                        this.InsertButton = b = this.CreateButton("Insert", this.InsertAction.replace(this.idrxs, this.ID));
                        break;
                    case "close":
                        b = this.CreateButton("Close", this.CloseAction.replace(this.idrxs, this.ID), "");
                        break;
                    case "update":
                        b = this.CreateButton("Update", this.UpdateAction.replace(this.idrxs, this.ID), "");
                        break;
                }
                if (b)
                {
                    ButtonContainer.grab(b);
                }
            }
        } .bind(this));
        this.Buttons.each(
        function modal_iterateCustomButtons(btn)
        {
            ButtonContainer.grab($(btn));
        });
        if (this.Settings.useDirtyIndicator)
        {
            this.di = new Element('div', { 'style': 'float:left;', 'class': 'di -clean' });
            ButtonContainer.grab(this.di);
        }
    },
    EnsureChildControls: function modal_EnsureChildControls()
    {

        if (null != this.Template)
            return;
        // build template...
        // at this point our template will look like this <div id="$id_ContentShell">$content</div>
        this.Template = px.Templates.dlg_contentTemplate.replace(this.idrxs, this.Contents[0].ID);
        // now we will have:
        // <div id="$id_ContentShell">
        //  whatever content template was defined which will have a node with $id_Content
        // </div>
        // the template will have a node with $id_Content.. that is the node that we will attach the 
        // data content passed into this modal
        this.Template = this.Template.replace(this.contentrxs, this.Contents[0].Template);
        // set the z-index and title
        this.Template = this.Template.replace(this.zindexrxs, ++Zindex).replace(this.titlerxs, this.Settings.title);
        // now we will create the node that will be attached to the dom
        this.DomNode = new Element('div', { id: this.ID + '_DomNode', 'class': this.Settings.containerCssClass });
        // we set the html of the dom node
        this.DomNode.innerHTML = this.Template;
        var type = $type(this.ClientTemplate);

        // now that we have our template we need to do a couple of things...
        // first:
        //  find an element to attach our unit to.
        // second:
        //  see if we need to create buttons for the template

        var Parent = null;
        // need to check to see if the content template is string or object,
        // then attach our unit
        //        if (type === 'element')
        //        {
        //            Parent = this.ClientTemplate.getParent();
        //        }
        //        else
        Parent = $(document.forms[0]);
        // some cases if an element is passed in that does not belong to dom yet, Parent will be null
        if (null == Parent)
            Parent = document.body;
        // attach our unit now
        Parent.adopt(this.DomNode);
        // now lets get our content node
        var c = $(this.ID + "_Content");

        if (this.Settings.width > 0)
            c.setStyle('width', this.Settings.width + "px");
        if (this.Settings.height > 0)
            c.setStyle('height', this.Settings.width + "px");
        // create buttons
        this.CreateButtons();

        // if this template does not have a frame, then we want to set a backdrop
        if (this.Settings.template == px.Templates.dlg_modal_NoFrame)
        {
            //c = $(this.ID + '_content');
            var frame = $(this.ID + '_Backdrop');
            frame.setStyles({ 'background-color': this.Settings.bgcolor, top: '0px', left: '0px', opacity: .4, 'z-index': Zindex - 4 });
            this.FrameResize(0, Browser.VisibleWidth, 0, Browser.VisibleHeight);
            Browser.State.addEvent('resize', this.FrameResize.bind(this));
            c.setStyles({
                position: 'absolute',
                top: 0,
                'z-index': Zindex
            });
            //c = $(this.ID)
        }
        // now we have a frame of sorts, so lets add the content
        if (type === 'string')
        {
            c.innerHTML = this.ClientTemplate;
        }
        else if (type === 'element')
        {
            // ensure visibility of element.
            this.ClientTemplate.setStyles({ 'display': '', 'visibility': '' });
            c.grab(this.ClientTemplate);
        }
        else
            throw ('the client content is not in format that can be attached to this object');
        this.DomNode.setStyle('display', 'none');
        // other options like tabs..etc
    },
    AddButton: function modal_AddButton(obj_button)
    {
        this.Buttons.push(obj_button);
    },
    FrameResize: function modal_frameresize(w, vw, h, vh)
    {
        var frame = $(this.ID + '_Backdrop');
        if (null == frame)
            return;
        frame.setStyles({ width: vw, height: document.getScrollHeight() });
        //console.log(vw, vh);
    },
    CloseAction: "$id.Close(px.DialogResult.Cancel);this.blur();return false;",
    InsertAction: "$id.Close(px.DialogResult.Ok);this.blur();return false;",
    UpdateAction: "$id.Update();this.blur();return false;",
    InsertButton: null,
    CreateButton: function modal_CreateButton(Name, Action, CssClass)
    {
        if (!CssClass)
            CssClass = '';
        if (CssClass.length > 0)
            CssClass = ' ' + CssClass;
        var a = new Element('a', { 'class': 'button-70 float-right' + CssClass, onclick: Action });
        var s = new Element('span');
        s.innerHTML = Name;
        a.grab(s);
        return a;
    },
    CreateTab: function modal_CreateTab(ID, Name, Content)
    {
        var tab = new Object();
        tab.ID = ID;
        tab.Name = Name;
        tab.Index = this.Tabs.length + 1;
        //etc etc  
    },
    EndDrag: function modal_EndDrag(el, evt)
    {
        this.Drag.detach();
        this.OnDrop(el, evt);
    },
    StartDrag: function modal_StartDrag(el, evt)
    {
        var t = this; //this.ID
        t.Drag.attach();
        this.OnStartDrag(el, evt);
        //        var myDrag = new Drag.Move(el,
        //        {
        //            droppables: '.droppable',

        //            onDrop: function(element, droppable, event)
        //            {
        //                if (!droppable) console.log(element, ' dropped on nothing');
        //                else console.log(element, 'dropped on', droppable, 'event', event);
        //                t.OnDrop(element, droppable, event);
        //            },

        //            onEnter: function(element, droppable)
        //            {
        //                console.log(element, 'entered', droppable);
        //                t.OnEnter(element, droppable, event);
        //            },

        //            onLeave: function(element, droppable)
        //            {
        //                console.log(element, 'left', droppable);
        //                t.OnLeave(element, droppable, event);
        //            }
        //        });
    },
    OnUpdate: function modal_onupdate()
    {
        this.fireEvent('OnUpdate');
    },
    OnLeave: function modal_onleave(el, droppable, evt)
    {
        this.fireEvent('OnLeave', [el, droppable, evt]);
    },
    OnEnter: function modal_onenter(el, droppable, evt)
    {
        this.fireEvent('OnEnter', [el, droppable, evt]);
    },
    OnStartDrag: function modal_onstartdrag(el, evt)
    {
        this.fireEvent('OnStartDrag', [el, evt]);
    },
    OnDrop: function(el, droppable, evt)
    {
        this.fireEvent('OnDrop', [el, droppable, evt]);
    },
    OnClose: function(DialogResult)
    {
        this.fireEvent('OnClose', [DialogResult]);
    }
});