/*
 * Set and get class variables
 */
$.fn.setcv = function(cvn, cvv) {
	this.each(function() {
		var classes = new String($(this).attr('class'));
		// Delete existing class variables with this name
		if (classes != '') {
			var classarr = classes.split(' ');
			for (ct = 0; ct < classarr.length; ct++) {
				if (classarr[ct].substr(0,cvn.length) == cvn) {
					$(this).removeClass(classarr[ct]);
					break;
				}
			}
		}
		$(this).addClass(cvn+cvv);
	})
        return this;
};

$.fn.getcv = function(cvn) {
	var ret = null;
	this.each(function() {
		var classes = new String($(this).attr('class'));
		// Delete existing class variables with this name
		if (classes != '') {
			var classarr = classes.split(' ');
			for (ct = 0; ct < classarr.length; ct++) {
				if (classarr[ct].substr(0,cvn.length) == cvn) {
					ret = classarr[ct].substr(cvn.length);
					return false;
				}
			}
		}
		return true;
	})
	return ret;
};

$.fn.stddialog = function(button, opts) {
    this.each(function() {
        var stdopts = {
            autoOpen: false,
            modal: true,
            zIndex: 13000,
            width: 450,
            buttons: $.extend(button, {"Cancel": function(){$(this).dialog('close')}}),
            open: function() {
                $(this).find('input[type=text],select,textarea').first().focus();
            }
        }
        opts = $.extend(stdopts, opts);
        $(this).dialog(opts);
    })
    return this;
}



$.fn.mypop = function (popmenu) {
    if ($(popmenu).size() == 0) return;
    this.each(function() {
        $(this).click(function(e) {
            e.stopPropagation();
            if (ignorenextclick) {
                ignorenextclick = false;
                return false;
            }
            popelement = $(this);
            $('.popup').css('display', 'none');
            $(popmenu).css('display', 'block').css('left', e.pageX-5).css('top',e.pageY-5).css('z-index', '50000');
            return false;
        }).css('cursor', 'pointer');
    })
}
