 <style type="text/css">
        .img-contact
        {
            vertical-align: middle;
            margin: 0px 0px 0px 0px;
            width:75px;
            height:100px;
        }
        .x-fieldset
        {
            border-style: solid none none none;
            border-width: 1px;
            border-color: #B5B8C8;
            padding: 10px;
            margin-bottom: 10px;
            margin-right: 20px;
            display: block;
        }
    </style>

<?php require "_header.php"; ?>
<?php 

$inquiry_id= Escape($_REQUEST["ID"]);
if ($inquiry_id !="" && isset($inquiry_id)) { 
		$mode="edit";	
		$limit=1;
		$start=0;
		$condition=" and inquiry_id = '$inquiry_id' ";
		$order_field="";
		$order_type="";
		    			
		$objInquiryMgmt = new InquiryMgmt();
		
		$out =  $objInquiryMgmt->getAllRecords(0,0,$condition,$order_field,$order_type) ;
		if (dbRows($out)){
			$row=dbArray($out);
			extract($row);
			$followup_id=0;			
		}    	   
}
$followup_id= Escape($_REQUEST["followupID"]);
if ($followup_id !="" && isset($followup_id)) { 

		$mode="fellowedit";	
		$limit=1;
		$start=0;
		$condition=" and followup_id = '$followup_id' ";
		$order_field="";
		$order_type="";
		    			
		$objfollowUpMgmt = new followUpMgmt();  
		
		$out = $objfollowUpMgmt->getAllRecords(0,0,$condition,$order_field,$order_type) ;
		if (dbRows($out)){
			$row=dbArray($out);
			extract($row);			
		}  

}
else{
	$mode="add";
	$inquiry_id=0;
	$followup_id=0;
}
?>
<script type="text/javascript" src="jquery/ux/CheckColumn.js"></script>
<?php require "includeGridFilters.php";?> 
<script type="text/javascript" language="javascript"> 

var formMode = '<?php echo $mode;?>';
var followup_id = '<?php  echo $followup_id; ?>';
var inquiry_id = '<?php  echo $inquiry_id; ?>';
var product_ids = '<?php  echo $product_ids; ?>';


var labelArray;
	
	labelArray = [
		['Inquiry Close:'],
		['Follow up Date :'],
		['Follow up Time :'],
	];
	
	Ext.QuickTips.init();

