var base_url = location;

function getAirportCode(objInput){
	
	
	$.get(
			'/ajax/getAirportCode.php', 
			{
				city:objInput.value
				
			},
			function(r){
					
					var codes = r.split('\n');				
					var str = '';
					
					//if(codes.length < 0) return;	
					
					for( i = 0; i < codes.length; i++ ){
						try{
							c = json_parse(codes[i]);
							if(c.heading) {
								str += '<h2>' + c.heading + '</h2>';
							}
							if(c.city) {
								str += '<a href="#" onclick="$(\'#'+objInput.id+'\').val(\''+c.code+'\');return false">' + c.code + ' - ' + c.name + ' ('+ c.city + ', ' + c.country + ')</a><br />';
							}
						}
						
						catch(e){
						}

					}
					
					if(str != '') $('#'+objInput.name+'-result').html(str).show();
			}
		);
}

function getAirlineCode(objInput){
	
	
	$.get(
			'/ajax/getAirlineCode.php', 
			{
				name:objInput.value
				
			},
			function(r){
					
					var codes = r.split('\n');
					if(codes.length < 0) return;
					var str = '';

					for( i = 0; i < codes.length; i++ ){
						try{
							c = json_parse(codes[i]);
							if(c.code) {
								str += '<a href="#" onclick="$(\'#'+objInput.id+'\').val(\''+c.code+' ('+ c.name +') \');return false">' + c.name + '</a><br />';
							}
						}
						
						catch(e){
						}

					}

					if(str != '') $('#'+objInput.id+'-result').html(str).show();
			}
		);
}

function validateFlightsForm(){
	var checks = $('#flights-form input[type=checkbox].flight-backup');
	var radios = $('#flights-form input[type=radio]');

	var checked = 0;
	for(var c=0;c < checks.length;c++){
		checked = (checks[c].checked) ? checked+1 : checked; 
	}

	var pri = 0;
	for(var c=0;c < radios.length;c++){
		pri = (radios[c].checked) ? pri+1 : pri; 
	}

	if(checked > 2) {
		alert('You may only choose up to two backup flights.');
		return false;
	}
	
	if(pri < 1){
		alert('Please choose at least one primary flight.');
		return false;
	}

	return true;	
}

function validateAccountForm(){
	var valid = false;

	return valid;
}

function testAjax(){
	alert(AJAX_SCRIPT_PATH);
}

function addToSelectedFlights(flight){
	
}

function showStatusDescription(obj){
	$(obj).slideToggle();
}

function getFlightStatusOld(obj){
	var url = AJAX_SCRIPT_PATH + 'getFlightStatus.php';
	$.get(
		url,
		obj
		,
		function(r){
			var st_class = r.toLowerCase();
			$('#'+obj.node).addClass('status-'+ st_class);
			$('#'+obj.node).html(r);
		}
	);
}

function getFlightStatus(obj){ 
	return;
	var url = AJAX_SCRIPT_PATH + 'getFlightStatus.php';
	
	var nodes = $('.flight-status-span');
	$.get(
		url,
		obj
		,
		function(r){

			var response = json_parse(r);
			for ( i = 0; i < nodes.length; i++ ) {
				try {
					c = legs[i].code + legs[i].flight_no;					
					$('.status-' + c).html(response[c].status).addClass('status-'+ response[c].status.toLowerCase());
				} catch(e){
					//pass
				}
			}

		}
	);
}

function getFlightStatusX(obj){ 

	var url = AJAX_SCRIPT_PATH + 'getFlightStatus.php';
	
	var nodes = $('.flight-status-span');
	$.get(
		url,
		obj
		,
		function(r){

			var response = json_parse(r);
			for ( i = 0; i < nodes.length; i++ ) {
				try {
					c = legs[i].code + legs[i].flight_no;					
					$('.status-' + c).html(response[c].status).addClass('status-'+ response[c].status.toLowerCase());
				} catch(e){
					//pass
				}
			}

		}
	);
}

function showZedFares(id){
	$('#t-'+id).qtip(
			{
				content:$('#zedfares-'+id).html(), 
				style: { 
					background:'#fff',
					color:'#333',
					name:'cream', 
					tip:true, 
					padding:'10px 0',
					width:'auto',
					'max-width':'140px',
					'text-align':'right',
					border: { 
						color:'#009'
						} 
					}, 
				position: { 
					corner: { 
						target: 'rightMiddle', 
						tooltip: 'leftMiddle' 
					} 
				} 
			}
		);
		
//		$('#t-'+rate_id).qtip('api');

}

$(document).ready(function(){
	$(".scroll").click(function(event){
		//prevent the default action for the click event
		event.preventDefault();

		//get the full url - like mysitecom/index.htm#home
		var full_url = this.href;

		//split the url by # and get the anchor target name - home in mysitecom/index.htm#home
		var parts = full_url.split("#");
		var trgt = parts[1];

		//get the top offset of the target anchor
		var target_offset = $("#"+trgt).offset();
		var target_top = target_offset.top;

		//goto that anchor by setting the body scroll top to anchor top
		$('html, body').animate({scrollTop:target_top}, 500);
	});
});






