function loadContent(url, nodeId) {
	dojo.io.bind({
		url : url,
		handler : function (type,data,evt) {
			alert(type);
			alert(data);
			if (type == "load") {
				dojo.byId(nodeId).innerHTML = data;
			} else if (type == "error") {
				alert (data.message);
			}
		},
		changeURL: true
	});
	return false;
}

steeplesoft = {};
if (typeof steeplesoft == "undefined") {
    steeplesoft = YAHOO.namespace("steeplesoft");
}


Date.prototype.ONE_SECOND = 1000;
Date.prototype.ONE_MINUTE = Date.ONE_SECOND * 60;
Date.prototype.ONE_HOUR = Date.ONE_MINUTE * 60;
Date.prototype.ONE_DAY = Date.ONE_HOUR * 24;

steeplesoft.PictureFader = function (elementId, updateUrl, duration, nextInChain) {
    this.elementId = elementId;
    this.updateUrl = updateUrl;
    this.duration = duration;
    this.nextInChain = (typeof nextInChain != "undefined" ? nextInChain : null);

    this.callback = {
        success : this.callbackSuccess,
        failure : this.callbackFallback,
        argument : this
    }

    YAHOO.util.Connect.asyncRequest('GET', updateUrl,
    	{ success : function(o) {
    			YAHOO.util.Dom.get(elementId).innerHTML = o.responseText;
    		}
    	});
}

steeplesoft.PictureFader.prototype.nap = function (m) {
    var then = new Date(new Date().getTime() + m);
    while (new Date() < then) {}
}


steeplesoft.PictureFader.prototype.execute = function() {
    YAHOO.util.Connect.asyncRequest('GET', this.updateUrl, this.callback);
}

steeplesoft.PictureFader.prototype.callbackSuccess = function(o) {
    var pf = o.argument;
    var elem = YAHOO.util.Dom.get(pf.elementId);
    var fadeOut = new YAHOO.util.Anim(pf.elementId, { opacity: { to: 0 } }, pf.duration, YAHOO.util.Easing.easeOut);
    fadeOut.onComplete.subscribe(function() {
        elem.innerHTML = o.responseText;
        var fadeIn = new YAHOO.util.Anim(pf.elementId, { opacity: { to: 100 } }, pf.duration, YAHOO.util.Easing.easeIn);
        fadeIn.onComplete.subscribe(function() {
            //pf.nap(pf.duration);
            if (pf.nextInChain != null) {
                pf.nextInChain.execute();
            }
        });
        fadeIn.animate();
    });
    fadeOut.animate();
}

steeplesoft.PictureFader.prototype.callbackFailure = function(o) {
    alert('Failure!');
}

steeplesoft.PictureFader.prototype.setNextInChain = function(next) {
    this.nextInChain = next;
}

steeplesoft.PhotoBox = function (image, title) {
    var photobox = new YAHOO.widget.PhotoBox("photobox", {
        effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.45},
        fixedcenter:true,
        constraintoviewport:true,
        underlay:"none",
        close:true,
        visible:false,
        draggable:false,
        modal:true,
        x: (YAHOO.util.Dom.getViewportWidth() - 640) / 2,
        y: (YAHOO.util.Dom.getViewportHeight() - 480) / 2,
        photos:[{src:image,caption:title}],
        width:"640px"
    } );
    photobox.render();
    photobox.showEvent.subscribe(function() {
        alert("after show!");
        YAHOO.util.Dom.setXY("photobox",
            (YAHOO.util.Dom.getViewportWidth() - 500) / 2,
            (YAHOO.util.Dom.getViewportHeight() - 500));});
    photobox.hideEvent.subscribe(function() {
        alert("hiding!");
        clone.parent.removeChild(clone);
    });
    photobox.show();
}
var pictureDialog = null;
steeplesoft.PictureDialog = function (elem, url) {
	var pd = this;
	if (pictureDialog != null) {
		pictureDialog.hide();
	}
	this.dialog = new YAHOO.widget.Dialog("picdialog",
		{ width : "550px",
	      //xy:[((YAHOO.util.Dom.getDocumentWidth() ) / 2, YAHOO.util.Dom.getDocumentHeight() ) / 2],
		  fixedcenter : true,
		  visible : true,
		  modal : true,
		  constraintoviewport : true,
		  buttons : [ { text:"Close", handler:this.cancel, isDefault:true }]
		 } );
	pictureDialog = this.dialog;

     var callback = {
        success : this.show,
        argument : this
    }

	YAHOO.util.Connect.asyncRequest('GET', url, callback);
}

