  
  var userCookie = document.cookie;

  function getCookie(name) { // use: getCookie("name");
    var index = userCookie.indexOf(name + "=");
    if (index == -1) return null;
    index = userCookie.indexOf("=", index) + 1;
    var endstr = userCookie.indexOf(";", index);
    if (endstr == -1) endstr = userCookie.length;
    return unescape(userCookie.substring(index, endstr));
  }

  var today = new Date();
  var expiry = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000); // plus 365 days
  var expired = new Date(today.getTime() - 365 * 24 * 60 * 60 * 1000); // less 365 days


  function setCookie(name, email, company, address, unitNumber, city, state, zipCode, tel) { // use: setCookie("name", email);
    	if (email != null && email != "")
      		document.cookie=name + "=" + escape(email) + ": company=" + escape(company) + ": address=" + escape(address) + ": unit_number=" + escape(unitNumber) + ": city=" + escape(city) + ": state=" + escape(state) + ": zip_code=" + escape(zipCode) + ": telephone=" + escape(tel) + "; expires=" + expiry.toGMTString();
    	userCookie = document.cookie; // update userCookie
    	return getCookie(name) != null; // return false if the cookie was refused
  }

  function deleteCookie(name) { // use: deleteCookie("name");
	document.cookie=name + "=null; expires=" + expired.toGMTString(); // delete cookie
    	userCookie = document.cookie; // update userCookie
    	document.forms[0].userName.value = formatCookie(); // delete cookie content
	document.forms[0].userEmail.value = formatCookie(); // delete cookie content
	document.forms[0].userCompany.value = formatCookie(); // delete cookie content
	document.forms[0].userAddress.value = formatCookie(); // delete cookie content
	document.forms[0].userUnitNumber.value = formatCookie(); // delete cookie content
	document.forms[0].userCity.value = formatCookie(); // delete cookie content
	document.forms[0].userState.value = formatCookie(); // delete cookie content
	document.forms[0].userZipCode.value = formatCookie(); // delete cookie content
    	document.forms[0].userTel.value = formatCookie(); // delete cookie content
  }


// make sure the cookie is set

  function makeCookie() { 
    	var form = document.forms[0];
    	while (!setCookie(form.userName.value, form.userEmail.value, form.userCompany.value, form.userAddress.value, form.userUnitNumber.value, form.userCity.value, form.userState.value, form.userZipCode.value, form.userTel.value)) 
		{
      		if (!alert('The cookie was not accepted by your browser\nYou will have to enter your information again upon a return visit')) 
 			break;
      		}
  }
  
// erases cookie info

  function formatCookie() 
  {
    var retValue = "";
    with (userCookie) 
    {
      for (var i=0; i < length; i++)
        retValue += (charAt(i) != " ") ? charAt(i) : "\n";
    }
    return retValue;
  }

// loads the user information from the cookie to the form fields

  function loadUserInfo(){
    	document.forms[0].userName.value = getName("name");
  	document.forms[0].userEmail.value = getEmail("name");
  	document.forms[0].userCompany.value = getCompany("name");
  	document.forms[0].userAddress.value = getAddress("name");
  	document.forms[0].userUnitNumber.value = getUnitNumber("name");
  	document.forms[0].userCity.value = getCity("name");
  	document.forms[0].userState.value = getState("name");
  	document.forms[0].userZipCode.value = getZipCode("name");
	document.forms[0].userTel.value = getTel("name");

}

// gets the user name from cookie

  function getName(name) { // use: getName("name");
    var index = 0;
    if (index == -1) return "";
    var endstr = userCookie.indexOf("=", index);
    if (endstr == -1) endstr = userCookie.length;
    return unescape(userCookie.substring(index, endstr));
  }

var token=0;

// gets the user email from cookie

  function getEmail(name) { // use: getCookie("name");
	var index = 0;
     	if (index == -1) return "";
     		index = userCookie.indexOf("=", index) + 1;
     	var endstr = userCookie.indexOf(":", index);
     	token = endstr;
     	if (endstr == -1) endstr = userCookie.length;
      		return unescape(userCookie.substring(index, endstr));
  }

// gets the user company from cookie

  function getCompany(name) { // use: getCookie("name");
    	token = token + 1;
	var index = 0;
	index = userCookie.indexOf("=", token) + 1;
    	var endstr = userCookie.indexOf(":", index);
	token = endstr;
    	if (endstr == -1) endstr = userCookie.length;
    	return unescape(userCookie.substring(index, endstr));
  }

// gets the user address from cookie

  function getAddress(name) { // use: getCookie("name");
    	token = token + 1;
	var index = 0;
	index = userCookie.indexOf("=", token) + 1;
    	var endstr = userCookie.indexOf(":", index);
	token = endstr;
    	if (endstr == -1) endstr = userCookie.length;
    	return unescape(userCookie.substring(index, endstr));
  }

// gets the user unit number from cookie

  function getUnitNumber(name) { // use: getCookie("name");
    	token = token + 1;
	var index = 0;
	index = userCookie.indexOf("=", token) + 1;
    	var endstr = userCookie.indexOf(":", index);
	token = endstr;
    	if (endstr == -1) endstr = userCookie.length;
    	return unescape(userCookie.substring(index, endstr));
  }

// gets the user city from cookie

  function getCity(name) { // use: getCookie("name");
    	token = token + 1;
	var index = 0;
	index = userCookie.indexOf("=", token) + 1;
    	var endstr = userCookie.indexOf(":", index);
	token = endstr;
    	if (endstr == -1) endstr = userCookie.length;
    	return unescape(userCookie.substring(index, endstr));
  }

// gets the user state from cookie

  function getState(name) { // use: getCookie("name");
    	token = token + 1;
	var index = 0;
	index = userCookie.indexOf("=", token) + 1;
    	var endstr = userCookie.indexOf(":", index);
	token = endstr;
    	if (endstr == -1) endstr = userCookie.length;
    	return unescape(userCookie.substring(index, endstr));
  }

// gets the user zip code from cookie

  function getZipCode(name) { // use: getCookie("name");
    	token = token + 1;
	var index = 0;
	index = userCookie.indexOf("=", token) + 1;
    	var endstr = userCookie.indexOf(":", index);
	token = endstr;
    	if (endstr == -1) endstr = userCookie.length;
    	return unescape(userCookie.substring(index, endstr));
  }

// gets the user tel from cookie

  function getTel(name) { // use: getCookie("name");
    	token = token + 1;
	var index = 0;
	index = userCookie.indexOf("=", token) + 1;
    	var endstr = userCookie.indexOf(":", index);
	token = 0;
    	if (endstr == -1) endstr = userCookie.length;
    	return unescape(userCookie.substring(index, endstr));
  }


