﻿// Create By JinYH  2010-2-23
//Create Class BaseInfo
var BaseInfo=function(){
    this.backEndCityName = "";
    this.backSeatTypeName = "";
    this.backStartCityName = "";
    this.backTrafficName = "";
    this.businessTypeName = "";
    this.child = "";
    this.childPrice = "";
    this.days = "";
    this.discount = "";
    this.goEndCity = "";
    this.goSeatTypeName = "";
    this.goStartCity = "";
    this.goTrafficName = "";
    this.kindName = "";
    this.lineCode = "";
    this.lineTypeName = "";
    this.person = "";
    this.price = "";
    this.room = "";
    this.startDate = "";
    this.webTypeName = "";
    this.lineName="";
    this.teamNo="";
    this.op="";
    this.opDep="";
    this.toString=function(){
        return this.lineCode + "|" + this.startDate + "|" + this.person + "|" + this.child + "|" + this.room + "|" + this.days + "|" + this.price + "|" + this.goStartCity + "|" + this.goEndCity + "|" + this.backStartCityName + "|" + this.backEndCityName + "|" + this.lineTypeName + "|" + this.kindName + "|" + this.webTypeName + "|" + this.goTrafficName + "|" + this.backTrafficName + "|" + this.goSeatTypeName + "|" + this.backSeatTypeName + "|" + this.businessTypeName + "|" + this.childPrice+"|"+this.discount+"|"+this.lineName+"|"+this.teamNo+"|"+this.op+"|"+this.opDep;
    };
    this.SetAll=function(v){
        var arr=v.split('|');
            this.lineCode = arr[0];
            this.startDate = arr[1];
            this.person = arr[2];
            this.child = arr[3];
            this.room = arr[4];
            this.days = arr[5];
            this.price = arr[6];
            this.goStartCity = arr[7];
            this.goEndCity = arr[8];
            this.backStartCityName = arr[9];
            this.backEndCityName = arr[10];
            this.lineTypeName = arr[11];
            this.kindName = arr[12];
            this.webTypeName = arr[13];
            this.goTrafficName = arr[14];
            this.backTrafficName = arr[15];
            this.goSeatTypeName = arr[16];
            this.backSeatTypeName = arr[17];
            this.businessTypeName = arr[18];
            this.childPrice = arr[19];
            this.discount = arr[20];
            this.lineName=arr[21];
            this.teamNo=arr[22];
            this.op=arr[23];
            this.opDep=arr[24];
    }
    
};


//Create Class TrafficInfo
var TrafficInfo=function(){
    this.goStartDate="";
    this.backStartDate="";
    this.goName="";
    this.backName="";
    this.goInfo="";
    this.backInfo="";
    this.memo="";
    this.s_goStartDate=function(v){this.goStartDate=v;};
    this.s_backStartDate=function(v){this.backStartDate=v;};
    this.s_goName=function(v){this.goName=v;};
    this.s_backName=function(v){this.backName=v;};
    this.s_goInfo=function(v){this.goInfo=v;};
    this.s_backInfo=function(v){this.backInfo=v;};
    this.s_memo=function(v){this.memo=v;};
    
    this.toString=function(){
        return this.goStartDate+"|"+this.backStartDate+"|"+this.goName+"|"+this.backName+"|"+this.goInfo+"|"+this.backInfo+"|"+this.memo;
    };
    this.SetAll=function(v){
        var arr=v.split('|');
        this.goStartDate=arr[0];
        this.backStartDate=arr[1];
        this.goName=arr[2];
        this.backName=arr[3];
        this.goInfo=arr[4];
        this.backInfo=arr[5];
        this.memo=arr[6];
    };
};

// Create Class SingleItemInfo
var SingleItemInfo=function(stype,itemCode,supID,name,outPrice,ourPrice,unit,useDate,count,amount,contaions,type){
    this.stype=stype;
    this.itemCode=itemCode;
    this.supID=supID;
    this.name=name;
    this.outPrice=outPrice;
    this.ourPrice=ourPrice;
    this.unit=unit;
    this.useDate=useDate;
    this.count=count;
    this.amount=amount;
    this.contains=contaions;
    this.type=type
    this.toString=function(){
        return this.stype + "|" + this.itemCode +"|" + this.supID + "|" + this.name+"|"+ this.outPrice + "|" +this.ourPrice+"|"+this.unit+"|"+this.useDate+"|"+this.count+"|"+this.amount+"|"+this.contains+"|"+this.type;
    };
    this.SetAll=function(v){
        var arr=v.split('|');
        this.stype = arr[0];
        this.itemCode= arr[1];
        this.supID = arr[2];
        this.name=arr[3];
        this.outPrice=arr[4];
        this.ourPrice=arr[5];
        this.unit=arr[6];
        this.useDate=arr[7];
        this.count=arr[8];
        this.amount=arr[9];
        this.contains=arr[10];
        this.type=arr[11];
    };
};

