﻿/*
* Get the class string from the object
* @param object o the DOM object 
* @return string the class string of the object
*/
//var getClass=function(o){
var getClassName = function (o) {
    return o.className;
}
/*
* Set the class string from the object
* @param string cls the class string to be set
* @param object o the DOM object where
* the class string to be set to
*/
//var setClass=function(o){
var setClassName = function (cls, o) {
    o.className = cls;
}
/*
* Parse the classes list to array by split(" ")
* @param string cl a string of class or a list of classes
* @return array with the element of class name
*/
var getClassArray = function (cl) {
    if (cl && typeof (cl) == "string")
        return cl.split(" ");
    else return cl;
}
/*
* If the class is listed in the classes list ,return true
* @param string cl a single class name 
* @param string cls class name list
* @return true if the class is listed 
* in the classes list.else return false.
*/
var matchClass = function (cl, cls) {
    if (!cls) return false;
    cls = getClassArray(cls);
    for (var c in cls) if (cl == cls[c]) return true;
    return cl == cls;
}
/*
* remove one of the classes from the object
* @param string cl a single class name 
* @param string cls class name list
*/
var removeClass = function (cl, o) {
    var cls = getClassArray(getClassName(o));
    var _cls = "";
    for (var i in cls) if (cl != cls[i]) _cls += " " + cls[i];
    setClassName(_cls, o);
}
/*
* add a class to the object
* @param string cl a single class name 
* @param object o the DOM object
* where the class string to be ADD to
*/
var addClass = function (cl, o) {
    removeClass(cl, o);
    setClassName(getClassName(o) + " " + cl, o);
}
