// Use this function to retrieve a cookie.
function getCookie(name){
var cname = name + "=";               
var dc = document.cookie;             
    if (dc.length > 0) {              
    begin = dc.indexOf(cname);       
        if (begin != -1) {           
        begin += cname.length;       
        end = dc.indexOf(";", begin);
            if (end == -1) end = dc.length;
            return unescape(dc.substring(begin, end));
        } 
    }
return null;
}

function onloaddocument()
{

  getValue(document.preregistration.firstname1);
  getValue(document.preregistration.lastname1);
  getValue(document.preregistration.Address);
  getValue(document.preregistration.City);
  getValue(document.preregistration.State);
  getValue(document.preregistration.Zip);
  getValue(document.preregistration.Phone);
  getValue(document.preregistration.email);
  getValue(document.preregistration.Birth_Month);
  getValue(document.preregistration.Birth_Day);
  getValue(document.preregistration.Birth_Year);

  getValue(document.preregistration.patientstatus1);
}
function onunloaddocument()
{

  setValue(document.preregistration.firstname1);
  setValue(document.preregistration.lastname1);
  setValue(document.preregistration.Address);
  setValue(document.preregistration.City);
  setValue(document.preregistration.State);
  setValue(document.preregistration.Zip);
  setValue(document.preregistration.Phone);
  setValue(document.preregistration.email);
  setValue(document.preregistration.Birth_Month);
  setValue(document.preregistration.Birth_Day);
  setValue(document.preregistration.Birth_Year);

  setValue(document.preregistration.patientstatus1);
}
// Use this function to save a cookie.
function setCookie(name, value, expires) {
document.cookie = name + "=" + escape(value) + "; path=/" +
((expires == null) ? "" : "; expires=" + expires.toGMTString());
}

// Use this function to delete a cookie.
function delCookie(name) {
document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
}



// Function to retrieve form element's value.
function getValue(element) {
var value = getCookie(element.name);
    if (value != null) element.value = value;
}

// Function to save form element's value.
function setValue(element) {
setCookie(element.name, element.value, exp);
}

var exp = new Date();                                   
exp.setTime(exp.getTime() + (1000 * 60 * 60 * 24 * 31));