// JavaScript Document
//获取对象
function $N(xName){return document.getElementsByName(xName);}
function $AirOrder(xString,xType){
    if (xType == "1") {
//        if ($("#UserLogin").val() != "") {
//            if ($("#FirstStr").val() != "") {
//                xString = $("#FirstStr").val() + "@" + xString;
//            }
//            $("#SelectedTicketStr").val(xString);
//            $("#Order").click();
        document.location = "/Ticket/FlightOrder/" + encodeURI(xString);
//        } else {
//            $LoginMinBox();
//        }
    } else {
        var startcity = $("#StartCity").val();
        var endcity = $("#EndCity").val();
        $("#StartCity").val(endcity);
        $("#EndCity").val(startcity);
        $("form").eq(0).submit();
        $("#SelectedTicketStr").val(xString);
        //$("#fairSearch").click();
    }
	
}
function $HotelOrder(xString) {
    document.location = "/Hotel/HotelOrder/" + encodeURI(xString);
//	if($("#UserLogin").val() != ""){
//		$("#OrderStr").val(xString);
//		$("#Order").click();
//	}else{
//		$LoginMinBox();
//	}
}



function $LoginMinBox(){
	$.msgbox({height:220,width:320,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();
			}else{
				$.msgbox({height:130,width:300,content:"<center>对不起！会员登录失败！</center>",title:"系统提示",type :"alert"});
			}
		}
	); 
}

function changeRoomNum(obj) {
    var tmptotal = $.trim($("#hPrice").val());
    $("#zPrice").text(Number($(obj).val() * tmptotal).toFixed(2));
}

function $SetPeople(xPeople){
	var cHTML="";
	for(N=1;N<xPeople;N++){cHTML+=$("#clientinfo").html();	}
	$("#clientlist").html(cHTML);
	$SetPrice();
}

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;	
}