//Create Class Tour
TourInfo=function(name,type,card,tel){
    this.name=name;
    this.type=type;
    this.card=card;
    this.tel=tel;
    this.toString=function(){
        return this.name+"|"+this.type+"|"+this.card+"|"+this.tel;
    };
    this.SetAll=function(v){
        var arr=v.split('|');
        this.name=arr[0];
        this.type=arr[1];
        this.card=arr[2];
        this.tel=arr[3];
    };
};

//Create Class Contact
ContactInfo=function(){
    this.contact="";
    this.mobile="";
    this.tel="";
    this.fax="";
    this.email="";
    this.userName="";
    this.toString=function(){
        return this.contact+"|"+this.mobile+"|"+this.tel+"|"+this.fax+"|"+this.email+"|"+this.userName;
    };
    this.SetAll=function(v){
        var arr=v.split('|');
        this.contact=arr[0];
        this.mobile=arr[1];
        this.tel=arr[2];
        this.fax=arr[3];
        this.email=arr[4];
        this.userName=arr[5];
    };
    
};

//Create Class Deliver
DeliverInfo=function(){
    this.distribution="0";
    this.city="0";
    this.address="0";
    this.recipient="0";
    this.zip="0";
    this.tel="0";
    this.payType="0";
    this.memo="0";
    this.toString=function(){
        return this.distribution+"|"+this.city+"|"+this.address+"|"+this.recipient+"|"+this.zip+"|"+this.tel+"|"+this.payType+"|"+this.memo;
    };
    this.SetAll=function(v){
        var arr=v.split('|');
        this.distribution=arr[0];
        this.city=arr[1];
        this.address=arr[2];
        this.recipient=arr[3];
        this.zip=arr[4];
        this.tel=arr[5];
        this.payType=arr[6];
        this.memo=arr[7];
    };
};

//Create Class Invoice
InvoiceInfo=function(){
    this.isNeed="0";
    this.title="0";
    this.type="0";
    this.notes="0";
    this.toString=function(){
        return this.isNeed+"|"+this.title+"|"+this.type+"|"+this.notes;
    };
    this.SetAll=function(v){
        var arr=v.split('|');
        this.isNeed=arr[0];
        this.title=arr[1];
        this.type=arr[2];
        this.notes=arr[3];
    };
};


function Dis(obj)
{
    var tr=document.getElementById(obj);
    if(tr.style.display=="block")
    {
        tr.style.display="none";
    }
    else
    {
        tr.style.display="block";
    }
}
// 提交OrderReserve.aspx数据
function submitReServe()
{
    $("#lineCode").val($("#hfLineCode").val());
    $("#hc").val($("#amountComposition").val());
    var baseInfo=new BaseInfo();
    baseInfo.SetAll($("#hfBaseAll").val());
    baseInfo.price=$("#lblAmount").text();
    $("#baseAll").val(baseInfo.toString());
    //$("#baseAll").val($("#hfBaseAll").val());
    var tempHotel="";
    var dd=baseInfo.days;
    if(dd=="1")
    {
         tempHotel+="0|0|0|0|0|0|0|0|0|0|0$";
    }
    else
    {
    $("#pHotelInfo .tab_hotel_title").each(function(i){
        tempHotel+=this.rows(0).cells(0).innerText+"|"+this.rows(0).cells(1).innerText+"|"+this.rows(0).cells(2).innerText;
        var baseInfo=new BaseInfo();
        baseInfo.SetAll($("#hfBaseAll").val());
        var businessType=baseInfo.businessTypeName;
//        if(businessType=="国内")
//        {
//              tempHotel+="|0|0|0|0|0|0|0|0$";
//        }
//        else if(businessType=="25005")
//        {
            var tab_content=$($("#pHotelInfo .tab_hotel_dataRow")[i]).find(".tab_content")[0];
            var hotelName=tab_content.rows(0).cells(0).innerText;
            var hotelInfo=tab_content.rows(1).cells(0).innerText;
            var room=$(tab_content).find(".tab_room")[0];
            var roomType=$(room.rows(1).cells(0)).find("select").val();
            var breakfast=room.rows(1).cells(1).innerText;
            var count=room.rows(1).cells(2).innerText;
            var price=room.rows(1).cells(3).innerText;
            var htem=$(room.rows(1).cells(4)).find("input")[0].value;
            //alert(i + " " + htem);
            var htemArr;
            if(htem.indexOf('|')>-1)
            {
                htemArr=htem.split('|');
            }
            else
            {
                htemArr[0]="0000";
                htemArr[1]="0000";
            }
            var hotelCode=htemArr[0];
            var roomCode=htemArr[1];
            tempHotel+="|"+hotelName+"|"+hotelInfo+"|"+ hotelCode +"|"+roomType+"|"+breakfast+"|"+count+"|"+price+"|"+ roomCode +"$";
            //alert(tempHotel);
//        }
    });
    }
    
    //取行程
    var tempTraffic=new TrafficInfo();
    tempTraffic.s_goStartDate($("#goStartDate").text());
    tempTraffic.s_backStartDate($("#backStartDate").text());
    tempTraffic.s_goName($("#goName").text());
    tempTraffic.s_backName($("#backName").text());
    tempTraffic.s_goInfo($("#goInfo").text());
    tempTraffic.s_backInfo($("#backInfo").text());
    tempTraffic.s_memo($("#memo").text());
     //tempTraffic.SetAll("1|2|3|4|5|6|7");
     
     //取包含的单项
     var tempSingleArr=new Array();
     var tempS="";
     $(".tab_contains .tr").each(function(i){
        var oiArr=this.cells(7).innerText.split('|');
        var tempSingle=new SingleItemInfo(oiArr[0],oiArr[1],oiArr[2],$(this.cells(0)).text(),$(this.cells(1)).text(),$(this.cells(2)).text(),$(this.cells(3)).text(),$(this.cells(4)).text(),$(this.cells(5)).text(),$(this.cells(6)).text(),true,"--");
        tempSingleArr.push(tempSingle);
        tempS+=tempSingle.toString()+"$";
     });
    $("#hdContainsInfo").val(tempS);
    //alert($("#hdContainsInfo").val());
    $("#hdHotelInfo").val(tempHotel);
    $("#hdTrafficInfo").val(tempTraffic.toString());
    
    document.getElementById("form2").submit();
}

