
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return "";
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}



function IsLoggedIn(){

	var login = getCookie("cookiesetnp");
	
	if (login == "true"){
		top.information.location.href="/ihtml/application/student/information.ihtml";
	}



}

      function parseSearchString()
      {
			/*
			This line does several things in one hit
			substring(1) - get the querystring portion after the question mark
			unescape - returns the data to 'readable' text
			replace(/\+/g," ") - change any "+" symbols with a " " (space)
			split('&') - take the data and create an array using any ampersands as delimiters
			e.g., this is the URL http://www.mypage.com/pageone.htm?courseid=123&SecondValue=abc[/url]
			would come out as:
			["courseid=123","SecondValue=abc"]
			*/
			var QueryString = "";
			var count = 0;
			var pairs=unescape(location.search.substring(1).replace(/\+/g," ")).split('&');
			var req_url = "";
			var req_url_flag = 0;
			
			//req_url = getCookie('req_url');

			//take the new array and loop through it
			for (var i=0;i<pairs.length;i++)
			{
				//split each part of the array using the "=" as the delimeter
          		//thus, "courseid=123" becomes an array : ["courseid","123"]

          		var pair = pairs[i].split('=');
			if (i == 0) {
				if (req_url == "") {
					if (pair[0] == "req_url"){
						req_url_flag=1;
					}
				}
			}

	          	
          		//create an object using the created array:
          		//this["one"] = "123";
          		this[pair[0]]=pair[1];
	          	
          		// Storing the whole querystring passed in a variable called QueryString

          		if (count == 0)
          		{

				QueryString = QueryString + pairs[i];
          			count = 1;
				if (req_url_flag == 1) {
					req_url = pair[1];
					if (pair.length > 2){
						req_url = req_url + "=" + pair[2];
					}
				}
          		}
          		else
          		{
          			QueryString = QueryString + "&" + pairs[i];
				if (req_url_flag == 1) {
					req_url = req_url + "&" + pairs[i];
				}
          		}
	          	          	
			}

			if (req_url == "") {
				req_url = getCookie('req_url');
				//alert('req_url cookie requested');
			}

			if(req_url != "" && req_url != "-999")          		
			{
          			top.main.location.href = req_url
				//alert('main set to ' + req_url);
			}

			if(QueryString != "" && req_url_flag != 1)
			{
          			top.main.location.href = '/ihtml/application/student/interface.heart/coursesearchheart.aspx?organization_id=' + organization_id + '&' + QueryString;
				//alert('main set to ' + QueryString);
			}

      }

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 eraseCookie(name)
{
	createCookie(name,"",-1);
}

function eraseAllCookies(){
eraseCookie('req_url');
eraseCookie('member_id');
eraseCookie('organization_id');
eraseCookie('member_company_id');
eraseCookie('member_auth');
eraseCookie('cookiesetnp');
eraseCookie('qsv');
eraseCookie('owc');
eraseCookie('proctor_authenticated');
}
      
