/* Modified for 4.11 change - karthikeyan */
var NDBSwitch = true;
var flightCount; 
$(document).ready(function() {
		$.ajax({ type: "GET",
			url: "https://www.united.com/ual/asset/airportSuggestion.js", 
			dataType: "script", 
			cache: false, 
			complete: function(){ 
			setTimeout ( "readyAutosuggest()", 1);			
			/* readyAutosuggest(); implemented in airportSuggestion.js */
			resizeAutosuggest();
				try
				{
					document.body.onclick = function(e) {
						if( document.getElementById('iframe') && (document.getElementById('iframe').style.display == "block" )){
							documentOnclickForAutosuggest(); 
						}
					}									
				}catch(exception){
					//do nothing
				}
			}});
	
	if(NDBSwitch){
		var anOption = document.createElement("OPTION") ;
		anOption.text = "Flight number"; 
		anOption.value = "Checkin_4";
		document.getElementById("Checkin_type").options.add(anOption) ;																			
	}

	$('#departureStation').keyup(function(event){
		if(($(this).val().length)>3){
			var tmp = $(this).val();
			tmp=tmp.substring(0,3);			
			$('input:text[class="ecohpCheckin_ccpnrdprtFrom"]').attr('value', tmp);
		}
		$('input:text[class="ecohpCheckin_ccpnrdprtFrom"]').css('border-color', 'black');
		$('input:text[class="ecohpCheckin_ccpnrdprtFrom"]').css('border-color', '#AABDCE');
	});
	$('#ci_gli a, #flightNum a').Tooltip({
		track: true, 
		delay: 0, 
		showURL: false, 
		showBody: " - ", 
		opacity: 0.90 
	});
	
	var fileref = document.createElement("link");
	fileref.setAttribute("rel", "stylesheet");
	fileref.setAttribute("type", "text/css");
	fileref.setAttribute("href", siteURL+ 'core/lib/css/autosuggest.css');
	document.getElementsByTagName("head")[0].appendChild(fileref);	
	
	/* ON Focus Events */
	$('.ecohpCheckin_flightNumber').focus(function(){
		if($(this).val() == 'Flight Number'){
			$(this).attr({ value: ''});
			$(this).css({color:'black'});
			$('input:text[class="ecohpCheckin_flightNumber"]').css('border-color', '#AABDCE');
		}
		//$('input:text[class="ecohpCheckin_ccpnrdprtFrom"]').css('border-color', 'black');
		//$('input:text[class="ecohpCheckin_ccpnrdprtFrom"]').css('border-color', '#AABDCE');
	});
	$('.ecohpCheckin_ccpnrFirstName').focus(function(){
		if($(this).val() == 'First name'){
			$(this).attr({ value: ''});
			$(this).css({color:'black'});
			$('input:text[class="ecohpCheckin_ccpnrFirstName"]').css('border-color', '#AABDCE');
		}
	});
	$('.ecohpCheckin_ccpnrdprtFrom').focus(function(){
		if($(this).val() == 'Departing airport code'){
			$(this).attr({ value: ''});
			$(this).css({color:'black'});
			$('input:text[class="ecohpCheckin_ccpnrdprtFrom"]').css('border-color', '#AABDCE');
		}
	});
	$('#ci_searchValueId').focus(function(){
		if($(this).val() == 'Confirmation or E-Ticket number'){
			$(this).attr({ value: ''});
			$(this).css({color:'black'});
			$('input:text[id="ci_searchValueId"]').css('border-color', '#AABDCE');
		} else if($(this).val() == 'Credit card number'){
			$(this).attr({ value: ''});
			$(this).css({color:'black'});
			$('input:text[id="ci_searchValueId"]').css('border-color', '#AABDCE');
		} 
	});
	$('.ecohpCheckin_ccpnrLastName').focus(function(){
		if($(this).val() == 'Last name'){
			$(this).attr({ value: ''});
			$(this).css({color:'black'});
			$('input:text[class="ecohpCheckin_ccpnrLastName"]').css('border-color', '#AABDCE');
		}
	});

	$('.ecohpCheckin_MpNumber').focus(function(){
		if($(this).val() == 'MileagePlus # or email address'){
			$(this).attr({ value: ''});
			$(this).css({color:'black'});
			$('input:text[class="ecohpCheckin_MpNumber"]').css('border-color', '#AABDCE');
		}
	});
	$('.ecohpCheckin_Password').focus(function(){
		if($(this).val() == 'Password' || $(this).val() == ''){
			$(this).attr({ value: ''});
			$(this).css({color:'black'});
			$('input:password[class="ecohpCheckin_Password"]').css('border-color', '#AABDCE');
		}
	});
	
	/* ON Blur Events */
	$('.ecohpCheckin_flightNumber').blur(function(){
		if($(this).val() == ''){
			$(this).attr({ value: 'Flight Number'});
			$(this).css({color:'gray'});
			$('input:text[class="ecohpCheckin_flightNumber"]').css('border-color', '#AABDCE');
		}
	});
	
	$('.ecohpCheckin_ccpnrFirstName').blur(function(){
		if($(this).val() == ''){
			$(this).attr({ value: 'First name'});
			$(this).css({color:'gray'});
			$('input:text[class="ecohpCheckin_ccpnrFirstName"]').css('border-color', '#AABDCE');
		}
	});

	$('.ecohpCheckin_ccpnrdprtFrom').blur(function(){
		if($(this).val() == ''){
			$(this).attr({ value: 'Departing airport code'});
			$(this).css({color:'gray'});
			$('input:text[class="ecohpCheckin_ccpnrdprtFrom"]').css('border-color', '#AABDCE');
		}
	});
																					
	$('#ci_searchValueId').blur(function(){
		if($(this).val() == ''){			
			if(document.getElementById("Checkin_type").selectedIndex == 2 ){
				$(this).attr({ value: 'Credit card number'});
				$(this).css({color:'gray'});
				$('input:text[id="ci_searchValueId"]').css('border-color', '#AABDCE');
			} else{
				$(this).attr({ value: 'Confirmation or E-Ticket number'});
				$(this).css({color:'gray'});
				$('input:text[id="ci_searchValueId"]').css('border-color', '#AABDCE');
			}
		} 
	});
	
	$('.ecohpCheckin_ccpnrLastName').blur(function(){
		if($(this).val() == ''){
			$(this).attr({ value: 'Last name'});
			$(this).css({color:'gray'});
			$('input:text[class="ecohpCheckin_ccpnrLastName"]').css('border-color', '#AABDCE');
		}
	});

	$('.ecohpCheckin_MpNumber').blur(function(){
		if($(this).val() == ''){
			$(this).attr({ value: 'MileagePlus # or email address'});
			$(this).css({color:'gray'});
			$('input:text[class="ecohpCheckin_MpNumber"]').css('border-color', '#AABDCE');
		}
	});
	
	$('.ecohpCheckin_Password').blur(function(){
		if($(this).val() == ''){
			$(this).attr({ value: 'Password'});
			$(this).css({color:'gray'});
			$('input:password[class="ecohpCheckin_Password"]').css('border-color', '#AABDCE');
		}
	});
	
	$('input:text[id="ci_searchValueId"]').attr('value', 'Confirmation or E-Ticket number');
	$('input:text[class="ecohpCheckin_ccpnrLastName"]').attr('value', 'Last name');
	document.getElementById('Checkin_type').selectedIndex  = 0;
	if(document.getElementById('help')){document.getElementById('help').style.display="block";}
	if(document.getElementById('help_cc')){document.getElementById('help_cc').style.display="none";}

	$('#shop_from1_temp').bind('keypress', function(e) {
	 if (e.keyCode == '13') {
		return false;
	 }
	});

	 $('#authForm3, #cio_MP ,#NDBSearchFrm').keypress(function(event) 
	 {
		   if (event.keyCode == '13') {
				   event.preventDefault();
				   switch(this.id) {
						  case "authForm3" :
								if (ecodlSubmit3(this)) {
									if (typeof removeFlash != "undefined") {removeFlash(); } /*to remove the flash on unload of the page */
									this.submit();
								}
						  break;
						  case "cio_MP" :
								if (ValidateUserId2(this)) {
									if (typeof removeFlash != "undefined") {removeFlash(); } /*to remove the flash on unload of the page */
									this.submit();
								}
						  break;
						   case "NDBSearchFrm" :
								if (ValidateNDB(this)) {
									if (typeof removeFlash != "undefined") {removeFlash(); } /*to remove the flash on unload of the page */
									this.submit();
								}												 
						  break;
					   
				   }
		   }
	});			 
	 if(document.getElementById("findAirportLink"))
	 {
		document.getElementById("findAirportLink").style.display="block";
	 }
 
});

