
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";
	}
	else
	{
		parseSearchString();
	}



}



      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 count = 0;
			var pairs=unescape(location.search.substring(1).replace(/\+/g," ")).split('&');
			
			var searchstring = "";
			var searchstring_flag = 0;
			var showcatalog = "";
			var showcatalog_flag = 0;
			

			//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 (pair[0] == "searchstring"){
					searchstring_flag=1;
					searchstring=pair[1];
				}
			
				if (pair[0] == "showcatalog"){
					showcatalog_flag=1;
					showcatalog=pair[1];
				}
			}		

	          	


			if(searchstring_flag == 1) {
				top.main.location.href = '/dotnet/application/coursesearch.aspx?searchareas=1,2,3,4,5&organization_id=' + organization_id + '&searchstring=' + searchstring;
			}

			if(showcatalog_flag == 1 && searchstring_flag != 1){
				top.main.location.href = '/ihtml/application/student/course_catalog_notloggedin.ihtml?organization_id_t=' + organization_id + '&language_type_id_t=' + language_type_id + '&company_id=' + company_id;
			}

			

      }

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');
}
      
