<%@ page extends="oneit.servlets.jsp.JSPInclude" %>

<%@ include file="/inc/stdimports50.jsp" %><%-- This is in cougar --%>
<%@ include file="/inc/stdcms.jsp" %><%-- This is in cougar --%>
<%@ include file="/extensions/performa/inc/stdimports.jsp" %>

<oneit:dynIncluded>
<%
    SecUser     loggedInUser    =   SecUser.getTXUser(transaction);
    CompanyUser companyUser     =   loggedInUser.getExtension(CompanyUser.REFERENCE_CompanyUser);
    Company     company         =   companyUser.getCompany();
    HiringTeam  hiringTeam      =   (HiringTeam) process.getAttribute("HiringTeam");
    String      nextPage        =   WebUtils.getSamePageInRenderMode(request, "Page");
    
    Debug.assertion(company != null , "Invalid company in admin portal my company");

    Debug.assertion(hiringTeam != null , "Invalid hiring team in admin portal my company");
    
    boolean     readOnly        =   hiringTeam.getObjectWriteability() == FieldWriteability.NOT_IN_GUI;
    boolean     assumedUser     =   Utils.isAssumedUser(request);
%>

    <script type="text/javascript">
        var PopupAlert = null;
        var PopupMsg = null;
        $(document).ready(function()
        {
            recalcFunction = setupRecalc ($("form#editCompany"), {'recalcOnError':true});
            
            PopupMsg = new jBox('Modal', {
                   id : "msg-pop",
                   overlay : true, 
                   width :600, height : 450
                   });   

            PopupAlert = new jBox('Modal', {
                   id : "alert-pop",
                   overlay : true, 
                   width : 350, height : 320
                   });            
         
            
            $("#upload").change(function(){
                readURL(this);
            });

            $("#remove-logo").click(function(){
                removeLogo();
            });
            
            var currSelected = $(".own-billing input:checked").val();
           
            $(".own-billing input").change(function(){
                if (currSelected!==$(this).val()){
                
                    if($(this).val()==='true'){
                        PopupMsg.setContent($("#manage-own-billing-alert"));
                        PopupMsg.open();        
                    }else{
                        PopupMsg.setContent($("#manage-other-billing-alert"));
                        PopupMsg.open();  
                    }
                    
                    currSelected = $(this).val();
                    disableOutSideLinks();
                }
            });
            
            $(".own-billing-alert-close-button").on("click",function(){             
                PopupMsg.close();
            });  
            
            $(".force-alert-close-button").on("click",function(){             
                PopupAlert.close();
            });  
            
            $('input[type="text"][id$="Industry"]').blur(function(){
                if($(this).next().val() === ""){
                   $(this).val('');
                }
            });
            
            $('input[type="text"][id$="Industry"]').attr('placeholder','Please select an Industry');
            
            var hasDiversity    = $(".has-diversity input:checked").val();
           
            $(".has-diversity input").change(function(){
                if (hasDiversity !== $(this).val()){
                    if($(this).val()==='true'){
                        $("button[name$='changeDiversity']").click();        
                    }
                    hasDiversity = $(this).val();
                }
            });
        });
        
    function disableOutSideLinks(){
       $("a ").each(function(){
           if ( !$(this).parents(".form-content-wrap").length) { 
               if($(this).prop("tagName") === "A"){
                   $(this).prop("onclick", null).off("click");
                   $(this).css("cursor","arrow").click(function(){
                        if ($(this).hasClass("own-billing-alert-close-button")){  
                            PopupMsg.close();
                        }
                        else if ($(this).hasClass("force-alert-close-button")){  
                              PopupAlert.close();
                        }else{
                            PopupAlert.setContent($("#force-to-choose-popup"));    
                            PopupAlert.open();       
                            return false;
                        }

                   });
               }

           }
       });
   }
    </script>    
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places&key=AIzaSyCaBh-MsMb8BBYJD_NcFzoCmygQbt5-QSw"></script>
    <oneit:script>
        <oneit:script src="/scripts/google_address.js"/>
    </oneit:script>
    <style>
        #overlay {
            position: fixed;
            width: 100%;
            height: 100%;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: rgba(0,0,0,0.5);
            z-index: 99999;
            cursor: pointer;
        }
        .welcome-pop-top {
            margin-top: 20%;
        }
        .main-welcome-popup h2 {
            padding: 0 20px 0;
        }
        .form-control.no-border {
            border: 0 !important;
        }
        .disabled-question{
            color:#908e8e;
            padding-left: 10px;
        }
    </style>
    <div class="container-fluid">
        <div class="row content">
            <div class="main-content-area">
                <oneit:form name="editCompany"  method="post"    enctype="multipart/form-data">
                    
                    <h1 class="page-title page-title-with-arrow">
                        <oneit:button cssClass="arrow-btn-blue"  name="gotoPage" value=" " skin="link"
                                    requestAttribs="<%= CollectionUtils.mapEntry("nextPage", nextPage)         
                                                                        .mapEntry("cancelProcess", true)
                                                                        .toMap() %>">
                            <img src="images/arrow-left-prev_blue.svg" />
                        </oneit:button>
                        <%= hiringTeam.getHiringTeamName() %>
                    </h1>
                    
                    <div class="my-company-area">
                        <div style="padding-left: 15px; padding-right: 15px;">
                            <oneit:dynInclude   page="/extensions/applicantportal/inc/multifieldtext.jsp"   data="<%= CollectionUtils.EMPTY_MAP%>"/>
                        </div>
                        
                        <oneit:dynInclude   page="/extensions/adminportal/inc/my_company_tabs.jsp"    TabNumber="1"    data="<%= CollectionUtils.EMPTY_MAP%>"/>

                        <div class="company-content-area">
                            <!-- Tab panes -->
                            <div class="tab-content form-content-wrap">
                                <div class="tab-pane active" id="company-detail">
                                    <div class="tabpage-title">
                                        <label class="label-20">Team Details</label>                
                                    </div>              
                                    <div class="form-group">
                                        <label><oneit:ormlabel  obj="<%= hiringTeam %>" field="HiringTeamName" /></label>
                                        <oneit:ormInput obj="<%= hiringTeam %>"    type="text" attributeName="HiringTeamName" cssClass="form-control"   displayType="autocomplete"/>                                
                                    </div>
                                    <div class="form-group">
                                        <label><oneit:ormlabel  obj="<%= hiringTeam %>" field="HiringTeamLogo" /></label>
                                        <div class="main-upload-logo">
                                            <span class="u-img-tag" style="<%= hiringTeam.getHiringTeamLogo() != null ? "" : "display: none" %>">
                                                <tagfile:img    src="<%= ThumbnailUtils.filterImage(DiskFileBinaryContent.getRelativeURL(hiringTeam.getHiringTeamLogo()), "KEEP", new ScaleWithin (0,90)) %>"
                                                                class="upload-img-w-h"  id="client-logo"/>
                                            <%
                                                if(hiringTeam.getObjectWriteability() != FieldWriteability.NOT_IN_GUI)
                                                {
                                            %>
                                                    <span class="remove-logo-btn">
                                                        <img src="images/logo-remove-btn.png" id="remove-logo">
                                                        <oneit:ormInput obj="<%= hiringTeam %>" type="text" attributeName="IsLogoDeleted"  style="display:none;" />
                                                    </span>
                                            <%
                                                }
                                            %>
                                            </span>

                                            <%
                                                if(!readOnly)
                                                {
                                            %>
                                                    <span class="up-rep-btn">
                                                        <oneit:ormInput obj="<%= hiringTeam %>" type="file" attributeName="HiringTeamLogo"  accept="image/*"    id="upload"
                                                                        style="visibility: hidden; width: 1px; height: 1px"/>
                                                        <a href="javascript:void(0)" onclick="document.getElementById('upload').click(); return false" id="replace-btn">
                                                            <%= hiringTeam.getHiringTeamLogo() != null ? "Replace" : "Upload" %>
                                                        </a>
                                                    </span>
                                            <%
                                                }

                                                Boolean isHTLogoPresent =   (Boolean) process.getAttribute("IsHTLogoPresent");

                                                if(CollectionUtils.equals(isHTLogoPresent, Boolean.FALSE))
                                                {
                                                    process.setAttribute("IsHTLogoPresent", Boolean.TRUE);
                                            %>
                                                    <div id="overlay">
                                                        <div class="modal-dialog welcome-pop-top">
                                                            <div class="modal-body main-welcome-popup">
                                                                <h2>You haven't added a logo yet!</h2>
                                                                <p>You have not specified a Logo for this Hiring Team. The Logo is displayed for job applicants so it is desirable to include a logo.</p>
                                                                <div class="create-y-f-job">
                                                                    <oneit:button   value="Ok"    name="saveCompany"    skin="link"
                                                                                    requestAttribs="<%= CollectionUtils.mapEntry("nextPage", WebUtils.getSamePageInRenderMode(request, "HiringTeam"))
                                                                                                                        .mapEntry ("restartProcess", Boolean.TRUE)
                                                                                                                        .mapEntry("procParams", CollectionUtils.mapEntry("HiringTeam", hiringTeam).mapEntry("IsHTLogoPresent",Boolean.TRUE).toMap())
                                                                                                                        .mapEntry ("attribNamesToRestore", Collections.singleton("HiringTeam"))
                                                                                                                        .toMap() %>">
                                                                        
                                                                    </oneit:button>
                                                                </div>
                                                            </div>          
                                                        </div>
                                                    </div>
                                            <%
                                                }
                                            %>
                                        </div>
                                    </div>
                                    <div class="form-group row">
                                        <div class="col-md-6">
                                            <label><oneit:label GUIName="Industry" /></label>
                                            <oneit:ormEnum  obj="<%= hiringTeam %>" attributeName="Industry"    cssClass="form-control" displayType="autocomplete"/>
                                        </div>
                                    </div>
                                    <div class="form-group row">
                                        <div class="col-md-12">
                                            <label><oneit:label GUIName="Will this team help Clients with hiring?" /><a href="#" title="Selecting this option activates the Client functionality and <br/>allows Jobs and Templates to be grouped and filtered by Client." class="info-icon"><img src="images/info-icon.png" /></a></label>
                                        </div>
                                    </div>
                                    <div class="form-group row">
                                        <div class="col-md-6">
                                            <div class="radio radio-primary second-radio-primary oneit-radio">
                                                <label>
                                                    <oneit:ormInput obj="<%= hiringTeam %>" type="radio" attributeName="HasClientSupport" value="true"/>Yes
                                                </label>
                                            </div>
                                             <div class="radio radio-primary second-radio-primary oneit-radio">
                                                <label>
                                                    <oneit:ormInput obj="<%= hiringTeam %>" type="radio" attributeName="HasClientSupport" value="false"/>No
                                                </label>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-brack-line-sub"></div>
                                    <div class="form-group row">
                                        <div class="col-md-12">
                                            <label><oneit:label GUIName="Will this Hiring Team use the Diversity questions?" /><a href="#" title="Selecting this option allows the capture of Diversity demographics <br/>from applicants to be used as part of affirmative action hiring." class="info-icon"><img src="images/info-icon.png" /></a></label>
                                        </div>
                                    </div>
                                    <div class="form-group row has-diversity">
                                        <div class="col-md-6">
                                            <div class="radio radio-primary second-radio-primary oneit-radio">
                                                <label>
                                                    <oneit:ormInput obj="<%= hiringTeam %>" type="radio" attributeName="HasDiversity"   value="true"/>Yes
                                                </label>
                                            </div>
                                            <div class="radio radio-primary second-radio-primary oneit-radio">
                                                <label>
                                                    <oneit:ormInput obj="<%= hiringTeam %>" type="radio" attributeName="HasDiversity"   value="false"/>No
                                                </label>
                                            </div>
                                            <%
                                                if(hiringTeam.getDiversityQuestionsCount() == 0)
                                                {
                                            %>
                                                    <oneit:button   value=" "    name="changeDiversity"   cssClass="hide"
                                                                    requestAttribs="<%= CollectionUtils.mapEntry ("HiringTeam", hiringTeam)
                                                                                                        .mapEntry (UpdateMappedObjFP.FAIL_VALIDATION_ERRORS, Boolean.FALSE)
                                                                                                        .toMap() %>" />
                                            <%
                                                }
                                            %>
                                        </div>
                                    </div>
                                    <oneit:recalcClass  htmlTag="div"  classScript="hiringTeam.showHasDiversity() ? 'show': 'hide'" hiringTeam="<%= hiringTeam %>">
                                        <%
                                            for(HTDiversityQuestion question : hiringTeam.getDiversityQuestionsSet())
                                            {
                                        %>
                                                <div class="form-group row">
                                                    <div class="col-md-11">
                                                        <oneit:recalcClass  htmlTag="div"  classScript="question.getIsApplicable() ? 'show': 'hide'" question="<%= question %>">
                                                            <oneit:ormInput obj="<%= question %>"    type="text" attributeName="QuestionText" cssClass="form-control no-border"/>                                
                                                        </oneit:recalcClass>   
                                                        <oneit:recalcClass  htmlTag="div"  classScript="question.getIsApplicable() ? 'hide': 'show'" question="<%= question %>">
                                                            <span class="disabled-question">
                                                                <oneit:toString value="<%= question.getQuestionText() %>" mode="EscapeHTML"/>
                                                            </span>
                                                        </oneit:recalcClass>   
                                                    </div>
                                                    <div class="col-md-1">
                                                        <label class="switch">
                                                            <oneit:recalcClass  htmlTag="span"  classScript="question.getIsApplicable() ? 'checkbox checked': 'checkbox unchecked'"    question="<%= question %>">
                                                                <oneit:ormInput obj="<%= question %>"    attributeName="IsApplicable"  type="checkbox"/>
                                                            </oneit:recalcClass>
                                                            <div class="slider round"></div>
                                                        </label>
                                                    </div>
                                                </div>
                                        <%
                                            }
                                        %>
                                    </oneit:recalcClass>
                                    <%
                                        if(Utils.isAssumedUser(request))
                                        {
                                    %>      <div class="form-brack-line-sub"></div>
                                            <div class="form-group">
                                                <label><oneit:ormlabel  obj="<%= hiringTeam %>" field="MessageID" /></label>
                                                <oneit:ormInput obj="<%= hiringTeam %>"    type="text" attributeName="MessageID" cssClass="form-control"/>                                
                                            </div>
                                    <%
                                        }

                                        if(company.getHiringTeamsCount() > 1)
                                        {
                                    %>         
                                            <div class="form-brack-line-sub"></div>
                                            <oneit:recalcClass  htmlTag="div"  classScript="!hiringTeam.getManageOwnBilling() && hiringTeam.getBilledByTeam() != null ? 'show': 'hide'"    hiringTeam="<%= hiringTeam %>">
                                                <div class="warning-box">
                                                    Billing has been disabled for this team as it is included in <oneit:recalc script="hiringTeam.getBilledByTeam()" hiringTeam="<%= hiringTeam %>" mode="EscapeHTML" />.
                                                </div>
                                            </oneit:recalcClass>
                                            <div class="form-group row">
                                                <div class="col-md-6">
                                                    <label><oneit:label GUIName="Will this team manage its own billing?" /><a href="#" title="Selecting this option allows the entry of <br/>separate billing details for this Hiring Team." class="info-icon"><img src="images/info-icon.png" /></a></label>
                                                </div>
                                                <div class="col-md-6">
                                                    <oneit:recalcClass  htmlTag="div"  classScript="hiringTeam.getManageOwnBilling() ? 'hide': 'show'"    hiringTeam="<%= hiringTeam %>">
                                                        <label><oneit:label GUIName="Which team will manage the billing?"/></label>
                                                    </oneit:recalcClass>
                                                </div>
                                            </div>
                                            <div class="form-group row own-billing">
                                                <div class="col-md-6">
                                                    <div class="radio radio-primary second-radio-primary oneit-radio">
                                                        <label>
                                                            <oneit:ormInput obj="<%= hiringTeam %>" type="radio" attributeName="ManageOwnBilling" value="true"  readonly="<%= !assumedUser %>"/>Yes
                                                        </label>
                                                    </div>
                                                     <div class="radio radio-primary second-radio-primary oneit-radio">
                                                        <label>
                                                            <oneit:ormInput obj="<%= hiringTeam %>" type="radio" attributeName="ManageOwnBilling" value="false" readonly="<%= !assumedUser %>"/>No
                                                        </label>
                                                    </div>
                                                </div>
                                                <div class="col-md-6">
                                                    <oneit:recalcClass  htmlTag="div"  classScript="hiringTeam.getManageOwnBilling() ? 'hide': 'show'"    hiringTeam="<%= hiringTeam %>">
                                                        <%
                                                            if(assumedUser)
                                                            {
                                                        %>
                                                                <div class="wider-select">
                                                                    <tagfile:ormsingleasso_select obj="<%= hiringTeam %>"  assocName="BilledByTeam" options="<%= Utils.getHiringTeamsWithOwnBilling(hiringTeam) %>"/>
                                                                </div> 
                                                        <%
                                                            }
                                                            else
                                                            {
                                                        %>
                                                                <oneit:toString value="<%= hiringTeam.getBilledByTeam() %>" mode="EscapeHTML"/>
                                                        <%
                                                            }
                                                        %>
                                                    </oneit:recalcClass>
                                                </div>
                                            </div>
                                    <%
                                        }
                                    %>          
                                    <div class="form-brack-line-sub"></div>

                                    <div class="form-group row">
                                        <div class="col-md-12">
                                            <label><oneit:label GUIName="Google Location"/></label>
                                            <oneit:ormInput obj="<%= hiringTeam %>" type="text" attributeName="GoogleAddressText" class="autoAddress" id="<%= "gAddress_"+hiringTeam.getObjectID() %>" placeholder="Enter your address" cssClass="form-control" />
                                        </div>
                                    </div>
                                    <div class="form-group row">
                                        <div class="col-md-6">
                                            <label><oneit:ormlabel  obj="<%= hiringTeam %>"    field="Country" /></label>
                                            <oneit:ormEnum  obj="<%= hiringTeam %>"    attributeName="Country" cssClass="form-control"  readonly="true"/>
                                        </div>
