
function canResolveLinkPath(hrefObj) {
	if ( hrefObj.className.indexOf('popupLink') >= 0 ) return false;
	else if ( hrefObj.id.indexOf('logout') >= 0 ) return false;
	else if ( hrefObj.id.indexOf('wrongUserLogoutLink') >= 0 ) return false;
	else if ( hrefObj.id.indexOf('wrongUserLogoutLink') >= 0 ) return false;
	else if ( hrefObj.className.indexOf('newWindowLink') >= 0 ) return false;
	else if ( hrefObj.className.indexOf('faqQ') >= 0 ) return false;
	else if ( hrefObj.id.indexOf('myStuff') >= 0 ) return false;
	else if ( hrefObj.className.indexOf('myInvoice') >= 0 ) return false;
	else if ( hrefObj.id.indexOf('AFlyGreen') >= 0 ) return false;
	else if ( hrefObj.id.indexOf('ATripProt') >= 0 ) return false;
	else if ( hrefObj.id.indexOf('AllPrice') >= 0 ) return false;
	else return true;
}

function selectField(eventType) {
	unflagError(eventType.target); // get rid of any error styles that could be applied to this field
	eventType.target.select(); // highlight the field, so the user can start typing over the existing value
}

function filterByPartner(eventType) {
	var radioObj = eventType.target;
	if ( !radioObj.checked && radioObj.value != "all" ) filterResults('type',radioObj.value,2);
	else if ( !radioObj.checked) removeFilter('type',2);
}

function initEmailField(eventType) {
	var promptValue = " Enter your email";
	if ( eventType.eventType == "blur" && eventType.target.value == "" ) {
		eventType.target.value = promptValue;
	}
	else if ( eventType.eventType == "focus" && eventType.target.value == promptValue ) {
		eventType.target.value = "";
	}
}

function initGroupEmailField(eventType) {
	var promptValue = " For Confirmation";
	if ( eventType.eventType == "blur" && eventType.target.value == "" ) {
		eventType.target.value = promptValue;
	}
	else if ( eventType.eventType == "focus" && eventType.target.value == promptValue ) {
		eventType.target.value = "";
	}
}

function initFirstNameField(eventType) {
	var promptValue = " First";
	
	if ( eventType.eventType == "change") {
		eventType.target.attributes["defaultVal"].nodeValue = "changed";
	}
	
	if ( eventType.eventType == "blur" && eventType.target.value == "" ) {
		eventType.target.value = promptValue;
		eventType.target.attributes["defaultVal"].nodeValue = "default";
		eventType.target.style.color = "#F6480E";
	}
	else if ( eventType.eventType == "focus" && eventType.target.value == promptValue ) {
		eventType.target.value = "";
		eventType.target.style.color = "#000000";
	}
	else if ( eventType.eventType == "focus" && eventType.target.value != promptValue) {
		
		eventType.target.style.color = "#000000";
	}
	else if ( eventType.eventType == "load" && eventType.target.value != promptValue) {
		eventType.target.style.color = "#000000";
	}
	else if ( eventType.eventType == "load" && eventType.target.value == promptValue) {
		eventType.target.style.color = "#F6480E";
	}
}

function initMiddleNameField(eventType) {
	var promptValue = " Middle (optional)";
	
	if ( eventType.eventType == "change") {
		eventType.target.attributes["defaultVal"].nodeValue = "changed";
	}
	
	if ( eventType.eventType == "blur" && eventType.target.value == "" ) {
		eventType.target.value = promptValue;
		eventType.target.attributes["defaultVal"].nodeValue = "default";
	}
	else if ( eventType.eventType == "focus" && eventType.target.value == promptValue ) {
		eventType.target.value = "";
	}
}

function initLastNameField(eventType) {
	var promptValue = " Last";
	
	if ( eventType.eventType == "change") {
		eventType.target.attributes["defaultVal"].nodeValue = "changed";
	}
	
	if ( eventType.eventType == "blur" && eventType.target.value == "" ) {
		eventType.target.value = promptValue;
		eventType.target.attributes["defaultVal"].nodeValue = "default";
		eventType.target.style.color = "#F6480E";
	}
	else if ( eventType.eventType == "focus" && eventType.target.value == promptValue ) {
		eventType.target.value = "";
		eventType.target.style.color = "#000000";
	}
	else if ( eventType.eventType == "focus" && eventType.target.value != promptValue) {
		eventType.target.style.color = "#000000";
	}
	else if ( eventType.eventType == "load" && eventType.target.value != promptValue) {
		eventType.target.style.color = "#000000";
	}
	else if ( eventType.eventType == "load" && eventType.target.value == promptValue) {
		eventType.target.style.color = "#F6480E";
	}
}


function prevAPChoice() {
	var currentIndex = SearchForm.getAPChoiceIndex();
	SearchForm.prevAPChoice();
	if ( currentIndex != SearchForm.getAPChoiceIndex() ) {
		get("airportChoice" + currentIndex ).className = "airportChoice";
		get("airportChoice" + SearchForm.getAPChoiceIndex() ).className = " selectedAirport";
	}
}

function nextAPChoice() {
	var currentIndex = SearchForm.getAPChoiceIndex();
	SearchForm.nextAPChoice();
	if ( currentIndex != SearchForm.getAPChoiceIndex() ) {
		get("airportChoice" + currentIndex ).className = "airportChoice";
		get("airportChoice" + SearchForm.getAPChoiceIndex() ).className = " selectedAirport";
	}
}

