<?php 
include_once("_dirinfo.php");
include_once(PATH_TO_ROOT."CRM/_CRM_config.php");

 class ZipChecker {
 
 	private $db;
	private $zipField;
	private $cityField;
 
 	function __construct($db,$zipField, $cityField) { 
 		$this->db = $db; 
		$this->zipField = $zipField;
		$this->cityField = $cityField;
	}
	function SetUp(){
		echo "Ext.getCmp('$this->zipField').setMaxValue('9999');";
		echo "Ext.getCmp('$this->zipField').on('blur', function(a,b){
			var zip = Ext.getCmp('$this->zipField').getValue();
			if(zip.toString().length == 4){
				Ext.Ajax.request({
					url: '".CRM_RPATH."_forms/_ajax/ajax.zipCheck.php',
					params:{
						action: 'get',
						zip: zip
					},
					success: function(resp, opt){
						Ext.getCmp('$this->cityField').setValue(resp.responseText);
					}
				});
				Ext.getCmp('$this->cityField').setReadOnly(true);
			}else{
				Ext.getCmp('$this->cityField').setReadOnly(false);
			}
		});
		Ext.getCmp('$this->cityField').on('select', function(comp, record, index){
			Ext.getCmp('$this->zipField').setValue(record.data.codeColumn);
		});
		";
			
	}
 } 