/* 
 * ua.united.js
 * 
 * Created: Nov 2010
 * Author: Rob O'Brien
 * Version: 1.0
 * 
 * Dependencies:
 * ua.js
 * 
 * United.com specific functionality
 * 
 */

ua.united = new function(){

};

ua.united.utils  = new function(){
	
}();



/* 
 * 
 * 
 * Original code from swn-scripts-2007.js
 * Modifications to remove redundant functions (defined in ua.js) 
 * and use of new UA namespace functionality. Also refactored much
 * of the code to clean it without affecting functionality. It should 
 * all be worked into the ua.united namespace (above) over time.
 * Rob O - 12/7/10
 * 
 * 
 */

if (typeof DASwitch == "undefined"){
	var DASwitch = true; /* added this switch to control Dynamic Air project changes */
}
var ecoOaRedirectOrigin = "N/A";
var ecoOaRecordLocValue = "N/A";

var pbaoSub = 0;
var epuSub = 0;
var rccSub = 0;

var annualOptions = [];
	annualOptions.push(["Expiring soon", "Will expire within the next 60 days.", "Renew now"]);
	annualOptions.push(["Auto Renewing", "Your annual option is scheduled to renew within 30 days.", ""]);
	annualOptions.push(["Option Expired", "Your annual option has expired.", "Renew now"]);

var epuOptions = ["Economy Plus", "https://www.united.com/ual/asset/economyPlus_37x30.gif", "Economy Plus annual option", "https://store.united.com/traveloptions/control/product?product_id=UM_EPA&category_id=UM_LEGRM&navSource=My+Profile+Subscriptions&linkTitle=UM_EPA"];
var rccOptions = ["United Club", "https://www.united.com/ual/asset/RCC_37x30.gif", "United Club annual option", "https://store.united.com/traveloptions/control/product?product_id=UM_RCC&category_id=UM_LOUNGES&navSource=My+Profile+Subscriptions&linkTitle=UM_RCC"];
var pbaoOptions =["Premier Baggage", "https://www.united.com/ual/asset/PBAO_37x25.gif", "Premier Baggage annual option", "https://store.united.com/traveloptions/control/product?product_id=UM_PBA&category_id=UM_BAGS&navSource=My+Profile+Subscriptions&linkTitle=UM_PBA"];

var StartinSelectLst = [];
	StartinSelectLst.push(["My MileagePlus", "&return_to=mp_review", "SI~MP"]);
	StartinSelectLst.push(["My reservations", "&return_to=newitin_us", "IC"]);
	StartinSelectLst.push(["-------------------", "", ""]);
	StartinSelectLst.push(["Shop for flights", "&return_to=booking_us", "PB"]);
	if (DASwitch) {
		StartinSelectLst.push(["Book with miles", "&return_to=mp_award_ibe_bridge&fwdPath=awardShop&country=us", ""]);
	}else{
		StartinSelectLst.push(["Book with miles", "&return_to=awardShop_us", ""]);
	}
	/*StartinSelectLst.push(["Book with miles", "&return_to=awardShop_us", ""]);*/
	StartinSelectLst.push(["United Club", "&return_to=rcc&echoParam=rcchome", ""]);
	StartinSelectLst.push(["-------------------", "", ""]);
	StartinSelectLst.push(["Check-in online", "&return_to=easy_checkin", ""]);
	StartinSelectLst.push(["Change reservations", "&return_to=rax", ""]);
	StartinSelectLst.push(["Upgrades", "&return_to=eug_sum", ""]);
	StartinSelectLst.push(["Ticket refunds", "&return_to=refund", ""]);
	StartinSelectLst.push(["-------------------", "", ""]);
	StartinSelectLst.push(["My profile", "&whereto=UpdateProfile.jsp", ""]);
	StartinSelectLst.push(["Flight notification", "&return_to=centerPost", ""]);
	StartinSelectLst.push(["My trip templates", "&return_to=triptemplate", ""]);

//update the dropdown list
//[0] = label, [1] = url, [2] = selected index
function writeStartIn() {
	if (document.forms.topLogin) {
		selObj = document.topLogin.sel_return_to;
		selObj.length = 0;
		for (q = 0; q < StartinSelectLst.length; q++) {
			selObj.options[q] = new Option(StartinSelectLst[q][0], StartinSelectLst[q][1]);
			if (StartinSelectLst[q][2].indexOf(selectedSection) > -1) selObj.options[q].selected = true;
		}
	}
}

var gblErr = [];
gblErr["en"] = ['Our records indicate that some of your profile information is invalid. ', 'Update your profile'];

function HPSearch(frm) {
	//if_queryForm(frm); insight first tag, deactivated
	return true;
}

function elevenLength(MPNO) {
	var id = MPNO.value.trim();
	if (MPNO && id != "" && id.length < 11) {
		while (id.length < 11) {
			id = "0" + id;
		}
		MPNO.value = id;
	}
}

function IsUserIdNumeric(a, addChars) {
	var i;
	var id = TrimString(a.value);
	if (id.length == 0) {
		return true;
	}
	for (i = 0; i < id.length; i++) {
		var c = id.charAt(i);
		if (!ua.utils.isNumeric(c) && !isCharInString(c, addChars)) {
			return false;
		}
	}
	return true;
}

