//////////////////////////////////////////////////////////////////////////////////////////////////////////
//:: STATION SELECT CONTROLS ::
function StationSelectControls( params ) { //:: CLASS

  this.postURL = _ROUTE_INIT+ ( _GET['rt'] || 'home' ); //'http://'+_HOME+'model/ajax/selectstation.ajax.php'; 
  this.params = params;

  ////////////////////////////////////////////////////////////////////////////////
  this.onSelectStation = function( station_id ) {
    //:::::::::::::::::::::::::::
    if( isNumeric( station_id ) ) { 
      //:::::::::::::::::::::::::::
      if( /NO_SET_COOKIE/i.test( this.params ) == false ) { $.cookie( visitorProfileCookie, 'station_id'+_ARG_SEPR+station_id+_OBJ_SEPR ); }
      //:::::::::::::::::::::::::::
      //if( /GO_LOCATION_VIEW/i.test( this.params ) ) { 
      if( /GO_VIEW/i.test( this.params ) ) {
        //:::::::::::::::::::::::::::
        var reg = new RegExp( "GO_VIEW=([a-zA-Z_0-9&=]+)", "i" );
        var windowLocation = reg.exec( this.params );
        window.location = _ROUTE_INIT + ( windowLocation[1] ? windowLocation[1] : 'location' ) + '&station_id='+station_id;
      } //:: 
    } //:: 
        
  } //:: this.onSelectStation = function( ) {  
  

  
  ////////////////////////////////////////////////////////////////////////////////
  this.stockSelect = function( stockParams ) {
    //:::::::::::::::::::::::::::
    var _THIS = this; //:: Local Instance Holder ::
    //:::::::::::::::::::::::::::
    var stockParmsArray = stockParams.split( ':' );
    //:::::::::::::::::::::::::::  
    //var postData = 'ajax=1&stockstationselect=' + stockParams + ( /MULTI_STATION/i.test( this.params ) == true ? '&multiStation=1' : '' );          
    var postData = 'ajax=1&stockstationselect=' + stockParams + '&params=' + this.params;          
    //:::::::::::::::::::::::::::
    $.ajax({
     url: _THIS.postURL,
     data: postData,
     success: function( responseData ){ _THIS.stockSelectResponse( stockParmsArray[0], responseData ); },
     error : function ( responseData ) { _THIS.stockSelectResponse( stockParmsArray[0], "AJAX ERROR: Could Not get Data" ); },
     beforeSend : function( ) { $( '#'+stockParmsArray[0]+'SelectWrapper' ).html( '<img src="images/throbbers/whitestripes_horizontal1.gif" border="0" alt="Loading Options" />' ); },
     //complete : function( ) { $( '#'+_THIS.name+'ListStockThrobber' ).css( { 'visibility' : 'hidden' } ); },
     type: "POST"
    });
    
  } //:: this.stockRegions = function( ...
  
  ////////////////////////////////////////////////////////////////////////////////
  this.stockSelectResponse = function( selectName, responseData ) {
    //:::::::::::::::::::::::::::
    var _THIS = this; //:: Local Instance Holder ::
    //:::::::::::::::::::::::::::
    var responseArray = responseData.split( _SPLITTER ); // alert( responseArray[1] );
    if( responseArray[0] == 'SUCCESS' ) {
      //:::::::::::::::::::::::::::
      $( '#'+selectName+'SelectWrapper' ).html( responseArray[1] );    
      //:::::::::::::::::::::::::::
      if( selectName == 'region' ) { //:: Reset the Station Select on Region Change ::
        if( /MULTI_STATION/i.test( this.params ) == false )      
          { $( '#stationSelectWrapper' ).html( '<select name="location_station" id= "location_station"><option value="">Station</option><option value="">Please select a Region</option></select>' ); } else
          { $( '#stationSelectWrapper' ).html( '<div class="noContentPadder">Please select a Region</div>' ); }
      } //:: 
    } else {
      if(  responseArray[0] != 'NO_ACTION' ) alert( 'Selection Failure:\n\nA system error has occurred and your selection could not proceed, this might be because of a connection problem.\n\nPlease try again later, or if this problem persists, contact support' );
      $( '#regionSelectWrapper' ).html( '<select name="location_region" id= "location_region"><option value="">Region</option><option value="">Please select a State</option></select>' );
      if( /MULTI_STATION/i.test( this.params ) == false )      
        { $( '#stationSelectWrapper' ).html( '<select name="location_station" id= "location_station"><option value="">Station</option><option value="">Please select a Region</option></select>' ); } else
        { $( '#stationSelectWrapper' ).html( '<div class="noContentPadder">Please select a Region</div>' ); }
      //$( '#stationSelectWrapper' ).html( '<select name="location_station" id= "location_station"><option value="">Station</option><option value="">Please select a Region</option></select>' );
    } //:: 
    
  } //:: 

} //:: function StationSelectControls( ) { :: CLASS

//////////////////////////////////////////////////////////////////////////////////////////////////////////
//stationSelecter = new StationSelectControls( );
//:::::::::::::::::::::::::::::::::::::::::::::::::::::
//$(document).ready(function(){ });


