
function setupDisplayPage(){
	var relatedNewsPane = 
            new dijit.TitlePane({
                title: 'Related News (click here)',
               open: false,
               class: 'dojoH3'
            }, dojo.byId("relatedNews"));
    var relatedPhotosPane = 
            new dijit.TitlePane({
                title: 'Related Photos (click here)',
               open: false,
               class: 'dojoH3'
            }, dojo.byId("relatedPhotos"));
    var relatedVideosPane = 
            new dijit.TitlePane({
                title: 'Related Videos (click here)',
               open: false,
               class: 'dojoH3'
            }, dojo.byId("relatedVideos"));
    var relatedBlogsPane = 
            new dijit.TitlePane({
                title: 'Related Blogs (click here)',
               open: false,
               class: 'dojoH3'
            }, dojo.byId("relatedBlogs"));
    
    
    var commentPane = 
            new dijit.TitlePane({
                title: 'Add a comment (click here)',
               open: false,
               class: 'dojoH3'
            }, dojo.byId("commentFormDiv"));
    
	dojo.connect(dojo.byId('commentForm'), 'onsubmit', 'commentFormSubmitted');
	dojo.connect(dojo.byId('commentContent'), 'onfocus', 'emptyCommentContent');
	//console.log("comment connected");
}

function emptyCommentContent()
{
	dojo.byId('commentContent').value= '';
}
function isEmpty(aTextField) {
   if ((aTextField.value.length==0) ||
   (aTextField.value==null)) {
      return true;
   }
   else { return false; }
}	

function commentFormSubmitted(event){
	if(isEmpty(dojo.byId("author")) || isEmpty(dojo.byId("commentContent")) 
		|| isEmpty(dojo.byId("email")))
	{
		dojo.byId("commentMessage").innerHTML = "Please fill out all the fields";
		dojo.stopEvent(event);
		return;
	}
	else if(dojo.byId("commentMessage") != "undefined")
	{
		dojo.byId("commentMessage").innerHTML = '';
	}
	var kw = {
		url: window.location,
		load: function(data){
			//console.log("data is" + data);
			dojo.byId('comments').innerHTML = data;
		},
		error: function(data){
			console.debug("An error occurred: ", data);
		},
		timeout: 2000,
		form: "commentForm"
	};
	
	dojo.xhrPost(kw);
	dojo.byId("submitComment").disabled = "true";
	dojo.byId("submitComment").value = "Comment Posted!";
	
	//console.log("just did post");
	
	dojo.stopEvent(event);

}
dojo.require("dijit.TitlePane");
dojo.addOnLoad(setupDisplayPage);