function isCharInString(sc, s) {
	return (!sc || !s) ? false : (s.indexOf(sc) > -1) ? true : false;
}

function isMpNumber(MPNO) {
	if (MPNO != null && MPNO.length == 11 && !(MPNO == "00000000000")) {
		var s = MPNO;
		var w60count1 = 0;
		var w60count2 = 0;
		w60count1 = s.substring(0, 1) * 5 + s.substring(1, 2) * 4 + s.substring(2, 3) * 3 + s.substring(3, 4) * 2 + s.substring(4, 5) * 7 + s.substring(5, 6) * 6 + s.substring(6, 7) * 5 + s.substring(7, 8) * 4 + s.substring(8, 9) * 3 + s.substring(9, 10) * 2;
		var w60remainder = w60count1 % 11;
		w60count1 = w60count1 / 11;
		if (w60remainder != 0) {
			w60count2 = 11 - w60remainder;
		} else {
			w60count2 = 0;
		}
		if (w60count2 == 10) {
			w60count2 = 0;
		}
		if (w60count2 != s.substring(10)) {
			return false;
		} else {
			return true;
		}
	}

	return false;
}

function remMP(name) {
	var today = new Date();
	var expires = new Date();
	expires.setTime(today.getTime() + 1000 * 60 * 60 * 24 * 365 * 2);
	ua.utils.setCookie("getMP", name, expires);
}

function remEMAIL(email) {
	var today = new Date();
	var expires = new Date();
	expires.setTime(today.getTime() + 1000 * 60 * 60 * 24 * 365 * 2);
	ua.utils.setCookie("rememberEMAIL", email, expires);
}


/*updated chngbox to refer to passed form name rather than just form name=MileagePlus*/
function chngbox(f) {
	if (f.remMP.checked == false) {
		ua.utils.deleteCookie("getMP", "/");
		ua.utils.deleteCookie("getMP");
		ua.utils.deleteCookie('rememberME');
		ua.utils.deleteCookie('rememberEMAIL');
		ua.utils.deleteCookie('rememberMP');
	} else {
		if ("getMP" in ua.cookies) {
			if (f.userId.value) {
				f.userId.value = ua.cookies.getMP;
			}
			f.remMP.checked = true;
		}
	}
}

function ValidateUserIdHome(f) {
	var MPNO = f.userId;
	var id = MPNO.value.trim();
	var cr = '\n';
	var msg = '';
	var isMP = false;
	var valid = true;
	var pwd = f.password.value.trim();

	//disable log in button
	if (id.length == 0 || id.value == "MileagePlus # or email address") {
		valid = false;
		msg = 'MileagePlus # or email address is a required field. ' + cr;
	}

	if (valid) {
		var isNum = IsUserIdNumeric(MPNO, null);
		if (isNum) {
			isMP = true;
			elevenLength(MPNO);
			id = TrimString(MPNO.value);
		}
		if (isMP) {
			valid = isMpNumber(id);
			if (!valid) {
				msg = 'The MileagePlus number you have entered is invalid. Please check the number and resubmit.' + cr;
			}
		}
		else {
			valid = isEmail(id);
			if (!isMP & !valid) {
				msg = 'The MileagePlus number or the email address you have entered is invalid. Please check the number or email address and resubmit.' + cr;
			}
		}
	}
	if (pwd.length == 0) {
		msg += 'Password is a required field.' + cr;
	}

	if (msg) {
		msg = 'Please Supply the Following:' + cr + cr + msg;
		alert(msg);
		return false;
	}
	
	/* Before we submit the form, let's remove extraneous field(s) */
	$('#topLoginUserPass_text').remove();
	
	return true;
}

function ValidateUserId(f) {
	if (f.sel_return_to.value == "") {
		return false;
	}
	var MPNO = f.userId;
	var id = MPNO.value.trim();
	var cr = '\n';
	var msg = '';
	var isMP = false;
	var valid = true;
	var pwd = f.password.value.trim();
	
	//disable log in button
	if (id.length == 0) {
		valid = false;
		msg = 'MileagePlus # or email address is a required field. ' + cr;
	}
	if (valid) {
		var isNum = IsUserIdNumeric(MPNO, null);
		if (isNum) {
			isMP = true;
			elevenLength(MPNO);
			id = MPNO.value.trim();
		}
		if (isMP) {
			valid = isMpNumber(id);
			if (!valid) {
				msg = 'The MileagePlus number you have entered is invalid. Please check the number and resubmit.' + cr;
			}
		}
		else {
			valid = ua.utils.isEmail(id);
			if (!isMP & !valid) {
				msg = 'The MileagePlus number or the email address you have entered is invalid. Please check the number or email address and resubmit.' + cr;
			}
		}
	}
	if (pwd.length == 0) {
		msg += 'Password is a required field.' + cr;
	}

	if (msg) {
		msg = 'Please Supply the Following:' + cr + cr + msg;
		alert(msg);
		return false;
	}
	f.action = "https://www.ua2go.com/ci/DoLogin.jsp?stamp=NEWCOOKY*itn/ord=NEWREC,itn/air/united" + f.sel_return_to.value;
	//if_queryForm(f); insight first tag, deactivated
	return true;
}


