<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Questionnaire_QueForm.aspx.cs"
    Inherits="RM.Web.Training.QuesNaire.Questionnaire_QueForm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Exam_infoedit")%></title>    
    <link href="/Themes/Styles/Site.css" rel="stylesheet" type="text/css" />
    <script src="/Themes/Scripts/jquery-1.8.2.min.js" type="text/javascript"></script>
    <script src="../../Themes/Scripts/jquery.form.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/Validator/JValidator.js" type="text/javascript"></script>
    <script src="../../Themes/Scripts/DatePicker/WdatePicker.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/artDialog/artDialog.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/artDialog/iframeTools.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/FunctionJS.js" type="text/javascript"></script>
    <style type="text/css">
        #uploadForm { position: absolute; bottom: 46px; left: 120px; }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <table border="0" cellpadding="0" cellspacing="0" class="frm" id="editTable">
        <tr>
            <th>
                <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Ques_tmmc")%>:                
            </th>
            <td colspan="3">
                <input id="Questions_Title" maxlength="35" runat="server" type="text" class="txt"
                    datacol="yes" err="题目名称" checkexpession="NotNull" style="width: 596px" />
            </td>
        </tr>
        <tr>
            <th>
                <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Question_item1")%>:                
            </th>
            <td>
                <input id="Questions_OptionOne" maxlength="400" runat="server" type="text" class="txt"
                    datacol="yes" err="选项1" style="width: 222px" />
            </td>
            <th>
                <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Question_item2")%>:
            </th>
            <td>
                <input id="Questions_OptionTwo" maxlength="400" runat="server" type="text" class="txt"
                    datacol="yes" err="选项2" style="width: 222px" />
            </td>
        </tr>
        <tr>
            <th>
                <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Question_item3")%>:
            </th>
            <td>
                <input id="Questions_OptionThree" maxlength="400" runat="server" type="text" class="txt"
                    datacol="yes" err="选项3" style="width: 222px" />
            </td>
            <th>
                <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Question_item4")%>:
            </th>
            <td>
                <input id="Questions_OptionFour" maxlength="400" runat="server" type="text" class="txt"
                    datacol="yes" err="选项4" style="width: 222px" />
            </td>
        </tr>
        <tr>
            <th>
                <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Question_item5")%>:
            </th>
            <td>
                <input id="Questions_OptionFive" maxlength="400" runat="server" type="text" class="txt"
                    datacol="yes" err="选项5" style="width: 222px" />
            </td>
            <th>
                <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Question_item6")%>:
            </th>
            <td>
                <input id="Questions_OptionSix" maxlength="400" runat="server" type="text" class="txt"
                    datacol="yes" err="选项6" style="width: 222px" />
            </td>
        </tr>
        <tr>
            <th>
                <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Question_item7")%>:
            </th>
            <td>
                <input id="Questions_OptionSeven" maxlength="400" runat="server" type="text" class="txt"
                    datacol="yes" err="选项7" style="width: 222px" />
            </td>
            <th>
                <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Question_item8")%>:
            </th>
            <td>
                <input id="Questions_OptionEight" maxlength="400" runat="server" type="text" class="txt"
                    datacol="yes" err="选项8" style="width: 222px" />
            </td>
        </tr>
        <tr>
            <th>
                <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Question_item9")%>:
            </th>
            <td>
                <input id="Questions_OptionNine" maxlength="400" runat="server" type="text" class="txt"
                    datacol="yes" err="选项9" style="width: 222px" />
            </td>
            <th>
                <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Question_item10")%>:
            </th>
            <td>
                <input id="Questions_OptionTen" maxlength="400" runat="server" type="text" class="txt"
                    datacol="yes" err="选项10" style="width: 222px" />
            </td>
        </tr>
        <tr>
            <th>
                <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Explain")%>:
            </th>
            <td colspan="3">
                <textarea id="Questions_Discription" class="txtRemark" runat="server" style="width: 596px;
                    height: 100px;"></textarea>
            </td>
        </tr>
        <tr>
            <th>
                <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Ques_uploadImg")%>：
            </th>
            <td colspan="3">
            </td>
        </tr>
    </table>
    <div class="frmbottom">
        <asp:LinkButton ID="Save" runat="server" class="l-btn" OnClientClick="return CheckDataValid('#form1');"
            OnClick="Save_Click"><span class="l-btn-left">
            <img src="/Themes/Images/disk.png" alt="" /><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Save")%></span></asp:LinkButton>
        <a class="l-btn" href="javascript:void(0)" onclick="OpenClose();"><span class="l-btn-left">
            <img src="/Themes/Images/cancel.png" alt="" /><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Close")%></span></a>
    </div>
    </form>
    <form method="post" action="" id="uploadForm" enctype="multipart/form-data">
    <input type="file" id="uploadImg" name="imgFile" /><span style="color: Red;">&nbsp;&nbsp;<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Question_selImg")%></span>
    </form>
