﻿var lock=false;	//全局锁
var global=Object();
//global.MainMenuTop		//初始化时的主菜单top
global.CurrentHref=location.href;	//当前页地址
global.DomainName=global.CurrentHref.replace(/^(http:\/\/[^\/]*)(.*)/ig,'$1');	//本站域名（含http://前缀）



//$('#MB,.MainMenu').corner("8px hiddenParent");

//	$('.dropshadow').dropShadow({left:0,top:0,blur:3,opacity:0.5});

//	$(".MBcolumn").sortable({
//		connectWith: ['.MBcolumn'],
//		handle: '.title'
//	});
	init_QKSearch();
	


/*
//############################## 网站主菜单动画 开始 #####################################3

	//点击动画
	global.MainMenuTop=$('.MainMenu:first').offset().top+document.documentElement.scrollTop;	//得到初始化时的主菜单top
	global.MainMenuWidth=$('.MainMenu:first').width();	//主菜单宽度
	global.pagebodyWidth=$('#pagebody').width();	//pagebody宽度
	
	$(window).bind('resize',resetMainMenuXY);
	
	resetMainMenuXY();
	
	$('.MainLink').css('float','left');	//解决Firefox下 float:left 执行 offset().top 结果不正确的问题
	
	var MB_MgTopDivID='pppd';
	$('#MB').before('<div id="'+MB_MgTopDivID+'" style="height:0px;overflow:hidden"></div>');
	
	init_MainMenu();
	
	init_Href();
//############################## 网站主菜单动画 结束 #####################################3
*/

