﻿//网站地址
var webdns="http://"+location.host;

/******************************************** 定购单客户信息操作 ********************************************/
function iniOrderUserInfoForm(container,template,count)
{  
    container.innerHTML="";
    var reg=new RegExp("#num","g");
    for(var i=0;i<count;i++)
    {
        var tempTemplate=template;
        tempTemplate=tempTemplate.replace(reg,i);
        container.innerHTML+=tempTemplate;
    }
}
/******************************************** 定购单客户信息操作 ********************************************/


/******************************************** 首页js ********************************************/
function pageLoad()
{
   indexIsLogin();
   indexWeekOrderCount();
   indexDayOrderCount();
   indexShowSelect();
   indexShowGoSelect();
   indexShowVisaSelect();
   indexShowLoginSelect();
   indexShowSightSelect();
   clearfield();
}


/**控制搜索(右 1)内容的显示和隐藏,并且控制按钮的样式**/
function indexShowSelect()
{
   $(".i_sm li").click(function(){
     $(this).addClass("hovertab").siblings().removeClass("hovertab").addClass("normaltab");
     var i=$(".i_sm li").index(this);
     $(".search_div").eq(i).show().siblings(".search_div").hide();
   })
}

/**控制签证大洲的隐藏显示**/
function indexShowVisaSelect()
{
   $(".g_out li").mouseover(function(){
     $(this).addClass("active").siblings().removeClass("active");
     var i=$(".g_out li").index(this);
     $("#g_content div").eq(i).show().siblings("div").hide();
   })
}

/**控制景点或资讯的隐藏显示**/
function indexShowSightSelect() {
    $(".a_sight li").mouseover(function () {
        $(this).addClass("active").siblings().removeClass("active");
        var i = $(".a_sight li").index(this);
        $("#a_sight>div").eq(i).show().siblings("div").hide();
    })
}

/**控制登陆注册的隐藏显示**/
function indexShowLoginSelect()
{
    $(".l_title a").click(function(){
     $(this).addClass("active").siblings("a").removeClass("active");
     var i=$(".l_title a").index(this);
     $("div.l_main").eq(i).show().siblings(".l_main").hide();
   })
}

/**控制热门目的地国内国外的隐藏显示**/
function indexShowGoSelect()
{
   $(".v_continent li").mouseover(function(){
     $(this).addClass("active").siblings().removeClass("active");
     var i=$(".v_continent li").index(this);
     $("#v_content div").eq(i).show().siblings("div").hide();
   })
}

/**登陆**/
function indexLogin()
{
    if(validateValue('login'))
    {
        var uid=$("#txt_login_uid").val();
        var pwd=$("#txt_login_pwd").val();
        var code1=$("#txt_validatecode1").val();
        var url="Register/index-login.aspx?type=login&uid="+escape(uid)+"&pwd="+escape(pwd)+"&code="+code1;
        
        $.ajax({ url:url, type:"post", success: function(data){
               if(data=="true")
               {
                  location.href=location.href;
               }
               else if(data=="validatecode")
               {
                   alert("验证码错误，请重新输入！")
                   $("#txt_validatecode1").focus()
                   return false;
               }
               else
               {
                 location.href="Register/?goback=1"
               }
        }});
    }

}

/**快速注册**/
function indexRegister()
{
    if(validateValue('register'))
    {
        var tel=$("#txt_res_tel").val();
        var email=$("#txt_res_email").val();
        var code2=$("#txt_validatecode2").val();
        var url="Register/index-login.aspx?type=register&tel="+tel+"&email="+escape(email)+"&code="+code2;
        $.ajax({ url:url, type:"post", success: function(data){
               switch(data)
               {
                 case '0':
                     alert("抱歉，访问过程中出现错误，请返回重试，或联系我们的客服人员！");
                     return false;
                     break;
                 case '1':
                     alert("注册成功，谢谢！");
                     location.href=location.href;
                     break;
                 case '-1':
                     alert('抱歉，该手机号已经绑定！');
                     return false;
                     break;
                 case '-2':
                     alert("抱歉，该邮件地址已经存在！");
                     return false;
                     break;
                 case '-3':
                     alert("抱歉，该手机号已经绑定！");
                     return false;
                     break;
                 case '-4':
                     alert("验证码错误，请重新输入！");
                     return false;
                     break;
               }
        }});
    }
}

