﻿//跨浏览器获取XmlHttpRequest对象
function AjaxXmlHttpRequest() {
    var xmlHttp;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    }
    catch (e) {

        // Internet Explorer
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {

            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {
                alert("您的浏览器不支持AJAX！");
                return false;
            }
        }
    }
    return xmlHttp;
}


function addBlogStar(BlogId, BlogRate) {

    var xhr = new AjaxXmlHttpRequest();

    //                var session = <%=Session["UID"]==null?1:2%>
    //                if(session==1)
    //                {
    //                    alert('Please login or register to proceed.！');
    //                    return;
    //                }
    xhr.onreadystatechange = function() {
        if (xhr.readyState == 4) {
            if (xhr.responseText == 1) {
                alert('Thank you! ');
                window.location.reload();

            }
            else {
                alert('Fail ! ');
            }

        }
    }
    xhr.open("GET", "../Js/AjaxBlog.aspx?BlogId=" + BlogId + "&BlogRate=" + BlogRate + "&date=" + new Date(), true);
    // xhr.onreadystatechange = updatePage;

    xhr.send(null);
}


function addNewLetter(email) {

    var xhr = new AjaxXmlHttpRequest();


    xhr.onreadystatechange = function() {
        if (xhr.readyState == 4) {
            if (xhr.responseText == 1) {
                alert('Please enter your email address.');
                return;

            }
            else if (xhr.responseText == 2) {

                alert('This is a wrong email format, please reenter your email address.');
                return;
            }
            else if (xhr.responseText == 3) {

                alert('Sorry, this email address has already been used to subscribe to My Local Store\'s newsletters.');
                return;
            }
            else if (xhr.responseText == 4) {

                alert('Thank you for subscribing our My Local Store newletter. Please check your inbox for your confirmation letter.');
                return;
            }
            else {
                alert('Fail ! ');
            }

        }
    }
    xhr.open("GET", "../Js/AjaxBlog.aspx?Email=" + email + "&date=" + new Date(), true);
    // xhr.onreadystatechange = updatePage;

    xhr.send(null);
}


