// for ONOL only
//need to change the 'title bar' text in the editTitleBar function. 
Object.extend(marketMessagService, {
	view:{
		constants:{
			CA_COUNTRY_CODE:"CA",
			GB_COUNTRY_CODE:"GB",
			CA_STAGING_LINK:"https://staging.merchantmail.net/m/p/gap/can/jemail/gpjapiprocess.asp",
			GB_XML_STRING:"?req=<?xml version='1.0' encoding='UTF-8'?><DRRESPONSE><LOGIN>GapUKRegistration</LOGIN><PASSWORD>R1BVbml0ZWRLaW5nZG9tUmVn</PASSWORD><SOURCE>"
		},
		emailRegistrationDisplayManager:{
			interceptMarket:null,
			nowTime:null,
			timeNowInMilliSecs:null,
			interceptDateRaw:null,
			interceptBrand:null,
			interceptBusinessUnit:null,
			interceptSeenCookieKey:null,
			interceptSeenExpire:null,
			userRegisteredForMarketList:null,
			hasUserSubmittedEmail:null,
			hasUserSeenInPast30Days:null,
			isInterceptDisplayRequired:null,
			linkForMoreInfo:null,
			omniPageNameForSignUp:null,
			
		    init:function() {
		     	//set variables
		     	//update: 4.07
		     	var constants = marketMessagService.view.constants;
		 		var emailRegistrationDisplayManager = marketMessagService.view.emailRegistrationDisplayManager;
		 		
		 		
		 		
		 		
				if (window["marketMessagService"] != undefined){
					//if window (string is not undefined)
			    	if (marketMessagService.isCanadaMarketCandidate == 'true') {
						emailRegistrationDisplayManager.interceptMarket = constants.CA_COUNTRY_CODE;
					}
					else if (marketMessagService.isEuMarketCandidate == 'true') {
						emailRegistrationDisplayManager.interceptMarket = constants.GB_COUNTRY_CODE;
					}
					/*	
					if (marketMessagService.requestOriginCountryCode){
						this.interceptMarket = marketMessagService.requestOriginCountryCode;
						}
					*/	
				}	
				
				//start forced mode testing
						if (gidLib.getQuerystringParam('forcedCountry',true)) {
							var forcedCountry = gidLib.getQuerystringParam('forcedCountry',true);
							emailRegistrationDisplayManager.interceptMarket = forcedCountry;
							//alert(emailRegistrationDisplayManager.interceptMarket);
						}	
				//end forced mode testing	
		
				if (emailRegistrationDisplayManager.interceptMarket == 'CA') {
					//alert('start evaluator');
					emailRegistrationDisplayManager.interceptEvaluator();
				}
					
		    },
		
		      
		    interceptEvaluator:function() {
		    		var constants = marketMessagService.view.constants;
		 			var emailRegistrationDisplayManager = marketMessagService.view.emailRegistrationDisplayManager;
		    		
		    		//get current date to compare with cookie
					emailRegistrationDisplayManager.nowTime = new Date();
					emailRegistrationDisplayManager.timeNowInMilliSecs = emailRegistrationDisplayManager.nowTime.getTime();
					
					//start forced mode testing
						if (gidLib.getQuerystringParam('interceptDate',true)) {
							emailRegistrationDisplayManager.interceptDateRaw = gidLib.getQuerystringParam('interceptDate');
							emailRegistrationDisplayManager.timeNowInMilliSecs = Date.parse(emailRegistrationDisplayManager.interceptDateRaw);
						}	
					//end forced mode testing
			
			    	emailRegistrationDisplayManager.interceptBrand = brandConst.BRAND_ID;
					emailRegistrationDisplayManager.interceptBusinessUnit = emailRegistrationDisplayManager.interceptBrand+emailRegistrationDisplayManager.interceptMarket;
						
					//grab cookies	
					//emailRegistrationDisplayManager.interceptSeenCookieKey = "interceptSeen"+emailRegistrationDisplayManager.interceptBusinessUnit;
					emailRegistrationDisplayManager.interceptSeenExpire = gidLib.getCookieVar("mktUniversalPersist", "UKANintSeenCAProd");				
			    	
				
					//check date expire for interceptSeen
					if ((emailRegistrationDisplayManager.interceptSeenExpire != "") && (emailRegistrationDisplayManager.timeNowInMilliSecs < emailRegistrationDisplayManager.interceptSeenExpire)) {
						emailRegistrationDisplayManager.hasUserSeenInPast30Days = true;		
					}
					else {
						emailRegistrationDisplayManager.hasUserSeenInPast30Days = false;
					}
			
				//if did not submit email (current brand and origin)
				//AND 
				//session cookie is expired
				//THEN show popup with the brandOrigin variable
				if ( emailRegistrationDisplayManager.hasUserSeenInPast30Days == false ) {
					emailRegistrationDisplayManager.isInterceptDisplayRequired = true;
					//alert('dispaly req true');
									}
			},
			
			editTitleBar:function() {
					if ($('layeredPopupNoDragFrameTop')) {
						Element.replace($('layeredPopupNoDragFrameTop'), '<div style="width: 375px;" class="topMiddle" id="layeredPopupNoDragFrameTop">old navy</div>');
					}		
		
			}
						
		}//end 	emailRegistrationDisplayManager
	}//end view
}); //end obj extend