function toggleGLL() {
	document.getElementById('swnGLLform').style.display = 'inline';
	document.getElementById('swnGLLtext').innerHTML = '<img id="swnGLLarrow" src="' + writeSWNprotocol + '://www.united.com/ual/asset/swn_2007_loginarrowdown.gif" height="11" width="11" alt="">&nbsp;&nbsp;Login';
	//document.getElementById('swnGLLnotamemtable').style.display='none';
}

function isDefined(variable) {
	return (!(!(variable || false)));
}

function embedGLL() {
	var mpSummaryReturnToVal = "mpsummary";
	var gllMyItinsPath = "https://www.ua2go.com/ci/Login.jsp?return_to=newitin";
	if (window.currentUALsite) {
		if (currentUALsite == "US-EN") {
			mpSummaryReturnToVal = "mp_review"; //used to append _us for mpsummary for US-EN customers
			gllMyItinsPath += "&navSource=LeftNav07&linkTitle=My+itineraries"; // domestic customers get IF tracking added
		} else if (currentUALsite == "US-ES") {
			mpSummaryReturnToVal = "mp_review"; //used to append _us for mpsummary for US-ES customers
			gllMyItinsPath += "&navSource=LeftNav07&linkTitle=My+itineraries"; // domestic customers get IF tracking added
		}
	}
	//Intl embedGLL patch SHD 02/11/2007
	// start with generic link 
	var redeemStr = '<tr><td valign="top" class="swnRelatedLinksgt">></td><td valign="top" class="swnRelatedLinksitem"><a href="http://www.united.com/page/article/0,6722,3831,00.html">Redeem miles</a></td></tr>';
	var itinStr = '<tr><td valign="top" class="swnRelatedLinksgt">></td><td valign="top" class="swnRelatedLinksitem"><a href="' + gllMyItinsPath + '">View my itineraries</a></td></tr>';
	//check for awardURL string--only defined in Intl sites.
	if (typeof(awardURL) != 'undefined') {
		if (awardURL == null) { //non-booking sites, suppress link
			redeemStr = "";
			itinStr = "";
		} else if (ua.utils.listContains(countryTel, "in,dk,se,nzit,tw,th,vn,es,ru,kw,ae,bh", "any")) {
			redeemStr = '<tr><td valign="top" class="swnRelatedLinksgt">></td><td valign="top" class="swnRelatedLinksitem"><a href="https://www.ua2go.com/ci/Login.jsp?return_to=mp_award_ibe_bridge">Redeem miles</a></td></tr>';
		} else if (awardURL) { //intl booking site with link
			redeemStr = '<tr><td valign="top" class="swnRelatedLinksgt">></td><td valign="top" class="swnRelatedLinksitem"><a href="' + awardURL + '">Redeem miles</a></td></tr>';
		}
	} //end awrdURL
	// rcc patch begin
	var isRedCarpet = false;
	var rccURL = document.location.href;
	rccURL = rccURL.toLowerCase();
	if (rccURL.indexOf('/rcc/') != -1) {
		isRedCarpet = true;
	}
	// rcc patch end
	// ua2go patch begin
	var isAppServer = false;
	var appServerURL = document.location.href;
	appServerURL = appServerURL.toLowerCase();
	if ((appServerURL.indexOf('www.ua2go.com') == -1) || (appServerURL.indexOf('travel.united.com') == -1)) {
		isAppServer = true;
	}
	// ua2go patch end
	if ("rememberProfile" in myCookies && "isSecure" in myCookies && myCookies["isSecure"] == "true") {
		var profile = myCookies["rememberProfile"];
		profile = unescape(profile);
		var parsedValue = profile.split("||");
		var mpiNumber = parsedValue[0];
		var mpLevel = parsedValue[3];
		var mpBal = parsedValue[4];
		var homeArpt = parsedValue[5];
		if ("mpInformation" in myCookies) {
			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) && (typeof(country) == "undefined" || country == "united")) {
				pbaoSub = parseInt(parsedValue[7]);
				epuSub = parseInt(parsedValue[8]);
				rccSub = parseInt(parsedValue[9]);
			}

			//alert("prefix: "+prefix+"\ninitial: "+middleinit+"\nsuffix: "+suffix);
		} //end mpInformation
		var errorStr = "";
		if ((typeof(country) == "undefined" || country == "united") && (emlErrFlg == "true" || addrErrFlg == "true")) {
			var lang = "en"; // for now, only errors in english
			errorStr = '<div style="color:#CC0000; font-size:10px;margin-left:5px">' + gblErr[lang][0] + '<a href="https://www.ua2go.com/ci/UpdateProfile.jsp">' + gblErr[lang][1] + '</a></div>';
		}

		//var swnlogoutUrl = "https://www.mileageplus.com/mp/logout.jsp";
		var swnlogoutUrl = "https://www.ua2go.com/ci/Logout.jsp"; //Per Naresh 11/18/2010
		//if (!isAppServer && !isRedCarpet)	{ swnlogoutUrl+='?static=true';}
		if (document.location.href.indexOf("etc/webcheckin/nonrevenue") != -1) {
			swnlogoutUrl = "https://www.ua2go.com/etc/webcheckin/nonrevenue/logout.do";
		} // for NRSA Logins
		if (firstName.length <= 6) {
			document.write('<div id="swnGLLhello">Hello ' + firstName + '</div>');
		} // hello firstName on one line
		if ((firstName.length > 6) && (firstName.length <= 9)) {
			document.write('<div id="swnGLLhello">Hello<br>	' + firstName + '</div>');
		} // hello firstName on two lines
		if (firstName.length > 9) {
			document.write('<div id="swnGLLhello">Hello</div>');
		} // hello no name (name is too long 
		//write out the left rail
		document.write('<div id="swnGLLstatus">' + mpLevel + '</div>' + '<table border="0" cellpadding="0" cellspacing="0" width="100%">');

		if (mpBal.length > 0) {
			document.write('<tr><td valign="top" class="swnRelatedLinksgt">></td><td valign="top" class="swnRelatedLinksitem"><a href="https://www.ua2go.com/ci/Login.jsp?return_to=' + mpSummaryReturnToVal + '">' + mpBal.commafy() + ' miles</a></td></tr>');
		}

		document.write(redeemStr + itinStr + '</table>');

		if ((pbaoSub > 0 && pbaoSub < 4) || (epuSub > 0 && epuSub < 4) || (rccSub > 0 && rccSub < 4)) {
			//write out the left rail
			document.write('<div id="swnGLLstatusAO">Annual Options</div>' + '<table border="0" cellpadding="0" cellspacing="0" width="100%">');

			if (epuSub > 0 && epuSub < 4) {
				document.write('<tr><td valign="top" class="swnRelatedLinksgt">></td><td valign="top" class="swnRelatedLinksitem"><a href="' + epuOptions[3] + '">' + epuOptions[0] + '</a></td></tr>');
			}
			if (pbaoSub > 0 && pbaoSub < 4) {
				document.write('<tr><td valign="top" class="swnRelatedLinksgt">></td><td valign="top" class="swnRelatedLinksitem"><a href="' + pbaoOptions[3] + '">' + pbaoOptions[0] + '</a></td></tr>');
			}
			if (rccSub > 0 && rccSub < 4) {
				document.write('<tr><td valign="top" class="swnRelatedLinksgt">></td><td valign="top" class="swnRelatedLinksitem"><a href="' + rccOptions[3] + '">' + rccOptions[0] + '</a></td></tr>');
			}

			document.write('</table>');
		}

		if (errorStr.length > 0) document.write(errorStr);
		document.write('<div id="swnGLLmyproflogout"><a href="https://www.ua2go.com/ci/UpdateProfile.jsp">My profile</a>&nbsp;<span id="swnGLLmyproflogoutPipe">|</span> <a href="' + swnlogoutUrl + '">Log out</a></div>');
	}
	else { //not logged in state
		var bookWithMilesLink="";
		if (DASwitch){
			bookWithMilesLink="mp_award_ibe_bridge&fwdPath=awardShop&country=us";
		}else{
			bookWithMilesLink="awardShop_us";
		}
		document.write('<div id="swnGLLid">' + '	<span id="swnGLLtext"><img id="swnGLLarrow" src="' + writeSWNprotocol + '://www.united.com/ual/asset/swn_2007_loginarrowright.gif" height="11" width="11" alt="" border="0">&nbsp;&nbsp;<a href="#" onmousedown="toggleGLL();">Login</a></span>' + '</div>' + '<div id="swnGLLform">' + '<form class="nospace" method="POST" action="https://www.ua2go.com/ci/DoLogin.jsp?stamp=NEWCOOKY*itn/ord=NEWREC,itn/air/united&return_to=ff_acct_hist" name="MileagePlus" onSubmit="return ValidateUserId(this);" style="margin:0;" target="_top">' + '	<div id="swnGLLlogin">MileagePlus #<br>or email address</div>' + '	<div id="swnGLLloginbox"><input type="text" id="swnGLLuserid" name="userId"></div>' + '	<div id="swnGLLpass">Password</div>' + '	<div id="swnGLLpassbox"><input type="password" id="swnGLLpassword" name="password"></div>' + '	<div id="swnGLLremem"><input type="checkbox" name="remMP">Remember me</div>' + '	<div id="swnGLLstartin">Start in</div>' + '	<div id="swnGLLdrop"><select id="swnGLLdropdown" name="sel_return_to">' + '		<option value="&return_to=' + mpSummaryReturnToVal + '" selected>My MileagePlus</option>' + '		<option value="&return_to=newitin_us">My itineraries</option>' + '		<option value="">-------------------</option>' + '		<option value="&return_to=booking_us" >Shop for flights</option>' + '		<option value="&return_to='+ bookWithMilesLink+'">Book with miles</option>' + '		<option value="&return_to=rcc&echoParam=rcchome">United Club</option>' + '		<option value="">-------------------</option>' + '		<option value="&return_to=easy_checkin">Check in online</option>' + '		<option value="&return_to=rax">Change itineraries</option>' + '		<option value="&return_to=eug_sum">Upgrades</option>' + '		<option value="&return_to=refund">Ticket refunds</option>' + '		<option value="">-------------------</option>' + '		<option value="&whereto=UpdateProfile.jsp">My profile</option>' + '		<option value="&return_to=centerPost">Flight notification</option>' + '		<option value="&return_to=triptemplate">My trip templates</option>' + '	</select>' + '	</div>' + '	<div id="swnGLLsubmit"><input type="image" src="' + writeSWNprotocol + '://www.united.com/ual/asset/swn_2007_buttonlogin.gif" border="0"></div>' + '	</form>' + '</div>' + '<table border="0" cellpadding="0" cellspacing="0" width="100%" id="swnGLLnotamemtable">' + '<tr><td valign="top" id="swnGLLnotamem" colspan="2">Not a member?</td></tr>' + '<tr><td valign="top" class="swnRelatedLinksgt">></td><td valign="top" class="swnRelatedLinksitem"><a href="https://www.ua2go.com/ci/JoinMileagePlus.jsp?jumpLink=%2Fjoinmp">Sign up now</a></td></tr>' + '</table>');
		writeStartIn();
		
		// this is for retriving the MileagePlus number.
		var rememberME = ua.utils.getCookie("rememberME");

		if (rememberME != undefined && rememberME == "E") {
			var rememberEmail = ua.utils.getCookie("rememberEMAIL");
			document.MileagePlus.userId.value = rememberEmail;
			document.MileagePlus.remMP.checked = true;
		}
		else {
			var rememberMP; // init to null
			// then reassign if necessary
			if (ua.utils.getCookie("getMP")) {
				rememberMP = ua.utils.getCookie("getMP");
			} // *.united.com
			if (ua.utils.getCookie("rememberMP")) {
				rememberMP = ua.utils.getCookie("rememberMP");
			} // ua2go.com
			if (rememberMP != null) {
				document.MileagePlus.userId.value = rememberMP;
				document.MileagePlus.remMP.checked = true;
			}
		} //end remember me cookie
	} //end logged out
} //end embedGLL

