$(document).ready(function() { 
	
	$('input:text').setMask();
	$('#form_login_load').css('visibility','hidden');
	$('#search_box1_load').css('visibility','hidden');

	
	$("#dp_city").suggest("core/airportSuggest.php");
	$("#ar_city").suggest("core/airportSuggest.php");
	$("#airline2").suggest("core/airlineSuggest.box2.php");


	/* ADS area */
	$("#adTop").fadeIn();
	$("#adLeft").fadeIn();
	$("#adRight").fadeIn();
	
	/* Event to change Search default values */
	$("#dp_city").click(function() { if($(this).val() == "Departure...") { $(this).val(""); } });
	$("#dp_city").blur(function() { if($(this).val() == "") { $(this).val("Departure..."); } });
	$("#ar_city").click(function() { if($(this).val() == "Arrival...") { $(this).val(""); } });
	$("#ar_city").blur(function() { if($(this).val() == "") { $(this).val("Arrival..."); } });
	$("#airline1").click(function() { if($(this).val() == "All Airlines...") { $(this).val(""); } });
	$("#airline1").blur(function() { if($(this).val() == "") { $(this).val("All Airlines..."); } });
	
	/* Event to change Search default values */
	$("#airline2").click(function() { if($(this).val() == "Airline...") { $(this).val(""); } });
	$("#airline2").blur(function() { if($(this).val() == "") { $(this).val("Airline..."); } });
	$("#flightnumber").click(function() { if($(this).val() == "Flight Number...") { $(this).val(""); } });
	$("#flightnumber").blur(function() { if($(this).val() == "") { $(this).val("Flight Number..."); } });	
	
	/* Set Mask to zipcode */
	$('#zipcode').setMask("99999");   
	$('#dateBox1').setMask("99/99/9999");   
	$('#dateBox2').setMask("99/99/9999");   
	$('#cell_phone').setMask("999-999-9999");  
	
	$("#newPassword").bind("submit", function() {
		if($("#newPass").val() == "") {
			alert("Please, enter a new password!");
			$("#newPass").focus();
			return false;
		} else if($("#newPass_confirm").val() == "") {
			alert("Please, confirm the password!");
			$("#newPass_confirm").focus();	
			return false;
		} else if($("#newPass").val() != $("#newPass_confirm").val() )  {
			alert("The passwords didn't match, try again!");
			$("#newPass").focus();
			return false;
		} else {
			password = $("#newPass").val();
			code = $("#code").val();		
			$.post("core/setPassword.php", { set: "new_password", password: password, code: code }, function(data) { 
				alert("Ok, your password was changed!");
				window.top.location.href='./';
			});
			return false;
		}
		
	});
 
	$('#idontremember').click(function() { 
		if($("#authEmail").val() == "") {
			alert("Please, enter your email!");
			$("#authEmail").focus();
		} else {
			email = $("#authEmail").val();
			$.post("core/setPassword.php",{ email: email }, function(data) {
				alert("Please, check your email. We sent the instructions!")
			});
		}
	});
	
	
	/* Validate Add User */
	$("#formUser").bind('submit', function() { 	
		if($("#name").val() == "") {
			$("#name").addClass("formUserReg_al");
			$("#name").focus();
			return false;
		} else if($("#last_name").val() == "") {
				$("#name").removeClass("formUserReg_al");
				$("#last_name").addClass("formUserReg_al");
				$("#last_name").focus();
				return false;
		} else if(($("#email").val() == "" || /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($("#email").val()) != "1") && $("#action").val() == "insert") {
			$("#name").removeClass("formUserReg_al");
			$("#last_name").removeClass("formUserReg_al");
			$("#email").addClass("formUserReg_al");
			$("#email").focus();
			return false;
		} else if($("#email_confirm").length == 1 && ($("#email").val() != $("#email_confirm").val())) {
			$("#email_confirm").addClass("formUserReg_al");
			$("#email_confirm").focus();
			return false;
		} else if($("#password").val() == "" && $("#action").val() == "insert") {
			$("#name").removeClass("formUserReg_al");		
			$("#last_name").removeClass("formUserReg_al");
			$("#email").removeClass("formUserReg_al");
			$("#email_confirm").removeClass("formUserReg_al");
			$("#password").addClass("formUserReg_al");
			$("#password").focus();
			return false;
		} else if($("#password_confirm").val() == "" && $("#action").val() == "insert") {
			$("#name").removeClass("formUserReg_al");	
			$("#last_name").removeClass("formUserReg_al");
			$("#email").removeClass("formUserReg_al");
			$("#password").removeClass("formUserReg_al");
			$("#password_confirm").addClass("formUserReg_al");
			$("#password_confirm").focus();
			return false;
		} else if($("#password").val() != $("#password_confirm").val() && $("#action").val() == "insert") {
			$("#password").addClass("formUserReg_al");
			$("#password_confirm").addClass("formUserReg_al");
			$("#password_match").html("The password is different!");
			$("#password_confirm").focus();
			return false;
		} else if($("#password").val() != "" && $("#action").val() == "update") {
			if($("#password").val() != $("#password_confirm").val()) {
				$("#password").addClass("formUserReg_al");
				$("#password_confirm").addClass("formUserReg_al");
				$("#password_confirm").focus();
				return false;
			}
		} else if($("#address1").val() == ""  ) {
			$("#name").removeClass("formUserReg_al");	
			$("#last_name").removeClass("formUserReg_al");
			$("#email").removeClass("formUserReg_al");
			$("#password").removeClass("formUserReg_al");
			$("#password_confirm").removeClass("formUserReg_al");
			$("#address1").addClass("formUserReg_al");
			$("#address1").focus();
			return false;
		} else if($("#city").val() == ""  ) {
			$("#name").removeClass("formUserReg_al");
			$("#last_name").removeClass("formUserReg_al");
			$("#email").removeClass("formUserReg_al");
			$("#password").removeClass("formUserReg_al");
			$("#password_confirm").removeClass("formUserReg_al");
			$("#address1").removeClass("formUserReg_al");
			$("#zipcode").removeClass("formUserReg_al");
			$("#city").addClass("formUserReg_al");
			$("#city").focus();
			return false;
		} else if($("#state").val() == ""  ) {
			$("#name").removeClass("formUserReg_al");	
			$("#last_name").removeClass("formUserReg_al");
			$("#email").removeClass("formUserReg_al");
			$("#password").removeClass("formUserReg_al");
			$("#password_confirm").removeClass("formUserReg_al");
			$("#address1").removeClass("formUserReg_al");
			$("#zipcode").removeClass("formUserReg_al");
			$("#city").removeClass("formUserReg_al");
			$("#state").addClass("formUserReg_al");
			$("#state").focus();
			return false;
		} else if($("#zipcode").val() == ""  ) {
			$("#name").removeClass("formUserReg_al");
			$("#last_name").removeClass("formUserReg_al");
			$("#email").removeClass("formUserReg_al");
			$("#password").removeClass("formUserReg_al");
			$("#password_confirm").removeClass("formUserReg_al");
			$("#address1").removeClass("formUserReg_al");
			$("#zipcode").addClass("formUserReg_al");
			$("#zipcode").focus();
			return false;
		} else if($("#cell_phone").val() == "") {
			$("#name").removeClass("formUserReg_al");
			$("#last_name").removeClass("formUserReg_al");
			$("#email").removeClass("formUserReg_al");
			$("#password").removeClass("formUserReg_al");
			$("#password_confirm").removeClass("formUserReg_al");
			$("#address1").removeClass("formUserReg_al");
			$("#zipcode").removeClass("formUserReg_al");
			$("#cell_phone").addClass("formUserReg_al");
			$("#cell_phone").focus();
			return false;
		}
		if($("#action").val() == "insert") {
			file = "addUser.php";
		} else {
			file = "upUser.php";
		}
		
		$.post("core/"+file, { 
			id_package: $("#package").val(), cell_phone: $("#cell_phone").val(), 
			auth: $("#auth").val(), name: $("#name").val(), last_name: $("#last_name").val(), 
			email: $("#email").val(), password: $("#password").val(),
			city: $("#city").val(),state: $("#state").val(),
			address1: $("#address1").val(), address2: $("#address2").val(), zipcode: $("#zipcode").val()
		},function(data) {
			if(data == 10) { // if email already used
				$("#email").addClass("formUserReg_al");
				$("#email_used").html("This e-mail is already in use!");
				return false;
			} else if(data == 1) { // if all is ok
				$("#name").removeClass("formUserReg_al");
				$("#last_name").removeClass("formUserReg_al");
				$("#email").removeClass("formUserReg_al");
				$("#email_confirm").removeClass("formUserReg_al");
				$("#password").removeClass("formUserReg_al");
				$("#password_confirm").removeClass("formUserReg_al");
				$("#address1").removeClass("formUserReg_al");
				if($("#action").val() == "insert") {
					//$("#alert").addClass("alert_red");
		
					$("#register").html("<div id='register_core'>We've sent by e-mail the instructions to validate your <br>account, please check your inbox!</div><br><a href='./Search' class='pn_link' id='backIn'>Back</a>");
					$("#prevnext").html("");

					
					// Clear all fields
					$("#name").val('');
					$("#last_name").val('');
					$("#email").val('');
					$("#email_confirm").val('');
					$("#password").val('');
					$("#password_confirm").val('');
					$("#address1").val('');
					$("#address2").val('');
					$("#city").val('');
					$("#state").val('');
					$("#zipcode").val('');
					$("#cell_phone").val('');
					$("#email_used").html("");
					window.top.location.href='#top';
				}
			} else {
				$("#alert").addClass("alert_red");
				if($("#valid_id_package").val() != $("#package").val() && $("#package").val() != "1")  { // if we detect upgrade 
					more_info = '. <a href="javascript:reloadPayLink()" id="pay" class="alertLink_red"><b>Click here</b> to active the new package</a>';
				} else {
					more_info = '';
				}
				$("#alert li").html("Ok, your information has been updated"+more_info+"!");
				window.top.location.href='#top';			
				return false;
			}
			return false;
		});
		return false;
	});
	$('#formUserSubmit').click(function() { $('#formUser').submit(); });

	/* Auth User */
	$("#authUser").bind('submit', function() {
		if($("#authEmail").val() == "" || /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($("#authEmail").val()) != "1" ) {
			 $("#authEmail").addClass("formLogin_input_al");
			 $("#authEmail").focus();
			 return false;
		}
		if($("#authPassword").val() == "") {
			 $("#authEmail").removeClass("formLogin_input_al");
			 $("#authPassword").addClass("formLogin_input_p_al");
			 $("#authPassword").focus();
			 return false;
		}
		$('#form_login_load').css('visibility','visible');
		$.post("core/authUser.php", { redirect: $("#redirect").val(),  authEmail: $("#authEmail").val(), authPassword: $("#authPassword").val() } ,
				
				function(data) { 	
					
						
					if(data == "0") {
						$("#authPassword").addClass("formLogin_input_p_al");
						$('#form_login_load').css('visibility','hidden');
					} else  { 
						window.top.location.href= './'+data;
					}
				}
		);
		return false;
	});
	$('#formUserAuthOK').click(function() { $('#authUser').submit(); });
	
	/* Clear button */
	$("#clear").click(function() { 
		$.post("core/clearForm.php");
		window.top.location.href = './';
	});
	
	/* Search BOX 1 */
	$("#search_box1").bind('submit', function() {
		if($("#dp_city").val() == "Departure..." ) {
			 $("#dp_city").addClass("formContent_search_al");
			 $("#dp_city").focus();
			 return false;
		}
		if($("#ar_city").val() == "Arrival...") {
			 $("#dp_city").removeClass("formContent_search_al");
			 $("#ar_city").addClass("formContent_search_al");
			 $("#ar_city").focus();
			 return false;
		}
		$("#dp_city").removeClass("formContent_search_al");
		$("#ar_city").removeClass("formContent_search_al");
		$('#search_box1_load').css('visibility','visible');
		$.post("core/setSearch.php", { dateBox1: $("#dateBox1").val(), box1: $("#box1").val(), dp_city: $("#dp_city").val(), airline1: $("#airline1").val(), ar_city: $("#ar_city").val(), sitekey: $("#sitekey").val() } ,
				function(data) { 	

					if(data=="4") {
						window.top.location.href='./Search-Result';
					} else if(data=="1") {
						$("#dp_city").addClass("formContent_search_al");
					} else if(data=="2") {
						 $("#ar_city").addClass("formContent_search_al");
					} else if(data=="3") {
						 $("#airline1").addClass("formContent_search_al");
					} else { 

						$('#search_box1_load').css('visibility','hidden');
					}
				}
		);
		return false;
	});
	
	/* Search BOX 2 */
	$("#search_box2").bind('submit', function() {
		if($("#airline2").val() == "Airline...") {
			 $("#airline2").addClass("formContent_search_al");
			 $("#airline2").focus();
			 return false;
		} else if($("#flightnumber").val() == "Flight Number...") {
			 $("#airline2").removeClass("formContent_search_al");
			 $("#flightnumber").addClass("formContent_search_al");
			 $("#flightnumber").focus();
			 return false;
		}
		$('#search_box1_load').css('visibility','visible');
		$("#airline2").removeClass("formContent_search_al");
		$("#flightnumber").removeClass("formContent_search_al");
		$.post("core/setSearch.php", { dateBox2: $("#dateBox2").val(), box2: $("#box2").val(), sitekey: $("#sitekey").val(),  airline2: $("#airline2").val(), flightnumber: $("#flightnumber").val() } ,
				function(data) { 	
					if(data=="4") {
						window.top.location.href='./Search-Result';
					} else { 
						
						$('#form_login_load').css('visibility','hidden');
					}
				}
		);
		return false;
	});


	/* Auth Code */
	$("#authCode").bind('submit', function() {
		$('#form_login_load').css('visibility','visible');
		$.post("core/authCode.php", { authCode: $("#authCodeI").val() } ,
				function(data) { 	
					if(data=="1") {
						window.top.location.href='./';
					} else { 
						alert('Invalid code!');
						$('#form_login_load').css('visibility','hidden');
					}
				}
		);
		return false;
	});
	$('#authCodeOK').click(function() { $('#authCode').submit(); });
	$('#authCodeEXIT').click(function() { $.get("core/exit.php", function() { window.top.location.href="./"+$("#redirect").val(); }); });
	
	
	$("#link_sc1").click(function() {
		CB_Open('href=core/airportPopup.php?dest=dp_city,,width=450,,height=300,,closeonh=off,, ...'); 
		//document.getElementById("CB_CloseWindow").style.visibility = 'hidden';
		document.getElementById("CB_TG").style.visibility = 'hidden';		
	});
	$("#link_sc2").click(function() {
		CB_Open('href=core/airportPopup.php?dest=ar_city,,width=450,,height=300,,closeonh=off,, ...'); 
		//document.getElementById("CB_CloseWindow").style.visibility = 'hidden';
		document.getElementById("CB_TG").style.visibility = 'hidden';		
	});
	
	
	/* Select FLights */
	$('[id^=sel]').click(function() {
		id = this.id;
		idc = id.replace("sel","");
		flightid = $('#FlightId'+idc).val();
		action = $('#FlightIdAction'+idc).val();
		$(this).html('<img src="images/loading2.gif" border="0" >');
		$.post("core/setFlight.php", { flightid: flightid, action: action, arrayid: idc } ,
			function(data) {
				if(data=="1") {
					if(action == "add") {
						$('#FlightIdAction'+idc).val("del");
						$("#"+id).html('<img src="images/v.gif" border="0"> Selected');
					} else if(action == "del") {
						$('#FlightIdAction'+idc).val("add");
						$("#"+id).html('Select');
					}
				}
		});
	});
	
	/* Page notification bottom remove */
	$("[id^=remove_]").click( function() {
		id = this.id.replace("remove_","");
		$.post("core/setFlight.php", { flightid: id, action: "del" } ,
				function (data) {
					window.top.location.href = './Notification';
		});
	});
	
	$('[id^=earlyOpCK_]').click(function() { 
		id = this.id.replace("earlyOpCK_","");
		value = $(this).is(':checked');
		$.post("core/setCheckbox.php?a=earlyOpCK", { flightid: id, value: value } ,
				function(data) {
					return false;
					
		});
	});
	
	$('[id^=lateOpCK_]').click(function() { 
		id = this.id.replace("lateOpCK_","");
		value = $(this).is(':checked');
		$.post("core/setCheckbox.php?a=lateOpCK", { flightid: id, value: value } ,
				function(data) {
					return false;
					
		});
	});
	
	$('[id^=cancelOpCK_]').click(function() { 
		id = this.id.replace("cancelOpCK_","");
		value = $(this).is(':checked');
		$.post("core/setCheckbox.php?a=cancelOpCK", { flightid: id, value: value } ,
				function(data) {
					return false;
					
		});
	});
	
	$('[id^=arrivalOpCK_]').click(function() { 
		id = this.id.replace("arrivalOpCK_","");
		value = $(this).is(':checked');
		$.post("core/setCheckbox.php?a=arrivalOpCK", { flightid: id, value: value } ,
				function(data) {
					return false;
					
		});
	});
	
	$('[id^=idcontact_]').click(function() { 
		id = this.id.replace("idcontact_","");
		value = $(this).val();
		$.post("core/setCheckbox.php?a=idcontact", { flightid: id, value: value } ,
				function(data) {
					return false;
					
		});
	});
	
	/* Save notification */
	$('#saveNotification').click( function() {
		$.post("core/saveNotification.php", {  action: "del" } ,
				function (data) {
					$("#alert").addClass("alert_red");
					$("#alert li").html("OK, all notifications has been updated!");
					window.top.location.href = '#top';
		});		
	});
	

	
	/* Notification page */
	$("#accordion").accordion();

	$('[id^=startDate]').editable('core/setDate.php?a=startDate', {
	     type: 'datepicker',
	     tooltip: 'CLick to edit...',
	     event: 'click',
	     width: '90px',
	     style: 'inherit'
	});

	$('[id^=endDate]').editable('core/setDate.php?a=endDate', {
	     type: 'datepicker',
	     tooltip: 'CLick to edit...',
	     event: 'click',
	     width: '90px',
	     style: 'inherit'
	});
	 

	  $("[id^=earlyOp]").editable("core/setTime.php?a=earlyOp", { 
		    indicator : '<img src="images/loading2.gif">',
		    data   : "{'20 Min':'20 Min','40 Min':'40 Min','1 Hour':'1 Hour','2 Hours':'2 Hours','> 2 Hours':'> 2 Hours'}",
		    type   : "select",
		    submit : "OK",
		    style  : "inherit",
		    submitdata : function() {
		      
		    }
		 });

	  $("[id^=lateOp]").editable("core/setTime.php?a=lateOp", { 
		    indicator : '<img src="images/loading2.gif">',
		    data   : "{'20 Min':'20 Min','40 Min':'40 Min','1 Hour':'1 Hour','2 Hours':'2 Hours','> 2 Hours':'> 2 Hours'}",
		    type   : "select",
		    submit : "OK",
		    style  : "inherit",
		    submitdata : function() {
		      
		    }
		 });
	  
	  $("[id^=arrivalOp]").editable("core/setTime.php?a=arrivalOp", { 
		    indicator : '<img src="images/loading2.gif">',
		    data   : "{'20 Min':'20 Min','40 Min':'40 Min','1 Hours':'1 Hours','2 Hours':'2 Hours','3 Hours':'3 Hours'}",
		    type   : "select",
		    submit : "OK",
		    style  : "inherit",
		    submitdata : function() {
		     
		    }
		 });
	
	  /* User menu */

		$("#lkMyContact").click(function() {
			CB_Open('href=core/myContact.php?dest=dp_city,,width=690,,height=300,,closeonh=off,, ...'); 
			//document.getElementById("CB_CloseWindow").style.visibility = 'hidden';
			document.getElementById("CB_TG").style.visibility = 'hidden';		
		});

		/* Save page contacts */
		$("[id^=confirm_]").click(function() {
			// get the looping id
			id = this.id.replace("confirm_","");
			
			// get the id from db
			id_db_input = $("[id^=name__"+id+"]").attr("id");
			id_db = id_db_input.replace("name__"+id+"__","");
			//get the values
			name = $("[id^=name__"+id+"]").val();
			type = $("[id^=type__"+id+"]").val();
			content = $("[id^=content__"+id+"]").val();
			// validation
			if(name == "") {
				$("[id^=name__"+id+"__]").addClass("contact_p_al");
				$("[id^=name__"+id+"__]").focus();
			} else if(type == "email" && /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(content) == false) {
				$("[id^=name__"+id+"__]").removeClass("contact_p_al");
				$("[id^=content__"+id+"__]").addClass("contact_p_al");
				$("[id^=content__"+id+"__]").focus();		
			} else if(content == "") {
				$("[id^=name__"+id+"__]").removeClass("contact_p_al");
				$("[id^=content__"+id+"__]").addClass("contact_p_al");
				$("[id^=content__"+id+"__]").focus();	
			} else { 
				$("[id^=name__"+id+"__]").removeClass("contact_p_al");
				$("[id^=content__"+id+"__]").removeClass("contact_p_al");
				$.post("myContactSave.php?action=addContact", { id_db: id_db, name: name, type: type, content: content },
						function(data) { 
							window.location.reload();
					
				});
			}
		});
		/* Option del contact */
		$("[id^=del__]").click(function() {
			// get the id from db
			id_db = this.id;
			id_db = id_db.replace("del__","");
			if(confirm("Are you sure?")) { 
				$.post("myContactSave.php?action=delContact", { id_db: id_db },
						function(data) { 
							window.location.reload();
					
				});
			}
		});
		/* code inputy */ 
		$("[id^=code_]").click(function() { if($(this).val() == "Code...") { $(this).val(""); } });
		$("[id^=code_]").blur(function() { if($(this).val() == "") { $(this).removeClass("code_al"); $(this).val("Code..."); } });
		$("[id^=code_]").keyup(function(event) {
			id = this.id.replace("code_","");
			content = $(this).val();
			if(content.length == "4") {
				$(this).removeClass("code_al");
				$(this).addClass("code");
				code = $(this).val();
				$.post("myContactSave.php?action=valCode",{ code: code, id: id}, function(data) { 
					if(data == 1) {
						window.location.reload();
					} else if(data == 2) {
						$("#code_"+id).addClass("code_al");
					}
				});
			} else if(content.length > "4") {
				$(this).addClass("code_al");
			}
		});
		
		/* Validation BOX contact */
		$('#cssdropdown li.headlink').hover(
				function() { $('ul', this).css('display', 'block'); },
				function() { $('ul', this).css('display', 'none'); });

		/* Set mask by selected type contact */
		$("[id^=type__]").change(function() { 
			type = $("#"+this.id+" option:selected").val();
			id = this.id.replace("type__","");
			if(type == "email") {
				$("#content__"+id).unsetMask().val(''); 
				$("#content__"+id).focus();
			} else {
				$("#content__"+id).setMask("999-999-9999");  	
				$("#content__"+id).focus();  	
			}
		});
		

	
		/* LINK PAYMENT */
		$("#pay").click(function() {
			CB_Open('href=payment.php?action=pay,,width=780,,height=400,,closeonh=off,, ...'); 
			document.getElementById("CB_CloseWindow").style.visibility = 'hidden';
			document.getElementById("CB_TG").style.visibility = 'hidden';
		});

		/* Airlines dropdown */	
		function loadAirlines() {
			var _data = "";
			$.get("core/airlineSuggest.php",function(data) { 
				$('#dropDown_airline').dropdown({
				    items: eval(data) ,
				    itemClick: function(key, value, isChecked) {
						// get items and transform to string
						var contentString = JSON.stringify(this.items);
						var contentStringToJson = "";
						// change the content as selected
						if(isChecked == true) {
							contentStringToJson = contentString.replace(('{"key":"'+value+'","value":"'+key+'"}'),('{"key":"'+value+'","value":"'+key+'","isChecked":"true"}'));
						} else if(isChecked == false) {
							contentStringToJson = contentString.replace(('{"key":"'+value+'","value":"'+key+'","isChecked":"true"}'),('{"key":"'+value+'","value":"'+key+'"}'));
						}
						// set back 
						this.items = eval(contentStringToJson);
						
						if(isChecked == true) { action = "?action=add&value="+value; } else { action = "?action=del&value="+value; }
						$.get("core/airlineSuggest.set.php"+action, function(data) { 
							if(data > 0) {
								$('#dropDown_airline').html("You've selected <b>"+data+"</b> airline(s)");
							} else {
								$('#dropDown_airline').html("All Airlines");						
							}

							
						});
				    }
					
				});

			});
		}
		$('#dropDown_airline').click(function() {
			if($('#arrow').attr("src") == "images/down.png") {
				$('#arrow').attr("src","images/up.png");
			} else if($('#arrow').attr("src") == "images/up.png") {
				$('#arrow').attr("src","images/down.png");
			}
		});

		if($('#dropDown_airline').length == 1) {
			loadAirlines();
		}
	
		$("#dateBox1").editable('core/setDateBox.php?box=1', {
		     type: 'datepicker',
		     tooltip: 'Click to edit...',
		     event: 'click',
		     width: '90px',
		     style: 'inherit'
		});
		$("#dateBox2").editable('core/setDateBox.php?box=2', {
		     type: 'datepicker',
		     tooltip: 'Click to edit...',
		     event: 'click',
		     width: '90px',
		     style: 'inherit'
		});		


		$('span').hoverbox();
		
		/* If the user wants to import contacts */ 
		$('#import_msn').bind("click", function() {
			$("#imp_login").css("visibility","visible");
			$("#imp_from_label").html('"MSN"');
			$("#imp_from").val("msn");
		});
		$('#import_gmail').bind("click", function() {
			$("#imp_login").css("visibility","visible");
			$("#imp_from_label").html('"GMail"');
			$("#imp_from").val("gmail");
		});
		$('#import_linkedin').bind("click", function() {
			$("#imp_login").css("visibility","visible");
			$("#imp_from_label").html('"LinkedIN"');
			$("#imp_from").val("linkedin");
		});
		$('#import_yahoo').bind("click", function() {
			$("#imp_login").css("visibility","visible");
			$("#imp_from_label").html('"Yahoo"');
			$("#imp_from").val("yahoo");
		});
		$('#import_facebook').bind("click", function() {
			$("#imp_login").css("visibility","visible");
			$("#imp_from_label").html('"Facebook"');
			$("#imp_from").val("facebook");
		});
		$('#import_myspace').bind("click", function() {
			$("#imp_login").css("visibility","visible");
			$("#imp_from_label").html('"MySpace"');
			$("#imp_from").val("myspace");
		});
		
		/* Submit import contacts */
		$("#imp_submit").bind("click", function() {
			$("#imp_result").html("<img src='../images/loading.gif'>");
			imp_from = $("#imp_from").val();
			imp_email = $("#imp_email").val();
			imp_password = $("#imp_password").val();
			$.post("importContact.php",{
				imp_from: imp_from, imp_email: imp_email, imp_password: imp_password
			},function(data) {
				result = $("#imp_result").load("importContact.results.php");
			});
		});
		


		
});

function reloadPayLink() {
	CB_Open('href=payment.php?action=pay,,width=780,,height=400,,closeonh=off,, ...'); 
	document.getElementById("CB_CloseWindow").style.visibility = 'hidden';
	document.getElementById("CB_TG").style.visibility = 'hidden';		
}

// Open Map real status
function openMap(map_url,sdep_time,sarr_time,rdep_time,rarr_time,dep_gate,arr_gate) {
	CB_Open('href=core/trackRealTime.php?map='+map_url+'&sdep_time='+sdep_time+'&sarr_time='+sarr_time+'&rdep_time='+rdep_time+'&rarr_time='+rarr_time+'&dep_gate='+dep_gate+'&arr_gate='+arr_gate+',,width=505,,height=425,,closeonh=off,, ...'); 
	//document.getElementById("CB_CloseWindow").style.visibility = 'hidden';
	document.getElementById("CB_TG").style.visibility = 'hidden';		
}


