﻿//图片加载失败时用默认图片替代
function errorLoad(target,errorSrc){target.src=errorSrc;target.onerror=null;return;}

//主导航样式切换
function navCtrl(index){
$(function(){
$("#nav a").removeClass();
$("#nav a").eq(index).addClass("navOn");
$("#navIndexL").val(index);
})
	}

//星级评价
function addStars(obj,num){
obj.empty();
for(var i=0;i<num;i++){obj.append("<img src=\"images/b2cImg/frimages/star.gif\">")}
	}

	
//=========================左侧菜单开始========================
function sideNavCtrl(dtIndex,ddIndex){
	$("#sideNav ul:eq("+dtIndex+")").show();
	if($("#sideNav dt:eq("+dtIndex+")").hasClass('noSub')){
	$("#sideNav dt:eq("+dtIndex+")").removeClass();
	$("#sideNav dt").eq(dtIndex).addClass("noSub");
	$("#sideNav dt").eq(dtIndex).addClass("sideNavFocOn");
	}
	else{
	$("#sideNav dt:eq("+dtIndex+")").removeClass();
	$("#sideNav dt").eq(dtIndex).addClass("sideNavFocOffs");
	$("#sideNav ul:eq("+dtIndex+")").find("li:eq("+ddIndex+")").addClass("liOn");
		}
	$("#sideNav dt:last").css("marginBottom", "-1px"); //修正最下方双边框
}

$(function(){
	function sideNavRemoveClass(obj){
	obj.removeClass("sideNavFocOffs");	
	obj.removeClass("sideNavOffs");	
	obj.removeClass("sideNavFocOns");	
	obj.removeClass("sideNavOns");	
		}
	
	$("#sideNav dt").not($(".noSub")).toggle(function(){	
		sideNavRemoveClass($("#sideNav dt").not($(".noSub")));
		$(this).removeClass();
		$("#sideNav dt.noSub").removeClass("sideNavFocOn");
		$("#sideNav .close").addClass("sideNavOns");
		$(this).addClass("sideNavFocOns");
		$(this).addClass("close");
		$(this).next().slideUp();
		$("#sideNav>dl ul:eq("+$("#sideNav dt").index(this)+")").slideDown("quick");	
		},function(){
		$(this).next().slideDown();
		sideNavRemoveClass($("#sideNav dt").not($(".noSub")));
		$(this).removeClass();
		$(this).addClass("sideNavFocOffs");
		$("#sideNav .close").addClass("sideNavOns");
			}
		)		
	
})
//=========================左侧菜单结束========================	





//==========================弹出窗口插件开始=====================================
var pageHeight,dialogContent;
var WinUrlContent; //全局变量，记录dialogURL div中html,用于关闭层时，恢复dialogURL容器内容
$(function(){
pageHeight=$(document).height(); 
if($("#dialogURL").html()!=null){WinUrlContent=$("#dialogURL").html();dialogContent=WinUrlContent.split("|");}
creatLayer();
})

function creatLayer(){
//创建遮挡背景层和窗口层，添加iframe层遮挡select控件（IE6BUG）
$("body").append('<div id="blackBg"><iframe style="width:100%; height:100%;opacity:0;filter:alpha(opacity=0);"></iframe></div>');
$("#blackBg").attr("style",'display:none; position:absolute; left:0px; top:0px;z-index:1000; background:#000;width:100%;height:'+pageHeight+'px;opacity:0.5;filter:alpha(opacity=50);');
$("#blackBg").after('<div id="dialogBox" style="position:absolute;z-index:1200;width:1%;"></div>');
}


//通用显示Dialog层函数
function showDialog(_content,_width,_height){
	$("#blackBg").show();
	$("#dialogBox").html(_content);
	var X=($(document).width()-_width)/2;
	//兼容webkit，webkit下document.documentElement.scrollTop始终为0;
	var Y=(document.documentElement.clientHeight-_height)/2+(/webkit/i.test(navigator.userAgent) ? document.body : document.documentElement).scrollTop;
	$("#dialogBox").css("left",X+"px");
	$("#dialogBox").css("top",Y+"px");
	$("#dialogURL").empty();//清空dialogURL容器，防止重ID
	if(window.resetDialog){
		resetDialog(dialogIndex);
	}
}