function openAiportLookupWindow(url)
{		
	if((typeof webAnalyticsPageTitle !="undefined") && (!(webAnalyticsPageTitle == "US%20EN%20Homepage" || webAnalyticsPageTitle == "Itineraries%20checkin%20landing" || webAnalyticsPageTitle == "EasyCheck-in%20Online"))){				
		document.domain = "travel.united.com";
	}else{	
		document.domain = "united.com";
	}
	popWin = window.open(url,'popDoc','width=539,height=500,scrollbars=yes,status=yes,resizable=yes,toolbar=no,dependent=yes','AirportLookup');

}

function ValidateNDB(obj) 	{
		var msg="", 
			rad_val="", 
			d;
		var firstName = obj.firstName.value.replace(/^\s*|\s*$/g,'');
		var lastName = obj.lastName.value.replace(/^\s*|\s*$/g,'');
		var departureStation = obj.shop_from1_temp.value.replace(/^\s*|\s*$/g,'');
		var flightnumber = obj.flightNumber.value.replace(/^\s*|\s*$/g,'');
		obj.flightNumber.value = flightnumber;
		
		if(!flightnumber || flightnumber == 'Flight Number'){
			$('input:text[class="ecohpCheckin_flightNumber"]').css('border-color', 'red');
			$('input:text[class="ecohpCheckin_flightNumber"]').css('color', 'red');
			$('input:text[class="ecohpCheckin_flightNumber"]').attr('value', 'Flight Number');
			msg+="Please enter the Flight number as it appears on your itinerary.\n"; 
		} 
		else 
		{
			if(isNaN(flightnumber)){
				$('input:text[class="ecohpCheckin_flightNumber"]').css('border-color', 'red');
				$('input:text[class="ecohpCheckin_flightNumber"]').css('color', 'red');
				$('input:text[class="ecohpCheckin_flightNumber"]').attr('value', 'Flight Number');
				msg+="Flight Number code should only contain numbers.\n"; 
			}
		}		
		
		if(!departureStation || departureStation == 'Departing airport code'){
			$('input:text[class="ecohpCheckin_ccpnrdprtFrom"]').css('border-color', 'red');
			$('input:text[class="ecohpCheckin_ccpnrdprtFrom"]').css('color', 'red');
			$('input:text[class="ecohpCheckin_ccpnrdprtFrom"]').attr('value', 'Departing airport code');
			msg+="Please enter the Departing airport code as it appears on your itinerary.\n"; 
		} 
		else 
		{
			departureStation = departureStation.trim();
			obj.departureStation.value = departureStation;
			obj.departureStation.value = obj.shop_from1.value;			
		}
				
		if(!firstName || firstName == 'First name'){
			$('input:text[class="ecohpCheckin_ccpnrFirstName"]').css('border-color', 'red');
			$('input:text[class="ecohpCheckin_ccpnrFirstName"]').css('color', 'red');
			$('input:text[class="ecohpCheckin_ccpnrFirstName"]').attr('value', 'First name');
			msg+="Please enter the First name as it appears on your itinerary.\n"; 
		} 
		else 
		{
			firstName = firstName.trim();
			obj.firstName.value = firstName;
			if(!/^[a-zA-Z]{1,40}$/.test(firstName)){
				$('input:text[class="ecohpCheckin_ccpnrFirstName"]').css('border-color', 'red');
				$('input:text[class="ecohpCheckin_ccpnrFirstName"]').css('color', 'red');
				$('input:text[class="ecohpCheckin_ccpnrFirstName"]').attr('value', 'First name');
				msg+="First name should only contain letters.\n"; 
			}
		}
			
		if(!lastName || lastName == 'Last name'){
			$('input:text[class="ecohpCheckin_ccpnrLastName"]').css('border-color', 'red');
			$('input:text[class="ecohpCheckin_ccpnrLastName"]').css('color', 'red');
			$('input:text[class="ecohpCheckin_ccpnrLastName"]').attr('value', 'Last name');
			msg+="Please enter the Last name as it appears on your itinerary.\n"; 
		} 
		else 
		{
			lastName = lastName.trim();
			obj.lastName.value = lastName;
			if(!/^[a-zA-Z]{1,40}$/.test(lastName)){
				$('input:text[class="ecohpCheckin_ccpnrLastName"]').css('border-color', 'red');
				$('input:text[class="ecohpCheckin_ccpnrLastName"]').css('color', 'red');
				$('input:text[class="ecohpCheckin_ccpnrLastName"]').attr('value', 'Last name');
				msg+="Last name should only contain letters.\n"; 
			}
		}
		
		for (var i=0; i < obj.todayTomoro.length; i++) {
			if (obj.todayTomoro[i].checked) {
				rad_val = obj.todayTomoro[i].value;
			}
		}		
		if(rad_val==1){
			d = new Date();	
			//document.getElementById("departureDate").value="20101029";
		}else{
			d = new Date(new Date().getTime() +24*60*60*1000);
			//document.getElementById("departureDate").value="20101030";
		}
		var month = d.getMonth() + 1;	
		document.getElementById("departureDate").value = d.getFullYear().toString() + parseValue(month.toString()) + parseValue(d.getDate().toString());
			if (msg) {
			msg='Please Supply the Following:\n\n' + msg;
			alert(msg);
			return false;
	   }
	   else{
		   if (typeof removeFlash != "undefined") {removeFlash(); } /*to remove the flash on unload of the page */
		   return true;
	   }
	}	
	