/*判断是否登录*/
function indexIsLogin()
{
    var url="Register/index-login.aspx?type=islogin";
      $.ajax({ url:url, type:"post", success: function(data){
          if(data!="")
          {
              $("#is_login").html(data);
              var str=indexGetDate();
              $("#i_uid").html(str+"，"+data);
              $("#i_login_div1").hide();
              $("#i_login_div2").show();
              $("#dis_register").hide();
              $("#dis_login").hide();
          }
          else
          {
               $("#is_login").html("");
               $("#dis_exit").hide();
          }
        }});
}

/*判断上下午*/
function indexGetDate()
{
    var str;
    now = new Date(),
    hour = now.getHours() 
    if(hour < 6){document.write("凌晨好！")} 
    else if (hour < 9){str="早上好"} 
    else if (hour < 12){str="上午好"} 
    else if (hour < 14){str="中午好"} 
    else if (hour < 17){str="下午好"} 
    else if (hour < 19){str="傍晚好"} 
    else if (hour < 22){str="晚上好"} 
    else {str="夜里好"} 
    return str;
}

/*周订单数*/
function indexWeekOrderCount()
{
    var url="Ordersearchlist/indexOrderCount.aspx?type=week";
    
      $.ajax({ url:url, type:"post", success: function(data){
               if(data!="")
               {
                   $("#week_order").html(data);
               }
               else
               {
                   $("#week_order").html();
               }
        }});
}

/*日订单数*/
function indexDayOrderCount()
{
    var url="Ordersearchlist/indexOrderCount.aspx?type=day";
    $.ajax({ url:url, type:"post", success: function(data){
           if(data!="")
           {
               $("#day_order").html(data);
           }
           else
           {
               $("#day_order").html();
           }
    }});
}

/*首页为什么要快速注册*/
function indexResHelp(type)
{

   if(type=='block')
   {
      $("#res_help").show();
   }
   else if(type='none')
   {
      $("#res_help").hide();
   }
}

//用户注销
function indexLogout()
{
    var url="Common/syns-logout.aspx";
     $.ajax({ url:url, type:"post", success: function(data){
            if(data==1)
            {
                location.href=location.href;
            }
        }});
}

//新写的首页查询 2010-4-22
function indexLineGroup(type)
{
    var url="";
    if(type=="line")
        url="Search/?scity=chufa1&title="+escape($("#txt_group_out").val())+"&days="+$("#txt_group_days1").val()+"&price="+$("#txt_group_price1").val()+"&type=line&style=2&size=10";
    else if(type=="diy")
        url="Search/?scity=chufa1&title="+escape($("#txt_group_in").val())+"&days="+$("#txt_group_days2").val()+"&price="+$("#txt_group_price2").val()+"&type=diy&style=2&size=10";       
    location.href=url;
}

//清除首页用户名文字
function clearfield()
{
   $("#txt_login_uid").focus(function(){
       if($(this).val()=="用户名/手机号/邮箱")
          $(this).val("").css("color","#000");
   })
}

//设置注册按钮的返回链接
function resReturnUrl()
{
   var returnUrl=escape(window.location.href);
   var url="http://www.51yougo.com/Register/signup.aspx?returnurl="+returnUrl;
   location.href=url;}

//编号搜索
function GetLineUrlByCode(type) {
    var lineCode = "";
    if(type=="line")
        lineCode = $("#txt_line_code").val();
    else if (type== "diy")
        lineCode = $("#txt_freeline_code").val();
    if (lineCode != "") {
        $.post("Search/SelectCodeAJAX.ashx", { code: lineCode, type: type }, function (data) {
            if (data != "")
                window.open(data);
            else
                alert("线路编号输入有误");
        })
    }
    else
        indexLineGroup(type);
}
/******************************************** 首页js ********************************************/


