var $j=jQuery.noConflict(),CallStatus={Connected:0,Calling:1,BusyCaller:2,BusyTarget:3,Failed:4},CallClient={TimeOut:6e4,CheckStatusInterval:1e3,CallId:null,IntervalId:null,Init:function(){var a=this;$j(".sourcePhoneNumber INPUT").val($j.cookie("_118C2CNumber"));$j(".buttonSubmit").click(function(){a.Call($j(".sourcePhoneNumber INPUT").val(),$j(".companyId INPUT").val());return false});$j(".buttonCancel").click(function(){if(a.CallId!=null)a.HangUp();else parent.$j.colorbox.close();return false})},Call:function(b,c){$j.cookie("_118C2CNumber",b,{domain:"",path:"/",expire:10});this.HideSubmitButton();this.ClearErrors();this.ShowProgress();var a=this;$j.ajax({type:"POST",url:"../../PublicServices/CallService.asmx/Call",data:"{'sourcePhoneNumber': '"+b+"', 'companyId': '"+c+"'}",contentType:"application/json; charset=utf-8",dataType:"json",timeout:this.TimeOut,success:function(b){a.QueueCall(b.d);a.HideProgress();a.ShowCallProgress()},error:function(b){if(b.responseText.toLowerCase().indexOf("sourcenumberisblocked")!=-1)a.NumberBlocked();else if(b.responseText.toLowerCase().indexOf("sourcenumberlimitexceeded")!=-1)a.NumberLimitExceeded();else a.FailCall();a.HideProgress()}})},HangUp:function(){this.HideCallProgress();this.ShowProgress();var a=this;$j.ajax({type:"POST",url:"../../PublicServices/CallService.asmx/HangUp",data:"{'id': '"+this.CallId+"'}",contentType:"application/json; charset=utf-8",dataType:"json",timeout:this.TimeOut,success:function(b){if(b.d){a.DequeueCall();a.SucceedHangUp();a.HideProgress()}else{a.FailHangUp();a.HideProgress();a.ShowCallProgress()}},error:function(){a.FailHangUp();a.HideProgress();a.ShowCallProgress()}})},CheckStatus:function(){var a=this;$j.ajax({type:"POST",url:"../../PublicServices/CallService.asmx/GetStatus",data:"{'id': '"+this.CallId+"'}",contentType:"application/json; charset=utf-8",dataType:"json",timeout:this.TimeOut,success:function(b){if(a.IntervalId!=null&&b.d!=CallStatus.Calling){a.DequeueCall();if(b.d==CallStatus.Connected)a.SucceedCall();else if(b.d==CallStatus.BusyCaller)a.BusyCaller();else if(b.d==CallStatus.BusyTarget)a.BusyTarget();else b.d==CallStatus.Failed&&a.FailCall();a.HideCallProgress()}else if(b.d==CallStatus.Calling)a.IntervalId=setTimeout("CallClient.CheckStatus()",this.CheckStatusInterval)},error:function(){a.FailCall();a.HideCallProgress()}})},QueueCall:function(a){this.CallId=a;this.IntervalId=setTimeout("CallClient.CheckStatus()",this.CheckStatusInterval)},DequeueCall:function(){this.CallId=null;clearTimeout(this.IntervalId);this.IntervalId=null},ShowSubmitButton:function(){$j(".buttonSubmit").show()},HideSubmitButton:function(){$j(".buttonSubmit").hide()},ClearErrors:function(){$j("div#errorFailedCall").hide();$j("div#errorFailedHangUp").hide();$j("div#errorBusyCaller").hide();$j("div#errorBusyTarget").hide();$j("div#errorNumberBlocked").hide();$j("div#errorNumberLimitExceeded").hide()},FailCall:function(){this.ShowSubmitButton();$j("div#errorFailedCall").show()},BusyCaller:function(){this.ShowSubmitButton();$j("div#errorBusyCaller").show()},BusyTarget:function(){this.ShowSubmitButton();$j("div#errorBusyTarget").show()},NumberBlocked:function(){this.ShowSubmitButton();$j("div#errorNumberBlocked").show()},NumberLimitExceeded:function(){this.ShowSubmitButton();$j("div#errorNumberLimitExceeded").show()},FailHangUp:function(){this.ShowSubmitButton();$j("div#errorFailedHangUp").show();setTimeout(function(){$j("div#errorFailedHangUp").fadeOut(200)},2800)},SucceedCall:function(){$j("div#successCall").show()},SucceedHangUp:function(){this.ShowSubmitButton();$j("div#successHangUp").show();setTimeout(function(){$j("div#successHangUp").fadeOut(200)},2800)},ShowProgress:function(){$j("div#waiting").show()},ShowCallProgress:function(){$j("div#calling").show()},HideProgress:function(){$j("div#waiting").hide()},HideCallProgress:function(){$j("div#calling").hide()}};$j(document).ready(function(){CallClient.Init()})
