$.fn.extend({
	/** checking and unchecking funcitons **/
    check: function() {
        return this.each(function() { this.checked = true; });
    },
    uncheck: function() {
        return this.each(function() { this.checked = false; });
    },
    checkToggle: function() {
        return this.each(function() { this.checked != this.checked; });
    },
    /** extension to jquery to allow for the use of the checked property **/
    checked: function() {
        if (this.length > 1) {
            return this.get(0).attr('checked');
        } else if (this.length == 1) {
            return this.attr('checked');
        } else {
            return false;
        }
    },
    tagName: function() {
        return (this.length > 0 ? this.get(0).tagName : 'No Element Found');
    },
    /** adding and removing a message formated with the jquery ui classes **/
    addErrorMsg: function(msg) {
        $(this).html('<div class="ui-widget"><div class="ui-state-error ui-corner-all" style="padding: 0 .7em;"><p><span class="ui-icon ui-icon-alert" style="float:left; margin-right: .3em;"></span>' + msg + '</p></div></div>').slideDown(300);
    },
    removeErrorMsg: function() {
        $(this).slideUp(300);
    },
    createSelect: function(name, selectValues, value, options) {
        if (typeof value == 'undefined') value = '';

        if (typeof options == 'undefined') options = new Object;
        if (typeof options['id'] == 'undefined') options['id'] = name;
        if (typeof options['multiple'] == 'undefined') options['multiple'] = false;
        if (typeof options['size'] == 'undefined') options['size'] = 1;

        selectHtml = '<select name="' + name + '" id="' + options['id'] + '"' + (options['multiple'] ? ' multiple="multiple"' : '') + '>';
        $.each(selectValues, function(value, text) {
            selectHtml += '<option value="' + value + '">' + text + '</option>';
        });

        $(this).html(selectHtml + '</select>');
        $('#' + options['id']).val(value);
        return this;
    }
});

$.extend($.ui.dialog.prototype.options, {
    modal: true,
    autoOpen: false
});

function OpenWindow(href, name, options) {
    return window.open(urlRoot + href, name, options);
    //return false;
}

/* show / hide a div */
function HideAndSeek(target) {
    var t = document.getElementById(target);
    if (! t) { /*alert('can\'t find');*/ return false; }
    if (t.style.display == '') {
        t.style.display = 'none';
    } else {
        t.style.display = '';
    }
    return true;
}

/* swap image */
function SwapImage(imgName, firstImg, secondImg) {
  if (document.images) {
    if (firstImg != "none" && secondImg != "none") {
			if (document.images[imgName].src == urlRoot + firstImg) {
				document.images[imgName].src = secondImg;
			} else if (document.images[imgName].src == urlRoot + secondImg) {
				document.images[imgName].src = firstImg;
			} else {
      	document.images[imgName].src = firstImg;
			}
    }
  }
}

/*
link to change the menu
<a href="javascript:;" onClick="HideAndSeek('studentLogin'); SwapImage('bullStudentLogin', '/images/menu_bullet-down.gif', '/images/menu_bullet.gif');">
*/
