<script type="text/javascript">  
theight=$( document ).height()-50; 
function setdg(){
	$('#dg').datagrid({  	
		height:theight,		
		toolbar:"#toolbar",
		fit:true,
		fitColumns:true,
		rownumbers:true,		
		pagination:true,
		pageSize:100,
		pageList:[100,200,300,400,500],
		frozenColumns:[[  
			{field:'id',title:'id',width:80,hidden:true},
			{field:'KdPrshn',title:'Kode'},
			{field:'NmPrshn',title:'Nama',width:373},
		]],
		columns:[[			
			{field:'nm_tp_prshn',title:'Tipe',width:92},
			// {field:'NpwpPrshn',title:'NPWP'},
			{field:'AlmtPrshn',title:'Alamat',width:419},
			{field:'NmNegara',title:'Negara',width:143},
			// {field:'fax',title:'NPWP.',width:115},
			// {field:'tlp',title:'Telp.',width:115},
			{field:'Valuta',title:'Valuta',width:151},			
			// {field:'Kurs',title:'Kurs',width:150},		
			{field:'NitKu',title:'Nitku',width:115}			
		]],
		onBeforeLoad: function (data) {
		  var panel = $(this).datagrid("getPanel");
		  // here is to add the css style
		  panel.css("border","0");
		},
		url: '<?=site_url('company_supplier/grid'); ?> '
	});
}
function cari(q){
	$('#dg').datagrid({
		queryParams:{q:q}		
	});
}
var url;
function tambah(){
	$('#dlg').dialog('open').dialog('setTitle','Tambah <?=$title?>');
	$('#fm').form('clear');
	$("[name=kd_jns_kelamin]").val(["L"]);
	url = '<?=site_url('company_supplier/getform/add'); ?>';
}
function ubah(){
	var row = $('#dg').datagrid('getSelected');
	$('#empl_id').combogrid({  
		editable:false  
    });  
	if (row){
		$('#dlg').dialog('open').dialog('setTitle','Ubah <?=$title?>');
		$('#fm').form('load',row);
		url = '<?=site_url('company_supplier/getform/edit'); ?>';
	}
}
function simpan(){
	$('#fm').form('submit',{
		url: url,
		onSubmit: function(){				
			return $(this).form('validate');
		},
		success: function(result){
			//alert(result);
			var result = eval('('+result+')');
			if (result.success){
				$('#dlg').dialog('close');		// close the dialog
				$('#dg').datagrid('reload');	// reload the company data
				$.messager.show({
					title: 'Info',
					msg: result.msg
				});
			} else {
				$.messager.show({
					title: 'Error',
					msg: result.msg
				});
			}
		}
	});
}
function validasi(strings){
	var i=0;
	var ch='';
	
	num=0;
	ucase=0;
	lcase=0;
	while (i <= strings.length){
		character = strings.charAt(i);
		if (!isNaN(character * 1)){
			num=1;
		}else{
			if (character == character.toUpperCase()) {
				ucase=1;
			}
			if (character == character.toLowerCase()){
				lcase=1;
			}
		}
		i++;
	}
	if (num==0 || ucase==0 || lcase==0){ 
		return false; 
	} else {
		return true;
	}
}
function hapus(){
	var row = $('#dg').datagrid('getSelected');
	if (row){
		$.messager.confirm('Confirm','Apakah anda yakin akan menghapus data ini?',function(r){
			if (r){
				$.post('<?=site_url(); ?>company_supplier/del',{id:row.id},function(result){
					var result = eval('('+result+')');
					if (result.success){
						$('#dg').datagrid('reload');	// reload the company data
						$.messager.show({
							title: 'Info',
							msg: result.msg
						});
					} else {
						$.messager.show({	// show error message
							title: 'Error',
							msg: result.msg
						});
					}
				});
			}
		});
	}
}
function toprint(){
	var opts = $('#dg').datagrid('options');
	q=$("#q").val();
	
	var win = window.open('<?= site_url()?>company_supplier/cetak?q='+q+'&page='+opts.pageNumber+'&rows='+opts.pageSize,'Popup','toolbar=no, location=no,status=no,menubar=no,scrollbars=yes,resizable=no');
	win.print();
}
function toxls(){
	var opts = $('#dg').datagrid('options');
	txtcari=$("#txtcari").val();
	q=$("#q").val();
	openurl('<?=site_url();?>company_supplier/excel?q='+q+'&page='+opts.pageNumber+'&rows='+opts.pageSize);
}
function topdf(){
	openurl("<?=site_url();?>company_supplier/topdf");
}
function insert_nama(row){
	$("#nama").val(row.nama);
}
</script>	