function SetValue(obj,str)
{
    $("#"+str).val(obj.value);
}

function AjaxLogin()
{
    var str_userName=$("#hfUserName").val();
    var str_userPwd=$("#hfUserPwd").val();
    $.ajax({
        url: "../User/UserLoginajax.aspx?userName="+str_userName+"&userPwd="+str_userPwd+"&type=login",
        cache:false,
        success:function(html){
        var arr=html.split("$$$");
        if(arr[0]=="SUC")
        {
            //this.location.href='SessionTest.aspx';
            JudgeLogin();
        }
        else
        {
            alert(arr[1]);
        }
        }
    });
}
function AjaxLogin1()
{
    var str_userName=$("#hfUserName").val();
    var str_userPwd=$("#hfUserPwd").val();
    $.ajax({
        url: "../User/UserLoginajax.aspx?userName="+str_userName+"&userPwd="+str_userPwd+"&type=login",
        cache:false,
        success:function(html){
        var arr=html.split("$$$");
        if(arr[0]=="SUC")
        {
            closeLayer();
            $("#btnNext")[0].click();
            //document.getElementById("btnNext").click();
        }
        else
        {
            alert(arr[1]);
        }
        }
    });
}

function JudgeLogin()
{
    $.ajax({
        url:"../User/UserLoginajax.aspx?type=judge",
        cache:false,
        success:function(html){
            if(html=="TRUE")
            {
                //alert("已登录");
                SubmitToContact();
            }
            else
            {
                //alert("未登录");
                openLayer('test3','test_con3');
            }
        }
    });
}
function DirectToOrder() //直接预订
{
    var str_mobile=$("#hfMobile").val();
    if(checkMobile(str_mobile))
    {
        $.ajax({
            url:"../user/AjaxRegister.aspx?mobile="+str_mobile,
            cache:false,
            success:function(html){
                var arr=html.split("$$$");
                if(arr[0]=="SUC")
                {
                    arr1=arr[1].split('|');
                    $("#hfUserName").val(arr1[0]);
                    $("#hfUserPwd").val(arr1[1]);
                    AjaxLogin();
                }
                else
                {
                    alert(html);
                }
                
            }
        });
    }
    else
    {
        alert("手机号码有误，请重新输入!");
    }
}

function checkMobile(mobile)
{
 var reg0=/^13\d{5,9}$/;   //130--139。至少7位
 var reg1=/^14\d{5,9}$/;  //联通14。至少7位
 var reg2=/^15\d{5,9}$/;  //联通15。至少7位
 var reg3=/^18\d{5,9}$/;  //联通18。至少7位
 var my=false;
 if (reg0.test(mobile))my=true;
 if (reg1.test(mobile))my=true;
 if (reg2.test(mobile))my=true;
 if (reg3.test(mobile))my=true;
 if (mobile.length!=11){my=false;}
 return my;
}


function SubmitToContact()
{
     //取客户已选择的单项
     var tempSingleArr=new Array();
     var tempS="";

    $(".pItemContain").each(function (i){
       var type=$(this).find(".pTitle").text();
       
       //tr=$(this).find(".item")[0];
//       var tempSingle=new SingleItemInfo($(tr.cells(0)).text(),$(tr.cells(1)).text(),$(tr.cells(2)).text(),$(tr.cells(3)).text(),$(tr.cells(4)).text(),$(tr.cells(5)).text(),$(tr.cells(6)).text(),false,type);
//       tempSingleArr.push(tempSingle);
//       tempS+=tempSingle.toString()+"$";
        $(this).find(".item").each(function(j,tr){
            if(tr.cells(6).innerText!="--")
            {
                 var oiArr=tr.cells(7).innerText.split('|');
                 var temp1=$(tr.cells(4)).find("select").val();
                 if(temp1=="-1")
                    temp1="--";
                 var tempSingle=new SingleItemInfo(oiArr[0],oiArr[1],oiArr[2],$(tr.cells(0)).text(),$(tr.cells(1)).text(),$(tr.cells(2)).text(),$(tr.cells(3)).text(),temp1,$(tr.cells(5)).find("select").val(),$(tr.cells(6)).text(),false,type);
                tempSingleArr.push(tempSingle);
                tempS+=tempSingle.toString()+"$";
            }
        });
    });
    $("#optionInfo").val(tempS);
    $("#amountComposition").val($("#amountComposition").val() + "@" + tempS);
    var lblAmount=$("#lblAmount").text();
    var baseInfo=new BaseInfo();
    baseInfo.SetAll($("#baseAll").val());
    baseInfo.price=lblAmount;
    $("#baseAll").val(baseInfo.toString());
    $("#form1")[0].action="OrderContact.aspx";
    $("#form1")[0].submit();
}

