	$(document).ready(function(){
		initFirmFormInformation();
		initReporterFormInformation();
		initClientFormInformation();
	});

	//FrmReporterCenter
	var remember_reporteremail = "reporteremail";
	var remember_reporterpassword = "reporterpassword";

	function saveReporterFormInformation() {
		// Save user information from the form!
		reporterform = $("form[@name='FrmReporterCenter']");
		reporteremail = $("input[@name='email']",reporterform).val();
		reporterpass = $("input[@name='pwd']",reporterform).val();
		reporterremember = $("input[@name='Remember']",reporterform);
		if (reporterremember) reporterremember = reporterremember.attr("checked");
		
		if (!reporteremail) { alert("Reporter Email is a required field"); return false; }
		if (!reporterpass) { alert("Reporter Password is a required field"); return false; }

		//only do the cookie stuff if the checkbox is selected
		if (reporterremember) {
			myCreateCookie(remember_reporteremail, reporteremail,365);
			myCreateCookie(remember_reporterpassword,reporterpass,365);
		} else {
			eraseCookie(remember_reporteremail);
			eraseCookie(remember_reporterpassword);
		}
		return true;
	}

	function initReporterFormInformation() {
		// Autofill user information if available
		reporterform = $("form[@name='FrmReporterCenter']");
		if (!reporterform) return;

		email = readCookie(remember_reporteremail);
		$("input[@name='email']",reporterform).val(email);
		$("input[@name='pwd']",reporterform).val(readCookie(remember_reporterpassword));
		if (email) $("input[@name='Remember']",reporterform).attr("checked",true);

		// Save comment information when form is submitted
		reporterform.submit(saveReporterFormInformation);
	}

	//FrmCase (Firm)
	var remember_firmid = "firmid";
	var remember_firmpassword = "firmpassword";

	function saveFirmFormInformation() {
		// Save user information from the form!
		firmform = $("form[@name='FrmCase']");
		caseid = $("input[@name='cid']",firmform).val();
		firmid = $("input[@name='fid']",firmform).val();
		firmpass = $("input[@name='pwd']",firmform).val();
		firmremember = $("input[@name='Remember']",firmform);
		if (firmremember) firmremember = firmremember.attr("checked");
		
		if (!caseid) { alert("Case ID is a required field"); return false; }
		if (!firmid) { alert("Firm ID is a required field"); return false; }
		if (!firmpass) { alert("Firm Password is a required field"); return false; }

		//only do the cookie stuff if the checkbox is selected
		if (firmremember) {
			myCreateCookie(remember_firmid, firmid,365);
			myCreateCookie(remember_firmpassword,firmpass,365);
		} else {
			eraseCookie(remember_firmid);
			eraseCookie(remember_firmpassword);
		}
		return true;
	}

	function initFirmFormInformation() {
		// Autofill user information if available
		firmform = $("form[@name='FrmCase']");
		if (!firmform) return;

		firmid = readCookie(remember_firmid)
		$("input[@name='fid']",firmform).val(firmid);
		$("input[@name='pwd']",firmform).val(readCookie(remember_firmpassword));

    if (firmid) $("input[@name='Remember']",firmform).attr("checked",true);

		// Save comment information when form is submitted
		firmform.submit(saveFirmFormInformation);
	}

	//FrmClientCenter
	var remember_clientoffice = "office_no";
	var remember_clientpassword = "clientpassword";

	function saveClientFormInformation() {
		// Save user information from the form!
		clientform = $("form[@name='FrmClientCenter']");
		clientid = $("input[@name='office_no']",clientform).val();
		clientpass = $("input[@name='pwd']",clientform).val();
		clientremember = $("input[@name='Remember']",clientform);
		if (clientremember) clientremember = clientremember.attr("checked");

		if (!clientid) { alert("Office/Enterprise ID is a required field"); return false; }
		if (!clientpass) { alert("Client Password is a required field"); return false; }

		//only do the cookie stuff if the checkbox is selected
		if (clientremember) {
			myCreateCookie(remember_clientoffice, clientid,365);
			myCreateCookie(remember_clientpassword,clientpass,365);
		} else {
			eraseCookie(remember_clientoffice);
			eraseCookie(remember_clientpassword);
		}
		return true;
	}

	function initClientFormInformation() {
		// Autofill user information if available
		clientform = $("form[@name='FrmClientCenter']");
		if (!clientform) return;

		office_no = readCookie(remember_clientoffice);
		$("input[@name='office_no']",clientform).val(office_no);
		$("input[@name='pwd']",clientform).val(readCookie(remember_clientpassword));

    if (office_no) $("input[@name='Remember']",clientform).attr("checked",true);

		// Save comment information when form is submitted
		clientform.submit(saveClientFormInformation);
	}

	// cookie functions http://www.quirksmode.org/js/cookies.html
	function myCreateCookie(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)
	{
		myCreateCookie(name,"",-1);
	}
	// /cookie functions
