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); };
}
}
},

ToggleMenu : function(El)
{
var node = El.parentNode;
var lists = node.getElementsByTagName("ul");
if (lists.length > 0)
{
if (!isVisible(lists[0])) node.className += " Opened";
else node.className = node.className.replace(/Opened/gi, "");
}
},

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";
},

HidingStatus : null,
ShowStatus : function(Text)
{
Text += " <span class=\"Hide\">(<a href=\"#\" onclick=\"Gloo.ClearStatus(this);return false;\">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);
},
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);
setHTML(Anchor, "View all <span>(show filter)</span>");
}
else
{
show(Filter);
setHTML(Anchor, "View all <span>(hide filter)</span>");
}
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";
}
},

Preview : function(id, script, width, height)
{
Gloo.Dialogue.Iframe("Preview", (script || "Preview.aspx") + "?Id=" + id, true, width || 640, height || 480);
return false;
}
};/* 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 top = getOffsetTop(Gloo.Calendar.Input) + getHeight(Gloo.Calendar.Input) - getOffsetScrollTop(Gloo.Calendar.Input);
var bottom = top + getHeight(Gloo.Calendar.Element);
var bottomBounds = getDocumentHeight();
if (bottom > bottomBounds) top = getOffsetTop(Gloo.Calendar.Input) - getHeight(Gloo.Calendar.Element) - getOffsetScrollTop(Gloo.Calendar.Input);

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 ($("GlooContextMenu")) $("GlooContextMenu").parentNode.removeChild($("GlooContextMenu"));

Gloo.ContextMenu.onHide();
},

Attach : function(Event, Html)
{
var menu = document.createElement("div");
menu.id = "GlooContextMenu";
menu.className = "ContextMenu";
setHTML(menu, "<ul>" + Html + "</ul>");
document.forms[0].appendChild(menu);

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);

if (Iframe)
{
var iframe = Dialogue.getElementsByTagName("iframe")[0];
var frame = document.all ? UploadFrame = document.frames[FrameName] : (document.getElementById(FrameName).contentWindow || document.getElementById(FrameName).contentDocument);
var win = frame.window;
win.Dialogue = 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, getDocumentHeight());
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>";

Gloo.Dialogue.Show(Title, Html, false, true);

return false;
},

Close : function(Event)
{
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);
}

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_",

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, "");
}
},

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, showError)
{
var field = Gloo.Form.GetField(fieldName);
if (field.value.match(expression)) return true;
else
{
if (showError) Gloo.Form.SetError(field);
return false;
}
},

isEmpty : function(fieldName)
{
return !Gloo.Form.isValid(fieldName, /[^\s]+/gi, true);
},

isFckEmpty : function(fieldName)
{
var Valid = FCKeditorAPI.GetInstance(Gloo.Form.GetField(fieldName).id).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, true);
},

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, true)
},

isTime : function(fieldName)
{
return Gloo.Form.isValid(fieldName, /^[0-1][0-9]:[0-5][0-9]\s(AM|PM)$/gi, true)
},

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, true)
},

isExtension : function(fieldName, extensions)
{
return Gloo.Form.isValid(fieldName, new RegExp(".(" + extensions + ")$", "gi"), true)
},

GetField : function (fieldName)
{
var form = document.forms[0];
if (form[fieldName]) return form[fieldName];
return form[Gloo.Form.GetPrefix() + fieldName];
},

SetError : function(field)
{
field.className += " Error";
field.onfocus = Gloo.Form.ClearError;
},

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;
}
};
/*******************/
/* 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();
},

Load: function()
{
var file = Gloo.Gallery.Files[Gloo.Gallery.Index];

Gloo.Gallery.Elements.Img.parentNode.removeChild(Gloo.Gallery.Elements.Img);
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, (getDocumentHeight() / 2) - (getHeight(div) / 2));
setLeft(div, (getDocumentWidth() / 2) - (getWidth(div) / 2));
}

show(div);
}
};
/*******************//* Row re-order drag handler */
var ReorderHandler =
{
DropTarget : null,
SwapDirection : null,
CallbackScript : null,
Element : 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].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) return;
if (ReorderHandler.CallbackScript != "" && ReorderHandler.CallbackScript != null)
{
var DraggingId = ReorderHandler.Element.getAttribute("dragid");
var ReferenceId = ReorderHandler.DropTarget.getAttribute("dragid");
var Direction = ReorderHandler.SwapDirection;
var PostData = "<request id=\"" + DraggingId + "\" referenceid=\"" + ReferenceId + "\" direction=\"" + Direction + "\"  />";
makeHttpRequest(ReorderHandler.CallbackScript, "POST", PostData, "ReorderHandler.RowSaveComplete", "ReorderHandler.RowSaveError");
}

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");
}
};
/*******************//* Task Handler */
Gloo.Task =
{
TaskId : null,
Dialogue : null,
onTaskComplete : function(){},
onTaskError : function(){},
onProgressUpdate : function(){},

Init : function()
{
Gloo.Task.TaskId = getQsVar(location.href, "taskId");

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");

switch (Status)
{
case "Error":
{
var ErrorMessage = ProgressXml.documentElement.firstChild.firstChild.nodeValue;
Gloo.Task.onTaskError(ErrorMessage);
break;
}
case "Complete":
{
Gloo.Task.onTaskComplete(ProgressXml.documentElement.firstChild);
break;
}
default:
{
Gloo.Task.onProgressUpdate(PercentageComplete, TimeRemaining, Error);
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.CloseDialogue", "Gloo.Task.LoadError");
},

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(DoNotClose)
{
if (top.window.stop) top.window.stop();
else if (top.document.execCommand) top.document.execCommand('Stop');

if (!DoNotClose) Gloo.Upload.CloseDialogue();
},

LoadError : function()
{
Gloo.Dialogue.Alert("Error", "Failed to load XML!");
}
};
/*******************/
$ = 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" && getStyle(Element, "display") != null; };
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); } } } };
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)) 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; };
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; };
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 = null;
}
};
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;
};// Account utils
var Account =
{
SelectTab : function(Anchor)
{
var anchorList = Anchor.parentNode.parentNode.getElementsByTagName("a");
for(var i = 0; i < anchorList.length; i++) anchorList[i].className = anchorList[i].className.replace(/Selected/gi, "");
Anchor.className += "Selected";

var divList = Anchor.parentNode.parentNode.parentNode.getElementsByTagName("div");
for(var i = 0; i < divList.length; i++) hide(divList[i]);
show($(Anchor.id.replace(/Tab$/, "Form")));
},
TogglePasswordInput : function(Change)
{
$("_ctl0_PageContent_Password").disabled = !Change;
if (!Change) $("_ctl0_PageContent_Password").value = "";
},
ValidateVideo : function(NewRecord)
{
Gloo.Form.Placeholder = "_PageContent_";
Gloo.Form.ClearErrors();

var Valid = true;
Valid = Gloo.Form.isEmpty("VideoTitle") ? false : Valid;
Valid = !Gloo.Form.isValid("VideoTitle", /[\w]+/gi, true) ? false : Valid;
Valid = Gloo.Form.isEmpty("Description") ? false : Valid;
Valid = Gloo.Form.isEmpty("Location") ? false : Valid;
Valid = Gloo.Form.isEmpty("Region") ? false : Valid;
Valid = !Gloo.Form.isValid("Location", /[\w]+/gi, true) ? false : Valid;
Valid = NewRecord ? (Gloo.Form.isEmpty("VideoFile") ? false : Valid) : Valid;
Valid = !Gloo.Form.isValid("Tags", /^[\w\s\,]*$/gi, true) ? false : Valid;

if (Gloo.Form.GetField("Description").value.length > 4000)
{
Gloo.Dialogue.Alert("Error", "The description may not contain more than 4,000 characters.");
return false;
}

if (!Valid) return Gloo.Form.ShowErrors();
else return Gloo.Upload.Attach("SaveButton");
},
ValidateLogin : function()
{
Gloo.Form.Placeholder = "_PageContent_";
Gloo.Form.ClearErrors();

var Valid = true;
Valid = Gloo.Form.isEmpty("Username") ? false : Valid;
Valid = Gloo.Form.isEmpty("Password") ? false : Valid;

if (!Valid) return Gloo.Form.ShowErrors();
else return true;
},
ValidatePassword : function()
{
Gloo.Form.Placeholder = "_PageContent_";
Gloo.Form.ClearErrors();

var Valid = true;
Valid = Gloo.Form.isEmpty("PasswordUsername") ? false : Valid;

if (!Valid) return Gloo.Form.ShowErrors();
else return true;
},
ValidateRegister : function()
{
Gloo.Form.Placeholder = "_PageContent_";
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("RegisterUsername") ? false : Valid;
Valid = !Gloo.Form.isValid("RegisterUsername", /^[a-z0-9\_]{6,16}$/gi, true) ? false : Valid;
Valid = Gloo.Form.isEmpty("RegisterPassword") ? false : Valid;

if (!Valid) return Gloo.Form.ShowErrors();
else return true;
},
ValidateDetails : function()
{
Gloo.Form.Placeholder = "_PageContent_";
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;

if (!Valid) return Gloo.Form.ShowErrors();
else return Gloo.Upload.Attach("UpdateButton");
},
ValidateMessage : function()
{
Gloo.Form.Placeholder = "_PageContent_";
Gloo.Form.ClearErrors();

var Valid = true;
Valid = Gloo.Form.isEmpty("Name") ? false : Valid;
Valid = Gloo.Form.isEmail("EmailAddress") ? Valid : false;
Valid = Gloo.Form.isEmpty("Message") ? false : Valid;

if (!Valid) return Gloo.Form.ShowErrors();
else return true;
},
DeleteThumbnail : function ()
{
Gloo.Form.Placeholder = "_PageContent_";
hide($(Gloo.Form.GetPrefix() + "CurrentThumbnailOptions"));
$(Gloo.Form.GetPrefix() + "DeleteThumbnail").value = "true";
},

HideSticky: function(Anchor)
{
hide(Anchor.parentNode);
}
};
var Search =
{
Focus : function(Input)
{
if (Input.value == "Search...") Input.value = "";
},
Blur : function(Input)
{
if (Input.value == "") Input.value = "Search...";
},
Execute : function(Anchor)
{
var Keywords = Anchor.parentNode.getElementsByTagName("input")[0].value;
Keywords = Keywords.replace(/[^a-z0-9\s\-]/gi, "");
location.href = "/Videos/Search.aspx?Keywords=" + escape(Keywords);
return false;
}
};
var Video =
{
ShowPostComment : function()
{
hide($("CommentListView"));
show($("PostCommentView"));
return false;
},
HidePostComment : function()
{
show($("CommentListView"));
hide($("PostCommentView"));
return false;
},
ValidatePostComment : function()
{
if ($("_ctl0_PageContent_Comment").value == "")
{
Gloo.Dialogue.Alert("Error", "Please enter a comment.");
return false;
}
if ($("_ctl0_PageContent_Comment").value.length > 4000)
{
Gloo.Dialogue.Alert("Error", "Comment is too long.  Please limit to 4000 characters.");
return false;
}
else return true;
},

LoadError : function()
{
setHTML($("_ctl0_StatusBar"), "Unable to complete request!");
show($("_ctl0_StatusBar"));
},

SaveFave : function()
{
var id = $("_ctl0_PageContent_VideoID").value;
makeHttpRequest("/Web/Common/Scripts/Video/AddFavourite.aspx", "post", "<request id='" + id + "' />", "Video.SaveFaveComplete", "Video.LoadError");
},
SaveFaveComplete : function(Request)
{
setHTML($("FavesDialogue"), Request.responseText);
},

ShareVideo : function()
{
if (!Gloo.Form.isEmail("FriendsEmail")) return Gloo.Dialogue.Alert("Error", "Friend's e-mail address is not valid.");
if ($("ShareMessage").value.length > 1000) return Gloo.Dialogue.Alert("Error", "Your message is too long. Please limit to 1,000 characters.");

var id = $("_ctl0_PageContent_VideoID").value;
var to = $("FriendsEmail").value;
var message = $("ShareMessage").value;
var data = "<request id='" + id + "' to='" + escape(to) + "' message='" + escape(message) + "' />";
makeHttpRequest("/Web/Common/Scripts/Video/Share.aspx", "post", data, "Video.ShareVideoComplete", "Video.LoadError");

setHTML($("ShareDialogue"), "Sending...");

return false;
},
ShareVideoComplete : function(Request)
{
setHTML($("ShareDialogue"), Request.responseText);
},

ShowRating : function(Rate)
{
$("RatingSlider").className = "Rating Rating" + Rate;
},
SetRating : function(Rate)
{
var id = $("_ctl0_PageContent_VideoID").value;
var data = "<request id='" + id + "' rate='" + Rate + "' />";
makeHttpRequest("/Web/Common/Scripts/Video/Rate.aspx", "post", data, "Video.SetRatingComplete", "Video.LoadError");

setHTML($("RatingDialogue"), "Saving...");

return false;
},
SetRatingComplete : function(Request)
{
setHTML($("RatingDialogue"), Request.responseText);
},

FavesDialogue : function()
{
show($("ToolbarDropdown"));

show($("FavesDialogue"));
hide($("ShareDialogue"));
hide($("RatingDialogue"));

$("FavesButton").className += " Selected";
$("ShareButton").className = $("ShareButton").className.replace(/Selected/gi, "");
$("RatingButton").className = $("RatingButton").className.replace(/Selected/gi, "");

Video.SaveFave();

return false;
},
ShareDialogue : function()
{
show($("ToolbarDropdown"));

hide($("RatingDialogue"));
show($("ShareDialogue"));
hide($("FavesDialogue"));

$("FavesButton").className = $("FavesButton").className.replace(/Selected/gi, "");
$("ShareButton").className += " Selected";
$("RatingButton").className = $("RatingButton").className.replace(/Selected/gi, "");

return false;
},
RateDialogue : function()
{
show($("ToolbarDropdown"));

show($("RatingDialogue"));
hide($("ShareDialogue"));
hide($("FavesDialogue"));

$("FavesButton").className = $("FavesButton").className.replace(/Selected/gi, "");
$("ShareButton").className = $("ShareButton").className.replace(/Selected/gi, "");
$("RatingButton").className += " Selected";

return false;
},

ToggleDescription : function()
{
var Span = $("_ctl0_PageContent_Description").getElementsByTagName("span")[0];
var Anchor = $("_ctl0_PageContent_Description").getElementsByTagName("a")[0];
if (isVisible(Span))
{
Span.style.display = "none";
setHTML(Anchor, "<em>...</em> more");
}
else
{
Span.style.display = "inline";
setHTML(Anchor, "&nbsp;less");
}
}
};/**
* SWFObject v1.4.1: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
*
* SWFObject is (c) 2006 Geoff Stearns and is released under the MIT License:
* http://www.opensource.org/licenses/mit-license.php
*
* **SWFObject is the SWF embed script formerly known as FlashObject. The name was changed for
*   legal reasons.
*/
if(typeof deconcept == "undefined") var deconcept = new Object();
if(typeof deconcept.util == "undefined") deconcept.util = new Object();
if(typeof deconcept.SWFObjectUtil == "undefined") deconcept.SWFObjectUtil = new Object();
deconcept.SWFObject = function(swf, id, w, h, ver, c, useExpressInstall, quality, xiRedirectUrl, redirectUrl, detectKey){
if (!document.createElement || !document.getElementById) { return; }
this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY);
this.params = new Object();
this.variables = new Object();
this.attributes = new Array();
if(swf) { this.setAttribute('swf', swf); }
if(id) { this.setAttribute('id', id); }
if(w) { this.setAttribute('width', w); }
if(h) { this.setAttribute('height', h); }
if(ver) { this.setAttribute('version', new deconcept.PlayerVersion(ver.toString().split("."))); }
this.installedVer = deconcept.SWFObjectUtil.getPlayerVersion(this.getAttribute('version'), useExpressInstall);
if(c) { this.addParam('bgcolor', c); }
var q = quality ? quality : 'high';
this.addParam('quality', q);
this.setAttribute('useExpressInstall', useExpressInstall);
this.setAttribute('doExpressInstall', false);
var xir = (xiRedirectUrl) ? xiRedirectUrl : window.location;
this.setAttribute('xiRedirectUrl', xir);
this.setAttribute('redirectUrl', '');
if(redirectUrl) { this.setAttribute('redirectUrl', redirectUrl); }
}
deconcept.SWFObject.prototype = {
setAttribute: function(name, value){
this.attributes[name] = value;
},
getAttribute: function(name){
return this.attributes[name];
},
addParam: function(name, value){
this.params[name] = value;
},
getParams: function(){
return this.params;
},
addVariable: function(name, value){
this.variables[name] = value;
},
getVariable: function(name){
return this.variables[name];
},
getVariables: function(){
return this.variables;
},
getVariablePairs: function(){
var variablePairs = new Array();
var key;
var variables = this.getVariables();
for(key in variables){
variablePairs.push(key +"="+ variables[key]);
}
return variablePairs;
},
getSWFHTML: function() {
var swfNode = "";
if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
if (this.getAttribute("doExpressInstall")) this.addVariable("MMplayerType", "PlugIn");
swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'"';
swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
var params = this.getParams();
for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
var pairs = this.getVariablePairs().join("&");
if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
swfNode += '/>';
} else { // PC IE
if (this.getAttribute("doExpressInstall")) this.addVariable("MMplayerType", "ActiveX");
swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'">';
swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
var params = this.getParams();
for(var key in params) {
swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
}
var pairs = this.getVariablePairs().join("&");
if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
swfNode += "</object>";
}
return swfNode;
},
write: function(elementId){
if(this.getAttribute('useExpressInstall')) {
var expressInstallReqVer = new deconcept.PlayerVersion([6,0,65]);
if (this.installedVer.versionIsValid(expressInstallReqVer) && !this.installedVer.versionIsValid(this.getAttribute('version'))) {
this.setAttribute('doExpressInstall', true);
this.addVariable("MMredirectURL", escape(this.getAttribute('xiRedirectUrl')));
document.title = document.title.slice(0, 47) + " - Flash Player Installation";
this.addVariable("MMdoctitle", document.title);
}
}
if(this.skipDetect || this.getAttribute('doExpressInstall') || this.installedVer.versionIsValid(this.getAttribute('version'))){
var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
n.innerHTML = this.getSWFHTML();
return true;
}else{
if(this.getAttribute('redirectUrl') != "") {
document.location.replace(this.getAttribute('redirectUrl'));
}
}
return false;
}
}
/* ---- detection functions ---- */
deconcept.SWFObjectUtil.getPlayerVersion = function(reqVer, xiInstall){
var PlayerVersion = new deconcept.PlayerVersion([0,0,0]);
if(navigator.plugins && navigator.mimeTypes.length){
var x = navigator.plugins["Shockwave Flash"];
if(x && x.description) {
PlayerVersion = new deconcept.PlayerVersion(x.description.replace(/([a-z]|[A-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
}
}else{
try{
var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
for (var i=3; axo!=null; i++) {
axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+i);
PlayerVersion = new deconcept.PlayerVersion([i,0,0]);
}
}catch(e){}
if (reqVer && PlayerVersion.major > reqVer.major) return PlayerVersion; // version is ok, skip minor detection
if (!reqVer || ((reqVer.minor != 0 || reqVer.rev != 0) && PlayerVersion.major == reqVer.major) || PlayerVersion.major != 6 || xiInstall) {
try{
PlayerVersion = new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
}catch(e){}
}
}
return PlayerVersion;
}
deconcept.PlayerVersion = function(arrVersion){
this.major = parseInt(arrVersion[0]) != null ? parseInt(arrVersion[0]) : 0;
this.minor = parseInt(arrVersion[1]) || 0;
this.rev = parseInt(arrVersion[2]) || 0;
}
deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
if(this.major < fv.major) return false;
if(this.major > fv.major) return true;
if(this.minor < fv.minor) return false;
if(this.minor > fv.minor) return true;
if(this.rev < fv.rev) return false;
return true;
}
/* ---- get value of query string param ---- */
deconcept.util = {
getRequestParameter: function(param){
var q = document.location.search || document.location.hash;
if(q){
var startIndex = q.indexOf(param +"=");
var endIndex = (q.indexOf("&", startIndex) > -1) ? q.indexOf("&", startIndex) : q.length;
if (q.length > 1 && startIndex > -1) {
return q.substring(q.indexOf("=", startIndex)+1, endIndex);
}
}
return "";
}
}
/* fix for video streaming bug */
deconcept.SWFObjectUtil.cleanupSWFs = function() {
var objects = document.getElementsByTagName("OBJECT");
for (var i=0; i < objects.length; i++) {
for (var x in objects[i]) {
if (typeof objects[i][x] == 'function') {
objects[i][x] = null;
}
}
}
}
if (typeof window.onunload == 'function') {
var oldunload = window.onunload;
window.onunload = function() {
deconcept.SWFObjectUtil.cleanupSWFs();
oldunload();
}
} else {
window.onunload = deconcept.SWFObjectUtil.cleanupSWFs;
}
/* add Array.push if needed (ie5) */
if (Array.prototype.push == null) { Array.prototype.push = function(item) { this[this.length] = item; return this.length; }}
/* add some aliases for ease of use/backwards compatibility */
var getQueryParamValue = deconcept.util.getRequestParameter;
var FlashObject = deconcept.SWFObject; // for legacy support
var SWFObject = deconcept.SWFObject;
