// JavaScript Document
$().ready(
	function()
	{
		textInit();
		gsug.setInputObj($('#frm_ticketsearch').find('input[@id="departure"]')[0]);
		gsug.setInputObj($('#frm_ticketsearch').find('input[@id="arrival"]')[0]);
		//k();
	}
);

function k(){
	var o=navigator.appName;
	var r=navigator.appVersion;
	var n=r.split(";");
	var p=n[1].replace(/[ ]/g,"");
	if(top.location!=self.location){
		alert("欢迎使您来到“天顺游易”旅行网(Qunar.com)!\n请您注意：“天顺游易”旅行网的正确拼写是：www.cntsyy.com\n其他任何域名，都是非正规的来源");
		top.location=self.location;
	}
}


function change_flightway(flightway){
	switch (flightway){
	case 2:
		apsug.isInternational = false;
		apdata = apdata_gn;
		
		$("#hot_city_popup").html($("#airplane_city").html());
		$("#searchtype").val(flightway);
		$("#frm_ticketsearch").attr("action","/jipiao/redirect.php");
		onInitCookies();
		break;
	case 1:
		apsug.isInternational = true;
		apdata = apdata_gj;
		$("#hot_city_popup").html($("#airplane_city_oversea").html());
		if (__CITY_TARGET=='d'){
			$('#hot_city_popup').find('div[@id="hot_city_end"]').css('display','none');
			$('#hot_city_popup').find('div[@id="hot_city_start"]').css('display','');
		}
		if (__CITY_TARGET=='a'){
			$('#hot_city_popup').find('div[@id="hot_city_end"]').css('display','');
			$('#hot_city_popup').find('div[@id="hot_city_start"]').css('display','none');
		}
		$("#searchtype").val(flightway);
		$("#frm_ticketsearch").attr("action","/jipiao/redirect.php");
		change_searchtab("#frm_ticketsearch");
		$("#frm_ticketsearch").find('.Switch_botton_a').attr('class','');
		$("#frm_ticketsearch").find('#radio_search1').attr('class','Switch_botton_a');
		onInitCookies_overSea()
		break;
	}	
}

function Submit_()
{
	//var form = document.sjipiao;
	var date = $("#startdate").val();
	if (date=="") {
		alert("日期不能为空");
		return false;
	}
	if(!onUrl($("#departure").val(),$("#arrival").val()))
	{
		if(window.event){
			window.event.returnValue = false;
		}
		return false;
	}
	return true;
}

//code by wangye 09-7-6 主页特价机票JQ的控制
//var city_id = "";
function get_ticketMsg(originalRequest, mode, city_id) {
	var newData = originalRequest.responseText;
//	alert( newData  ) ;
	if ( 'guoneitejia' == mode  )	
	{
		if( newData  != null)
		{
			$('.content').hide();
			$('.content#'+city_id).html(newData);
			$('.content#'+city_id).show();
		}
		else
		{
			return false ; 
		}
	}
	else if( 'guojitejia' == mode || '2' == mode )
	{
		if( newData  != null)
		{
			$('.content_guoji').hide();
			$('.content_guoji#'+ city_id).html(newData);
			$('.content_guoji#'+ city_id).show();
		}
		else
		{
			return false ; 
		}
	}
}


function show_ticketMsg(tkt_id, mode)
{
var city_id = tkt_id;

	switch (mode){
		case 1:
			if ($('.content#'+city_id).html()){
				$('.content').hide();
				$('.content#'+ city_id).show();
				return;
			}
			break;
		case 2:
			if ($('.content_guoji#'+city_id).html()){
				$('.content_guoji').hide();
				$('.content_guoji#'+ city_id).show();
				return;
			}
			break;
	}
    var sURL = "/jipiao/ajax_test.php";
	var rand = Math.random( 9999 );

	var pars = 'id=' + tkt_id + '&mode=' + mode + '&rand=' + rand;
	$.ajax({
		url: sURL +"?"+ pars,
		type: 'GET',
		dataType: 'html',
		error: function(){
		//	alert('error');
		return null;
		},
		beforeSend:function(){
			switch (mode){
				case 1:
					$('.content').hide();
					$('.content#'+city_id).html("<img src='/images/cntsyy/ico_loading3.gif' />请稍候,数据正在加载中...");
					$('.content#'+city_id).show();
					break;
				case 2:
					$('.content_guoji').hide();
					$('.content_guoji#'+city_id).html("<img src='/images/cntsyy/ico_loading3.gif' />请稍候,数据正在加载中...");
					$('.content_guoji#'+city_id).show();
					break;
			}
		},
		complete:function(XMLHttpRequest, textStatus) {
			if (XMLHttpRequest!=null) {
				switch (mode){
					case 1:
						$('.content#'+city_id).html("");
						break;
					case 2:
						$('.content_guoji#'+city_id).html("");
						break;
					default:
						$('.content#'+city_id).html("");
						$('.content_guoji#'+city_id).html("");
						break ; 
				}
				get_ticketMsg(XMLHttpRequest, mode, city_id);
			}
		}
	});
}

