if(typeof (Tms)=='undefined') {
  var Tms={
    version: '2.0',
    popup: null,
    createDialog: function (c_id,tms) {                   // Loads initializes dialog & load code
      return Tms.createControl(c_id,'Dialog',TmsRoot+'Compressed/Dialog.js',tms,{ skin: 'Safari',type: 'Dialog',x: 10,y: 10,w: 600,h: 480,mw: 90,mh: 0,sx: 0,sy: 0,dx: 0,dy: 0,showMenu: false,showStatus: true,allowScroll: false,allowResize: true,isMaximized: false });
    },
    createLogIn: function (c_id,tms) {                    // Loads initializes login & load code
      return Tms.createControl(c_id,'LogIn',TmsRoot+'Compressed/LogIn.js',tms,{ skin: 'Safari',type: 'Database',mode: 'LogIn',fields: '',labels: '',userName: '' },'span');
    },
    createImageList: function (c_id,tms) {                // Loads initializes login & load code
      return Tms.createControl(c_id,'ImageList',TmsRoot+'Compressed/ImageList.js',tms,{ skin: 'Safari',pics: new Array(),tWidth: '60px',tPosition: 'Left',lWidth: '120px',columns: 3,picIndex: 0 });
    },
    createRotator: function (c_id,tms) {                  // Set up ctl
      return Tms.createControl(c_id,'Rotator',TmsRoot+'Compressed/Rotator.js',tms,{ skin: 'Safari',transTime: 2 });
    },
    createFileSystemItem: function (c_id,tms) {           // Set up ctl
      return Tms.createControl(c_id,'FileSystem',TmsRoot+'Compressed/FileSystem.js',tms,{ skin: 'Safari',mode: 'ReadOnly',backColor: '#ffffff',highLiteColor: '#ff0000',root: '',path: '',name: '',ext: '',exists: false,size: 0,creationDate: '',updateDate: '' });
    },
    createSoapClient: function (tms) {
      var tm={ username: null,password: null,url: null,fnc: null,params: [] };
      if(!$nu(tms)) {
        tm.username=!$nu(tms.username)?tms.username:null;
        tm.password=!$nu(tms.password)?tms.password:null;
        tm.url=!$nu(tms.url)?tms.url:null;
        tm.fnc=!$nu(tms.fnc)?tms.fnc:null;
        tm.params=!$nu(tms.params)?tms.params:[];
        tm.async=!$nu(tms.async)?tms.async:false;
        tm.callback=!$nu(tms.callback)?tms.callback:null;
        tm.xmlHttp=!$nu(tms.xmlHttp)?tms.xmlHttp:null;
      }
      return tm;
    },
    createControl: function (c_id,ctlType,codeUrl,tms,tmsDefault,elementType) {
      var c=typeof (c_id)=='string'?$(c_id):c_id;  // Get item
      elementType=!$nu(elementType)?elementType:'div';
      (c=c==null?$ce(elementType):c).id=c_id;    // If ctl not found create one & assign id
      if($nu(Tms[ctlType])) {
        Tms.addScript(codeUrl);                            // Load code
        new Function('Tms.'+ctlType+'={isLoaded:false,pre:[]}')(); // Avoid eval
        switch(ctlType) {
          case "Rotator": if($nu(Tms.Fader)) { Tms.Fader={ isLoaded: false };Tms.addScript(TmsRoot+'Compressed/Fader.js'); } break;
          case "FileSystem":
            Tms.FileSystem.prvDlg=Tms.createDialog("TmsSelectDialog",{ skin: 'Safari',type: 'DialogTool',x: 10,y: 10,w: 600,h: 480,mw: 90,mh: 0,sx: 0,sy: 0,dx: 0,dy: 0,showMenu: false,showStatus: true,scrollable: false,enableResize: true,isMaximized: false });
            Tms.FileSystem.selDlg=Tms.createDialog("TmsPreviewDialog",{ skin: 'Safari',type: 'DialogTool',x: 10,y: 10,w: 600,h: 480,mw: 90,mh: 0,sx: 0,sy: 0,dx: 0,dy: 0,showMenu: false,showStatus: true,scrollable: false,enableResize: true,isMaximized: false });
            Tms.FileSystem.uplDlg=Tms.createDialog("TmsUploadDialog",{ skin: 'Safari',type: 'DialogTool',x: 10,y: 10,w: 600,h: 480,mw: 90,mh: 0,sx: 0,sy: 0,dx: 0,dy: 0,showMenu: false,showStatus: true,scrollable: false,enableResize: true,isMaximized: false });
            if($nu(Tms.Soap)) { Tms.Soap={ isLoaded: false,pre: new Array() };Tms.addScript(TmsRoot+'Compressed/Soap.js'); }
            break;
          case "LogIn":
            if($nu(Tms.Encrypt)) { Tms.Encrypt={ isLoaded: false };Tms.addScript(TmsRoot+'Compressed/Encrypt.js'); }
            if($nu(Tms.Soap)) { Tms.Soap={ isLoaded: false,pre: new Array() };Tms.addScript(TmsRoot+'Compressed/Soap.js'); }
            break;
        }
      }
      c.tms=!$nu(tms)?tms:tmsDefault;
      Tms.addCss(TmsRoot+"Skins/"+c.tms.skin+"/aaStyle.css"); // Load skin
      new Function('c','(Tms.'+ctlType+'.isLoaded ? Tms.'+ctlType+'.load(c) : Tms.'+ctlType+'.pre.push(c));')(c); // Avoid eval
      return c;
    },
    addImageListImage: function (c,url) {
      c=typeof (c)=='string'?$(c):c;
      debugger
      if(!$nu(c.tms))
        c.tms.pics[c.tms.pics.length]={ 'url': url };    // Add image to pre loaded array
      else {
        if($nu(c.pics)) c.pics=new Array();             // If image list is not defined create it
        c.pics[c.pics.length]={ 'url': url };            // Add image to pre loaded array
      }
    },
    addRotatorImage: function (c,tag,url,showSeconds,linkUrl,transition) {
      var i=new Image($gi(c,'width'),$gi(c,'height'));// Create image
      i.onload=function () { this.isLoaded=true; };    // Set onload function
      i.src=url;                                         // Set image source
      i.transition=transition;                           // Type of transition
      i.tag=tag;                                         // Set tag
      i.linkUrl=$u(linkUrl)||linkUrl==null?"":linkUrl; // Set link url
      i.seconds=showSeconds;                             // Second to show image
      i.isLoaded=false;                                  // Loaded flag
      if($nu(c.imgs)) c.imgs=new Array();               // If image list is not defined create it
      c.imgs[c.imgs.length]=i;                           // Add image to pre loaded array
    },
    attachFader: function (c,fadeComplete,initValue) {   // Attach addon
      if($nu(Tms.Fader)) {                                // If first addon create code place holder 
        Tms.Fader={ isLoaded: false}                     // Set isLoaded flag
        Tms.addScript(TmsRoot+'Compressed/Fader.js');
      }
      c.fader={ parentNode: c,onComplete: fadeComplete }
      $nu(initValue)?Tms.setOpacity(c,100):Tms.setOpacity(c,initValue); // Set opacity
      return c;                                            // Return control pointer
    },
    init: function () {                                    // Initialize Tms stuff         
      var de=document.documentElement,db=document.body;
      this.body=(document.compatMode=="CSS1Compat")?de:document.body;
      if($t(window.innerWidth)=='number') {             // Get docWidth/HeightNon-IE
        this.docWidth=window.innerWidth;
        this.docHeight=window.innerHeight;
      } else if(de&&(de.clientWidth||de.clientHeight)) {  //IE 6+ in 'standards compliant mode'
        this.docWidth=de.clientWidth;
        this.docHeight=de.clientHeight;
      } else if(db&&(db.clientWidth||db.clientHeight)) {  //IE 4 compatible
        this.docWidth=db.clientWidth;
        this.docHeight=db.clientHeight;
      }
      this.preLoad=$ce('div');                           // Create a div for preloaded images
      this.preLoad.id='preLoaded-Images';this.preLoad.style.position='absolute';
      this.preLoad.style.overflow='hidden';this.preLoad.style.left='-9999px';
      this.preLoad.style.top='-9999px';this.preLoad.style.width='1px';
      this.preLoad.style.height='1px';
      Tms.popup=document.forms[0].appendChild($ce('span'));
    },
    //#region Preload Images
    preLoad: null,preLoadImages: new Array(),
    preLoadImage: function (url) {
      var x,i=new Image();
      for(x=0;x<this.preLoadImages.length;x++)
        if(this.preLoadImages[x]==url) return;          // Already loaded
      i.src=url
      i.width=1;
      i.height=1;
      this.preLoad.appendChild(i);
      this.preLoadImages.push(url);
    },
    //#endregion
    sleep: function (milliSeconds) {
      var startTime=new Date().getTime(); // get the current time
      while(new Date().getTime()<startTime+milliSeconds); // hog cpu
    },
    getChildControls: function (o,ctls) {                 // Get child items with a class
      if($u(ctls)) ctls=new Array();                    // If first iteration create items
      for(var x=0;x<o.childNodes.length;x++) {      // Loop through child nodes
        if(!$u(o.childNodes[x].className)) {              // If childNode className is defined
          ctls[o.childNodes[x].className]=o.childNodes[x]; // Add childNode it to items by className
          if(o.childNodes[x].childNodes.length>0)       // If childNode has children
            Tms.getChildControls(o.childNodes[x],ctls);   // Load recursive
        }
      }
      return (ctls);                                       // Return the items list
    },
    setOpacity: function (o,v) {                          // Sets element opacity
      try {
        o.style.opacity=o.style.MozOpacity=(v==100)?.999999:v/100;
        o.style.KhtmlOpacity=(v/100);
        if(!$u(o.filters)) o.style.filter="alpha(opacity="+v+")";
      } catch(err) {
      }
    },
    showIt: function (url,attribs) {
      if(url.substring(0,4)=='http')
        window.open(url,'TmsDialogWindow',attribs);
      else
        if(url.substring(0,1)=='/') {
          document.forms[0].action=url.replace('//','/');
          document.forms[0].submit();
        } else
          Tms.showItem(url,attribs);
      return false;
    },
    showItem: function (url,attribs) {
      attribs=(!$u(attribs)&&attribs!='')?attribs:'left=20,top=20,width=800,height=600,status=1,scrollbars=1,toolbar=0,resizable=1';
      if(url.substring(0,4)=='http')
        window.open(url,'TmsDialogWindow',attribs);
      else
        if(url.substring(0,1)=='/')
          window.open('.'+url.replace('//','/'),'TmsDialogWindow',attribs);
        else
          window.open(url.replace('~/',TmsRoot+'/').replace('//','/'),'TmsDialogWindow',attribs);
      return false;
    },
    doNothing: function () { },
    getPosition: function (o) {
      var rval=new Object(),parentNode=null,parentTagName=null;
      rval.x=0;
      rval.y=0;
      if(o!==null) {
        rval.ax=o.offsetLeft;
        rval.ay=o.offsetTop;
        //var offsetParent = o.offsetParent;
        parentNode=o.parentNode,borderWidth=null;
        while(parentNode.tagName!='BODY') {
          rval.ax+=parentNode.offsetLeft;
          rval.ay+=parentNode.offsetTop;
          parentTagName=parentNode.tagName.toLowerCase();
          if((__isIE&&parentTagName!="table")||(__isFireFoxNew&&parentTagName=="td")) {
            borderWidth=__getBorderWidth(parentNode);
            rval.ax+=borderWidth.left;
            rval.ay+=borderWidth.top;
          }
          if(parentNode!=document.body&&parentNode!=document.documentElement) {
            rval.ax-=parentNode.scrollLeft;
            rval.ay-=parentNode.scrollTop;
          }
          parentNode=parentNode.parentNode;
        }
      }
      return { left: rval.x,top: rval.y,absoluteLeft: rval.ax,absoluteTop: rval.ay,width: $getComputedStyle(o,'width'),height: $getComputedStyle(o,'height') };
    },
    __getBorderWidth: function (element) {   //returns border width for some element
      var res=new Object(),elStyle=null;
      res.left=0;res.top=0;res.right=0;res.bottom=0;
      try {
        elStyle=$getComputedStyle(element,null);
        res.left=parseInt(elStyle.borderLeftWidth.slice(0,-2));
        res.top=parseInt(elStyle.borderTopWidth.slice(0,-2));
        res.right=parseInt(elStyle.borderRightWidth.slice(0,-2));
        res.bottom=parseInt(elStyle.borderBottomWidth.slice(0,-2));
      } catch(ex) {
        res.left=Tms.__parseBorderWidth(element.style.borderLeftWidth);
        res.top=Tms.__parseBorderWidth(element.style.borderTopWidth);
        res.right=Tms.__parseBorderWidth(element.style.borderRightWidth);
        res.bottom=Tms.__parseBorderWidth(element.style.borderBottomWidth);
      }
      return res;
    },
    __parseBorderWidth: function (width) {
      var res=0,p=null;
      if(typeof (width)=="string"&&width!=null&&width!="") {
        p=width.indexOf("px");
        if(p>=0)
          res=parseInt(width.substring(0,p));
        else
          res=1;  //do not know how to calculate other values (such as 0.5em or 0.1cm) correctly now so just set the width to 1 pixel
      }
      return res;
    },
    regBtnEvent: function (rid,btn,cmd) {
      $(rid+btn).style.cursor='pointer';
      if(typeof (cmd)=='function')
        Tms.attachEvent($(rid+btn),'onclick',cmd);
      else
        Tms.attachEvent($(rid+btn),'onclick',function () { return Tms.LogIn.processCommand(rid,cmd); });
    },
    serialize: function (obj) {
      var returnVal,vArr,vobj,i;
      if(obj!=undefined) {
        switch(obj.constructor) {
          case Array:
            vArr="[";
            for(i=0;i<obj.length;i++) {
              if(i>0) vArr+=",";
              vArr+=serialize(obj[i]);
            }
            vArr+="]"
            return vArr;
          case String:
            returnVal=escape("'"+obj+"'");
            return returnVal;
          case Number:
            returnVal=isFinite(obj)?obj.toString():null;
            return returnVal;
          case Date:
            returnVal="#"+obj+"#";
            return returnVal;
          default:
            if(typeof obj=="object") {
              vobj=[];
              for(attr in obj) {
                if(typeof obj[attr]!="function") {
                  vobj.push('"'+attr+'":'+serialize(obj[attr]));
                }
              }
              if(vobj.length>0)
                return "{"+vobj.join(",")+"}";else return "{}";
            } else {
              return obj.toString();
            }
        }
      }
      return null;
    },
    //#region Include js & css functions
    addScript: function (url) {                            // Include javascript code
      var headID=$Tag(document,"head")[0],o=$ce('script'); // Create script tag
      o.type='text/javascript';                          // Set type 
      o.src=url;                                         // Set url
      headID.appendChild(o);                               // Add to head tag
    },
    addCss: function (url) {                               // Include stylesheet
      if(Tms.cssExists(url)) return;                      // Return if already loading
      var o=$ce('link');                                 // Create link tag
      o.rel='stylesheet';                                // Set rel
      o.type='text/css';                                 // Set type
      o.href=url;                                        // Set url
      $Tag(document,"head")[0].appendChild(o);            // Add to head tag
    },
    cssExists: function (url) {                            // Does css exist (Has it been added)
      var ss=document.styleSheets,x;
      for(x=0,l=ss.length;x<l;++x)
        if(ss[x].href!=null&&ss[x].href==url)
          return true;
      return false;
    },
    cssLoaded: function (url) {
      var ss=document.styleSheets,x,r;
      for(x=0,l=ss.length;x<l;++x)
        if(ss[x].href!=null&&ss[x].href==url) {
          try {                                            // Must be done with t/c for firefox
            r=!$u(ss[x].cssRules)?ss[x].cssRules:r=ss[x].rules;
            if(r.length>0)
              return true;
            else
              break;
          } catch(err) {
          }
        }
      return false;
    },
    //#endregion
    //#region Cross browser event registeration
    attachEvent: function (o,eventname,handler) {
      if(o.addEventListener)
        o.addEventListener(eventname.substr(2),handler,false);
      else
        if(o.attachEvent)
          o.attachEvent(eventname,handler);
    },
    detachEvent: function (o,eventname,handler) {
      if(o.addEventListener)
        o.removeEventListener(eventname.substr(2),handler,false);
      else if(o.attachEvent)
        o.detachEvent(eventname,handler);
    }
    //#endregion
  };


  /**
  * Returns the absolute X and Y positions of an object.
  * @param {HTMLObject} obj HTML Object.
  * @return {Object} Returns an accessor with .x and .y values.
  */
  function getXY(obj) {
    var curleft = 0,curtop = 0,border;
    if (obj.offsetParent) {
      do {
        // XXX: If the element is position: relative we have to add borderWidth
        if (getStyle(obj, 'position') == 'relative') {
          if (border = _pub.getStyle(obj, 'border-top-width')) curtop += parseInt(border);
          if (border = _pub.getStyle(obj, 'border-left-width')) curleft += parseInt(border);
        }
        curleft += obj.offsetLeft;
        curtop += obj.offsetTop;
      }
      while (obj = obj.offsetParent)
    }
    else if (obj.x) {
      curleft += obj.x;
      curtop += obj.y;
    }
    return { 'x': curleft, 'y': curtop };
  }
  /**
  * Returns the specified computed style on an object.
  * @param {HTMLObject} obj HTML Object
  * @param {String} styleProp Property name.
  * @return {Mixed} Computed style on object.
  */
  function getStyle(obj, styleProp) {
    if (obj.currentStyle)
      return obj.currentStyle[styleProp];
    else if (window.getComputedStyle)
      return document.defaultView.getComputedStyle(obj, null).getPropertyValue(styleProp);
  };



  $ = function (x) {
    return document.getElementById(x); 
  };
  $Tag = function (obj, x) {
    var r = null;
    try { r = obj.getElementsByTagName(x); }
    catch (er) { r = document.getElementsByTagName(x); }
    return r;
  };
  $TagClass = function (obj, tag, className) {
    var l = obj.getElementsByTagName(tag);
    for (n = 0; n < l.length; n++)
      if (l[n].className == className) 
        return (l[n]); 
    return (null); 
  };
  //var $ParentByClass = function (obj, cn) { var o = obj; while ((o = o.parentNode) != null) if (o.className == cn) return o; return (null); };
  $t=function (x) {                                      // Return typeof
    return typeof (x);
  }
  $o=function (c) {
    return typeof (c)=='string'?$(c):c;                           // return type from object or string
  };
  $nu=function (x) {                                     // Is undefined or null
    return (typeof (x) == 'undefined' || x == null); 
  };
  $u=function (x) {                                      // Is undefined
    return (typeof (x) == 'undefined'); 
  };
  $ce=function (x) {                                     // Create element
    return document.createElement(x);
  };
  $g=function (o,p) {                                    // Get computed value
    return getComputedStyle(o, '').getPropertyValue(p);
  };
  $gi=function (o,p) {                                    // Get computed value
    return parseInt(getComputedStyle(o, '').getPropertyValue(p));
  };
  if (!window.getComputedStyle) {
    window.getComputedStyle = function (el, pseudo) {
      this.el = el;
      this.getPropertyValue = function (prop) {
        var re = /(\-([a-z]){1})/g;
        if (prop == 'float') prop = 'styleFloat';
        if (re.test(prop)) {
          prop = prop.replace(re, function () {
            return arguments[2].toUpperCase();
          });
        }
        return el.currentStyle[prop] ? el.currentStyle[prop] : null;
      }
      return this;
    }
  };
  Array.prototype.findIndex=function (obj) {
    var i=this.length;
    while(i--) if(this[i]===obj) return i;
    return -1;
  };
  //#region String prototypes
  String.prototype.startsWith = function (str) { return (this.indexOf(str) === 0); }
  String.prototype.endsWith = function (str) { return (this.match(str + "$") == str) }
  String.prototype.reverse = function () { return this.split("").reverse().join(""); }
  String.prototype.trim = function () { return this.replace(/^\s+|\s+$/, ''); };
  Array.prototype.contains = function (obj) { var i = this.length; while (i--) { if (this[i] === obj) { return true; } } return false; }
  Array.prototype.containsKey = function (key) { var i = this.length; while (i--) { if (this[i].key == 'undefined') return false; if (this[i].key === key) return true; } return false; }
  //#endregion
  Tms.init();

}