function closeDialog(){
	$("#blackBg").hide();
	$("#dialogBox").html("");
	$("#dialogURL").html(WinUrlContent);//还原dialogURL容器内容
	if(window.resetEvt){resetEvt()}
	}
	
	
$("#dialogBox img.close").live("click", function(){
closeDialog();
});



//==========================弹出窗口插件结束=====================================




//登录弹出层
var fcabinIndex;
function showLogin(parm,cabinIndex){
	if($("#dialogURL").html()==null){loginContent=dialog_login.split("|");}
	else{var loginContent=$("#dialogURL").html().split("|");}
	if(cabinIndex==-5 || cabinIndex==-6){//-5、-6时为团购 by lzb
	//alert(loginContent[2])
	showDialog(loginContent[1],580,320);//弹出议价层
	}else if(cabinIndex==-7){//-7时为酒店 by lzb
		showDialog(loginContent[4],580,320);//弹出议价层
	}else{
		showDialog(loginContent[2],580,320);//弹出议价层
	}
	indx_bargain = parm;
	fcabinIndex = cabinIndex;
}



//支付对话框
function pay(){
var PayContent=$("#dialogURL").html().split("|");
showDialog(PayContent[0],382,270);//弹出议价层
}
//支付对话框2
function pay2(){
var PayContent=$("#dialogURL").html().split("|");
closeDialog();
showDialog(PayContent[1],382,270);//弹出议价层
}
$("#win_pay .til img").click(function(){closeDialog()})


//==========改期弹出层==================
var indx_flight;//航班索引
var indx_cabin;
var changeDateContent;
var nowobj;
var index_cabin; //航班按钮索引（每个航班从0开始）
$(".linelist01 :button[name='btn_changeDate']").live("click",function(){
																	  
indx_cabin=$(".linelist01 :button[name='btn_changeDate']").index(this);

nowobj=$(".linelist01 :button[name='btn_changeDate']").eq(indx_cabin);
var parentObj=nowobj.parent().parent().parent();
if(parentObj.hasClass('linelist01')){
indx_flight=$(".linelist01").index(parentObj);
var obbj=$(".linelist01").eq(indx_flight).find("ul>li :button[name='btn_changeDate']");
index_cabin=indx_cabin-$(".linelist01 :button[name='btn_changeDate']").index(obbj);
//alert(index_cabin);
}
else{
indx_flight=$(".linelist01").index(parentObj.parent());
var obbj=$(".linelist01").eq(indx_flight).find("ul>li :button[name='btn_changeDate']");
index_cabin=indx_cabin-$(".linelist01 :button[name='btn_changeDate']").index(obbj);
//alert(index_cabin);
	}

changeDateContent=$("#dialogURL").html().split("|");
showDialog(changeDateContent[1],630,580);
getflight(indx_flight,index_cabin);
})

$(":button[name='btn_ticketChangeDate']").live("click",function(){ticketChangeDate(indx_flight,index_cabin);})
//==========改期弹出层结束==================



//==========议价弹出层==================
var indx_bargain;//议价记录索引
var urlContent;//弹出层URL数组
$(".linelist01 :button[name='btn_bargain']").live("click",function(){
indx_bargain=$(".linelist01 :button[name='btn_bargain']").index(this);
urlContent=$("#dialogURL").html().split("|");
//showDialog(urlContent[0],588,435);//弹出议价层
//addBargain(indx_bargain);
if(window.isLogin){isLogin(indx_bargain);}
//addBargain();
})

