function copyright()
{
	now = new Date();
	year = now.getYear();

	document.write("All content on this web site copyright © 2002-" + year + " MN Car Sales unless otherwise stated. All rights reserved");
}

function setCookie(name, value, days)
{
	nameValue = name + "=" + value;
	exp = new Date();
	exp.setTime(exp.getTime() + days * 24 * 60 * 60 * 1000);
	expStr = (days == null) ? "" : ";expires=" + exp.toGMTString();

	document.cookie = nameValue + expStr;
}

function getCookie(name)
{
	nameStr = name + "=";
	maxLen = document.cookie.length;
	cnt = 0;

	while (cnt < maxLen)
	{
		indx = cnt + nameStr.length;

		if (document.cookie.substring(cnt,indx) == nameStr)
		{
			cookieEnd = document.cookie.indexOf(";", indx);

			if (cookieEnd == -1)
			{
				cookieEnd = document.cookie.length;
			}

			cookieData = unescape(document.cookie.substring(indx, cookieEnd));

			params = new Array();
			paramStart = 0;
			paramEnd = cookieData.length;
			cnt2 = 0;

			for (cnt2 = 0; cnt2 <= 1; cnt2 ++)
			{
				paramEnd = cookieData.indexOf("|", paramStart);
				params[cnt2] = cookieData.substring(paramStart, paramEnd);
				paramStart = paramEnd + 1;
			}

			document.contact.name.value = params[0];
			document.contact.email.value = params[1];
			document.contact.phone.value = cookieData.substring(paramStart, cookieData.length);
			document.contact.details.focus();

			return;
		}

		cnt ++;
	}

	document.contact.name.focus();

	return;
}

function checkForm()
{
	message = "";
	if (document.forms.contact.security_code.value.length == 0)
	{
		message = "* You haven't entered the security code.\n" + message;
		document.forms.contact.security_code.focus();
	}
	else
	{
		if (isNaN(document.forms.contact.security_code.value))
		{
			message = "* You've entered an invalid security code.\n" + message;
			document.forms.contact.security_code.focus();
		}
		else
		{
			if (document.forms.contact.security_code.value.length != 5)
			{
				message = "* The scurity code entered does not match the one requested.\n" + message;
				document.forms.contact.security_code.focus();
			}
		}
	}
	if (document.contact.details.value.length == 0)
	{
		message = "* You haven't entered details of your enquiry.\n" + message;
		document.contact.details.focus();
	}
	if (document.contact.email.value.length == 0)
	{
		message = "* You haven't entered your email address.\n" + message;
		document.contact.email.focus();
	} 
	else
	{
		if (document.contact.email.value.indexOf("@") == -1 || document.contact.email.value.indexOf(".") == -1 || document.contact.email.value.indexOf(" ") != -1 || document.contact.email.length < 6)
		{
			message = "* The email address you've entered appears to be invalid.\n" + message;
			document.contact.email.focus();
		}
	}
	if (document.contact.name.value.length == 0)
	{
		message = "* You haven't entered your name.\n" + message;
		document.contact.name.focus();
	} 
	if (message.length > 0)
	{
		message = "MN Car Sales\n\n\nForm contains errors and cannot be submitted for the following reason(s):\n\n" + message + "\nPlease press 'OK' and resubmit the required data.";
		alert(message);
		return false;
	}
	else
	{
		cookieParams = escape(document.contact.name.value) + "|" + escape(document.contact.email.value) + "|" + escape(document.contact.phone.value);
		setCookie("contact", cookieParams, 3650);
		return true;
	}			
}
