﻿function Go_Click() {
    document.forms[0].submit();
}
function clearSearchBox() {
    var searchTxtBox = document.getElementById("txtSearch");
    searchTxtBox.value = "";
}
function addCourse(cid) {
    var x = readCookie('courseList');
    if (x) {
        var arrCourseList = x.split('+');
        var bDuplicate = false;
        for (courseID in arrCourseList) {
            if (arrCourseList[courseID] == cid.toString()) {
                bDuplicate = true;
            }
        }
        if (!bDuplicate) {
            x += "+" + cid;
        }        
    }
    else {
        x = cid;
    }
    createCookie('courseList',x,1);
}
function deleteCourse(cid, searchType) {
    var x = readCookie('courseList');
    if (x) {
	    x = x.replace(cid, "");
	    x = x.replace("++", "+");
	    if (x.lastIndexOf("+") == x.length-1) {
	        x = x.substr(0,x.length-1);
	    }
	    if (x.length == 0) {
	        createCookie('courseList',x,-1);
	    }
	    else {
	        createCookie('courseList',x,1);
	    }
    }
    document.location = "search.aspx?searchType=" + searchType;
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function checkEnter(e) {
    var characterCode;
    if (e && e.which) {
        e = e;
        characterCode = e.which;
    }
    else {
        e = event;
        characterCode = e.keyCode;
    }
    alert (characterCode);
    if(characterCode == 13) {
        document.forms[0].submit();
        return false;
    }
    else {
        return true;
    }
}