<%= stylesheet_link_tag 'css/common'%>
<%= stylesheet_link_tag 'css/public'%>

<script type="text/javascript">
    $(document).ready(function(){
        $(".homepageSearchIcon").click(function(){
            var val=$('input:radio[name="search_type"]:checked').val();
            if(val==null){
                $("#navSearchAlert").css({display:"block"});
            }
            else {
                $("#navSearchAlert").css({display:"none"});
            }
        });
    });

    $(document).ready(function(){
        $(".navHomepageSearchBoxcontainer").mouseover(function(){
            $(".navSearchTypeBox").css({display:"block"});
        });
        $(".navHomepageSearchBoxcontainer").mouseout(function(){
            $(".navSearchTypeBox").css({display:"none"});
        });
    })
    $(document).ready(function(){
        if(<%= @login%>){
            $("#signUpBox").css({display:"none"});
            $("#loginInBox").css({display:"block"});
        }else{
            $("#signUpBox").css({display:"block"});
            $("#loginInBox").css({display:"none"});
        }
    });

    var $login_correct = false;
    var $mail_correct = false;
    var $passwd_correct = false;
    var $passwd_comfirm_correct = false;
    jQuery(document).ready(function () {
        var $login = $('#user_login')
        var $mail = $('#user_mail')
        var $password = $('#user_password')
        var $password_confirmation = $('#user_password_confirmation')
        $login.blur(function (event) {
            if ($(this).is('#user_login')) {
                $.get(
                        '<%=account_valid_ajax_path%>',
                        { valid: "login",
                            value: this.value },
                        function (data) {
                            if (data.valid) {
                                $('#login_req').html('<span style="color: green">'+data.message+'</span>');
                                $login_correct = true;
                            } else {
                                $('#login_req').html( '<span style="color: #c00202">'+data.message+'</span>');
                                $login_correct = false;
                            }
                            $('#login_req').css('display','block');
                        });
            }
            ;
        });

        $mail.blur(function (event) {
            if (/^[a-zA-Z0-9]+([._\\]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test(this.value) == false){
                $('#mail_req').html( '<span style="color: #c00202">邮件格式不对</span>').show();
                $mail_correct = false;
                return ;
            }
            if ($(this).is('#user_mail')) {
                $.get('<%=account_valid_ajax_path%>',
                        { valid: "mail",
                            value: this.value },
                        function (data) {
                            if (data.valid) {
                                $('#mail_req').html( '<span style="color: green">'+data.message+'</span>' );
                                 $mail_correct = true;
                            } else {
                                $('#mail_req').html( '<span style="color: #c00202">'+data.message+'</span>' );
                                 $mail_correct = false;
                            }
                            $('#mail_req').css('display','block');
                        });
            }
            ;
        });
        $password.blur(function () {
            var pas1 = document.getElementById("user_password").value;
            var password_min_length = <%= Setting.password_min_length.to_i %>
            if (pas1.length >= password_min_length) {
                $('#passwd_req').html('');
                 $passwd_correct = true;
            }
            else {
                $('#passwd_req').html( '<span style="color: #c00202">'+'<%= l(:setting_password_min_length_limit, :count => Setting.password_min_length.to_i) %>'+'</span>');
                 $passwd_correct = false;
            }
            $('#passwd_req').css('display','block');


        });
        $password_confirmation.blur(function () {
            var password_min_length = <%= Setting.password_min_length.to_i %>
            var pas1 = document.getElementById("user_password").value;
            var pas2 = document.getElementById("user_password_confirmation").value;
            if (pas1.length >= password_min_length && pas1 == pas2 ) {
                $('#confirm_req').html('<span style="color: green">'+'<%= l(:setting_password_success) %>'+'</span>');
                 $passwd_comfirm_correct = true;
            }
            else {
                $('#confirm_req').html('<span style="color: #c00202">'+'<%= l(:setting_password_error) %>'+'</span>');
                 $passwd_comfirm_correct = false;

            }
            $('#confirm_req').css('display','block');



        });
    });
</script>

<div class="new_login" id = "loginInBox">
  <div class="new_login_con">
    <div class="new_login_txt fl">
      <h3> 欢迎加入Trustie创新实践社区</h3>
      <p>在这里，您的创新意识和创新潜力将得到充分发挥！目前已有超过200所高校和科研机构在平台中开展在线协同开发、协同学习和协同研究。</p>
    </div>
    <div class="new_login_box fr mr45 mt100">
      <h2 class="new_login_h2">登录
        <a href="<%= register_url_without_domain %>" class="fr mt5">立即注册</a><div class="cl"></div>
      </h2>
      <div class="new_login_form">
        <%= form_tag(signin_path,:id=>'main_login_form',:method=>'post') do %>
            <%= back_url_hidden_field_tag %>
            <ul>
              <li class="new_loggin_users">
                <%= text_field_tag 'username', params[:username], :tabindex => '1', :class=>'new_loggin_input',:placeholder=>'请输入邮箱地址或登录名', :onkeypress => "user_name_keypress(event);"%>
              </li>
              <li class="new_login_lock">
                <%= password_field_tag 'password', nil, :tabindex => '2', :class => 'new_loggin_input' , :placeholder => '请输入登录密码', :onkeypress => "user_name_keypress(event);"%>
                <p class="new_login_error"><%= flash.empty? || flash[:error].nil? ? "" : flash[:error].html_safe  %></p>
              </li>

              <li>
                <% if Setting.autologin? %>
                    <label><%= check_box_tag 'autologin', 1, true, :tabindex => 4, :class => "new_login_check" %><%= l(:label_stay_logged_in) %></label>
                <% end %>
                <a href="<%= lost_password_path %>"  class="fr">
                  <% if Setting.lost_password? %>忘记密码<% end %>
                </a>
                <div class="cl"></div>
              </li>
              <li><button type="submit" class="new_login_submit"><a href="javascript:void(0);" id="login_btn" onclick="$('#main_login_form').submit();" style="text-decoration: none;">登录</a></button></li>
            </ul>
        <% end %>
      </div>

    </div>
    <div class="cl"></div>
  </div>
</div>
<%# 注册 %>
<div class="new_register" id = "signUpBox">
  <div class="new_register_con">
    <div class="new_login_txt fl new_register_left">
      <h3> 欢迎加入Trustie创新实践社区</h3>
      <p>在这里，您的创新意识和创新潜力将得到充分发挥！目前已有超过200所高校和科研机构在平台中开展在线协同开发、协同学习和协同研究。</p>
    </div>
    <div class="new_login_box fr mr45 mt50">
      <h2 class="new_login_h2">注册<a href="<%= signin_url_without_domain %>"  class="fr mt5">已有账号 请登录</a><div class="cl"></div></h2>
      <div class="new_login_form">
        <%= form_for :user, :url => register_path,:method=>'post', :html => {:id=>'main_reg_form'} do |f| %>
            <%= error_messages_for 'user' %>
            <ul>
              <li class="new_register_li">
                <%= f.text_field :mail, :size => 25, :class => 'new_register_input' , :placeholder => "请输入邮箱地址"%>
                <p class="new_login_error" id="mail_req" style="display: none"  >请输入正确的邮箱</p>
              </li>
              <li class="new_register_li">
                <%= f.password_field :password, :size => 25, :placeholder => "请输入密码", :class => 'new_register_input' %>
                <p class="new_login_error" id="passwd_req" style="display: none">请输入6-16位密码，区分大小写，不能使用空格！</p>
              </li>
              <li class="new_register_li">
                <%= f.password_field :password_confirmation, :size => 25, :placeholder => "请再次输入密码", :class=> 'new_register_input' %>
                <p class="new_login_error" id="confirm_req" style="display: none">两次密码不一致！</p>
              </li>
              <li class="new_register_li">
                <%= f.text_field :login, :size => 25, :placeholder => "请输入用户登录名", :class => 'new_register_input'%>
                <p class="new_login_error" id="login_req" style="display: none">用户登录名为2-18个中英文，数字或下划线</p>
              </li>
              <li>
                <label><input type="checkbox" checked id="read_and_confirm" onchange="changeRegisterBtn(this);" class=" new_login_check">我已阅读并接受<a href="<%= agreement_path %>"  >Trustie服务协议条款</a></label>
              </li>
              <li>
                <div class="new_login_submit" id="loginUpButton">
                  <a href="javascript:void(0);" id="regist_btn" onclick="register();" class ="db" style="text-decoration: none;">注册</a>
                </div>
            </ul>
        <% end %>
      </div>

    </div>
    <div class="cl"></div>
  </div>
</div>

