/**
	States
**/

/**Constructor of Interface**/

function IState(locator) {
  this.locator = locator;
}

/**prototype of method**/
/**

**/
IState.prototype.set_address = function() {}


IState.prototype.change_address = function() {
	this.locator.left_info.hide();
	this.locator.open_address();
}

IState.prototype.error_message = function(code) {
		var wc_error_message;
		switch (code)
			{
				case G_GEO_UNKNOWN_ADDRESS     : wc_error_message = GL_ERR_UNKNOWN_ADDRESS;     break;							
				case G_GEO_BAD_REQUEST         : wc_error_message = GL_ERR_BAD_REQUEST;         break;
				case G_GEO_SERVER_ERROR        : wc_error_message = GL_ERR_SERVER_ERROR;        break;
				case G_GEO_MISSING_ADDRESS     : return false;                                  break;
				case G_GEO_UNAVAILABLE_ADDRESS : wc_error_message = GL_ERR_UNAVAILABLE_ADDRESS; break;							
				case G_GEO_TOO_MANY_QUERIES    : wc_error_message = GL_ERR_TOO_MANY_QUERIES;    break;
				case G_GEO_UNKNOWN_DIRECTIONS  :wc_error_message  = GL_ERR_UNKNOWN_DIRECTIONS;  break;
				default: wc_error_message = GL_ERR_DEFAULT +  code;
			}
			this.locator.right_error_address.set(wc_error_message);
			this.locator.right_error_address.show();

	}
IState.prototype.default_action = function() {
	
	this.locator.center_loading_box.hide();
}


function DirectionsState(locator){
	this.locator = locator;		
}
function StartState(locator){
	this.locator = locator;
}
function EmptyState(locator){
	this.locator = locator;	
	
}
function NormalState(locator){
	this.locator = locator;		
			
}
/**StartState inherited of IState **/
StartState.prototype  = new IState(); 
EmptyState.prototype  = new IState(); 
NormalState.prototype = new IState(); 

DirectionsState.prototype = new NormalState();

EmptyState.prototype.error = function(code) {
	if (code!=null)this.error_message(code);	
	this.locator.search_string = '';
	this.locator.left_info.show();
	this.locator.left_info.set("Enter location to see nearby "+this.locator.site_name+" stores.");
	this.locator.left_error_localsearch.hide();
	this.locator.left_loading_box.hide();
	this.locator.map.setCenter(new GLatLng(37,-95),3);
	this.default_action();
}

EmptyState.prototype.post_loaded_address = function(){
	this.locator.change_state(new NormalState(this.locator));
	this.locator.load_stores();
}

NormalState.prototype.error = function(code) {
		this.error_message(code);
		this.default_action();
	
	}

NormalState.prototype.post_loaded_address = function(){

	this.locator.load_stores();
}

DirectionsState.prototype.post_loaded_address = function(){

	this.locator.load_directions();
}

/* DirectionsState.prototype.change_address = function () {
	this.locator.load_dirs_direct();

} */

DirectionsState.prototype.error = function(code) {
		this.error_message(code);
		this.default_action();
		this.locator.search_string = this.locator.current_address_directions;
	}