/******************************************** 签证部分 开始 ********************************************/
function visaOrderSumitValiate()
{
    return true;
}
function visaOrderSubmit()
{
    if(visaOrderSumitValiate())
    {
        document.getElementById("form1").method="post";
        document.getElementById("form1").action="order-detail.aspx";
        document.getElementById("form1").submit();
    }
}
/******************************************** 签证部分 结束********************************************/


/******************************************** 会员服务部分 开始 ********************************************/
function memberZoneloginValidate()
{
    return true;
}
function memberZoneRecoverPassword()
{
    return true;
}
function memberZonelogin()
{
    if(memberZoneloginValidate())
    {
        //发送数据并跳转
    }
}
function memberZoneRegister()
{
    location.href="../Register/signup.aspx";
}
function orderTravelNews(type)
{
    if(ValidateLength($("txt_email").value,1,100)&&ValidateEmail($("txt_email").value))
    {
        var email=$("txt_email").value;
        var url="syns-orderenews.aspx?email="+email+"&type="+type;
        new Ajax.Request(url ,{ method: 'post',postBody:'data=',onSuccess:function(req)
            {
                alert("订阅成功!");
                location.href='default.aspx';
            }
        });
    }
    else
        alert("请输入正确的邮箱地址!");
}
/******************************************** 会员服务部分 结束 ********************************************/


/******************************************** 礼品兑换 开始 ********************************************/

//兑换礼品
function exchangeGift(giftid,score)
{
    var bln=window.confirm("兑换该礼品将扣除您"+score+"积分,请确认!");
    if(bln)
    {
        var url="syns-exchangegift.aspx?giftid="+giftid;
        new Ajax.Request(url ,{ method: 'post',postBody:'data=',onSuccess:function(req)
            {
                var text=req.responseText.strip();
                if(text==0)
                    alert("您的积分不足,不能兑换该礼品!");
                else if(text==-1)
                    alert("请登录之后再进行操作!");
                else
                    alert("兑换成功!");
            }
        });
    }
}

/******************************************** 礼品兑换 结束 ********************************************/


/******************************************** 用户注销 开始 ********************************************/

//用户注销
function logout()
{
    var url=webdns+"/Common/syns-logout.aspx";
    new Ajax.Request(url ,{ method: 'post',postBody:'data=',onSuccess:function(req)
        {
            var text=req.responseText.strip();
            if(text=="1")
            {
//                $("span_menu").show();
//                $("span_user").innerHTML="";
                location.href=location.href;
            }
        }
    });
}

/******************************************** 用户注销 结束 ********************************************/

/*验证*/
//验证输入内容是否合法
function validateValue(type)
{
   if(type=='login')
   {
        var ret=ValidateLength($("#txt_login_uid").val(),1,14);
        if(!ret)
        {
            alert("用户名的长度必须在1－14个字符之间");
            $("#txt_login_uid").focus();
        }
        if(ret)
        {
            ret=ValidateLength($("#txt_login_pwd").val(),4,14);
            if(!ret)
            {
                alert("密码的长度必须在4－14个字符之间");
                 $("#txt_login_pwd").focus();
            }
        }
        return ret;
    }else if(type=='register')
    {
        var ret=(ValidateTel($("#txt_res_tel").val()));
        if(!ret)
        {
            alert("请输入正确格式的手机号码");
            $("#txt_res_tel").focus();
        }
        if(ret)
        {
             ret=(ValidateLength($("#txt_res_email").val(),-1,100)&&ValidateEmail($("#txt_res_email").val()));
            if(!ret)
            {
                alert("请输入正确格式的邮件地址,且长度不超过100个字符");
                $("#txt_res_email").focus();
            }    
        }
        return ret;
    }
}


