
Type.registerNamespace('Monster.Client.Behavior.BuyWidgets');Monster.Client.Behavior.BuyWidgets.DiversityAdapter=function(element)
{Monster.Client.Behavior.BuyWidgets.DiversityAdapter.initializeBase(this,[element]);this._quantityPriceBreaks=[];this._isRateCardVisible=false;this._maxUnits=249;this.createProperty("btnBuy");this.createProperty("txtQuantity");this.createProperty("ddlDuration");this.createProperty("defaultDuration");this.createProperty("msgErrorQuantity");this.createProperty("maxUnitsDuration30");this.createProperty("maxUnitsDuration60");this.createProperty("diversityBoardID");this.createProperty("maxCategoryGroup");this.createProperty("maxPostingLocationGroup");}
Monster.Client.Behavior.BuyWidgets.DiversityAdapter.prototype={initialize:function(){Monster.Client.Behavior.BuyWidgets.DiversityAdapter.callBaseMethod(this,'initialize');if(!MonsPageManager.enableInitOnDemand)
{this.initOnDemand();}
else
{MonsPageManager.registerInitState(this._id,false,null);}
this._webService=Services.Products.Pricing;this.registerDataProperty("Quantity");this.registerDataProperty("Duration");this.registerDataProperty("EcomProductTypeID");this._dataStore.set_property("Quantity","")
this._dataStore.set_property("Duration",this.defaultDuration);$addHandlers(this.ddlDuration,{change:this.handleDurationDropdown},this);$addHandlers(this.txtQuantity,{keyup:this.handleQuantityUpdate},this);$addHandlers(this.btnBuy,{click:this.handleBuyButton},this);this.txtQuantity.value="";$("#"+this.ddlDuration.id).val(this.defaultDuration);},initOnDemand:function(){},initHandlers:function(element,event,context){},dispose:function(){},onSuccess:function(result,context,methodName){switch(methodName){case"GetRateCard":if(!context._isRateCardVisible){$(".rate-card").removeClass("initial-view");$(".totals").css("display","block");$(".buy-btn").css("display","block");context._isRateCardVisible=true;}
$(".rate-card tbody").html(result[0]);context.updateTotalPrice();break;case"GetPricingInfo":$(".total-amount").html(result[3]);context._dataStore.set_property("EcomProductTypeID",result[13]);publishGadgetView(result[11]);break;default:break;}},onFailure:function(result,context,methodName){Sys.Debug.trace("error in DiversityAdapter.js");},onDataStoreEvent:function(sender,args){switch(args.get_propertyName()){default:break;}},handleDurationDropdown:function(event){var d=this.ddlDuration[this.ddlDuration.selectedIndex].value;this._dataStore.set_property("Duration",d);if(d=="30"){this._maxUnits=this.maxUnitsDuration30;}else if(d=="60"){this._maxUnits=this.maxUnitsDuration60;}
this.updateRateCard();},handleQuantityUpdate:function(event){var q=this.txtQuantity.value;this._dataStore.set_property("Quantity",q);this.updateRateCard();},handleBuyButton:function(event){event.preventDefault();this.addToCart();},validateQuantity:function(){var errArr=[];var q=parseInt(this._dataStore.get_property("Quantity"));if(isNaN(q)){errArr.push(this.msgErrorQuantity);}else if((q>parseInt(this._maxUnits))||(q<1)){errArr.push(this.msgErrorQuantity);}
return errArr;},validateForm:function(){var errArr=[];errArr=errArr.concat(this.validateQuantity());return errArr;},updateRateCard:function(){var errArr=this.validateForm();if(errArr.length===0){this._quantityPriceBreaks=[];this.callServer("GetRateCard",[this.getServiceQueryParams(),this._maxUnits]);$(".error-field").css("display","none");}else{$(".total-amount").html("");$(".rate-card tr").removeClass("highlight-row");}},updateTotalPrice:function(){var errArr=this.validateForm();if(errArr.length===0){var q=this._dataStore.get_property("Quantity");this.highlightRateCardRow(q);this.callServer("GetPricingInfo",[q,this.getServiceQueryParams()]);$(".error-field").css("display","none");}else{$(".total-amount").html("");$(".rate-card tr").removeClass("highlight-row");}},highlightRateCardRow:function(quantity){if(this._quantityPriceBreaks.length===0)this.initQuantityPriceBreaks();var qpb=this._quantityPriceBreaks;var actualQ=parseInt(quantity);var trIdx,tempMin,tempMax;for(var i=0;i<qpb.length;i++){tempMin=parseInt(qpb[i][0]);tempMax=parseInt(qpb[i][1]);if(isNaN(tempMax)){if(actualQ===tempMin){trIdx=i;break;}}else{if(actualQ>=tempMin&&actualQ<=tempMax){trIdx=i;break;}}}
$(".rate-card tr").removeClass("highlight-row");$(".rate-card tr:nth-child("+(trIdx+1)+")").addClass("highlight-row");},initQuantityPriceBreaks:function(){var tempQPB=[];var trElems=$(".rate-card tr");var tempTdQ,tempMinQ,tempMaxQ,tempDashIdx;for(var i=0;i<trElems.length;i++){if(i===0)continue;tempTdQ=$("td",trElems[i])[0].innerHTML;tempDashIdx=tempTdQ.indexOf("-");if(tempDashIdx!==-1){tempMinQ=tempTdQ.substring(0,tempDashIdx);tempMaxQ=tempTdQ.substring(tempDashIdx+1);}else{tempMinQ=tempTdQ.substring(0);tempMaxQ=null;}
tempQPB[tempQPB.length]=[tempMinQ,tempMaxQ];}
this._quantityPriceBreaks=tempQPB;},getServiceQueryParams:function(){var params=[];params.push("01:"+"");params.push("02:"+"0");params.push("03:"+false);params.push("04:"+false);params.push("05:"+this._dataStore.get_property("Duration"));params.push("07:"+false);params.push("11:"+false);params.push("12:"+this.diversityBoardID);params.push("13:"+false);params.push("16:"+0);return params;},addToCart:function(){var errArr=this.validateForm();if(errArr.length>0){$(".error-field").html(errArr.join("<br />"));$(".error-field").css("display","block");return false;}
publishGadgetClick();var urlPath="/products/JobProductsSecure.aspx?";var params=[];params.push("bundleid="+"0");params.push("quantity="+this._dataStore.get_property("Quantity"));var promoID=this.getQueryStringValue("promotionID")
if(promoID!==""){params.push("pid="+promoID);}
params.push("ecomProductTypeID="+this._dataStore.get_property("EcomProductTypeID"));params.push("MaxCategoryGroup="+this.maxCategoryGroup);params.push("MaxPostingLocationGroup="+this.maxPostingLocationGroup);params.push("editMode="+false);params.push("postingDuration="+this._dataStore.get_property("Duration"));params.push("hasBolding="+false);params.push("hasAutoRefresh="+false);params.push("refreshInterval="+false);params.push("jobBoardID="+this.diversityBoardID);var redirLoc=urlPath+params.join("&");var redirLink=document.createElement("A");if(typeof(redirLink.click)==="undefined"){window.location=redirLoc;}else{redirLink.href=redirLoc;document.body.appendChild(redirLink);redirLink.click();}},getQueryStringValue:function(key,default_){if(default_==null)default_="";key=key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");var regex=new RegExp("[\\?&]"+key+"=([^&#]*)");var qs=regex.exec(window.location.href);if(qs==null){return default_;}else{return qs[1];}}}
Monster.Client.Behavior.BuyWidgets.DiversityAdapter.registerClass('Monster.Client.Behavior.BuyWidgets.DiversityAdapter',Monster.Client.Behavior.DataAdapterBase);if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();
;
