/*************************************************************************************************************************************
	** COOKIE FUNCTIONALITY
	** Added for 0198BTTA - BT Tahiti, to allow basic tracking through cookies
	** Angus Main 02/10/07
	*************************************************************************************************************************************/
		/**
		* Switch between cookie / lms tracking (BT Tahiti Chnage AM 02/10/07)
		*/
		
		var useCookieTracking = false;
	
		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 nameEQ = name + "=";
			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(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
			}
			return null;
		}

		function eraseCookie(name) {
			createCookie(name,"",-1);
		}

		function clearAllCookies() {
			eraseCookie('firstName');
			eraseCookie('surname');
			eraseCookie('EIN');
			eraseCookie('emailSent');
			eraseCookie('suspendData');
			eraseCookie('rawScore');
			eraseCookie('role');
			location.reload(true)
			
		}

		/**
		* Set initial cookie values
		*/
		if (useCookieTracking) {
			// Test if a cookie already exists if not set values
			var existingSuspendData = readCookie("suspendData");
			
			//alert("exisiting sd = "+existingSuspendData);
			if (existingSuspendData == null) {
				createCookie("studentFirstName","",100);
				createCookie("studentSurname","",100);
				createCookie("suspendData",null,100);
				//alert("cookies set");
				//alert("sdCookie = "+readCookie("suspendData"))
			
			}
		}
		
		function writeEmail() {
			
			if (readCookie("emailSent") != "true"){
			
				//alert("SEND EMAIL\nFirst Name: "+readCookie("firstName")+"\nSurname: "+readCookie("surname")+"\nEIN: "+readCookie("EIN")+"\nScore: "+readCookie("rawScore"));
				createCookie("emailSent","true",100);
				 sendMail( readCookie("EIN"), readCookie("surname"), readCookie("firstName"), readCookie("rawScore"), "neil.gratton@bt.com", "noreply@saffroninteractive.com", "tahiti@saffroninteractive.com", "BT Tahiti results notification" );
				//sendMail( '4800', 'Scott', 'Barry', '8800', 'paul@saffroninteractive.com', 'noreply@saffroninteractive.com', 'angus@saffroninteractive.com', 'HC Test' );
				
				//createCookie("emailSent","true",100);
			}
		}