function embedAnnualOptions() {
	var sideNavOptionsClass = "aobox1-body-block";
	var sepLineImage = '';
	if ((pbaoSub > 1 && pbaoSub < 5) || (epuSub > 1 && epuSub < 5) || (rccSub > 1 && rccSub < 5)) {
		document.write('<div style="padding-top:8px;"><div class="aobox-bg-shade"><div class="aobox_sidenav_corner1"><div class="aobox_sidenav_corner2"><div class="aobox-head-height"><span class="aobox-heading">Important notice</span></div></div></div></div><div class="ao-sidenav-fd">');
		var indexArr = 0;
		if (epuSub > 1 && epuSub < 5) {
			indexArr = epuSub - 2;
			document.write('<div class="' + sideNavOptionsClass + '"><div class="ao-side-img"><img src="' + epuOptions[1] + '" /></div><div class="ao-alert-text">' + annualOptions[indexArr][0] + '</div><div class="ao-heading-text"><b>' + epuOptions[2] + '</b><br />' + annualOptions[indexArr][1] + '<br /><b><a href="' + epuOptions[3] + '">' + annualOptions[indexArr][2] + '</a></b></div></div>');
			sideNavOptionsClass = "aobox-body-block";
			sepLineImage = '<div><img src="https://www.united.com/ual/asset/dashed_line_98x1.gif" height="1" width="98" alt="swn_sep_line"></div>';
		}
		if (pbaoSub > 1 && pbaoSub < 5) {
			indexArr = pbaoSub - 2;
			document.write(sepLineImage + '<div class="' + sideNavOptionsClass + '"><div class="ao-side-img"><img src="' + pbaoOptions[1] + '" /></div><div class="ao-alert-text">' + annualOptions[indexArr][0] + '</div><div class="ao-heading-text"><b>' + pbaoOptions[2] + '</b><br />' + annualOptions[indexArr][1] + '<br /><b><a href="' + pbaoOptions[3] + '">' + annualOptions[indexArr][2] + '</a></b></div></div>');
			sideNavOptionsClass = "aobox-body-block";
			sepLineImage = '<div><img src="https://www.united.com/ual/asset/dashed_line_98x1.gif" height="1" width="98" alt="swn_sep_line"></div>';
		}
		if (rccSub > 1 && rccSub < 5) {
			indexArr = rccSub - 2;
			document.write(sepLineImage + '<div class="' + sideNavOptionsClass + '"><div class="ao-side-img"><img src="' + rccOptions[1] + '" /></div><div class="ao-alert-text">' + annualOptions[indexArr][0] + '</div><div class="ao-heading-text"><b>' + rccOptions[2] + '</b><br />' + annualOptions[indexArr][1] + '<br /><b><a href="' + rccOptions[3] + '">' + annualOptions[indexArr][2] + '</a></b></div></div>');
			sideNavOptionsClass = "aobox-body-block";
			sepLineImage = '<div><img src="https://www.united.com/ual/asset/dashed_line_98x1.gif" height="1" width="98" alt="swn_sep_line"></div>';
		}
		document.write('</div></div><div><img src="https://www.united.com/ual/asset/swn_2007_left_shadowbottom.gif" height="9" width="108" alt="swn_2007_left_shadowbottom"></div><div id="gllPresent"><img src="https://www.united.com/ual/asset/swn_2007_leftdots.gif" height="1" width="108" alt="swn_2007_leftdots"></div>');

	}
}