</body>
</html>
<script type="text/javascript">
    $(function () {
        var $currFocusObj = $("#Questions_Discription"); //当前有焦点的对象
        $("#editTable input:not(#uploadImg),#editTable textarea").focus(function () {
            $currFocusObj = $(this);
        });
        //光标处插入图片
        var funGetSelected = function (element) {
            if (!window.getSelection) {
                //IE浏览器
                return document.selection.createRange().text;
            } else {
                return element.value.substr(element.selectionStart, element.selectionEnd - element.selectionStart);
            }
        }, funInsertTopic = function (textObj, textStr) {
            var topic = textStr, value = textObj.value, index = value.indexOf(topic);
            if (index === -1) {
                //匹配
                funTextAsTopic(textObj, topic);
            }
            value = textObj.value;
            index = value.indexOf(topic);
            if (textObj.createTextRange) {
                var range = textObj.createTextRange();
                range.moveEnd("character", (index + textStr.length) - value.length);
                range.moveStart("character", index);
                range.select();
            } else {
                textObj.setSelectionRange(index, index + textStr.length);
                textObj.focus();
            }
        }, funTextAsTopic = function (textObj, textFeildValue) {
            textObj.focus();
            if (textObj.createTextRange) {
                var caretPos = document.selection.createRange().duplicate();
                document.selection.empty();
                caretPos.text = textFeildValue;
            } else if (textObj.setSelectionRange) {
                var rangeStart = textObj.selectionStart;
                var rangeEnd = textObj.selectionEnd;
                var tempStr1 = textObj.value.substring(0, rangeStart);
                var tempStr2 = textObj.value.substring(rangeEnd);
                textObj.value = tempStr1 + textFeildValue + tempStr2;
                textObj.blur();
            }
        };
        $("#uploadImg").change(function () {
            var imgSrc = "";
            //上传图片
            var fileName = $(this).val(); //文件名
            if (fileName.length < 1) {//不合法
                showTipsMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("upload_pictures")%>', 2000, 3);
            } else {
                var extension = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length).toLowerCase(); //获取扩展名
                if (extension == "bmp" || extension == "jpg" || extension == "jpge" || extension == "gif") {//合法
                    $("#uploadForm").ajaxSubmit({
                        type: "post",
                        url: "/Training/TrainingTest/UploadImg.ashx",
                        success: function (data) {
                            if (data) {
                                switch (data) {
                                    case "1":
                                        showTipsMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("File_not")%>', 2000, 3);
                                        return;
                                    case "2":
                                        showTipsMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("File_size")%>', 2000, 3);
                                        return;
                                    case "3":
                                        showTipsMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("File_format")%>', 2000, 3);
                                        return;
                                    case "4":
                                        showTipsMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("File_Exam")%>', 2000, 5);                                        
                                        return;
                                    default:
                                        //插入图片
                                        var textObj = $currFocusObj.get(0);
                                        var textSelection = funGetSelected(textObj); //检测是否选择了文字
                                        if (!textSelection) {
                                            //没有文字选中，光标处插入
                                            funInsertTopic(textObj, '<div class="qid"><img src=' + data + ' alt=""  /></div> ');
                                        } else
                                            funTextAsTopic(textObj, '<div class="qid"><img src=' + data + ' alt=""  /></div> ');
                                        break;
                                }
                            } else {
                                showTipsMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("File_Exam")%>', 3000, 5);
                            }
                        }
                    });
                } else {
                    showTipsMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("File_format")%>', 2000, 3);
                }
            }
        });
    });
</script>
