var Tripplanner = {

		InitializeTripPlannerPage: function () {
			var TripPlanText = "Do not include city/zip";
			
			// Interface
			if(!$.browser.msie){
				$("#TripPlannerForm,#TripPlannerFeedbackForm,#ResultsTable,.faretable,#BookMarkWrapper,#TripPlannerNote,.TripItinerary,.TripItineraryNumber,.error,#TripPlannerLocationsDesc,.serviceprovider").corner();
				$(".maplink").corner("2px");
			}
			
			if($(".xmode").length){
				$(".xmode").click(function(){
					$(".xmodeAll").attr("checked",false);
				});
				$(".xmodeAll").click(function(){
					$(".xmode").attr("checked",false);
				});	
			}
			
			if($("#MoreOptions").length){
				$("#MoreTripPlannerOptions").toggle(
					function(){
						$("#MoreOptions").show();
						$("#MoreTripPlannerOptions").val("Less Options");
					},
					function(){
						$("#MoreOptions").hide();
						$("#MoreTripPlannerOptions").val("More Options");
					}
				);
			}
			
			if($("#MoreOptions")){
				if($("#firstroute").val() == "" &&  $("#lastroute").val() == "" && $("input[name='xmode']:checked").val() == "BCFKLRSTX123"){ 
					$("#MoreOptions").hide();
				}
			}

			$("#TripPlannerForm").submit(function(){
				var start = $("#Origin").val();
				var end = $("#Destination").val();
				if(start == TripPlanText || end == TripPlanText){
					$("#errors").show("fast");
					$("#errors").html("Please specify a start and end location");
					return false;
				} else {
					return true;	
				}
			});
	
			if($("#Origin").val() == '' | $("#Origin").val() == TripPlanText) {
				$("#Origin").val(TripPlanText);
				$("#Origin").css({ "color":"gray" });
			};
			
			if($("#Destination").val() == '' | $("#Destination").val() == TripPlanText) {
				$("#Destination").val(TripPlanText);
				$("#Destination").css({ "color":"gray" });
			};
			
			if($("#BookMarkTrip").length){
				$("#BookMarkTrip").toggle(function(){
					$("#bookmark").show();
				},function(){
					$("#bookmark").hide();
				});
				//$("#bookmarkBox").click(function(){
					//$("#bookmarkBox").select();
				//});
			};
			
			// Find Landmarks
			if($("#findlandmarks").length){
				$("#findlandmarks").change(function(){
					var landmark = $("#findlandmarks").val();
					$("#findlandmarksresults").show();
					$("#findlandmarksresults").html("<blink>Loading...</blink>");
					$.ajax({
					   type: "POST",
					   url: "/BusService/TripPlanner.cfc?method=getLandmarksByCategories",
					   data: "type="+landmark,
					   success: function(msg){
						 $("#findlandmarksresults").html(msg);
						 $(".landmarksuggestion").click(function(){
							var startend = $("input[name='landmarkstartend']:checked").val();
							var selectedval = $(this).html();
							//console.log(startend + "-" + selectedval);
							if(startend=="landmarkstart"){
								$("#Origin").val(selectedval);
								$("#Origin").css({ "color":"black" });
							} else {
								$("#Destination").val(selectedval);
								$("#Destination").css({ "color":"black" });
							}
						});
					   }
					 });
				});
			};
	
			$("#Origin").focus(
				function () {
					if($(this).val() == TripPlanText) {
							$(this).val("");
							$(this).css({ "color":"black" });
					};
					$(this).select();
				}
			 );
			
			$("#Origin").blur(
				function () {
					if($(this).val() == '') {
							$(this).val(TripPlanText);
							$(this).css({ "color":"gray" });
					};
				}
			 );
			
			$("#Destination").focus(
				function () {
					if($(this).val() == TripPlanText) {
							$(this).val("");
							$(this).css({ "color":"black" });
					};
				$(this).select();
				}
			 );
			
			$("#Destination").blur(
				function () {
					if($(this).val() == '') {
							$(this).val(TripPlanText);
							$(this).css({ "color":"gray" });
					};
				}
			 );
			
			// Hide icon key
			$("#KeyTable").hide();
			$("#BusIconKey").toggle(
				function(){
					$("#KeyTable").show('fast');
					$("#BusIconKeyArrow").attr("src","/Images/Interface/ArrowDown_Blue.png");
				},
				function(){
					$("#KeyTable").hide('fast');
					$("#BusIconKeyArrow").attr("src","/Images/Interface/ArrowLeft_Blue.png");
				}
			);
			// Hide Fare Tables
			$(".faretable").hide();
			$(".showhidefare").toggle(function(){
				$(this).siblings(".faretable").show();
				$(this).children(".FareArrow").attr("src","/Images/Interface/ArrowDown_Blue.png");
			},function(){
				$(this).siblings(".faretable").hide();
				$(this).children(".FareArrow").attr("src","/Images/Interface/ArrowLeft_Blue.png");
			});
	}  //InitializeTripPlannerPage
};

$(Tripplanner.InitializeTripPlannerPage);


function printPage(obj){
	var newwindow = window.open('','', config='height=400,width=600, toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, directories=no, status=no',false);
	// get content
	content = '<h3>Trip Planner</h3>'+$("#"+obj).html();
	
	// style
	var style;
	style = '<link href="/busservice/TripPlanner_Print.css" rel="stylesheet" type="text/css">';
	
	// build html object
	var htmlobj;
	htmlobj = '<html>';
	htmlobj = htmlobj + '<head>';
	htmlobj = htmlobj + '<title>Print Trip</title>';
	htmlobj = htmlobj + style;
	htmlobj = htmlobj + '</head>';
	htmlobj = htmlobj + '<body>';
	htmlobj = htmlobj + '<a id="PrintWindow" onclick="window.print();">Print</a>';
	htmlobj = htmlobj + content;
	htmlobj = htmlobj + '</body>';
	htmlobj = htmlobj + '</html>';
	
	// attach object
	newwindow.document.write(htmlobj);
	newwindow.document.close();
	newwindow.print();
	//$(htmlobj).appendTo($(newwindow.document));
	// newwindow.location.reload(false);
	// newwindow.focus();
	// newwindow.print();
}
		




		



