 /* Utility to set up the prototype, constructor and superclass properties to
 * support an inheritance strategy that can chain constructors and methods.
 *
 * @param {Function} subclass   the object to modify
 * @param {Function} superclass the object to inherit
 */

var CS = window.CS || {};

CS.namespace = function(ns) 
{
    if (!ns || !ns.length) 
    { return null; }

    var levels = ns.split(".");
    var nsobj = CS;

    // YAHOO is implied, so it is ignored if it is included
    for (var i=(levels[0] == "CS") ? 1 : 0; i<levels.length; ++i) 
    {
        nsobj[levels[i]] = nsobj[levels[i]] || {};
        nsobj = nsobj[levels[i]];
    }
 
    return nsobj;
};

CS.extend = function(subclass, superclass) 
{
    var f = function() {};
    
    f.prototype = superclass.prototype;
    subclass.prototype = new f();
    subclass.prototype.constructor = subclass; 
    subclass.superclass = superclass.prototype;
    
    if (superclass.prototype.constructor == Object.prototype.constructor) 
    { superclass.prototype.constructor = superclass; }
};

// Adding Codestars namespaces
CS.namespace("kernel");
CS.namespace("DOM");
CS.namespace("validation");
CS.namespace("controlpannel");
CS.namespace("plugins");
CS.namespace("config");

// Here we add some JavaScript core functionality
function trim(value) 
{
  value = value.replace(/^\s+/,'');
  value = value.replace(/\s+$/,'');
  return value;
}

function ReplaceAll(text, strA, strB)
{
    return text.replace( new RegExp(strA,"g"), strB );    
}

function mergeObjects(a, b)
/* Merge two objects */
{
	for( i in a )
	{
		for( j in b )
		{
			if(i==j)
			{
				for( k in b[j] )
				{
					a[i][k] = b[j][k];
				}
			}
		}
	}
}

function IsNumeric(sText)
{
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			IsNumber = false;
		}
	}
	
	return IsNumber;
   
 }
 
 function strpos(haystack, needle, offset)
 {
    var i = (haystack+'').indexOf( needle, offset ); 
    return i===-1 ? false : i;
}

function htmlentities(texto)
{
    var i,carac,letra,novo='';
    for(i=0;i<texto.length;i++){
        carac = texto[i].charCodeAt(0);
        if( (carac > 47 && carac < 58) || (carac > 62 && carac < 127) ){
            novo += texto[i];
        }else{
            novo += "&#" + carac + ";";
        }
    }
    return novo;
}
