function assignCookie() {

	var cookie;
	var start = 0; 
	var finish = 0;

	if (ReadCookie("tsupport") == null || ReadCookie("tsupport") == "") {
		document.main.Company.value = "";
		document.main.Contact.value = "";
		document.main.Email.value = "";
		document.main.Telephone.value = "";
		document.main.Customer.value = "";
	} else {
		cookie = ReadCookie("tsupport");

		// Check if cookie format is as expected
		for (var i = 0; i < 4; i++) {
			if (cookie.indexOf('^', start) == -1) {
				return null;
			}
			start = finish + 1;
		}

		// Split the cookie and populate the fields
		splitCookie = cookie.split('^');
		document.main.Company.value = splitCookie[0];
		document.main.Contact.value = splitCookie[1];
		document.main.Email.value = splitCookie[2];
		document.main.Telephone.value = splitCookie[3];
		document.main.Customer.value = splitCookie[4];
	}
}

function ReadCookie(Name) {

	var cookies = ' ' + document.cookie;
	
	if (cookies.indexOf(' ' + Name + '=') == -1) return null;
	var start = cookies.indexOf(' ' + Name + '=') + (Name.length + 2);
	var finish = cookies.substring(start, cookies.length);

	finish = (finish.indexOf(';') == -1) ? cookies.length : start + finish.indexOf(';');
	return unescape(cookies.substring(start, finish));
}


function setCookie(){

	var cookie='';

	if (document.main.save.checked == true) {

		cookie=document.main.Company.value +'^'+ document.main.Contact.value +'^'+ document.main.Email.value +'^'+ document.main.Telephone.value +'^'+ document.main.Customer.value;
		WriteCookie("tsupport", cookie);
	}
}

function WriteCookie (cookieName, cookieValue){

	var expDate = new Date(2010, 1, 1);
//	document.cookie = cookieName + "=" + escape (cookieValue) + ";expires=" + expDate.toGMTString() + ";secure";
	document.cookie = cookieName + "=" + escape (cookieValue) + ";expires=" + expDate.toGMTString();
}
