// Globals
////////////////////////////////
var d = document;

function LTrim(strText){while(strText.substring(0,1)==' ')strText = strText.substring(1, strText.length);return strText;}
function RTrimcook(strText){while(strText.substring(strText.length-1,strText.length)==' ')strText=strText.substring(0, strText.length-1);return strText;}
function Trim(strText){return RTrimcook(LTrim(strText));}

function buildKeywordSearch()
{
  //var f1=document.Form1,f2=document.Form2,f3=document.Form3,bits=35,oneselected=false,fc;
  var f1=document.Form1,f4=document.Form4,fc;
  f1.b.value='';
  
   f1.k.value=Trim(f4.SS.value).split(' ').join(',');
    if(f1.k.value.length==0){
      alert('Please enter a few keywords before beginning your search.');
      f4.SS.focus();
      f4.SS.select();
    } else {
      f1.submit();
    }
 
return false;
}

// Cookie functions
////////////////////////////////
setLang = function(f) {
	if(f) {
		createCookie("rklang",f, 365);
	}
}


getLang = function() {
  return (readCookie("rklang")) ? readCookie("rklang") : "en";
}

createCookie = function(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  d.cookie = name+"="+value+expires+"; path=/";
}

readCookie = function(name) {
  var nameEQ = name + "=";
  var ca = d.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 checkLanguageSelection(url)
{
	var lang="";
	lang = getLang();
	if (lang == "fr")
	{
		document.location.href = url;
	}
}
function redirectToFrench(url)
{
	setLang("fr");
	document.location.href = url;
	
}
function redirectToEnglish(url)
{
	setLang("en");
	document.location.href = url;
	
}
////////////////////////


goList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("navigation");

		//for (i=0; i<navRoot.childNodes.length; i++) {
		try {
			node = navRoot.childNodes[0].childNodes[0];
			
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
					//alert (this.className);
				}
				node.onmouseout=function() {
				  this.className=this.className.replace(" over", "");
				}
			}
		}
		catch (err) {}
	}
}

function goSurvey(link) {
	urls = ["http://kellogg.inquisiteasp.com/cgi-bin/qwebcorporate.dll?idx=NP2JWN",
"http://kellogg.inquisiteasp.com/cgi-bin/qwebcorporate.dll?idx=FK7KK5",
"http://kellogg.inquisiteasp.com/cgi-bin/qwebcorporate.dll?idx=HY2QJT"]
	link.href = urls[parseInt(Math.random()*3)];
}


// Check for login cookie
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 null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}
var tmprkuid=getCookie("rkuid");
var uidcheck="";
// If the cookie exists, and is not blank or zero, the user is logged in
   if(tmprkuid){
      if(tmprkuid=="0" || tmprkuid==""){
         uidcheck="";
      } else {
         uidcheck=tmprkuid;
      }
   } else {
      uidcheck="";
   }
window.onload=goList;
