$('#fb-modal').fadeIn("slow");
$('#fb-modal_contact').fadeIn("slow");

$('#mask').fadeIn("slow");
var sTerm = "";

function setTerm(term){
	sTerm = term;
}

function fungo(term){
	sTerm = term;
	loadCourses(term);
}

var http = getHTTPObject();
var http2 = getHTTPObject();
function getHTTPObject(){
    var xmlhttp;
    if(!xmlhttp && typeof XMLHttpRequest != 'undefined'){
        try {
            xmlhttp = new XMLHttpRequest();
        }catch(e){
            xmlhttp = false;
        }
    }
    return xmlhttp;
}

function loadCourses(sTerm){
    url = 'loadCourses.php';
    http.open("GET", url+"?term="+sTerm+"&rand="+Math.floor(Math.random()*99999999), true);
    http.onreadystatechange = loadCoursesResponse;
    http.send(null);
}

function loadCoursesResponse(){
    if(http.readyState == 4){
        if(http.status == 404){
        }else{
            document.getElementById('fragment-1-content').innerHTML = http.responseText;
			loadProfessors();
        }
    }
}

function loadProfessors(){
    url = 'loadProfessors.php';
    http.open("GET", url+"?term="+sTerm+"&rand="+Math.floor(Math.random()*99999999), true);
    http.onreadystatechange = loadProfessorsResponse;
    http.send(null);
}

function loadProfessorsResponse(){
    if(http.readyState == 4){
        if(http.status == 404){
        }else{
            document.getElementById('fragment-2-content').innerHTML = http.responseText;
			updateTerm();
			$('#fb-modal').fadeOut("slow");
			$('#mask').fadeOut("slow");
        }
    }
}

function updateTerm(){
    url = 'updateTerm.php';
    http.open("GET", url+"?term="+sTerm+"&rand="+Math.floor(Math.random()*99999999), true);
    http.onreadystatechange = updateTermResponse;
    http.send(null);
}

function updateTermResponse(){
    if(http.readyState == 4){
        if(http.status == 404){
        }else{
            document.getElementById('updateTerm').innerHTML = http.responseText;
			$('#fb-modal').fadeOut("slow");
			$('#mask').fadeOut("slow");
        }
    }
}

function loadCourseInfo(sCRN, sTitle){
    url = 'courseinfo.php';
	if(sCRN == ""){	
	    http.open("GET", url+"?sTitle="+sTitle+"&term="+sTerm+"&rand="+Math.floor(Math.random()*99999999), true);
	}else{
		http.open("GET", url+"?sCRN="+sCRN+"&term="+sTerm+"&rand="+Math.floor(Math.random()*99999999), true);
	}
    http.onreadystatechange = loadCourseInfoResponse;
    http.send(null);
}

function loadCourseInfoResponse(){
    if(http.readyState == 4){
        if(http.status == 404){
        }else{
            document.getElementById('fragment-3-content').innerHTML = http.responseText;
			document.getElementById('Course_LI').style.display = 'block';
			$('#container-1 > ul').tabs('select', 2);document.getElementById('mask').style.display = 'none';
        }
    }
}

function loadCRNInfo(sCRN){
    url = 'http://online.edison.edu/eolapp/crninfo.php';
	http.open("GET", url+"?sCRN="+sCRN+"&term="+sTerm+"&rand="+Math.floor(Math.random()*99999999), true);
    http.onreadystatechange = loadCRNInfoResponse;
    http.send(null);
}

function loadCRNInfoResponse(){
    if(http.readyState == 4){
        if(http.status == 404){
        }else{
            document.getElementById('fragment-4-content').innerHTML = http.responseText;
			document.getElementById('Course_LI').style.display = 'block';
			$('#container-1 > ul').tabs('select', 3);
			document.getElementById('mask').style.display = 'none';
        }
    }
}

var q1 = new Array();
var q2 = new Array();
var q3 = new Array();
var q4 = new Array();
var q5 = new Array();

function highLight(curQuest, curStar){
	var t = 0;
	while(t != curStar){
		t ++;
		document.getElementById("q"+curQuest+"_s"+t).src = 'http://online.edison.edu/eolapp/IMAGES/star.png';
	}
}

function outLight(curQuest){
	var t = 0;
	while(t != '5'){
		t ++;
		if(window['q'+curQuest][t] != 'on'){
			document.getElementById("q"+curQuest+"_s"+t).src = 'http://online.edison.edu/eolapp/IMAGES/star_out.png';
		}
	}
}

function clickLight(curQuest, curStar){
	var t = 0;
	window['q'+curQuest] = new Array();
	while(t != curStar){
		t ++;
		window['q'+curQuest][t] = 'on';
	}
	document.getElementById('q'+curQuest).value = curStar;
	outLight(curQuest)
}
var sFragment = 0;
function loadFragment(sURL, sFragment1){
	sFragment = sFragment1;
    http.open("GET", sURL+"?rand="+Math.floor(Math.random()*99999999), true);
    http.onreadystatechange = loadFragmentResponse;
    http.send(null);
}

function loadFragmentResponse(){
    if(http.readyState == 4){
        if(http.status == 404){
        }else{
            document.getElementById('fragment-'+sFragment+'-content').innerHTML = http.responseText;
			$('#container-1 > ul').tabs('select', sFragment - 1);
			if(sFragment == 3){
			$("#tokenize2").tokenInput("http://online.edison.edu/eolapp/admin/emailList.php", {
            classes: {
                tokenList: "token-input-list-facebook",
                token: "token-input-token-facebook",
                tokenDelete: "token-input-delete-token-facebook",
                selectedToken: "token-input-selected-token-facebook",
                highlightedToken: "token-input-highlighted-token-facebook",
                dropdown: "token-input-dropdown-facebook",
                dropdownItem: "token-input-dropdown-item-facebook",
                dropdownItem2: "token-input-dropdown-item2-facebook",
                selectedDropdownItem: "token-input-selected-dropdown-item-facebook",
                inputToken: "token-input-input-token-facebook",
            	noResultsText: "No results",
            	searchingText: "Searching..."
            }
		    });
			}
			if(sFragment == 4){
				$("#accordion").accordion({ animated: 'bounceslide', autoHeight: false, collapsible: true, active: false});
			}
        }
    }
}

function loadCount(){
	sURL = 'notificationCount.php';
    http2.open("GET", sURL+"?rand="+Math.floor(Math.random()*99999999), true);
    http2.onreadystatechange = loadCountResponse;
    http2.send(null);
}

function loadCountResponse(){
    if(http2.readyState == 4){
        if(http2.status == 404){
        }else{
            document.getElementById('notificationcount').innerHTML = http2.responseText;
			setTimeout("loadCount()", 3000);
        }
    }
}
