﻿// JavaScript Document
//获取对象
function $N(xName){return document.getElementsByName(xName);}
function $AirOrder(xString,xType){
	if(xType=="1"){
		$("#OrderStr").val(xString);
		if($("#UserLogin").val() != ""){
			if($("#FirstStr").val() != "")
			{
				xString = $("#FirstStr").val()+"@"+ xString;
			}
			$("#Order").click();
		}else{
			$LoginMinBox();
		}
	}else{
		$("#FirstStr").val(xString);
		$("#fairSearch").click();
	}
}
function $HotelOrder(xString){
	if($("#UserLogin").val() != ""){
		$("#OrderStr").val(xString);
		$("#Order").click();
	}else{
		$LoginMinBox();
	}
}
function $TrainOrder(xString){
	if($("#UserLogin").val() != ""){
		$("#OrderStr").val(xString);
		$("#Order").click();
	}else{
		$LoginMinBox();
	}
}


function $LoginMinBox(){
	$.msgbox({height:260,width:400,content:"/member/loginmin.aspx?r="+Math.random(),type:'get',title: '会员登录',afterAjaxEvent: function(data){}});	
}
function $LoginMin(xUrl){
	$.post(
		xUrl,
		{
			action:"login",
			username:$("#UserName").val(),
			password:$("#Password").val(),
			logintype:$("input[name=LoginType][checked]").val(),
			r:Math.random()
		}, 
		function(data){
			if(data.indexOf("success")!=-1){
				$("#UserLogin").val($("#UserName").val());
				$("#zUserInfo").html("当前会员："+$("#UserName").val()+" [<a href=\"/member/index.aspx\">会员中心</a>] [<a href=\"/member/exitsystem.aspx\">退出</a>]")
				$("[name=msgclose]").find("a").mousedown();
				//if($("#OrderStr")){
				//	if($("#OrderStr").val()!="") $("#Order").click();
				//}
				
			}else{
				$.msgbox({height:130,width:300,content:"<center>对不起！会员登录失败！</center>",title:"系统提示",type :"alert"});
			}
		}
	); 
}

function $SetPeople(xPeople){
	var cHTML="";
	for(N=1;N<xPeople;N++){cHTML+=$("#clientinfo").html();	}
	$("#clientlist").html(cHTML);
}

function $SetPrice(){
	var cType=$N("cType");;
	var aPeople=0;
	var bPeople=0;
	var cPeople=0;
	var aSafe=0;
	var aPeoplePrice =0;
	var bPeoplePrice=0;
	var cPeoplePrice=0;
	var aSafePrice=0;
	var buildPrice=0;
	var FuelPrice=0;
	var SafePrice=0;
	for(var N=0;N<cType.length;N++){
		switch(cType[N].value)
   		{
			case "成人":
				aPeople++;
				$N("cBirthday")[N].value="";
				$N("cCardNo")[N].style.display='';
				$N("cBirthday")[N].style.display='none';
				break;
			case "儿童":
				bPeople++;
				$N("cCardNo")[N].value="";
				$N("cCardNo")[N].style.display='none';
				$N("cBirthday")[N].style.display='';
				break;
			case "婴儿":
				cPeople++;
				$N("cCardNo")[N].value="";
				$N("cCardNo")[N].style.display='none';
				$N("cBirthday")[N].style.display='';
				break;
		}
		aSafe +=eval($N("cSafe")[N].value);
	}
	$("#aPeople").html(aPeople);
	$("#bPeople").html(bPeople);
	$("#cPeople").html(cPeople);
	$("#aPeople_val").val(aPeople);
	$("#bPeople_val").val(bPeople);
	$("#cPeople_val").val(cPeople);
	$("#aPeoplePrice_val").val(0);
	$("#bPeoplePrice_val").val(0);
	$("#cPeoplePrice_val").val(0);
	if(aPeople>0){
		aPeoplePrice = aPrice_Base * aPeople;
		$("#aPeoplePrice").html(aPeoplePrice);
		$("#aPeoplePrice_val").val(aPeoplePrice);
		buildPrice += buildPrice_Base * aPeople;
		FuelPrice += aFuelPrice_Base * aPeople;
	}else{
		alert("至少填写一个成人！");
		$N("cType")[0].value="成人";
		return false;
	}
	if(bPeople>0){
		bPeoplePrice=(Price_Base*0.5)*bPeople;
		$("#bPeoplePrice").html(bPeoplePrice);
		$("#bPeoplePrice_val").val(bPeoplePrice);
		FuelPrice += bFuelPrice_Base * bPeople;
	}
	if(cPeople>0){
		cPeoplePrice=(Price_Base*0.1)*cPeople;
		$("#cPeoplePrice").html(cPeoplePrice);
		$("#cPeoplePrice_val").val(cPeoplePrice);
		FuelPrice += cFuelPrice_Base * cPeople;
	}
	SafePrice=SafePrice_Base * aSafe
	$("#buildPrice").html("￥"+buildPrice+"元");
	$("#FuelPrice").html("￥"+FuelPrice+"元");
	$("#SafePrice").html("￥"+SafePrice+"元");
	$("#buildPrice_val").val(buildPrice);
	$("#FuelPrice_val").val(FuelPrice);
	$("#SafePrice_val").val(SafePrice);
	$("#TotalPrice").html("￥"+(aPeoplePrice+bPeoplePrice+cPeoplePrice+buildPrice+FuelPrice+SafePrice)+"元");
	$("#TotalPrice_val").val(aPeoplePrice+bPeoplePrice+cPeoplePrice+buildPrice+FuelPrice+SafePrice);
}

