//Copyright 2007 Roman Ardern-Corris
//Licenced to 3legs.com

/*
   Defines a common ancestor for all ligo components

   Also exports the extend method so that inheritance works in a pseudo classical way

*/

function ligoCommon (paramsObj) {

   this._init(paramsObj);

}

function extend (subclass, superclass) {
    //function for extending a class

   function Dummy() {}
   Dummy.prototype = superclass.prototype;
   subclass.prototype = new Dummy();
   subclass.prototype.constructor = subclass;
   subclass.superclass = superclass;
   subclass.superproto = superclass.prototype;
}


ligoCommon.prototype._init = function (paramsObj) {
   //Standard init method

   //we are going to trust the user and just asign the vars passed in paramsObj

   for (var i in paramsObj) {
      this[i] = paramsObj[i];
   }

   //alert(this.instanceName);

}

String.prototype.escapeHTML = function () {                                       
   return(                                                                 
      this.replace(/&/g,'&amp;').                                         
      replace(/>/g,'&gt;').                                           
      replace(/</g,'&lt;').                                           
      replace(/"/g,'&quot;')                                         
   );                                                                     
};


function getElementsByClassName(classname, node) {
    if (!node) {
        node = document.getElementsByTagName("body")[0];
    }
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");

    for(var i=0,j=els.length; i<j; i++) {
        if (re.test(els[i].className)) {
            a.push(els[i]);
        }
    }
        
    return a;
}

ligoCommon.prototype.array_to_param = function (param_name, in_array) {
    var query_string = '';
    
    for (var i=0; i<in_array.length; i++) {
        query_string += param_name + '=' + in_array[i] + '&';
    }
    
    return(query_string);
}
