dojo.declare("MQLandingController",null,{constructor:function(){
this._wireUpFormForEnterTrap();
dojo.query("#back-to-previous").forEach(function(_1){
dojo.connect(_1,"onclick",function(){
history.back();
});
});
dojo.connect(dojo.byId("brand"),"onchange",function(_2){
c.handleBrandChange(_2);
});
},INVALID_ADDRESS_MSG:"The address you specified seems to be incorrect, please enter valid address.",STATE_ZIP_ERROR_MSG:"The state and zip code do not match. Please make sure they are correct.",INVALID_CITY_STATE_ZIP_MSG:"Please enter a City and State or Zip Code to continue.",SELECT_BRAND_MSG:"Please select the store you are interested in to continue.",SELECT_RADIO_MSG:"Please select the distance you're willing to travel.",WS_HOME_URL:"http://www.wshome.com/cust/storelist/content.cfm",WESTELM_URL:"http://www.westelm.com/online/store/StoreLocationsView?categoryId=&storeId=17001&langId=-1&catalogId=17002&viewSetCode=E&bnrid=3910004",WE_PROMPT:"You will be redirected to the West Elm store listings.",WS_HOME_PROMPT:"You will be redirected to the Williams-Sonoma Home store listings.",_wireUpFormForEnterTrap:function(){
if(dojo.isIE>0){
dojo.query("#storeLookupForm input").forEach(function(_3){
dojo.connect(_3,"onkeypress",null,function(_4){
if(_4.keyCode==13){
c.handleStoreLookupFormSubmit(_4);
}
});
});
}
dojo.connect(dojo.byId("storeLookupForm"),"onsubmit",this,"handleStoreLookupFormSubmit");
},handleBrandChange:function(_5){
this._promptExtranetSites(_5.currentTarget);
},_promptExtranetSites:function(_6){
var _7=_6.value;
var _8=0;
var _9,_a;
if(_7=="wh"){
_9=this.WS_HOME_PROMPT;
_a=this.WS_HOME_URL;
}
if(_7=="we"){
_9=this.WE_PROMPT;
_a=this.WESTELM_URL;
}
if((_7=="we")||(_7=="wh")){
_8=confirm(_9);
if(_8==1){
window.open(_a);
}
_6.selectedIndex=0;
}
},handleStoreLookupFormSubmit:function(_b){
var _c=dojo.byId("brand").value;
if((_c=="we")||(_c=="wh")){
_b.preventDefault();
this._promptExtranetSites(dojo.byId("brand"));
return false;
}
var _d=this._isFormValid();
if(!_d){
_b.preventDefault();
}else{
dojo.byId("storeLookupForm").submit();
return false;
}
},_isFormValid:function(){
var _e=this._validateAddress();
if(_e){
var _f=this._isRadioSelected();
if(!_f){
this._showErrorMessage(this.SELECT_RADIO_MSG);
return false;
}
return true;
}else{
return false;
}
},_isRadioSelected:function(){
var _10=dojo.query("input[type=\"radio\"]");
var _11=false;
for(var i=0;i<_10.length;i++){
if(_10[i].checked==true){
_11=true;
break;
}
}
return _11;
},_showErrorMessage:function(_13){
dojo.byId("errorDisplay").style["display"]="block";
dojo.byId("errorDisplay").style["opacity"]="0";
dojo.byId("errorDisplay").style["visibility"]="visible";
dojo.byId("errorMessage").innerHTML=_13;
var _14=dojo.fadeIn({node:dojo.byId("errorDisplay"),duration:500}).play();
dojo.connect(_14,"onEnd",null,function(){
dojo.byId("errorDisplay").style["opacity"]="1.0";
});
},_hideErrorMessage:function(){
var _15=dojo.fadeOut({node:dojo.byId("errorDisplay"),duration:500}).play();
dojo.connect(_15,"onEnd",null,function(){
dojo.byId("errorMessage").innerHTML="";
dojo.byId("errorDisplay").style["display"]="none";
});
},_validateAddress:function(){
var _16,_17,_18,_19,_1a;
var _1b=dojo.byId("brand").value;
if(_1b==""){
this._showErrorMessage(this.SELECT_BRAND_MSG);
return false;
}
_16=new MQAddress();
_16.setStreet(dojo.byId("address").value);
_16.setCity(dojo.byId("city").value);
_18=dojo.byId("state").value;
_16.setState(_18);
_16.setPostalCode(dojo.byId("zipCode").value);
_16.setCountry(dojo.byId("country").value);
_1a=dojo.byId("zipCode").value;
_19=dojo.byId("country").value;
_17=dojo.byId("city").value;
if(_17==""&&_18==""&&_1a==""){
this._showErrorMessage(this.INVALID_CITY_STATE_ZIP_MSG);
return false;
}
if(((_17!=""&&_18=="")||(_17==""&&_18!=""))&&_1a==""){
this._showErrorMessage(this.INVALID_CITY_STATE_ZIP_MSG);
return false;
}
if(_1a!=""&&_18!=""&&_19!="CA"&&!ValidZip(_1a)){
this._showErrorMessage(this.STATE_ZIP_ERROR_MSG);
return false;
}
var _1c=new MQLocationCollection();
var _1d=new MQExec(geocodeServer,serverPath,serverPort,proxyServer,proxyPath,proxyPort);
_1d.geocode(_16,_1c,null);
if(_1c.getSize()==0){
return true;
}else{
if(_1c.getSize()==1){
var _1e=_1c.getAt(0);
if(validateResultCode(_1e.getResultCode())){
return true;
}else{
this._showErrorMessage(this.INVALID_ADDRESS_MSG);
return false;
}
}else{
this._showErrorMessage(this.INVALID_ADDRESS_MSG);
return false;
}
}
}});