function show_ticketData(tkt_id, mode)
{
	var city_id = tkt_id;
	switch (mode){
		case 'guoneitejia':
			if ($('.content#'+city_id).html()){
				$('.content').hide();
				$('.content#'+ city_id).show();
				return;
			}
			break;
		case 'guojitejia':
			if ($('.content_guoji#'+city_id).html()){
				$('.content_guoji').hide();
				$('.content_guoji#'+ city_id).show();
				return;
			}
			break;
	}
    var sURL = "/do/ticket_cache_pro.php";
	var rand = Math.random( 9999 );

	var pars = 'code_id=' + tkt_id + '&type=' + mode + '&rand=' + rand;
	$.ajax({
		url: sURL +"?"+ pars,
		type: 'GET',
		dataType: 'html',
		error: function(){
		//	alert('error');
		return null;
		},
		beforeSend:function(){
			switch (mode){
				case 'guoneitejia':
					$('.content').hide();
					$('.content#'+city_id).html("<img src='/images/cntsyy/ico_loading3.gif' />请稍候,数据正在加载中...");
					$('.content#'+city_id).show();
					break;
				case 'guojitejia':
					$('.content_guoji').hide();
					$('.content_guoji#'+city_id).html("<img src='/images/cntsyy/ico_loading3.gif' />请稍候,数据正在加载中...");
					$('.content_guoji#'+city_id).show();
					break;
			}
		},
		complete:function(XMLHttpRequest, textStatus) {
			if (XMLHttpRequest!=null) {
				switch (mode){
					case 'guoneitejia':
						$('.content#'+city_id).html("");
						break;
					case 'guojitejia':
						$('.content_guoji#'+city_id).html("");
						break;
					default:
						//$('.content#'+city_id).html("");
						//$('.content_guoji#'+city_id).html("");
						break ; 
				}
				get_ticketMsg(XMLHttpRequest, mode, city_id);
			}
		}
	});
}





//code by wangye 09-7-20 国际查询页头等公务学生仓的AJAX请求

function get_ticketMsg_head(originalRequest, mode, city_id) {
	var newData = originalRequest.responseText;
//	alert( city_id ) ;
	if ( 'guoji_son' == mode  )	
	{
		if( newData  != null)
		{
			$('.content_son').hide();
			$('.content_son#'+city_id).html(newData);
			$('.content_son#'+city_id).show();
		}
		else
		{
			return false ; 
		}
	}
	
}
function show_head(tkt_id, mode )
{
	var city_id = tkt_id;
	switch (mode){
		case 'guoji_son':
			if ($('.content_son#'+city_id).html()){
				$('.content_son').hide();
				$('.content_son#'+ city_id).show();
				return;
			}
			break;
	}
    sURL = "/do/ticket_cache_pro.php";
	var rand = Math.random( 9999 );
	var pars = 'code_id=' + tkt_id + '&type=' + mode + '&rand=' + rand;
	$.ajax({
		url: sURL +"?"+ pars,
		type: 'GET',
		dataType: 'html',
		error: function(){
			return null ;
		},
		beforeSend:function(){
			switch (mode){
				case 'guoji_son':
					$('.content_son').hide();
					$('.content_son#'+city_id).html("<img src='/images/cntsyy/ico_loading3.gif' />请稍候,数据正在加载中...");
					$('.content_son#'+city_id).show();
					break;
				
			}
		},
		complete:function(XMLHttpRequest, textStatus) {
			if (XMLHttpRequest!=null) {
				switch (mode){
					case 'guoji_son':
						$('.content_son#'+city_id).html("");
						break;
				
					default:
						break ; 
				}
				get_ticketMsg_head(XMLHttpRequest, mode, city_id);
			}
		}
	});
}


//code by wangye 09-7-21 可申请AJAX
function show_policy( tkt_id, mode )
{
	var city_id = tkt_id;
	switch (mode)
	{
		case 'isapply':
			if ($('.content_policy#'+city_id).html()){
				$('.content_policy').hide();
				$('.content_policy#'+ city_id).show();
				return;
			}
			break;
		
	}
    sURL = "/do/ticket_cache_pro.php";
	var rand = Math.random( 9999 );
	var pars = 'code_id=' + tkt_id + '&type=' + mode + '&rand=' + rand;
	$.ajax({
		url: sURL +"?"+ pars,
		type: 'GET',
		dataType: 'html',
		error: function(){
			return null ;	
		},
		beforeSend:function(){
			switch (mode){
				case 'isapply':
					$('.content_policy').hide();
					$('.content_policy#'+city_id).html("<img src='/images/cntsyy/ico_loading3.gif' />请稍候,数据正在加载中...");
					$('.content_policy#'+city_id).show();
					break;
			}
		},
		complete:function(XMLHttpRequest, textStatus) {
			if (XMLHttpRequest!=null) {
				switch (mode){
					case 'isapply':
						$('.content_policy#'+city_id).html("");
						break;
				
				}
				get_policy(XMLHttpRequest, mode, city_id);
			}
		}
	});
}
function get_policy(originalRequest, mode, city_id)
{
	var newData = originalRequest.responseText;
	if ( 'isapply' == mode  )	
	{
		if( newData  != null)
		{
			$('.content_policy').hide();
			$('.content_policy#'+city_id).html(newData);
			$('.content_policy#'+city_id).show();

		}
		else
		{
			return false ; 
		}
	}
	
}


