
 function show_box()
 {

   var params = $(".tripform").serialize();

   //alert(params);
  tb_show("Submit your Trip Request", "submit_atw.php?"+params, "");

 
 }
 
function serialize(s)
{
	serial = $.SortSerialize(s);
	alert(serial.hash);
};


// pre-submit callback 
function showRequest(formData, jqForm, options) 
{ 

// formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    //var queryString = $.param(formData); 
 
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
   // var formElement = jqForm[0]; 
    //alert('About to submit: \n\n' + queryString); 

$("#main").slideUp(300,function(){$("#main").animate({ opacity: 1.0}, "slow").html("<div style='margin:100px 0 0 0px;text-align: center;background:#9bbdd5;'><img src='images/loader1.gif' alt='fares loading' title='fares loading' /><br/><div style='vertical-align:top;margin:0px 0 0 0;text-align: center;font-weight:bold;background:#9bbdd5;font-size: 16px'>Map Loading...<br/></div></div>");});


    // here we could return false to prevent the form from being submitted
    // returning anything other than false will allow the form submit to continue 

    return true; 
 
 } 
 
// post-submit callback 

function showResponse(msg){
 $("#main").fadeIn(1000,function(){$("#main").html( msg);});

   }
 
 
 var toggleContent = function(e)
{
	var targetContent = $('div.tripContent', this.parentNode.parentNode.parentNode);
	if (targetContent.css('display') == 'none') {
		targetContent.slideDown(300);
		$(this.parentNode.parentNode).find(".toggle").html('[-]');
	} else {
		targetContent.slideUp(300);
		$(this.parentNode.parentNode).find(".toggle").html('[+]');
		//$(this).html('[+]');
	}
	return false;
};
 
 
 
  
 var toggleImage = function(e)
{
	//  alert($(this.parentNode).attr("title"));
	if($(this.parentNode).attr("title") == "air")
{
$(this.parentNode).attr({ title: "land"});
	  $(this).slideUp(500, function(){$(this).attr({ src: "land.gif"}) ;});
   $(this).slideDown(500);
$(this.parentNode.parentNode).find('.mode').html('<input class="tripform" type="hidden"  value="land" name="trip_mode[]"/>');

}

else
{
$(this.parentNode).attr({ title: "air"});
	  $(this).slideUp(500, function(){$(this).attr({ src: "air.gif"}) ;});
   $(this).slideDown(500);
  //alert($(this.parentNode).attr("title"));
  	$(this.parentNode.parentNode).find('.mode').html('<input class="tripform" type="hidden"  value="air" name="trip_mode[]"/>');
}
};
 
 
 
/***
function showWindow(city){

//alert(city);

if($('#window').css('display') == 'none') {
$('#windowContent').append('<div class="temp_city"><span  style="color:lightblue;marin:2px 0 0 0" onclick="addCityToList(\''+city+'\')" >Add ' + city + ' To trip</span></div>');
				$('#window').fadeIn(500);
				}
				this.blur();
				return false;
   }*****/

function showWindow(city){

        // cache the question element 
               
 addCityToList(city);

       
         
   }

 
function hideWindow(){

$.unblockUI();
}


