dojo.addOnLoad(function(){
    /* Shortcuts */
    dojo.connect(document, "onkeydown", function(event){
        //Ctrl + S -> Save
        if (event.ctrlKey && event.keyCode == 83) {
        	try{
				event.preventDefault();
	            dojo.byId(submitbuttonid).click();
			}catch(e){}
        }
        //Escape -> Cancel
        if (event.keyCode == 27) {
            try{
	            event.preventDefault();
				dojo.byId(cancelbuttonid).click();
			}catch (e){}
        }				
    });
});//end of addOnLoad

function markWorking(divid){
	dojo.byId(divid).innerHTML = "<br /><br /><img src=\"" + dbPath + "/working.gif\" />";
}

function getSuggestions(matchingString, iqspace){
	dojo.byId("suggestions").style.display = "block";
	dojo.byId("suggestions").innerHTML = "<img src=\"" + dbPath + "/working.gif\" />";
	dojo.xhrGet({
    	url: dbPath + "/checkForSimilarQuestions?openagent&question=" + escape(matchingString) + "&iqspace=" + escape(iqspace),
    	load: function(data){
			if (data == ""){
				dojo.byId("suggestions").innerHTML = "<b>There are no matching questions in this IQSpace</b>";
			}else{
				dojo.byId("suggestions").innerHTML = "<b>Similar Questions</b><br />" + data;
			}
	    }
	});
}

function followQuestion(unid, user, buttonid){
	dojo.byId(buttonid).style.display = "none";
	dojo.xhrGet({
    	url: dbPath + "/followQuestion?openagent&unid=" + unid + "&user=" + escape(user),
    	load: function(data){
			//do nothing
	    }
	});
}

function unfollowQuestion(unid, user, buttonid){
	dojo.byId(buttonid).style.display = "none";
	dojo.xhrGet({
    	url: dbPath + "/unfollowQuestion?openagent&unid=" + unid + "&user=" + escape(user),
    	load: function(data){
			//do nothing
	    }
	});
}