String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/gi,"") };
var iBrowserVersion;
$(document).ready(function() {	
	// START BROWSER TWEAKS
		iBrowserVersion = Number($.browser.version);
		if($.browser.msie) {  // Apply all Internet Explorer tweaks (all version?)
			$('#ffTopImage').css('width','246px');
			$('#ffBotImage').css('width','246px');
			$('#redeemMilesFFContainer').css('margin-top','-4px');
			if(iBrowserVersion==6) { // Apply all Internet Explorer 6 tweaks
				$('#redeemMilesTopDashedLine').css('margin-left','6px');
				$('#redeemMilesFFHeaderText').css('top','1px');
				$('#redeemMilesContentTitle').css('margin-top','6px');
				$('#redeemMilesContentTitle').css('margin-bottom','2px');
				$('.ff_ChangeTo238').width('238px'); // ADDED FOR PSU-6069
				$('.ff_ChangeTo247').width('247px'); // ADDED FOR PSU-6069
			} else if (iBrowserVersion > 6) { // Fix all Internet Explorer 7 tweaks
				$('#redeemMilesContentTitle').css('top','-1px');
				$('#redeemMilesTopDashedLine').width('473px');
			$('.ff_ChangeTo238').width('238px'); // ADDED FOR PSU-6069
			$('.ff_ChangeTo247').width('247px'); // ADDED FOR PSU-6069
			}
		} else if($.browser.safari) { // Apply all saferi tweaks
			document.getElementById('redeemMilesLowerContentTable').setAttribute('height','476');
			$('.ff_ChangeTo238').width('239px'); // ADDED FOR PSU-6069
			$('.ff_ChangeTo247').width('248px'); // ADDED FOR PSU-6069
		  $('#redeemMilesContentTitle').css('padding-left','1px');
		  $('#redeemMilesContentTitle').css('margin-top','8px');
		  $('#redeemMilesContentTitle').css('margin-bottom','4px');
			
			// Check for Safari on a Mac
			if(navigator.userAgent.indexOf("Macintosh") > -1) {
				$('#sel_return_to').width('120px');
				$('#redeemMilesTopDashedLine').css('margin-left','5px');
				$('#redeemMilesTopDashedLine').width('473px');
			}
		} else if($.browser.mozilla) { // Apply all FireFox tweaks
		  $('#redeemMilesContentTitle').css('padding-left','1px');
		  $('#redeemMilesContentTitle').css('margin-top','8px');
		  $('#redeemMilesContentTitle').css('margin-bottom','2px');
		  $('#redeemMilesTopDashedLine').width('475px');
			$('.ff_ChangeTo238').width('238px'); // ADDED FOR PSU-6069
			$('.ff_ChangeTo247').width('247px'); // ADDED FOR PSU-6069
			
			var sMyFFVersion = String($.browser.version).trim();
			if(sMyFFVersion == "1.9.0.15") {
				$('.ff_ChangeTo238').width('239px'); // ADDED FOR PSU-6069
			}
			
			// Check for FireFox on a Mac
			if(navigator.userAgent.indexOf("Macintosh") > -1) {
				$('#sel_return_to').width('120px');
			}
		} else {
			$('.ff_ChangeTo238').width('238px'); // ADDED FOR PSU-6096
			$('.ff_ChangeTo247').width('247px'); // ADDED FOR PSU-6096
			$('#redeemMilesFFContainer').css('margin-top','-8px');
		}
	
	// END BROWSER TWEAKS
	
	//$('div.loginborder').border('landingd2d-');
	$('div.height').css("height", "123px");
	$('div.height1').css("height1", "313px");
		
	$("#ff29loginlink").click(function() {
		$('#ff29loginbox').slideToggle('fast');	
		$("#ff29loginlink").hide();
		return false;
	});
	// toggle to award mode and hide tabs
	//$('#affContainer').show();
	chgAff(2);
	$('#aff, #ff29loginlink, #ff29loginpanel').hide();
	$('#ff29search, #ff29loginpanel').css('padding-top','0');
	// moved into ready function to call after dom- Sunil-08/31/09
	// $.getScript("http://content.united.com/ual/asset/swn-scripts-2007.js",function(){
	//determine login state
	if (isDefined(myCookies["rememberProfile"]) && isDefined(myCookies["isSecure"]) && myCookies["isSecure"]=="true") {
		//var mpiNumber=parsedValue[0];
		//var homeArpt=parsedValue[5];
		var profile=myCookies["rememberProfile"];
				profile = unescape(profile);
		var parsedValue=profile.split("||");
		var mpLevel=parsedValue[3];
		var mpBal=parsedValue[4];
		if (isDefined(myCookies["mpInformation"])) {
			var profile=myCookies["mpInformation"];
					profile = unescape(profile);
			var parsedValue=profile.split("||");
			var prefix=parsedValue[0];
			var firstName=parsedValue[1];
			var middleinit=parsedValue[2];
			var lastName=parsedValue[3];
			var suffix= parsedValue[4];
			var emlErrFlg = parsedValue[5];
			var addrErrFlg = parsedValue[6];
			if ((parsedValue.length >= 9 ) && ( isDefined("country") || country=="united" )){
				pbaoLandingPageSub = parseInt(parsedValue[7]);
				epuLandingPageSub =  parseInt(parsedValue[8]);
				rccLandingPageSub = parseInt(parsedValue[9]);
			}
			//alert("prefix: "+prefix+"\ninitial: "+middleinit+"\nsuffix: "+suffix);
		}
		
		// Hide the login boxes
		$('.removeMyId').hide();
		
		//31 characters print OK		
		if (firstName.length < 31 || (firstName.length > 31 && firstName.indexOf(" ") > -1 && firstName.indexOf(" ")  < 31))  {
			$('#loggedin').html('<span style="color:#000000;"><B>Hello ' +prefix+' '+ firstName+' ' +middleinit+ ' ' + lastName +' '+suffix +'</b></span>');
		} else {
			//give up, print HELLO only
			$('#loggedin').html('<div style="color:#000000;"><B>Hello </b></div>');
		}
		if (mpLevel != "" && mpBal != "") {
			$('#loggedin').append('<div style="white-space:nowrap;color:#000000;margin-top:5px">' + mpLevel + '</div>');
			$('#loggedin').append('<div style="white-space:nowrap;color:#000000;margin-top:5px">' + 'MP Visa Signature Card'+ '</div>');
			$('#loggedin').append('<div style="white-space:nowrap;color:#000000;margin-top:5px;margin-left:100px;padding-right:10px;text-align:right;font-weight: bold;">' + addCommas(mpBal)+'  Miles ' + '</div>');
		}
		var lang="en"; // for now, only errors in english
		if ((typeof(country)== "undefined" || country=="united" )&& (emlErrFlg == "true" || addrErrFlg == "true")) {
			$('#loggedin').append('<div style="color:#FFF794;">' + gblErr[lang][0]+' <a href="https://www.ua2go.com/ci/UpdateProfile.jsp">'+gblErr[lang][1]+'</a></div>');
		}
		//This block is added for annual options -- starts here
		var countAO = 3;
		if((pbaoLandingPageSub > 0 && pbaoLandingPageSub < 4)) { countAO--; }
		if((epuLandingPageSub > 0 && epuLandingPageSub < 4)) { countAO--; }
		if((rccLandingPageSub > 0 && rccLandingPageSub < 4)) { countAO--; }
	
		if((rccLandingPageSub > 0 && rccLandingPageSub < 4)|| (epuLandingPageSub > 0 && epuLandingPageSub < 4)|| (pbaoLandingPageSub > 0 && pbaoLandingPageSub < 4)) {
			var topStyleLogin = countAO * 10;
			document.getElementById("loggedin").style.paddingTop= topStyleLogin+'px';
			$('#loggedin').append('<div style="clear:left;line-height:1px;"> </div><span style="white-space: nowrap;color:#EEEEEE;">Annual options</span>');
			if(epuLandingPageSub > 0 && epuLandingPageSub < 4){
				$('#loggedin').append('<div class=""><ul><li><a href="https://store.united.com/traveloptions/control/product?product_id=UM_EPA&category_id=UM_LEGRM&navSource=My+Profile+Subscriptions&linkTitle=UM_EPA">Economy Plus</a></li></ul></div>');
			}
			if(pbaoLandingPageSub > 0 && pbaoLandingPageSub < 4){
				$('#loggedin').append('<div class=""><ul><li><a href="https://store.united.com/traveloptions/control/product?product_id=UM_PBA&category_id=UM_BAGS&navSource=My+Profile+Subscriptions&linkTitle=UM_PBA">Premier Baggage</a></li></ul></div>');
			}
			if(rccLandingPageSub > 0 && rccLandingPageSub < 4){
				$('#loggedin').append('<div class=""><ul><li><a href="https://store.united.com/traveloptions/control/product?product_id=UM_RCC&category_id=UM_LOUNGES&navSource=My+Profile+Subscriptions&linkTitle=UM_RCC">Red Carpet Club</a></li></ul></div>');
			}
		}
		//This block is added for annual options -- ends here

		$('#loggedin').append('<div style="padding-right:10px;text-align:right;"><a href="http://www.united.com/updateprofile">My profile</a> ' +'|'+ ' <a href="https://www.ua2go.com/ci/Login.jsp?return_to=mpsummary_us">My mileage summary</a> '+'|'+ ' <a href="https://www.ua2go.com/ci/Logout.jsp?static=true">Log out</a></div>').show();
		//since we're logged in, hide the MP login and guest login divs, just display the condinue button.
		//$('#mi_notLogged, #cio_mplogin, #cio_gstlogin').hide();	
		
		document.getElementById('loggedin').setAttribute('id','loggedin2')
	} else {  
		//display the log in modules and look for remember cookies. If found fill in userid field
		if (myCookies["rememberME"] != undefined) {
			//	if (cookieAUTHTYPE!= undefined) {	
			switch (myCookies["rememberME"]) {
				case "E":
					var rememberEmail = myCookies["rememberEMAIL"];
					//fill 3 fields with this value
					if(rememberEmail) { $('input.userId').val(rememberEmail); }
				break;
				case "M":
					var rememberMP = myCookies["getMP"];
					//fill 3 fields with this value
					if (rememberMP) { $('input.userId').val(rememberMP); }
				break;
			}
			
			// click remember me box 3 locations
			$.fn.check = function() {
				return this.each(function() {
					this.checked = true;
				});
			};
			
			//if value, check the checkbox
			$(".remMP").check();
		}
		$('.removeMyId').show();
	}
	
	// SMS - ADDED FOR PSU-6096 To Set the Default Selected Option in the top right login box to Reedem Miles
	document.getElementById('sel_return_to').options[document.getElementById('sel_return_to').options.length-1].selected = true;
}); //end function loading swn-scripts-2007.js