function parseValue(value){
	if(value.length == "1"){
	 value = "0" + value;
	}
	return value;
}
	
	function checkin_type(check_ID, Check_Val){
	var gotMPno = null;
	rememberME = getCookie("rememberME");	
	if (rememberME!= undefined && rememberME=="E") {
		gotMPno = getCookie("rememberEMAIL");
	}
	if (rememberME!= undefined && rememberME=="M") {
		gotMPno = getCookie("getMP");
	}
	
	if(check_ID == 'Checkin_type'){
		if(Check_Val == 'Checkin_1'){
			document.getElementById('Confirm_CrdCard').style.display  = "none";
			document.getElementById('MileagePlus_email').style.display  = "block";
			document.getElementById('NDBSearch').style.display  = "none";					
			if (gotMPno != null) {
				document.getElementById('ecoText1').value=gotMPno;			
				document.getElementById('remMP').checked=true;
				$('input:text[class="ecohpCheckin_MpNumber"]').css('border-color', '#AABDCE');
				$('input:password[class="ecohpCheckin_Password"]').css('border-color', '#AABDCE');
				$('input:password[class="ecohpCheckin_Password"]').attr('value', '');
				$('input:text[class="ecohpCheckin_MpNumber"]').css('color', 'black');
				$('input:password[class="ecohpCheckin_Password"]').css('color', 'black');
			} else {
				$('input:text[class="ecohpCheckin_MpNumber"]').css('border-color', '#AABDCE');
				$('input:password[class="ecohpCheckin_Password"]').css('border-color', '#AABDCE');
				$('input:text[class="ecohpCheckin_MpNumber"]').attr('value', 'MileagePlus # or email address');
				$('input:password[class="ecohpCheckin_Password"]').attr('value', 'Password');
				$('input:text[class="ecohpCheckin_MpNumber"]').css('color', 'gray');
				$('input:password[class="ecohpCheckin_Password"]').css('color', 'gray');
			}
		}
		else if(Check_Val == 'Checkin_2'){
			document.getElementById('MileagePlus_email').style.display  = "none";
			document.getElementById('Confirm_CrdCard').style.display  = "block";
			document.getElementById('NDBSearch').style.display  = "none";					
			$('input:text[id="ci_searchValueId"]').css('border-color', '#AABDCE');
			$('input:text[class="ecohpCheckin_ccpnrLastName"]').css('border-color', '#AABDCE');
			$('input:text[id="ci_searchValueId"]').attr('value', 'Confirmation or E-Ticket number');
			$('input:text[class="ecohpCheckin_ccpnrLastName"]').attr('value', 'Last name');
			$('input:text[id="ci_searchValueId"]').css('color', 'gray');
			$('input:text[class="ecohpCheckin_ccpnrLastName"]').css('color', 'gray');
			$('input:hidden[id="ci_cc"]').attr('value', 'pnr');
			$('input:hidden[id="ci_cc"]').attr('id', 'ci_pnr');						
			if(document.getElementById('toolTipMessage')){
				var obj = document.getElementById('toolTipMessage');
				obj.tooltip_message='<span style="font-size:10px;"><b style="font-size:11px;">Confirmation number</b> <br>The United confirmation number is a six character alpha-numeric code. It can be found on your itinerary or ticket receipt. <br><br><b style="font-size:11px;">E-Ticket number</b><br>This is a 13 digit number that can be located on your E-Ticket receipt.</span>';
			}			
			if(document.getElementById('help')){document.getElementById('help').style.display="block";}
			if(document.getElementById('help_cc')){document.getElementById('help_cc').style.display="none";}
			}
		else if(Check_Val == 'Checkin_3'){
			document.getElementById('MileagePlus_email').style.display  = "none";
			document.getElementById('Confirm_CrdCard').style.display  = "block";
			document.getElementById('NDBSearch').style.display  = "none";					
			$('input:text[id="ci_searchValueId"]').css('border-color', '#AABDCE');
			$('input:text[class="ecohpCheckin_ccpnrLastName"]').css('border-color', '#AABDCE');
			$('input:text[id="ci_searchValueId"]').attr('value', 'Credit card number');
			$('input:text[class="ecohpCheckin_ccpnrLastName"]').attr('value', 'Last name');
			$('input:text[id="ci_searchValueId"]').css('color', 'gray');
			$('input:text[class="ecohpCheckin_ccpnrLastName"]').css('color', 'gray');
			$('input:hidden[id="ci_pnr"]').attr('value', 'cc');
			$('input:hidden[id="ci_pnr"]').attr('id', 'ci_cc');			
			if(document.getElementById('toolTipMessage')){
				var obj = document.getElementById('toolTipMessage');
				obj.tooltip_message='<span style="font-size:10px;"><b style="font-size:11px;">Credit card number</b> <br>Enter the credit card number used to purchase your ticket. Your credit card will not be charged.</span>';
			}
			if(document.getElementById('help')){document.getElementById('help').style.display="none";}
			if(document.getElementById('help_cc')){document.getElementById('help_cc').style.display="block";}
		}
		else if(Check_Val == 'Checkin_4'){
			document.getElementById('MileagePlus_email').style.display  = "none";
			document.getElementById('Confirm_CrdCard').style.display  = "none";	
			document.getElementById('NDBSearch').style.display  = "block";
			$('input:text[class="ecohpCheckin_ccpnrLastName"]').css('border-color', '#AABDCE');
			$('input:text[class="ecohpCheckin_ccpnrLastName"]').attr('value', 'Last name');	
			$('input:text[class="ecohpCheckin_ccpnrLastName"]').css('color', 'gray');
			$('input:text[class="ecohpCheckin_ccpnrFirstName"]').css('border-color', '#AABDCE');
			$('input:text[class="ecohpCheckin_ccpnrFirstName"]').attr('value', 'First name');	
			$('input:text[class="ecohpCheckin_ccpnrFirstName"]').css('color', 'gray');
			$('input:text[class="ecohpCheckin_ccpnrdprtFrom"]').css('border-color', '#AABDCE');
			$('input:text[class="ecohpCheckin_ccpnrdprtFrom"]').attr('value', 'Departing airport code');	
			$('input:text[class="ecohpCheckin_ccpnrdprtFrom"]').css('color', 'gray');			
			$('input:text[class="ecohpCheckin_flightNumber"]').css('border-color', '#AABDCE');
			$('input:text[class="ecohpCheckin_flightNumber"]').attr('value', 'Flight Number');	
			$('input:text[class="ecohpCheckin_flightNumber"]').css('color', 'gray');			
		
		}
		
	}
}

