﻿function checkLogin()
{
    var userid;
    var pwd;
    var code;
    
    var obj = document.getElementById("username");
    userid =obj.value.replace(/\s/g,"");
    if(userid.length == 0)
    {
      alert("请输入用户名!");
      obj.focus();
      return false;
    }
    
    obj = document.getElementById("password");
    pwd = obj.value.replace(/\s/g,"");
    if(pwd.length == 0)
    {
      alert("请输入密码!");
      obj.focus();
      return false;
    }
    
    obj = document.getElementById("code");
    code = obj.value.replace(/\s/g,"");
    if(code.length == 0)
    {
      alert("请输入密码!");
      obj.focus();
      return false;
    }
    
    //检查登陆
    var rns = RemoteCourses_Default.checkLogin(userid,pwd,code).value;
    if(rns == "-2")
    {
        alert("验证码错误");
        return false;
    }else if(rns == "0")
    {
      alert("用户名或密码错误");
      return false;
    }
    else
    {
      //论坛登陆
      //theForm.action="http://bbs.newedu365.com/login.aspx?reurl="+location.href;
      //theForm.submit();
      location.href = location.href;
      return true;  
    }
    
}

function tryIt(val)
{
   //location.href="User/CourseWare.aspx?id=" + val + "&free=1" ;
   window.open("User/CourseWare.aspx?id=" + val + "&free=1","_blank"); 
    return false;
}

function buyIt(type,id,name,memberPrice)
{
    //var rn = RemoteCourses_Default.addShopCart(1," + dr["CourseWareId"].ToString() + ",'" + dr["CourseWareName"].ToString() + "'," + dr["MemberPrice"] + ").value; 
    var rn = RemoteCourses_Default.addShopCart(type,id,name,memberPrice).value;  
    if(rn == -1){alert('请先去登陆!');location.href ="/System/CheckLogin.aspx?url="+encodeURI(location.href);};
    if(rn == 3){
        alert('放入购物车成功');
        var w1 = window.open('/Shopping/ShopCart.aspx','shopcart');
        w1.location.reload(true);
    };
    if(rn == 2){
        alert('已存在购物车中');
    };
    if(rn == 4){
        alert('放入购物车失败');
    };
    if(rn == 5){
        alert('暂时无法购买,请刷新页面');
    };
    return false;
}

function addCPFavorite(id)
{
    var rns = RemoteCourses_Default.addFavoriteCP(id).value;
    if(rns == -1){alert('请先去登陆!');location.href ="/System/CheckLogin.aspx?url="+encodeURI(location.href);};
    if(rns == 1){
         alert('放入收藏夹成功');
         var w2 = window.open('/Myhome/Courses/sList.aspx','favorite');
         w2.location.reload(true);
      };
     
      if(rns == 99){alert('已存在收藏夹中');
       };
      
      if(rns == 98) {alert('放入收藏夹失败');};
      return false;
}

function addCFavorite(id)
{
    var rns = RemoteCourses_Default.addFavoriteC(id).value;
    if(rns == -1){alert('请先去登陆!');location.href ="/System/CheckLogin.aspx?url="+encodeURI(location.href);};
    if(rns == 1){alert('放入收藏夹成功');
    var w2 = window.open('/Myhome/Courses/sList.aspx','favorite');w2.location.reload(true);};
    if(rns == 99){alert('已存在收藏夹中');};
    if(rns == 98){alert('放入收藏夹失败');};
    return false;

}


function reLoadCode(val)
{
    val.src="../System/code.aspx?rand="+Math.random();
    return false;
}
function changeCursor(val)
{
    val.style.cursor="pointer";
}

function findPass()
{
    window.open("/System/FindPassword.aspx","_blank");
    return false;
}