function GetCommonTour()
{
        var businessTypeName=$("#businessTypeName").val();
        $.ajax({
         url:"../User/GetCommonTour.aspx?businessType="+businessTypeName,
        cache:false,
        success:function(html){
            var arr=html.split("$$$");
            if(arr[0]=="TRUE")
            {
                $("#commonTour").html(arr[1]);
                //alert(arr[1]); 
                
            }
            else
            {
                //alert(html);  
                $("tourInfo").hide("slow"); 
            }
        }
    });
}

function GetContact()
{
    $.ajax({
        url:"../User/UserLoginajax.aspx?type=contact",
        cache:false,
        success:function(html){
            var arr=html.split("$$$");
            if(arr[0]=="TRUE")
            {
                var contact=new ContactInfo();
                contact.SetAll(arr[1]);
                $("#contact").val(contact.contact);
                $("#mobile").val(contact.mobile);
                $("#tel").val(contact.tel);
                $("#fax").val(contact.fax);
                $("#email").val(contact.email);
                
            }
            else
            {
                alert("登录超时，请重新登录！");
            }
        }
    });
}

function SetCommonTour(obj)
{
    var tour=new TourInfo("","","","");
    tour.SetAll(obj.value);
    //alert(obj.value);
    if(obj.checked)
    {
        var state=false;
        $(".tours_dataRow").each(function(i){
            var value=$(this.cells(0)).find(":input").val();
            if(value=="")
            {
                if(state==false)
                {
                    $(this.cells(0)).find(":input").val(tour.name);
                    $(this.cells(1)).find(":input").val(tour.type);
                    $(this.cells(2)).find(":input").val(tour.card);
                    $(this.cells(3)).find(":input").val(tour.tel);
                    state=true;
                }
            }
        });
        
        var inputCount=$("#commonTour :input").length;
        var pCount=$(".tours_dataRow").length;
        var teml=0;
        $("#commonTour :input").each(function(i){
            if(this.checked)
                teml++;
        });
        if(teml==pCount)
        {
            $("#commonTour :input").each(function(i){
            if(!this.checked)
            {
                this.disabled=true;
            }
            });
        }
        
    }
    else
    {
       $(".tours_dataRow").each(function(i){
            if($(this.cells(0)).find(":input").val()==tour.name)
            {
                $(this.cells(0)).find(":input").val("");
                $(this.cells(1)).find(":input").val("");
                $(this.cells(2)).find(":input").val("");
                $(this.cells(3)).find(":input").val("");
                return false;
            }
        });
        
        
    }
    EnabledCheckBox();
}

function EnabledCheckBox()
{
    var inputCount=$("#commonTour :input").length;
    var pCount=$(".tours_dataRow").length;
    var teml=0;
    $("#commonTour :input").each(function(i){
        if(this.checked)
            teml++;
    });
    if(teml<pCount)
    {
        $("#commonTour :input").each(function(i){
        if(!this.checked)
        {
            this.disabled=false;

        }
        });
    }
}

function EmptyTour(obj)
{
    var row=obj.parentNode.parentNode;
    var name="";
    $(row).find(":input").each(function(i){
        if(i==0)
        {
            name=this.value;
        }
        this.value=""; 
    });
    
    $("#commonTour :input").each(function(i){
        var tem=this.value;
        tem=tem.substring(0,tem.indexOf('|'));
        if(tem==name)
        {
            if(this.checked)
            {
                this.checked=false;
                return false;
            }
        }
    });
    EnabledCheckBox();
}

// OrderContact.aspx post
function SubmitContact()
{
    if(Valid())
    {
        var contact=new ContactInfo();
        contact.contact=$("#contact").val();
        contact.mobile=$("#mobile").val();
        contact.tel=$("#tel").val();
        contact.fax=$("#fax").val();
        contact.email=$("#email").val();
        $("#hfContact").val(contact.toString());
        
        var toursArr="";
        $(".tours_dataRow").each(function(i){
            var tour=new TourInfo($(this.cells(0)).find(":input").val(),$(this.cells(1)).find(":input").val(),$(this.cells(2)).find(":input").val(),$(this.cells(3)).find(":input").val());
            toursArr+=tour.toString()+"$$$";
            
        });
        $("#hfTours").val(toursArr); 
        
        $("#form1")[0].action="OrderDeliver.aspx";
        $("#form1")[0].submit();
    }
}