String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/gi,"") };

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));	
}

function validateEml(str) {
	re = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]{0,4}[a-zA-Z]$/;
	return (re.test(str));
}

function validateCC(cardNo) {
	/*
	Visa	4-4-4-4, prefix 4 (4111 1111 1111 1111)
	American Express	4-6-5, prefix 37-34  (3400 000000 00009)
	Carte Blanche	3000 0000 0000 04
	Discover	4-4-4-4, prefix 6011 (6011 0000 0000 0004)
	Diner's Club	3000 0000 0000 04
	enRoute	2014 0000 0000 009
	JCB	2131 0000 0000 0008
	MasterCard	51-55, 5500 0000 0000 0004
	Solo	6334 0000 0000 0004
	Switch	4903 0100 0000 0009
	UATP 101657900007043
	*/
	var nCheck = 0,	nDigit = 0,	bEven = false;
	cardNo = cardNo.replace(/\D/g, ""); 
	cardRe = /^\d{13,16}$/;
	if(!cardRe.test(cardNo)) { return false;} 
return true;
}

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;
	if ($("#mi_cc").is(":checked")) {
			searchValue = searchValue.replace(/\D/g, "");
			f.searchValueId.value = searchValue;
		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")) {
		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');
			}
		}
		else if (!/^\d{13}$/.test(searchValue)){msg+=tktError;}
		else {
				$('#authForm2 #mi_pnr').val('tkt');
		}		
	}
	
	var lastName = f.lastName.value;
	if(!lastName){msg+="Please enter the Last name as it appears on your itinerary.\n"} 
	else 
	{
		lastName = lastName.trim();
		f.lastName.value = lastName;
		if(!/^[a-zA-Z]{1,40}$/.test(lastName))msg+="Last name should only contain letters.\n"; 
	}

	if (msg) {
        msg='Please Supply the Following:\n\n' + msg;
        alert(msg);
        return false;
   }
	return true;
}

