//writes cookie to browser.
function XMwriteCookie(n,i,t){
	var ep="";
	if (t){d = new Date();d.setTime(d.getTime()+(t*86400000));
	ep = "; expires="+d.toGMTString();}document.cookie = n+"="+i+ep+"; path=/";
}

// gets and sets veriables from the query string.
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
		while(pair[1].indexOf('+') >0){
			pair[1] = pair[1].substring(0,pair[1].indexOf('+')) + ' ' + pair[1].substring(pair[1].indexOf('+') + 1);
		}
      return pair[1];
    }
  } 
 // alert('Query Variable ' + variable + ' not found');
  return null;
}

//function that returns the value of a cookie or null if the cookie doesn't exist.
function readCookie(name){
	eval('var re=/^('+escape(name)+')=(.*)$/i;');
	var c=document.cookie.split(/;\s*/);
	
	for(var i in c){
		if(re.test(c[i])){
			return unescape(re.exec(c[i])[2]);
		}
	}
	return null;
}

//script called when page loads.
function toDoOnLoad(){
	//if the cookie hasn't been set or the cookie is blank then write the cid to myCID. 
	if(getQueryVariable('cid') != null){
		XMwriteCookie('myCID',getQueryVariable('cid'),1);
	}
}