function show_map(continent)
{
 $.ajax({
   type: "GET",
   url: "map_nav.php",
   data: "continent=" + continent,
   beforeSend:  showRequest,  // pre-submit callback 
   success:       showResponse  // post-submit callback 	
 });
}
function addNewCityToList(newcity)
{
 var inputCity = $('#dep_city').val();
 //alert(testing12);
 
 if(inputCity == "" | inputCity.length < 3 | inputCity == "City not on Map? Type here")
 {
 
// $('#null_city').text("Enter City").addClass("null_error").fadeIn("slow");
  $('#dep_city').css({ border: "1px solid red"});
  alert("Please Enter a city  name or code greater than 3 character.");
 return false;
 }
 else 
 $('#null_city').removeClass("null_error").empty();
var nofade = "omit_fade";
$('#dep_city').attr({ value: ""});
 addCityToList(inputCity,nofade);
}
var trip_mode = "air";
var j = 0;
function addCityToList(city,fade_item,trip_mode)
				{
			if(!trip_mode)
				{
				//alert(trip_mode );
				trip_mode = "air";
				}
			
						
					var cartItem;
					var isInCart = $('#' + j + '_cart');
						
	
			if ($('.sortableitem').size() == 0)
			{
				
				
				/***********************************************************
				 * Keep in mind here that changes that are made to the 
				 * div id top also affect the updating of the sortable
				 * as well as the toggleImage function
				 *
				*************************************************************/		
				
							$('#tripList')
							.append('<li id="tripList' + j + '" class="sortableitem"><div title="air" id="top" class="tripImage"><span style="color:green">start</span></div><div class="containerItem"><div class="productCart" id="' + j + '"><div class="itemHeading">' + city + '<a href="#" style="margin:0 20px 3px 0;text-decoration:none;color:#333" class="closeEl toggle">[+]</a><a href="#" class="closeEl"><img src="calendar.gif" border="0" /></a><img src="cross.jpg"  class="removeLoc" alt="close"/></div><div class="tripContent">Depart: <input  style="width:70px" class="date-pick tripform" id="dep_date' + j + '" name="date[]" type="text" readonly="readonly" value="mm/dd/yyyy" /><br /></div><input class="tripform" type="hidden" value="'+city+'" name="depart_city[]"/><div class="mode"><input class="tripform" type="hidden"  value="air" name="trip_mode[]"/></div></div></div></li>')
							.find('div.productCart:last')
							.fadeIn(400)
							.find('.removeLoc')
							.bind(
							
								'click', function(){
								
											$(this.parentNode.parentNode).DropOutDown(
											400,
											function()
												 {
													$(this.parentNode.parentNode).remove((j--));
	//alert($('.sortableitem').size());							
										
										
																if( $('.sortableitem').size() == 2)
			{
				
				$("#add_to_trip").fadeOut(600);
				
			}
						if($('#tripList').find('.tripImage:first').attr("id") != 'top')
					{
						//alert("This is the 1st div")
						
						/*************************************************
						 * logical proces here.
						 * 
						 * If first item is not id=start
						 * 	set the top items html() to  'start'
						 * 	The html() of the #top to default of Air
						 * 	remove the div with the attribute of id=top
						 * 	return to the 1st item and assign it the id
						 *  attribute= top.
						 * 
						 * 
						 ***************************************************/
					$('#tripList').find('div.tripImage:first').html('<span style="color:green">start</span>');
						
						$('#top').html('<img title="Click icon to switch between air or overland" src="air.gif" alt="hint" class="mode_image" style="margin:5px 0px 0px 3px"  width="20" height="20"/>');
						$('#tripList').find('#top').removeAttr( "id");
						$('#tripList').find('div.tripImage:first').attr({ id: "top", title: "air"});
		
					
					$('a.closeEl').bind('click', toggleContent);
					$('.mode_image').bind('click', toggleImage);
	
									$('.mode_image').ToolTip(
	{
		className: 'linksTooltip',
		position: 'mouse',
		delay: 200
	}
);
					}

																

													
												}
											);
										return false;
									});
				
				
				
			}
		
		
			else
			 	
							$('#tripList')
							.append('<li id="tripList' + j + '" class="sortableitem"><div title="air" class="tripImage"><img title="Click icon to switch between air or overland" src="' +trip_mode+ '.gif" class="mode_image" style="margin:5px 0px 0px 3px"  alt="hint"  width="20" height="20"/></div><div class="containerItem"><div class="productCart" id="' + j + '"><div class="itemHeading">' + city + '<a href="#" class="closeEl toggle" style="margin:0 20px 3px 0;text-decoration:none;color:#333">[+]</a><a href="#" class="closeEl"><img src="calendar.gif" border="0" /></a><img src="cross.jpg"  alt="close"  class="removeLoc"/></div><div class="tripContent">Depart: <input  style="width:70px" class="date-pick tripform" id="dep_date' + j + '" name="date[]" type="text" readonly="readonly" value="mm/dd/yyyy" /><br /></div><input class="tripform" type="hidden" value="'+city+'" name="depart_city[]"/><div class="mode"><input class="tripform" type="hidden" value="' +trip_mode+ '" name="trip_mode[]"/></div></div></div></li>')
							.find('div.productCart:last')
							.fadeIn(400)
							.find('.removeLoc')
							.bind(
							
								'click', function(){
								
											$(this.parentNode.parentNode).DropOutDown(
											400,
											function()
												 {
													$(this.parentNode.parentNode).remove((j--),createLists());								
													//alert($('.sortableitem').size());										
					 if( $('.sortableitem').size()  == 2)
			{
				
				$("#add_to_trip").fadeOut(600);
				
			}	
		
									
									if($('#tripList').find('.tripImage:first').attr("id") != 'top')
					{
						//alert("This is the 2nd div")
						
						/*************************************************
						 * logical proces here.
						 * 
						 * If first item is not id=start
						 * 	set the top items html() to  'start'
						 * 	The html() of the #top to default of Air
						 * 	remove the div with the attribute of id=top
						 * 	return to the 1st item and assign it the id
						 *  attribute= top.
						 * 
						 * 
						 ***************************************************/
					$('#tripList').find('div.tripImage:first').html('<span style="color:green">start</span>');
						
						$('#top').html('<img title="Click icon to switch between air or overland" src="air.gif"  alt="hint" class="mode_image" style="margin:5px 0px 0px 3px"  width="20" height="20"/>');
						$('#tripList').find('#top').removeAttr( "id");
						$('#tripList').find('div.tripImage:first').attr({ id: "top", title: "air"});
		
					
					$('a.closeEl').bind('click', toggleContent);
					$('.mode_image').bind('click', toggleImage);
	
									$('.mode_image').ToolTip(
	{
		className: 'linksTooltip',
		position: 'mouse',
		delay: 200
	}
);
					}
	
			
											
										
												}
											);
										
									});


	/**	if(fade_item != "omit_fade"){
		$('#window').fadeOut(700, function() {$('.temp_city').remove();});
			}**/
						

						/*************************************************
						 * Start of sortable creation.
						 *  
						 * 
						 ***************************************************/
				function createLists(){			
								
					$('#tripList').Sortable(
			{
				accept : 		'sortableitem',
				helperclass : 	'sorthelper',
				ghosting  :     1,
				activeclass : 	'sortableactive',
				hoverclass : 	'sortablehover',
				snapDistance: 10,
				onStop:        function()
				{
					
					
					
					if($('#tripList').find('.tripImage:first').attr("id") != 'top')
					{
						//alert("This is the 3rd div")
						
						/*************************************************
						 * logical proces here.
						 * 
						 * If first item is not id=start
						 * 	set the top items html() to  'start'
						 * 	The html() of the #top to default of Air
						 * 	remove the div with the attribute of id=top
						 * 	return to the 1st item and assign it the id
						 *  attribute= top.
						 * 
						 * 
						 ***************************************************/
					$('#tripList').find('div.tripImage:first').html('<span style="color:green">start</span>');
						
						$('#top').html('<img title="Click icon to switch between air or overland" src="air.gif" alt="hint"  class="mode_image" style="margin:5px 0px 0px 3px"  width="20" height="20"/>');
						$('#tripList').find('#top').removeAttr( "id");
						$('#tripList').find('div.tripImage:first').attr({ id: "top", title: "air"});
		
					
					$('a.closeEl').bind('click', toggleContent);
					$('.mode_image').bind('click', toggleImage);
	
									$('.mode_image').ToolTip(
	{
		className: 'linksTooltip',
		position: 'mouse',
		delay: 200
	}
);
					}
					
				},
				opacity: 		0.7,
				fx:				200,
				axis:			'vertically',
				opacity:		0.4
			}
		);
			
							$('a.closeEl').bind('click', toggleContent);
					$('.mode_image').bind('click', toggleImage);
						var r ="";
			r +=	$("#dep_date" + j ).datePicker({clickInput:true});
									$('.mode_image').ToolTip(
	{
		className: 'linksTooltip',
		position: 'mouse',
		delay: 200
	}
);		
		}
				//alert("#dep_date" + j );
				

createLists();
						/*************************************************
						 * End of sortable creation
						 ***************************************************/


						
						/*************************************************
						 * How many do we want before we show the submit
						 * button
						 * 
						 * 
						 ***************************************************/
 			if( $('.sortableitem').size()  == 3)
					{
				
					$("#add_to_trip").html('<span class="add_trip"  onclick="show_box()" title="Submit your Around the world request." ><input type="button" value="Submit Request"/></span>').fadeIn(600);
					
					}

						/*************************************************
						 * End of submit
						 ***************************************************/
		


				j++;
			
	}			

function load_cal(item_class)
{

		
		/**
		$('#windowClose').bind(
			'click',
			function()
			{
				$('#window').fadeOut(700);
$('.temp_city').remove();
			}
		);***/


}





function formatItem(row) {
	return row[0] + "<br /><i>" + row[1] + "</i>";
}
		
	
/**
 * @author timani
 */


function show_info(page)
{

 
  $.ajax({
   type: "GET",
   url: "atw_info.php",
   data: "page=" + page,
   beforeSend:  showLoad,  // pre-submit callback 
   success:       showInfo  // post-submit callback 	
 });
}


// pre-submit callback 
function showLoad(formData, jqForm, options) 
{ 

// formData is an array; here we use $j.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    //var queryString = $j.param(formData); 
 
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
   // var formElement = jqForm[0]; 
    //alert('About to submit: \n\n' + queryString); 

$("#information").fadeIn(150).empty( );


    // here we could return false to prevent the form from being submitted
    // returning anything other than false will allow the form submit to continue 

    return true; 
 
 } 
 
// post-submit callback 

function showInfo(msg){
 $("#information").fadeIn(100, function(){$("#information").html( msg);});

   }
		