function changeAPChoice(index) {
	if ( index != SearchForm.getAPChoiceIndex() ) {
		get("airportChoice" + SearchForm.getAPChoiceIndex() ).className = "airportChoice";
		SearchForm.setAPChoice(index);
		get("airportChoice" + SearchForm.getAPChoiceIndex() ).className = " selectedAirport";
	}
}

var apCodeEvent = null;
var minLengthToLookup = 3;
var maxAirportsToShow = 20;

function resetLookup(keepCurrentResults) {
	try { clearTimeout(apCodeEvent); } // clear any outstanding requests to show airport code choices
	catch(e) {}
	if ( !keepCurrentResults ) {
		SearchForm.resetAPChoices();
		hideAirportResults();
	}
}

function apCodeSearchLookup(targetID,value,showChoices) {
	if(controller==true){
	apCodeLookupTargetID = targetID;
	var returnFunction = ( showChoices ) ? apCodeSearchLookupReturnFunction1:apCodeSearchLookupReturnFunction2;
	submitAjaxFromQuery("lookupAirport",returnFunction,"GET","lookupString="+value);
	controller = false;
	}
}

var apCodeLookupTargetID;
var controller = true;

function apCodeSearchLookupReturnFunction(jsonReturnMsg,showChoices) {

	var json = eval("new Object(" + jsonReturnMsg + ")");	
	var airports = eval(json.returnMsg);
	var apCodesOutput = "";
	try{
	if ( airports.length == 0 ) {
		hideAirportResults();
	}
	else if ( showChoices)  {
		SearchForm.resetAPChoices();
		for ( var i = 0 ; i < airports.length && i < maxAirportsToShow ; i++ ) {
			var apObject = airports[i];
			SearchForm.addAPChoice(apObject);
			var divClass;
			if (i == SearchForm.getAPChoiceIndex() ) var divClass = "airportChoice selectedAirport";
			else divClass = "airportChoice";
			apCodesOutput += "<div id='airportChoice" + i + "' class='" + divClass + "'><a class='airportChoiceLink' href='' id='" + apCodeLookupTargetID + "/" + apObject.apCode + "' onclick='chooseAirport(this); return false' onmouseover='changeAPChoice(" + i + ")'>";
			apCodesOutput += apObject.apDesc;
			apCodesOutput += "</a></div>\n";
			if ( i == 0 ) {
				if ( apCodeLookupTargetID == "outboundAirport" ) SearchForm.setOutboundAirport(apObject.apCode);
				else if ( apCodeLookupTargetID == "inboundAirport" ) SearchForm.setInboundAirport(apObject.apCode);
				else if ( apCodeLookupTargetID == "outboundJawAirport" ) SearchForm.setOutboundJawAirport(apObject.apCode);
			}
		}
		var lookupResultsDiv = createElement("div","airportLookupResults");
		lookupResultsDiv.style.top = getBottomPos(get(apCodeLookupTargetID)) + "px";
		lookupResultsDiv.style.left = getLeftPos(get(apCodeLookupTargetID)) + "px";
		lookupResultsDiv.innerHTML = apCodesOutput;
		lookupResultsDiv.style.display = "block";
	}
	else {
		var apObject = airports[0];
		SearchForm.setByFieldId(apCodeLookupTargetID,apObject.apCode,true,apObject.apDesc);
	}
	controller = true;
	}catch(e){		
		controller = true;
	}
}

function apCodeSearchLookupReturnFunction1(jsonReturnMsg) {
	apCodeSearchLookupReturnFunction(jsonReturnMsg,true);
}

function getAirportResults(apSearchString,recursive) {
	if ( validAPDescription(apSearchString) ) {
		apSearchString = getAirportCode(apSearchString); // if input field has a valid airport description, replace with code here
	}
	apCodes = new Array();
	for ( var i = 0 ; i < airports.length ; i++ ) {
		var airport = airports[i];
		if ( airport.code.toLowerCase().match( apSearchString.toLowerCase() ) || 
			airport.city.toLowerCase().indexOf( apSearchString.toLowerCase() ) == 0 || 
			airport.name.toLowerCase().indexOf( apSearchString.toLowerCase() ) == 0 || 
			airport.stateName.toLowerCase().indexOf( apSearchString.toLowerCase() ) == 0 || 
			airport.country.toLowerCase().indexOf( apSearchString.toLowerCase() ) == 0|| 
			airport.description().toLowerCase().indexOf( apSearchString.toLowerCase() ) == 0 ) {
			apCodes.push(airport);   
		}
	}
	if ( apCodes.length > 0 ) {
		apSortValue = apSearchString.toLowerCase();
		apCodes.sort(sortApCodes);
	}
	else if ( !recursive && apSearchString.split(",").length > 1 ) {
		apCodes = getAirportResults( apSearchString.split(",")[0],true );
	}
	else if ( !recursive && apSearchString.split(", ").length > 1 ) {
		apCodes = getAirportResults( apSearchString.split(", ")[0],true );
	}
	else if ( !recursive && apSearchString.split(" ").length > 1 ) {
		apCodes = getAirportResults( apSearchString.split(" ")[0],true );
	}
	return apCodes;
}

