var TransferHome_Class = function() {

	this.init();

}

TransferHome_Class.prototype.init = function() {

	this._assignEvents();
	
}

TransferHome_Class.prototype._assignEvents = function() {

	this._setGeneralInfo();
	
	this._setSideBySide();
	
	this._setInteractiveForms();
	
}

TransferHome_Class.prototype._setSideBySide = function() {
	
	this.sbsMajors = $("a.sbsMajors");
		
	this.sbsMajors.bind("click", function() {
		
		var elId = String(this.id).split("_")[1];
		
		location.href = "sidebyside.asp?major=" + elId;
		
	});
		
}

TransferHome_Class.prototype._setInteractiveForms = function() {
	this.infoMajors = $("a.infoMajors");
	
	this.infoMajors.bind("click", function() {
		
		var elId = String(this.id).split("_")[1];
		
		location.href = "interactive.asp?major=" + elId;
		
	});
}

TransferHome_Class.prototype._setGeneralInfo = function() {
	// assign events for General Information section
	
	this.giInfo = $(".genInfoLink a");
	this.giText = $(".genInfoText");
	
	var i, len; 
	
	for (i = 0, len = this.giInfo.length; i < len; i++) {
		
		$(this.giInfo[i]).bind("click", {index: i, giText: this.giText}, function() {
			
			var args = arguments[0].data;
			
			var messageText = args.giText[args.index];
			
			msgBox.display({
			    title: "General Information &gt; " + this.innerHTML + ":"
			    , displayTitle: true
			    , content: messageText.innerHTML
			    , buttons: {
			        okay: {
			            label: "Close"
			            , id: "okayButton"
			            , className: "buttonSave"
			            , oData: {ref: "okayButton"}
			            , actionFunc: function() {
			            	msgBox.close();
			            }
			        }
			    }
			});
			
			
			var docBody = {
				width: $(document.body).width()
				, height: $(document.body).height()
			};
			
			var msgWidth = 800;
			
			var cssMessage = {
				"left": (docBody.width/2 - msgWidth/2)
				, "width": msgWidth
				, "top": 70
			};
			
			msgBox.cssOverride("msgBox", cssMessage);
			
			window.scrollTo(0,0);
			
		});
			
	}
	
}

TransferHome_Class.prototype.courseJSON = function() {
		
	// create elements for input entry, 
	// create button to execute method to display escaped string
	
	var jsonBTN = Element.create("a", {id: "createJSON"}, "Create JSON String");
	
	$(document.body).append(jsonBTN);
	
	$("a#createJSON").bind("click", function() {
		
		var cPrefix = prompt("Enter the course prefix:", "");
		var cTitle = prompt("Enter the course title:", "");
		var cCredit = prompt("Enter the course credit:", "");
		var cColleges = prompt("Enter the colleges available:", "LCC,OJC,PPCC,PCC,TSJC");
		
		var objString = '[{"prefix":"' + cPrefix + '","title":"' + cTitle + '","credit":"' + cCredit + '","colleges":"' + cColleges + '"}]';
		
		console.log(objString);
		console.log(json_parse(objString));
		console.log(escape(objString));
		
	});	
		
}

TransferHome_Class.prototype.majorJSON = function() {

	var jsonBTN = Element.create("a", {id: "majorJSON"}, "Create Major JSON String");
		
	$(document.body).append(jsonBTN);
	
	$("a#majorJSON").bind("click", function() {
		var fLine = prompt("Will there be a line above?", "");
		var fText = prompt("Enter Text, if any?", "");
		var fSpace = prompt("Will there be space above?", "");
		var fSeq = prompt("Enter the sequence number:", "");
		
		var objString = '{"feature":{"line":' + (fLine == "" ? 0 : 1) + ',"text":"' + (fText == "" ? "null" : fText) + '","space":' + (fSpace == "" ? 0 : 1) + '},"sequence":' + fSeq +'}';
		
		console.log(objString);
		console.log(json_parse(objString));
		console.log(escape(objString));
		
	});
	
}

TransferHome_Class.prototype.setJSON = function() {
	
	this.courseJSON();
	$(document.body).append(Element.create("span", null, "&nbsp;&nbsp;"));
	this.majorJSON();
		
}

var transfer = new TransferHome_Class();