function $SetPeople(xVal,xPrice){
	$("#zPrice").html("￥"+Number(xPrice)*Number(xVal)+"元");
	$("#Price").val(Number(xPrice)*Number(xVal));
	$("#PeopleNum").empty();
	var lString="";
	for(i=1;i<=Number(xVal)*2;i++){
		lString+="<option value=\""+i+"\">"+i+"</option>";
	}
	$(lString).appendTo("#PeopleNum");
	$("#PeopleNum").attr("value",xVal);
	$SetName(xVal);
}
function $SetName(xVal){
	var cHTML=""
	for(N=1;N<xVal;N++){cHTML+=$("#clientinfo").html();	}
	$("#clientlist").html(cHTML);
}

function $ShowTrinInfo(xStr){
	$("#"+xStr.replace("/","")).toggle();
	if($("#"+xStr.replace("/","")).html()=="请稍后，数据加载中...")
	{
		$.post(
			"train_info.aspx",
			{
				checi:xStr,
				r:Math.random()
			}, 
			function(data){
				$("#"+xStr.replace("/","")).html(data)
			}
		); 
	}
}

function $FlushCheckCode(xID){
	var xURL = $("#"+xID)[0].src;
	$("#"+xID).attr("src",xURL+"?r="+Math.random()); 
}
function $Del(xUrl){
	if(confirm('真的要删除记录吗?')){window.location=xUrl}	
}
function $Cancel(xUrl){
	if(confirm('真的要取消此订单吗?')){window.location=xUrl}	
}
function $SaveTicketNo(xUrl,xVal)
{
	$.post(
		xUrl,
		{
			action:"save",
			ticketno:$("#"+xVal).val(),
			r:Math.random()
		}, 
		function(data){
			location.href=xUrl;
		}
	); 
}

function $UPFile(xUrl){
	//window.open(""+xUrl,"","Width=330,Height=220,top=100,left=100,status=no,scrollbars=no")
	$.msgbox({height:220,width:330,content:xUrl+"&r="+Math.random(),type:'iframe',title: '上传文件',afterAjaxEvent: function(data){}});
}

function $GiftOrder(xURL,xNum,xID){
	if (xNum != "0"){
		location.href=xURL+"?id="+xID;
	}else{
		$.msgbox({height:130,width:300,content:"<center>对不起，此商品暂时库存为0，请选购其他物品！</center>",title:"系统提示",type :"alert"});
	}
}

function $ShowMsg(xAir,xBase)
{
	$.post(
			"/flight/flight_altered.aspx",
			{
				air:xAir,
				base:xBase,
				r:Math.random()
			}, 
			function(data){
				$.msgbox({height:200,width:450,content:data,title:xAir+" 航班 "+xBase+"折扣 退改签规定",type :"text"});
			}
		); 
}

function $GoUrl(xUrl){
	location.href=xUrl;	
}