$(":button[name='submit_bargain']").live("click",function(){bargain(indx_bargain);});//by zhangyun 修改：关闭打开页面功能已经改到自己页面
$(":button[name='cancel_bargain']").live("click",function(){orderTicket(indx_bargain);closeDialog();});
$(":button[name='btn_cashPay']").live("click",function(){cashPay(indx_bargain);})//by zhangyun 修改：关闭打开页面功能已经改到自己页面
$("a[name='btn_noPay']").live("click",function(){closeDialog();})
//==========议价弹出层结束==================











//退票选择对话框
var indx_refundTicket;
var indx_refund;
function refundTicket(obj){
var rfnTicketContent=$("#dialogURL").html().split("|");
showDialog(rfnTicketContent[0],302,196);
indx_refundTicket=obj;//by lizhibin 修改：参数获取方式
}
$('.win_refundTicket img').live('click', function() {closeDialog();});
$(".win_refundTicket #btn_refundTktSelf").live("click",function(){
closeDialog();
refundTktSelf(indx_refundTicket);
})
$(".win_refundTicket #btn_refundTkt").live("click",function(){
closeDialog();
refundTkt(indx_refundTicket);
})

//退款对话框
function refund(obj){
var rfnTicketContent=$("#dialogURL").html().split("|");
showDialog(rfnTicketContent[1],302,196);
indx_refund=obj;//by lizhibin 修改：参数获取方式
}
$('.win_refund img').live("click", function() {closeDialog();});
$(".win_refund #btn_refund").live("click",function(){
closeDialog();	
re_fund(indx_refund);
})



//应用成功对话框
function showSucessInfo(index){
		if(index!=null || index!=""){
			$("#sucessInfo"+index).slideDown("slow"); 
			$("#sucessInfo"+index+" div").replaceWith("<div><img src=\"images/b2cImg/ico_apply.gif\" width=\"14\" height=\"14\" />修改已生效，保存成功！</div>"); 
			setTimeout(function(){$("#sucessInfo"+index).slideUp("slow");},3500);
		}
		
		else{
			$("#sucessInfo").slideDown("slow"); 
			$("#sucessInfo div").replaceWith("<div><img src=\"images/b2cImg/ico_apply.gif\" width=\"14\" height=\"14\" />修改已生效，保存成功！</div>"); 
			setTimeout(function(){$("#sucessInfo").slideUp("slow");},3500);
			}
}
		 
//应用失败对话
function showFailInfo(){	  									  			
		$("#sucessInfo").slideDown("slow"); 
		$("#sucessInfo div").replaceWith("<div><img src=\"images/b2cImg/ico_delInfo.gif\" width=\"16\" height=\"16\" />修改未生效，保存失败！</div>"); 
		setTimeout(function(){$("#sucessInfo").slideUp("slow");},3500);
	}		 



//显示搜索区域
function showSearchArea(tabIndex){
	$("#closeSearch").show();
	$("#searchCriteria").hide();
	$("#searchArea").show();
	$("#searchArea div").hide();
	$("#searchArea div:eq("+tabIndex+")").show();
	}
	
	
function showOrderHistory(parm){
if(parm==0){
	$("#historyOrder .listRecord").hide();
	$("#historyOrder>ul:eq(0)").show();
	}
	else{
	$("#historyOrder .listRecord").hide();
	$("#historyOrder>ul:eq(1)").show();
		}
}


//去除空格
　　 String.prototype.trim=function(){
　　    return this.replace(/(^\s*)|(\s*$)/g, "");
　　 }
//去除左空格
　　 String.prototype.ltrim=function(){
　　    return this.replace(/(^\s*)/g,"");
　　 }
//去除右空格
　　 String.prototype.rtrim=function(){
　　    return this.replace(/(\s*$)/g,"");
　　 }


//获取DOM对象的绝对位置
function getAbsPoint(e) {   
    var x = e.offsetLeft;   
    var y = e.offsetTop;   
    while(e = e.offsetParent) {   
        x += e.offsetLeft;   
        y += e.offsetTop;   
    }   
    return {x:x,y:y};   
}