function apCodeSearchLookupReturnFunction2(jsonReturnMsg) {
	apCodeSearchLookupReturnFunction(jsonReturnMsg,false);
}

function chooseAirport(thisAnchor) {
	var inputID = thisAnchor.id.split("/")[0];
	var apCode = thisAnchor.id.split("/")[1];
	var apDesc = thisAnchor.innerHTML;
	SearchForm.setByFieldId(inputID,apCode,true,apDesc);
	resetLookup();
}

var apSortValue;
function sortApCodes(ap1,ap2) {
	if ( ap1.code.toLowerCase() == apSortValue ) return -1;
	else if ( ap2.code.toLowerCase() == apSortValue.toLowerCase() ) return 1;
	else if ( ap1.city.toLowerCase().indexOf(apSortValue) == 0 && ap2.city.toLowerCase().indexOf(apSortValue) != 0 ) return -1;
	else if ( ap2.city.toLowerCase().indexOf(apSortValue) == 0 && ap1.city.toLowerCase().indexOf(apSortValue) != 0 ) return 1;
	else if ( ap1.rank < ap2.rank ) return -1;
	else if ( ap1.rank > ap2.rank ) return 1;
	else return 0;
}

function getDateFromString(dateString) {
	// replace dashes and periods with slashes
	dateString = dateString.replace(/-/g,"/");
	dateString = dateString.replace(/\./g,"/");
	
	// convert no year format to show year
	dateString = convertNoYearFormat(dateString);

	// convert 2 digit years to 4
	dateString = dateString.replace(/\/(\d\d)$/,"/20$1");
	
	var validFormat = /(^\d\d\/\d\d\/\d\d\d\d$)/;
	if ( !validFormat.test(dateString) ) return null;
	else return new Date(dateString);
}

function updateDate(eventType) {
	unflagError(eventType.target); // get rid of any error styles that could be applied to this field
	var dateField = eventType.target; // target element that changed
	var value = trim(dateField.value); // trim whitespace
	var date = validatedDate(value);
	SearchForm.setByFieldId(eventType.target.id,date,false);
}

function changedDate(eventType) {
	var dateField = eventType.target; // target element that changed
	var value = trim(dateField.value); // trim whitespace
	var date = validatedDate(value);
	SearchForm.setByFieldId(eventType.target.id,date,false);
	SearchForm.initField(eventType.target.id);
}

function validateDate(dateField,suppressErrorMessages) {
	// replace dashes and periods with slashes
	dateField.value = dateField.value.replace(/-/g,"/");
	dateField.value = dateField.value.replace(/\./g,"/");
	
	// convert no year format to show year
	dateField.value = convertNoYearFormat(dateField.value);

	// convert 2 digit years to 4
	dateField.value = dateField.value.replace(/\/(\d\d)$/,"/20$1");

	var validFormat = /(^\d\d\/\d\d\/\d\d\d\d$)/;
	
	if ( !validFormat.test(dateField.value) ) { 
		if ( !suppressErrorMessages ) {
			if ( dateField.id == "outboundDate" ) {
				alert("Please enter a valid departure date.  Enter using the format mm/dd/yyyy");
			}
			if ( dateField.id == "inboundDate" ) {
				alert("Please enter a valid return date.  Enter using the format mm/dd/yyyy");
			}
			dateField.focus();
		}
		return false;
	}
	else {
		var thisDate = new Date(dateField.value);
		var dayOfWeekDivID = dateField.id + "DayOfWeek";
		get(dayOfWeekDivID).innerHTML = thisDate.format("DD");
		return true;
	}
}

function convertNoYearFormat(dateString) {
	var now = getCurrentDateRef();
	todaysMonth = now.getMonth() + 1;
	todaysDate = now.getDate();
	todaysYear = now.getFullYear();
	
	var noYearFormat = /^\d+\/\d+$/;
	if ( noYearFormat.test(dateString) ) {
		var month = parseInt(dateString.split("/")[0],10);
		var date = parseInt(dateString.split("/")[1],10);
		if ( month < todaysMonth || month == todaysMonth && date < todaysDate ) {
			dateString += "/" + (todaysYear + 1);
		}
		else {
			dateString += "/" + todaysYear;
		}
	}
	return dateString;
}

var defaultDaysBetweenDates = 14;

function resolveLinkPath(hrefObj) {
	hrefObj.href = resolveScheme(hrefObj.href);
}

function showAnswer() {
	var targetDiv = $( $(this).attr("target") );
	if ( targetDiv.is(':hidden') ) $("div.footAnswer:visible").hide();
	$(targetDiv).slideToggle();
	return false;
}

function signUp(eventType) {
		//add the pre checking
		
	
	
	
		var returnFunction = function(returnMsg) {
			if ( returnMsg.indexOf("success") >= 0 ) goToURL("/confirmJoin.html");
			else if ( returnMsg.indexOf("permissionToVerify:") == 0 ) {
				// if permissionToVerify is the only error
				alert('You must check the box above the Continue button, agreeing to the Terms and Conditions.');
			}
			else {
			$(".signUpRCBox").height($(".signUpRCBox").height() + 130);
				showErrors("errorTop",returnMsg,true);
				
				}
		}
		submitAjax("signUp",returnFunction,"POST",eventType.target.form,"Attempting to sign up");
	
	
}