//code by wangye 09-7-12 航空公司专题AJAX
function show_airways( tkt_id, mode )
{
	
	var city_id = tkt_id;
	switch (mode)
	{
		case 'airways':
			if ($('.content_airways#'+city_id).html()){
				$('.content_airways').hide();
				$('.content_airways#'+ city_id).show();
				return;
			}
			break;
	}
    sURL = "/do/ticket_cache_pro.php";
	var rand = Math.random( 9999 );
	var pars = 'code_id=' + tkt_id + '&type=' + mode + '&rand=' + rand;
	$.ajax({
		url: sURL +"?"+ pars,
		type: 'GET',
		dataType: 'html',
		error: function(){
//			alert('error');
			return null ;	
		},
		beforeSend:function(){
			switch (mode){
				case 'airways':
					$('.content_airways').hide();
					$('.content_airways#'+city_id).html("<img src='/images/cntsyy/ico_loading3.gif' />请稍候,数据正在加载中...");
					$('.content_airways#'+city_id).show();
					break;
			}
		},
		complete:function(XMLHttpRequest, textStatus) {
			if (XMLHttpRequest!=null) {
				switch (mode){
					case 'airways':
						$('.content_airways#'+city_id).html("");
						break;
				}
				get_airways(XMLHttpRequest, mode, city_id);
			}
		}
	});
}
function get_airways(originalRequest, mode, city_id)
{

	var newData = originalRequest.responseText;
	//alert(newData);
	if ( 'airways' == mode  )	
	{
		if( newData  != null)
		{
			$('.content_airways').hide();
			$('.content_airways#'+city_id).html(newData);
			$('.content_airways#'+city_id).show();
		}
		else
		{
			return false ; 
		}
	}
}

//控制往返链接的
function set_flightwaytype(city_pinyin, mode){
	if( 1 == mode )
	{
//		alert(mode); 
		$("#oneway_flight").attr("href",$("#oneway_flight").attr("oldurl") + city_pinyin + ".html") ;
		$("#roundtrip_flight").attr("href",$("#roundtrip_flight").attr("oldurl") + city_pinyin + ".html");
	}
	else if( 2 == mode )
	{
		$("#NSf_Son").find("#oneway_flight").attr("href",  city_pinyin + "/single.html") ;
		$("#NSf_Son").find("#roundtrip_flight").attr("href", city_pinyin + "/double.html");
	}
	
}
//控制首页国际机票信息展示以及往返的
function guoji_click(){
	var obj_link = $('#Isf').find('a[@class="guoji_link"]');
	for (var i=0;i<obj_link.length;i++){
		obj_link.eq(i).bind('click',function(){
			set_flightwaytype($(this).attr('alt'), 1);
			show_ticketData($(this).attr('flag'), "guojitejia");
		});
	}
}
//国际子页面
function guoji_son_click(){
	var obj_link = $('#NSf_Son').find('a[@class="guoji_link"]');
	for (var i=0;i<obj_link.length;i++){
			obj_link.eq(i).bind('click',function(){
			set_flightwaytype($(this).attr('alt'), 2);
			show_head($(this).attr('flag'), "guoji_son");
		});
	}
}





function show_policy_max( tkt_id, mode )
{
	var city_id = tkt_id;
	switch (mode)
	{
		case 'maxisapply':
			if ($('.content_policy_max#'+city_id).html()){
				$('.content_policy_max').hide();
				$('.content_policy_max#'+ city_id).show();
				return;
			}
			break;
		
	}
    sURL = "/do/ticket_cache_pro.php";
	var rand = Math.random( 9999 );
	var pars = 'code_id=' + tkt_id + '&type=' + mode + '&rand=' + rand;
	$.ajax({
		url: sURL +"?"+ pars,
		type: 'GET',
		dataType: 'html',
		error: function(){
			return null ;	
		},
		beforeSend:function(){
			switch (mode){
				case 'maxisapply':
					$('.content_policy_max').hide();
					$('.content_policy_max#'+city_id).html("<img src='/images/cntsyy/ico_loading3.gif' />请稍候,数据正在加载中...");
					$('.content_policy_max#'+city_id).show();
					break;
			}
		},
		complete:function(XMLHttpRequest, textStatus) {
			if (XMLHttpRequest!=null) {
				switch (mode){
					case 'maxisapply':
						$('.content_policy_max#'+city_id).html("");
						break;
				
				}
				get_policy_max(XMLHttpRequest, mode, city_id);
			}
		}
	});
}
function get_policy_max(originalRequest, mode, city_id)
{
	var newData = originalRequest.responseText;
	if ( 'maxisapply' == mode  )	
	{
		if( newData  != null)
		{
			$('.content_policy_max').hide();
			$('.content_policy_max#'+city_id).html(newData);
			$('.content_policy_max#'+city_id).show();

		}
		else
		{
			return false ; 
		}
	}
	
}