<apex:page id="Page" controller="SearchVisitorController" sidebar="false" showHeader="false" >
    <apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}"/>
    <apex:includeScript value="{!URLFOR($Resource.PleaseWaitDialog)}"/>
    <script type="text/javascript">
        function addContact(){
            window.opener.showModal();
            
            var setVisitor = new Array();

            setVisitor[0] = new Array();
            setVisitor[0][0] = '{!id1}';
            setVisitor[0][1] = '{!hId1}';
            
            setVisitor[1] = new Array();
            setVisitor[1][0] = '{!id2}';
            setVisitor[1][1] = '{!hId2}';
                
            setVisitor[2] = new Array();
            setVisitor[2][0] = '{!id3}';
            setVisitor[2][1] = '{!hId3}';

            setVisitor[3] = new Array();
            setVisitor[3][0] = '{!id4}';
            setVisitor[3][1] = '{!hId4}';

            setVisitor[4] = new Array();
            setVisitor[4][0] = '{!id5}';
            setVisitor[4][1] = '{!hId5}';
            
            var sltList = new Array();
            var j = 0;

            for(var i=0; i<5; i++){
                if(j$(escapeVfId('Page:mainForm:idSearchVisitor:idAddVisitor:' + i + ':idAddHiddenId')).value() != ''){
                    sltList[j] = new Array();
                    sltList[j][0] = document.getElementById('Page:mainForm:idSearchVisitor:idAddVisitor:' + i + ':idAddName').innerHTML;
                    sltList[j][1] = j$(escapeVfId('Page:mainForm:idSearchVisitor:idAddVisitor:' + i + ':idAddHiddenId')).value();
                    j++;
                }
            }
            
            for(var i=j; i<5; i++){
                sltList[j] = new Array();
                sltList[j][0] = '';
                sltList[j][1] = '';
                j++;
            }
            
            for(var a=0; a<5; a++){
                window.opener.document.getElementById(setVisitor[a][0]).value = sltList[a][0];
                window.opener.document.getElementById(setVisitor[a][1]).value = sltList[a][1];
            }

            window.close();
        }
        
        function sltContact(index){
            var addId = j$(escapeVfId('Page:mainForm:idSearchVisitor:idRezultVisitor:' + index + ':idHiddenId')).value();
            var addName = document.getElementById('Page:mainForm:idSearchVisitor:idRezultVisitor:' + index + ':idName').innerHTML;
            var addDep = document.getElementById('Page:mainForm:idSearchVisitor:idRezultVisitor:' + index + ':idDep').innerHTML;
            var addJob = document.getElementById('Page:mainForm:idSearchVisitor:idRezultVisitor:' + index + ':idJob').innerHTML;
            var addPhone = document.getElementById('Page:mainForm:idSearchVisitor:idRezultVisitor:' + index + ':idPhone').innerHTML;
            var addMyDr = document.getElementById('Page:mainForm:idSearchVisitor:idRezultVisitor:' + index + ':idMyDr').innerHTML;
            var     addPlease_Delete = document.getElementById('Page:mainForm:idSearchVisitor:idRezultVisitor:' + index + ':idPlease_Delete').innerHTML;
            
            for(var i=0; i<5; i++){
                if(j$(escapeVfId('Page:mainForm:idSearchVisitor:idAddVisitor:' + i + ':idAddHiddenId')).value() == addId){
                    alert('{!$Label.Error_Message45}');
                    return;
                }
            }
                    
            for(var i=0; i<5; i++){
                if(document.getElementById('Page:mainForm:idSearchVisitor:idAddVisitor:' + i + ':idAddName').innerHTML == '　'){
                    j$(escapeVfId('Page:mainForm:idSearchVisitor:idAddVisitor:' + i + ':idAddHiddenId')).val(addId);
                    document.getElementById('Page:mainForm:idSearchVisitor:idAddVisitor:' + i + ':idAddName').innerHTML = addName;
                    document.getElementById('Page:mainForm:idSearchVisitor:idAddVisitor:' + i + ':idAddDep').innerHTML = addDep;
                    document.getElementById('Page:mainForm:idSearchVisitor:idAddVisitor:' + i + ':idAddJob').innerHTML = addJob;
                    document.getElementById('Page:mainForm:idSearchVisitor:idAddVisitor:' + i + ':idAddPhone').innerHTML = addPhone;
                    document.getElementById('Page:mainForm:idSearchVisitor:idAddVisitor:' + i + ':idAddMyDr').innerHTML = addMyDr;
                    break;
                }
            }
        }
        
        function delContact(index){
            j$(escapeVfId('Page:mainForm:idSearchVisitor:idAddVisitor:' + index + ':idAddHiddenId')).val("");
            document.getElementById('Page:mainForm:idSearchVisitor:idAddVisitor:' + index + ':idAddName').value = null;
            document.getElementById('Page:mainForm:idSearchVisitor:idAddVisitor:' + index + ':idAddName').innerHTML = '　';
            document.getElementById('Page:mainForm:idSearchVisitor:idAddVisitor:' + index + ':idAddDep').innerHTML = '　';
            document.getElementById('Page:mainForm:idSearchVisitor:idAddVisitor:' + index + ':idAddJob').innerHTML = '　';
            document.getElementById('Page:mainForm:idSearchVisitor:idAddVisitor:' + index + ':idAddPhone').innerHTML = '　';
            document.getElementById('Page:mainForm:idSearchVisitor:idAddVisitor:' + index + ':idAddMyDr').innerHTML = '<img src=\"/img/checkbox_unchecked.gif\" width=\"16\" height=\"16\" class=\"checkImg\" />';
        }
        
    </script>
    <style type="text/css">
        div#iframelike {
            color: #fff;
            height: 210px;
            overflow-y: auto;
            overflow-x: hidden;
        }
        
        div#iframelike2 {
            color: #fff;
            height: 185px;
            overflow-y: auto;
            overflow-x: hidden;
        }
    </style>
    <apex:outputPanel id="all">
        <apex:form id="mainForm">
        <apex:actionFunction name="updContactP" action="{!updContactP}" rerender="idRezultVisitor,idRegistration">
        <apex:param name="index" assignTo="{!index}" value="" />
        </apex:actionFunction>
        <apex:actionFunction name="updContactM" action="{!updContactM}" rerender="idRezultVisitor">
        <apex:param name="index" assignTo="{!index}" value="" />
        </apex:actionFunction>
        <apex:actionFunction name="editVistor" action="{!editVistor}" rerender="idRegistration" oncomplete="setButtonDisable(document.getElementById('Page:mainForm:idSearchVisitor:idRegSave'), false);">
        <apex:param name="index" assignTo="{!index}" value=""/>
        </apex:actionFunction>
            <apex:pageBlock id="idSearchVisitor" >
                <table width="1060" height="50" border="0">
                    <tr>
                      <th style="font-size:15px;">{!$Label.Search_Personnel}</th>
                      <td width="700px" >
                          <apex:outputPanel id="idMessage">
                            <apex:pageMessages />
                          </apex:outputPanel>
                      </td>
                      
                    </tr></table>
                <table width="1060" border="0" style="background-color:#DCDCDC">
                    <colgroup>
                        <col width="20" />
                        <col width="90" />
                        <col width="20" />
                        <col width="90" />
                        <col width="90" />
                        <col width="20" />
                        <col width="145" />
                        <col width="20" />
                        <col width="145" />
                        <col width="20" />
                        <col width="120" />
                        <col width="20" />
                        <col width="95" />
                        <col width="20" />
                        <col width="120" />
                    </colgroup>
                    <tr>
                        <td>&nbsp;</td>
                        <th>{!$Label.Search_Condition}</th>
                        <td>&nbsp;</td>
                        <th>{!$Label.Last_Name}</th>
                        <th>{!$Label.First_Name}</th>
                        <td>&nbsp;</td>
                        <th>{!$Label.Attribute}</th>
                        <td>&nbsp;</td>
                        <th>{!$Label.Post}</th>
                        <td>&nbsp;</td>
                        <th>{!$Label.MyDr}</th>
                        <td>&nbsp;</td>
                        <th>&nbsp;</th>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td><apex:inputText value="{!sc.Search_LastName__c}" style="width:80px" required="false"/></td>
                        <td><apex:inputText value="{!sc.Search_FirstName__c}" style="width:80px" required="false"/></td>
                        <td>&nbsp;</td>
                        <th><apex:inputField value="{!sc.Type__c}" /></th>
                        <td>&nbsp;</td>
                        <th><apex:inputField value="{!sc.Doctor_Division1__c}" /></th>
                        <td>&nbsp;</td>
                        <th><apex:inputField value="{!sc.MyDr_Flg__c}" /></th>
                        <td>&nbsp;</td>
                        <th>&nbsp;</th>
                        <td>&nbsp;</td>
                        <td><apex:commandButton value="{!$Label.Search}" action="{!serContact}" style="width:100px" rerender="idRezultVisitor" /></td>
                    </tr>
                    <tr>
                        <td style="border-bottom: 1px solid #888;" colspan="15">&nbsp;</td>
                    </tr>
                </table>
                <table width="1060" border="0" style="background-color:#DCDCDC">
                    <tr>
                        <td>
                        <div id="iframelike">
                        <apex:pageBlockTable id="idRezultVisitor" value="{!scwl}" var="scw" border="1" columns="8" columnsWidth="47px,90px,,90px,180x,90px,40px,200px">
                            <apex:column >
                                <apex:facet name="header">{!$Label.Selected}</apex:facet>
                                <input type="button" id="idSlt" value="{!$Label.Selected}" onclick="sltContact('{!scw.index}');" class="btn" style="width:40px"/>
                            </apex:column>
                            <apex:column >
                                <apex:facet name="header">{!$Label.Visitor_Name}</apex:facet>
                                <apex:outputLink value="/{!scw.con.Id}" id="idName" target="_blank">{!scw.con.Name}</apex:outputLink>
                                <apex:inputText id="idHiddenId" value="{!scw.conid}" style="display:none" />
                            </apex:column>
                            <apex:column >
                                <apex:facet name="header">{!$Label.Department_Name}</apex:facet>
                                <apex:outputText id="idDep" value="{!IF(scw.con.Account.Name==null,'　',scw.con.Account.Name)}" />
                            </apex:column>
                            <apex:column >
                                <apex:facet name="header">{!$ObjectType.Contact.fields.Doctor_Division1__c.Label}</apex:facet>
                                <apex:outputText id="idJob" value="{!IF(scw.con.Doctor_Division1__c==null,'　',scw.con.Doctor_Division1__c)}" />
                            </apex:column>
                            <apex:column >
                                <apex:facet name="header">{!$ObjectType.Lead.fields.Phone.Label}</apex:facet>
                                <apex:outputText id="idPhone" value="{!IF(scw.con.Phone==null,'　',scw.con.Phone)}" />
                            </apex:column>
                            <apex:column >
                                <apex:facet name="header">MyDr</apex:facet>
                                <apex:inputField id="idMyDr" value="{!scw.con.MyDr_Flg__c}" onclick="this.disabled=true;updContactM('{!scw.index}');"/>
                            </apex:column>
                            <!--2014/6/16__yu追加-->
                            <apex:column id="Delete">
                                <apex:facet name="header" >Delete</apex:facet>
                                <apex:inputField id="idPlease_Delete" value="{!scw.con.Please_Delete__c}" onclick="this.disabled=true;updContactP('{!scw.index}');" />
                            </apex:column>
                            <!--2016/10/10__ZHAO追加-->
                            <apex:column id="Reason">
                                <apex:facet name="header" >删除理由</apex:facet>
                                <apex:inputField id="DeleteReason" value="{!scw.con.Delete_Reason__c}"/>
                            </apex:column>
                        </apex:pageBlockTable>
                        </div>
                        </td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>{!$Label.Add_List}</b>　</td>
                    </tr>
                    <tr>
                        <td>
                        <div id="iframelike2">
                        <apex:pageBlockTable id="idAddVisitor" value="{!acwl}" var="acw" border="1" columns="7" columnsWidth="47px,90px,,90px,180x,90px,40px">
                            <apex:column >
                                <apex:facet name="header">{!$Label.Back}</apex:facet>
                                <input type="button" id="idDel" value="{!$Label.Back}" onclick="delContact('{!acw.index}');" class="btn" style="width:40px"/>
                            </apex:column>
                            <apex:column >
                                <apex:facet name="header">{!$Label.Visitor_Name}</apex:facet>
                                <apex:outputText id="idAddName" value="{!IF(acw.con.Name==null,'　',acw.con.Name)}" />
                                <apex:inputText id="idAddHiddenId" value="{!acw.conid}" style="display:none" />
                            </apex:column>
                            <apex:column >
                                <apex:facet name="header">{!$Label.Department_Name}</apex:facet>
                                <apex:outputText id="idAddDep" value="{!IF(acw.con.Account.Name==null,'　',acw.con.Account.Name)}" />
                            </apex:column>
                            <apex:column >
                                <apex:facet name="header">{!$ObjectType.Contact.fields.Doctor_Division1__c.Label}</apex:facet>
                                <apex:outputText id="idAddJob" value="{!IF(acw.con.Doctor_Division1__c==null,'　',acw.con.Doctor_Division1__c)}" />
                            </apex:column>
                            <apex:column >
                                <apex:facet name="header">{!$ObjectType.Lead.fields.Phone.Label}</apex:facet>
                                <apex:outputText id="idAddPhone" value="{!IF(acw.con.Phone==null,'　',acw.con.Phone)}" />
                            </apex:column>
                            <apex:column >
                                <apex:facet name="header">MyDr</apex:facet>
                                <apex:outputField id="idAddMyDr" value="{!acw.con.MyDr_Flg__c}" />
                            </apex:column>
                            <apex:column >
                                <apex:facet name="header">{!$Label.Edit}</apex:facet>
                                <input type="button" id="idEdit" value="{!$Label.Edit}" onclick="setButtonDisable(document.getElementById('Page:mainForm:idSearchVisitor:idRegSave'), true);editVistor('{!acw.index}');" class="btn" style="width:40px"/>
                            </apex:column>
                        </apex:pageBlockTable>
                        </div>
                        </td>
                    </tr>
                    <tr><td>
                        <table width="880" border="0" style="background-color:#DCDCDC"><tr>
                            <td>
                                <apex:commandButton value="{!$Label.Clear}" action="{!clearRC}"  style="width:40px" rerender="idRegistration" />
                            </td>
                            <td style="text-align:center">
                                <input type="button" value="{!$Label.Set}" onclick="addContact();" class="btn"/>
                            </td>
                            <td style="text-align:right">
                                <apex:commandButton id="idRegSave" value="{!$Label.Registration}" action="{!regContact}" style="width:60px" rerender="idRegistration,idRezultVisitor,idAddVisitor,idMessage"/>
                            </td>
                        </tr></table>
                    </td></tr>
                    <!-- <tr><td align="center"><input type="button" value="{!$Label.Set}" onclick="addContact();" class="btn" style="width:80px" /></td></tr> -->
                </table>
                <br></br>
                
                <apex:outputPanel id="idRegistration">

                <table class="formtable" width="1060" border="0">
                    
                    <tr>
                        <td width= "20">&nbsp;</td>
                        <th width= "80">{!$Label.Attribute}</th>
                        <th width= "80" ><apex:inputField value="{!rc.Type__c}" style="width:66px"/></th>
                        <th width= "80" style="text-align:right">{!$Label.Last_Name}</th>
                        <td width= "80" ><span><div class="requiredInput"><div class="requiredBlock"></div><apex:inputField value="{!rc.Search_LastName__c}" style="width:70px" /></div></span></td>
                        <th width= "80" style="text-align:right">{!$Label.First_Name}</th>
                        <td width= "160" colspan="2" rowspan="2"><apex:inputField value="{!rc.FirstName}" style="width:150px" /></td>
                        <th width= "80" style="text-align:right">{!$ObjectType.Lead.fields.Phone.Label}</th>
                        <td width= "80"><apex:inputField value="{!rc.phone}" style="width:110px" /></td>
                        <th width= "80" style="text-align:right">{!$ObjectType.Contact.fields.Supplement__c.Label}</th>
                        <th width= "130" colspan="2" rowspan="3"><apex:inputField value="{!rc.Supplement__c}" style="width:130px" /></th>
                        
                    </tr>
                    <tr></tr>
                    <tr>
                        <td>&nbsp;</td>
                        <th colspan="2">{!$ObjectType.Contact.fields.Doctor_Division1__c.Label}</th>
                        <th colspan="2"><apex:inputField value="{!rc.Doctor_Division1__c}" style="width:150px"/></th>
                        <th style="text-align:right">{!$Label.Department_Name}</th>
                        <th colspan="3"><apex:inputField value="{!rc.Account_Visitor_Search__c}" style="width:280px" /></th>
                        <th>{!$Label.MyDr}</th>
                        <th style="text-align: left;"><apex:inputField value="{!rc.MyDr_Flg__c}" /></th>
                        
                        
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td colspan="3">{!$ObjectType.Contact.fields.Ignore_Same_Name__c.Label}</td>
                        <th style="text-align: left;"><apex:inputField value="{!rc.Ignore_Same_Name__c}" /></th>
                    </tr>
                </table>
            </apex:outputPanel>
            </apex:pageBlock>
        </apex:form>
    </apex:outputPanel>
</apex:page>