<script language="javascript" type="text/javascript">
    var view_url = "<?php echo Yii::app()->createAbsoluteUrl("/tid/view"); ?>";
    var asset_create_url = "<?php echo Yii::app()->createAbsoluteUrl("/asset/create"); ?>";
    var invoice_create_url = "<?php echo Yii::app()->createAbsoluteUrl("/invoice/create"); ?>";
    
</script>
<style>

    .accordion-group {
	width: 1150px !important;
    }
    #Invoice_value {
        width: 170px !important;
    }   

    #Invoice_tid_id
    {
	width: 176px !important;
        border-bottom-right-radius: 0px !important;
        border-top-right-radius: 0px !important;
    }

</style>

<div id='dialog'></div>
<?php
/* @var $this InvoiceController */
/* @var $model Invoice */
/* @var $form CActiveForm */
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
	    'id' => 'invoice_form',
	    'enableAjaxValidation' => false,
	));

$this->widget('bootstrap.widgets.TbAlert');
?>
<div id="flash-msg">
    <br>
    <?php $this->widget('bootstrap.widgets.TbAlert'); ?>
</div>
  <?php
	       if ($tid_id != '') {?>
<div class="accordion-group">
    <div class="accordion-heading">
	<a class="accordion-toggle" data-toggle="collapse"
	   data-parent="#accordion2" href="#collapse0">
	       <?php echo Yii::t('default', 'Saved Invoices'); ?>
	</a>
    </div>
    <div id="collapse0" class="accordion-body collapse in">
	<div class="accordion-inner">
	  <?php
		   Yii::app()->controller->renderPartial('/invoice/viewInvoiceInTid', array('model' => new Invoice('search'), 'tid_id' => $tid_id, 'page_name' => 'saveAndAdd'));
	       
	    ?>
   	</div>
       </div>
   </div>
   <br/>
   <?php } ?>
<?php
	       echo $form->labelEx($model, 'tid_id');

	       $form->widget('zii.widgets.jui.CJuiAutoComplete', array(
		   'model' => $model,
		   'attribute' => 'tid_id',
		   'source' => array_values(tid::getNumbersForDropDown()),
		   'options' => array(
		       'minLength' => '0',
		   ),
		   'htmlOptions' => array(
		       'disabled' => ($tid_id != ''),
		       'placeholder' => 'Search By TID No'
		   )
	       ));
	       echo TbHtml::image(Yii::app()->request->baseUrl . '/css/flags/search.png', '', array("style" => ""
		   . "display: inline-block;
                                        vertical-align: top;
                                        margin-top: 0px;
                                        margin-left: 0px;
                                        border: 1px solid #CCC;
                                        padding: 2px;                                    
                                        -webkit-border-bottom-right-radius: 6px;
                                        -webkit-border-top-right-radius: 6px;                                        
                                        -moz-border-bottom-right-radius: 6px;
                                        -moz-border-top-right-radius: 6px;
                                        border-bottom-right-radius: 6px;
                                        border-top-right-radius: 6px;",
		       )
	       );

	       echo $form->textFieldControlGroup($model, 'number', array('size' => 50, 'maxlength' => 50));

	       echo $form->textFieldControlGroup($model, 'value', array('size' => 15, 'maxlength' => 15, 'append' => 'USD'));
?>

<?php
	       echo $form->textAreaControlGroup($model, 'description', array('size' => 255, 'maxlength' => 255,));

	       echo $form->textAreaControlGroup($model, 'comments', array('size' => 255, 'maxlength' => 255,));
?>



	       <div class="actions">

