/* add class to the existing element's class attribute */
//---------------------------------------------------------------------------------
function addElementToClass(element, className){
    // get value of class attribute
    this._elementClass = _getElementClassMembership(element);
    // check class already exists with the element class attribute's value
    this._classMembership = _checkClassMembership(this._elementClass, className);
    // if not exist, add new class to the element's class attribute
    if(this._classMembership == -1){
        this._elementClass += " " + className;
       _setElementClassMembership(element, this._elementClass);
    }
}
//----------------------------------------------------------------------------------

/* remove the class from the existing classes of element class attribute */
//----------------------------------------------------------------------------------
function removeElementFromClass(element, className){
    // get value of class attribute
    this._elementClass = _getElementClassMembership(element);
    // check class already exists with the element class attribute's value
    this._classMembership = _checkClassMembership(this._elementClass, className);
    // if exist, remove the class from the element's class attribute
    if(this._classMembership != -1){
        var classes = this._elementClass.split(' ');
        classes.splice(this._classMembership, 1);
        this._elementClass = classes.join(' ');
       _setElementClassMembership(element, this._elementClass);
    }
}
//----------------------------------------------------------------------------------    

/* check for the class whether it already exists with the element or not */
//----------------------------------------------------------------------------------
function _checkClassMembership(elementClass, c){
    var temp = elementClass.split(' ');
    for (var i = 0; i<temp.length; i++){
        if(temp[i].trim() == c.trim()){
            return i;
        }
    }
    return -1;
}
//----------------------------------------------------------------------------------

/* get the value of element's class attribute */
//----------------------------------------------------------------------------------
function _getElementClassMembership(element){
    //return document.getElementById(elementId).className;
    return element.className;
}
//----------------------------------------------------------------------------------

/* set the value of element's class attribute */
//----------------------------------------------------------------------------------
function _setElementClassMembership(element, c){
    element.className = c;
}
//----------------------------------------------------------------------------------

// strip spaces 
//----------------------------------------------------------------------------------
String.prototype.trim = function() {
    return this.replace(/^\s+/,'').replace(/\s+$/,'');
}
//----------------------------------------------------------------------------------