wspRoot = function(name)
 {this.name = name; this.wspUrl = '/-/wsrcs/';};
 
// целочисленное значение
wspRoot.prototype.IntVal = function(mixed_var)
{
 var tmp;
 if(typeof(mixed_var) == 'string')
 {
  tmp = parseInt(mixed_var);
  if(isNaN(tmp)) return 0;
   else return tmp;
 }
 else if(typeof(mixed_var) == 'number')
  return Math.floor(mixed_var);
 else return 0;
};

// назначение прозрачности объекту
wspRoot.prototype.setOpacity = function(obj, set)
{
 try{set = this.IntVal(set);
  obj.style.filter = "alpha(opacity="+(100-set)+")";
  obj.style.opacity = (100-set)/100;
 }catch(e){};
};


// создание AJAX-объекта
wspRoot.prototype.getXmlHttp = function()
{
  var xmlhttp;
  try{
   xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  }catch(e){
   try{
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
   }catch(E){xmlhttp = false;};
  };
  if(!xmlhttp && (typeof XMLHttpRequest != 'undefined'))
    xmlhttp = new XMLHttpRequest();
  return xmlhttp;
};

// массив объектов тега 'tag' дочерних по отношению к 'obj'
wspRoot.prototype.getElementsByTag = function(tag, obj) // укороченный алиас
 {return this.getElementsByTagName(tag, obj);}
wspRoot.prototype.getElementsByTagName = function(tag, obj)
 {return obj.getElementsByTagName(tag);}

// массив объектов с классом 'clss' дочерних по отношению к 'obj'
wspRoot.prototype.getElementsByClass = function(clss, obj) // укороченный алиас
 {return this.getElementsByClassName(clss, obj);}
wspRoot.prototype.getElementsByClassName = function(clss, obj)
{
 var node = (obj || document);
 if(node.getElementsByClassName)
  return node.getElementsByClassName(clss);

 var list = node.getElementsByTagName('*');
 var length = list.length;
 var classArray = clss.split(/\s+/);
 var classes = classArray.length;
 var result = new Array();
 for(var i=0; i<length; i++)
 {
  for(var j=0; j<classes; j++)
  {
   if(list[i].className.search('\\b' + classArray[j] + '\\b') != -1)
    {result.push(list[i]); break;};
  };
 };
 return result;
};

// определение элемента по ID
wspRoot.prototype.getElementById = function(id)
 {return document.getElementById(id);};
// определение/назначение ID элементу
wspRoot.prototype.getElementId = function(obj)
{
 var pref = 'wspGlobalObjId';
 var id = '';
 try{
  if(obj.id.length > 0)
   id = obj.id;
  else
  {
   var tmp = new Date().getTime();
   while(document.getElementById(pref+tmp)) tmp++;
   id = pref+tmp; obj.id = id;
  };  
 }catch(e){id = null;};
 return id;
};

// определение родительского элемента с указанным тегом
wspRoot.prototype.getElementParent = function(obj, tag)
{
 var reg = new RegExp(tag, "i");
 try{while(!reg.test(obj.tagName))
  obj = obj.parentNode;
 }catch(e){obj = null;};
 return obj;
};
// определение следующего элемента с указанным тегом
wspRoot.prototype.getElementNext = function(obj, tag)
{
 obj = (obj.nextElementSibling ? obj.nextElementSibling : obj.nextSibling);
 if(tag && (tag.length>0)){var reg = new RegExp(tag, "i");
  try{while(!reg.test(obj.tagName))
   obj = (obj.nextElementSibling ? obj.nextElementSibling : obj.nextSibling);
  }catch(e){obj = null;};
 }; return obj;
};
// определение следующего элемента с указанным тегом
wspRoot.prototype.getElementPrev = function(obj, tag)
{
 obj = (obj.previousElementSibling ? obj.previousElementSibling : obj.previousSibling);
 if(tag && (tag.length>0)){var reg = new RegExp(tag, "i");
  try{while(!reg.test(obj.tagName))
   obj = (obj.previousElementSibling ? obj.previousElementSibling : obj.previousSibling);
  }catch(e){obj = null;};
 }; return obj;
};


wspRoot.prototype.LoadCss = function(urlcss)
{
 var ret = true;
 try
 {
  var d = window.document; var isXML = d.documentElement.nodeName !== 'HTML' || !d.write;
  var css = (d.createElementNS&&isXML ? d.createElementNS('http://www.w3.org/1999/xhtml', 'link') : d.createElement('link'));
   css.setAttribute('type', 'text/css'); css.setAttribute('href', urlcss); css.setAttribute('rel', 'stylesheet');
   
  if(d.getElementsByTagNameNS && isXML)
  {
   if(d.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'head')[0])
    d.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'head')[0].appendChild(css)
   else
    d.documentElement.insertBefore(css, d.documentElement.firstChild);
  } else d.getElementsByTagName('head')[0].appendChild(css);
 }catch(e){ret = false;};
 return ret;
};




/* http://phpjs.org/functions/include:433 */
wspRoot.prototype.Modules = {};
wspRoot.prototype.ModuleLoadTimeOut = function(key)
{
 this.Modules[name]['ajax'].abort();
 this.Modules[name]['stat'] = false;
};
wspRoot.prototype.ModuleSet = function(name, stat)
{
 this.Modules[name] = {'stat':stat};
};
wspRoot.prototype.ModuleLoad = function(name, time, async)
{
 this.ModuleLoadCss(name);
 return this.ModuleLoadJs(name, time, async);
};
wspRoot.prototype.ModuleLoadCss = function(name)
{
 name = name.toLowerCase();
 var filecss = this.wspUrl+name+'/'+name+'.css';
 return this.LoadCss(filecss);
};
wspRoot.prototype.ModuleLoadSkin = function(mod, skin)
{
 mod = mod.toLowerCase(); skin = skin.toLowerCase();
 var filecss = this.wspUrl+mod+'/skins/'+skin+'/'+skin+'.css';
 return this.LoadCss(filecss);
};
wspRoot.prototype.ModuleLoadJs = function(name, time, async)
{
 time = this.IntVal(time);
 time = 1000*(time<1 ? 7 : time);
 async = (async ? false : true);
 name = name.toLowerCase();

 if(this.Modules[name]) return '';

 this.ModuleSet(name, false);
 this.Modules[name]['ajax'] = this.getXmlHttp();
 var mod = null;
 try
 {
  var file = this.wspUrl+name+'/'+name+'.js';
  var stok = (/^(file)|(ftp)/i.test(file) ? 0 : 200);
  var tmr = setTimeout(this.name+'.ModuleLoadTimeOut("'+name+'")', time);
  this.Modules[name]['ajax'].open('GET', file, false);
  this.Modules[name]['ajax'].send(null);
  if(this.Modules[name]['ajax'].status == stok)
  {
   clearTimeout(tmr);
   this.Modules[name]['stat'] = true;
   mod = this.Modules[name]['ajax'].responseText;   
  };
 }catch(e){};
  
 delete this.Modules[name]['ajax'];
 return mod;
};

wsp = new wspRoot('wsp');
