 
Ext.onReady(function(){
    Ext.QuickTips.init();
    Ext.form.Field.prototype.msgTarget = 'side';
    var msg = function(title, msg){
        Ext.Msg.show({
            title: title, 
            msg: msg,
            minWidth: 200,
            modal: true,
            icon: Ext.Msg.INFO,
            buttons: Ext.Msg.OK
        });
    };
    var chooser, btn;
	 var cascade_limitation = 20;
	function date_style(val){
		var dt = new Date( val );
		return '<span style="float: right;">' + dt.format('j F Y') + '</span>';
	}
	function num_style(val){
			return '<span style="float: right;">' + val + '</span>';
		}
		 
	/* Hidden values
	-------------------------------------*/
	var thisFormStatus = '';
	var input_width = 630;
	
	var hidenCo_alldoci_asn_thisVal_id = new Ext.form.Hidden({
		id:'value_alldoci_asn_thisVal_Id',
		name:'value_alldoci_asn_thisVal_Id'
	});
	var hidden_alldoci_asn_thatVal_id = new Ext.form.Hidden({
		id:'value_alldoci_asn_thatVal_Id',
		name:'value_alldoci_asn_thatVal_Id'
	});
	var hidden_alldoci_asn_thereVal_id = new Ext.form.Hidden({
		id:'value_alldoci_asn_thereVal_Id',
		name:'value_alldoci_asn_thereVal_Id'
	});
	
	var hidden_alldoci_asn_theyreVal_id = new Ext.form.Hidden({
		id:'value_alldoci_asn_theyreVal_Id',
		name:'value_alldoci_asn_theyreVal_Id'
	});
	var table_style	= 'font-family:tahoma,arial,sans-serif; font-size: 12px;';
	var btn_style	= 'width: 50px; cursor: pointer; border: 1px solid; padding: 5px;';
	var img_path	= 'assets/images/btn_icon/';		
   //alert(jobid);
   /* My Template data
   --------------------*/
	/* THIS FUNCTIONS
	 -----------------*/
	 function show_popCalc(id){
		window.open("v3/employee_finder/get/"+str_id);
    }
    
    /* BEGIN COMBOS
    ----------------*/
     
	/* BEGIN PANEL
	---------------*/
	var store_mgmalldocumentsfnl_dstm = new Ext.data.GroupingStore({
		proxy: new Ext.data.HttpProxy({
			url: 'v3/domestic_helpers/getall_dh'
		}),
		reader: new Ext.data.JsonReader({
		root: 'value_data',
		totalProperty: 'total_data',
		id: 'id',
		fields: [
			'id', 'position', 'name', 'contract_period', 'nationality', 'religion', 'birthday',
			'age', 'civil_status', 'lang_en', 'no_work_exp'
		]
		}),
		sortInfo:{field: 'position', direction: "DESC"},
		groupField:'position',
		baseParams: {sel_exps: sel_exps, sel_relig: sel_relig, sel_lang: sel_lang, sel_status: sel_status, sel_age: sel_age },
		remoteSort: false
	});
	 
	/* create the Grid
	-------------------------------------*/
	var grid_mgmalldocumentFnl_conts_gds = new Ext.grid.GridPanel({
		store: store_mgmalldocumentsfnl_dstm,
		columns: [
			{id:'id',header: "ID", width: 18, hidden: true,  renderer: num_style, sortable: true, dataIndex: 'id'},
			{header: "Name", width: 50, sortable: true, dataIndex: 'name'},
			{header: "Position", width: 50, sortable: true, dataIndex: 'position'},
			{header: "Nationality", width: 30, sortable: true, dataIndex: 'nationality'},
			{header: "Religion", width: 30, sortable: true, dataIndex: 'religion'},
			{header: "Birthday", width: 25, sortable: true, dataIndex: 'birthday'},
			{header: "Age", width: 20, sortable: true, dataIndex: 'age'},
			{header: "Marital Status", width: 37, sortable: true, dataIndex: 'civil_status'},
			{header: "English Proficiency", width: 50, sortable: true, dataIndex: 'lang_en'},
			{header: "Work Exp.", width: 50, sortable: true, dataIndex: 'no_work_exp'},
			{header: "Contract Period", width: 40, sortable: true, dataIndex: 'contract_period'}
		 ],
		view: new Ext.grid.GroupingView({
			forceFit:true,
			groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'
		}),
		stripeRows: true,
		frame: true,
		autoExpandColumn: 'id',
		autoScroll: true,
		width: 895,
		height: 400,
		bbar: new Ext.PagingToolbar({
            pageSize: cascade_limitation,
            store: store_mgmalldocumentsfnl_dstm,
            displayInfo: true 
        })
	});
	
	var form_mgmdocsall_assigner_fpsm = new Ext.FormPanel({
		frame:true,
		title: 'Available Applicants',
		iconCls:'icon-cmp',
		bodyStyle: 'text-align: left; ',
		width: 910,
		items: [{
			items: grid_mgmalldocumentFnl_conts_gds
		},{
		   	layout:'column',
					id: 'area_panel_button_bottombar',
		            items:[{
		                columnWidth:.5,
		                layout: 'form',
		                items: [{
							xtype:'panel',
							html: '<table style="'+table_style+'"><tr>'+
							'<td>'+
								'<div id="btn_alldoci_asn_edi" align="center" '+
									'style="'+btn_style+'">'+
									'<img src="'+img_path+'edit.png" /><br />'+
									'Edit'+
								'</div>'+
							'</td>'+
							'</tr></table>'
					    }]
		            }]
			}]
		});
   form_mgmdocsall_assigner_fpsm.render('domestic_helper_htgrid');			
	store_mgmalldocumentsfnl_dstm.load( {params:{start:0, limit:cascade_limitation}} );
	
	var str_id = "";
	grid_mgmalldocumentFnl_conts_gds.on('rowclick',function(objGrid, rowindex, e){
				state_form = 'submit_edited';
				var rowSelection = objGrid.getSelectionModel().getSelected();
				//alert(rowSelection);
				
				str_id = rowSelection.get("id");
				show_popCalc(str_id);
	});
});