steeplesoft.PictureDialog.prototype.show = function(o) {
	YAHOO.util.Dom.get('pd_body').innerHTML = o.responseText;
	var pd = o.argument;
	pd.dialog.render();
	pd.dialog.show();
}

steeplesoft.PictureDialog.prototype.cancel = function() {
	this.hide();
}

steeplesoft.calendar = function(inputId, containerId, trigger, startMonth, selectedDate, multiSelect, showWeekdays,
        startWeekday, showWeekHeader, showWeekFooter, hideBlankWeeks) {
    this.containerId = containerId;
    this.inputId = inputId;
    this.hidden = true;

    var pos = YAHOO.util.Dom.getXY(trigger);
    var img_width = 22;
    var elem = YAHOO.util.Dom.get(containerId);

    elem.style.top  = pos[1] + "px";
    elem.style.left = pos[0] + img_width + "px";
    elem.style.position = 'absolute';

    this.calendar = new YAHOO.widget.Calendar(containerId, containerId,
        {
            pageDate: startMonth,
            selected: selectedDate,
            MULTI_SELECT: multiSelect,
            SHOW_WEEKDAYS: showWeekdays,
            START_WEEKDAY: startWeekday,
            SHOW_WEEK_HEADER: showWeekHeader,
            SHOW_WEEK_FOOTER: showWeekFooter,
            HIDE_BLANK_WEEKS: hideBlankWeeks
        });
	//this.calendar.onSelect = this.onSelect;
	//this.calendar.onBeforeSelect
	//this.calendar.selectEvent.subscribe(this.onSelect);
    this.calendar.render();
    this.calendar.inputId = inputId;


    var el = YAHOO.util.Dom.get(trigger);
    el.calendar = this.calender;
    YAHOO.util.Event.addListener(trigger, "click", this.toggle, this, true);

}

steeplesoft.calendar.prototype.toggle = function() {
    if (this.hidden == true) {
        this.calendar.show();
        this.hidden = false;
    } else {
        this.calendar.hide();
        this.hidden = true;
    }
}

//YAHOO.widget.Calendar.prototype.formatDate = function() {
steeplesoft.calendar.prototype.formatDate = function() {
        var selDate = this.getSelectedDates()[0];
        var date_separator = "/";
        var day_ = selDate.getDate();
        var day = ( day_ < 10 ) ? "0" + day_ : day_;
        var month_ = selDate.getMonth()+1;
        var month = ( month_ < 10 ) ? "0" + month_ : month_;
        var year = selDate.getFullYear();
        return year + date_separator + month + date_separator + day;
}

YAHOO.widget.Calendar.prototype.onSelect = function() {
//steeplesoft.calendar.prototype.onSelect = function() {
        var inputField = YAHOO.util.Dom.get(this.inputId);
        var selDate = this.getSelectedDates()[0];
        var date_separator = "/";
        var day_ = selDate.getDate();
        var day = ( day_ < 10 ) ? "0" + day_ : day_;
        var month_ = selDate.getMonth()+1;
        var month = ( month_ < 10 ) ? "0" + month_ : month_;
        var year = selDate.getFullYear();
        inputField.value =  year + date_separator + month + date_separator + day;
        if (inputField.onchange) {
            inputField.onchange();
        }
        this.hide();
}

steeplesoft.FormDialog = function (elem, url, width) {
	var pd = this;
	if (pictureDialog != null) {
		pictureDialog.hide();
	}
	var handleCancel = function() {
		this.cancel();
	}
	var handleSubmit = function() {
		this.submit();
	}
	var myButtons = [ { text:"Submit", handler:handleSubmit, isDefault:true },
					  { text:"Cancel", handler:handleCancel } ];

	this.dialog = new YAHOO.widget.Dialog(elem,
		{ width : width,
		  fixedcenter : true,
		  visible : true,
		  modal : true,
		  constraintoviewport : true,
		  buttons : myButtons
		 } );
     var callback = {
        success : this.show,
        argument : this
    }

	YAHOO.util.Connect.asyncRequest('GET', url, callback);
}
steeplesoft.FormDialog.prototype.show = function(o) {
	YAHOO.util.Dom.get('body').innerHTML = o.responseText;
	var fd = o.argument;
	fd.dialog.render();
	fd.dialog.show();
}

steeplesoft.FormDialog.prototype.cancel = function() {
	this.hide();
}