<?php
$form = $this->beginWidget('ext.PlGrid.PlActiveForm', array(
    'id' => 'credential-password',
    'gridId' => 'third-party-credentials-grid',
    'action' => $model->isNewRecord ? array('create') : array()
        ));
echo $form->passwordFieldRow($model, 'newPassword', array(
    'class' => 'span3',
    'value' => '',
    'data-translation-id' => 'THIRDPARTYCREDENTIAL_MODEL_NEW_PASSWORD',
));

echo $form->passwordFieldRow($model, 'confirmPassword', array(
    'class' => 'span3',
    'value' => '',
    'data-translation-id' => 'THIRDPARTYCREDENTIAL_MODEL_CONFIRM_PASSWORD',
));
echo "<div id='password-info'class='alert alert-info' data-translation-id='THIRDPARTYCREDENTIAL_MODEL_PASSWORD_INFO'>" . __("THIRDPARTYCREDENTIAL_MODEL_PASSWORD_INFO") . "</div>";
echo $form->textFieldRow($model, 'serverURI', array('data-translation-id' => 'THIRDPARTYCREDENTIAL_MODEL_SERVERURI', 'readonly' => true));
echo $form->errorSummary($model);
$this->endWidget();
?>
<script>
    $('#ThirdPartyCredential_serverURI').closest(".control-group").hide();
    $('#credential-password').submit(validateIDandPassword);
    function validateIDandPassword() {
        $.ajax({
            url: "<?php echo Yii::app()->createUrl('phonesettingsThirdPartyCredentials/default/validateICloudCredentials'); ?>",
            type: "POST",
            async: false,
            dataType: "json",
            data: {username: "<?php echo $model->username; ?>", password: $('#ThirdPartyCredential_newPassword').val()},
            success: function (result) {
                if (result !== "false") {
                    $('#ThirdPartyCredential_serverURI').val(result);
                    return true;
                } else {
                    $('#ThirdPartyCredential_serverURI').val('');
                    return false;
                }
            }
        });
    }
</script>