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);
});
if(dojo.isIE){
dojo.query(".dropDown").forEach(function(_3){
dojo.style(_3,{"backgroundImage":"","filter":""});
});
}
},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(_4){
dojo.connect(_4,"onkeypress",null,function(_5){
if(_5.keyCode==13){
c.handleStoreLookupFormSubmit(_5);
}
});
});
}
dojo.connect(dojo.byId("storeLookupForm"),"onsubmit",this,"handleStoreLookupFormSubmit");
},handleBrandChange:function(_6){
this._promptExtranetSites(_6.currentTarget);
},_promptExtranetSites:function(_7){
var _8=_7.value;
var _9=0;
var _a,_b;
if(_8=="wh"){
_a=this.WS_HOME_PROMPT;
_b=this.WS_HOME_URL;
}
if(_8=="we"){
_a=this.WE_PROMPT;
_b=this.WESTELM_URL;
}
if((_8=="we")||(_8=="wh")){
_9=confirm(_a);
if(_9==1){
window.open(_b);
}
_7.selectedIndex=0;
}
},handleStoreLookupFormSubmit:function(_c){
var _d=dojo.byId("brand").value;
if((_d=="we")||(_d=="wh")){
_c.preventDefault();
this._promptExtranetSites(dojo.byId("brand"));
return false;
}
var _e=this._isFormValid();
if(!_e){
_c.preventDefault();
}else{
dojo.byId("storeLookupForm").submit();
return false;
}
},_isFormValid:function(){
var _f=this._validateAddress();
if(_f){
var _10=this._isRadioSelected();
if(!_10){
this._showErrorMessage(this.SELECT_RADIO_MSG);
return false;
}
return true;
}else{
return false;
}
},_isRadioSelected:function(){
var _11=dojo.query("input[type=\"radio\"]");
var _12=false;
for(var i=0;i<_11.length;i++){
if(_11[i].checked==true){
_12=true;
break;
}
}
return _12;
},_showErrorMessage:function(_14){
dojo.byId("errorDisplay").style["display"]="block";
dojo.byId("errorDisplay").style["opacity"]="0";
dojo.byId("errorDisplay").style["visibility"]="visible";
dojo.byId("errorMessage").innerHTML=_14;
var _15=dojo.fadeIn({node:dojo.byId("errorDisplay"),duration:500}).play();
dojo.connect(_15,"onEnd",null,function(){
dojo.byId("errorDisplay").style["opacity"]="1.0";
});
},_hideErrorMessage:function(){
var _16=dojo.fadeOut({node:dojo.byId("errorDisplay"),duration:500}).play();
dojo.connect(_16,"onEnd",null,function(){
dojo.byId("errorMessage").innerHTML="";
dojo.byId("errorDisplay").style["display"]="none";
});
},_validateAddress:function(){
var _17,_18,_19,_1a,_1b;
var _1c=dojo.byId("brand").value;
if(_1c==""){
this._showErrorMessage(this.SELECT_BRAND_MSG);
return false;
}
_17=new MQAddress();
_17.setStreet(dojo.byId("address").value);
_17.setCity(dojo.byId("city").value);
_19=dojo.byId("state").value;
_17.setState(_19);
_17.setPostalCode(dojo.byId("zipCode").value);
_17.setCountry(dojo.byId("country").value);
_1b=dojo.byId("zipCode").value;
_1a=dojo.byId("country").value;
_18=dojo.byId("city").value;
if(_18==""&&_19==""&&_1b==""){
this._showErrorMessage(this.INVALID_CITY_STATE_ZIP_MSG);
return false;
}
if(((_18!=""&&_19=="")||(_18==""&&_19!=""))&&_1b==""){
this._showErrorMessage(this.INVALID_CITY_STATE_ZIP_MSG);
return false;
}
if(_1b!=""&&_19!=""&&_1a!="CA"&&!ValidZip(_1b)){
this._showErrorMessage(this.STATE_ZIP_ERROR_MSG);
return false;
}
var _1d=new MQLocationCollection();
var _1e=new MQExec(geocodeServer,serverPath,serverPort,proxyServer,proxyPath,proxyPort);
_1e.geocode(_17,_1d,null);
if(_1d.getSize()==0){
return true;
}else{
if(_1d.getSize()==1){
var _1f=_1d.getAt(0);
if(validateResultCode(_1f.getResultCode())){
return true;
}else{
this._showErrorMessage(this.INVALID_ADDRESS_MSG);
return false;
}
}else{
this._showErrorMessage(this.INVALID_ADDRESS_MSG);
return false;
}
}
}});
