
function omniObj(){
	
	// Local varibles
	this.COOKIE_NAME = 'u';
	
	// Methods using non anon functions
	this.load = loadValues;				// Loads instance paramaters base on values in a cookie
	this.save = saveValues;				// Saves all instance paramaters in cookie
	this.get  = getValue;				// Returns instance paramater value
	this.set = setValue;				// Sets on instance paramater value
	this.alertValues = alertValues;		// Alerts all the current property values (For Testing Only)
	this.update = updateValues;
	
	//Non anon method assignment
	//Calling as obj.load() will take the value and parse it.  Parsing is based on the assumption
	//that keys and values are seperated by ':' and that key value pairs are seperated by ';'.
	//The pased values will then be assigned as instance paramaters to the object.
	function loadValues(){
		var cookieValue;
		cookieValue = getCookie(this.COOKIE_NAME);
		
		var valueArray = cookieValue.split(";");
		for (var i=0; i<valueArray.length;i++){
			var elementArray = valueArray[i].split("=");
			try{
				eval("this." + elementArray[0] + "='" + elementArray[1] + "'");
			}catch(err){
				//alert("err occured: " + err.description + " could not find "+"set" + elementArray[0] + "()<br>");
			}finally{
				//alert('exit');
				//return;
			}
		}
	}
	
	// Calling as obj.get('[key]') will return the corresponding object's key's value.
	function getValue(key){
		var value = eval("this."+key);
		if(typeof(value)=="undefined"){
		value='';
		} 
		return value;
	}
	
	// Calling as obj.set('[key]','[value]') will set the instance param [key] to the corresponding value.
	function setValue(key, value){
		eval("this." + key + "='" + value + "'");
	}
	
	function saveValues(){
		var cookieValue;
		cookieValue='';
		
		for (sProperty in this) { 
        	if ( typeof(this[sProperty]) != "function"){
				cookieValue += sProperty + "=" + this[sProperty]+";";
			}
      	} 
		//Make sure expire date is out 10 years or so...
		setCookie(this.COOKIE_NAME, cookieValue, 365*10, '/', null, null);
	}
	
	function alertValues(){
		var v;
		v='';
		
		for (sProperty in this) { 
        	if ( typeof(this[sProperty]) != "function"){
				v += sProperty + "=" + this[sProperty]+";\n";
			}
      	} 
	  	alert(v);
	}
	
	//This may not be the best way but there is inevitably some ugly logic...and here is where it's going...
	//This should be called immediatly after calling obj.load() and before any other omniture cookies are set...
	//This will allow us to see current values of those cookies before they are changed by current page.
	function updateValues(){
	
		// ### Helper info                                                             ###
		//
		// General helper info for use later
		// this.userId			User ID
		// this.userIdChange	Whether or not the user ID changed from the last page view.
		// this.conPage			Identifies if the current page is the registration confirmation page.
		// this.aaPage			Identifies if the current page is the account activation page.
		// this.loginConPage	Page after user logs in
		
		// User Id and whether or not it changed from last page view.
		if (this.userId != getUserID()){
			this.userIdChange = true;
		}else{
			this.userIdChange = false;
		}

		this.userId = getUserID();

		// Registration Thank You Page
		if (window.location.href.indexOf("rPage=thankyou") != -1){	
			this.conPage = true;
		}else{
			this.conPage = false;
		}
		
		// Account Activation Confirmation Page
		if (window.location.href.indexOf("rPage=activated") != -1){
			this.aaPage = true;
		}else{
			this.aaPage = false;
		}		
		
		// First page after login
		if ((document.referrer.indexOf("autoLogin.jsp") != -1 || document.referrer.indexOf("rPage=login") != -1) && (typeof(MNGiRegistrationLoginStatus) != "undefined") && (MNGiRegistrationLoginStatus == "in")){
			this.loginConPage = true;
		}else{
			this.loginConPage = false;
		}	
		
		// ### Registration Type: Primary use eVar16; Secondary eVar14 (Visitory Type) ###
		//
		// Set based on the vertical through which the user registeres.
		// NGPS				NEWS
		// Real Estate		RE
		// Automotive		AUTO
		// Jobs				JOBS
		// Classifieds		CLASS
		// 
		// Currently Registration is only on NGPS so the value will alwasy be 'NEWS'.  Will need to update.
		
		if (this.conPage){
			this.rType = "NEWS";
		}
		
		// ### Visitor Type: Primary use eVar14; Secondary Various components are reused ###
		//
		// Set based on critera related to registration state
		// New Visitor (First Time to Site)					1
		// Returning Visitor (Been to site not Registered)	2
		// Registered (Registered but not Logged in)		3 + Registration Type
		// Logged In (Registered user that is Logged in)	4 + Registration Type
		//
		// To determine the above statuses there a few pieces of info we will need.  They are:
		// fPage or First Page (boolean) lets us know if this is the first page the user is viewing 
		// fVisit or First Vist (boolean) lets us know if this is the first visit (based on presece of fPage cookie)
		// MNGiRegistrationLoginStatus lets us know if the user is logged in.
		
		
		// fPage (First Page) will be determined by the presence of a session cookie.  If the cookie is not
		// present then this is the first page view, if it is present that another page view must of set it.
		if (getCookie('fPage')==''){
			this.fPage=true;
			setCookie('fPage','true', null, '/');
		}else{
			this.fPage=false;
			setCookie('fPage','false', null, '/');
		}
		
		// fVisit (Fist Visit) is used to determine if value 1 (New Visitor) state is appropriate.  The visit flag
		// will only be toggled on the first page so that viewing a second page doesn't set it falsely to a returning
		// visitor status. First visit is determined based on the userObject cookie, if not present this must be the first page 
		// of the first visit. 
		var cookieExists = getCookie(this.COOKIE_NAME); 

		if (this.fPage){
			if (cookieExists==''){
				this.fVisit=true;
			}else{
				this.fVisit=false;
			}
		}
		
		// MNGiRegistrationLoginStatus is set by Registration to "in" or "out"
		// If a user is not logged in we have no way of knowing if they are registered...
		// Since the vType paramater persists though we can 
		
		if (this.fVisit){
			this.vType = '1';
		}else{
			this.vType = '2';
		}
		
		if ((typeof(MNGiRegistrationLoginStatus) != "undefined") && (MNGiRegistrationLoginStatus == "in")){
			this.vType = '4+' + this.rType;
		}else{
			if ((this.userId).indexOf('R:') != -1) {
				this.vType = '3+' + this.rType;
			}
		}

		
		// ### Registration Status: Primary use eVar19 ###
		//
		// Records the Registration Status, Initial Registration Entry Type and Print Subscriber Status
		// Registration Status:
		// Registered within last 72hrs but not activated account (email confirm)			New
		// Registered longer than 72hrs but has not activated account						Old
		// Has activated account and visited site within last 30 days						Active
		// Has activated account and has not visited site in last 30 days					Innactive
		
		// Track cVisit (Current Visit) and lVisit (Last Visit).  Only set on fPage (First Page) so that subsequent page 
		// views will still be aware of when the last visit was.
		var date = new Date();
		var registrationWindow = 72*60*60*1000;		//72 hrs
		var visitWindow = 30*24*60*60*1000;			//30 days

		
		if (this.fPage){
			if (this.lVisit){
				this.lVisit = this.cVisit;
			}else{
				this.lVisit = date.getTime();
			}
			
			this.cVisit = date.getTime();
		}
		
		// rDate (registration Date)
		if (this.conPage){
			this.rDate = date.getTime();
		}
		
		// aaDate (Account Activation Date)
		if (this.aaPage){
			this.aaDate = date.getTime();
		}

		// First we'll check that the user is registered then we can check if they have an active account date
		// and subsequently derive all the status values.
		if (this.rDate){
			if (this.aaDate){
				// Active Account
				if (parseInt(this.cVisit) < (parseInt(this.lVisit) + visitWindow)){
					this.status = "Active"
				}else{
					this.status = "Inactive"
				}
			}else{
				// No Acctive Account
				if (parseInt(this.cVisit) < (parseInt(this.rDate) + registrationWindow)){
					this.status = "New"
				}else{
					this.status = "Old"
				}
			}
		}

		// Initial Registration Entry Type
		// User voluntarily selected to register										Voluntary
		// User was forced to register based on system rules							Premium
		
		// Since there is only Voluntary registration right now we'll hard code...this will need updating in a future version
		if (this.conPage){
			var voluntary = true
			
			if (voluntary){
				this.initRegType = 'Voluntary'
			}else{
				this.initRegType = 'Premium'
			}
		}
		// Print Subscriber Status
		// User responded "Yes" to "Are you a subscriber?" during registration		Yes
		//  User responded "No" to "Are you a subscriber?" during registration		No
		
		if (this.conPage){
		
			if (window.location.href.indexOf("print=true") != -1){
				this.pSub = 'Yes'
			}else{
				this.pSub = 'No'
			}
		}

		
		if (typeof(this.rDate) != "undefined"){
			this.regStatus = this.status + ":" + this.initRegType + ":" + this.pSub
		}
		
	}
	
}
