<?php $application = $this->getApplication() ?>
<div class="application">
    <div class="infos">
        <div class="area">
            <h3 class="title">
                <span class="left area"><?php echo $this->_('General information'); ?></span>
                <hr class="area reverse" />
                <div class="clear"></div>
            </h3>
            <div class="area_content">
                <table class="no-collapse" cellspacing="10" width="100%">
                    <col width="33%"/>
                    <col width="33%"/>
                    <col width="34%"/>
                    <tr>
                        <td><div><label data-tip="44" data-tip-left="80" for="name"><?php echo $this->_('Application name'); ?> : </label></div></td>
                        <td><input type="text" id="name" name="name" class="autosave input" value="<?php echo $application->getName() ? $application->getName() : ucfirst(mb_strtolower($this->getSession()->getAdmin()->getName())); ?>" maxlength="30" /></td>
                        <td><img src="<?php echo $this->getImage('customization/ajax/spinner.gif'); ?>" id="loader_name" alt="Loading" title="Loading" width="24" style="display:none;" /></td>
                    </tr>
                    <tr>
                        <td><div><label for="description"><?php echo $this->_('Description'); ?> : </label></div></td>
                        <td><textarea type="text" id="description" name="description" class="autosave input"><?php echo $application->getDescription(); ?></textarea></td>
                        <td><img src="<?php echo $this->getImage('customization/ajax/spinner.gif'); ?>" id="loader_name" alt="Loading" title="Loading" width="24" style="display:none;" /></td>
                    </tr>
                    <tr>
                        <td><div><label for="description"><?php echo $this->_('Keywords'); ?> : </label></div></td>
                        <td><input type="text" id="keywords" name="keywords" class="autosave input" value="<?php echo $application->getKeywords(); ?>" /></td>
                        <td><img src="<?php echo $this->getImage('customization/ajax/spinner.gif'); ?>" id="loader_name" alt="Loading" title="Loading" width="24" style="display:none;" /></td>
                    </tr>
                    <tr>
                        <td><div><label for="main_category_id"><?php echo $this->_('Main category'); ?> : </label></div></td>
                        <td>
                            <select id="main_category_id" name="main_category_id" class="span3 autosave" tabindex="1">
                                <option value=""><?php echo $this->_('Main category'); ?></option>
                                <?php $categories = Application_Model_Device_Ios::getStoreCategeories(); ?>
                                <?php foreach($categories as $category) : ?>
                                <option value="<?php echo $category->getId(); ?>"<?php if($application->getMainCategoryId() == $category->getId()) : ?> selected="selected"<?php endif; ?>><?php echo $category->getName(); ?></option>
                                <?php endforeach ?>
                            </select>
                        </td>
                        <td><img src="<?php echo $this->getImage('customization/ajax/spinner.gif'); ?>" id="loader_main_category_id" alt="Loading" title="Loading" width="24" style="display:none;" /></td>
                     </tr>
                    <tr>
                        <td><div><label data-tip="48" data-tip-left="80" for="secondary_category_id"><?php echo $this->_('Secondary category<br />(Optional)'); ?> : </label></div></td>
                        <td>
                            <select id="secondary_category_id" name="secondary_category_id" class="span3 autosave" tabindex="2">
                                <option value=""><?php echo $this->_('Secondary category'); ?></option>
                                <?php foreach($categories as $category) : ?>
                                <option value="<?php echo $category->getId(); ?>"<?php if($application->getSecondaryCategoryId() AND $application->getSecondaryCategoryId() == $category->getId()) : ?> selected="selected"<?php endif; ?>><?php echo $category->getName(); ?></option>
                                <?php endforeach ?>
                            </select>
                        </td>
                        <td><img src="<?php echo $this->getImage('customization/ajax/spinner.gif'); ?>" id="loader_secondary_category_id" alt="Loading" title="Loading" width="24" style="display:none;" /></td>
                     </tr>
                </table>
            </div>
        </div>

        <div class="area">
            <?php $device = $application->getDevice(1); ?>
            <h3 class="title">
                <span class="left area"><?php echo $this->_("Apple's Information"); ?></span>
                <hr class="area reverse" />
                <div class="clear"></div>
            </h3>
            <div class="area_content">
                <div class="ask_if_has_account">
                    <div>
                        <label for="has_apple_account_1" class="radio">
                            <input data-tip="49" data-tip-right="60" type="radio" id="has_apple_account_1" name="has_apple_account" class="has_account autosave" value="1" onclick="$('#doesnt_have_apple_account').slideUp(); $('#has_apple_account').slideDown();" />
                            <?php echo $this->_("I have an Apple developer account"); ?>
                        </label>
                    </div>
                    <div>
                        <label for="has_apple_account_0" class="radio">
                            <input data-tip="50" data-tip-right="300" type="radio" id="has_apple_account_0" name="has_apple_account" class="has_account" value="0" onclick="$('#has_apple_account').slideUp(); $('#doesnt_have_apple_account').slideDown();" />
                            <?php echo $this->_("I don't have an Apple developer account and I want to create one"); ?>
                        </label>
                    </div>
                    <div>
                        <label for="has_apple_account_2" class="radio <?php if($device->getUseOurDeveloperAccount()) echo "checked"; ?>">
                            <input type="radio" id="has_apple_account_2" name="has_apple_account" class="has_account autosave" value="2" onclick="$('#has_apple_account').slideUp(); $('#doesnt_have_apple_account').slideUp();" />
                            <?php echo $this->_('I let you publish my application under your Apple developer account'); ?>
                        </label>
                    </div>
                </div>
                <div class="separator"></div>
                <div class="has_account">
                    <div id="has_apple_account" style="display:none;">
                        <table class="no-collapse" cellspacing="10" width="100%">
                            <col width="33%"/>
                            <col width="33%"/>
                            <col width="34%"/>
                            <tr>
                                <td><label for="ios_username"><?php echo $this->_("Email:"); ?></label></td>
                                <td><input type="text" id="ios_username" name="ios_username" class="autosave input" value="<?php echo $device->getDeveloperAccountUsername(); ?>" maxlength="30" /></td>
                                <td><img src="<?php echo $this->getImage('customization/ajax/spinner.gif'); ?>" id="loader_ios_username" alt="Loading" title="Loading" width="24" style="display:none;" /></td>
                            </tr>
                            <tr>
                                <td><label for="ios_password"><?php echo $this->_('Password:'); ?></label></td>
                                <td><input type="password" id="ios_password" name="ios_password" class="autosave input" value="<?php echo $device->getDeveloperAccountPassword(); ?>" /></td>
                                <td><img src="<?php echo $this->getImage('customization/ajax/spinner.gif'); ?>" id="loader_ios_password" alt="Loading" title="Loading" width="24" style="display:none;" /></td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        <div class="area">
            <?php $device = $application->getDevice(2); ?>
            <h3 class="title">
                <span class="left area"><?php echo $this->_("Google's Information"); ?></span>
                <hr class="area reverse" />
                <div class="clear"></div>
            </h3>
            <div class="area_content">
                <div class="ask_if_has_account">
                    <div>
                        <label for="has_android_account_1" class="radio">
                            <input data-tip="51" type="radio" id="has_android_account_1" name="has_android_account" class="has_account autosave input" value="1" onclick="$('#doesnt_have_google_account').slideUp(); $('#has_android_account').slideDown();" />
                            <?php echo $this->_("I have an Google developer account"); ?>
                        </label>
                    </div>
                    <div>
                        <label for="has_android_account_0"  class="radio <?php if(!$device->getUseOurDeveloperAccount()) echo 'checked' ?>">
                            <input data-tip="52" type="radio" id="has_android_account_0" name="has_android_account" class="has_account input" value="0" onclick="$('#has_android_account').slideUp(); $('#doesnt_have_google_account').slideDown();" />
                            <?php echo $this->_("I don't have a Google developer account and I want to create one"); ?>
                        </label>
                    </div>
                    <div>
                        <label for="has_android_account_2" class="radio <?php if($device->getUseOurDeveloperAccount()) echo "checked"; ?>">
                            <input type="radio" id="has_android_account_2" name="has_android_account" class="has_account autosave input" value="2" onclick="$('#has_android_account').slideUp(); $('#doesnt_have_google_account').slideUp();" />
                            <?php echo $this->_('I let you publish my application under your Google developer account'); ?>
                        </label>
                    </div>
                </div>
                <div class="separator"></div>
                <div class="has_account">
                    <div id="has_android_account" style="display:none;">
                        <table class="no-collapse" cellspacing="10" width="100%">
                            <col width="33%"/>
                            <col width="33%"/>
                            <col width="34%"/>
                            <tr>
                                <td><label for="android_username"><?php echo $this->_("Email:"); ?></label></td>
                                <td><input type="text" id="android_username" name="android_username" class="autosave input" value="<?php echo $device->getDeveloperAccountUsername(); ?>" maxlength="30" /></td>
                                <td><img src="<?php echo $this->getImage('customization/ajax/spinner.gif'); ?>" id="loader_android_username" alt="Loading" title="Loading" width="24" style="display:none;" /></td>
                            </tr>
                            <tr>
                                <td><label for="android_password"><?php echo $this->_('Password:'); ?></label></td>
                                <td><input type="password" id="android_password" name="android_password" class="autosave input" value="<?php echo $device->getDeveloperAccountPassword(); ?>" /></td>
                                <td><img src="<?php echo $this->getImage('customization/ajax/spinner.gif'); ?>" id="loader_android_password" alt="Loading" title="Loading" width="24" style="display:none;" /></td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">

    <?php if(!$application->getDevice(2)->getUseOurDeveloperAccount()) : ?>
    $('#has_android_account_1').click();
    <?php else : ?>
    $('#has_android_account_2').click();
    <?php endif; ?>
    <?php if(!$application->getDevice(1)->getUseOurDeveloperAccount()) : ?>
    $('#has_apple_account_1').click();
    <?php else : ?>
    $('#has_apple_account_2').click();
    <?php endif; ?>

    setAppName($('#name').val());
    //changement de nom appli
    $('#name').keyup(function() {
        setAppName($('#name').val());
    });

    function setAppName(name) {
        if(!name) name = '';
        var mobileName = '';
        name = name.trim();
        if(name.length > 11) mobileName = name.substring(0, 10).trim()+'...';
        else mobileName = name;

        var parts = name.split(" ");
        for(var i = 0; i < parts.length; i++) {
            if(parts[i].length >= 10) {
                parts[i] = parts[i].substr(0, 9) + "- " + parts[i].substr(9, parts[i].length);
            }
        }

        var headerName = parts.join(" ");

        $('#app_name').html(mobileName);
        $('#header_app_name').html(headerName);
    }

    $('.autosave').change(function() {
        var input_loader = $('#loader_'+$(this).attr('id'));
        input_loader.show();
            reload(this.parentNode, '<?php echo $this->getUrl('application/customization_publication_infos/save'); ?>', false, function(datas) {
            input_loader.hide();
        }, function() {
            input_loader.hide();
        });
    });
</script>

<style type="text/css">
    .application .infos .ask_if_has_account { padding: 5px; }
    .application .infos input.has_account { min-width: 20px; width: 20px; }

    /*homescreen*/
    #mobile_homescreen {  }
    /*#mobile_homescreen .touch_icon { position: absolute; top: 249px; left: 128px; height: 71px; }*/
    #name:disabled { opacity:0.4 }
    input#name.error { border: 1px dotted red !important }
</style>