function $TrainPrice(){
	var SeatPrice=$("#Seat").val().split("|")[1]
	var ServicesPrice=$("#Seat").val().split("|")[3];
	var FarePrice=$("#Seat").val().split("|")[2];
	var FareClass=$("#Seat").val().split("|")[4];
	var Amount=$("#Amount").val();
	var allPrice=0;
	
	$("#zpPrice").html("￥"+Number(SeatPrice)*Number(Amount)+"元");
	$("#pPrice").val(Number(SeatPrice)*Number(Amount));
	allPrice+=Number(SeatPrice)*Number(Amount);
	$("#ztPrice").html("￥"+Number(ServicesPrice)*Number(Amount)+"元");
	$("#tPrice").val(Number(ServicesPrice)*Number(Amount));
	allPrice+=Number(ServicesPrice)*Number(Amount);
	if(FareClass=="1")
	{
		$("#zsPrice").html("￥"+Number(FarePrice)*Number(Amount)+"元");
		$("#sPrice").val(Number(FarePrice)*Number(Amount));
		allPrice+=Number(FarePrice)*Number(Amount);
	}
	else
	{
		$("#zsPrice").html("￥"+Number(FarePrice)+"元");
		$("#sPrice").val(Number(FarePrice));
		allPrice+=Number(FarePrice);
	}
	$("#zallPrice").html("￥"+(allPrice)+"元");
	$("#allPrice").val(allPrice);
}

var LoadLayer=null;
function $LoadPage(xBool){
	
	if(xBool==true)
	{
		if(LoadLayer) return;
		LoadLayer=document.createElement("DIV");
		with(LoadLayer.style){
			width="230px";
			height="80px";
			position="absolute";
			left=(document.body.clientWidth/2-115)+"px";
			top="200px";
			backgroundColor="#FCFEFC";
			borderLeft="solid 1px #ACD9F7";
			borderTop="solid 1px #ACD9F7";
			borderRight="solid 1px #5AB4EF";
			borderBottom="solid 1px #5AB4EF";
			paddingTop="10px";
			lineHeight="30px";
			fontWeight="700";
			fontSize="13px";
			color="#0241FD";
			zIndex="999";
			textAlign="center";
		}
		
		LoadLayer.innerHTML="<p><img src=\"/images/loading.gif\" /></p>请稍后，数据加载中...";
		document.body.appendChild(LoadLayer);
	}
	else
	{
		if(LoadLayer){
			LoadLayer.removeNode(true);
			LoadLayer=null;
		}
	}
}

//航空公司筛选
function $SelectAirCompany(Air){
	$("#AirInfo").find("div").each(function(){
		if($(this).attr("name")!=undefined)
		{
			if($(this).attr("name")==Air.toUpperCase() || Air.toUpperCase()=="ALL")
			{
				$(this).show();
			}
			else
			{
				$(this).hide();
			}
		}
	});
}
//航班排序
function $SelectAirSort(xSort){
	var zAir=[];
	var zSort=[];
	var n=0;
	$("#AirInfo").find("div").each(function(){
	if($(this).attr("class")=="list")
		{
			zAir[n] = $(this).attr("id");
			zSort[n] = Number($(this).find("."+xSort).text().replace(":",""));
			n++;
		}
	});
	zAir=$SortPice(zSort,zAir);
	var newString="";
	for(var i = 0;i < zAir.length; i++)
    { 
		newString+="<div class=\"list\"  name=\""+zAir[i].substring(0,2)+"\" id=\""+zAir[i]+"\">"+$("#"+zAir[i]).html()+"</div>"
		newString+="<div class=\"airnolist\" id=\""+zAir[i]+"_Text\">"+$("#"+zAir[i]+"_Text").html()+"</div>"
	}
	$("#AirInfo").html(newString);
}
//将价格或时间从小到大排列(冒泡算法)
function $SortPice(zSort,zAir) {
    var temp;
    for(var i = 0;i < zSort.length-1; i++)
    { 
      for(var j = zSort.length-1; j >= i; j--)  
      if(zSort[j+1]<zSort[j])
      {
        temp = zSort[j+1];
        zSort[j+1] = zSort[j];
        zSort[j] = temp;
		
		temp = zAir[j+1];
        zAir[j+1] = zAir[j];
        zAir[j] = temp;
     }
   }
    return zAir;
}
