/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Cookie script - Scott Andrew
Popup script, Copyright 2005, Sandeep Gangadharan */

function newCookie(name,value,days) {
 var days = 30;   // the number at the left reflects the number of days for the cookie to last
                 // modify it according to your needs
 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 nameSG = name + "=";
   var nuller = '';
  if (document.cookie.indexOf(nameSG) == -1)
    return nuller;

   var ca = document.cookie.split(';');
  for(var i=0; i<ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
  if (c.indexOf(nameSG) == 0) return c.substring(nameSG.length,c.length); }
    return null; }

function eraseCookie(name) {
  newCookie(name,"",1); }

function toMem(a) {  
    newCookie('theCompany', document.form.company.value);   // add a new cookie as shown at left for every
	newCookie('theAddress1', document.form.address1.value);  // field you wish to have the script remember
	newCookie('theAddress2', document.form.address2.value);
	newCookie('theCity', document.form.city.value);
	newCookie('theState', document.form.state.value);
	newCookie('theZip', document.form.zip.value);
	newCookie('theCountry', document.form.country.value);
	newCookie('theContact', document.form.contact.value);
	newCookie('thePhone', document.form.phone.value);
	newCookie('theFax', document.form.fax.value);
	newCookie('theEmail', document.form.email.value);
}

function delMem(a) {
  eraseCookie('theCompany');   // make sure to add the eraseCookie function for every field
  eraseCookie('theAddress1');

   document.form.company.value = '';   // add a line for every field
   document.form.address1.value = ''; }


function remCookie() {
document.form.company.value = readCookie("theCompany");
document.form.address1.value = readCookie("theAddress1");
document.form.address2.value = readCookie("theAddress2");
document.form.city.value = readCookie("theCity");
document.form.state.value = readCookie("theState");
document.form.zip.value = readCookie("theZip");
document.form.country.value = readCookie("theCountry");
document.form.contact.value = readCookie("theContact");
document.form.phone.value = readCookie("thePhone");
document.form.fax.value = readCookie("theFax");
document.form.email.value = readCookie("theEmail");
}

// Multiple onload function created by: Simon Willison
// http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function() {
  remCookie();
});

