var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
var IE7 = false /*@cc_on || @_jscript_version == 5.7 @*/;  // exactly IE7
var gteIE7 = false /*@cc_on || @_jscript_version >= 5.7 @*/; // IE7+
var isMSIE = /*@cc_on!@*/false; // any IE

//added new function start
function modifySelected(value)
{
	res=value.match(/^([^,]+),.+(\[.+\])/);
	if (res){
		if (res.length == 3){
			value=res[1]+' '+res[2];
		}
	}
	return value;
}
//added new function end

function show_progress_bar()
{
	
	$('#form_center_id').hide();
	//$('.center').hide();
	$('#result-area').html('<div class="align-center"><div class="bigspacer">Flygbokaren s&ouml;ker nu igenom ett stort antal resebyr&aring;er och flygbolag f&ouml;r att hitta b&auml;sta pris, detta kan ta 2 min.<br /><img  src="img/facebox/loading.gif"/></div></div>');
}


function show_comments()
{
	$('#hidden_comm').toggle();
	return false;
}

function show_comment_form()
{
	$('#cform').show();
	$('#comm_form a').hide();
	$('#cmform').ajaxForm({
		url:'/test/engine/newcomment.php',
		type:'POST',
		success: function(response){
			$('#comm_form').after(response);
			$('#comm_form a').show();
			$('#cform').hide();
			$('textarea').val('');
		}
	});
	return false;
}

function submit_form(fid,datefrm,dateto,from,to,adults,childs,child_ages)
{
	
	$('#form_center_id').hide();
	show_progress_bar();
		//$('.center').hide();
	var j=fid-1;
	$.ajax({
		 url:"engine/getflights.php",
		 data:"datefrm="+datefrm+"&dateto="+dateto+"&from="+from+"&to="+to+"&adults="+adults+"&childs="+childs+"&childs_ages="+child_ages+"&dayout="+datefrm+"&dayin="+dateto+"&fid="+fid,

  		 success: function(data){
	
					$('#result-area').html(data);

			}	
		});

	

}

$(document).ready(function()
{	
$('#vingsform').ajaxForm({
				 
		beforeSubmit: show_progress_bar,
		target: '#result-area',
		success: function(){
 		if (isMSIE){

			if (! IE6){
				$('div.result').mouseover( function(){
					$(this).addClass('result-hover');
				}
				).mouseout( function(){
					$(this).removeClass('result-hover');
				}
				);
			}
			if (! IE7){
				$('div.row').mouseover( function(){
					$(this).addClass('hover');
				}
				).mouseout( function(){
					$(this).removeClass('hover');
				}
				);
			}
		}
			
			_submit();

		}
	});

	$('#flightform').ajaxForm({
							 
		beforeSubmit: show_progress_bar,
		target: '#result-area',
		success: function(){
		if($(".andra-sokning")!=null){	
		$(".andra-sokning").click(function(){
		$('#form_center_id').show();
		//$('.center').hide();
	
							               });
		}
		if (isMSIE){

			if (! IE6){
				$('div.result').mouseover( function(){
					$(this).addClass('result-hover');
				}
				).mouseout( function(){
					$(this).removeClass('result-hover');
				}
				);
			}
			if (! IE7){
				$('div.row').mouseover( function(){
					$(this).addClass('hover');
				}
				).mouseout( function(){
					$(this).removeClass('hover');
				}
				);
			}
		}
		
			_submit();
		}
	});
	$('#from_input').autocomplete('/engine/autocomplete.php',{maxItemsToShow:20,width:630,delay:10,minChars:2,matchSubset:1,matchContains:1,cacheLength:10});
	$('#to_input').autocomplete('/engine/autocomplete.php',{maxItemsToShow:20,width:630,delay:10,minChars:2,matchSubset:1,matchContains:1,cacheLength:10});

});

