﻿function checkMobile(utel) {
    var mobile = utel;
    var reg1 = /^1[358]\d{9}$/;
    var my = false;
    if (reg1.test(mobile)) {
        my = true;
    }
    if (!my) {
        alert("请填写正确的手机号码");
        return false;
    }
    else {
        return true;
    }
    return true;
}

function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) {
                c_end = document.cookie.length;
            }
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

function xiazai() {
    var utel = document.getElementById("txt_tel").value;
    var ucid = getCookie("egouser=egouserid").split('|')[0];
    var cmsid = document.getElementById("hdd_cmsid").value;
    var id = document.getElementById("hdd_id").value;
    var name = getCookie("egouser=egouserid").split('|')[1];
    if (utel.length > 0) {
        if (ucid != "") {
            if (checkMobile(utel)) {
                LoadData('GET', '/api/smssend.aspx?action=xiazai&utel=' + escape(utel) + '&ucid=' + ucid + '&cmsid=' + cmsid + '&id=' + id + '&name=' + escape(name), true, 'xiazai');
            }
        }
        else {
            alert("请登录后下载");
            var strurl = location.href;
            window.location.href = "/membercenter/login.aspx?returnurl=" + strurl;
        }
    }
    else {
        alert("手机号码不能为空");
    }
}

function shoucang(type,contentid,cmsid) {
    var ucid = getCookie("egouser=egouserid").split('|')[0];
    if (ucid != "") {
        LoadData('GET', '/api/smssend.aspx?action=shoucang&type=' + type + '&ucid=' + ucid + '&contentid=' + contentid + '&cmsid=' + cmsid, true, 'xiazai');
    }
    else {
        alert("请登录后收藏");
        var strurl = location.href;
        window.location.href = "/membercenter/login.aspx?returnurl=" + strurl;
    }
}

function weibohuodongcanyu(activityid) {
    var ucid = getCookie("egouser=egouserid").split('|')[0];
    var strurl = location.href;
    if (ucid != "") {
        LoadData('GET', '/api/smssend.aspx?action=huodongcanyu&ucid=' + ucid + '&activityid=' + activityid + '&returnurl=' + strurl, true, 'huodongcanyu');
    }
    else {
        alert("请使用新浪微博账号快速登录后参与活动，如果使用其他方式登录将可能无法验证您的账号！");
        window.location.href = "/membercenter/login.aspx?returnurl=" + strurl;
    }
}

function huodonglingjiang(activityid,name,tel,address) {
    var ucid = getCookie("egouser=egouserid").split('|')[0];
    if (ucid != "") {
        LoadData('GET', '/api/smssend.aspx?action=huodonglingjiang&ucid=' + ucid + '&activityid=' + activityid + '&name=' + escape(name) + '&tel=' + escape(tel) + '&address=' + escape(address), true, 'huodonglingjiang');
    }
    else {
        alert("请登录后领奖");
        var strurl = location.href;
        window.location.href = "/membercenter/login.aspx?returnurl=" + strurl;
    }
}

function huodongguanzhu() {
    var id = document.getElementById("hdd_id").value;
    LoadData1('GET', '/api/smssend.aspx?action=huodongguanzhu&id=' + id, true, 'huodongguanzhu');
}

function huodongcanyu() {
    var ucid = getCookie("egouser=egouserid").split('|')[0];
    var name = document.getElementById("txt_name").value;
    var utel = document.getElementById("txt_tel").value;
    var id = document.getElementById("hdd_id").value;
    LoadData('GET', '/api/smssend.aspx?action=huodongcanyu&ucid=' + ucid + '&activityid=' + id + '&name=' + escape(name) + '&tel=' + escape(utel), true, 'huodongcanyu');
}

function loadofferlist(num) {
    LoadData('GET', '/api/smssend.aspx?action=loadofferlist&num=' + num, true, 'loadofferlist');
}