function updateProfile(eventType) {
	var returnFunction = function(returnMsg) {
		if ( returnMsg.indexOf("success") >= 0 ) replaceURL("/myaccount/mystuff.jsp");
		else showErrors("errorTop",returnMsg,true);
	}
	submitAjax("updateProfile",returnFunction,"POST",eventType.target.form,"Updating Profile");
}

function login(eventType) {
	var errorMsg = "";
	hideErrors("error");
	if(document.getElementById("loginEmail").value == null 
	|| document.getElementById("loginEmail").value.replace(/ /,"") == "") {
		errorMsg = errorMsg + "\nemail2:Please enter a valid email address.";
	}else if(document.getElementById("loginEmail").value.indexOf("@") < 0){
		errorMsg = errorMsg + "\nemail2:Please enter a valid email address.";
	}
	
	if(document.getElementById("password").value == null 
	|| document.getElementById("password").value.replace(/ /,"") == "") {
		errorMsg = errorMsg + "\npassword:Please enter a password.";
	}else if(document.getElementById("password").value.length < 6){
		errorMsg = errorMsg + "\npassword:Passwords must contain letters or numbers only, and be 6-16 characters.";
	}
	
	if(errorMsg != '') {
		showErrors("error",errorMsg);
	}else {	
		var returnFunction = function(returnMsg) {
			if ( returnMsg.indexOf("success") >= 0 ) {
				if ( returnMsg.indexOf("page:") >= 0 ) {
					returnURL = returnMsg.split("page:")[1];
					replaceURL(returnURL);
				}
				else replaceURL("/");
			}
			else showErrors("error",returnMsg);
		}
		//hideErrors("error");
		submitAjax("login",returnFunction,"POST",eventType.target.form,"Logging in");
	}
}

function billShipSubmit(eventType) {
	hideErrors("error");
	submitAjax("billShipInfo",billShipReturn,"POST",eventType.target.form,"Submitting info");
}

function changePerPage(eventType) {
	submitAjaxFromQuery("changePerPage",updateResults,"GET","value="+eventType.value);//scroll(0,0);
}

function showCalendars(eventType) {
	if ( eventType.target.id == "outbound-calendarIcon" ) {
		try { 
				showCalendar("outboundDate",SearchForm.getOutboundDate().getMonth(),SearchForm.getOutboundDate().getFullYear());
				get("outboundFlexibility").style.display = "none";
				if(get("searchBox").className == "roundTrip"){
					get("inboundFlexibility").style.display = "block"; 
				}
			}
		catch(e) { showCalendar("outboundDate",SearchForm.getDefaultOutboundDate().getMonth(),SearchForm.getDefaultOutboundDate().getFullYear()); }
	}	
	else if ( eventType.target.id == "inbound-calendarIcon" ) {
		try { 
				showCalendar("inboundDate",SearchForm.getInboundDate().getMonth(),SearchForm.getInboundDate().getFullYear());
				get("inboundFlexibility").style.display = "none";
				if(get("searchBox").className == "roundTrip" || get("searchBox").className == "oneWay"){
					get("outboundFlexibility").style.display = "block"; 
				}
				 
				}
		catch(e) { showCalendar("inboundDate",SearchForm.getDefaultInboundDate().getMonth(),SearchForm.getDefaultInboundDate().getFullYear()); }
	}
}

function showGroupTravelCalendars(eventType){
	if ( eventType.target.id == "outbound-calendarIcon" ) {
		try { showCalendar("outboundDate",SearchForm.getOutboundDate().getMonth(),SearchForm.getOutboundDate().getFullYear()); }
		catch(e) { showCalendar("outboundDate",SearchForm.getDefaultOutboundDate().getMonth(),SearchForm.getDefaultOutboundDate().getFullYear()); }
	}	
	else if ( eventType.target.id == "inbound-calendarIcon" ) {
		try { showCalendar("inboundDate",SearchForm.getInboundDate().getMonth(),SearchForm.getInboundDate().getFullYear()); }
		catch(e) { showCalendar("inboundDate",SearchForm.getDefaultInboundDate().getMonth(),SearchForm.getDefaultInboundDate().getFullYear()); }
	}
}

function showCalendar(dateFieldID,month,year) {
	var output = getCalendarMonthOutput(dateFieldID,month,year);
	var calendarDiv = createElement("div","calendarDiv");
	calendarDiv.style.top = getTopPos(get(dateFieldID)) + "px";
	calendarDiv.style.left = getRightPos(get(dateFieldID)) + "px";
	calendarDiv.innerHTML = output;
	calendarDiv.style.display = "block";
}

