﻿//依赖文件 buycar/js/base.js, buycar/js/popUp.js

//个人用户收藏
//ct类别:1车辆2咨询3问题4置换
//cti收藏标题:
//ck:收藏页面Id
function collect(ct,cti,ck,callback)
{
  var url="../User/AddCollection.ashx?ct="+ ct + "&cti=" +cti + "&u="+location.href+"&ck=" + ck + "&"+Math.random();
  new Ajax.Request(url, {method:"get",onComplete:callback,evalScripts:true,asynchronous:true} ); 
}
//检查用户是否登录
//未登录:锁定当前页面,弹出登录界面
//登录:执行回调函数del
function CheckUserUserLogIn(del)
{
    bit.popUp.coping.load('showIdasdaaa','',250,30,'bgIedasdaa','#333',9999,1,'',onloadHTML(),function(){});
    var url="../ajaxPage/personAttention.ashx?t=checkLog&sj="+Math.round(Math.random()*10000);
    new Ajax.Request(url, {method:"get",onComplete:function callback(request){CheckLogInResult(request,del)},evalScripts:true,asynchronous:true} );
}
function onloadHTML()
{
    var html='';
    html +="<div>";
    html +="<img id=\"imgmiddle1\" src=\"http://img2.ucar.cn/ucar/image/ucar/ucar2009/buycar/onload.gif\" alt=\"正在加载\" />";
    html += "系统正在加载请稍后...";
    html += '</div>';
    return html;
}
//用户登录框
function outHTML(del)
{
     var html =''; 
//     html+="<div style=\"width:398px;height:208px;left:2px;bottom:29px;position: absolute;\" id=\"divUserLogin\">"
//     html+="<div  style=\"width:398px;height:208px;background:#B5C4E3;position:relative;\">";
//     html+="<div style=\"width:378px;height:198px;background:#fff;position:absolute;border:2px solid #94A4DF;top:-7px;left:-7px;text-align:left;padding:5px 10px;\">";
//     html+="<h2 style=\"height:35px;line-height:35px;font-size:14px;font-weight:normal;font-weight:bold;background:url(http://img1.ucar.cn/ucar/image/ucar/ucar2009/buycar/cyxx_xxt.gif) repeat-x left bottom;\">";
//     html+=" <span style=\"float:right;color:#002D7A;font-weight:normal;font-size:12px;margin-right:5px;cursor: pointer;\" onclick=\"bit.popUp.coping.clear('bgIedasda','showIdasdaa')\">关闭</span>会员登录</h2>";
     html+=" <p style=\"line-height:45px;\">";
     html+="<strong>提示：</strong>只有登录后才能保存你设置的关注。没有注册的用户请先<strong><a href=\"/User/reg.aspx?back=true\" class=\"mc_cola\">注册</a></strong></p>";
     html+="<div style=\"height:24px;line-height:24px;margin-bottom:5px;\">";
     html+="<samp style=\"width:90px;float:left;text-align:right;font-style:normal;font-weight:normal;margin-right:5px;\">";
     html+= "用户名：</samp>";
     html+= "<input type=\"text\" id='__txtuserName' style=\"width:208px;\"/>";
     html+= "</div>";
     html+= "<div class=\"height:24px;line-height:24px;margin-bottom:5px;\">";
     html+= "<samp style=\"width:90px;float:left;text-align:right;font-style:normal;font-weight:normal;margin-right:5px\">";
     html+= "密码：</samp>";
     html+= "<input id='__txtpwd' type=\"password\" style=\"width:208px;\"/>";
     html+= "</div>";
     html+="<div style=\"height:24px;line-height:24px;margin-bottom:5px;padding-left:96px;margin-top:8px;\">";
     html+=" <input type=\"button\" style=\"background:url(http://img3.ucar.cn/ucar/image/ucar/ucar2009/buycar/cyxx_bg13.gif) no-repeat left -78px;width:55px;height:23px;text-align:center;color:#fff;font-weight:bold;border:none;cursor:pointer;margin-right:20px;font-size:12px;\" value=\"登录\" onclick=\"userLogIn("+ del+ ");\" /> ";
     html+="<a href=\"/User/Findpwd.aspx\" class=\"mc_cola\">忘记密码？</a>";
     html+="</div>";
//     html+= "</div>";
//     html+= "</div>";
//     html+= "</div>";
     return html;
}
//回调函数
function CheckLogInResult(request,del)
{
    var result = request.responseText;
    bit.popUp.coping.clear('bgIedasdaa','showIdasdaaa')
    if(result=='true')
    {
         del(); 
    }
    else//未登录用户
    {
      bit.popUp.coping.load('showIdasdaa','会员登录',398,208,'bgIedasda','#333',9999,30,'popUpCss1',outHTML(del),function(){});
      document.getElementById("showIdasdaa").getElementsByTagName('label')[1].innerHTML='关闭';
    }
}
//用户登录
//del登录成功回调函数
function userLogIn(del)
{
    var name = $F('__txtuserName');
    var pwd = $F('__txtpwd');
    if(name=='')
    {
        alert('用户名不能为空');return;
    }
    if(pwd == '')
    {
     alert('密码不能为空');return;
    }
    var url="../ajaxPage/personAttention.ashx?t=login&username=" + escape(name) + "&pwd=" + pwd;
    new Ajax.Request(url, {method:"get",onComplete:function callback2(request){LogInResult(request,del)},evalScripts:true,asynchronous:true} ); 
}
//回调函数
function LogInResult(request,del)
{
    var result = request.responseText;
    if(result=='true')//登录成功
    {
       bit.popUp.coping.clear('bgIedasda','showIdasdaa');
       window.location.href=this.location.href;
    }
    else//登录失败
    {
      alert('登录失败，请重试！');
    }
}