// 11-19-08 10:30am - SMS - Espanol Removal From Footer - JIRA 3491
var bEspanolRemoved;
function removeEspanolFromFooter() {
	if (isDefined(document.getElementById("ualFooter1left"))) {
		try {
			var eUalFooter = document.getElementById("ualFooter1left");
			var eUalFooterFirstChild = eUalFooter.firstChild;

			if (eUalFooterFirstChild.childNodes.length > 0) {

				if (eUalFooterFirstChild.firstChild.nodeType == 3) {

					if (eUalFooterFirstChild.firstChild.nodeValue.indexOf("Esp") > -1) {

						bEspanolRemoved = false;
					}
				}
			} else if (eUalFooter.childNodes > 0) {

				if (eUalFooter.firstChild.nodeType == 3) {

					if (eUalFooter.firstChild.nodeValue.indexOf("Esp") > -1) {
						bEspanolRemoved = false;

					}
				}
			}

			if (bEspanolRemoved == false) {
				eUalFooter.removeChild(eUalFooter.childNodes[0]);
				eUalFooter.removeChild(eUalFooter.childNodes[1]);
				bEspanolRemoved = true;
			}
		} catch (exception) {
			// Do Nothing for now on exceptions
			//alert("Caught an exception!\n\n"+exception);
		}
	}
}
ua.utils.attachEvent(window,'load',removeEspanolFromFooter);