//搜索窗口初始化
function init_QKSearch(){
	//机票搜索Tabs
	var tbi=0,url=(location.href).toLowerCase();
	if(url.replace(/(searchi\.asp|flighti)/,'')!=url)tbi=1;
	$("#QKSearch").tabs({ selected: tbi });


	//在线客服
//	if(typeof(IM_isOnline)!='undefined'  && $ID('IM_Icon_0')!=null){
//		if(IM_isOnline){
//			$ID('IM_Icon_0').innerHTML='<a '+IM_newChatWin('rrr','客服人员在线,欢迎点击咨询')+'><img src="http://aaa.1860.cn/images/floatimg/online_cn.gif" border="0"></a>';
//		}else{
//			$ID('IM_Icon_0').innerHTML='<a '+IM_newChatWin('rrr','客服人员不在线,请点击留言')+'><img src="http://aaa.1860.cn/images/floatimg/offline_cn.gif" border="0"></a>';
//		}
//	}
/*	window.onscroll=function(){
		var o=$('#OnlineServerIco');
		var st=document.documentElement.scrollTop;
		if((o.position().top+st)<$('#MB').height()){
			o.css('margin-top',(5+st));
		}
	};
*/	
	//国内 - 搜索窗口中的自动完成	# 出发城市/目的城市
	$tmp=$('form[name=SearchD] input[name=SC],form[name=SearchD] input[name=DC],form[name=SearchD] input[name=DC2]');
	$tmp.autocomplete(FltD_Cities, {
		minChars: 0,
		width: 160,
		matchContains: true,
//		autoFill: true,
		mustMatch:true,
		formatItem: function(row, i, max) {
			return row[0] + "	[" + row[3] + "]";
		},
		formatMatch: function(row, i, max) {
			return row[0] + "|" + row[1] + "|" + row[2] + "|" + row[3];
		},
		formatResult: function(row) {
			return row[3];
		}
	});
	$tmp.result(function(event, data, formatted) {
		var $form=$($(this).parents('form')[0]);
		if(data){$form.find('input[name='+this.name+'ID]').val(data[4])}
	});
	
	//国际 - 搜索窗口中的自动完成	# 出发城市
	$tmp=$('form[name=SearchI] input[name=SC]');
	$tmp.autocomplete(FltI_From, {
		minChars: 0,
		width: 160,
		matchContains: true,
//		autoFill: true,
		mustMatch:true,
		formatItem: function(row, i, max) {
			return row[0] + "	[" + row[3] + "]";
		},
		formatMatch: function(row, i, max) {
			return row[0] + "|" + row[1] + "|" + row[2] + "|" + row[3];
		},
		formatResult: function(row) {
			return row[3];
		}
	});
	$tmp.result(function(event, data, formatted) {
		var $form=$($(this).parents('form')[0]);
		if(data){$form.find('input[name='+this.name+'ID]').val(data[4])}
	});

	//国际 - 搜索窗口中的自动完成	# 目的城市
	$tmp=$('form[name=SearchI] input[name=DC]');
	$tmp.autocomplete(FltI_To, {
		minChars: 0,
		width: 160,
		matchContains: true,
//		autoFill: true,
		mustMatch:true,
		formatItem: function(row, i, max) {
			return row[0] + "	[" + row[3] + "]";
		},
		formatMatch: function(row, i, max) {
			return row[0] + "|" + row[1] + "|" + row[2] + "|" + row[3];
		},
		formatResult: function(row) {
			return row[3];
		}
	});
	$tmp.result(function(event, data, formatted) {
		var $form=$($(this).parents('form')[0]);
		if(data){$form.find('input[name='+this.name+'ID]').val(data[4])}
	});


	//机票搜索窗口 - 日期选择器
	$('input[name=DOS],input[name=DOB]').datepicker({
		numberOfMonths:2,
//		closeText: '关闭',
//		prevText: '&#x3c;上月',
//		nextText: '下月&#x3e;',
//		currentText: '今天',
//		monthNames: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
//		monthNamesShort: ['一','二','三','四','五','六','七','八','九','十','十一','十二'],
//		dayNames: ['星期日','星期一','星期二','星期三','星期四','星期五','星期六'],
//		dayNamesShort: ['周日','周一','周二','周三','周四','周五','周六'],
//		dayNamesMin: ['日','一','二','三','四','五','六'],
		dateFormat: 'yy-mm-dd',
		firstDay: 1,
		duration:0,
		minDate: 0,
		isRTL:false
	});


	//搜索窗口中的单选框（模拟）
	$('span[forRadio]').bind('click',Myradio_Click).css('cursor','pointer').bind('click',flushQSearchF);
	

	init_InputTips();
	
	$('span[forRadio]').each(function(){
							var $form=$($(this).parents('form')[0]);
							if(this.value==$form.find('input[name='+this.forRadio+']').val()){$(this).trigger('click')}});
}








//初始化文本框默认值提示
function init_InputTips(){
	var $form=$('form');
	$('input[tip_value]').each(function(){
								if(this.value!=this.getAttribute('tip_value') && this.value!=''){
									$(this).removeClass('tip_value')
								}else{
									$(this).addClass('tip_value');this.value=this.getAttribute('tip_value');
								}
							});
	$('input[tip_value]').bind('blur',function(){if(this.value==''){$(this).addClass('tip_value').val(this.getAttribute('tip_value'))}});
	$('input[tip_value]').bind('focus',function(){if(this.value==this.getAttribute('tip_value'))$(this).removeClass('tip_value').val('');});
	$('input[tip_value]').bind('change',function(){if(this.value!=this.getAttribute('tip_value') && this.value!=''){$(this).removeClass('tip_value')}});
}


//模拟的单选按钮
function Myradio_Click(){
	var $form=$($(this).parents('form')[0]);
	var n=$(this).attr('forRadio'),t=this.tagName;
	$form.find('input[name='+n+']').val(this.getAttribute('value'));
	$form.find(t+'[forRadio='+n+']').attr('className','');
	$(this).attr('className','radioChecked')
}

