///////////////////////////////////////////////////////////////////////////////////////
// The class-wrapper, usually is not created by obvious image
function CssClassesHandler(object) { this.object = object }

CssClassesHandler.prototype = {
    object      : null,

    // Returns all classes of an element in the form of a array of lines
    all         : function() {
                    return this.object.className.split(/\s+/)
                },

    // checks if the given className exists in the classes.
    exists      : function(className) {
                    var classes = this.all()
                    for(var i = 0; i < classes.length; i++)
                        if(classes[i] == className) return true
                    return false
                },

    // Appoints a class to an element
    add         : function(className) {
                    var classes = this.all()
                    for(var i = 0; i < classes.length; i++)
                        if(classes[i] == className) return
                    this.object.className = this.object.className + " " + className
                },

    // Deletes a class from appointed to an element.
    // It is possible to specify both a name of a class,
	// and regular expression which will be separately compared to each of the appointed classes.
    remove      : function(className) {
                    var classes = this.all()
                    var cn = ""
                    for(var i = 0; i < classes.length; i++) {
                        var isMatch = (typeof className.test == "function")
                            ? className.test(classes[i])
                            : (classes[i] == className)
                        if(!isMatch) cn = cn + " " + classes[i]
                    }
                    this.object.className = cn.substr(1)
                },

    // Appoints/deletes a class depending on bool parameter "state"
    set         : function(className, state) {
                    if(state)
                        this.add(className)
                    else
                        this.remove(className)
                },

    // Appoints to an element a class if it still is not appointed, otherwise deletes
    flip        : function(className) {
                    if(this.exists(className))
                        this.remove(className)
                    else
                        this.add(className)
                }
}

// The function creating a class-wrapper for the given element
function CssClasses(object) {
    return new CssClassesHandler(object)
}


///////////////////////////////////////////////////////////////////////////////////////
// The class-wrapper
function CssSizesHandler(DOMObject) {this.object = DOMObject};

CssSizesHandler.prototype =
{
	object 			: null,
	// given width for element
	getWidth		: function()
	{
		var width = 0;
		width += this.object.offsetWidth;
			
		var mLeft = parseInt(getCurrentStyle(this.object, 'marginLeft'));
		var mRight = parseInt(getCurrentStyle(this.object, 'marginRight'));
		var pLeft = parseInt(getCurrentStyle(this.object, 'paddingLeft'));
		var pRight = parseInt(getCurrentStyle(this.object, 'paddingRight'));
		
		if (!isNaN(mLeft) && (mLeft>0)) width += mLeft;
		if (!isNaN(mRight) && (mRight>0)) width += mRight;
		if (!isNaN(pLeft) && (pLeft>0)) width += pLeft;
		if (!isNaN(pRight) && (pRight>0)) width += pRight;

		return width;
	},
	
	getHeight		: function()
	{
		var height = 0;
		height += this.object.offsetHeight;
		
		var mTop = parseInt(getCurrentStyle(this.object, 'marginTop'));
		var mBottom = parseInt(getCurrentStyle(this.object, 'marginBottom'));
		var pTop = parseInt(getCurrentStyle(this.object, 'paddingTop'));
		var pBottom = parseInt(getCurrentStyle(this.object, 'paddingBottom'));
		
		mTop = isNaN(mTop)?0 : mTop;
		mBottom = isNaN(mBottom)?0 : mBottom;
		pTop = isNaN(pTop)?0 : pTop;
		pBottom = isNaN(pBottom)?0 : pBottom;
		
		height+= mTop+ mBottom+ pTop+ pBottom;
		return height;
	}
}

// The function creating a class-wrapper for the given element
function CssSizes(DOMObject)
{
	return new CssSizesHandler(DOMObject);
}
///////////////////////////////////////////////////////////////////////////////////////
function init_datepicker(id, dformat) {
  $(function() {
  	$('#'+id).datepick({
      dateFormat: dformat
    });
  });
}


