/// <reference path="jquery-1.10.2.min.js" />
var canvas, context;
var ids = 1;

$(function () {
    draw();
    $("#Tort_Cv_Code").click(function () {
        context.clearRect(0, 0, 120, 40);
        draw();

    })

    $("#Tort_btn").click(function (e) {
        e.preventDefault();
        var Tort_Name = $.trim($("#Tort_Name").val());
        var Tort_Link = $.trim($("#Tort_Link").val());
        var pContent = $.trim($("#pContent").val());
        var imgSelf = $.trim($("#imgSelf").attr("src"));
        var imgSelfs = $.trim($("#imgSelfs").attr("src"));
        var imgSelfss = $.trim($("#imgSelfss").attr("src"));
        var Tort_Txtcode = $.trim($("#Tort_Txtcode").val());
        var TortLink = /^((https|http|ftp|rtsp|mms)?:\/\/)[^\s]+/;
        if (Tort_Txtcode == "") {
            alert("验证码不能为空");
            return;

        } else if (Tort_Txtcode.toUpperCase() != $.cookie('logincode')) {
            alert("验证码不正确");
            return;

        } if (Tort_Name == "") {
            alert("侵权名称不能为空");
            return;

        }
        if (Tort_Link == "") {
            alert("侵权链接不能为空");
            return;
        }
        if (!TortLink.test(Tort_Link)) {
            alert("对不起，你输入的侵权链接不正确");
            return;
        }
        $.post("/ajax/Overall.ashx", { "type": "Tort", "Tort_Name": Tort_Name, "Tort_Link": Tort_Link, "pContent": pContent, "imgSelf": imgSelf, "imgSelfs": imgSelfs, "imgSelfss": imgSelfss, "ids": ids }, function (data) {
            var data = eval('(' + data + ')');
            if (data.Success == true) {
                alert("感谢你的提交，我们将在1-3工作日进行处理，请耐心等待！！！");
                location.reload();

            } else {
                alert("提交失败")

            } if (data.Success == false) {
                alert("不能重复在提交哦，我们已经在处理你的问题了！！！")

            }







        })





    })


})



function draw() {
    $.cookie('logincode', null, { path: '/' });
    canvas = document.getElementById("Tort_Cv_Code");
    context = canvas.getContext("2d");
    canvas.width = 120;
    canvas.height = 40;
    context.strokeStyle = "#009688";
    context.strokeRect(0, 0, 120, 40);
    var scode = "";
    var aCode = "A,B,C,E,F,G,H,J,K,L,M,N,P,Q,R,S,T,W,X,Y,1,2,3,4,5,6,7,8,9";
    var aLength = aCode.split(",").length;
    for (var i = 0; i <= 3; i++) {
        var x = 20 + i * 20;
        var y = 20 + Math.random() * 10;
        var j = Math.floor(Math.random() * aLength);
        var deg = Math.random() * 90 * Math.PI / 180;//随机弧度
        txt = aCode.split(",")[j];
        scode += txt;
        context.fillStyle = randomRgbColor();
        context.font = "bold 20px 微软雅黑";
        //修改坐标原点和旋转角度
        context.translate(x, y);
        context.rotate(deg);
        context.fillText(txt, 0, 0);
        //恢复坐标原点和旋转角度
        context.rotate(-deg);
        context.translate(-x, -y);
    }
    $.cookie('logincode', scode, { path: '/' });
    //干扰线
    for (var i = 0; i < 8; i++) {
        context.strokeStyle = randomRgbColor();
        context.beginPath();
        context.moveTo(Math.random() * 120, Math.random() * 40);
        context.lineTo(Math.random() * 120, Math.random() * 40);
        context.stroke();
    }
    /**绘制干扰点**/
    for (var i = 0; i < 10; i++) {
        context.fillStyle = randomRgbColor();
        context.beginPath();
        context.arc(Math.random() * 120, Math.random() * 40, 1, 0, 2 * Math.PI);
        context.fill();
    }
}
function randomRgbColor() { //随机生成RGB颜色
    var r = Math.floor(Math.random() * 256); //随机生成256以内r值
    var g = Math.floor(Math.random() * 256); //随机生成256以内g值
    var b = Math.floor(Math.random() * 256); //随机生成256以内b值
    return "rgb(" + r + "," + g + "," + b + ")"; //返回rgb(r,g,b)格式颜色
}
