<div class="panelHeader">
    <h3>YouTube Channel Basics</h3>
</div>
<div class="panelContent">
    <div id="channel_error_message" class="alertError" style="display:none"></div>
    <div id="channel_success_message" class="alertConfirm" style="display:none"></div>
    <script>
        //from /scripts/jsfunctions.js
    <?php if (!$this->id) {  // To hide the calender in edit mode ?>
        addCalendar('calDateInit', 'Select Date', 'dateInitiated', 'addYoutubeChannel_form');
    <?php } ?>
        addCalendar('calDateConn', 'Select Date', 'dateConnected', 'addYoutubeChannel_form');
    </script>
    <form id="addYoutubeChannel_form" method="post">
    <table class="form">
        <tr>
            <th colspan="2"><h2 style="text-align:left; font-size:16px">Channel Basics</h2></th>
            <?php echo $this->form->id->renderViewHelper();?>
        </tr>
        <tr>
            <th><span class="required">* </span><label for="autoClaim">Automatically Claim Videos:</label></th>
            <td>
                <?php echo $this->form->autoClaim->setAttrib('label_class', 'label-input-text')->renderViewHelper(); ?>
                <div class="validation_message" ></div>
            </td>
        </tr>
        <tr>
            <th><span class="required">* </span><label for="contentIdMatching">Enable for Content ID Matching:</label></th>
            <td>
                <?php echo $this->form->contentIdMatching->renderViewHelper();?> <div class="validation_message"></div>
            </td>
        </tr>
        <?php if (!$this->id) :  // Field is only editable in add mode ?>
        <tr>
            <th>
                <span class="required">* </span><span>Channel Address: </span>
            </th>
            <td> 
                <div class="floatClear">
                    <input class="youtubeChannelUrlType" name="urlType" checked="checked" value="channelName" type="radio">
                    <div class="channelUrlEntry">
                        <label for="youtubeChannelName">Channel Name: </label>
                        <div class="channelUrl">youtube.com/ <input id="youtubeChannelName" name="youtubeChannelName" value="" type="text"></div>
                    </div>
                </div>
                <br/>
                <div class="floatClear">
                    <input class="youtubeChannelUrlType" name="urlType" value="channelId" type="radio">
                    <div class="channelUrlEntry">
                        <label for="unverifiedYoutubeChannelId">Channel ID: </label>
                        <div class="channelUrl">youtube.com/channel/ <input id="unverifiedYoutubeChannelId" name="unverifiedYoutubeChannelId" value="" type="text"></div>
                    </div>
                    <input id="youtubeChannelId" name="youtubeChannelId" value="" type="hidden">
                </div>
                <div id="channelVerified" class="formSubText floatClear"></div>
            </td>
        </tr>
        <?php else : ?>
        <tr>
            <th><label for="youtubeChannelName">Channel Name: youtube.com/</label></th>
            <td>
                <?php
                if (empty($this->youtubeChannelName)) :
                    echo $this->form->youtubeChannelName->renderViewHelper();?>
                    <div id='channelVerified' class="formSubText" ></div>
                <?php
                else :
                    echo $this->channel->youtubeChannelName ?>
                    <input type="hidden" id="youtubeChannelName" name="youtubeChannelName" value="<?php echo $this->youtubeChannelName; ?>">
                <?php
                endif;
                ?>
            </td>
        </tr>
        <tr>
            <th><label for="youtubeChannelId">Channel Id: youtube.com/channel/</label></th>
            <td><?= $this->channel->youtubeChannelId ?>
            <input type="hidden" id="youtubeChannelId" name="youtubeChannelId" value="<?php echo $this->youtubeChannelId; ?>" /></td>
        </tr>
        <?php endif; ?>
        <tr>
            <th><span class="required">* </span><label for="youtubeChannelCurrentUpc">Current Channel UPC:</label></th>
            <td>
                <?php
                    echo $this->form->youtubeChannelCurrentUpc->renderViewHelper();
                ?>
                <div id='subaccountName' class="formSubText" ><?php echo  isset($this->subaccountName) ? 'Subaccount Name : '.$this->subaccountName : ''; ?></div>
            </td>
        </tr>
        <tr>
            <th><?=!$this->id ? '<span class="required">* </span>' : '';?><label for="youtubeChannelCmsAccount">CMS Account:</label></th>
            <td>
                <?php
                if (!$this->id) {
                    echo $this->form->youtubeChannelCmsAccount->renderViewHelper();
                } else {
                    echo $this->escape($this->youtubeChannelCmsAccountDisplayName);;
                }
                ?>
                <input type="hidden" id="youtubeChannelCmsAccountId" name="youtubeChannelCmsAccountId" value="<?php echo $this->youtubeChannelCmsAccountId; ?>" />
            <div id='cmsaVerified' class="formSubText" ></div>
            </td>
        </tr>
        <tr>
        
            <th><label for="partnerStatus">Partner Status:</label></th>
            <td><?php echo $this->form->youtubeChannelPartnerStatus->renderViewHelper();?>
        </tr>
        <tr>
            <th><label for="monetizationStatus">Monetization Status:</label></th>
            <td><?php echo $this->form->monetizationStatus->renderViewHelper();?></td>
        </tr>
        <tr>
            <th><span class="required">* </span><label for="youtubeChannelAssetTypeId">Asset Type:</label></th>
            <td><?php echo $this->form->youtubeChannelAssetTypeId->renderViewHelper();?></td>
        </tr>
        <tr>
            <th><span class="required">* </span><label for="artistId">Artist ID:</label></th>
            <td><?php echo $this->form->artistId->renderViewHelper();?>
            <div id='artistName' class="formSubText" ><?php echo $this->artistDetails; ?></div>
            </td>
        </tr>
    </table>

    <table class="form">
        <tr>
            <th colspan="2"><h2 style="text-align:left; font-size:16px">Business Information</h2></th>
        </tr>
        <tr>
            <th><span class="required">* </span><label for="serviceTier">Service Tier:</label></th>
            <td><?php echo $this->form->youtubeChannelServiceTier->renderViewHelper();?></td>
        </tr>
        <tr>
        <tr>
            <th><label for="accountManager">Account Manager:</label></th>
            <td><?php echo $this->form->accountManager->renderViewHelper();?>
        </tr>
        <tr>
            <th><span class="required">* </span><label for="dateInitiated">Date Initiated:</label></th>
            <td>
                <?php
                echo $this->form->dateInitiated->renderViewHelper();
                if ($this->id == 0) {  // To hide the calender in edit youtube channel mode
                ?>
                <a href="javascript:void(0);" onclick="showCal('calDateInit');" id="date-initiated-link"><img src="/images/icoCalendar.gif" border="0" alt="Calendar" align="absmiddle" /></a>
                <?php
                }
                ?>
                <div class="validation_message"></div>
            </td>
        </tr>
        <tr>
            <th><label for="dateConnected">Date Connected:</label></th>
            <td><?php echo $this->form->dateConnected->renderViewHelper();?>
                <a href="javascript:void(0);" onclick="showCal('calDateConn');" id="date-connected-link"><img src="/images/icoCalendar.gif" border="0" alt="Calendar" align="absmiddle" /></a>
            </td>
        </tr>
        <tr>
            <th><label for="notes">Notes:</label></th>
            <td><?php echo $this->form->notes->renderViewHelper();?>
        </tr>
    </table>

    <table  class="form">
        <tr>
            <th colspan="2"><h2 style="text-align:left; font-size:16px">Location Data</h2></th>
        </tr>
        <tr>
            <th><label for="countryId">Channel Country:</label></th>
            <td><?php echo $this->form->countryId->renderViewHelper();?>
        </tr>
        <tr>
            <th><label for="languageCode">Primary Language:</label></th>
            <td><?php echo $this->form->languageCode->renderViewHelper();?>
        </tr>
        <tr>
            <th><label for="youtubeChannelCategoryId">Category:</label></th>
            <td>
            <div class="input-group">
                <?php echo $this->form->youtubeChannelCategoryId->renderViewHelper();?>
                <span class="input-group-btn space-left">
                    <?php echo $this->form->newCategoryButton->setAttrib('onClick', 'selectAddNew();')->setAttrib('class', 'btn btn-default btn-sm')->renderViewHelper();?>
                </span>
            </div>
            </td>
        </tr>
        <tr id="youtubeCategory" style="display: none;">
            <form id="youtubeCategoryForm" method="post">
                <th><label for="youtubeChannelCategoryId">New Category:</label></th>
                <td><input id="youtubeChannelCategoryName" class="small" type="text" name="youtubeChannelCategoryName" width="255">
                    <input class="btn btn-default btn-sm" id="addYoutubeCategoryBtn" type="button" name="addYoutubeCategoryBtn" value="Save" onClick="return saveCategory();"></td>
            </form>
        </tr>
    </table>
    <div class="panelButtons">
        <?php echo $this->form->submit->setLabel('Submit')->setAttrib('onClick', 'return validateYoutubeChannel();')->setAttrib('class', 'btn btn-primary btn-sm')->renderViewHelper();?>
        <?php
            echo $this->form->reset->setLabel('Reset')->setAttrib('class', 'btn btn-default btn-sm')->renderViewHelper();
        ?>
    </div>
