
function Class()
{return function()
{if(this.construct!=undefined)
{this.construct.apply(this,arguments);}};};var ShortcutManager=new Class();var ShortcutCollection=new Class();var Shortcut=new Class();ShortcutCollection.prototype={construct:function(collectionName,domainName)
{if(null!=collectionName&&collectionName>"")
{this.CollectionName=collectionName;}
else
{this.CollectionName="Common";}
if(null!=domainName&&domainName>"")
{this.DomainName=domainName;}
else
{this.DomainName=null;}
this.Members=new Array();this.SERIALIZATION_DELIMITER="|~|";this.TEMPLATE_TOKEN_URI="#URI#";this.TEMPLATE_TOKEN_TITLE="#TITLE#";this.Load();},Save:function(daysToLive)
{var cookieName="Shortcuts"+this.CollectionName;var exdate=new Date();if(null==daysToLive)
{daysToLive=3650;}
exdate.setTime(exdate.getTime()+daysToLive*24*60*60*1000)
cookieString=cookieName+"="+escape(this.Serialize())+"; expires="+exdate.toGMTString();if(null!=this.DomainName&&this.DomainName.length>0)
{cookieString+="; domain="+this.DomainName;}
document.cookie=cookieString;},Load:function()
{if(document.cookie.length>0)
{var cookieName="Shortcuts"+this.CollectionName;var c_start=document.cookie.indexOf(cookieName+"=")
if(c_start!=-1)
{c_start=c_start+cookieName.length+1
c_end=document.cookie.indexOf(";",c_start)
if(c_end==-1)
c_end=document.cookie.length;cookieData=unescape(document.cookie.substring(c_start,c_end));this.Deserialize(cookieData);}}
return null},Add:function(uri,title)
{if(null==title||title.length<1)
{title="Untitled page";}
var existingIndex=this.IndexOfUri(uri);if(existingIndex>-1)
{this.Members[existingIndex].Title=title;}
else
{newShortcut=new Shortcut(uri,title);this.Members[this.Members.length]=newShortcut;}
this.Sort();this.Save();},Remove:function(uri)
{var existingIndex=this.IndexOfUri(uri);if(existingIndex>-1)
{for(i=existingIndex+1;i<this.Members.length;i++)
{this.Members[i-1]=this.Members[i];}
this.Members.length--;this.Save();}
else
{alert("Uri not found in shortcut collection");}},IndexOfUri:function(uri)
{for(var i=0;i<this.Members.length;i++)
{if(this.Members[i].Uri==uri)
{return i;}}
return-1;},Serialize:function()
{var serialized="";for(var i=0;i<this.Members.length;i++)
{if(i>0)
{serialized+=this.SERIALIZATION_DELIMITER;}
serialized+=this.Members[i].Serialize();}
return serialized;},Deserialize:function(serializedEntry)
{serializedShortcuts=serializedEntry.split(this.SERIALIZATION_DELIMITER);for(i=0;i<serializedShortcuts.length;i++)
{if(serializedShortcuts[i].length>0)
{var shortcut=new Shortcut("","");if(!shortcut.Deserialize(serializedShortcuts[i]))
{alert("Could not deserialize the following block: "+serializedEntry);}
this.Members[this.Members.length]=shortcut;}}},Render:function(htmlTemplate)
{if(htmlTemplate==null||htmlTemplate=="")
{htmlTemplate="<li><a href='"+this.TEMPLATE_TOKEN_URI+"'>"+this.TEMPLATE_TOKEN_TITLE+"</a></li>";}
var renderedHtml="";for(var i=0;i<this.Members.length;i++)
{renderedHtml+=DomainWideWebShortcuts_StringReplace(DomainWideWebShortcuts_StringReplace(htmlTemplate,this.TEMPLATE_TOKEN_URI,this.Members[i].Uri),this.TEMPLATE_TOKEN_TITLE,this.Members[i].Title);}
return renderedHtml;},Sort:function()
{for(var j=this.Members.length-1;j>0;j--){for(var i=0;i<j;i++)
{if(this.Members[i+1].Title<this.Members[i].Title)
{var mbrRef=this.Members[i+1];this.Members[i+1]=this.Members[i];this.Members[i]=mbrRef;}}}}};Shortcut.prototype={construct:function(uri,title)
{this.Uri=uri;this.Title=title;this.SERIALIZATION_DELIMITER=":::";},Serialize:function()
{return this.Uri+this.SERIALIZATION_DELIMITER+this.Title;},Deserialize:function(serializedEntry)
{if(serializedEntry.indexOf(this.SERIALIZATION_DELIMITER)>-1)
{var values=serializedEntry.split(this.SERIALIZATION_DELIMITER);this.Uri=values[0];this.Title=values[1];return true;}
else
{return false;}}};ShortcutManager.prototype={construct:function(collectionName,domainName,shortcutsDomElement,addDomElement,removeDomElement)
{if(null==shortcutsDomElement)
{alert('ShortcutManager constructor missing input.\n\nThe following parameters are required:\n - collectionName (a-z,A-Z)\n - domainName (empty = this host only)\n - shortcutsDomElement (div that holds shortcuts)\n - addDomElement (div that holds add link)\n - removeDomElement (div that holds remove link)');}
this.ShortcutsDomElement=shortcutsDomElement;this.AddDomElement=addDomElement;this.RemoveDomElement=removeDomElement;if(null!=collectionName&&collectionName>"")
{this.CollectionName=collectionName;}
else
{this.CollectionName="Common";}
if(null!=domainName&&domainName>"")
{this.DomainName=domainName;}
else
{this.DomainName=null;}
this.Shortcuts=new ShortcutCollection(this.CollectionName,this.DomainName);this.ShortcutTemplateHead='<ul>';this.ShortcutTemplateBody='  <li><a href="#URI#">#TITLE#</a></li>';this.ShortcutTemplateTail='</ul>';this.NoShortcutsHtml='<div>Use the link below to add this page to your shortcuts</div>';this.TitleSeparatorChar=null;},Add:function(uri,shortcutTitle)
{if(null==shortcutTitle||shortcutTitle.length==0)
{shortcutTitle=document.title;}
if(null==uri||uri.length==0)
{uri=document.location;}
if(!(this.TitleSeparatorChar==null||this.TitleSeparatorChar.length==0||shortcutTitle.lastIndexOf(this.TitleSeparatorChar)==-1))
{shortcutTitle=shortcutTitle.substring(shortcutTitle.lastIndexOf(this.TitleSeparatorChar)+this.TitleSeparatorChar.length);}
if(shortcutTitle.length==0)
{shortcutTitle='Untitled page';}
this.Shortcuts.Add(uri,shortcutTitle);this.Render();},Remove:function(uri)
{if(null==uri||uri.length<0)
{uri=document.location;}
this.Shortcuts.Remove(uri);this.Render();},Render:function()
{if(this.Shortcuts.Members.length!=0)
{this.ShortcutsDomElement.innerHTML=this.ShortcutTemplateHead+
this.Shortcuts.Render(this.ShortcutTemplateBody)+
this.ShortcutTemplateTail;}
else
{this.ShortcutsDomElement.innerHTML=this.NoShortcutsHtml;}
if(this.Shortcuts.IndexOfUri(document.location)!=-1)
{if(null!=this.RemoveDomElement)this.RemoveDomElement.style.display='';if(null!=this.AddDomElement)this.AddDomElement.style.display='none';}
else
{if(null!=this.RemoveDomElement)this.RemoveDomElement.style.display='none';if(null!=this.AddDomElement)this.AddDomElement.style.display='';}},ContainsUri:function(uri)
{return(this.Shortcuts.IndexOfUri(uri)>-1);}};function DomainWideWebShortcuts_StringReplace(sourceString,toFind,toInsert)
{i=sourceString.indexOf(toFind);r="";if(i==-1)return sourceString;r+=sourceString.substring(0,i)+toInsert;if(i+toFind.length<sourceString.length)
r+=DomainWideWebShortcuts_StringReplace(sourceString.substring(i+toFind.length,sourceString.length),toFind,toInsert);return r;}