//	Client side sctipting for location finder component
//
//  @version    1.0
//  @company    Liquid Edge Solutions
//	@copyright  Copyright Liquid Edge Solutions. All rights reserved.
///--------------------------------------------------------------------------------

// contructor

//--------------------------------------------------------------------------------
var com_locationfinder = function(the_cid) {
  	// properties
  	this.cid = the_cid; // unique id for component

  	// elements
  	this.e_block = $(this.cid + '_block');
  	this.e_iframe = $(this.cid + '_iframe');

  	this.e_id = $(this.cid + '__id');
  	this.e_city = $(this.cid + '__city');
  	this.e_suburb = $(this.cid + '__suburb');
  	this.e_code = $(this.cid + '__code');
  	this.e_province = $(this.cid + '__province');

  	this.e_type = $(this.cid + '__type');

  	this.e_findsuburb = $(this.cid + '_suburb');
  	this.e_findcode = $(this.cid + '_code');
}
//--------------------------------------------------------------------------------

// globals

//--------------------------------------------------------------------------------
com_locationfinder.current = null;
//--------------------------------------------------------------------------------

// prototype

//--------------------------------------------------------------------------------
com_locationfinder.prototype = {
	//--------------------------------------------------------------------------------
	show: function() {
		cr.element.show(this.e_block);
		cr.element.show(this.e_iframe);
	  	if (com_locationfinder.current != this && com_locationfinder.current != null) com_locationfinder.current.hide();
	  	com_locationfinder.current = this;
	},
	//--------------------------------------------------------------------------------
	hide: function() {
		cr.element.hide(this.e_block);
		cr.element.hide(this.e_iframe);
	},
	//--------------------------------------------------------------------------------
	select: function(the_id, the_city, the_suburb, the_code, the_province) {
		$$getvalue(this.e_id, the_id);
		$$getvalue(this.e_city, the_city);
		$$getvalue(this.e_suburb, the_suburb);
		$$getvalue(this.e_code, the_code);
		$$getvalue(this.e_province, the_province);

		// disable province selection when not 'unknown'
		if (the_province != '1') this.e_province.disabled = true;
		else this.e_province.disabled = false;

		this.hide();
	},
	//--------------------------------------------------------------------------------
	find_code: function() {
		$$getvalue(this.e_findsuburb, '');
		var code_value =  $$getvalue(this.e_findcode);
		if (code_value) core.ajax.requestUpdate('index.php?m=general&j=xlist_locationfinder&cid=' + this.cid + '&' + this.cid + '_code=' + code_value + '&' + this.cid + '__type=' + $$getvalue(this.e_type), this.cid + '_findresults');
	},
	//--------------------------------------------------------------------------------
	find_suburb: function() {
		$$getvalue(this.e_findcode, '');
		var suburb_value =  $$getvalue(this.e_findsuburb);
		if (suburb_value) core.ajax.requestUpdate('index.php?m=general&j=xlist_locationfinder&cid=' + this.cid + '&' + this.cid + '_suburb=' + suburb_value + '&' + this.cid + '__type=' + $$getvalue(this.e_type), this.cid + '_findresults');
	}
	//--------------------------------------------------------------------------------
}