//OrderDeliver.aspx 
function ToggleClass(obj)
{
    //alert($("#businessTypeName").val());
    $(".P_Deliver").each(function(i){
        this.className="P_Deliver";
    });
    obj.className="P_Deliver Selected";

    if(!$(obj).find(".ipt_deliver")[0].checked)
    {
        $(obj).find(".ipt_deliver")[0].checked=true;
        if($(obj).find(".ipt_deliver")[0].value=="门店自取")
        {
            if(storesState==false)
            {
                GetStores1();
            }
        }
        else
            $(obj).find(".de_tab")[0].style.display="block";
            
        JudgeValid();
    }
}

function GetStores1(state)
{
        $.ajax({
        url:"../WebService/GetStores.aspx",
        cache:false,
        success:function(html){
            //alert(html);
            $("#p2_sotres").html(html);
            $("#p2_sotres").show();
            storesState=true;
            if(state==true)
            {
                GetGoogleMap();
            }
        }
    });
}

function JudgeValid()
{
    if($("#r1")[0].checked)
    {
        if($("#r2_valid")[0]!=null)
            $("#r2_valid")[0].style.display="none";
        if($("#recipient_valid")[0]!=null)
            $("#recipient_valid")[0].style.display="none";
        if($("#zip_valid")[0]!=null)
            $("#zip_valid")[0].style.display="none";  
        if($("#tel_valid")[0]!=null)
            $("#tel_valid")[0].style.display="none";      
        if($("#p3_address_valid")[0]!=null)
            $("#p3_address_valid")[0].style.display="none";         
    }
    if($("#r2")[0].checked)
    {
        if($("#recipient_valid")[0]!=null)
            $("#recipient_valid")[0].style.display="none";
        if($("#zip_valid")[0]!=null)
            $("#zip_valid")[0].style.display="none";  
        if($("#tel_valid")[0]!=null)
            $("#tel_valid")[0].style.display="none";      
        if($("#p3_address_valid")[0]!=null)
            $("#p3_address_valid")[0].style.display="none";
        if($("#p1_address_valid")[0]!=null)
            $("#p1_address_valid")[0].style.display="none";         
    }
//    if($("#r3")[0].checked)
//    {
//        if($("#r2_valid")[0]!=null)
//            $("#r2_valid")[0].style.display="none";
//                //        if($("#recipient_valid")[0]!=null)
//                //            $("#recipient_valid")[0].style.display=="none";
//                //        if($("#zip_valid")[0]!=null)
//                //            $("#zip_valid")[0].style.display=="none";  
//                //        if($("#tel_valid")[0]!=null)
//                //            $("#tel_valid")[0].style.display=="none";      
//                //        if($("#p3_address_valid")[0]!=null)
//                //            $("#p3_address_valid")[0].style.display=="none";
//        if($("#p1_address_valid")[0]!=null)
//            $("#p1_address_valid")[0].style.display="none";         
//    }
    
}

function GetMap()
{
    document.getElementById('test3').click();
    if(storesState==false)
    {
        GetStores1(true);
    }
    else
    {
        GetGoogleMap();
    }
    
}

function GetGoogleMap()
{
    if (GBrowserIsCompatible()) 
    {
        var map = new GMap2(document.getElementById("map"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(31.22955502275548,121.4779543876648), 12);
        map.addControl(new GOverviewMapControl());
        GEvent.addListener(map, "moveend", function() {
        var center = map.getCenter();});
        
        // 为所有的标注创建一个“基准”图标，并指定它的阴影、尺寸、锚点等
        var baseIcon = new GIcon();
        baseIcon.shadow = "http://ditu.google.com/mapfiles/shadow50.png";
        baseIcon.iconSize = new GSize(20, 34);
        baseIcon.shadowSize = new GSize(37, 34);
        baseIcon.iconAnchor = new GPoint(9, 34);
        baseIcon.infoWindowAnchor = new GPoint(9, 2);
        baseIcon.infoShadowAnchor = new GPoint(18, 25);
        
        // 创建一个标注，它的气泡提示窗口会根据标注编号显示对应的英文字母
        function createMarker(point, index,sname,tel,id) {
          // 利用我们的图标类，为这个标注创建一个带字母的图标
          var letter = String.fromCharCode("A".charCodeAt(0) + index);
          var icon = new GIcon(baseIcon);
          icon.image = "http://ditu.google.com/mapfiles/marker" + letter + ".png";
          var marker = new GMarker(point, icon);

          GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowHtml("名称： <b>" + sname + "</b><br />电话：<b>"+ tel +"</b><br /><span class='span_gmap_sel' onclick=SelStore('" + id + "');>到此门店领取合同信息</span>");
          });
          return marker;
        }
            $("#p2_sotres :input").each(function(i){
               var oneInfo = this.value.split('#');
               if(oneInfo[3]!=""&&oneInfo[4]!=""&&oneInfo[3]!="0"&&oneInfo[4]!="0")
                {
                    var point=new GLatLng(oneInfo[3],oneInfo[4]);
                    map.addOverlay(createMarker(point,i,oneInfo[1],oneInfo[2],oneInfo[0]));
                }
            });
      }
}

