/**
 * Created by W.J.Chang on 2014/7/24.
 */

define(function(require,exports) {
    function urlAccessCheck(url) {
        var def = $.Deferred();

        $.ajax({
            type: "POST",
            url: url,
            success: function (msg) {
                def.resolve(true);
            },
            timeout:5000,
            error:function(msg) {
                def.resolve(false);
            }
        });
        return def.promise();
    }

    function pingBaidu() {
        var def = $.Deferred();
        var url = "http://www.baidu.com";
        $.ajax({
            type: "POST",
            url: url,
            success: function (msg) {

                if(msg.indexOf('百度') >= 0) {
                    def.resolve(true);
                } else {
                    def.resolve(false);
                }

            },
            timeout:5000,
            error:function(msg) {
                def.resolve(false);
            }
        });
        return def.promise();
    }

    exports.pingBaidu = pingBaidu;
    exports.urlAccessCheck = urlAccessCheck;
});
