<h2 class="winbox_h2">添加新的高校（单位）</h2>
<div class="cl"></div>
<ul class="winbox_edit_new">
<li>
  <label class="fl"><span class="c_red mr5">*</span>名称：</label>
  <input id = "schoolname" type="text" class="winbox_input fl" onBlur = 'ifNameRepeat()' onFocus = '$("#schoolrepeatnotice").text("");$("#schoolrepeatnotice").attr("value",1);$("#schoolrepeatnotice").hide(); '/>
  <span class="ml2" id="schoolrepeatnotice" style="color:red;" display="none"></span>
</li>
<li>
  <label class="fl">&nbsp;&nbsp;</label>
  <span class="fl">例如：</span><span class="icons_right fl mt5 "></span><span class="fl">国防科学技术大学</span>
  <span class="icons_error fl mt5 ml10"></span><span class="fl">国防科大计算机1班</span>
</li>
<li>
  <label class="fl"><span class="c_red mr5">*</span>地区：</label>
    <select onchange="showcity(this.value, document.getElementById('schoolCity'));" name="province" id="schollProvince" class="winbox_select fl" style="height:28px;margin-left:2px;">
      <option value="">--请选择省份--</option>
      <option value="北京">北京</option>
      <option value="上海">上海</option>
      <option value="广东">广东</option>
      <option value="江苏">江苏</option>
      <option value="浙江">浙江</option>
      <option value="重庆">重庆</option>
      <option value="安徽">安徽</option>
      <option value="福建">福建</option>
      <option value="甘肃">甘肃</option>
      <option value="广西">广西</option>
      <option value="贵州">贵州</option>
      <option value="海南">海南</option>
      <option value="河北">河北</option>
      <option value="黑龙江">黑龙江</option>
      <option value="河南">河南</option>
      <option value="湖北">湖北</option>
      <option value="湖南">湖南</option>
      <option value="江西">江西</option>
      <option value="吉林">吉林</option>
      <option value="辽宁">辽宁</option>
      <option value="内蒙古">内蒙古</option>
      <option value="宁夏">宁夏</option>
      <option value="青海">青海</option>
      <option value="山东">山东</option>
      <option value="山西">山西</option>
      <option value="陕西">陕西</option>
      <option value="四川">四川</option>
      <option value="天津">天津</option>
      <option value="新疆">新疆</option>
      <option value="西藏">西藏</option>
      <option value="云南">云南</option>
      <option value="香港">香港特别行政区</option>
      <option value="澳门">澳门特别行政区</option>
      <option value="台湾">台湾</option>
      <option value="海外">海外</option>
    </select>
    <select name="city" id="schoolCity" class="winbox_select fl ml5" style="height:28px;"></select>
    <span class="ml2" id="provincenotice" style="color:red;" display="none"></span>
</li>
<li>
  <label class="fl"><span class="c_red mr5">*</span>详细地址：</label><input id="address" type="text" class="winbox_input fl" />
  <span class="ml2" id="addressnotice" style="color:red;" display="none"></span>
</li>
<li><label class="fl">说明：</label><textarea id = "remarks" class="winbox_textarea fl" placeholder="如果您有特别需要说明的内容请填入"></textarea></li>
<div class="cl"></div>
<li><label class="fl">&nbsp;&nbsp;</label><button id="apply_school" class="fl winbox_btn_blue mt10">确定</button></li>
</ul>

<script type="text/javascript">
    function commit_add_school(){
        var name,province,city,address,remarks;

        name = $("#schoolname").val();
        province = $("#schollProvince").val();
        address = $("#address").val();

        if(name == ""){
            $("#schoolname").focus();
            return;
        }
        if($("#schoolrepeatnotice").attr("value") == "1"){
            return;
        }
        if(province == ""){
            $("#provincenotice").text("请选择");
            $("#provincenotice").show();
            return;
        }
        city = $("#schoolCity").val();
        if(city == ""){
            return;
        }

        if(address == ""){
            $("#address").focus();
            return;
        }

        remarks = $("#remarks").val();

        $.ajax({
                url: '/school/apply_add_school',
                type: 'get',
                data: {name:name,province:province,city:city,address:address,remarks:remarks},
                success: function(data){
                    if(data.result == 0){
                        $("input[name='province']").val(data.name);
                        $("input[name='occupation']").val(data.school_id);
                        var htmlvalue = "</br><div style='width:550px;text-align:center'>添加成功！您可以继续使用了。</div></br><div style='width:550px;text-align:center'>后续我们将对您的高校（单位）进行审核，如有问题我们再联系您。</div></br><div style='width:67px; margin:0 auto; text-align:center'></div>";
                        //$('#province').onload();
                        //$('#my_account_form_link').click();
                        pop_up_box(htmlvalue,500,30,50);
                    }
                    else if (data.result == 1){
                    }
                    else if (data.result == 2){
                        $("#schoolrepeatnotice").text("名称已存在");
                        $("#schoolrepeatnotice").show();
                        $("#schoolrepeatnotice").attr("value",1);
                        $("#schoolrepeatnotice").attr("style","color:red");
                    }
                    return;
                }
        });
    }
    function pop_up_box(value,tWidth,tTop,tLeft){

        if(!tWidth){
            var tWidth = 580;
        }

        if(!tTop){
            var tTop = 30;
        }

        if(!tLeft){
            var tLeft = 50;
        }

        $("#ajax-modal").html(value);
        showModal('ajax-modal', tWidth + "px");
        $('#ajax-modal').siblings().remove();
        $('#ajax-modal').before("<a href='javascript:void(0)' onclick='hideModal(); my_account_form_submit();' style='margin-right: 5px; margin-top:-10px;right:0;' class='resourceClose'></a>");
        $('#ajax-modal').parent().css("top", tTop+"%").css("left", tLeft+"%").css("padding-top", "10px").css("position", "fixed");
        $('#ajax-modal').parent().addClass("resourceUploadPopup");
        $('#ajax-modal').css("padding-left", "16px").css("padding-bottom", "16px");

        function hideModal(){
            $('#ajax-modal').hide();
        }
    }
    function ifNameRepeat(){

        //名称不能为空也不能重复
        if($("#schoolname").val() == ""){
            return;
        }

        $.ajax({
            url: '/school/search_repeat_schoolname',
            type: 'get',
            data: {name:$("#schoolname").val()},
            success: function(data){
                if (data == 1){
                    $("#schoolrepeatnotice").text("名称已存在");
                    $("#schoolrepeatnotice").show();
                    $("#schoolrepeatnotice").attr("value",1);
                    $("#schoolrepeatnotice").attr("style","color:red");
                }
                else{
                    $("#schoolrepeatnotice").text("可用");
                    $("#schoolrepeatnotice").show();
                    $("#schoolrepeatnotice").attr("value",0);
                    $("#schoolrepeatnotice").attr("style","color:green");
                }
            }
        });
    }

    $('#apply_school').on("click",(function(e){
        commit_add_school();
    }));
</script>