function flushQSearchF(){
	var $form=$($(this).parents('form')[0]);
	var FW=$form.find('input[name=FW]').val();//航程类型
	if($form.attr('name')=='SearchD'){	//国内
		if(FW=='D'){//往返
			$form.find('.DOB').show();
			$form.find('.DOB_Tag').html('Return date:');
			$form.find('.DCID2').hide();
		}else if(FW=='S'){	//单程
			$form.find('.DOB').hide();
			$form.find('.DCID2').hide();
		}else if(FW=='M'){	//联程
			$form.find('.DOB').show();
			$form.find('.DOB_Tag').html('Depart:');
			$form.find('.DCID2').show();
		}
	}else{	//国际
		if(FW=='D'){//往返
			$form.find('.DOB').show();
			$form.find('.DOB_Tag').html('Return：');
			$form.find('.DCID2').hide();
		}else if(FW=='S' || FW=='O'){	// 单程 / 往返（返程open）
			$form.find('.DOB').hide();
		}
	}
}


//国内机票搜索表单检查（串行化提交）
function CF_Search(FName){
	var FName;
	var $form=$('form[name='+FName+']');
	var obj=$form.find('input[type!=button][type!=submit],select');
	var para='';
	for(var i=obj.length-1;i>=0;i--){
		if(obj[i].value=='' || obj[i].value==obj[i].getAttribute('tip_value'))continue;
		para+=obj[i].getAttribute('name')+'='+Urlencoding(obj[i].value)+'&';
	}
	location.href=$form.attr('action')+'?'+rtrimVBcrlf(para,'&');
	return false;
}


//保存查询最低票价结果
function SearchD_SaveRt(MinPrice,MinDiscount){
	var MinPrice,MinDiscount;
	var data="action=SearchD_SaveRt&SearchUrl="+Urlencoding(location.href)+'&MinPrice='+Urlencoding(MinPrice)+'&MinDiscount='+Urlencoding(MinDiscount);
	$.get('Ajax_ServerSide.asp?'+data)
}