function SelStore(id)
{
    //alert(id);
    closeLayer();
    //alert(id);
    $("#p2_sotres :radio").each(function (j,item){
        if(item.value.substring(0,item.value.indexOf('#'))==id)
        {
            item.checked=true;
            return false;
        }
    });
    
}

function SubmitDeliver()
{
    if(Valid())
    {
        if(confirm("你的订单即将保存，请认真阅读支付页面的订单补充条款\n\n确认保存订单，并去支付吗？"))
        {
            Save(1);
        }
        else
        {
            if(confirm("只保存订单\n\n到订单管理中心?"))
            {
                Save(0);
            }
            else
            {
                alert("您的订单将不会保存，请检查信息后重新提交！");
            }
        }
    }

}

function Save(type)
{
    var deliInfo=new DeliverInfo();
    if($("#r1")[0].checked)
    {
        deliInfo.address=$("#p1_address").val();
        deliInfo.distribution="市内配送";
    }
//    if($("#r2")[0].checked)
//    {
//        $("#p2_sotres :radio").each(function(i){
//            if(this.checked)
//            {
//                deliInfo.address=this.value;
//                if(this.value.indexOf('#')>-1)
//                {
//                    deliInfo.address=this.value.split('#')[1];
//                }
//                return false;
//            }
//        });
//        deliInfo.distribution="门店自取";
//    }
    //    if($("#r3")[0].checked)
    //    {
    //        deliInfo.address=$("#p3_address").val();
    //        deliInfo.distribution="EMS邮递";
    //        deliInfo.tel=$("#tel").val();
    //        deliInfo.recipient=$("#recipient").val();
    //        deliInfo.zip=$("#zip").val();
    //    }
        deliInfo.memo= $("#amountComposition").val() + "&" + $("#tareaAdditional").val();
        var invoiceInfo=new InvoiceInfo();
//        if($("#rdo_inv_0")[0].checked)
//        {
            invoiceInfo.isNeed="true";
            invoiceInfo.title=$("#invTitle").val();
            invoiceInfo.type=$("#invType").val();
            invoiceInfo.notes=$("#invNotes").val();
//        }
//        else
//        {
//            invoiceInfo.isNeed="false";
//        }
        if(Valid())
        {
            //alert(deliInfo.toString());
            $("#loadSaveOrder")[0].click();

            $.post("SaveOrder.aspx",{
            baseAll:encodeURIComponent($("#hfBaseAll").val()),
            traffic:encodeURIComponent($("#hfTraffic").val()),
            hotel:encodeURIComponent($("#hfHotel").val()),
            singleItem:encodeURIComponent($("#hfSingleItem").val()),
            tours:encodeURIComponent($("#hfTours").val()),
            contact:encodeURIComponent($("#hfContact").val()),
            deliver:encodeURIComponent(deliInfo.toString()),
            invoice:encodeURIComponent(invoiceInfo.toString())
            },function(html){
                //alert(html);
                var arr=html.split("$$$");
               //alert(html);
                if(arr[0]=="SUC")
                {
                    closeLayer();
                    if(type==1)
                        location.href="pay.aspx?orderCode="+arr[1];
                    else
                        location.href="../user";
                }
                else
                {
                    closeLayer();
                    //alert("订单保存失败："+html);
                    $("#btnUserLogion")[0].click();
                }
                
            });
        }
}



function ToPay(orderNo,type)
{
    //alert($("#hfCldNo").val());
    $.ajax({
        url:"../WebService/pushOrder.aspx?orderNo=" + orderNo + "&type=" +type+"&cldNo=" + $("#hfCldNo").val(),
        cache:false,
        success:function(html){
            //alert(html);
            var arr=html.split("$$$");
            if(arr[0]=="SUC")
            {
                //alert(html);
                if(type=="33009")
                {
                    $("#test3")[0].click();
                    openwindow(decodeURIComponent(arr[2]),"alipay",1003,800);
                }
                else if(type=="33014")
                    openwindow(OpenPayFrom(orderNo,$("#hfCldNo").val()),"billpay",1003,800);
                else if(type=="33013")
                    openwindow("../booking/mmtPay.aspx?orderNo=" + orderNo+"&cldNo="+ $("#hfCldNo").val(),"mmtPay",1003,800);
                else if(type=="33033")
                    openwindow("../booking/tenpayApp.aspx?orderNo=" + orderNo+"&cldNo="+ $("#hfCldNo").val(),"tenpay",1003,800);

            }
            else
            {   
                if(arr[1]=="订单超时")
                {
                    alert("订单超时！");
                    this.location.href="../user/";
                }
                else if(arr[1]=="出境游")
                {
                    alert("占位失败,如遇到无法支付，请拨打客服热线400-820-1999进行咨询！");
                }
                else if(arr[1]=="订单总金额已全付")
                {
                    alert("订单金额已全付！");
                    this.location.href="../user/";
                }
                else 
                {
                    alert("占位失败，将返回订单页面！");
                    this.location.href="../user/";
                }
            }
        }
    });
    
}