Ext.onReady(function() {

    function formatDate(value){
        return value ? value.dateFormat('M d, Y') : '';
    }
	var encode = false;
	var local = false;

    var fm = Ext.form;
    var checkColumn = new Ext.grid.CheckColumn({
       header: 'Select',
	  dataIndex:'selected',
	  id: 'selected',
	  name: 'selected',
	  width: 55
    });
	
	 var finalleadstore = new Ext.data.ArrayStore({
           fields: ['finallead'],
	       data: [['Yes'],['No']]
        }); 
	
	store = new Ext.data.JsonStore({
       	autoDestroy: true,
        url:'data/getproduct-data.php',
        remoteSort: true,
        sortInfo: {
            field: 'product_id',
            direction: 'ASC'
        },        
        idProperty: 'product_id',
        root: 'data',
        totalProperty: 'total',
        fields: [{
            name: 'product_id',
			type: 'int'
        }, {
            name: 'product_name'
        }, {
            name: 'product_price'
        },
		{name:'selected', type: 'bool'}
		]
    });
    
var createColModel = function (finish, start) {
        var columns = [
		{
            dataIndex: 'product_id',
			header: 'Product ID',
			hidden:true
			
        }, {
            dataIndex: 'product_name',
			header: 'Product Name',
			width: 400
        }, {
            dataIndex: 'product_price',
			header: 'Price',
			width:120
        },checkColumn];
		return new Ext.grid.ColumnModel({
        columns: columns.slice(start || 0, finish),
            defaults: {
                sortable: true
            }
        });
    };
	
var grid = new Ext.grid.GridPanel({
        store: store,
		colModel: createColModel(40), 
        loadMask: true,
		frame: false,
		enableColLock:false,
		height:150,    
        width: 600,
        layout: 'fit',
		columnLines:true,
    	selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
		plugins: checkColumn
    });



var busAddress = { columnWidth: .45,
    layout: 'form',
	labelWidth: 92,
    items: [{   width:130,
				xtype: 'combo',
				name: 'finallead',
				id:'finallead',
				labelSeparator:'',	
				fieldLabel :labelArray[0],
				forceSelection:true,				
				displayField:'finallead',
				valueField: 'finallead',
				emptyText:'',
				allowBlank:false,
				triggerAction:'all',
				mode:'local',
				store: finalleadstore,
   				listeners:{select:{fn:function(combo, value) 
                {
					if(combo.getValue()=='No')
					{
						Ext.getCmp('followupdate').enable();
						Ext.getCmp('followuptime').enable();
						Ext.getCmp('comment').enable();
					}
					else
					{
						Ext.getCmp('followupdate').reset();
						Ext.getCmp('followuptime').reset();
						Ext.getCmp('comment').reset();
						Ext.getCmp('followupdate').disable();
						Ext.getCmp('followuptime').disable();
					}
				}	
				}}

				},{
				xtype: 'datefield',
				name: 'followupdate',
				labelSeparator:'',	
				allowBlank:false,
				fieldLabel :labelArray[1] 
				,width:130
				,disabled:true
				,id: 'followupdate'
				,vtype: 'daterange'
				 
			  },{
			  xtype: 'timefield',
				name: 'followuptime',
				labelSeparator:'',	
				fieldLabel :labelArray[2] 
				,width:130
				,allowBlank:false
				,disabled:true
				,id: 'followuptime'
				 
			  }]
}

var homeAddress = {columnWidth: .55,
    layout: 'form',
	labelWidth: 60,
    items: [{
			  layout: 'form',					
			  items:[{	xtype: 'textarea',
						width:240,
						name: 'comment',
						fieldLabel:'Comment',
						id:'comment'
					 },{
			xtype: 'textfield',
            name: 'product_ids',
            id:'product_ids',
			value:product_ids,
			hidden:true
        },{
			xtype: 'textfield',
            name: 'followup_id',
            id:'followup_id',
			value:followup_id,
			hidden:true
        },{
			xtype: 'textfield',
            name: 'inquiry_id',
            id:'inquiry_id',
			value:inquiry_id,
			hidden:true
        }]				
		  }]
}


    var inquiryForm = new Ext.FormPanel({
        frame: true,
		url:'save-followup.php',
        bodyStyle: 'padding:5px',
        width: 650,				
        items: [{
            bodyStyle: {
                margin: '0px 0px 0px 0px'
            }
            },{
                    xtype: 'fieldset',
                    title: '',
					width: 620,	
                    autoHeight: true,
                    hideBorders: true,
                    layout: 'column',
                    items: [busAddress,homeAddress]
		
				},{
                    xtype: 'fieldset',
                    title: 'Product List',
                    autoHeight: true,
                    hideBorders: true,
                    layout: 'column',
                    items: [grid]
		}]
    });
	

var inquiryWindow = new Ext.Window({
		title: 'Follow Up Deatil',
		width:655,		
		height:415,
		modal:true,
		shadow: false,
		border: false,
		layout: 'fit',
		closeAction:'close',
		collapsible:true,
		items: inquiryForm,
		buttonAlign: 'center',
	    buttons: [{
            text: 'Save',			
			handler: function () {
				var selectedproduct_ids = "";
				var produdct_id= "";
				for(var i = 0,len = grid.store.getCount(); i < len; i++)
				{
					var record = grid.store.getAt(i);
					if(record.data.selected == true)
					{
							 produdct_id =record.data.product_id;
							 selectedproduct_ids = selectedproduct_ids + produdct_id + ",";
						 
					}
							
				}	
				if(produdct_id!="")
				{
					selectedproduct_ids= selectedproduct_ids.substr(0,selectedproduct_ids.length - 1);
					inquiryForm.getForm().findField('product_ids').setValue(selectedproduct_ids);
					inquiryForm.getForm().submit({
					waitMsg: 'Saving...',		
					success: function () {
					Ext.MessageBox.show({
									   title: 'Message',
									   msg: 'Data has been saved..',
									   buttons: Ext.MessageBox.OK,
									   icon:Ext.MessageBox.INFO
				                      });
									  inquiryForm.getForm().reset();
									  store.load();
									  if(formMode=='edit'){
											location.href="search-product-inquiry.php";
										}
										else if(formMode=='fellowedit')
										{
											location.href="view-product-inquiry-followup.php";
										 }
							
					},
					failure: function () {	
						
								Ext.MessageBox.show({
									   title: 'Error',
									   msg: 'Please fill complete form!',
									   buttons: Ext.MessageBox.OK,
									   icon:Ext.MessageBox.ERROR
				                      });
			
					     
					}
				});
				}	
				else
				{
					
					 Ext.MessageBox.show({
								   title: 'Error',
								   msg: 'Please Select Product.',
								   buttons: Ext.MessageBox.OK,
								   icon:Ext.MessageBox.ERROR
								});
				}
				
			}
          },
		           {
            text: 'Reset',
			handler: function () {
			if(formMode!='edit'){
				inquiryForm.getForm().reset();
			store.load();
			}
			
						
			 		
			}
        },
	 	           {
            text: 'Close',
			handler: function () {
			if(formMode=='edit'){
				location.href="search-product-inquiry.php";
			}
			else if(formMode=='fellowedit')
			{
				location.href="view-product-inquiry-followup.php";
			 }
			 else
			 {
			 	inquiryWindow.close();
			 }	
			}
        }
	 ]

	});
	
	var varWidth =  (screen.width - inquiryWindow.width)/2;
	inquiryWindow.setPosition(varWidth,((screen.height/4)-110));
	inquiryWindow.show();	
	if(formMode=='add'){
	   store.load();
	}
	
	if(formMode=='edit'){
	<?php
	$comment 		= replaceSpecial($comment);
	
	?>	
		store.load({
                        params: {inquiry_id:<?php print $inquiry_id; ?>}
                    });
	}
	else if(formMode=='fellowedit'){
	<?php
	$comment = replaceSpecial($comment);
	
	?>
		inquiryForm.getForm().findField('finallead').setValue('<?php print $leadfinal; ?>');
		if('<?php print $leadfinal; ?>'=='No')
		{
						Ext.getCmp('followupdate').enable();
						Ext.getCmp('followuptime').enable();
						
			inquiryForm.getForm().findField('followupdate').setValue('<?php print $followupdate; ?>');
     		inquiryForm.getForm().findField('followuptime').setValue('<?php print $followuptime; ?>');
			inquiryForm.getForm().findField('comment').setValue('<?php print $comment; ?>');
		}
		
		store.load({
                        params: {inquiry_id:<?php print $inquiry_id; ?>}
                    });
	}

});
</script>
<div align="center"><div id="main-content" align="center"></div></div> 
<?php require "_footer.php";?>