//
//  General framework
//  LightStorage - Simple MP3 search engine
//  (P) 2010
//  Pou Le Serg
//

function $ (ObjectID) {
  if (ObjectID == null) {
    alert ("Undefinied call to $. Parameter is null.");
    return '';
  }
  return document.getElementById (ObjectID);
}

// --- strings

function ltrim (s) {
  return s.replace(/^\s+/, '');
}

function rtrim (s) {
  return s.replace(/\s+$/, '');
}

function trim (s) {
  return rtrim(ltrim(s));
}

// --- styles

function getElementComputedStyle (elem, prop) {
  if (typeof elem != "object") elem = $ (elem);
  // external stylesheet for Mozilla, Opera 7+ and Safari 1.3+
  if (document.defaultView && document.defaultView.getComputedStyle) {
    if (prop.match(/[A-Z]/)) prop = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
    return document.defaultView.getComputedStyle(elem, "").getPropertyValue(prop);
  }
  // external stylesheet for Explorer and Opera 9
  if (elem.currentStyle) {
    var i;
    while ((i = prop.indexOf("-")) != -1) prop = prop.substr(0, i) + prop.substr(i + 1, 1).toUpperCase() + prop.substr(i + 2);
    return elem.currentStyle[prop];
  }
  return "";
}

function RealValue (elem, prop) {
  var CurValue = getElementComputedStyle (elem, prop);
  return parseInt (CurValue.substring (0, CurValue.length - 2));
}

// ---

function getXYOffset (GetCurObj) {
  var TNObj = GetCurObj;
  var x = y = 0;
  while (TNObj) {
    x += TNObj.offsetLeft;
    y += TNObj.offsetTop;
    TNObj = TNObj.offsetParent;
  }
  return { "x" : x, "y" : y };
}

// --- classes

function GetThisObject (ObjNameOrItself) {
  if (typeof (ObjNameOrItself) != "object") {
    return $ (ObjNameOrItself);
  } else {
    return ObjNameOrItself;
  }
}

function AddClass (TCurElem, TClassName) {
  ClassNameWSpace = " " + TClassName;
  if (!GetThisObject(TCurElem).className.match(ClassNameWSpace)) {
    GetThisObject(TCurElem).className += ClassNameWSpace;
  }
}

function RemoveClass (TCurElem, TClassName) {
  ClassNameWSpace = " " + TClassName;
  GetThisObject(TCurElem).className = GetThisObject(TCurElem).className.replace(ClassNameWSpace, '');
}


//
//  DByte64
//
