var Gloo =
{
Init : function()
{
Gloo.ResizePage();
Gloo.SetupMenu();
attachEventListener(window, "resize", Gloo.ResizePage, false);
},

SetupMenu : function()
{
if ($("Navigation"))
{
var anchors = $("Navigation").getElementsByTagName("a");
var spans = $("Navigation").getElementsByTagName("span");
for(var i = 0; i < anchors.length; i++)
{
anchors[i].onclick = function(){ Gloo.ToggleMenu(this); };
spans[i].onclick = function(){ Gloo.ToggleMenu(this); };
}
}

var cookie = readCookie("glooMenu");
if (cookie != null)
{
var items = $("Navigation").getElementsByTagName("li");
for(var i = 0; i < items.length; i++)
{
var sublists = items[i].getElementsByTagName("ul");
if ((sublists.length > 0 || items[i].className.match(/SiteContentNode/)) && cookie.match(items[i].id)) items[i].className += " Opened";
}
}

Gloo.LoadSiteMap();

attachEventListener(window, "unload", GlooUnload, true);
},

SelectedMenuPage: null,
ContentFolderPane: null,
LoadSiteMap: function()
{
if (!$("Navigation")) return;

var node = null;
var items = $("Navigation").getElementsByTagName("li");
for(var i = 0; i < items.length; i++)
{
if (items[i].className.match(/SiteContentNode/gi))
{
node = items[i];
break;
}
}
if (node == null) return;

ExplorerAsset.prototype.AddPage = function()
{
location.href = "/Cms/SiteContent/Edit.aspx?ParentId=" + this.Id;
};
ExplorerAsset.prototype.EditPage = function()
{
location.href = "/Cms/SiteContent/Edit.aspx?Id=" + this.Id;
};
ExplorerAsset.prototype.ViewPage = function()
{
Gloo.ContextMenu.Hide();
window.open("/Web/SiteContent/Default.aspx?Preview=True&Id=" + this.Id);
};
ExplorerAsset.prototype.DeletePage = function()
{
Gloo.ContextMenu.Hide();
Gloo.Dialogue.ConfirmOk("Confirm", "Are you sure you want to delete <strong>" + this.Title + "</strong>?  All pages beneath this page will also be deleted.", this.Self + ".PreDeleteConfirmed()");
};
ExplorerAsset.prototype.PreDeleteConfirmed = function()
{
if (this.Pane.Selected[0] == this) setHTML($("MetaData"), "Select a page to view more details here...");
this.DeleteConfirmed();
};

Gloo.ContentFolderPane = new ExplorerPane(node, Explorer.MODE_TREE, "/Cms/SiteContent/Folders.aspx", "Root Tree");
Gloo.ContentFolderPane.onLoad = function()
{
node.className += " Branch";

if (Gloo.SelectedMenuPage != null)
{
node.className += " Opened";

var asset;
for (var i = 0; Gloo.ContentFolderPane.Assets.length; i++)
{
if (isNaN(Gloo.SelectedMenuPage))
{
if (Gloo.ContentFolderPane.Assets[i].Type.match(new RegExp(Gloo.SelectedMenuPage + "Module", "gi")))
{
asset = Gloo.ContentFolderPane.Assets[i];
break;
}
}
else
{
if (Gloo.ContentFolderPane.Assets[i].Id == Gloo.SelectedMenuPage)
{
asset = Gloo.ContentFolderPane.Assets[i];
break;
}
}
}

asset.Highlight();
while (asset.Parent != null)
{
asset.Parent.Expand();
asset = asset.Parent;
}
}

var cookie = readCookie("glooMenu");
if (cookie != null)
{
for (var i = 0; Gloo.ContentFolderPane.Assets.length; i++)
{
var memId = "a" + Gloo.ContentFolderPane.Assets[i].Id + "_";
if (cookie.match(memId))
{
Gloo.ContentFolderPane.Assets[i].Expand();
}
}
}
};
Gloo.ContentFolderPane.onGetClass = function(Asset)
{
var className = "";
if (!Asset.HasChildren) className = "Empty";
if (Asset.Type.match(/Content/gi)) className += "Page";
else if (Asset.Type.match(/Custom/gi)) className += "PageShortcut";
else if (Asset.Type.match(/Shortcut/gi)) className += "ExternalShortcut";
if (Asset.Type.match(/Disabled/gi)) className += " Disabled";
if (Asset.Type.match(/[a-z]+Module/gi)) className += " " + Asset.Type.match(/[a-z]+Module/gi).toString();
return className;
}
Gloo.ContentFolderPane.onDropAllowed = function(Asset, Target)
{
if (Asset == Target) return false;
return Asset.Pane == Target.Pane;
};
Gloo.ContentFolderPane.onContextMenuItems = function(Asset)
{
var Html = "";
if (Asset.Type.match(/(Tree)/gi))
{
Html += "<li><a href='#' onclick='return " + Asset.Self + ".AddPage();'>Add page</a></li>";
}

if (Asset.Type.match(/(Content|Custom|Shortcut)/gi))
{
Html += "<li><a href='#' onclick='return " + Asset.Self + ".AddPage();'>Add page</a></li>";
Html += "<li><a href='#' onclick='return " + Asset.Self + ".EditPage();'>Edit</a></li>";
Html += "<li><a href='#' onclick='return " + Asset.Self + ".ViewPage();'>View</a></li>";
Html += "<li><a href='#' onclick='return " + Asset.Self + ".DeletePage();'>Delete</a></li>";
}
return Html;
};
Gloo.ContentFolderPane.onSelect = function(Asset)
{
if (Asset.Type.match(/Module/gi))
{
var path = Asset.Type.match(/[a-z]+Module/gi).toString().replace(/Module/gi, "");
location.href = "/Cms/" + path + "/";
}
else
{
location.href = "/Cms/SiteContent/Edit.aspx?Id=" + Asset.Id;
}
};
Gloo.ContentFolderPane.onAssetToggle = function(Asset)
{
var memId = "a" + Asset.Id + "_";

var cookie = readCookie("glooMenu");
if (cookie == null) cookie = "";
cookie = cookie.replace(memId, "");
if (Asset.Expanded) cookie += memId;
createCookie("glooMenu", cookie, 365);
};
Gloo.ContentFolderPane.Load(0);
},

ToggleMenu : function(El)
{
var node = El.parentNode;
var lists = node.getElementsByTagName("ul");
if (lists.length > 0)
{
if (!isVisible(lists[0]))
{
if (!node.className.match(/Opened/)) node.className += " Opened";
}
else node.className = node.className.replace(/Opened/, "");
}

var cookie = readCookie("glooMenu");
if (cookie == null) cookie = "";
cookie = cookie.replace(node.id + "_", "");
if (node.className.match(/Opened/)) cookie += node.id + "_";
createCookie("glooMenu", cookie, 365);
},

TogglePanel : function(Anchor)
{
var El = Anchor.parentNode.parentNode;
if (El.className.match(/Collapsed/gi)) El.className = El.className.replace(/Collapsed/gi, "");
else El.className += " Collapsed";
return false;
},

StatusCounter: 0,
HidingStatus : null,
ShowStatus : function(Text, AutoHide)
{
var id = "Status" + (this.StatusCounter++);
Text += " <span class=\"Hide\">(<a href=\"#\" onclick=\"Gloo.ClearStatus(this);return false;\" id='" + id + "'>Hide</a>)</span>";

var Message = document.createElement("div");
Message.id = "StatusMessage";
Message.className = "Status";
setHTML(Message, Text);

var StatusDiv = $("StatusBar").getElementsByTagName("div")[0];
var InnerDivs = StatusDiv.getElementsByTagName("div");
if (InnerDivs.length > 0) StatusDiv.insertBefore(Message, InnerDivs[0]);
else StatusDiv.appendChild(Message);

if (AutoHide)
{
setTimeout("Gloo.ClearStatus($('" + id + "'));", 5000);
}
},
ClearStatus : function(Anchor)
{
var Element = Anchor;
while (Element.nodeName != "DIV" && Element.parentNode) Element = Element.parentNode;
if (Element.nodeName != "DIV") return;
else Element.parentNode.removeChild(Element);
},

ShowInfo : function(Text)
{
if (!$("InfoBar")) return;
setHTML($("InfoBar"), Text);
show($("InfoBar"));
},

ShowFilter : function(Anchor)
{
var Filter = "";
var Divs = $("RightPane").getElementsByTagName("div");
for(var i = 0; i < Divs.length; i++)
{
if (Divs[i].id.match(/_ListFilter$/gi)) { Filter = Divs[i]; break; }
}
if (!Filter) return;

setTop(Filter, getOffsetTop(Anchor) - getOffsetTop($("RightPane")) + getHeight(Anchor) +1);
setLeft(Filter, getOffsetLeft(Anchor) - getOffsetLeft($("RightPane")) + getWidth(Anchor) - getWidth(Filter) + 10);

if (isVisible(Filter))
{
hide(Filter);
Anchor.parentNode.className = Anchor.parentNode.className.replace(/Selected/gi, "");
}
else
{
show(Filter);
Anchor.parentNode.className += " Selected";
}
Gloo.ResizePage();

return false;
},

ResizePage : function()
{
var newHeight = getDocumentHeight() - getHeight($("Banner"));
if (newHeight > 0)
{
setHeight($("LeftPane"), newHeight);
setHeight($("RightPane"), newHeight);
}

try
{
var h = getDocumentHeight() - getOffsetTop($("RightPaneScroller")) - getHeight($("StatusBar"));
if (h > 0) setHeight($("RightPaneScroller"), h);
}
catch (err) {}

setTimeout("Gloo.ResizeTable();", 1);
},

ResizeTable : function()
{
try
{
var aCells = $("TableHeaderRow").getElementsByTagName("td");
var bCells = $("RightPaneScroller").getElementsByTagName("tr")[0].getElementsByTagName("td");
for(var i = 0; i < aCells.length; i++)
{
for(var j = 1; j < 999; j++) { var c = j; }
setWidth(aCells[i], getWidth(bCells[i]));
if (i == aCells.length - 1) aCells[i].className = "Last";
}
$("TableHeaderRow").getElementsByTagName("table")[0].style.visibility = "visible";
}
catch (err)
{
if ($("TableHeaderRow")) $("TableHeaderRow").getElementsByTagName("table")[0].style.visibility = "visible";
}
},

AddLinkButtonClick : function (id)
{
var b = $(id);
if (b && typeof(b.click) == 'undefined')
{
b.click = function()
{
var result = true;
if (b.onclick) result = b.onclick();
if (typeof(result) == 'undefined' || result)
{
eval(b.href);
}
}
}
},

Preview : function(id, script, width, height)
{
Gloo.Dialogue.Iframe("Preview", (script || "Preview.aspx") + "?Id=" + id, true, width || 640, height || 480);
return false;
}
};
function GlooUnload()
{
if ($("Navigation"))
{
var anchors = $("Navigation").getElementsByTagName("a");
var spans = $("Navigation").getElementsByTagName("span");
for(var i = 0; i < anchors.length; i++)
{
anchors[i].onclick = null;

if (anchors[i].parentNode.className.match(/Selected/))
{
spans[i].onclick = null;
}
else
{
spans[i].onclick = null;
}
}
}

detachEventListener(window, "resize", Gloo.ResizePage, false);
}
$ = function (Element) { return document.getElementById(Element); };
show = function (Element) { Element.style.display = "block"; };
hide = function (Element) { Element.style.display = "none"; };
isVisible = function (Element) { return getStyle(Element, "display") != "none"; };
setVisibility = function (Element, Visibility) { Element.style.visibility = Visibility; };
setHeight = function (Element, Height) {  if (isNaN(Height)) Element.style.height = Height; else Element.style.height = Height + "px"; };
setWidth = function (Element, Width) { if (isNaN(Width)) Element.style.width = Width; else Element.style.width = Width + "px"; };
setTop = function (Element, Top) { Element.style.top = Top + "px"; };
setLeft = function (Element, Left) { Element.style.left = Left + "px"; };
setClip = function (Element, Top, Left, Width, Height) { Element.style.clip = "rect(" + Top + "px, " + (Left + Width) + "px, " + (Top + Height) + "px, " + Left + "px)"; };
setZindex = function (Element, Index) { Element.style.zIndex = Index; };
setHTML = function (Element, HTML) { Element.innerHTML = HTML; };
getStyle = function (Element, Property, CssProperty) { if (Element.currentStyle) return Element.currentStyle[Property]; if (window.getComputedStyle) return window.getComputedStyle(Element, "").getPropertyValue(CssProperty ? CssProperty : Property); return null; };
getVisibility = function (Element) { return Element.style.display; };
getClip = function (Element) { var clips = Element.style.clip.toString().replace(/[^0-9\s]/gi, "").split(" "); return { top: clips[0], right: clips[1], bottom: clips[2], left: clips[3], width: clips[1] - clips[3], height: clips[2] - clips[0] }; };
getZindex = function (Element) { return Element.style.zIndex; };
getOffsetTop = function (Element) { var Top = 0; while (Element.offsetParent) { Top += getTop(Element); Element = Element.offsetParent; } return Top; };
getOffsetLeft = function (Element) { var Left = 0; while (Element.offsetParent) { Left += getLeft(Element); Element = Element.offsetParent; } return Left; };
getHeight = function (e) { return getProperties(e).height; };
getWidth = function (e) { return getProperties(e).width; };
getTop = function (e) { return getProperties(e).top; };
getLeft = function (e) { return getProperties(e).left; };
getProperties = function(e) { if (isVisible(e)) return { top: e.offsetTop, left: e.offsetLeft, width: e.offsetWidth, height: e.offsetHeight }; var o = { v: e.style.visibility, p: e.style.position, d: e.style.display }; e.style.visibility = "hidden"; e.style.position = "absolute"; e.style.display = "block"; var v = { top: e.offsetTop, left: e.offsetLeft, width: e.offsetWidth, height: e.offsetHeight }; e.style.visibility = o.v; e.style.position = o.p; e.style.display = o.d; return v; };
getScrollX = function () { try { return document.documentElement.scrollLeft + document.body.scrollLeft; } catch (e) { return window.scrollX; } };
getScrollY = function () { try { return document.documentElement.scrollTop + document.body.scrollTop; } catch (e) { return window.scrollY; } };
getMouse = function(Event) { Event = !Event ? window.event : Event; return { x: Event.clientX + getScrollX(), y: Event.clientY + getScrollY() }; };
getMouseX = function (Event) { return getMouse(Event).x; };
getMouseY = function (Event) { return getMouse(Event).y; };
removeItemFromArray = function (ArrayItem, OriginalArray) { var NewArray = new Array(); for (var i = 0; i < OriginalArray.length; i++) { if (OriginalArray[i] != ArrayItem) NewArray.push(OriginalArray[i]); } return NewArray; };
htmlEncode = function(Text) { var d = document.createElement("div"); var t = document.createTextNode(Text); d.appendChild(t); return d.innerHTML; };
getOffsetScrollTop = function(Element) { var off = 0; while (Element && Element.parentNode) { off += Element.scrollTop; Element = Element.parentNode; } return off; };
getOffsetScrollLeft = function(Element) { var off = 0; while (Element && Element.parentNode) { off += Element.scrollLeft; Element = Element.parentNode; } return off; };
addLinkButtonClick = function (id) { var b = $(id); if (b && typeof(b.click) == 'undefined') { b.click = function() { var result = true; if (b.onclick) result = b.onclick();  if (typeof(result) == 'undefined' || result) { eval(b.href); } } } };
createCookie = function (name, value, days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else var expires = ""; document.cookie = name+"="+value+expires+"; path=/"; };
readCookie = function (name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; };
eraseCookie = function (name) { createCookie(name,"",-1); };
getQsVar = function(url, name) { if (!url.match(/\?/gi)) return ""; var qs = url.split("?")[1]; var pairs = qs.split("&"); for (var i = 0; i < pairs.length; i++) { var nameValue = pairs[i].split("="); if (nameValue[0] == name) return nameValue[1]; } return ""; };
addQsVar = function(urlQs, nameValue) { if (urlQs.match(/#/gi)) urlQs = urlQs.split('#')[0]; if (!urlQs.match(/\?/gi)) return urlQs + "?" + nameValue; var url = urlQs.split("?")[0] + "?"; var qs = urlQs.split("?")[1]; var pairs = qs.split("&"); var name = nameValue.split("=")[0]; for (var i = 0; i < pairs.length; i++) { var nv = pairs[i].split("="); if (nv[0] != name) url += pairs[i] + "&"; } return url + nameValue; };
getSelectionStart = function(o) { if (o.createTextRange) { var r = document.selection.createRange().duplicate(); r.moveEnd('character', o.value.length); if (r.text == '') return o.value.length; return o.value.lastIndexOf(r.text); } else return o.selectionStart; };
getSelectionEnd = function (o) { if (o.createTextRange) { var r = document.selection.createRange().duplicate(); r.moveStart('character', -o.value.length); return r.text.length; } else return o.selectionEnd; };
setSelection = function(o, a, b) { if (o.createTextRange) { var range = o.createTextRange(); range.collapse(true); range.moveStart("character", a); range.moveEnd("character", b - a); range.select(); } else { o.setSelectionRange(a, b); } };
attachEventListener = function (Element, Method, Function, Capture) { if (Element.addEventListener) Element.addEventListener(Method, Function, Capture); else if (Element.attachEvent) Element.attachEvent("on" + Method, Function); else eval("Element.on" + Method + "=" + Function); };
detachEventListener = function (Element, Method, Function, Capture) { if (Element.removeEventListener) Element.removeEventListener(Method, Function, Capture); else if (Element.detachEvent) Element.detachEvent("on" + Method, Function); else eval("delete Element.on" + Method); };
cancelEventBubble = function (Event) { if (!Event) Event = window.event; try { Event.cancelBubble = true; Event.returnValue = false; } catch(e){} if (Event.preventDefault) Event.preventDefault(); if (Event.stopPropagation) Event.stopPropagation(); };
getEventTarget = function (Event) { var Target; if (!Event) var Event = window.event; if (Event.target) Target = Event.target; else if (Event.srcElement) Target = Event.srcElement; if (Target && Target.nodeType == 3) Target = Target.parentNode; return Target; };
getKeyCode = function (Event) { if (!Event) var Event = window.event; if (Event.keyCode) return Event.keyCode; else if (Event.which) return Event.which; };
isEnterKey = function (Event) { return (getKeyCode(Event) == 13); };
getDocumentWidth = function () { if (window.innerWidth) return window.innerWidth; if (document.documentElement.clientWidth) return document.documentElement.clientWidth; if (document.body.clientWidth) return document.body.clientWidth; };
getDocumentHeight = function () { if (window.innerHeight) return window.innerHeight; if (document.documentElement.clientHeight) return document.documentElement.clientHeight; if (document.body.clientHeight) return document.body.clientHeight; };
getScrollTop = function () { if (document.documentElement && document.documentElement.scrollTop) return document.documentElement.scrollTop; else if (document.body) return document.body.scrollTop; else return 0; };
getScrollLeft = function () { if (document.documentElement && document.documentElement.scrollLeft) return document.documentElement.scrollLeft; else if (document.body) return document.body.scrollLeft; else return 0; };
getScrollerWidth = function () { var a = document.body.style.overflow; document.body.style.overflow = 'hidden'; var width = document.body.clientWidth; document.body.style.overflow = 'scroll'; width -= document.body.clientWidth; if(!width) width = document.body.offsetWidth-document.body.clientWidth; document.body.style.overflow = a; return width; };
getPageHeight = function() { var a = getDocumentHeight(); var b = document.body.scrollHeight; return a > b ? a : b; };
getPageWidth = function() { var a = getDocumentWidth(); var b = document.body.scrollWidth; return a > b ? a : b; };
sentenceCase = function (Text) { var Words = Text.split(" "); var Sentence = ""; for (var i = 0; i < Words.length; i++) { Sentence += Words[i].replace(/^[a-z]/gi, Words[i].substr(0,1).toUpperCase()) + (i < Words.length - 1 ? " " : ""); } return Sentence; };
trimWhiteSpace = function (Text) { return Text.replace(/^\s*/, "").replace(/\s*$/, ""); };
truncate = function(Text, Length, Suffix) { return (Text.length <= Length) ? Text : Text.substr(0, Length) + "..."; };
formatFileSize = function (Size) { if (Size < 1024) return Size + "bytes"; if (Size < (1024 * 1024)) return Math.round(Size / 1024) + "Kb"; return (Math.round((Size / (1024 * 1024))*100)/100) + "Mb"; };
stripHTML = function (Text) { if (Text == "") return ""; var p = new Array("</p>", "\n\n", "<br />", "\n", "<[^>]+>", "", "&amp;", "&", "&nbsp;", " ", "&gt;", ">", "&lt;", "<", "&apos;", "'"); for (var i = 0; i < p.length; i++) { var r = new RegExp(p[i], "gi"); i++; Text = Text.replace(r, p[i]); } return Text; };
toggleSelectBoxes = function (State) { if (!document.all) return; var Selects = document.getElementsByTagName("select"); for (var i = 0; i < Selects.length; i++) Selects[i].style.visibility = (State == "on") ? "visible" : "hidden"; };
hideSelectBoxes = function () { toggleSelectBoxes("off"); };
showSelectBoxes = function () { toggleSelectBoxes("on"); };
strongEaseOut = function (t, b, c, d) { return c*((t=t/d-1)*t*t*t*t + 1) + b; };
strongEaseIn = function (t, b, c, d) { return c*(t/=d)*t*t*t*t + b; };
strongEaseInOut = function (t, b, c, d) { if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b; return c/2*((t-=2)*t*t*t*t + 2) + b; };
function stringToDOM(q){var r=function(a){a=a.replace(/\r/g," ");a=a.replace(/\n/g," ");return a};var s=function(a){a=a.replace(/&amp;/g,"&");a=a.replace(/&gt;/g,">");a=a.replace(/&lt;/g,"<");a=a.replace(/&nbsp;/g," ");a=a.replace(/&quot;/g,'"');return a};var t=function(a){a=a.replace(/ /g,"");return a};var u=function(a){var b=document.createDocumentFragment();var c=a.indexOf(' ');if(c===-1){var d=a.toLowerCase();b.appendChild(document.createElement(d))}else{d=t(a.substring(0,c)).toLowerCase();if(document.all&&d==='input'){b.appendChild(document.createElement('<'+a+'/>'));return b}a=a.substring(c+1);b.appendChild(document.createElement(d));while(a.length>0){var e=a.indexOf('=');if(e>=0){var f=t(a.substring(0,e)).toLowerCase();var g=a.indexOf('"');a=a.substring(g+1);g=a.indexOf('"');var h=s(a.substring(0,g));a=a.substring(g+2);if(document.all&&f==='style'){b.lastChild.style.cssText=h}else{b.lastChild.setAttribute(f,h)}}else{break}}}return b};var v=function(a,b,c){var d=a;var e=b;c=c.toLowerCase();var f=e.indexOf('</'+c+'>');d=d.concat(e.substring(0,f));e=e.substring(f);while(d.indexOf('<'+c)!=-1){d=d.substring(d.indexOf('<'+c));d=d.substring(d.indexOf('>')+1);e=e.substring(e.indexOf('>')+1);f=e.indexOf('</'+c+'>');d=d.concat(e.substring(0,f));e=e.substring(f)}return b.length-e.length};var w=function(a){var b=document.createDocumentFragment();while(a&&a.length>0){var c=a.indexOf("<");if(c===-1){a=s(a);b.appendChild(document.createTextNode(a));a=null}if(c>0){var d=s(a.substring(0,c));b.appendChild(document.createTextNode(d));a=a.substring(c)}if(c===0){var e=a.indexOf('<!--');if(e===0){var f=a.indexOf('-->');var g=a.substring(4,f);g=s(g);b.appendChild(document.createComment(g));a=a.substring(f+3)}else{var h=a.indexOf('>');if(a.substring(h-1,h)==='/'){var i=a.indexOf('/>');var j=a.substring(1,i);b.appendChild(u(j));a=a.substring(i+2)}else{var k=a.indexOf('>');var l=a.substring(1,k);var m=document.createDocumentFragment();m.appendChild(u(l));a=a.substring(k+1);var n=a.substring(0,a.indexOf('</'));a=a.substring(a.indexOf('</'));if(n.indexOf('<')!=-1){var o=m.lastChild.nodeName;var p=v(n,a,o);n=n.concat(a.substring(0,p));a=a.substring(p)}a=a.substring(a.indexOf('>')+1);m.lastChild.appendChild(w(n));b.appendChild(m)}}}}return b};var x=w(q);return x}function DOMtoString(h){var j=function(a){a=a.replace(/&/g,"&amp;");a=a.replace(/>/g,"&gt;");a=a.replace(/</g,"&lt;");a=a.replace(/\"/g,'&quot;');return a};var k=function(a){var b=a.childNodes;var c='';for(var i=0;i<b.length;i++){var d=b[i].nodeType;switch(d){case 1:var e=b[i].nodeName.toLowerCase();var f=b[i].attributes;c=c.concat('<'+e);if(f.length>0){for(var g=0;g<f.length;g++){if(document.all){if(f[g].nodeName&&f[g].nodeValue!==null&&f[g].nodeValue!=''&&(f[g].nodeName!='contentEditable'&&f[g].nodeValue!='inherit')&&(f[g].nodeName!='shape'&&f[g].nodeValue!='rect')){c=c.concat(' '+f[g].nodeName.toLowerCase()+'="'+j(f[g].nodeValue)+'"')}if(f[g].nodeName==='style'&&b[i].style.cssText!==null&&b[i].style.cssText.length!==0){c=c.concat(' style="'+b[i].style.cssText.toLowerCase()+';"')}}else{c=c.concat(' '+f[g].nodeName.toLowerCase()+'="'+j(f[g].nodeValue)+'"')}}}if(e==='meta'||e==='img'||e==='br'||e==='input'||e==='link'||e==='hr'){c=c.concat(' />')}else{c=c.concat('>'+k(b[i])+'</'+e+'>')}break;case 3:c=c.concat(j(b[i].nodeValue));break;case 8:c=c.concat('<!--'+j(b[i].nodeValue)+'-->');break}}return c};var l=k(h);return l}
getStringFromXml = function(Node){ return (new XMLSerializer()).serializeToString(Node); }
loadXmlFromString = function(Text) { var Doc; if (window.ActiveXObject) { Doc = new ActiveXObject("Microsoft.XMLDOM"); Doc.async = "false"; Doc.loadXML(Text); } else { Doc = new DOMParser().parseFromString(Text, "text/xml"); } return Doc; };
makeHttpRequest = function (ScriptUrl, Method, PostData, SuccessCallbackFunction, FailureCallbackFunction) { var Request; var RefreshQS = "Refresh=" + Math.round((Math.random() * 999999)); if (ScriptUrl.indexOf("?") > -1) ScriptUrl += "&" + RefreshQS; else ScriptUrl += "?" + RefreshQS; if (window.XMLHttpRequest) { Request = new XMLHttpRequest(); Request.onreadystatechange = function () {  if(Request.readyState == 4) { var s = 0; try { s = Request.status; } catch (e) {} if (s != 200) try { eval(FailureCallbackFunction + "(Request);"); } catch(e){} else try { eval(SuccessCallbackFunction + "(Request);"); }catch(e){} Request.onreadystatechange = new Function(); } }; Request.open(Method, ScriptUrl, true); if (Method.toUpperCase() == "POST") Request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); Request.send(PostData); } else if (window.ActiveXObject) { try { Request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (err) { return null; } if (Request) { Request.onreadystatechange = function () { if(Request.readyState == 4) { var s = 0; try { s = Request.status; } catch (e){} if (s != 200) try { eval(FailureCallbackFunction + "(Request);"); } catch(e){} else try { eval(SuccessCallbackFunction + "(Request);"); }catch(e){} Request.onreadystatechange = new Function(); }  }; Request.open(Method, ScriptUrl, true); if (Method.toUpperCase() == "POST") Request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); Request.send(PostData); } } return Request; };
/* Calendar */
Gloo.Calendar =
{
Element : null,
Months : new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"),
Highlighted : null,
CurrentInput : null,
Input : null,

Show : function(Input)
{
Gloo.Calendar.Input = $(Input);

if (!$("GlooCalendar"))
{
Gloo.Calendar.Element = document.createElement("div");
Gloo.Calendar.Element.id = "GlooCalendar";
Gloo.Calendar.Element.className = "GlooCalendar";
document.forms[0].appendChild(Gloo.Calendar.Element);
}

if (Gloo.Calendar.ValidDate($(Input).value)) Gloo.Calendar.Highlighted = new Date($(Input).value);
else Gloo.Calendar.Highlighted = new Date();
Gloo.Calendar.CurrentInput = new Date(Gloo.Calendar.Highlighted);

var Html =
"<div class='Calendar'>" +
"<table cellspacing='0' class='TitleBar'>" +
"<tr>" +
"<td><a href='#' onclick='return Gloo.Calendar.ShowPreviousYear();' class='PreviousYear'>&laquo;</a></td>" +
"<td><a href='#' onclick='return Gloo.Calendar.ShowPreviousMonth();' class='PreviousMonth'>&lt;</a></td>" +
"<td align='center' width='100%'><span id='GlooCalendarTitle'><span></td>" +
"<td><a href='#' onclick='return Gloo.Calendar.ShowNextMonth();' class='NextMonth'>&gt;</a></td>" +
"<td><a href='#' onclick='return Gloo.Calendar.ShowNextYear();' class='NextYear'>&raquo;</a></td>" +
"</tr>" +
"</table>" +
"<div id='CalendarMonth' class='MonthBar'></div>" +
"<table cellspacing='0' class='StatusBar'>" +
"<tr>" +
"<td align='center'>" +
"<a href='#' onclick='return Gloo.Calendar.SetToday();' class='SelectToday'>Today</a>" +
"</td>" +
"</tr>" +
"</table>" +
"</div>";
setHTML(Gloo.Calendar.Element, Html);

Gloo.Calendar.BuildMonth();

attachEventListener(document, "mouseup", Gloo.Calendar.Hide, false);

return false;
},

Hide : function(Event)
{
if (Event)
{
var Target = getEventTarget(Event);
while (Target.id != "GlooCalendar" && Target.parentNode != null) Target = Target.parentNode;
if (Target.id == "GlooCalendar") return;
}

detachEventListener(document, "click", Gloo.Calendar.Hide, true);

if ($("GlooCalendar")) $("GlooCalendar").parentNode.removeChild($("GlooCalendar"));
},

ShowPreviousYear : function()
{
Gloo.Calendar.CurrentInput.setFullYear(Gloo.Calendar.CurrentInput.getFullYear() - 1);
Gloo.Calendar.BuildMonth();
return false;
},
ShowPreviousMonth : function()
{
Gloo.Calendar.CurrentInput.setMonth(Gloo.Calendar.CurrentInput.getMonth() - 1);
Gloo.Calendar.BuildMonth();
return false;
},
ShowNextMonth : function()
{
Gloo.Calendar.CurrentInput.setMonth(Gloo.Calendar.CurrentInput.getMonth() + 1);
Gloo.Calendar.BuildMonth();
return false;
},
ShowNextYear : function()
{
Gloo.Calendar.CurrentInput.setFullYear(Gloo.Calendar.CurrentInput.getFullYear() + 1);
Gloo.Calendar.BuildMonth();
return false;
},

BuildMonth : function()
{
var SelectedDate = new Date("1 " + Gloo.Calendar.Months[Gloo.Calendar.CurrentInput.getMonth()] + " " + Gloo.Calendar.CurrentInput.getFullYear());
SelectedDate.setDate(SelectedDate.getDate() - ((SelectedDate.getDay() == 0) ? 7 : SelectedDate.getDay()));

var Html = "";

Html +=
"<tr>" +
"<th>M</th>" +
"<th>T</th>" +
"<th>W</th>" +
"<th>T</th>" +
"<th>F</th>" +
"<th>S</th>" +
"<th>S</th>" +
"</tr>";

for (var i = 0; i < 6; i++)
{
Html += "<tr>";

for (var j = 0; j < 7; j++)
{
SelectedDate.setDate(SelectedDate.getDate() + 1);

var ClassName = "";
if (SelectedDate.getMonth() != Gloo.Calendar.CurrentInput.getMonth() || SelectedDate.getYear() != Gloo.Calendar.CurrentInput.getYear()) ClassName += " Other";
if (SelectedDate.getDay() == 0 || SelectedDate.getDay() == 6) ClassName += " Weekend";

if (Gloo.Calendar.FormatDate(SelectedDate) == Gloo.Calendar.FormatDate(Gloo.Calendar.Highlighted) && !ClassName.match(/Other/gi)) ClassName += " Highlight"

var FullDate = Gloo.Calendar.FormatDate(SelectedDate);

Html +=
"<td class='" + ClassName + "'>" +
"<a href='#' title='" + FullDate + "' onclick=\"return Gloo.Calendar.SetDate('" + FullDate + "');\">" +
SelectedDate.getDate() +
"</a>" +
"</td>";
}

Html += "</tr>";
}

Html = "<table cellspacing='0'>" + Html + "</table>";

setHTML($("GlooCalendarTitle"), Gloo.Calendar.Months[Gloo.Calendar.CurrentInput.getMonth()] + " " + Gloo.Calendar.CurrentInput.getFullYear());

setHTML($("CalendarMonth"), Html);

var offset = (getScrollTop() == 0) ? getOffsetScrollTop(Gloo.Calendar.Input) : 0;

var top = getOffsetTop(Gloo.Calendar.Input) + getHeight(Gloo.Calendar.Input) - offset;
var bottom = top + getHeight(Gloo.Calendar.Element);
var bottomBounds = getScrollTop() + getDocumentHeight();
if (bottom > bottomBounds) top = getOffsetTop(Gloo.Calendar.Input) - getHeight(Gloo.Calendar.Element) - offset;

setWidth(Gloo.Calendar.Element, getWidth(Gloo.Calendar.Input));
setLeft(Gloo.Calendar.Element, getOffsetLeft(Gloo.Calendar.Input));
setTop(Gloo.Calendar.Element, top);

show(Gloo.Calendar.Element);
},

SetToday : function()
{
return Gloo.Calendar.SetDate(Gloo.Calendar.FormatDate(new Date()));
},

SetDate : function(Text)
{
Gloo.Calendar.Input.value = Text;

Gloo.Calendar.Hide();

return false;
},

ValidDate : function(Text)
{
return Text.match(/^[0-9]{1,2}\s(January|February|March|April|May|June|July|August|September|October|November|December)\s[0-9]{4}$/gi);
},

FormatDate : function(date)
{
return date.getDate() + " " + Gloo.Calendar.Months[date.getMonth()] + " " + date.getFullYear();
},

TimeInput : null,
UpdateTime : function(Input)
{
Gloo.Calendar.TimeInput = Input;

attachEventListener(Input, "keydown", Gloo.Calendar.UpdateTimeValue, false);
attachEventListener(Input, "keyup", Gloo.Calendar.UpdateTimeSelection, false);
attachEventListener(Input, "blur", Gloo.Calendar.RemoveUpdateTime, false);
},
RemoveUpdateTime : function(Event)
{
detachEventListener(Gloo.Calendar.TimeInput, "keydown", Gloo.Calendar.UpdateTimeValue, false);
detachEventListener(Gloo.Calendar.TimeInput, "keyup", Gloo.Calendar.UpdateTimeSelection, false);
detachEventListener(Gloo.Calendar.TimeInput, "blur", Gloo.Calendar.RemoveUpdateTime, false);

Gloo.Calendar.TimeInput = null;
},
UpdateTimeValue : function(Event)
{
var CurrentTime = Gloo.Calendar.GetCurrentTime();

var keyCode = getKeyCode(Event);
var Cursor = getSelectionStart(Gloo.Calendar.TimeInput);
var Select = 0;
if (Cursor < 3)
{
if (keyCode == 38) CurrentTime.Hour = ++CurrentTime.Hour > 12 ? 1 : CurrentTime.Hour;
if (keyCode == 40) CurrentTime.Hour = --CurrentTime.Hour < 1 ? 12 : CurrentTime.Hour;
}
else if (Cursor < 5)
{
Select = 3;
if (keyCode == 38) CurrentTime.Minute = ++CurrentTime.Minute > 59 ? 0 : CurrentTime.Minute;
if (keyCode == 40) CurrentTime.Minute = --CurrentTime.Minute < 0 ? 59 : CurrentTime.Minute;
}
else
{
Select = 6;
if (keyCode == 38 || keyCode == 40) CurrentTime.Period = CurrentTime.Period == "AM" ? "PM" : "AM";
}

Gloo.Calendar.UpdateTimeDisplay(CurrentTime, Select);
},
UpdateTimeSelection : function(Event)
{
var CurrentTime = Gloo.Calendar.GetCurrentTime();

var keyCode = getKeyCode(Event);
var Cursor = getSelectionStart(Gloo.Calendar.TimeInput);
var Select;
if (Cursor < 3)
{
Select = 0;
if (keyCode == 39) Select = 3;
if (keyCode >= 48 && keyCode <= 57)
{
if (Gloo.Calendar.RememberTime.Hour == 1) CurrentTime.Hour = parseInt("1" + CurrentTime.Hour.toString().substr(0,1));
Gloo.Calendar.RememberTime.Hour = keyCode - 48;
}
if (keyCode >= 96 && keyCode <= 105)
{
if (Gloo.Calendar.RememberTime.Hour == 1) CurrentTime.Hour = parseInt("1" + CurrentTime.Hour.toString().substr(0,1));
Gloo.Calendar.RememberTime.Hour = keyCode - 96;
}
}
else if (Cursor < 5)
{
Select = 3;
if (keyCode == 37) Select = 0;
if (keyCode >= 48 && keyCode <= 57)
{
if (Gloo.Calendar.RememberTime.Minute < 6) CurrentTime.Minute = parseInt(Gloo.Calendar.RememberTime.Minute + CurrentTime.Minute.toString().substr(0,1));
Gloo.Calendar.RememberTime.Minute = keyCode - 48;
}
if (keyCode >= 96 && keyCode <= 105)
{
if (Gloo.Calendar.RememberTime.Minute < 6) CurrentTime.Minute = parseInt(Gloo.Calendar.RememberTime.Minute + CurrentTime.Minute.toString().substr(0,1));
Gloo.Calendar.RememberTime.Minute = keyCode - 96;
}
}
else
{
Select = 6;
if (keyCode == 37) Select = 3;
}

Gloo.Calendar.UpdateTimeDisplay(CurrentTime, Select);
},
UpdateTimeDisplay : function(CurrentTime, Select)
{
if (CurrentTime.Minute < 10) CurrentTime.Minute = '0' + CurrentTime.Minute;
if (CurrentTime.Hour < 10) CurrentTime.Hour = '0' + CurrentTime.Hour;

Gloo.Calendar.TimeInput.value = CurrentTime.Hour + ":" + CurrentTime.Minute + " " + CurrentTime.Period;
setSelection(Gloo.Calendar.TimeInput, Select, Select + 2);
},
GetCurrentTime : function()
{
var Text = Gloo.Calendar.TimeInput.value;

var hour = 1;
try
{
hour = parseInt(Text.split(":")[0].replace(/^0/gi, ""));
hour = isNaN(hour) ? 1 : hour < 1 ? 1 : hour > 12 ? 12 : hour;
}
catch (e) { }

var minute = 0;
try
{
minute = parseInt(Text.split(":")[1].split(" ")[0].replace(/^0/gi, ""));
minute = isNaN(minute) ? 0 : minute < 0 ? 0 : minute > 59 ? 59 : minute;
}
catch (e) { }

var period = "PM";
try
{
period = Text.split(" ")[1];
if (period.match(/^a/gi)) period = "AM"; else period = "PM";
}
catch (e) { }

return { Hour: hour, Minute: minute, Period: period };
},
RememberTime : { Hour: 0, Minute: 0 }
};
/*******************/
/* Context menu */
Gloo.ContextMenu =
{
Highlighted : new Array(),

onHide : function(){},

Show : function(Event)
{
if (window.event) Event = window.event;

Gloo.ContextMenu.Hide();

if (!Event) return;

var MenuItems = "";
var El = getEventTarget(Event);
while (El.parentNode != null)
{
if (El.getAttribute("contextObj"))
{
var obj = eval(El.getAttribute("contextObj"));
if (obj.ContextMenuItems)
{
MenuItems += obj.ContextMenuItems();
if (obj.Highlight)
{
Gloo.ContextMenu.Highlighted.push(obj);
obj.Highlight();
}
break;
}
}
El = El.parentNode;
}

if (MenuItems == "") return true;

Gloo.ContextMenu.Attach(Event, MenuItems);
return false;
},

Hide : function(Event)
{
if (Event)
{
var El = getEventTarget(Event);
while (El.parentNode != null && El.id != "GlooContextMenu") El = El.parentNode;
if (El && El.id == "GlooContextMenu") return;
}

detachEventListener(document, "mouseup", Gloo.ContextMenu.Hide, true);

while (Gloo.ContextMenu.Highlighted.length > 0)
{
var obj = Gloo.ContextMenu.Highlighted.pop();
if (obj.Lowlight) obj.Lowlight();
}

if ($("GlooContextMenuOverlay")) $("GlooContextMenuOverlay").parentNode.removeChild($("GlooContextMenuOverlay"));
if ($("GlooContextMenu")) $("GlooContextMenu").parentNode.removeChild($("GlooContextMenu"));

Gloo.ContextMenu.onHide();
},

Attach : function(Event, Html)
{
var overlay = Gloo.Dialogue.CreateModalLayer(true);
overlay.id = "GlooContextMenuOverlay";

var menu = document.createElement("div");
menu.id = "GlooContextMenu";
menu.className = "ContextMenu";
setHTML(menu, "<ul>" + Html + "</ul>");
document.forms[0].appendChild(menu);
setZindex(menu, ++Gloo.Dialogue.zindex);

var NewX = getMouseX(Event);
if (NewX + getWidth(menu) > getDocumentWidth()) NewX = getMouseX(Event) - getWidth(menu);
var NewY = getMouseY(Event);
if (NewY + getHeight(menu) > getDocumentHeight()) NewY = getMouseY(Event) - getHeight(menu);
setLeft(menu, NewX);
setTop(menu, NewY);

show(menu);

attachEventListener(document, "mouseup", Gloo.ContextMenu.Hide, true);

return false;
}
};
document.oncontextmenu = Gloo.ContextMenu.Show;
/*******************/
/* Dialogue */
Gloo.Dialogue =
{
zindex : 999999,

Show : function(Title, Content, Iframe, Modal, Width, Height)
{
if (Modal) Gloo.Dialogue.CreateModalLayer();

var Dialogue = document.createElement("div");
var TitleBar = document.createElement("h2");
var TitleText = document.createTextNode(Title);
var Anchor = document.createElement("a");

var ContentBar;
var FrameName = "iframe" + Gloo.Dialogue.zindex;
if (Iframe)
{
try
{
var IframeHtml =
"<iframe " +
"id='" + FrameName + "' " +
"name='" + FrameName + "' " +
"width='" + Width + "' " +
"height='" + Height + "' " +
"frameborder='no' " +
"src='" + Content + "' >";
ContentBar = document.createElement(IframeHtml);
}
catch (e)
{
ContentBar = document.createElement("iframe");
ContentBar.setAttribute("id", FrameName);
ContentBar.setAttribute("name", FrameName);
ContentBar.setAttribute("width", Width);
ContentBar.setAttribute("height", Height);
ContentBar.setAttribute("frameborder", "no");
ContentBar.src = Content;
}

setWidth(Dialogue, Width);
setHeight(Dialogue, "auto");
}
else
{
if (Width) setWidth(Dialogue, Width);
if (Height) setHeight(Dialogue, Height);
ContentBar = document.createElement("div");
setHTML(ContentBar, Content);
}

Dialogue.className = "Dialogue";
TitleBar.onmousedown = function(Event)
{
var t = getEventTarget(Event);
if (t.nodeName == "A") return;
Gloo.Drag.StartDrag(Event, Dialogue);
if (Iframe)
{
Gloo.Dialogue.IframeDragOverlay = Gloo.Dialogue.CreateModalLayer(true);
Gloo.Drag.onDragComplete = Gloo.Dialogue.IframeDragComplete;
}

};
Anchor.onclick = Gloo.Dialogue.Close;

TitleBar.appendChild(Anchor);
TitleBar.appendChild(TitleText);
Dialogue.appendChild(TitleBar);
Dialogue.appendChild(ContentBar);
document.forms[0].appendChild(Dialogue);

setTop(Dialogue, (getDocumentHeight() / 2) - (getHeight(Dialogue) / 2) + getScrollTop());
setLeft(Dialogue, (getDocumentWidth() / 2) - (getWidth(Dialogue) / 2) + getScrollLeft());
setZindex(Dialogue, ++Gloo.Dialogue.zindex);

show(Dialogue);
hideSelectBoxes();

if (Iframe)
{
var iframe = Dialogue.getElementsByTagName("iframe")[0];
var frame = document.all ? UploadFrame = document.frames[FrameName] : document.getElementById(FrameName).contentWindow;
var win = frame.window;
win.Dialogue = Dialogue;
top["Dialogue_" + FrameName] = Dialogue;
}

return Dialogue;
},

CreateModalLayer : function(Invisible)
{
var Overlay = document.createElement("div");
Overlay.className = "ModalOverlay";
if (Invisible)
{
Overlay.style.filter = "alpha(opacity=0)";
Overlay.style.opacity = "0";
}
document.forms[0].appendChild(Overlay);
setZindex(Overlay, ++Gloo.Dialogue.zindex);
setTop(Overlay, getScrollTop());
setLeft(Overlay, getScrollLeft());
setHeight(Overlay, getPageHeight());
return Overlay;
},

Iframe : function(Title, Url, Modal, Width, Height)
{
return Gloo.Dialogue.Show(Title, Url, true, Modal, Width, Height);
},
IframeDragComplete : function()
{
Gloo.Dialogue.IframeDragOverlay.parentNode.removeChild(Gloo.Dialogue.IframeDragOverlay);
},

Alert : function(Title, Message)
{
var Html =
"<div class=\"Content\">" + Message + "</div>" +
"<div class=\"Buttons\">" +
"   <table cellspacing=\"0\" align=\"center\">" +
"      <tr>" +
"          <td><a href=\"#\" onclick=\"return Gloo.Dialogue.Close(event);\" class=\"Button\">Ok</a></td>" +
"      </tr>" +
"   </table>" +
"</div>";

Gloo.Dialogue.Show(Title, Html, false, true);

return false;
},

Confirm : function(Title, Message, Anchor)
{
var OkFunction = Anchor.href.replace(/javascript\:/gi, "");

return Gloo.Dialogue.ConfirmOk(Title, Message, OkFunction);
},
ConfirmOk : function(Title, Message, OkFunction)
{
var Html =
"<div class=\"Content\">" + Message + "</div>" +
"<div class=\"Buttons\">" +
"   <table cellspacing=\"0\" align=\"center\">" +
"       <tr>" +
"           <td>" +
"           <a href=\"#\" onclick=\"Gloo.Dialogue.Close(event);" + OkFunction + ";\" class=\"Button\">Yes</a>" +
"           <a href=\"#\" onclick=\"return Gloo.Dialogue.Close(event);\" class=\"Button\">No</a>" +
"           </td>" +
"       </tr>" +
"   </table>" +
"</div>";

var El = Gloo.Dialogue.Show(Title, Html, false, true);

document.onkeypress = function(event)
{
var c = getKeyCode(event);
switch (getKeyCode(event))
{
case 89, 121:
{
document.onkeypress = null;
Gloo.Dialogue.Remove(El);
eval(OkFunction);
break;
}

case 27, 78, 110:
{
document.onkeypress = null;
Gloo.Dialogue.Remove(El);
break;
}
}
};

return false;
},

Close : function(Event)
{
document.onkeypress = null;
return Gloo.Dialogue.Remove(getEventTarget(Event));
},

Remove : function (Element)
{
if(!Element || !Element.parentNode) return;

while(!Element.className.match(/Dialogue$/gi) && Element.parentNode != null) Element = Element.parentNode;
if (Element.className.match(/Dialogue$/gi))
{
if (Element.previousSibling && Element.previousSibling.className == "ModalOverlay") Element.previousSibling.parentNode.removeChild(Element.previousSibling);
Element.parentNode.removeChild(Element);
}
showSelectBoxes();

return false;
},

/********
Utils for dialogue page content
********/
Window:
{
FocusFirstInput: true,

Init : function()
{
Gloo.Form.Placeholder = "_ContentPane_";

if (getPageHeight() + 20 > getDocumentHeight())
{
var h = getDocumentHeight() - getHeight($("StatusBar")) - 20;
if (h > 0) setHeight($("PaneScroller"), h);
}

if (Gloo.Dialogue.Window.FocusFirstInput)
{
var inputs = document.getElementsByTagName("input");
for (var i = 0; i < inputs.length; i++)
{
if (inputs[i].type == "text" && !inputs[i].disabled)
{
inputs[i].focus();
break;
}
}
}
},

Close: function()
{
var iframe = top.document.getElementById(window.name);
var iframe = top["Dialogue_" + window.name];
top.Gloo.Dialogue.Remove(iframe);
return false;
}
}
};
/*******************/
/* Drag handler */
Gloo.Drag =
{
Element : null,

onDrag : function(){},
onDragComplete : function(){},

StartDrag : function(Event, DragDiv)
{
Event = !Event ? window.event : Event;

cancelEventBubble(Event);

Gloo.Drag.Element = !DragDiv ? this : DragDiv;

Gloo.Drag.Element.Mouse = { x: Event.clientX, y: Event.clientY };

document.onmousemove = Gloo.Drag.Drag;
document.onmouseup = Gloo.Drag.StopDrag;

return false;
},

Drag : function(Event)
{
Event = !Event ? window.event : Event;

setLeft(Gloo.Drag.Element, getLeft(Gloo.Drag.Element) + Event.clientX - Gloo.Drag.Element.Mouse.x);
setTop(Gloo.Drag.Element, getTop(Gloo.Drag.Element) + Event.clientY - Gloo.Drag.Element.Mouse.y);

Gloo.Drag.Element.Mouse = { x: Event.clientX, y: Event.clientY };

Gloo.Drag.onDrag(Gloo.Drag.Element, Event);

return false;
},

StopDrag : function(Event)
{
Event = !Event ? window.event : Event;

Gloo.Drag.onDragComplete(Gloo.Drag.Element, Event);

Gloo.Drag.onDrag = function(){};
Gloo.Drag.onDragComplete = function(){};
Gloo.Drag.Element = null;
document.onmousemove = null;
document.onmouseup = null;
}
};
/*******************/
/* Form */
Gloo.Form =
{
Placeholder : "_RightPaneContent_",
ShowErrorSpans : false,

SetEventTarget : function(Button)
{
if (!document.forms[0]["__EVENTTARGET"])
{
var Element = document.createElement("input");
Element.type = "hidden";
Element.name = "__EVENTTARGET";
document.forms[0].appendChild(Element);
}
document.forms[0]["__EVENTTARGET"].value = Button.replace(/_/gi, ":").replace(/^:/gi, "_");
},

ClearErrors : function()
{
var form = document.forms[0];
for(var i = 0; i < form.length; i++)
{
form[i].className = form[i].className.replace(/Error/gi, "");
}
var frames = document.getElementsByTagName("iframe");
for(var i = 0; i < frames.length; i++)
{
frames[i].className = frames[i].className.replace(/Error/gi, "");
}

var spans = document.getElementsByTagName("span");
for (var i = 0; i <  spans.length; i++)
{
if (spans[i].getAttribute("controltovalidate")) hide(spans[i]);
}
},

ShowErrors : function()
{
var form = document.forms[0];
for (var i = 0; i < form.length; i++)
{
if (form[i].className.match(/Error/gi))
{
var Div = form[i].parentNode.parentNode;
Div.className = Div.className.replace(/Collapsed/gi, "");
}
}

if ($("RightPaneScroller")) $("RightPaneScroller").parentNode.scrollTop = 0;

top.Gloo.Dialogue.Alert("Error", "The form is not complete.  Please check the highlighted fields.");

return false;
},

isValid : function(fieldName, expression)
{
var field = Gloo.Form.GetField(fieldName);
if (field.value.match(expression)) return true;
else
{
Gloo.Form.SetError(field);
return false;
}
},

isEmpty : function(fieldName)
{
return !Gloo.Form.isValid(fieldName, /[^\s]+/gi);
},

isFckEmpty : function(fieldName)
{
var Valid = Gloo.Form.GetFckEditor(fieldName).GetXHTML().match(/[^\s]+/gi) != null;
if (!Valid) $(Gloo.Form.GetField(fieldName).id + "___Frame").className += " Error";
return !Valid;
},

isNumber : function(fieldName)
{
return Gloo.Form.isValid(fieldName, /^[0-9]+[.]{0,1}[0-9]*$/gi);
},

isDate : function(fieldName)
{
return Gloo.Form.isValid(fieldName, /^[0-9]{1,2}\s(January|February|March|April|May|June|July|August|September|October|November|December)\s[0-9]{4}$/gi)
},

isTime : function(fieldName)
{
return Gloo.Form.isValid(fieldName, /^[0-1][0-9]:[0-5][0-9]\s(AM|PM)$/gi)
},

isEmail : function(fieldName)
{
return Gloo.Form.isValid(fieldName, /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3} \.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/gi)
},

isExtension : function(fieldName, extensions)
{
return Gloo.Form.isValid(fieldName, new RegExp(".(" + extensions + ")$", "gi"))
},

GetField : function (fieldName)
{
var form = document.forms[0];
if (form[fieldName]) return form[fieldName];
return form[Gloo.Form.GetPrefix() + fieldName];
},
GetFckEditor : function (fieldName)
{
return FCKeditorAPI.GetInstance(Gloo.Form.GetField(fieldName).id);
},

SetError : function(field)
{
field.className += " Error";
field.onfocus = Gloo.Form.ClearError;

if (Gloo.Form.ShowErrorSpans)
{
var spans = document.getElementsByTagName("span");
for (var i = 0; i <  spans.length; i++)
{
if (spans[i].getAttribute("controltovalidate") == field.id) show(spans[i]);
}
}
},

ClearError : function(e)
{
var el = getEventTarget(e);
el.className = el.className.replace(/Error/gi, "");
el.onfocus = null;
},

SetPrefix : function(prefix)
{
document.FormFieldPrefix = prefix;
},
GetPrefix : function()
{
var form = document.forms[0];
if (document.FormFieldPrefix == null)
{
for (var i = 0; i < form.length; i++)
{
var exp = new RegExp(Gloo.Form.Placeholder, "gi");
if (form[i].id.match(exp))
{
document.FormFieldPrefix = form[i].id.substr(0, form[i].id.lastIndexOf(Gloo.Form.Placeholder)) + Gloo.Form.Placeholder;
break;
}
}
}
return document.FormFieldPrefix;
},

SubmitOnEnter: function(Event, Button)
{
if (isEnterKey(Event))
{
$(Button).click();
return false;
}
},

InitThumb: function()
{
if (Gloo.Form.isEmpty("ThumbnailPath"))
{
hide($("CurrentThumb"));
show($("UploadThumb"));
}
else
{
show($("CurrentThumb"));
hide($("UploadThumb"));
}
},
DeleteThumb: function()
{
Gloo.Form.GetField("ThumbnailPath").value = "";
Gloo.Form.InitThumb();
}
};
/*******************/
/* Photo gallery */
Gloo.Gallery =
{
Mode: "ResizeToFit",
Files: null,
Index: null,
Elements: { Div: null, Crop: null, Img: null, Title: null, Previous: null, Next: null, Mode: null, Close: null },

Launch: function(Files, Index)
{
for(var i = 0; i < Files.length; i++)
{
if (Files[i].Width == 0 || Files[i].Height == 0 || Files[i].Deleted)
{
Files.splice(i, 1);
i--;
}
}

Gloo.Gallery.Mode = "ResizeToFit";
Gloo.Gallery.Files = Files;
Gloo.Gallery.Index = Index;

Gloo.Dialogue.CreateModalLayer();

var Html =
"<table cellspacing='0'>" +
"<tr>" +
"<th colspan='2'><div><img src='' /></div></th>" +
"</tr>" +
"<tr>" +
"<td></td>" +
"<td>" +
"<table cellspacing='0' align='right'><tr>" +
"<td><a href='#' onclick='return Gloo.Gallery.Previous();' class='Previous' title='Previous picture'></a></td>" +
"<td><a href='#' onclick='return Gloo.Gallery.Next();' class='Next' title='Next picture'></a></td>" +
"<td><a href='#' onclick='return Gloo.Gallery.ToggleMode();' class='ActualSize' title='Actual size'></a></td>" +
"<td><a href='#' onclick='return Gloo.Gallery.Close();' class='Close' title='Close'></a></td>" +
"</tr></table>" +
"</td>" +
"</tr>" +
"</table>";

var div = document.createElement("div");
div.className = "ImageDialogue";
document.forms[0].appendChild(div);
setHTML(div, Html);
setZindex(div, ++Gloo.Dialogue.zindex);

Gloo.Gallery.Elements.Div = div;
Gloo.Gallery.Elements.Crop = div.getElementsByTagName("div")[0];
Gloo.Gallery.Elements.Img = div.getElementsByTagName("img")[0];
Gloo.Gallery.Elements.Title = div.getElementsByTagName("td")[0];
Gloo.Gallery.Elements.Previous = div.getElementsByTagName("a")[0];
Gloo.Gallery.Elements.Next = div.getElementsByTagName("a")[1];
Gloo.Gallery.Elements.Mode = div.getElementsByTagName("a")[2];
Gloo.Gallery.Elements.Close = div.getElementsByTagName("a")[3];

if (Files.length == 1)
{
hide(Gloo.Gallery.Elements.Previous);
hide(Gloo.Gallery.Elements.Next);
}

attachEventListener(window, "resize", Gloo.Gallery.Resize, true);

Gloo.Gallery.Load();

return false;
},

Load: function()
{
var file = Gloo.Gallery.Files[Gloo.Gallery.Index];

Gloo.Gallery.Elements.Img.parentNode.removeChild(Gloo.Gallery.Elements.Img);

if (file.Type.match(/Video/gi))
{
Gloo.Gallery.Elements.Img = document.createElement("div");
Gloo.Gallery.Elements.Crop.appendChild(Gloo.Gallery.Elements.Img);
Gloo.Gallery.Elements.Img .setAttribute("style", "overflow:hidden");

var inner = document.createElement("div");
inner.id = 'swfer';
Gloo.Gallery.Elements.Img.appendChild(inner);

file.Height = 380;

swfobject.embedSWF(file.EmbedPath, 'swfer', 480, 380, '8.0.0', null, null);
}
else
{
Gloo.Gallery.Elements.Img = document.createElement("img");
Gloo.Gallery.Elements.Crop.appendChild(Gloo.Gallery.Elements.Img);

Gloo.Gallery.Elements.Img.src = addQsVar(file.FilePath, "r=" + (Math.random() * 9999));
setHTML(Gloo.Gallery.Elements.Title, file.Title);
}

Gloo.Gallery.Resize();
},

Previous: function()
{
Gloo.Gallery.Index--;
if (Gloo.Gallery.Index < 0) Gloo.Gallery.Index = Gloo.Gallery.Files.length - 1;
Gloo.Gallery.Load();

return false;
},
Next: function()
{
Gloo.Gallery.Index++;
if (Gloo.Gallery.Index > Gloo.Gallery.Files.length - 1) Gloo.Gallery.Index = 0;
Gloo.Gallery.Load();

return false;
},

ToggleMode: function()
{
var Anchor = Gloo.Gallery.Elements.Mode;

Anchor.className = Gloo.Gallery.Mode;
if (Gloo.Gallery.Mode == "ActualSize")
{
Anchor.title = "Actual size";
Gloo.Gallery.Mode = "ResizeToFit";
}
else
{
Anchor.title = "Resize to fit";
Gloo.Gallery.Mode = "ActualSize";
}

Gloo.Gallery.Resize();

return false;
},

Close: function()
{
Gloo.Dialogue.Remove(Gloo.Gallery.Elements.Div);

detachEventListener(window, "resize", Gloo.Gallery.Resize, true);

return false;
},

Resize : function()
{
if (!Gloo.Gallery.Elements.Div) return;

var bounds = {
width: getDocumentWidth() - 20 > 400 ? getDocumentWidth() - 20 : 400,
height: getDocumentHeight() - 20 > 300 ? getDocumentHeight() - 20 : 300 };

var div = Gloo.Gallery.Elements.Div;
var crop = Gloo.Gallery.Elements.Crop;
var img = Gloo.Gallery.Elements.Img;
var file = Gloo.Gallery.Files[Gloo.Gallery.Index];

setWidth(img, file.Width);
setHeight(img, file.Height);
setWidth(crop, "auto");
setHeight(crop, "auto");

var ratio = file.Width / file.Height;
var toolbarHeight = getHeight(div) - file.Height;

switch(Gloo.Gallery.Mode)
{
case "ActualSize":
{
setHeight(crop, file.Height);
setWidth(crop, file.Width);

if (getHeight(div) > bounds.height)
{
var newHeight = bounds.height - toolbarHeight;
setHeight(crop, newHeight);

var newWidth = file.Width + getScrollerWidth();
if (newWidth < bounds.width) setWidth(crop, newWidth);
}

if (getWidth(div) > bounds.width)
{
var newWidth = bounds.width;
setWidth(crop, newWidth);

var newHeight = file.Height + getScrollerWidth();
if (newHeight < bounds.height) setHeight(crop, newHeight);
}

break;
}
case "ResizeToFit":
{
if (getHeight(div) > bounds.height)
{
var newHeight = bounds.height - toolbarHeight;
var newWidth = Math.round(newHeight * ratio);
setHeight(img, newHeight);
setWidth(img, newWidth);
}

if (getWidth(div) > bounds.width)
{
var newWidth = bounds.width;
var newHeight = Math.round(newWidth / ratio);
setHeight(img, newHeight);
setWidth(img, newWidth);
}

break;
}
}

if (getDocumentHeight() > 0)
{
setTop(div, getScrollTop() + (getDocumentHeight() / 2) - (getHeight(div) / 2));
setLeft(div, getScrollLeft() + (getDocumentWidth() / 2) - (getWidth(div) / 2));
}

show(div);
}
};
/*******************/
/* Multi-level menu */
Gloo.MultiMenu =
{
Counter: 0,
MenuItems: new Array(),
FirstRun: true,

Init: function(MenuElementId)
{
this.Root = $(MenuElementId);

this.SetupMenuItems(this.Root, null);

if (this.FirstRun)
{
attachEventListener(window, "unload", GlooUnloadMultiMenu, true);
this.FirstRun = false;
}
},

SetupMenuItems: function(ParentElement, ParentMenuItem)
{
for (var i = 0; i < ParentElement.childNodes.length; i++)
{
var node = ParentElement.childNodes[i];
if (node.nodeName == "LI")
{
var menuItem = new GlooMultiMenuItem(ParentElement.childNodes[i], ParentMenuItem);

if (menuItem.HasChildren())
{
menuItem.AnchorElement().className += " Branch";
this.SetupMenuItems(menuItem.SubmenuElement(), menuItem);
}

this.MenuItems.push(menuItem);
}
}
}
};
function GlooMultiMenuItem(ListItem, ParentItem)
{
this.Self = "MultiMenuItem" + (Gloo.MultiMenu.Counter++);
eval(this.Self + "=this");

this.Parent = ParentItem;
this.HasChildren = function()
{
return this.LinkElement.getElementsByTagName("ul").length > 0;
};

this.LinkElement = ListItem;
this.SubmenuElement = function()
{
if (this.HasChildren()) return this.LinkElement.getElementsByTagName("ul")[0];
else return null;
};
this.AnchorElement = function()
{
return this.LinkElement.getElementsByTagName("a")[0];
};

var item = this;
this.AnchorElement().onmouseover = function(){ item.ShowSubmenu(); };
this.AnchorElement().onmouseout = function(){ item.HideSubmenu(); };

this.ShowSubmenu = function()
{
hideSelectBoxes();

if (this.Parent != null) this.Parent.ShowSubmenu();

clearTimeout(this.Hiding);
if (this.HasChildren()) show(this.SubmenuElement());
if (!this.AnchorElement().className.match(/Selected/))
{
if (this.HasChildren()) this.AnchorElement().className += " BranchSelected";
this.AnchorElement().className += " Selected";
}
};

this.HideSubmenu = function(Paused)
{
clearTimeout(this.Hiding);
if (!Paused)
{
showSelectBoxes();

this.Hiding = setTimeout(this.Self + ".HideSubmenu(true);", 50);

if (this.Parent != null) this.Parent.HideSubmenu();

return;
}

if (this.HasChildren()) hide(this.SubmenuElement());
this.AnchorElement().className = this.AnchorElement().className.replace(/(Branch)?Selected/gi, "");


};
}
function GlooUnloadMultiMenu()
{
for(var i = 0; i < Gloo.MultiMenu.MenuItems.length; i++)
{
var item = Gloo.MultiMenu.MenuItems[i];
item.AnchorElement().onmouseover = null;
item.AnchorElement().onmouseout = null;
delete item;
}
}
/* Page scroller */
Gloo.PageScroller =
{
Interval: null,
CurrentValue: null,
StartValue: null,
EndValue: null,
CurrentTime: null,

ScrollTo: function(Ypos)
{
this.StartValue = getScrollTop();
this.CurrentValue = this.StartValue;
this.EndValue = Ypos;
this.CurrentTime = 0;
this.Duration = 50;

clearInterval(this.Interval);
this.Interval = setInterval('Gloo.PageScroller.Scroll();', 25);
},

Scroll: function(Ypos)
{
this.CurrentValue = Math.round(strongEaseInOut(this.CurrentTime++, this.CurrentValue, (this.EndValue - this.CurrentValue), this.Duration));

window.scrollTo(0, this.CurrentValue);

if (this.CurrentTime > this.Duration || this.CurrentValue == this.EndValue) clearInterval(this.Interval);
}

};
/* Row re-order drag handler */
var ReorderHandler =
{
DropTarget : null,
SwapDirection : null,
CallbackScript : null,
Element : null,
onDrop : function(){},
DragElement: null,

Init : function(CallbackScript)
{
ReorderHandler.CallbackScript = CallbackScript;

var Rows = document.getElementsByTagName("tr");
for (var i = 0; i < Rows.length; i++)
{
if (Rows[i].getAttribute("dragid")) Rows[i].getElementsByTagName("a")[0].onmousedown = ReorderHandler.StartDrag;
}
},
Refresh : function()
{
var Rows = document.getElementsByTagName("tr");
for (var i = 0; i < Rows.length; i++)
{
if (Rows[i].getAttribute("dragid") && Rows[i].getElementsByTagName("a")[0].onmousedown == null) Rows[i].getElementsByTagName("a")[0].onmousedown = ReorderHandler.StartDrag;
}
},

StartDrag : function (Event)
{
cancelEventBubble(Event);

var _element = this;
while(_element.nodeName != "TR" && _element.parentNode) _element = _element.parentNode;
if (_element.nodeName != "TR") return;

_element.className += "Drag";

ReorderHandler.Element = _element;
document.onmousemove = ReorderHandler.Drag;
document.onmouseup = ReorderHandler.EndDrag;
},

Drag : function (Event)
{
var Table = ReorderHandler.Element.parentNode;
var Rows = Table.getElementsByTagName("tr");
var MouseY = getMouse(Event).y;
for (var i = 0; i < Rows.length; i++)
{
var CurrentTop = getOffsetTop(ReorderHandler.Element) - document.body.scrollTop;
var Top = getOffsetTop(Rows[i]) - document.body.scrollTop;
var Bottom = Top + getHeight(Rows[i]);
if (MouseY > Top && MouseY < Bottom && Rows[i].getAttribute && Rows[i].getAttribute("dragid") && Rows[i].getAttribute("dragid") != ReorderHandler.Element.getAttribute("dragid"))
{
if (CurrentTop < Top)
{
ReorderHandler.DropTarget = Rows[i];
ReorderHandler.SwapDirection = "After";
ReorderHandler.Element.parentNode.insertBefore(Rows[i], ReorderHandler.Element);
}
else
{
ReorderHandler.DropTarget = Rows[i];
ReorderHandler.SwapDirection = "Before";
Rows[i].parentNode.insertBefore(ReorderHandler.Element, Rows[i]);
}
i = Rows.length;
}
}

return false;
},

EndDrag : function (Event)
{
ReorderHandler.Element.className = ReorderHandler.Element.className.replace(/Drag/gi, "");

if (ReorderHandler.DropTarget)
{
var DraggingId = ReorderHandler.Element.getAttribute("dragid");
var ReferenceId = ReorderHandler.DropTarget.getAttribute("dragid");
var Direction = ReorderHandler.SwapDirection;

if (ReorderHandler.CallbackScript != "" && ReorderHandler.CallbackScript != null)
{
var PostData = "<request id=\"" + DraggingId + "\" referenceid=\"" + ReferenceId + "\" direction=\"" + Direction + "\"  />";
makeHttpRequest(ReorderHandler.CallbackScript, "POST", PostData, "ReorderHandler.RowSaveComplete", "ReorderHandler.RowSaveError");
}

ReorderHandler.onDrop(DraggingId, ReferenceId, Direction);
}

ReorderHandler.DropTarget = null;
ReorderHandler.SwapDirection = null;
ReorderHandler.Element = null;
document.onmousemove = null;
document.onmouseup = null;
},

RowSaveComplete : function(Request)
{
if (Request.responseText != "")
{
var Result = Request.responseXML;
if (Result.documentElement.nodeName == "error")
{
Gloo.Dialogue.Alert("Error", Result.documentElement.getAttribute("message"));
}
else
{
Gloo.ShowStatus("Order updated.");
}
}
},

RowSaveError : function()
{
Gloo.Dialogue.Alert("Error", "Unable to update order");
}
};
/*******************/
/*
<?xml version="1.0"?>
<suggestions>
<suggestion>
<display><![CDATA[Bradley Searle<br /><span>brad@c2.net.au</span>]]></display>
<text>Bradley Searle</text>
<value>1</value>
</suggestion>
</suggestions>
*/
Gloo.Form.Suggestions =
{
Input: null,
ValueInput: null,
CurrentRequest: null,
CurrentIndex: null,
Options: null,
onSelect: function(){},

Init: function(Input, Script, ValueInput)
{
Gloo.Form.Suggestions.Input = Input;
Gloo.Form.Suggestions.ValueInput = $(ValueInput);
Gloo.Form.Suggestions.CurrentIndex = -1;
Gloo.Form.Suggestions.Options = new Array();

Input.setAttribute("autocomplete", "off");

Input.onkeyup = function(Event)
{
switch (getKeyCode(Event))
{
case 27: case 37: case 39: { return false; }
case 40:
{
Gloo.Form.Suggestions.CurrentIndex++;
if (Gloo.Form.Suggestions.CurrentIndex >= Gloo.Form.Suggestions.Options.length)
{
Gloo.Form.Suggestions.CurrentIndex = 0;
}

Gloo.Form.Suggestions.Highlight(Gloo.Form.Suggestions.CurrentIndex);

return false;
}
case 38:
{
Gloo.Form.Suggestions.CurrentIndex--;
if (Gloo.Form.Suggestions.CurrentIndex < 0)
{
Gloo.Form.Suggestions.CurrentIndex = Gloo.Form.Suggestions.Options.length - 1;
}

Gloo.Form.Suggestions.Highlight(Gloo.Form.Suggestions.CurrentIndex);

return false;
}
case 13:
{
Gloo.Form.Suggestions.Select(Gloo.Form.Suggestions.CurrentIndex);

return false;
}
}

if (!$("Suggestions"))
{
var Div = document.createElement("div");
Div.id = "Suggestions";
document.body.appendChild(Div);
var List = document.createElement("ul");
Div.appendChild(List);
var Loader = document.createElement("li");
Loader.className = "Loading";
Loader.innerHTML = "Loading...";
List.appendChild(Loader);

setTop(Div, getOffsetTop(Input) + getHeight(Input));
setLeft(Div, getOffsetLeft(Input));
setWidth(Div, getWidth(Input));
show(Div);
}

if (Script == null || Script == undefined) Script = "Suggestions.aspx";
if (Gloo.Form.Suggestions.CurrentRequest) Gloo.Form.Suggestions.CurrentRequest.abort();
Gloo.Form.Suggestions.CurrentRequest = makeHttpRequest(addQsVar(Script, "Text=" + escape(Input.value)), "GET", "", "Gloo.Form.Suggestions.Show", "Gloo.Form.Suggestions.LoadError");
};
Input.onblur = function()
{
Gloo.Form.Suggestions.Input.onkeyup = null;
Gloo.Form.Suggestions.Input.onblur = null;

setTimeout("Gloo.Form.Suggestions.Hide();", 250);
};
},

Hide: function()
{
if ($("Suggestions")) $("Suggestions").parentNode.removeChild($("Suggestions"));
},

Highlight: function(Index)
{
if (!$("Suggestions")) return;

var List = $("Suggestions").getElementsByTagName("ul")[0];
for (var i = 0; i < List.childNodes.length; i++)
{
if (i == Index)
{
List.childNodes[i].className += " Selected";

var height = getHeight( $("Suggestions") );
var scrolltop = getOffsetScrollTop( $("Suggestions") );
var top = getTop(List.childNodes[i]) - scrolltop + getHeight(List.childNodes[i]);
if (top < 0 || top > height) $("Suggestions").scrollTop = top;
}
else
{
List.childNodes[i].className = List.childNodes[i].className.replace(/Selected/gi, "");
}
}
},

Select: function(Index)
{
var Input = Gloo.Form.Suggestions.Input;
var ValueInput = Gloo.Form.Suggestions.ValueInput;
var Item = Gloo.Form.Suggestions.Options[Index];

Input.value = Item.Text;
if (ValueInput) ValueInput.value = Item.Value;

if ($("Suggestions")) $("Suggestions").parentNode.removeChild($("Suggestions"));

Gloo.Form.Suggestions.onSelect(Item);

return false;
},

LoadError: function(Request)
{
},

Show: function(Request)
{
Gloo.Form.Suggestions.Options = new Array();
Gloo.Form.Suggestions.CurrentIndex = -1;

var Xml = Request.responseXML;

var Div = $("Suggestions");
var List = Div.getElementsByTagName("ul")[0];
while(List.childNodes.length > 0) List.removeChild(List.childNodes[0]);

var Nodes = Xml.documentElement.getElementsByTagName("suggestion");
for (var i = 0; i < Nodes.length; i++)
{
var Node = Nodes[i];
var Display = Node.getElementsByTagName("display")[0].firstChild.nodeValue;
var Text = Node.getElementsByTagName("text")[0].firstChild.nodeValue;
var Value = Node.getElementsByTagName("value")[0].firstChild.nodeValue;

Gloo.Form.Suggestions.Options.push({ Display: Display, Text: Text, Value: Value });

var Item = document.createElement("li");

var Html = "<a href='#' onclick='return Gloo.Form.Suggestions.Select(" + i + ");'>" + Display + "</a>";
setHTML(Item, Html);

List.appendChild(Item);
}
}
};
/*	SWFObject v2.0 <http://code.google.com/p/swfobject/>
Copyright (c) 2007 Geoff Stearns, Michael Williams, and Bobby van der Sluis
This software is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
*/
var swfobject=function(){var Z="undefined",P="object",B="Shockwave Flash",h="ShockwaveFlash.ShockwaveFlash",W="application/x-shockwave-flash",K="SWFObjectExprInst",G=window,g=document,N=navigator,f=[],H=[],Q=null,L=null,T=null,S=false,C=false;var a=function(){var l=typeof g.getElementById!=Z&&typeof g.getElementsByTagName!=Z&&typeof g.createElement!=Z&&typeof g.appendChild!=Z&&typeof g.replaceChild!=Z&&typeof g.removeChild!=Z&&typeof g.cloneNode!=Z,t=[0,0,0],n=null;if(typeof N.plugins!=Z&&typeof N.plugins[B]==P){n=N.plugins[B].description;if(n){n=n.replace(/^.*\s+(\S+\s+\S+$)/,"$1");t[0]=parseInt(n.replace(/^(.*)\..*$/,"$1"),10);t[1]=parseInt(n.replace(/^.*\.(.*)\s.*$/,"$1"),10);t[2]=/r/.test(n)?parseInt(n.replace(/^.*r(.*)$/,"$1"),10):0}}else{if(typeof G.ActiveXObject!=Z){var o=null,s=false;try{o=new ActiveXObject(h+".7")}catch(k){try{o=new ActiveXObject(h+".6");t=[6,0,21];o.AllowScriptAccess="always"}catch(k){if(t[0]==6){s=true}}if(!s){try{o=new ActiveXObject(h)}catch(k){}}}if(!s&&o){try{n=o.GetVariable("$version");if(n){n=n.split(" ")[1].split(",");t=[parseInt(n[0],10),parseInt(n[1],10),parseInt(n[2],10)]}}catch(k){}}}}var v=N.userAgent.toLowerCase(),j=N.platform.toLowerCase(),r=/webkit/.test(v)?parseFloat(v.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,i=false,q=j?/win/.test(j):/win/.test(v),m=j?/mac/.test(j):/mac/.test(v);/*@cc_on i=true;@if(@_win32)q=true;@elif(@_mac)m=true;@end@*/return{w3cdom:l,pv:t,webkit:r,ie:i,win:q,mac:m}}();var e=function(){if(!a.w3cdom){return }J(I);if(a.ie&&a.win){try{g.write("<script id=__ie_ondomload defer=true src=//:><\/script>");var i=c("__ie_ondomload");if(i){i.onreadystatechange=function(){if(this.readyState=="complete"){this.parentNode.removeChild(this);V()}}}}catch(j){}}if(a.webkit&&typeof g.readyState!=Z){Q=setInterval(function(){if(/loaded|complete/.test(g.readyState)){V()}},10)}if(typeof g.addEventListener!=Z){g.addEventListener("DOMContentLoaded",V,null)}M(V)}();function V(){if(S){return }if(a.ie&&a.win){var m=Y("span");try{var l=g.getElementsByTagName("body")[0].appendChild(m);l.parentNode.removeChild(l)}catch(n){return }}S=true;if(Q){clearInterval(Q);Q=null}var j=f.length;for(var k=0;k<j;k++){f[k]()}}function J(i){if(S){i()}else{f[f.length]=i}}function M(j){if(typeof G.addEventListener!=Z){G.addEventListener("load",j,false)}else{if(typeof g.addEventListener!=Z){g.addEventListener("load",j,false)}else{if(typeof G.attachEvent!=Z){G.attachEvent("onload",j)}else{if(typeof G.onload=="function"){var i=G.onload;G.onload=function(){i();j()}}else{G.onload=j}}}}}function I(){var l=H.length;for(var j=0;j<l;j++){var m=H[j].id;if(a.pv[0]>0){var k=c(m);if(k){H[j].width=k.getAttribute("width")?k.getAttribute("width"):"0";H[j].height=k.getAttribute("height")?k.getAttribute("height"):"0";if(O(H[j].swfVersion)){if(a.webkit&&a.webkit<312){U(k)}X(m,true)}else{if(H[j].expressInstall&&!C&&O("6.0.65")&&(a.win||a.mac)){D(H[j])}else{d(k)}}}}else{X(m,true)}}}function U(m){var k=m.getElementsByTagName(P)[0];if(k){var p=Y("embed"),r=k.attributes;if(r){var o=r.length;for(var n=0;n<o;n++){if(r[n].nodeName.toLowerCase()=="data"){p.setAttribute("src",r[n].nodeValue)}else{p.setAttribute(r[n].nodeName,r[n].nodeValue)}}}var q=k.childNodes;if(q){var s=q.length;for(var l=0;l<s;l++){if(q[l].nodeType==1&&q[l].nodeName.toLowerCase()=="param"){p.setAttribute(q[l].getAttribute("name"),q[l].getAttribute("value"))}}}m.parentNode.replaceChild(p,m)}}function F(i){if(a.ie&&a.win&&O("8.0.0")){G.attachEvent("onunload",function(){var k=c(i);if(k){for(var j in k){if(typeof k[j]=="function"){k[j]=function(){}}}k.parentNode.removeChild(k)}})}}function D(j){C=true;var o=c(j.id);if(o){if(j.altContentId){var l=c(j.altContentId);if(l){L=l;T=j.altContentId}}else{L=b(o)}if(!(/%$/.test(j.width))&&parseInt(j.width,10)<310){j.width="310"}if(!(/%$/.test(j.height))&&parseInt(j.height,10)<137){j.height="137"}g.title=g.title.slice(0,47)+" - Flash Player Installation";var n=a.ie&&a.win?"ActiveX":"PlugIn",k=g.title,m="MMredirectURL="+G.location+"&MMplayerType="+n+"&MMdoctitle="+k,p=j.id;if(a.ie&&a.win&&o.readyState!=4){var i=Y("div");p+="SWFObjectNew";i.setAttribute("id",p);o.parentNode.insertBefore(i,o);o.style.display="none";G.attachEvent("onload",function(){o.parentNode.removeChild(o)})}R({data:j.expressInstall,id:K,width:j.width,height:j.height},{flashvars:m},p)}}function d(j){if(a.ie&&a.win&&j.readyState!=4){var i=Y("div");j.parentNode.insertBefore(i,j);i.parentNode.replaceChild(b(j),i);j.style.display="none";G.attachEvent("onload",function(){j.parentNode.removeChild(j)})}else{j.parentNode.replaceChild(b(j),j)}}function b(n){var m=Y("div");if(a.win&&a.ie){m.innerHTML=n.innerHTML}else{var k=n.getElementsByTagName(P)[0];if(k){var o=k.childNodes;if(o){var j=o.length;for(var l=0;l<j;l++){if(!(o[l].nodeType==1&&o[l].nodeName.toLowerCase()=="param")&&!(o[l].nodeType==8)){m.appendChild(o[l].cloneNode(true))}}}}}return m}function R(AE,AC,q){var p,t=c(q);if(typeof AE.id==Z){AE.id=q}if(a.ie&&a.win){var AD="";for(var z in AE){if(AE[z]!=Object.prototype[z]){if(z=="data"){AC.movie=AE[z]}else{if(z.toLowerCase()=="styleclass"){AD+=' class="'+AE[z]+'"'}else{if(z!="classid"){AD+=" "+z+'="'+AE[z]+'"'}}}}}var AB="";for(var y in AC){if(AC[y]!=Object.prototype[y]){AB+='<param name="'+y+'" value="'+AC[y]+'" />'}}t.outerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+AD+">"+AB+"</object>";F(AE.id);p=c(AE.id)}else{if(a.webkit&&a.webkit<312){var AA=Y("embed");AA.setAttribute("type",W);for(var x in AE){if(AE[x]!=Object.prototype[x]){if(x=="data"){AA.setAttribute("src",AE[x])}else{if(x.toLowerCase()=="styleclass"){AA.setAttribute("class",AE[x])}else{if(x!="classid"){AA.setAttribute(x,AE[x])}}}}}for(var w in AC){if(AC[w]!=Object.prototype[w]){if(w!="movie"){AA.setAttribute(w,AC[w])}}}t.parentNode.replaceChild(AA,t);p=AA}else{var s=Y(P);s.setAttribute("type",W);for(var v in AE){if(AE[v]!=Object.prototype[v]){if(v.toLowerCase()=="styleclass"){s.setAttribute("class",AE[v])}else{if(v!="classid"){s.setAttribute(v,AE[v])}}}}for(var u in AC){if(AC[u]!=Object.prototype[u]&&u!="movie"){E(s,u,AC[u])}}t.parentNode.replaceChild(s,t);p=s}}return p}function E(k,i,j){var l=Y("param");l.setAttribute("name",i);l.setAttribute("value",j);k.appendChild(l)}function c(i){return g.getElementById(i)}function Y(i){return g.createElement(i)}function O(k){var j=a.pv,i=k.split(".");i[0]=parseInt(i[0],10);i[1]=parseInt(i[1],10);i[2]=parseInt(i[2],10);return(j[0]>i[0]||(j[0]==i[0]&&j[1]>i[1])||(j[0]==i[0]&&j[1]==i[1]&&j[2]>=i[2]))?true:false}function A(m,j){if(a.ie&&a.mac){return }var l=g.getElementsByTagName("head")[0],k=Y("style");k.setAttribute("type","text/css");k.setAttribute("media","screen");if(!(a.ie&&a.win)&&typeof g.createTextNode!=Z){k.appendChild(g.createTextNode(m+" {"+j+"}"))}l.appendChild(k);if(a.ie&&a.win&&typeof g.styleSheets!=Z&&g.styleSheets.length>0){var i=g.styleSheets[g.styleSheets.length-1];if(typeof i.addRule==P){i.addRule(m,j)}}}function X(k,i){var j=i?"visible":"hidden";if(S){c(k).style.visibility=j}else{A("#"+k,"visibility:"+j)}}return{registerObject:function(l,i,k){if(!a.w3cdom||!l||!i){return }var j={};j.id=l;j.swfVersion=i;j.expressInstall=k?k:false;H[H.length]=j;X(l,false)},getObjectById:function(l){var i=null;if(a.w3cdom&&S){var j=c(l);if(j){var k=j.getElementsByTagName(P)[0];if(!k||(k&&typeof j.SetVariable!=Z)){i=j}else{if(typeof k.SetVariable!=Z){i=k}}}}return i},embedSWF:function(n,u,r,t,j,m,k,p,s){if(!a.w3cdom||!n||!u||!r||!t||!j){return }r+="";t+="";if(O(j)){X(u,false);var q=(typeof s==P)?s:{};q.data=n;q.width=r;q.height=t;var o=(typeof p==P)?p:{};if(typeof k==P){for(var l in k){if(k[l]!=Object.prototype[l]){if(typeof o.flashvars!=Z){o.flashvars+="&"+l+"="+k[l]}else{o.flashvars=l+"="+k[l]}}}}J(function(){R(q,o,u);if(q.id==u){X(u,true)}})}else{if(m&&!C&&O("6.0.65")&&(a.win||a.mac)){X(u,false);J(function(){var i={};i.id=i.altContentId=u;i.width=r;i.height=t;i.expressInstall=m;D(i)})}}},getFlashPlayerVersion:function(){return{major:a.pv[0],minor:a.pv[1],release:a.pv[2]}},hasFlashPlayerVersion:O,createSWF:function(k,j,i){if(a.w3cdom&&S){return R(k,j,i)}else{return undefined}},createCSS:function(j,i){if(a.w3cdom){A(j,i)}},addDomLoadEvent:J,addLoadEvent:M,getQueryParamValue:function(m){var l=g.location.search||g.location.hash;if(m==null){return l}if(l){var k=l.substring(1).split("&");for(var j=0;j<k.length;j++){if(k[j].substring(0,k[j].indexOf("="))==m){return k[j].substring((k[j].indexOf("=")+1))}}}return""},expressInstallCallback:function(){if(C&&L){var i=c(K);if(i){i.parentNode.replaceChild(L,i);if(T){X(T,true);if(a.ie&&a.win){L.style.display="block"}}L=null;T=null;C=false}}}}}();
/* Task Handler */
Gloo.Task =
{
TaskId : null,
Dialogue : null,
onTaskComplete : function(){},
onTaskError : function(){},
onProgressUpdate : function(){},

Init : function()
{
Gloo.Task.TaskId = getQsVar(location.href, "taskId").replace(/#$/gi, "");

if (Gloo.Task.TaskId != "") window.onload = Gloo.Task.MonitorProgress;
},

MonitorProgress : function(taskId)
{
if (typeof(taskId) == "string") Gloo.Task.TaskId = taskId;
var Data = "<request taskid=\"" + Gloo.Task.TaskId + "\" abort=\"false\" />";
makeHttpRequest("/Cms/Common/Components/Task/TaskProgressXml.aspx", "POST", Data, "Gloo.Task.ProgressUpdate", "Gloo.Task.LoadError");
},
ProgressUpdate : function(Request)
{
if (!Request) Gloo.Task.CancelTask();

var ProgressXml = Request.responseXML;

var Status = ProgressXml.documentElement.getAttribute("status");
var TimeRemaining = ProgressXml.documentElement.getAttribute("timeremaining");
var PercentageComplete = ProgressXml.documentElement.getAttribute("percentcomplete");

var ErrorMessage = "";
try { ErrorMessage = ProgressXml.documentElement.firstChild.firstChild.nodeValue; }
catch (e) { }


switch (Status)
{
case "Cancelled":
{
ErrorMessage = "Task cancelled by user.";
Gloo.Task.onTaskError(ErrorMessage);
break;
}
case "Error":
{
Gloo.Task.onTaskError(ErrorMessage);
break;
}
case "Complete":
{
Gloo.Task.onTaskComplete(ProgressXml.documentElement.firstChild);
break;
}
default:
{
Gloo.Task.onProgressUpdate(PercentageComplete, TimeRemaining, ErrorMessage);
setTimeout("Gloo.Task.MonitorProgress()", 1000);
break;
}
}
},

ShowDialogue : function(TaskId)
{
Gloo.Task.TaskId = TaskId;

Gloo.Task.Dialogue = Gloo.Dialogue.Iframe("Task progress", "/Cms/Common/Components/Task/Progress.html?" +
"refresh=" + Math.round(Math.random() * 99999999) + "&taskId=" + Gloo.Task.TaskId, true, "350", "100");
},

CloseDialogue : function()
{
if (Gloo.Task.Dialogue) Gloo.Dialogue.Remove(Gloo.Task.Dialogue);
},

CancelTask : function()
{
var Data = "<request taskid=\"" + Gloo.Task.TaskId + "\" abort=\"true\" />";
makeHttpRequest("/Cms/Common/Components/Task/TaskProgressXml.aspx", "POST", Data, "Gloo.Task.CancelComplete", "Gloo.Task.LoadError");
return false;
},
CancelComplete : function()
{
Gloo.Task.CloseDialogue();
Gloo.Task.MonitorProgress();
},

LoadError : function()
{
Gloo.Dialogue.Alert("Error", "Failed to load XML!");
}
};
/*******************/
/* Tooltip */
Gloo.Tooltip =
{
Element : null,
Div : null,

Show : function(Event, Text)
{
Gloo.Tooltip.Hide();

Gloo.Tooltip.Element = getEventTarget(Event);

Gloo.Tooltip.Div = document.createElement("div");
Gloo.Tooltip.Div.className = "Tooltip";
Gloo.Tooltip.Div.innerHTML = Text;
document.body.appendChild(Gloo.Tooltip.Div);
Gloo.Tooltip.SetPosition(Event);

attachEventListener(document, "mousemove", Gloo.Tooltip.SetPosition, true);
attachEventListener(document, "mousedown", Gloo.Tooltip.Hide, true);
attachEventListener(Gloo.Tooltip.Element, "mouseout", Gloo.Tooltip.Hide, true);
},

Hide : function()
{
if (!Gloo.Tooltip.Div) return;

detachEventListener(document, "mousemove", Gloo.Tooltip.SetPosition, true);
detachEventListener(document, "mousedown", Gloo.Tooltip.Hide, true);
detachEventListener(Gloo.Tooltip.Element, "mouseout", Gloo.Tooltip.Hide, true);

Gloo.Tooltip.Div.parentNode.removeChild(Gloo.Tooltip.Div);

Gloo.Tooltip.Div = null;
Gloo.Tooltip.Element = null;
},

SetPosition : function(Event)
{
var NewY = getMouseY(Event) + 20;
var NewX = getMouseX(Event) - (getWidth(Gloo.Tooltip.Div) / 2);

if (NewY + getHeight(Gloo.Tooltip.Div) > getDocumentHeight() - getScrollY()) NewY = getDocumentHeight() - getScrollY() - getHeight(Gloo.Tooltip.Div);
if (NewX + getWidth(Gloo.Tooltip.Div) > getDocumentWidth() - getScrollX()) NewX = getDocumentWidth() - getScrollX() - getWidth(Gloo.Tooltip.Div);

setTop(Gloo.Tooltip.Div, NewY);
setLeft(Gloo.Tooltip.Div, NewX);
show(Gloo.Tooltip.Div);
}
};
/*******************/
/* Upload Handler */
Gloo.Upload =
{
PostbackId : null,
Dialogue : null,
onUploadError : function(){},
onUploadComplete : function(){},
onProgressUpdate : function(){},

Init : function()
{
Gloo.Upload.PostbackId = getQsVar(location.href, "postbackId");

if (Gloo.Upload.PostbackId != "") window.onload = Gloo.Upload.MonitorProgress;
},

Attach : function(Button)
{
var Anchors = document.getElementsByTagName("a");
for (var i = 0; i < Anchors.length; i++)
{
if (Anchors[i].id.match(new RegExp("_" + Button + "$")))
{
document.forms[0]["__EVENTTARGET"].value = Anchors[i].id.replace(/_/gi, ":").replace(":", "_");
}
}

var Inputs = document.forms[0].getElementsByTagName("INPUT");
for (var i = 0; i < Inputs.length; i++)
{
if (Inputs[i].type.toLowerCase() == "file" && Inputs[i].value.match(/[^\s]+/gi))
{
Gloo.Upload.PostbackId = Inputs[i].name.match(/^NeatUpload_[0-9A-Z]+/gi);
}
}

if (Gloo.Upload.PostbackId != null) Gloo.Upload.ShowDialogue(); else document.forms[0].submit();

return false;
},

ShowDialogue : function(postbackId)
{
if (postbackId) Gloo.Upload.PostbackId = postbackId;

top.Gloo.Upload.Dialogue = top.Gloo.Dialogue.Iframe("Upload progress", "/Cms/Common/Components/Upload/Progress.html?" +
"refresh=" + Math.round(Math.random() * 99999999) + "&postbackId=" + Gloo.Upload.PostbackId, true, "350", "100");

window.onunload = Gloo.Upload.CloseDialogue;

setTimeout("document.forms[0].submit();", 2000);
},

CloseDialogue : function()
{
if (top.Gloo.Upload.Dialogue) Gloo.Dialogue.Remove(top.Gloo.Upload.Dialogue);
},

MonitorProgress : function(postbackId)
{
if (typeof(postbackId) == "String") Gloo.Upload.PostbackId = postbackId;
var url = "/Cms/Common/Components/Upload/UploadProgressXml.aspx?postbackId=" + Gloo.Upload.PostbackId;
makeHttpRequest(url, "GET", "", "Gloo.Upload.ProgressUpdate", "Gloo.Upload.LoadError");
},
ProgressUpdate : function(Request)
{
if (!Request) Gloo.Upload.CancelUpload();

var ProgressXml = Request.responseXML;

var Status = ProgressXml.documentElement.getAttribute("status");
var TimeRemaining = ProgressXml.documentElement.getAttribute("timeremaining");
var TransferRate = ProgressXml.documentElement.getAttribute("transferrate");
var BytesRead = ProgressXml.documentElement.getAttribute("bytesread");
var ContentLength = ProgressXml.documentElement.getAttribute("contentlength");
var PercentageComplete = Math.round((BytesRead / ContentLength) * 100);
if (isNaN(PercentageComplete)) PercentageComplete = 0;

if (Status == "Rejected")
{
Gloo.Upload.CancelUpload(true);

Gloo.Upload.onUploadError("Upload rejected: File is too large!");
}
else if (Status != "Completed")
{
Gloo.Upload.onProgressUpdate(PercentageComplete, BytesRead, ContentLength, TransferRate, TimeRemaining);
setTimeout("Gloo.Upload.MonitorProgress()", 1000);
}
else
{
Gloo.Upload.onUploadComplete();
}
},

CancelUpload : function()
{
if (window.stop) window.stop();
else if (document.execCommand) document.execCommand('Stop');

Gloo.Upload.CloseDialogue();
},

LoadError : function()
{
Gloo.Dialogue.Alert("Error", "Failed to load XML!");
}
};
/*******************/
Gloo.Form.Placeholder = "_ContentColumn_";
var Tools =
{
SetFontSize: function(ClassName)
{
var c = document.body.className.replace(/(Small|Medium|Large)/gi, "");
document.body.className = c + " " + ClassName;

createCookie("FontSize", ClassName, 30);

return false;
},

Print: function()
{
window.print();
return false;
}
};
var Blog =
{
ValidateComment: function()
{
Gloo.Form.ClearErrors();

var Valid = true;
Valid = Gloo.Form.isEmpty("FirstName") ? false : Valid;
Valid = Gloo.Form.isEmpty("LastName") ? false : Valid;
Valid = !Gloo.Form.isEmail("EmailAddress") ? false : Valid;
Valid = Gloo.Form.isEmpty("Validation") ? false : Valid;
Valid = Gloo.Form.isEmpty("Comment") ? false : Valid;

return Valid || Gloo.Form.ShowErrors();
}
};
