
$(function(){
	
	/*var oldLinks = $('a[href="/current-students/courses/schedule.cfm"]');
	
	$.each(oldLinks, function(i, n){
		$(n).attr({"href":"https://webproc.mnscu.edu/registration/search/basic.html?campusid=211"});
	});
	*/
	$('a[href^="https://webproc.mnscu.edu/registration"]').filter(":not(.nodialog)").click(function(e){
		
		
		if (bigEnough()) {
			e.preventDefault();
		} else {
			return true;
		}
		
		
		windowOpen = true;
		
		$(window).bind('beforeunload', function() {
			if (windowOpen)
			return "Going 'back' any further will cause you to leave this page.";
		});
		
		
		var $scheduleDialog = $('<div id="scheduleDialog"></div>').dialog({ 
			autoOpen:false,
			closeOnEscape: true,
			draggable: false,
			resizable: false,
			modal: true,
			height: '800',
			width: '1100',
			title: 'Course Search and Registration',
			zindex: 1000,
			position: 'center',
			buttons: {
				"Close": function(e){
					$scheduleDialog.dialog("close");
					
					
				},
				"Open in new window": function(e) {
					window.open($iframe.attr("src"), 'scheduleWindow', 'height=768, width=1024');
				}
		
			}
		});

		$scheduleDialog.bind("dialogclose", function(){
			windowOpen = false;
		});

		var $iframe = $('<iframe id="extIframe" width="100%" height="100%" frameborder="0" scrolling="auto"/>');
		
		$iframe.attr({"src":e.target.href});
		$scheduleDialog.html($iframe);
		$scheduleDialog.dialog("open");
		
		var $inst = $('<div id="instBanner" />');
		$inst.css({
			"backgroundColor":"#E88815",
			"color":"#ffffff",
			"height":"20px",
			"width":"100%",
			"font-size":"1em",
			"text-align": "center",
			"vertical-align":"middle",
			"position":"absolute",
			"top":"30",
			"left":"0"
			
		});
		//Note: 
		
		$inst.html('To navigate this internal window you may use the normal "Back" and "Forward" buttons in your browser');
		
		$scheduleDialog.prepend($inst);
		
		if ($.cookie("NoNotes") == null) {
			var $notes = $('<div id="notesPopup" />');
			$notes.css({
				"backgroundColor":"#E88815",
				"color":"#ffffff",
				"height":"100%",
				"width":"100%",
				"overflow":"hidden",
				"font-size":"1.8em",
				"text-align": "center",
				"vertical-align":"middle"
				
			});
			//Note: To navigate this internal window you may use the normal "Back" and "Forward" buttons in your browser
			
			$notes.html('To better serve the needs of our students we are now using the MnSCU course search tool');
			
			var $notesDialog = $("<div />").dialog({
				autoOpen:false,
				closeOnEscape: true,
				draggable: false,
				resizable: false,
				modal: true,
				height: '250',
				width: '400',
				title: 'Instructions',
				zindex: 1001,
				position: 'center'
				
			});
			
			$notesDialog.css({
				"backgroundColor":"#E88815"
			});
			
			$notesDialog.html($notes);
			$notesDialog.dialog("open");
			
			$notesDialog.bind("dialogclose", function(){
				$.cookie("NoNotes", "true", {expires: 1, path: '/'});
			});
		}
		
		
	});	
});


function bigEnough() {
	var winW = 0
	var winH = 0;
	
	if (document.body && document.body.offsetWidth) {
	 winW = document.body.offsetWidth;
	 winH = document.body.offsetHeight;
	}
	
	if (document.compatMode=='CSS1Compat' &&
	    document.documentElement &&
	    document.documentElement.offsetWidth ) {
	
			winW = document.documentElement.offsetWidth;
			winH = document.documentElement.offsetHeight;
	}
	
	if (window.innerWidth && window.innerHeight) {
		winW = window.innerWidth;
		winH = window.innerHeight;
	}

	if (winW >= 1100 && winH >= 500) {
		return true;
	} else {
		return false;
	}

}