function insightfirstcall(sDummy) {
	return true;
}

/* TODO: ECO-specific function. Move to ua.eco.js */
function embedTopGLL() {
	var mpSummaryReturnToVal = "mpsummary";
	var gllMyItinsPath = "https://www.ua2go.com/ci/Login.jsp?return_to=newitin";
	if (window.currentUALsite) {
		if (currentUALsite == "US-EN") {
			mpSummaryReturnToVal = "mpsummary_us"; //used to append _us for mpsummary for US-EN customers
			gllMyItinsPath += "&navSource=LeftNav07&linkTitle=My+itineraries"; // domestic customers get IF tracking added
		}
	}
	//Intl embedGLL patch SHD 02/11/2007
	// start with generic link 
	var redeemStr = "";
	var itinStr = "";

	// ua2go patch begin
	var isAppServer = false;
	var appServerURL = document.location.href;
	appServerURL = appServerURL.toLowerCase();

	if ("rememberProfile" in myCookies && "isSecure" in myCookies && myCookies["isSecure"] == "true") {

		document.write('<div  align="right" id="topRightbcrm" class="no_print_confirm">');


		var profile = myCookies["rememberProfile"];
		profile = unescape(profile);
		var parsedValue = profile.split("||");
		var mpiNumber = parsedValue[0];
		var mpLevel = parsedValue[3];
		var mpBal = parsedValue[4];
		var homeArpt = parsedValue[5];
		if ("mpInformation" in myCookies) {
			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) && (typeof(country) == "undefined" || country == "united")) {
				pbaoSub = parseInt(parsedValue[7]);
				epuSub = parseInt(parsedValue[8]);
				rccSub = parseInt(parsedValue[9]);
			}

			//alert("prefix: "+prefix+"\ninitial: "+middleinit+"\nsuffix: "+suffix);
		} //end mpInformation
		var errorStr = "";

		var swnlogoutUrl = "https://www.ua2go.com/ci/Logout.jsp";
		//if (!isAppServer)	{ swnlogoutUrl+='?static=true';}		

		if (firstName.length <= 6) {
			document.write('<div style="font-size:12px; ">Hello, <span style="font-weight:bold;">' + firstName + '</span> <span class="swnGLLmyproflogoutPipe">|</span> <a href="' + swnlogoutUrl + '">Logout</a></div>');
		} // hello firstName logout on one line
		if ((firstName.length > 6) && (firstName.length <= 9)) {
			document.write('<div>Hello , <b>' + firstName + '</b> <span class="swnGLLmyproflogoutPipe">|</span> <a href="' + swnlogoutUrl + '">Logout</a></div>');
		} // hello firstName on two lines
		if (firstName.length > 9) {
			document.write('<div>Hello </div>');
		} // hello no name (name is too long 
		//write out the left rail
		document.write(' <div id ="memberMilesDisp" style="font-size:12px;">');

		if (mpLevel != '') {
			document.write(mpLevel + ' - ');
		}
		if (mpBal.length > 0) {
			document.write(mpBal.commafy() + ' Miles');
		}

		document.write('</div>');
		document.write('<div style="font-size:12px;"><a href="https://www.ua2go.com/ci/Login.jsp?return_to=newitin">My reservations</a> <span class="swnGLLmyproflogoutPipe">|</span> <a href="http://www.united.com/EasyCheckinonlineFAQ">Check-in FAQs</a></div>');
		document.write('</div>');
		document.getElementById("topRightbcrm").style.display = "block";
	}
}

$(document).ready(function () {
	if (document.getElementById("memberMilesDisp")) {
		if (document.getElementById("memberMilesDisp").innerHTML != "") {
			if (document.getElementById("topRightbcrm").style.display == "block" && document.getElementById("swnPagetitle")) {
				$('#swnPagetitle').addClass('mprev');
			}
			else {
				$('#swnPagetitle').addClass('mtrev');
			}
		}
		else {
			$('#swnPagetitle').addClass('mprev_noStatus');
		}
	}

	$(".flightDeparts a, .flightArrives a").click(function (event) {
		event.preventDefault();
	});
	$("#MileagePlus_email #remMP").parent().css({
		'width': '150px'
	});
});


/* 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * Original code from global_2010.js
 * Modifications to remove redundant functions (defined in ua.js) 
 * and use of new UA namespace functionality. Also refactored much
 * of the code to clean it without affecting functionality. It should 
 * all be worked into the ua.united namespace (above) over time.
 * Rob O - 12/7/10
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 */