/***************

***************/
function OpenPayFrom(orderNo,cldNo)
{
   var obj;    
    obj=document.getElementsByName("radiobutton");
    if(obj!=null){
        var i;
        for(i=0;i<obj.length;i++){
            if(obj[i].checked){
                document.getElementById("hfBankId").value=obj[i].value;              
            }
        }
       var url="../booking/send.aspx?orderNo="+orderNo+"&bankType="+document.getElementById("hfBankId").value+"&cldNo=" + cldNo;
       return url;
    }
    
}
function PayComplete(url)
{
    closeLayer();
    this.location.href=url;
}

function DisOrHide(obj)
{
    $("#"+obj).toggleClass("tab_detailOrder");
}

//OrderReserveOption.aspx 可选项改变时计算价格
function CalSelItem(obj)
{
    var value=$(obj).val();
    var tab=$(getObjTable(obj))[0];
    var rowNum=getRowNum(obj);
    var ddlDate=$(tab.rows(rowNum).cells(4)).find("select")[0];
    var price=tab.rows(rowNum).cells(2).innerText;
    
    var singleAmount=tab.rows(rowNum).cells(6).innerText;

    var total=parseInt(value)*parseInt(price);
    tab.rows(rowNum).cells(6).innerText=total;
    
    if(tab.rows(rowNum).cells(6).innerText=="0")
    {
        tab.rows(rowNum).cells(6).innerText="--";
    }
    
    var totalAmount=$("#lblAmount").text();

    if(parseInt(singleAmount)>0)
    {
        totalAmount=parseFloat(totalAmount)-parseInt(singleAmount);
    }
    document.getElementById("lblAmount").innerText=parseFloat(totalAmount)+parseInt(total);

}

//改变房型时计算价格
function CalSelRoom(obj)
{
    var value=$(obj).val();
    var tab=$(getObjTable(obj))[0];
    var rowNum=getRowNum(obj);
    var roomType=$(tab.rows(rowNum).cells(0)).find("select")[0];
    var price=tab.rows(rowNum).cells(3).innerText;
    if(price=="--")
        price="0";
    var totalAmount=$("#lblAmount").text();
    //alert(value);
    
    
    
}

//得到对象所在的行
function getRowObj(obj)
{

    obj=obj.parentNode.parentNode;
    return obj;
    

}

function getRowNum(obj)
{
    
    var trObj=getRowObj(obj);
       
    var trArr=trObj.parentNode.children;
    //alert(trArr.length);
    for(var trNo=0;trNo<trArr.length;trNo++)
    {
        if(trObj==trArr[trNo])
        {
            return trNo;
        }
    }
}
function getObjTable(obj)
{
    while(obj.tagName.toUpperCase()!="TABLE")
    {
        obj=obj.parentNode;
    }
    return obj;
}
function getObjTR(obj)
{
    while(obj.tagName.toUpperCase()!="TR")
    {
        obj=obj.parentNode;
    }
    return obj;
}

//OrderOption.aspx  选中可选项
function SelInsurance()
{
    
}

//OrderReserve.aspx  重新选择酒店
function ChangeHotel(str)
{
    //alert(str);
    var arr=str.split('|');
    window.open("ChangeHotel.aspx?hotelCode="+arr[0]+"&hotelTypeCode="+arr[1]+"&checkInDate="+arr[2]+"&checkOutDate="+arr[3]+"&row="+arr[4]+"&lineCode="+arr[5]+"&room="+arr[6]);
}