/*


//初始化主导航菜单 方法、事件
function init_MainMenu(){
	var $MainMenu=$('.MainMenu'),href='',$a;
	for(var i=$MainMenu.length-1;i>=0;i--){
		$m=$($MainMenu[i]);
		
			$a=$m.find('.MainLink a');
			href=$a.attr('href');
			eval("$m.find('.MainLink').bind('click',function(){changeChannel('"+href+"',this.parentNode);})");
			
			$a.hide();
			$a[0].parentNode.innerHTML+=$a.html();

			$m.find('ul[className=Nav]')
				.addClass('lavaLampWithImage')
				.height($m.height())
				.css('float','right');

//			$m.find('div[name=MainLink]').mouseover(function(){$(this.parentNode).animate({width:'+=6px'},150)});
//			$m.find('div[name=MainLink]').mouseout(function(){$(this.parentNode).animate({width:'-=6px'},150)});
	}
}


//主菜单按DOM顺序运动排序
function animateMMSort(onFinish){
	var $MainMenu=$('.MainMenu');
	for(var i=$MainMenu.length-1;i>=0;i--){
		$m=$($MainMenu[i]);
		//主菜单位置初始化
		$m.animate({top:global.MainMenuTop+(32*i)+'px'},'slow',function(){if(onFinish)onFinish()});
	}
}


//调整主菜单位置
function resetMainMenuXY(){
	var pbXY=$('#pagebody').position();
	var mm=$('.MainMenu');
	var st=document.documentElement.scrollTop;
	for(var i=mm.length-1;i>=0;i--){
		var tp=$(mm[i]).offset().top;
		$(mm[i]).css({
		   position:'absolute',
		   left:pbXY.left,
		   top:$(mm[i]).css('top')
		   })
		if($(mm[i]).css('top')=='auto'){
			$(mm[i]).css('top',tp+st);
		}
	}
}


//初始化链接 将链接变成Ajax的
function init_Href(){
	$('a[href][target!=_blank][exclude!=true]').each(function(){
								var href=this.href.toLowerCase();
								if(href.indexOf('javascript:')!=0
									&& ltrimVBcrlf(href,global.DomainName)!=href){
									$(this)
										.attr('oldHref',this.href)
										.attr('href','javascript:getHref("'+this.href+'");');
								}
							});
}

//切换一级频道
function changeChannel(href,t){
	var href,t;

	if($(t).attr('focus')=="1")return;	//当前栏目
	
	if(lock==true)return;
	lock=true;
	
	$('ul[className*="Nav"]').hide();
	$('.MainMenu').attr('focus','0');
	
	if($('.MainMenu:first')[0]!=t){
		$('.MainMenu:first').before(t);
	}


	$('.MainMenu').animate({width:global.MainMenuWidth},'normal');	//导航条还原
	
	animateMMSort();
	
	//判断是否为首页，若是首页，则初始化
	if(href=='/'){
		setTimeout(function(){$('#'+MB_MgTopDivID).animate({height:'0px'},'normal',function(){getHref(href,function(){lock=false})})},1000);

	}else{
		$('#'+MB_MgTopDivID).animate({height:'32px'},'normal');
		$(t).attr('focus','1')
			.animate({width:global.pagebodyWidth},'normal',function(){
												getHref(href,function(){lock=false});
												$(t).find('ul[className*="Nav"]')
													.fadeIn('slow',function(){
																		if($(this).attr('lavaLamp')!='1')
																			$(this).attr('lavaLamp','1').lavaLamp({ fx: "backout", speed: 500 });
																	});
											});
		
	}
}


//Ajax读取Url并显示到#MBBody区域
function getHref(href,onFinish){
	var href,onFinish;
	reflushNav(href);
	if(ltrimVBcrlf(href,global.DomainName)==ltrimVBcrlf(global.CurrentHref,global.DomainName)){if(onFinish)onFinish();return;};	//检查要请求的地址是否就是当前页
	//显示 Loading 窗口
//	var $LoadingForm=$('<div style="display:none;font-size:12px;padding:10px 0px 10px 0px;background:#FFFFE1;text-align:center;position:absolute;left:0px;top:0px;width:100%"><img src="/images/loading.gif" align="absmiddle" /> 载入中，请稍候</div>');
//	$('#MBBody').prepend($LoadingForm);	$LoadingForm.fadeIn();

	$.ajax({
	   url:href,
	   error:function(){alert('有错误');if(onFinish)onFinish()},
	   type:'GET',
	   cache:true,
	   success:function(t){
				var t,patrn=/<!--MBBody Start-->([\s\S]*)<!--MBBody End-->/;
				global.CurrentHref=href;	//设置全局变量
				t=patrn.exec(t)[1];
				$('#MBBody').fadeOut('fast',function(){
												$('#MBBody').html(t);
//												$('#MBBody').append(t);
												$('#MBBody').fadeIn('fast',function(){
																				if(onFinish)onFinish();
																				init_Href();
																				init_QKSearch()
																			});
											});
		   }
	   });
}


//当正文ajax链接被点击后，更新导航位置
function reflushNav(Curhref){
	var Curhref;
	$('.MainMenu').each(function(){
						var $this=$(this);
						var href=$this.find('.MainLink a:first').attr('oldHref');
						if(ltrimVBcrlf(href,global.DomainName)==ltrimVBcrlf(Curhref,global.DomainName)){
							$this.find('.MainLink:first').trigger('click')
						}
					});
}


*/




//订票窗口表单验证
function checkform(form){
	var form;
	if($('#UName').val()==''){
		alert('请填写您的姓名!');
		$('#UName').focus();
		return false;
	}
	if($('#Date1').val()==''){
		alert('请填写出发日期!');
		$('#Date1').focus();
		return false;
	}
	if($('#tel').val()==''){
		alert('请填写您的联系电话!');
		$('#tel').focus();
		return false;
	}
}