function validateMP(MPNO) {
	if (!/^\d{11}$/.test(MPNO)) {
		return false;
	}
	var factor = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2];
	var check = 0;
	for (var digit = 0; digit < 10; digit++)
	check += MPNO.charAt(digit) * factor[digit];
	check = (((11 - (check % 11)) % 11) % 10);
	return (check == MPNO.charAt(10));
}

/* Temporary patch for 4.11. Only when page is /promoreg do we want to redefine this function to 
 * override what is inline on the page. In doing it this way, we mitigate the chance it will 
 * affect any other function of the same name on another page.
 */
if (ua.url._location.pathname == '/promoreg') {
	function ValidateMPNO(){
		var cr = '\n'
		var msg = '';
		if (document.frmreg.MPNO.value.length == 0) {
			alert("Please enter a MileagePlus number");
			return false;
		}
		
		if (!IsNumeric(document.frmreg.MPNO.value, null) || document.frmreg.MPNO.value.length == 0) {
			msg = 'Invalid MileagePlus number.' + cr;
		}
		
		a = document.frmreg.MPNO;
		if (a && a.value != "" && a.value.length < 11) {
			while (a.value.length < 11) {
				a.value = "0" + a.value;
			}
		}
		
		if (msg) {
			alert(msg)
			return false;
		}
		else {
			document.frmreg.submit();
		}
	}
}

var tktError = "Please enter your valid confirmation number (e.g. 5M4L6M) or your 13-digit e-ticket number (e.g. 0160987654321). Both numbers can be found on your travel itinerary.\n";

function ecodlSubmit2(f) {
	var msg = "";
	var searchValue = f.searchValueId.value.replace(/[\(\)\.\-\s,]/g, "");
	f.searchValueId.value = searchValue; //put it back
	if ($("#mi_cc").is(":checked")) {
		//		$('#mi_searchValueId').attr("name", 'ccNumber');
		searchValue = searchValue.replace(/\D/g, "");
		f.searchValueId.value = searchValue; //put it back
		if (searchValue == "") {
			msg += "Please enter the credit card number.\n";
		}

		else if (!validateCC(searchValue)) {
			msg += "Please enter a valid credit card number.\n";
		}
	}
	else if ($("#mi_pnr").is(":checked")) { //confirm("checking ci_pnr");
		if (searchValue == "") {
			msg += tktError;
		}
		else if (searchValue.length < 5) {
			msg += tktError;
		}
		else if (searchValue.length <= 6) {
			if (!/^[a-zA-Z0-9]{5,6}$/.test(searchValue)) {
				msg += 'Confirmation number should only contain letters and numbers.\n'
			} else {
				$('#authForm2 #mi_pnr').val('pnr');
				//				$('#ci_searchValueId').attr("name", 'pnrNumber');
			}
		}
		else if (!/^\d{13}$/.test(searchValue)) {
			msg += tktError;
		}
		//		else if (searchValue.substr(0,3) != "016") {msg+='e-ticket must begin with "016."\n';}
		else { //confirm("good e-ticket value");
			$('#authForm2 #mi_pnr').val('tkt');
		} //end of e-ticket validation
	}

	var lastName = f.lastName.value;
	if (!lastName) {
		msg += "Please enter the last name as it appears on your itinerary.\n"
	} // check for empty form elements
	else {
		lastName = lastName.trim(); //leading trailing
		f.lastName.value = lastName; //put it back
		if (!/^[a-zA-Z]{1,40}$/.test(lastName)) msg += "Last name should only contain letters.\n"; // check for empty form elements
	}

	if (msg) {
		msg = 'Please Supply the Following:\n\n' + msg;
		alert(msg);
		document.getElementById("errorDisp").innerHTML = msg;
		return false;
	}
	return true;
}