function ecodlSubmit3(f)	{
	var msg="";
	var searchValue = $('#ci_searchValueId').val();
	if((searchValue != 'Confirmation or E-Ticket number') && (searchValue != 'Credit card number')){
		searchValue = $('#ci_searchValueId').val().replace(/[\(\)\.\-\s,]/g, "");
	}
	$('#ci_searchValueId').attr("value", searchValue);
	if (document.getElementById('Checkin_type').selectedIndex == 0) {
		if (searchValue=="") {
			$('input:text[id="ci_searchValueId"]').css('border-color', 'red');
			$('input:text[id="ci_searchValueId"]').css('color', 'red');
			$('input:text[id="ci_searchValueId"]').attr('value', 'Confirmation or E-Ticket number');
			msg+=tktError;
		}
		else if (searchValue.length < 5) {
			$('input:text[id="ci_searchValueId"]').css('border-color', 'red');
			$('input:text[id="ci_searchValueId"]').css('color', 'red');
			$('input:text[id="ci_searchValueId"]').attr('value', '');
			$('input:text[id="ci_searchValueId"]').attr('value', 'Confirmation or E-Ticket number');
			msg+=tktError;
		}
		else if (searchValue.length <= 6) {
			reCipnr = /^[a-zA-Z0-9]{5,6}$/;
			if (!reCipnr.test(searchValue)) {
				$('input:text[id="ci_searchValueId"]').css('border-color', 'red');
				$('input:text[id="ci_searchValueId"]').css('color', 'red');
				$('input:text[id="ci_searchValueId"]').attr('value', '');
				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)){
			$('input:text[id="ci_searchValueId"]').css('border-color', 'red');
			$('input:text[id="ci_searchValueId"]').css('color', 'red');
			$('input:text[id="ci_searchValueId"]').attr('value', 'Confirmation or E-Ticket number');
			msg+=tktError;
		}
		else if (!/^\d{13}$/.test(searchValue)) {
			$('input:text[id="ci_searchValueId"]').css('border-color', 'red');
			$('input:text[id="ci_searchValueId"]').css('color', 'red');
			$('input:text[id="ci_searchValueId"]').attr('value', 'Confirmation or E-Ticket number');
			msg+='The e-ticket should only contain numbers.\n';
		}else {
				$('#ci_pnr').val('tkt');
				$('#ci_searchValueId').attr("name", 'tktNumber');
		}
	
	}
	else if (document.getElementById('Checkin_type').selectedIndex == 2) {
			if(searchValue != 'Credit card number'){
				searchValue = searchValue.replace(/\D/g, "");
			}
			$('#ci_searchValueId').val(searchValue);
			$('#ci_searchValueId').attr("name", 'ccNumber');
			if(searchValue == "" || searchValue == "Credit card number"){
				$('input:text[id="ci_searchValueId"]').css('border-color', 'red');
				$('input:text[id="ci_searchValueId"]').css('color', 'red');
				$('input:text[id="ci_searchValueId"]').attr('value', 'Credit card number');
				msg+="Please enter the credit card number.\n"; 
			} 
			else if(!validateCC(searchValue)) {
				if(searchValue == 'Credit card number' || searchValue == ''){
					$('input:text[id="ci_searchValueId"]').css('border-color', 'red');
					$('input:text[id="ci_searchValueId"]').css('color', 'red');
					$('input:text[id="ci_searchValueId"]').attr('value', 'Credit card number');
				} else {
					$('input:text[id="ci_searchValueId"]').css('border-color', 'red');
					$('input:text[id="ci_searchValueId"]').css('color', 'red');
					$('input:text[id="ci_searchValueId"]').attr('value', '');
					$('input:text[id="ci_searchValueId"]').attr('value', 'Credit card number');
				}				
				msg+="Please enter a valid credit card number.\n";
			}
	}
	var lastName = f.lastName.value;
	if(!lastName || lastName == 'Last name'){
		$('input:text[class="ecohpCheckin_ccpnrLastName"]').css('border-color', 'red');
		$('input:text[class="ecohpCheckin_ccpnrLastName"]').css('color', 'red');
		$('input:text[class="ecohpCheckin_ccpnrLastName"]').attr('value', 'Last name');
		msg+="Please enter the Last name as it appears on your itinerary.\n"; 
	} 
	else 
	{
		lastName = lastName.trim();
		f.lastName.value = lastName;
		if(!/^[a-zA-Z]{1,40}$/.test(lastName)){
			$('input:text[class="ecohpCheckin_ccpnrLastName"]').css('border-color', 'red');
			$('input:text[class="ecohpCheckin_ccpnrLastName"]').css('color', 'red');
			$('input:text[class="ecohpCheckin_ccpnrLastName"]').attr('value', 'Last name');
			msg+="Last name should only contain letters.\n"; 
		}
	}
	if (msg) {
        msg='Please Supply the Following:\n\n' + msg;
        alert(msg);
        return false;
   }
   if (typeof removeFlash != "undefined") {removeFlash(); }; /* Validateuserid from ajax.js SHD 2-15-2010 */
	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 || searchValue == 'MileagePlus # or email address') {
		$('input:text[class="ecohpCheckin_MpNumber"]').css('border-color', 'red');
		$('input:text[class="ecohpCheckin_MpNumber"]').css('color', 'red');
		$('input:text[class="ecohpCheckin_MpNumber"]').attr('value', 'MileagePlus # or email address');
		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 {
			$('input:text[class="ecohpCheckin_MpNumber"]').css('border-color', 'red');
			$('input:text[class="ecohpCheckin_MpNumber"]').css('color', 'red');
			$('input:text[class="ecohpCheckin_MpNumber"]').attr('value', 'MileagePlus # or email address');
			msg='The MileagePlus number you have entered is invalid. Please check the number and resubmit.\n';
		}
	} else if (validateEml(searchValue)) {
		f.authType.value="ea";
	} else {
		$('input:text[class="ecohpCheckin_MpNumber"]').css('border-color', 'red');
		$('input:text[class="ecohpCheckin_MpNumber"]').css('color', 'red');
		$('input:text[class="ecohpCheckin_MpNumber"]').attr('value', 'MileagePlus # or email address');
	 	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 || pwd == 'Password') {
		$('input:password[class="ecohpCheckin_Password"]').css('border-color', 'red');
		$('input:password[class="ecohpCheckin_Password"]').css('color', 'red');
		$('input:password[class="ecohpCheckin_Password"]').attr('value', 'Password');
		msg+='Password is a required field.\n';   	
	}
	if (msg) {
        msg='Please Supply the Following:\n\n' + msg;
        alert(msg);
        return false;
   }		
	if (typeof removeFlash != "undefined") {removeFlash(); }; //validateuserid2 from ajax, if necessary SHD 2-15-2010
	return true;
}

var popupWin; 
function popItUp(url){
    popupWin=window.open(url,'remote','width=500,height=400,scrollbars=yes');	
    if (window.focus) {popupWin.focus()}
}