function getCalendarMonthOutput(dateFieldID,month,year) {
	var currentDate = new Date(year,month,1,12,0,0,0);
	var lastDayLastMonth = currentDate.clone();
	lastDayLastMonth.addDay(-1);
	var prevMonth = lastDayLastMonth.getMonth();
	var prevMonthYear = lastDayLastMonth.getFullYear();
	
	var firstDayNextMonth = currentDate.clone();
	if ( firstDayNextMonth.getMonth() < 11 ) {
		firstDayNextMonth.setMonth(firstDayNextMonth.getMonth()+1);
	} else {
		 firstDayNextMonth.setMonth(0);
		 firstDayNextMonth.setFullYear(firstDayNextMonth.getFullYear()+1)
	}
	var nextMonth = firstDayNextMonth.getMonth();
	var nextMonthYear = firstDayNextMonth.getFullYear();
	
	//var prevMonth = 0;var prevYear= 0;var nextMonth = 0;var nextYear = 0;
	
	// calculate earliest travel date ( 2 days after today )
	var earliestTravelDate = getCurrentDateRef();
	earliestTravelDate.setHours(0);earliestTravelDate.setMinutes(0);earliestTravelDate.setSeconds(0);earliestTravelDate.setMilliseconds(0);
	//earliestTravelDate.addDay(2);
	
	// calculate latest travel date ( a year from yesterday )
	var latestTravelDate = earliestTravelDate.clone();
	latestTravelDate.setFullYear( latestTravelDate.getFullYear() + 1 );
	latestTravelDate.addDay(-1);
	
	var showPrevMonth = false;
	if ( lastDayLastMonth.getTime() >= earliestTravelDate.getTime() ) {
		showPrevMonth = true;
	}
	
	var showNextMonth = false;
	if ( firstDayNextMonth.getTime() <= latestTravelDate.getTime() ) {
		showNextMonth = true;
	}

	var output = "<table class=\"calendar " + dateFieldID + "\" cellspacing=0 cellpadding=2><tr><th></th>";
	
	
	if ( showPrevMonth ) {
		output += "<th><a href='' onclick=\"showCalendar('" + dateFieldID + "'," + prevMonth + "," + prevMonthYear + ");return false\"><img class='calendarArrow' src='" + imageHost + "/images/su08/calendarArrowLeft.gif' width='9' height='13' alt='Previous Month'/></a></th>";
	}
	else {
		output += "<th>&nbsp;</th>";
	}
	
	output += "<th colspan=3>" + currentDate.getFullMonthName() + "&nbsp;" + currentDate.getFullYear() + "</th>";

	if ( showNextMonth ) {
		output += "<th><a href='' onclick=\"showCalendar('" + dateFieldID + "'," + nextMonth + "," + nextMonthYear + ");return false\"><img class='calendarArrow' src='" + imageHost + "/images/su08/calendarArrowRight.gif' width='9' height='13' alt='Next Month'/></a></th>";
	}
	else {
		output += "<th>&nbsp;</th>";
	}

	output += "<th><a href='' onclick=\"hideCalendar();return false\"><img style=\"margin-left:5px\" src='" + imageHost + "/images/su08/closeWindowButton.gif' width='15' height='15' alt='Close Calendar'/></a></th></tr>";
	
	output += "<tr><td class=\"dayOfWeek\">Su</td><td class=\"dayOfWeek\">Mo</td><td class=\"dayOfWeek\">Tu</td><td class=\"dayOfWeek\">We</td><td class=\"dayOfWeek\">Th</td><td class=\"dayOfWeek\">Fr</td><td class=\"dayOfWeek\">Sa</td></tr>";
	
	
	// pad days of week to calendar if first day of month is not a Sunday
	var startDayOfWeek = 0;
	while ( currentDate.getDay() > startDayOfWeek ) {
		output += "<td>&nbsp;</td>";
		startDayOfWeek++;
	} 
	
	while ( currentDate.getMonth() == month || currentDate.getDay() != 0 ) {
		var calDateClass = "invalid";
		var validDate = false;
		
		if ( currentDate.getTime() >= earliestTravelDate && currentDate.getTime() <= latestTravelDate ) {
			calDateClass = "validDate";
			validDate = true;
			
			try {
				
				if ( currentDate.getTime() == SearchForm.getOutboundDate().getTime() ) {
					//alert(currentDate.getDate() +"\n"+	currentDate.getMonth() +"\n"+	currentDate.getFullYear() +"\n");
					calDateClass += " date1";
				}
				if ( SearchForm.tripType > 1 && currentDate.getTime() == SearchForm.getInboundDate().getTime() ) calDateClass += " date2";
			}
			catch(e) {} // above block won't work when there is an invalid date in one of the fields

	    }
	
		if ( currentDate.getDay() == 0 ) output += "<tr>";
		
		if ( currentDate.getMonth() != month ) {
			output += "<td>&nbsp;</td>"; // padded days after last day of month
		}
		else if ( validDate ) {
			output += "<td onclick='chooseDate(\"" + dateFieldID + "\"," + currentDate.getTime() + ");return false' class='" + calDateClass + "'><a id='calChoice' href='#' onclick='return false'>" + currentDate.getDate() + "</a></td>";
		}
		else {
			output += "<td class='" + calDateClass + "'>" + currentDate.getDate() + "</td>";
		}
		
		if ( currentDate.getDay() == 6 ) output += "</tr>";
		currentDate.addDay();
	}
	output += "</table>";

	return output;
}


function switchToStudent(){
	get("userTypeId").value="Student";
	get("selectStudent").className="toggleOn";
	get("selectFaculty").className="toggleOff";
}
function switchToFaculty(){
	get("userTypeId").value="Faculty";
	get("selectStudent").className="toggleOff";
	get("selectFaculty").className="toggleOn";

}


// JQUERY 
      	
