function loadCookie() {
  //
  // rmcnPopunder - Production Version
  //
  var days = 30 // Cookie expires in 30 days
  //alert("Initial onLoad Status: " + readCookie("status")); 
  //alert("Initial onLoad URL: " + readCookie("url")); 
  //alert("Initial onLoad Search Term: " + readCookie("searchterm")); 
  if (readCookie("status")) {
    var status = readCookie("status");
  }
  else {
    var status = "NoSubmit";
    createCookie("status", status, days);
  }
  // 
  // Capture Referring URL and Search Terms
  //
  if (readCookie("searchterm")) {
    var searchterm = readCookie("searchterm");
	var url = readCookie("url");
  }
  else {
    var ref = document.referrer;
    var firstsplit = ref.split("?");
	var secondsplit = firstsplit[1].split("&");
    var thirdsplit;
    var keyWord;
    for (i=0; i<10; i++) {
	  if (secondsplit[i]) {
	    thirdsplit = secondsplit[i].split("=");
	    if (thirdsplit[0] == "q") {
          keyWord = thirdsplit[1];
        }
        if (thirdsplit[0] == "p") {
          keyWord = thirdsplit[1];
        }
      }
    }
	var days2 = 1 // Search Terms Cookies Expire in 1 day
    createCookie("url", firstsplit[0], days2);
	createCookie("searchterm", keyWord, days2);
  }
  // Display Cookies at end of onLoad
  //alert("Final onLoad Status: " + readCookie("status"));
  //alert("Final onLoad URL: " + readCookie("url"));
  //alert("Final onLoad Search Term: " + readCookie("searchterm"));
}
function submitCookie() {
  var days = 30 // Cookie expires in 30 days 
  //alert("Initial onSubmit Status: " + readCookie("status")); 
  //alert("Initial onSubmit URL: " + readCookie("url")); 
  //alert("Initial onSubmit Search Term: " + readCookie("searchterm")); 
  // Check for Existence of Cookie
  if (readCookie("status")) {
    var instatus = readCookie("status");
  //  alert("Initial Setting: " + instatus);
  }
  // Set Initial Status
  var status = "Submit";
  // Write Value to Cookie
  createCookie("status", status, days);
  // If Pop Under Previously Generated, close window
  if (instatus == "PopUnder") {
    window.close("SecondChance.htm");
  }
  if (readCookie("url")) {
    var url = readCookie("url");
	document.form1.searchURL.value = url;
  }
  if (readCookie("searchterm")) {
    var keyWord = readCookie("searchterm");
	var keyWordLength;
    var keyWordLeft;
    var keyWordRight;
    for (i=0; i<10; i++) {
      x = keyWord.indexOf("+");
	  if (x != -1) {
	    keyWordLength = keyWord.length;
	    keyWordLeft = keyWord.substring(0,x);
	    keyWordRight = keyWord.substring(x+1,keyWordLength);
	    keyWord = keyWordLeft + " " + keyWordRight;
	  }
    }
	document.form1.searchTerm.value = keyWord;
  }
  //alert("Final onSubmit Status: " + readCookie("status"));
  //alert("Final onSubmit URL: " + url);
  //alert("Final onSubmit Search Term: " + keyWord);
  //alert("Submit happens next");
}
function popupWindow() {
  var days = 30 // Cookie expires in 30 days
  //alert("Initial onUnLoad Status: " + readCookie("status"));
  //alert("Initial onUnLoad URL: " + readCookie("url"));
  //alert("Initial onUnLoad Search Term: " + readCookie("searchterm")); 
  // Check for Existence of Cookie
  // & Load Cookie Value
  var instatus;
  if (readCookie("status")) {
    instatus = readCookie("status");
  }
  else {
    instatus = "NoSubmit";
  }
  //alert("Initial Unload Status: " + instatus);
  // Determine Status
  if (instatus == "NoSubmit") {
    TheNewWin  = window.open("SecondChance.htm",'TheNewWin','width=420,height=600,toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1');
    TheNewWin.blur();
	// Set Cookie to Pop Under Generated
	var status = "PopUnder";
	// Write Value to Cookie
    createCookie("status", status, days);
  }
  //alert("Final onUnLoad Status: " + readCookie("status"));
  //alert("Final onUnLoad URL: " + readCookie("url"));
  //alert("Final onUnLoad Search Term: " + readCookie("searchterm"));
}
//
// Cookie Scripts written by Scott Andrew from 
// http://www.yourhtmlsource.com/javascript/cookies.html#convenientscripts
// 
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 readCookie(name)
{
  var ca = document.cookie.split(';');
  var nameEQ = name + "=";
  for(var i=0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1, c.length); //delete spaces
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
  return null;
}

function eraseCookie(name)
{
  createCookie(name, "", -1);
}