//ChangeHotel.aspx 
function HotelToOrder(hotelCode,RoomCode,RoomType,breakfast,roomNum,spread,obj)
{
    var tab1=getObjTable(obj);
    var tab2=getObjTable(tab1.parentNode);
    var tab3=getObjTable(tab2.parentNode);
    var tab4=getObjTable(tab3.parentNode);
    var roomTypeName=tab1.rows(0).cells(0).innerText;
    var breakfast=tab1.rows(0).cells(1).innerText;
    var maxAdult=tab1.rows(0).cells(2).innerText;
    var roomNum=tab1.rows(0).cells(3).innerText;
    var roomSpread=tab1.rows(0).cells(4).innerText;
    var hotelName=tab3.rows(0).cells(0).innerHTML;    
    var hotelContent=tab3.rows(1).cells(0).innerText;
    var hotelImg=tab4.rows(0).cells(0).innerHTML;
    //alert(hotelImg);
    var str=hotelCode+RoomCode+RoomType+breakfast+roomNum+spread;
    var row=$("#hfRow").val();
    if(window.opener)
    {
        var tab_hotel=window.opener.document.getElementById("pHotelInfo");
        
        $($(tab_hotel).find(".tab_content")[parseInt(row)]).find(".inTD")[0].innerHTML=hotelName;
        $($(tab_hotel).find(".td_img")[parseInt(row)])[0].innerHTML=hotelImg;
        $(tab_hotel).find(".tab_content")[parseInt(row)].rows(1).cells(0).innerText=hotelContent;
        var tab_room=$($(tab_hotel).find(".tab_content")[parseInt(row)]).find(".tab_room")[0];
        var ddl=$(tab_room.rows(1).cells(0)).find("select")[0];
        ddl.options.length=0;
       // var obi=new Option("房间","-1",true,true);
        var oitem=window.opener.document.createElement("option");
        oitem.text=roomTypeName;
        oitem.value=roomTypeName + ",0";
        ddl.options.add(oitem);
        //alert(ddl.options.length);
        //ddl.options.add(new Option("1","1"));
        var befPrice=tab_room.rows(1).cells(3).innerText;
        tab_room.rows(1).cells(1).innerText=breakfast;
        tab_room.rows(1).cells(2).innerText=roomNum;
        tab_room.rows(1).cells(3).innerText=roomSpread;
        //$(tab_room.rows(1).cells(4)).html("<img src=\"../sysImages/common/images/info1q2.gif\" width=\"22\" height=\"17\" /><input type=\"hidden\" id=\"hotelCode\" class=\"hfHotelCode\" value=\"" + hotelCode+"|"+ RoomCode + "\"  />");
        $(tab_room.rows(1).cells(3)).find(".hfHotelCode")[0].value=hotelCode+"|"+RoomCode;
        //alert($(tab_room.rows(1).cells(3)).find(".hfHotelCode")[0].value);
        var inputPrice = window.opener.document.getElementById("inputPrice").value;
        var addPrice=0;
        $(tab_hotel).find(".tab_room_dataRow").each(function(i){
            if(parseInt(row)!=i)
            {
                var onePrice=this.cells(3).innerText;
                if(onePrice!="--")
                {
                    if(onePrice.indexOf('+')>-1)
                    {
                        addPrice+=parseInt(onePrice.substring(1));
                    }
                    else if(onePrice.indexOf('-')>-1)
                    {
                        addPrice-=parseInt(onePrice.substring(1));
                    }
                }
            }
        });

        //alert(befPrice);
        if(befPrice=="--")
        {
            var temHc="@";
            //alert(11);
            var oldPrice=0;
            //alert(roomSpread);
            if(roomSpread=="--")
            {}
            else if(roomSpread.indexOf('+')>-1)
            {
                var p=parseInt(roomSpread.substring(1));
                var tot = parseInt(inputPrice)+parseInt(p)+addPrice;
                window.opener.document.getElementById("lblAmount1").innerText=tot;
                window.opener.document.getElementById("lblAmount").innerText=tot;
                temHc="@重选酒店：合计(" + tot + ") =原价(" + inputPrice + ") + 房差(" + p + ") + 酒店差价(" + addPrice + ")";
                window.opener.document.getElementById("amountComposition").innerText+=temHc;
            }
            else if(roomSpread.indexOf('-')>-1)
            {
                var p=parseInt(roomSpread.substring(1));
                var tot = parseInt(inputPrice)-parseInt(p);
                window.opener.document.getElementById("lblAmount1").innerText=tot;
                window.opener.document.getElementById("lblAmount").innerText=tot;
                temHc="@重选酒店：合计(" + tot + ") =原价(" + inputPrice + ") + 房差(" + p + ") + 酒店差价(" + addPrice + ")";
                window.opener.document.getElementById("amountComposition").innerText+=temHc;
            }
            
        }
        self.close();
        tab_hotel.focus();
    }
}

 //门店
 function GetStores(panel)
 {
    $.ajax({
        //url:"../WebService/GetStores.aspx",
        url:'../WebService/popCity.aspx?flag=3',
        cache:false,
        success:function(html){
            //alert(html);
            document.getElementById(panel).innerHTML=html;
        }
    });

 }
 //门店
function GetStoresValue(ID)
{
   //this.location.href="../stores/index.aspx?v_ID="+ID+"";
   window.open("../stores/index.aspx?v_ID="+ID,null);
}

function HidePanel(panel)
{
    var baseInfo=new BaseInfo();
    baseInfo.SetAll($("#hfBaseAll").val());
    //alert(baseInfo.businessTypeName);
    if(baseInfo.businessTypeName!="25005"||baseInfo.days=="1")
    {
       document.getElementById('btnNext').click();
       //document.getElementById(panel).style.display="none";
    }
}

function openwindow(url,name,iWidth,iHeight)
{
var url; //转向网页的地址;
var name; //网页名称，可为空;
var iWidth; //弹出窗口的宽度;
var iHeight; //弹出窗口的高度;
var iTop = (window.screen.availHeight-30-iHeight)/2; //获得窗口的垂直位置;
var iLeft = (window.screen.availWidth-10-iWidth)/2; //获得窗口的水平位置;
window.open(url,name,'height='+iHeight+',,innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=yes,menubar=yes,scrollbars=yes,resizeable=yes,location=no,status=yes');
}

function GoBack(num)
{
    history.go(num);
}
function GetvHelp()
{}

