
Type.registerNamespace('Monster.Client.Behavior.BuyWidgets');Monster.Client.Behavior.BuyWidgets.CareerAdNetworkAdapter=function(element)
{Monster.Client.Behavior.BuyWidgets.CareerAdNetworkAdapter.initializeBase(this,[element]);this._quantityPriceBreaks=[];this._maxUnits=249;this.createProperty("btnBuy");this.createProperty("txtQuantity");this.createProperty("ddlDuration");this.createProperty("msgErrorQuantity");this.createProperty("ecomProductTypeID");}
Monster.Client.Behavior.BuyWidgets.CareerAdNetworkAdapter.prototype={initialize:function(){Monster.Client.Behavior.BuyWidgets.CareerAdNetworkAdapter.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._dataStore.set_property("Duration",this.ddlDuration[0].value)
$addHandlers(this.ddlDuration,{change:this.handleDurationUpdate},this);$addHandlers(this.txtQuantity,{keyup:this.handleQuantityUpdate},this);$addHandlers(this.btnBuy,{click:this.handleBuyButton},this);this.txtQuantity.value="";this.ddlDuration.selectedIndex=0;},initOnDemand:function(){},initHandlers:function(element,event,context){},dispose:function(){},onSuccess:function(result,context,methodName){switch(methodName){case"GetRateCard":$(".rate-card tbody").html(result[0]);context.updateTotalPrice();break;case"GetPricingInfo":$(".total-amount").html(result[3]);context._dataStore.set_property("PostingLocationGroupID",result[4]);context._dataStore.set_property("TierID",result[5]);context._dataStore.set_property("EcomProductTypeID",result[13]);publishGadgetView(result[11]);break;default:break;}},onFailure:function(result,context,methodName){Sys.Debug.trace("error in CareerAdNetworkAdapter.js");},onDataStoreEvent:function(sender,args){switch(args.get_propertyName()){default:break;}},handleDurationUpdate:function(evt){var d=this.ddlDuration[this.ddlDuration.selectedIndex].value;this._dataStore.set_property("Duration",d);this.updateRateCard();},handleQuantityUpdate:function(evt){var q=this.txtQuantity.value;this._dataStore.set_property("Quantity",q);this.updateTotalPrice();},handleBuyButton:function(evt){evt.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(){this._quantityPriceBreaks=[];this.callServer("GetRateCard",[this.getServiceQueryParams(),this._maxUnits]);$(".error-field").css("display","none");},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("06:"+this.ecomProductTypeID);params.push("10:"+this._dataStore.get_property("Duration"));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"));params.push("ecomProductTypeID="+this.ecomProductTypeID);params.push("editMode="+false);params.push("CANDuration="+this._dataStore.get_property("Duration"));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.CareerAdNetworkAdapter.registerClass('Monster.Client.Behavior.BuyWidgets.CareerAdNetworkAdapter',Monster.Client.Behavior.DataAdapterBase);if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();
;