<%--                                    <div class="col-md-4">
                                            <label><oneit:ormlabel  obj="<%= hiringTeam %>"    field="State" /></label>
                                            <oneit:ormEnum  obj="<%= hiringTeam %>"    attributeName="State" cssClass="form-control"/>
                                        </div>
                                        <div class="col-md-4">
                                            <label><oneit:ormlabel  obj="<%= hiringTeam %>"    field="PostCode" /></label>
                                            <oneit:ormInput obj="<%= hiringTeam %>"    type="text" attributeName="PostCode"    cssClass="form-control" />      
                                        </div>
--%>
                                    </div> 
<%--                                    
                                    <div class="form-group row">
                                        <div class="col-md-6">
                                            <label><oneit:ormlabel  obj="<%= hiringTeam %>"    field="City" /></label>
                                            <oneit:ormInput obj="<%= hiringTeam %>"    type="text" attributeName="City"    cssClass="form-control" />      
                                        </div>
                                        <div class="col-md-6">
                                            <label><oneit:label GUIName="Default Timezone" /></label>
                                            <oneit:ormEnum  obj="<%= hiringTeam %>"    attributeName="TimeZone"    cssClass="form-control"/>
                                        </div>
                                    </div>
--%>                                
                                    <div id="manage-own-billing-alert" class="hidden-pop" >
                                        <div class="change-plan-content">
                                            <h3>Alert!</h3>
                                            <div class="upgrade-info">
                                                <span>
                                                    Any prior Jobs you have created are applied to the Hiring Team previously used for Billing.<br/>
                                                    All future Jobs will be applied to a new subscription for this Hiring Team.
                                                </span>
                                            </div>
                                        </div>
                                        <div class="change-plan-button">
                                            <a class="own-billing-alert-close-button popup-no-button" href="javascript:void(0)">Ok</a>
                                        </div>        
                                    </div>
                                    <div id="manage-other-billing-alert" class="hidden-pop" >
                                        <div class="change-plan-content">
                                            <h3>Alert!</h3>
                                            <div class="upgrade-info">
                                                <span>
                                                    Your current Subscription for this Hiring Team will be ended and any unused jobs on your current subscription will be forfeited.<br/>
                                                    Any Jobs that you have used above the allowance in your prior subscription will be invoiced at next invoice date.
                                                </span>
                                            </div>
                                        </div>
                                        <div class="change-plan-button">
                                            <a class="own-billing-alert-close-button  popup-no-button" href="javascript:void(0)">Ok</a>
                                        </div>        
                                    </div>
                                    
                                   <div id="force-to-choose-popup" class="hidden-pop" >
                                    <div class="change-plan-content">
                                        <h3>Alert!</h3>
                                        <div class="upgrade-info">
                                            <span>Please save before continue.</span>
                                        </div>
                                    </div>
                                    <div class="change-plan-button">
                                        <a class="force-alert-close-button popup-no-button">Ok</a>
                                    </div>        
                                </div> 
                                        
                                    <div class="text-center form-group">
                                        <oneit:button   value="Cancel" name="gotoPage" cssClass="btn btn-primary largeBtn greyBtn"
                                                        requestAttribs='<%= CollectionUtils.mapEntry ("nextPage", nextPage)
                                                                                            .mapEntry("cancelProcess", true)
                                                                                            .toMap() %>'/>
                                        <oneit:button   value="Save Team"    name="saveCompany"  cssClass="btn btn-primary largeBtn" disabled="<%= readOnly ? "true" : "false" %>"
                                                        requestAttribs="<%= CollectionUtils.mapEntry("nextPage", nextPage)
                                                                                            .mapEntry("procParams", CollectionUtils.mapEntry("HiringTeam", hiringTeam).toMap())
                                                                                            .mapEntry("Company", company)
                                                                                            .toMap() %>" />
                                    </div> 
                                </div>
                            </div>
                        </div>
                    </div>
                    <script>
                        addGoogleAddressListener('#<%= "gAddress_"+ hiringTeam.getObjectID() %>');
                    </script>
                </oneit:form>
            </div>
        </div>
    </div>
</oneit:dynIncluded>