$(document).ready(function(){

		$("a").mouseover(function (e) { 
			if ( canResolveLinkPath(this) ) {
				resolveLinkPath(this); return true
			}
		});
		$("a").focus(function (e) { 
			if ( canResolveLinkPath(this) ) {
				resolveLinkPath(this); return true
			}
		});
		$("a").click(function (e) { 
			if ( canResolveLinkPath(this) ) {
				resolveLinkPath(this); return true
			}
		});
		
		$("a.footerQuestion").click(showAnswer);

		$("a#logout").click(function (e) {
			var returnFunction = function(returnMsg) { goToURL("/register"); return false }
			submitAjax("logout",returnFunction,null,null,"Logging out");
			return false;
		});

		$("a#orderLogout").click(function (e) {
			var returnFunction = function(returnMsg) { goToURL("/register"); return false }
			submitAjax("logout",returnFunction,null,null,"Logging out");
			return false;
		});
		
		$("a#wrongUserLogoutLink").click(function (e) {
			var returnFunction = function(returnMsg) { goToURL("/"); return false }
			submitAjax("notMe",returnFunction,null,null,"Logging out");
			return false;
		});
		
		$("a#orderWrongUserLogoutLink").click(function (e) {
			var returnFunction = function(returnMsg) { goToURL("/"); return false }
			submitAjax("notMe",returnFunction,null,null,"Logging out");
			return false;
		});
		
		$("a.newWindowLink").click(function (e) {
			window.open(this.href);
			return false;
		});	
		$("a.faqQ").click(function (e) {
			var faqLink = this;
			if ( faqLink.parentNode.className.indexOf(" ") < 0 ) {
				changeClass(faqLink.parentNode,faqLink.parentNode.className + " visited");
			}
			else {
				spaceIndex = faqLink.parentNode.className.indexOf(" ");
				changeClass(faqLink.parentNode,faqLink.parentNode.className.substring(0,spaceIndex));
			}
			return false;
		});
		
		  
		$(".roundTripToggle").mousedown(function (e) {
			$(this).unbind("click");
			switchToRoundTrip(); return false;
		});
		
		$(".oneWayToggle").mousedown(function (e) {
			$(this).unbind("click");
			switchToOneWay(); return false;
		});
		
		$(".openJawToggle").mousedown(function (e) {
			$(this).unbind("click");
			switchToOpenJaw(); return false;
		});
		$("#shortChinesePopupImg").removeAttr("class");
     	$("a.popupLink, img.popupLink, a.airportCodeLink, a#popupLink, a#abandonPopUp").attr("rel","facebox[.bigsizeBox]").facebox();
      	      	      	
      	$("img#outbound-calendarIcon.calendarLink").click(function (e) {
      		showCalendar("outboundDate",SearchForm.getOutboundDate().getMonth(),SearchForm.getOutboundDate().getFullYear());
      		
      		get("outboundFlexibility").style.display = "none";
			if(get("searchBox").className == "roundTrip"){
				get("inboundFlexibility").style.display = "block"; 
			}
			return false;
      	});
      	
      	$("img#inbound-calendarIcon.calendarLink").click(function (e) {
      		showCalendar("inboundDate",SearchForm.getOutboundDate().getMonth(),SearchForm.getOutboundDate().getFullYear());
      		get("inboundFlexibility").style.display = "none";
				if(get("searchBox").className == "roundTrip" || get("searchBox").className == "oneWay"){
					get("outboundFlexibility").style.display = "block"; 
			}
      		return false;
      	});
      	
      	$("img#checkIn-calendarIcon.calendarLink").click(function (e) {
      		if($.browser.safari){
      			showCalendar("checkInDate",(new Date($("#checkInDate").val())).getMonth(),(new Date($("#checkInDate").val())).getFullYear());
      		}else{
      			showCalendar("checkInDate",(new Date($("#checkInDate").val())).getMonth(),(new Date($("#checkInDate").val())).getFullYear()+100);
      		}
      		return false;
      	});
      	
      	$("img#checkOut-calendarIcon.calendarLink").click(function (e) {
      		if($.browser.safari){
      			showCalendar("checkOutDate",(new Date($("#checkOutDate").val())).getMonth(),(new Date($("#checkOutDate").val())).getFullYear());
      		}else{
      			showCalendar("checkOutDate",(new Date($("#checkOutDate").val())).getMonth(),(new Date($("#checkOutDate").val())).getFullYear()+100);
      		}
      		return false;
      	});
      	
      	$("input.dateField").change(function (e) {
			var value = trim(this.value); // trim whitespace
			var date = validatedDate(value);
			SearchForm.setByFieldId(this.id,date,false);
			SearchForm.initField(this.id);
      	});
		
		$("#hotelsTooCheckbox").click(function (e) {
			submitAjax("setHotelsToo?checked=" + $(this).attr("checked"),function () {},"GET",null,null);
      	});
      	
      	$("BUTTON#searchButton").click(function () {
      		showWaitMsg("Searching");
			SearchForm.startSearch();
			if ( $("#hotelsTooCheckbox").attr("checked") ) {
				searchHotelsToo(SearchForm.inboundAirport,SearchForm.outboundDate,SearchForm.inboundDate,SearchForm.tripType);
			}
			return false;
		});
      	
      	var promptValue = " City name or code";
      	$("INPUT.airportField").blur(function (e) { 
      	    if (this.value == "") this.value = promptValue; 
      	}).focus(function (e) { 
      		if (this.value == promptValue) this.value = "";
      		else if(this.id == "inboundJawAirport") this.blur();
      		else this.select();
      	}).blur(function (e) { 
      	    var targetField = $(this).attr("id");
			var apCode = this.value;
			if ( targetField == "outboundAirport" ) {
				SearchForm.setOutboundAirport(apCode);
				SearchForm.setInboundJawAirport(apCode);
				get(SearchForm.inboundJawAirportInput).value = get(SearchForm.outboundAirportInput).value;
			}
			else if ( targetField == "inboundAirport" ) SearchForm.setInboundAirport(apCode);
			else if ( targetField == "outboundJawAirport" ) SearchForm.setOutboundJawAirport(apCode);
      	}).autocomplete("/nospring/ajax/lookupAirport", {
			width: 300,
			cacheLength: 20,
			delay:lookupDelay,
			minChars: 3,
			max:10,
			scrollHeight: 100,
			loadingClass: "ac_loading",
			selectFirst: true
		}).result(function(event, data, formatted) {
		if (data){
			var targetField = $(this).attr("id");
			var apCode = data[1];
			
			if ( targetField == "outboundAirport" ) {
				SearchForm.setOutboundAirport(apCode);
				SearchForm.setInboundJawAirport(apCode);
				get(SearchForm.inboundJawAirportInput).value = get(SearchForm.outboundAirportInput).value;
				$("#inboundAirport").focus();
			}
			else if ( targetField == "inboundAirport" ) {
				SearchForm.setInboundAirport(apCode);
				if ( SearchForm.tripType == 3 ) {
					$("#outboundJawAirport").focus();
				}
				else {
					$("#outboundDate").focus();
					$("#outboundDate").select();
				}
			}
			else if ( targetField == "outboundJawAirport" ) {
				SearchForm.setOutboundJawAirport(apCode);
				$("#outboundDate").focus();
				$("#outboundDate").select();
			}
		}
		
	});
      	  	
      	


      	
      	  	
      	$("SELECT#billcountry, INPUT.shipCountryField").change(function (e) {
      		loadStates(e);
      			
      	});
      	
      	$("IMG#groupTravelCalendarLink, IMG.groupTravelCalendarLink").click(function (e) {
      			showGroupTravelCalendars(e);
      			
      	});

		$("SPAN#apAltTag, SPAN.apAltTag").mouseout(function () {
      			if ( get("movingAltTag") ) get("movingAltTag").style.display = "none";
				if ( defined(showingAirportCodeDesc) ) clearTimeout(showingAirportCodeDesc);	
      	});
      	
      	
      	$("SELECT#outboundFlexibility,SELECT#inboundFlexibility").change(function () {
      			SearchForm.setByFieldId(this.id,this.value,false);
      			
      	});
      	
      	$("SELECT#perPage").change(function (e) { if(e.value) {changePerPage(e); }});
      	;
      	
	    $("a#myStuff").click(function (e) { 
	    	var returnFunction = function(returnMsg) {
	    
				if ( returnMsg.indexOf("login") >= 0 ) { 
					goToURL("/register"); 
					return false 
				}
				else if ( returnMsg.indexOf("success") >= 0 ) {
					goToURL("/myaccount/mystuff.jsp");
				}
				else showErrors("errorTop",returnMsg,true);
			}
			submitAjax("myStuff",returnFunction,null,null,"My Stuff");	
     	    return false;
      	});
      	
		$(".verifyMeButton").click(function(){
			verifyMe();
		})
		
		$("#penddingVerify").click(function(){
			updateVerifiedStatus();
		})
		
		if($("#penddingVerify") != null && $("#penddingVerify").css("display") != null 
			&& ($("#penddingVerify").css("display") == "" || $("#penddingVerify").css("display") == "block")){
			//verifyOnlyUpdateTime define in appData.jsp
			if(parseInt(verifyOnlyUpdateTime) > 0 && autocheckVerifiedStatus == null){
				autocheckVerifiedStatus = setInterval(updateVerifiedStatus,verifyOnlyUpdateTime);
			}
		}
   	
      	$("a.myInvoice").click(function (e) { 
      	
		   var returnFunction = function(returnMsg) {
				if ( returnMsg.indexOf("success") >= 0 ) {
					goToURL("/myaccount/invoice.jsp");
				}
				else if ( returnMsg == "login" ) { goToURL("/register"); return false }
				else showErrors("errorTop",returnMsg,true);
			}
			var urlid = getURLParam(this.href, 'id');
			
			var query="id="+urlid;
			
			submitAjaxFromQuery("myInvoice",returnFunction,"GET", query,"View Invoice");
			return false;
	    });
	    
	    $("BUTTON#sendEmailButton").click(function () { sendSabreEmail();});
	    
	    //SLIDERS

	var timeOB0 = new Date($('#obDepartTimeValue0').text()).getTime();
	var timeOB1 = new Date($('#obDepartTimeValue1').text()).getTime();
	$('#obDepartTimeValue0').html(formatTime(new Date(timeOB0),true));
	$('#obDepartTimeValue1').html(formatTime(new Date(timeOB1),true));
			
	var timeIB0 = new Date($('#ibDepartTimeValue0').text()).getTime();
	var timeIB1 = new Date($('#ibDepartTimeValue1').text()).getTime();
	$('#ibDepartTimeValue0').html(formatTime(new Date(timeIB0),true));
	$('#ibDepartTimeValue1').html(formatTime(new Date(timeIB1),true));
	
	
	$('#jQsliderOB').slider({
		handle: '.jQsliderHandle',
		min: timeOB0,
		max: timeOB1,
		stepping: 900000,
		range: true,
		start: function(e, ui) {
			var minValue = $(this).slider('value', 0); 
			var maxValue = $(this).slider('value', 1);
			$('#' + ui.handle.attr('id') + 'Value0').html(formatTime(new Date(minValue),true));
			$('#' + ui.handle.attr('id') + 'Value1').html(formatTime(new Date(maxValue),true));
			
		},
		stop: function(e, ui) { 
			var minValue = $(this).slider('value', 0); 
			var maxValue = $(this).slider('value', 1);
			$('#' + ui.handle.attr('id') + 'Value0').html(formatTime(new Date(minValue),true));
			$('#' + ui.handle.attr('id') + 'Value1').html(formatTime(new Date(maxValue),true));
			
		},
		slide: function(e, ui) {
			var minValue = $(this).slider('value', 0); 
			var maxValue = $(this).slider('value', 1);
			$('#' + ui.handle.attr('id') + 'Value0').html(formatTime(new Date(minValue),true));
			$('#' + ui.handle.attr('id') + 'Value1').html(formatTime(new Date(maxValue),true));
		},
		change: function(e, ui) {
			var minValue = $(this).slider('value', 0); 
			var maxValue = $(this).slider('value', 1);
			$('#' + ui.handle.attr('id') + 'Value0').html(formatTime(new Date(minValue),true));
			$('#' + ui.handle.attr('id') + 'Value1').html(formatTime(new Date(maxValue),true));
			if (ui.value == minValue){
				filterResults(ui.handle.attr('id'),ui.value,'0');
			}
			else {
				filterResults(ui.handle.attr('id'),ui.value,'1');
			}

		}
	});
	
	$('#jQsliderIB').slider({
		handle: '.jQsliderHandle',
		min: timeIB0,
		max: timeIB1,
		stepping: 900000,
		range: true,
		start: function(e, ui) {
			var minValue = $(this).slider('value', 0); 
			var maxValue = $(this).slider('value', 1);
			$('#' + ui.handle.attr('id') + 'Value0').html(formatTime(new Date(minValue),true));
			$('#' + ui.handle.attr('id') + 'Value1').html(formatTime(new Date(maxValue),true));
			
		},
		stop: function(e, ui) { 
			var minValue = $(this).slider('value', 0); 
			var maxValue = $(this).slider('value', 1);
			$('#' + ui.handle.attr('id') + 'Value0').html(formatTime(new Date(minValue),true));
			$('#' + ui.handle.attr('id') + 'Value1').html(formatTime(new Date(maxValue),true));
			
		},
		slide: function(e, ui) {
			var minValue = $(this).slider('value', 0); 
			var maxValue = $(this).slider('value', 1);
			$('#' + ui.handle.attr('id') + 'Value0').html(formatTime(new Date(minValue),true));
			$('#' + ui.handle.attr('id') + 'Value1').html(formatTime(new Date(maxValue),true));
		},
		change: function(e, ui) {
			var minValue = $(this).slider('value', 0); 
			var maxValue = $(this).slider('value', 1);
			$('#' + ui.handle.attr('id') + 'Value0').html(formatTime(new Date(minValue),true));
			$('#' + ui.handle.attr('id') + 'Value1').html(formatTime(new Date(maxValue),true));
			if (ui.value == minValue){
				filterResults(ui.handle.attr('id'),ui.value,'0');
			}
			else {
				filterResults(ui.handle.attr('id'),ui.value,'1');
			}
		}
	});
		
	    //ec.register(null,null,getSliderClassName(),"mousedown","Clicking Slider",clickSlider,true,null,null);
		//ec.register(null,null,getSliderClassName(),"drag","Dragging Slider",dragSlider,true,null,null);
		//ec.register(null,null,getSliderClassName(),"dragstop","Released Slider",releaseSlider,true,null,null);
	    
	    
	    $("BUTTON#billShipSubmitButton").click(function (e) {billShipSubmit(e); });
      	$("BUTTON#signInButton").click(function (e) {login(e); });
      	$("BUTTON#continueBtnJoin").click(function (e) {signUp(e); });
		$("BUTTON#saveBtn").click(function (e) {updateProfile(e); });
		$("A#AFlyGreen").click(function () {    
			$("#idGreen").toggle(); 
			imageToggle(2);
			return false;
			});
		$("A#ATripProt").click(function () {    
			$("#tripProt").toggle(); 
			imageToggle(1); 
			return false;
			});
		$("A#AllPrice").click(function () {
			$("#disprice").toggle();
			return false;
		});	
		
$("#dealAlertSignup SELECT#universityCountryID").change(function (e) {
      		loadStates(e);
      			
      	});			
$("#dealAlertSignup SELECT#universityLocationID").change(function (e) {
      		loadUnivs(e);
      			
      	});				
		$("a#abandonPopUp").click();	
});


