// *********************************************************************
// * csUserInfo.js
// *********************************************************************
function CsUserInfo_saveCookie( )
{
	var expires = new Date();
	expires.setMonth(expires.getMonth() + 6);
	var cookieValue = "";
	if (this.saveData)
	{
		var cookieBits = new Array();
		cookieBits.push(encodeURIComponent(this.firstName));
		cookieBits.push(encodeURIComponent(this.lastName));
		cookieBits.push(encodeURIComponent(this.company));
		cookieBits.push(encodeURIComponent(this.acctNum));
		cookieBits.push(encodeURIComponent(this.irnId));
		cookieBits.push(encodeURIComponent(this.email));
		cookieBits.push(encodeURIComponent(this.phoneNumber));
		cookieBits.push(encodeURIComponent(this.street1));
		cookieBits.push(encodeURIComponent(this.street2));
		cookieBits.push(encodeURIComponent(this.city));
		cookieBits.push(encodeURIComponent(this.state));
		cookieBits.push(encodeURIComponent(this.zip));
		cookieValue = cookieBits.join("|");
	}
	else
	{
		cookieValue = "x";
	}
	document.cookie = this.cookieName + "=" + cookieValue + ";expires=" + expires.toUTCString() + ";path=/";
}
function CsUserInfo_readCookie( )
{
	if (document.cookie == "") return;
	var cookieBits = document.cookie.split(";");
	var nv = null;
	for (var i = 0; i < cookieBits.length; i++)
	{
		nv = cookieBits[i].split("=");
		nv[0] = CsUserInfo_trimString(nv[0]);
		nv[1] = CsUserInfo_trimString(nv[1]);
		
		if (nv[0] == this.cookieName)
		{
			if (nv[1].toLowerCase() != "x")
			{
				this.saveData = true;
				var cd = nv[1].split("|");
				this.firstName = decodeURIComponent(cd[0]);
				this.lastName = decodeURIComponent(cd[1]);
				this.company = decodeURIComponent(cd[2]);
				this.acctNum = decodeURIComponent(cd[3]);
				this.irnId = decodeURIComponent(cd[4]);
				this.email = decodeURIComponent(cd[5]);
				this.phoneNumber = decodeURIComponent(cd[6]);
				this.street1 = decodeURIComponent(cd[7]);
				this.street2 = decodeURIComponent(cd[8]);
				this.city = decodeURIComponent(cd[9]);
				this.state = decodeURIComponent(cd[10]);
				this.zip = decodeURIComponent(cd[11]);
			}
			else
			{
				this.saveData = false;
			}
		}
	}
}
function CsUserInfo_trimString(s)
{
	return s.replace(/^\s+/, "").replace(/\s+$/, "");
}
function CsUserInfo_splitName(singleName)
{
	var namePattern = /^([^\s]+)\s+(.+)$/;
	var r = namePattern.exec(singleName);
	
	if (r != null)
	{
		this.firstName = r[1];
		this.lastName = r[2];
	}
	else
	{
		this.firstName = "";
		this.lastName = singleName;
	}
}
function CsUserInfo_fullName( )
{
	if (this.firstName != "")
	{
		return this.firstName + " " + this.lastName;
	}
	else
	{
		return this.lastName;
	}
}
function CsUserInfo( )
{
	this.firstName = "";
	this.lastName = "";
	this.company = "";
	this.acctNum = "";
	this.irnId = "";
	this.email = "";
	this.phoneNumber = "";
	this.street1 = "";
	this.street2 = "";
	this.city = "";
	this.state = "";
	this.zip = "";
	this.saveData = true;
}
CsUserInfo.trimString = CsUserInfo_trimString;
CsUserInfo.prototype.saveCookie = CsUserInfo_saveCookie;
CsUserInfo.prototype.readCookie = CsUserInfo_readCookie;
CsUserInfo.prototype.splitName = CsUserInfo_splitName;
CsUserInfo.prototype.fullName = CsUserInfo_fullName;
CsUserInfo.prototype.cookieName = "csUserInfo";