Type.registerNamespace("Geo");
Geo.OperationStatus = function() {}
Geo.OperationStatus.prototype ={
Validating: 1,
Validated: 2}
Geo.OperationStatus.registerEnum("Geo.OperationStatus", false);
Geo.Country = function(countryNodeID, stateLabelID, cityZipLabelID, zipLabelID, zipBlockID, zipSupported,
zipValidatorID, zipRequiredMessageTemplate){
this._countryNode = $get(countryNodeID);
this._stateLabel = $get(stateLabelID);
this._cityZipLabel = $get(cityZipLabelID);
this._zipLabel = $get(zipLabelID);
this._zipBlock = $get(zipBlockID);
this._zipSupported = zipSupported;
this._zipValidator = $get(zipValidatorID);
this._zipRequiredMessageTemplate = zipRequiredMessageTemplate;
this._abortExecutor = null;
this._currentRequest = null;
this._countryChangedHandler = Function.createDelegate(this, this._requestInfo);
$addHandler(this._countryNode, 'change', this._countryChangedHandler);
this._setupZipBlock();}
Geo.Country.prototype ={
_requestInfo : function(eventElement){
if (this._currentRequest) this._currentRequest.get_executor().abort();
this._currentRequest = Sys.Net.WebServiceProxy.invoke(BSLayer.Service.ScriptService.get_path(),
'GetCountryInfo', false,{countryValue:this._countryNode.value},
Function.createDelegate(this, this._countryChanged),
Function.createDelegate(this, this._requestFiled));},
_countryChanged : function(result, eventArgs){
this._abortExecutor = null;
if (this._stateLabel != null)
this._stateLabel.innerHTML = result.StateText;
if (this._cityZipLabel != null)
this._cityZipLabel.innerHTML = result.CityZipText;
if (this._zipLabel != null)
this._zipLabel.innerHTML = result.ZipText;
if (this._zipValidator)
this._zipValidator.RequiredMessage = String.format(this._zipRequiredMessageTemplate, result.ZipText);
this._zipSupported = result.ZipSupported;
this._setupZipBlock();},
_setupZipBlock : function(){
if (this._zipSupported && this._zipSupported != 'false'){
if (this._zipBlock != null)
this._zipBlock.style.display = '';
if (this._zipValidator != null){
ValidatorEnable(this._zipValidator, true);}}
else{
if (this._zipBlock != null){
this._zipBlock.style.display = 'none';}
if (this._zipValidator != null){
ValidatorEnable(this._zipValidator, false);}}},
_requestFiled : function() {}}
Geo.Country.registerClass('Geo.Country');
Geo.State = function(stateNodeID, countryNodeID, loadingString, selectionRequired, validatorControlID){
this._stateNode = $get(stateNodeID);
this._countryNode = $get(countryNodeID);
this._loadingString = loadingString;
this._selectionRequired = selectionRequired;
this._status = Geo.OperationStatus.Validated;
this._countryChangedHandler = Function.createDelegate(this, this._requestStates);
this._validatorControl = $get(validatorControlID);
$addHandler(this._countryNode, 'change', this._countryChangedHandler);
this._updateValidator();}
Geo.State.prototype ={
_removeStates: function (){
while (this._stateNode.firstChild){
this._stateNode.removeChild(this._stateNode.firstChild);};},
_addState: function (name, value, parent){
var option = document.createElement("OPTION");
option.innerHTML = name;
option.value = value;
parent.appendChild(option);},
_requestStates: function(eventElement){
this._removeStates();
this._stateNode.disabled = true;
this._addState(this._loadingString, "", this._stateNode);
this._status = Geo.OperationStatus.Validating;
if (this._currentRequest) this._currentRequest.get_executor().abort();
this._currentRequest = Sys.Net.WebServiceProxy.invoke(BSLayer.Service.ScriptService.get_path(),
'GetStates', false,{countryValue:this._countryNode.value, selectionRequired:this._selectionRequired},
Function.createDelegate(this, this._statesLoadedCallback),
Function.createDelegate(this, this._errorOnServer));},
_statesLoadedCallback: function(result, eventArgs){
this._removeStates();
var group = '';
var parentOptGroup = this._stateNode;
for (var i=0; i<result.length; i++){
if (group != result[i].Group){
group = result[i].Group;
var optgroup = document.createElement("optgroup");
optgroup.setAttribute("label", group);
parentOptGroup = optgroup;
this._stateNode.appendChild(optgroup);}
this._addState(result[i].Name, result[i].Value, parentOptGroup);};
if (result.length <= 1)
this._stateNode.disabled = true;
else this._stateNode.disabled = false;
this._updateValidator();
this._mode = Geo.OperationStatus.Validated;},
getStatus: function(){
return this._status;},
_errorOnServer: function(error){
this._status = Geo.OperationStatus.Validated;},
RefreshValidators: function(){
for (var i=0; i<Page_Validators.length; i++){
ValidatorValidate(Page_Validators[i]);}},
_updateValidator: function(){
if (this._validatorControl != null){
if (this._stateNode.disabled){
ValidatorEnable(this._validatorControl, false);
this._validatorControl.style.display = 'none';}
else{
ValidatorEnable(this._validatorControl, true);
this._validatorControl.style.display = '';}}}}
Geo.State.registerClass('Geo.State');
Geo.ValidationMode = function(){}
Geo.ValidationMode.prototype ={
City: 1,
Zip: 2,
CityZip: 3}
Geo.ValidationMode.registerEnum("Geo.ValidationMode", false);
Geo.City = function(cityNodeID, countryNodeID, stateNodeID, helpNodeID,
cityValidatorID, validationMode){
this._cityNode = $get(cityNodeID);
this._countryNode = $get(countryNodeID);
this._stateNode = $get(stateNodeID);
this._helpNode = $get(helpNodeID);
this._validationMode = validationMode;
this._cityValidator = $get(cityValidatorID);
this._isvalid = true;
this._status = Geo.OperationStatus.Validated;
this._contextChangedHandler = Function.createDelegate(this, this._contextChanged);
this._cityTextChangedHandler = Function.createDelegate(this, this._validateCity);
$addHandler(this._countryNode, 'change', this._contextChangedHandler);
$addHandler(this._stateNode, 'change', this._contextChangedHandler);
$addHandler(this._cityNode, 'blur', this._cityTextChangedHandler);}
Geo.City.prototype ={
_contextChanged: function (eventElement){
this._validateCity();},
_validateCity: function (eventElement){
this._disableValidators();
if (this._cityNode.value == ""){
this._isvalid = true;
return;}
if (this._countryNode.value == ""){
this._isvalid = true;
return;}
this._status = Geo.OperationStatus.Validating;
BSLayer.Service.ScriptService.ValidateCity(this._cityNode.value,
this._countryNode.value,
this._stateNode.value,
this._validationMode,
Function.createDelegate(this, this._cityValidatedCallback),
Function.createDelegate(this, this._errorOnServer));},
_cityValidatedCallback: function(result, eventArgs){
if (result.Value == ""){
this._isvalid = true;
this._cityNode.value = result.Name;}
else{
this._isvalid = false;
ValidatorEnable(this._cityValidator, true);}
this._status = Geo.OperationStatus.Validated;
this.RefreshValidators();},
_disableValidators: function(){
ValidatorEnable(this._cityValidator, false);},
ValidatorCallback: function(source, args){
args.IsValid = this._isvalid;},
LoadingValidatorCallback: function(source, args){
if (this._status == Geo.OperationStatus.Validating)
args.IsValid = false;
else args.IsValid = true;},
_errorOnServer: function(error){
this._isvalid = true;
this._status = Geo.OperationStatus.Validated;},
RefreshValidators: function(){
for (var i=0; i<Page_Validators.length; i++){
ValidatorValidate(Page_Validators[i]);}}}
Geo.City.registerClass('Geo.City');
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