function LoadData(methodstr,url,flag,actionstr)
{
    var xmlHTTP=null;
    if (window.ActiveXObject) {
        try {
            xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e1) {
            xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP");
        }
    }
    else if (window.XMLHttpRequest) {
        xmlHTTP = new XMLHttpRequest();
    }
    xmlHTTP.open(methodstr, url, flag);
    xmlHTTP.onreadystatechange = function () { handleResponse(xmlHTTP, actionstr) };
    document.getElementById("sumbit_yanzheng").innerHTML = "<img src=\"http://www.ego.com.cn/images/animated_loading.gif\" align=\"absmiddle\" />";
    xmlHTTP.send(null);
}

function LoadData1(methodstr, url, flag, actionstr) {
    var xmlHTTP = null;
    if (window.ActiveXObject) {
        try {
            xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e1) {
            xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP");
        }
    }
    else if (window.XMLHttpRequest) {
        xmlHTTP = new XMLHttpRequest();
    }
    xmlHTTP.open(methodstr, url, flag);
    xmlHTTP.onreadystatechange = function () { handleResponse(xmlHTTP, actionstr) };
    document.getElementById("sumbit_yanzheng1").innerHTML = "<img src=\"http://www.ego.com.cn/images/animated_loading.gif\" align=\"absmiddle\" />";
    xmlHTTP.send(null);
}

function handleResponse(obj,actionstr)
{
    if (obj.readyState == 4)
    {
        if (obj.status == 200)
        { 
            switch (actionstr)
            {
                case "xiazai":
                    document.getElementById("sumbit_yanzheng").innerHTML = obj.responseText;
                    break;
                case "shoucang": 
                    alert(obj.responseText);
                    document.getElementById("sumbit_yanzheng").innerHTML = obj.responseText;
                    break;
                case "weibohuodongcanyu":
                    if (obj.responseText == 1) {
                        document.getElementById("sumbit_yanzheng").innerHTML = "";
                        alert("参与成功");
                        var url = 'http://service.weibo.com/share/share.php?url=http%3A%2F%2Fwww.ego.com.cn%2Fhuodong%2F&appkey=762109970&title=12580%E9%83%BD%E5%B8%82%E6%B6%88%E8%B4%B9%E7%BA%BF%E4%B8%8A%E4%BD%8E%E8%B0%83%E6%B4%BE%E5%8F%91%EF%BC%81%E4%BD%A0hold%E4%B8%8D%E4%BD%8F%EF%BC%81&pic=&ralateUid=2247398734';
                        window.open(url);
                    }
                    else if (obj.responseText == 0) {
                        alert("请使用新浪微博账号快速登录后参与活动，如果使用其他方式登录将可能无法验证您的账号！");
                        var strurl = location.href;
                        window.location.href = "/membercenter/login.aspx?returnurl=" + strurl;
                    }
                    else {
                        document.getElementById("sumbit_yanzheng").innerHTML = "";
                        alert(obj.responseText);
                    }
                    break;
                case "huodonglingjiang":
                    if (obj.responseText == 1) {
                        document.getElementById("sumbit_yanzheng").innerHTML = "";
                        alert("领取成功，请等待客服与您联系");
                    }
                    else {
                        document.getElementById("sumbit_yanzheng").innerHTML = "";
                        alert(obj.responseText);
                    }
                    break;
                case "huodongcanyu":
                    if (obj.responseText == 1) {
                        document.getElementById("sumbit_yanzheng").innerHTML = "报名成功";
                    }
                    else {
                        document.getElementById("sumbit_yanzheng").innerHTML = obj.responseText;
                    }
                    break;
                case "huodongguanzhu":
                    if (obj.responseText == 1) {
                        document.getElementById("sumbit_yanzheng1").innerHTML = "关注成功";
                    }
                    else {
                        document.getElementById("sumbit_yanzheng1").innerHTML = obj.responseText;
                    }
                    break;
                case "loadofferlist":
                    document.getElementById("sumbit_yanzheng").innerHTML = obj.responseText;
                    break;
            }
        }
    }
}
