/*
User profile API

Usage:  1. get user profile class via "var userProfile = embGetProfileManager()"
		2. get profile information via public methods of returned object, e.g.
		   "userProfile.getFirstName()" or directly via "embGetProfileManager().getFirstName()"

*/

// (hide everything except the things we make public explicitly)
(function() {

var embProfileManager = new EmbProfileManager();

// user profile is singleton
window.embGetProfileManager = function () {
  return embProfileManager;
};

function EmbProfileManager() {
	
	//  private variables
	var MODEL_COOKIE = "model;"
	this.COOKIE_LAST_CC_BM_CODE = "lastCCBmCode";
	
	var userData = new Object();
	userData.isLoggedIn = false;
	
	this.setUserData = function(data) {
		userData = data;
	};
	
	// public methods
	this.isLoggedIn = function () {
		return userData.isLoggedIn;
	};
	
	this.getFirstName = function () {
		return userData.firstName;
	};

	this.getSecondFirstName = function () {
		return userData.secondFirstName;
	};
	
	this.getLastName = function () {
		return userData.lastName;
	};

	this.getSecondLastName = function () {
		return userData.secondLastName;
	};
	
	this.getTitle = function () {
		return userData.title;
	};
	
	this.getSalutation = function () {
		return userData.salutation;
	};
	
	this.getDealerName1 = function () {
		return userData.dealerName1;
	};
	
	this.getDealerName2 = function () {
		return userData.dealerName2;
	};
	
	this.getDealerStreet = function () {
		return userData.dealerStreet;
 	};
 	
 	this.getDealerZIP = function () {
 		return userData.dealerZIP;
 	};
 	
 	this.getDealerCity = function () {
 		return userData.dealerCity;
	};
	
 	this.getZipCode = function () {
		return userData.zipCode;
	};
	
	this.getBirthday = function () {
		return userData.birthday;
	};
	
	this.getFavoriteName = function () {
		return userData.favoriteName;
	};
	
	this.getFavoriteBmCode = function () {
		return userData.favoriteBmCode;
	};
	
	this.getFavoritePrice = function () {
		return userData.favoritePrice;
	};
	
	this.getFavoriteCurrency = function () {
		return userData.favoriteCurrency;
	};
	
	this.getFavoriteRate = function () {
		return userData.favoriteRate;
	};
	
	this.getFavoriteDate = function () {
		return userData.favoriteDate;
	};

	this.getConfigurationBmCode = function () {
		if(userData.isLoggedIn){
			return get_cookie(this.COOKIE_LAST_CC_BM_CODE);
		}else{
			return "";
		}
	};
	
	this.getFavoriteImgSmallUrl = function () {
		return userData.favoriteImgSmallUrl;
	};
	
	this.getFavoriteImgLargeUrl = function () {
		return userData.favoriteImgLargeUrl;
	};
	
	this.getCCiUrl = function () {
		return "/cci";
	};
	
	this.getSavedVehiclesUrl = function () {
		return "/saved_vehicles";
	};
	
	/**
	 * @returns either the bmcode of the vehicle the user is interested in or null if he has no vehicle interest yet.
	 */
	this.getVehicleInterestBmCode = function () {
		// read out model cookie value;
		return get_cookie(MODEL);
	};
}

EmbProfileManager.prototype.loadData = function(secureHost, signonHandle) {
 
 var profileRef = get_cookie("profile_ref");
 if (profileRef) {
	 var scriptpath = secureHost + signonHandle +".profiledata." + profileRef + ".js";
	 document.write("<script src="+scriptpath+"></script>");
 }
};

})();