</form>
</div>
<script type="text/javascript" src="/scripts/youtubechannel.js"></script>
<script type="text/javascript">
$(document).ready(function () {
    $("#artistId").bind("blur",function(){
        if($("#artistId").val()!= "" && !isNaN($("#artistId").val()))
            getArtistName($(this).val());
        else
            $("#artistName").hide();
    });
    $("#youtubeChannelCurrentUpc").bind("blur",function(){
        if($("#youtubeChannelCurrentUpc").val()!= "" && !isNaN($("#youtubeChannelCurrentUpc").val()))
            getSubaccountName($(this).val());
        else
            $("#subaccountName").hide();
    });
    $("#youtubeChannelName").bind("blur",function(){
        if($("#youtubeChannelName").val()!= ""){
            $("#cmsaLoader").show();
            $("#cmsaVerified").html("");
            var verifiedChannelId = '<?php echo $this->channel == null ? "" : $this->channel->youtubeChannelId; ?>';
            if(verifiedChannelId.length > 0){
                validateYoutubeChannelAgainstChannelId($(this).val(), verifiedChannelId);
            } else {
                getYoutubeChannelID($(this).val());
            }
        }
    });
    $("#youtubeChannelCmsAccount").bind("blur",function(){
        if($("#youtubeChannelCmsAccount").val()!= "" && $("input:hidden[name=youtubeChannelId]").val() != ""){
            $("#cmsaVerified").hide();
            verifyCmsa($(this).val(), $("input:hidden[name=youtubeChannelId]").val());
        }
    });
    $('#unverifiedYoutubeChannelId').bind('blur', function() {
        var channelId = $(this).val();
        if (channelId) {
            verifyYoutubeChannelID(channelId);
        }
    });
    $('#reset').bind('mouseup', function() {
        setTimeout(function() {
            if($("#youtubeChannelCurrentUpc").val()!= "" && !isNaN($("#youtubeChannelCurrentUpc").val()))
                getSubaccountName($("#youtubeChannelCurrentUpc").val());
            else
                $("#subaccountName").hide();
            if($("#artistId").val()!= "" && !isNaN($("#artistId").val()))
                getArtistName($("#artistId").val());
            else
                $("#artistName").hide();
        }, 100);
        $("#channelVerified").hide();
    });
    $('.channelUrlEntry').click(function() {
        $(this).parent().find('input[name="urlType"]').prop('checked', true);
    });
});

</script>
