function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}

function readQuery(name)
{
  var queryValue = "";
  var search = name + "=";
  if(location.search.length > 0)
  { 
    offset = location.search.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = location.search.indexOf("&", offset);
      if (end == -1) end = location.search.length;
      queryValue = unescape(location.search.substring(offset, end));
    }
  }
  return queryValue;
}

function writeCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire + "; path=/";
}

var q=readQuery("css");
var cc=readCookie("css");
var expire=readQuery("days");
if (q=="nomenus"){
	q="http://itde.vccs.edu/uploads/css/navigation-free.css";
}
if (q=="reset"){
	q="";
	cc="";
	expire="";
	writeCookie("css","");
}
// some sanity checks on the value of q provided
if (q.indexOf("http:")!=0){  // make sure it begins with http:
	q="";
}
var notincluded=new Array(">","<","javascript");
var teststring = q.toLowerCase();
for (var i=0; i<notincluded.length; i++){
	if (teststring.indexOf(notincluded[i])!=-1){
		q="";
	}
}
if (expire!=""){
	expire=eval(24*expire);
}
else{
	expire=null;
}
if (q!=""){
	writeCookie("css",q,expire);
	cc=q;
}
if (cc!=""){
	document.writeln("<link rel=\"Stylesheet\" type=\"text/css\" href=\"" + cc + "\">");
}
//window.status="q:" + q + "/cc:" + cc;