<?php
	       echo CHtml::ajaxSubmitButton(
		       Yii::t('default', 'Save'), ($model->isNewRecord) ? array('create', 'tid_id' => $tid_id) : array('update', 'id' => $model->id), array(
		   'type' => "post",
		   'success' => 'js:function(data) {
            
			   if(data.indexOf("</div>") != -1){
                                $("#flash-msg").html(data);
				$("html, body").animate({ scrollTop: 0 }, "slow");
				}
                           else
                           if(data.indexOf("dialog") != -1){
                                var result = data.split("#");                                
                                $("#dialog").html(result[1]);
                                $("#dialog").dialog({
                                        width: "490px",  
                                        title: "Confirmation Message",
                                        modal: true,
                                        buttons: {
                                        Yes: function() {
                                        $("#invoice_form").append("<input type=\'hidden\' name=\'dialogResult\' id=\'pass\' value=\'true\' />");
                                                $("#submit_button").click();
                                               $(this).dialog("close");
                                        },
                                        No: function() {
                                                $(this).dialog("close");
                                        }				
                                    },
                                });
                           }
                           else{
                                var result = data.split("#");  
                                window.location.href=addParam(view_url,"id",result[1]);
                                }


		    }',
		       ), array('type' => 'submit', 'class' => 'btn primary', 'name' => 'submit_button', 'id' => 'submit_button')
	       );
?>
	       &ensp;
<?php
	       echo CHtml::ajaxSubmitButton(
		       Yii::t('default', 'Save and Add Invoice'), ($model->isNewRecord) ? array('create', 'from' => 'New', 'tid_id' => $tid_id) : array('update', 'id' => $model->id, 'from' => 'New'), array(
		   'type' => "post",
		   'success' => 'js:function(data) {
			   if(data.indexOf("</div>") != -1){
                                $("#flash-msg").html(data);
				$("html, body").animate({ scrollTop: 0 }, "slow");
				}
                           else
                           if(data.indexOf("dialog") != -1){
                                var result = data.split("#");
                                $("#dialog").html(result[1]);
                                $("#dialog").dialog({
                                width: "490px", 
                                        title: "Confirmation Message",
                                        modal: true,
                                        buttons: {
                                        Yes: function() {
                                        $("#invoice_form").append("<input type=\'hidden\' name=\'dialogResult\' id=\'pass\' value=\'true\' />");
                                                $("#submit_button_new").click();
                                               $(this).dialog("close");
                                        },
                                        No: function() {
                                                $(this).dialog("close");
                                        }				
                                    },
                                });
                           }
                           else {
                                var result = data.split("#");  
                                window.location.href=addParam(invoice_create_url,"tid_id",result[1]);
                             }


		    }',
		       ), array('type' => 'submit', 'class' => 'btn primary', 'name' => 'submit_button_new', 'id' => 'submit_button_new')
	       );
?>
	       &ensp;
<?php
	       echo CHtml::ajaxSubmitButton(
		       Yii::t('default', 'Save and Add Asset'), ($model->isNewRecord) ? array('create', 'from' => 'New', 'tid_id' => $tid_id) : array('update', 'id' => $model->id, 'from' => 'New'), array(
		   'type' => "post",
		   'success' => 'js:function(data) {
			   if(data.indexOf("</div>") != -1){
                                $("#flash-msg").html(data);
				$("html, body").animate({ scrollTop: 0 }, "slow");
				}
                           else
                           if(data.indexOf("dialog") != -1){
                                var result = data.split("#");
                                $("#dialog").html(result[1]);
                                $("#dialog").dialog({
                                width: "490px", 
                                        title: "Confirmation Message",
                                        modal: true,
                                        buttons: {
                                        Yes: function() {
                                        $("#invoice_form").append("<input type=\'hidden\' name=\'dialogResult\' id=\'pass\' value=\'true\' />");
                                                $("#submit_button_new_asset").click();
                                               $(this).dialog("close");
                                        },
                                        No: function() {
                                                $(this).dialog("close");
                                        }				
                                    },
                                });
                           }
                           else {
                                var result = data.split("#");  
                                var url = addParam(asset_create_url,"tid_id",result[1]);
                                window.location.href=addParam(url,"invoice_id",result[0]);
                             }


		    }',
		       ), array('type' => 'submit', 'class' => 'btn primary', 'name' => 'submit_button_new_asset', 'id' => 'submit_button_new_asset')
	       );
?>
	       &ensp;
<?php echo CHtml::link(Yii::t('default', 'Cancel'), array('index'), array('class' => 'btn primary')); ?>
	   </div>

<?php $this->endWidget(); ?>




