
function ourphp_autoupload() {
	var haspicContainer = $(".has_pic").html();
	if (haspicContainer == null || haspicContainer == '') {
		haspicContainer= '<style type="text/css">.contentupload,.confirm {width:98%; background:#ffc798; height:30px; line-height:30px; padding:0 1%;}.contentupload b{float:left; margin-right:15px;}.autoupload{margin-top:9px;}</style><div class="has_pic"><input type="text" id="piclist" value="" style="display:none;"/><div class="contentupload"><b>发现您内容中的图片是外部链接地址，是否上传到本地服务器？</b>&nbsp;&nbsp;<label><input name="wateradd" class="autoupload" type="radio" value="0" checked="checked"/>&nbsp;无</label>&nbsp;&nbsp;<label><input name="wateradd" class="autoupload" type="radio" value="1" />&nbsp;图片水印</label>&nbsp;&nbsp;<label><input name="wateradd" class="autoupload" type="radio" value="2" />&nbsp;文字水印</label>&nbsp;&nbsp;<label><input name="wateradd" class="autoupload" type="radio" value="3" />&nbsp;OSS储存</label>&nbsp;&nbsp;<a href="javascript:uploadpic();">点击上传</a>&nbsp;&nbsp;<a href="javascript:closeupload();">关闭提示</a></div><div class="confirm"></div></div>';
		$(".ke-toolbar").after(haspicContainer);
	}	
    var img = $(".ke-edit-iframe").contents().find("img");
    var piccount = 0;
    var sstr = "";
    $(img).each(function (i) {
        var that = $(this);
        if (that.attr("src").indexOf("http://") >= 0 || that.attr("src").indexOf("https://") >= 0) {
            piccount++;
            if (i == $(img).length - 1)
                sstr += that.attr("src");
            else
                sstr += that.attr("src") + "|";
        }
    });
    $("#piclist").val(sstr);
    $(".confirm").hide();
	$(".has_pic").hide();
    if(piccount > 0)
	{
		$(".has_pic").show();
		$(".contentupload").show();
		$(".confirm").hide();
	}
}

function closeupload() {
    $(".has_pic").hide();
}
	
function uploadpic() {

	var wateradd = $('input[name="wateradd"]:checked').val();
	$(".contentupload").hide();
	$(".confirm").show();
	var token = localStorage.getItem("token");
	if(token == "" || token == null)
	{
		alert("上传失败！请换个浏览器重试！");
		return;
	}
    var piclist = encodeURI($("#piclist").val());
    if (piclist.length == 0) return ; false;

	var http = document.location.protocol;
	var weburl = window.location.host;
    $.ajax({
        url: http+"//"+weburl+"/function/editor/php/autoupload_json.php",
        data: {localUrl:piclist,wateradd:wateradd,token:token},
        type: "POST",
        dataType: "json",
        beforeSend: function () {
            $(".contentupload").hide();
            $(".confirm").text("正在上传中...");
        },
        success: function (msg) {
            if (msg.error == 1) {
                var str = new Array();
                str = msg.imglist.split('|');
                var img = $(".ke-edit-iframe").contents().find("img");
				
				for(ii=0;ii<str.length;ii++)
				{
					$(img).each(function (i) {
						var that = $(this);
						if (that.attr("src").indexOf("http://") >= 0 || that.attr("src").indexOf("https://") >= 0) {
							that.attr("src", str[ii]);
							that.attr("data-ke-src", str[ii]);
							console.log(i);
						}
					});				
				}


                $(".confirm").html(img.length + "张图片已经上传成功！&nbsp;&nbsp;<a href='javascript:closeupload();'>关闭</a>");
            }
            else $(".confirm").html(msg.msg + '<a href="javascript:closeupload();">关闭提示</a>');
        }
    });
	
}