function ecodlSubmit3(f) {
	var msg = "";
	var searchValue;
	if (document.getElementById("ccLoginBloc").style.display == "block" && document.getElementById("confirmEticketBloc").style.display == "none") {
		searchValue = f.ci_searchValueId.value.replace(/[\(\)\.\-\s,]/g, "");
		$('#ci_searchValueId').attr("value", searchValue); //put it back
		searchValue = searchValue.replace(/\D/g, "");
		$('#ci_searchValueId').val(searchValue); //put it back
		$('#ci_searchValueId').attr("name", 'ccNumber');
		if (searchValue == "") {
			msg += "Please enter the credit card number.\n";
		}
		else if (!validateCC(searchValue)) {
			msg += "Please enter a valid credit card number.\n";
		}

		f.authType.value = 'cc';
	}
	else if (document.getElementById("ccLoginBloc").style.display == "none" && document.getElementById("confirmEticketBloc").style.display == "block") {
		searchValue = $('#ci_searchValueId').val().replace(/[\(\)\.\-\s,]/g, "");
		$('#ci_searchValueId').attr("value", searchValue); //put it back
		if (searchValue == "") {
			msg += tktError;
		}
		else if (searchValue.length < 5) {
			msg += tktError
		}
		else if (searchValue.length <= 6) {
			reCipnr = /^[a-zA-Z0-9]{5,6}$/;
			if (!reCipnr.test(searchValue)) {
				msg += 'Confirmation number should only contain letters and numbers.\n'
			} else {
				$('#ci_pnr').val('pnr');
				$('#ci_searchValueId').attr("name", 'pnrNumber');
			}
		}
		else if (!/^.{13}$/.test(searchValue)) {
			msg += tktError;
		}
		else if (!/^\d{13}$/.test(searchValue)) {
			msg += 'The e-ticket should only contain numbers.\n'
		}
		//		else if (searchValue.substr(0,3) != "016") {msg+='e-ticket must begin with "016."\n';}
		else {
			$('#ci_pnr').val('tkt');
			$('#ci_searchValueId').attr("name", 'tktNumber');
		} //end of e-ticket validation
		var usrid = f.ci_searchValueId.value;
		if (usrid.length > 4 && usrid.length <= 6) {
			//pnrNumber				
			f.authType.value = 'pnr';
		} else {
			//etkt
			f.authType.value = 'tkt';
		}

	}

	var lastName = f.lastName.value;
	if (!lastName) {
		msg += "Please enter the last name as it appears on your itinerary.\n"
	} // check for empty form elements
	else {
		lastName = lastName.trim();
		f.lastName.value = lastName; //put it back
		if (!/^[a-zA-Z]{1,40}$/.test(lastName)) msg += "Last name should only contain letters.\n"; // check for empty form elements
	}

	if (msg) {
		msg = 'Please Supply the Following:\n\n' + msg;
		document.getElementById("errorBlckDisp").style.display = "block";
		document.getElementById("errorDisp").innerHTML = msg;
		return false;
	}
	return true;
}

function ValidateUserId2(f) {
	var searchValue = f.userId.value.replace(/^\s*|\s*$/g, '');
	var pwd = f.password.value;
	var msg = '';
	if (searchValue.length == 0) {
		msg = 'MileagePlus # or email address is a required field.\n';
	}

	else if (/^\d{1,11}$/.test(searchValue)) {
		while (searchValue.length < 11) {
			searchValue = "0" + searchValue
		}; //pad left with 0 until length 11
		f.userId.value = searchValue;

		if (validateMP(searchValue)) {
			f.authType.value = "mp";
		} else {
			msg = 'The MileagePlus number you have entered is invalid. Please check the number and resubmit.\n';
		} //end testing for mpno
		//try to validate for email now
	} else if (validateEml(searchValue)) {
		f.authType.value = "ea";
	} else {
		msg = 'The MileagePlus number or the email address you have entered is invalid. Please check the number or email address and resubmit.\n';
	}

	if (pwd.length == 0) {
		msg += 'Password is a required field.\n';
	}
	if (msg) {
		msg = 'Please Supply the Following:\n\n' + msg;
		alert(msg);
		//the following code is not complete SHD
		//document.getElementById("errorBlckDisp").style.display = "block";
		//document.getElementById("errorDisp").innerHTML = msg;
		return false;
	}
	return true;
}

var popupWin;
function popItUp(url) {
	popupWin = window.open(url, 'remote', 'width=500,height=400,scrollbars=yes');
	if (window.focus) {
		popupWin.focus()
	}
	//return false;
}

function ValidateUserId3(mpNum, pwd) {
	var searchValue = mpNum.replace(/^\s*|\s*$/g, '');
	var msg = '';
	if (searchValue.length == 0) {
		msg = 'MileagePlus # or email address is a required field.\n';
	}
	else if (/^\d{1,11}$/.test(searchValue)) {
		while (searchValue.length < 11) {
			searchValue = "0" + searchValue
		}; //pad left with 0 until length 11
		mpNum = searchValue;

		if (validateMP(searchValue)) {
			//f.authType.value="mp"; 
		} else {
			msg = 'The MileagePlus number you have entered is invalid. Please check the number and resubmit.\n';
		} //end testing for mpno
		//try to validate for email now
	} else if (validateEml(searchValue)) {
		//f.authType.value="ea";
	} else {
		msg = 'The MileagePlus number or the email address you have entered is invalid. Please check the number or email address and resubmit.\n';
	}

	if (pwd.length == 0) {
		msg += 'Password is a required field.\n';
	}
	if (msg) {
		msg = 'Please Supply the Following:\n\n' + msg;
		alert(msg);
		return false;
	}
	return true;
}

/* Update the Flight Status date select */
function updateDateList() {
	var today = (new Date);
	if (typeof ualhpDate != 'undefined') {
		var tmpDate = new Date(ualhpDate);
		if (ua.utils.isDate(tmpDate)) today = tmpDate;
	}
	today = today.dateFormat('yyyymmdd');
	var rangeStart = (new Date).dateAdd('d',-3);
	var numOfDays = 4; 
	var i = 0, thisDate = 0, thisVal = 0, thisDisplay = 0, selected = 0;
	var selObj = document.getElementById('flightStatusSelect');
	selObj.length = 0;
	
	for (i=0; i<numOfDays; i++){
		thisDate = rangeStart.dateAdd('d',1);
		thisVal = thisDate.dateFormat('yyyymmdd');
		thisDisplay = thisDate.dateFormat('mm/dd/yyyy');
		/* If the value is today, we select it by default */
		if (thisVal == today) { selected = true; }
		else { selected = false; }
		selObj.options[i] = new Option (thisDisplay,thisVal,selected);
	}
}
