
function writeContactInfo(){
	
	// Need to redo this with form name specified for general use - see usage below in 
	// getClientId function
	
		// debugger;
				contactInfo  = new cookieObject("contact", null, "/", "fname", "lname", "from", "clientId");
				var formFname = document.entrycontact.fname.value;
				var formLname = document.entrycontact.lname.value;
				var formEmail = document.entrycontact.from.value;
				var formClientId = document.entrycontact.clientid.value;
				
				contactInfo.put("fname", formFname);
				contactInfo.put("lname", formLname);				
				contactInfo.put("from", formEmail);
				contactInfo.put("clientId", formClientId);

				//Output the updated cookie
				contactInfo.expires = 500;
				contactInfo.write();
			
			//alert("System check - please continue, nothing's wrong: code "+sTime.value)


}

function getContactInfo(){
	
	// Need to redo this with form name specified for general use - see usage below in 
	// getClientId function
	
	contactInfo  = new cookieObject("contact", null, "/", "fname", "lname", "from", "clientId");
	
		// debugger;
		if (contactInfo.found) {
				
								
				var formFname =  contactInfo.get("fname");
				var formLname =  contactInfo.get("lname");
				var formEmail = contactInfo.get("email");
				var formClientId = contactInfo.get("clientId");
				
				document.paymentNotify.name.value = formName;
				document.paymentNotify.from.value = formEmail;
				
				document.getElementById('clientId').value = formClientId;         //  That's the field below with space in name
				// document.paymentNotify.customclientid.value = formClientId;  // which is invalid!

				//Output the updated cookie
			
				contactInfo.write();
			
		}


}

function checkClientId() {
	
	var clientIdDate = new Date();
	var	clientId = clientIdDate.getTime();
	var noVisits = 0;
	var prevVisit = "";
	
	
// Test if session cookie exists

// Create cookie object and attempt to read it from disk
	sessionCookie  = new cookieObject("session", null, "/", "sessionStarted", "qDurn");
// if cookie doesn't exist, create it

 // debugger;


	sessionCookie.put("sessionStarted", "Yes"); 
	
	
if (sessionCookie.found) {

	// sessionCookie.write(); // superfluous now but left in in case we later decide to reinstate cookie with 30 min lifetime

} else {
	  sessionCookie.put("qDurn", "0"); // qDurn is total answer time for all Qs this session
      sessionCookie.write();
}
	  
	  // Now check to see if there is a clientId cookie - 
	  // If yes, update it - they've been here before

	  
	  clientIdCookie  = new cookieObject("clientId", 500, "/", "cid", "firstVisit", "prevVisit", "lastVisit", "noVisits");
	  
	  if (clientIdCookie.found) {
       // Yes, update it - they've been here before
			prevVisit = clientIdCookie.get("lastVisit");
			clientIdCookie.put("prevVisit", prevVisit);
			clientIdCookie.put("lastVisit",clientIdDate);
			noVisits =	clientIdCookie.get("noVisits");
			++noVisits;
			clientIdCookie.put("noVisits", noVisits);

			clientIdCookie.write();
	  
	  } else {
		  	//No - never here before, create one
			clientIdCookie.put("cid", clientId);
			clientIdCookie.put("firstVisit", clientIdDate);
			clientIdCookie.put("prevVisit", clientIdDate);
			clientIdCookie.put("lastVisit",clientIdDate);
			clientIdCookie.put("noVisits",1);

			clientIdCookie.write();
		  
		  }
	
}

function getClientId(myForm) {
	
	// Unless cookies or javascript disabled, there should always be a client cookie - created by 
	// the function checkClientId which should  have been called before this routine [most pages have onLoad="checkClientId()"] 
	// If we find a client cookie, add the necessary fields to the form on the page
	
 // debugger;
 
  // alert ("getCID");
	  var cid = "";
	   var firstVisit = "";
	   var prevVisit = "";
	   var lastVisit = "";
	   var noVisits = 0;
	
	 clientIdCookie  = new cookieObject("clientId", null, "/", "cid", "firstVisit", "prevVisit", "lastVisit", "noVisits")
	 
	 if (clientIdCookie.found) {
       // Yes, get record details
		

			cid = clientIdCookie.get("cid");
			firstVisit = clientIdCookie.get("firstVisit");
			prevVisit = clientIdCookie.get("prevVisit");
			lastVisit = clientIdCookie.get("lastVisit");
			noVisits =	clientIdCookie.get("noVisits");
			
	  		myForm.clientid.value = cid;
			myForm.firstVisit.value = firstVisit;
			myForm.prevVisit.value = prevVisit;
			myForm.lastVisit.value = lastVisit;
			myForm.noVisits.value =	noVisits;
	  }
	
}








