!(function($, win, top) {
	var PHONEBLOCK = function(options) {
		if(!options){throw new Error('读取一键通话组件配置失败!'); return ;}
		if(!options.serverConnection){throw new Error('serverConnection 不能为空!'); return ;}
		this.uuid = null;
		this.phoneNumber = null;
		this.serverConnection=null;
		this.startcall=0;
		this.stopcall=1;
		$.extend(this, options);
	}
	//拨打电话
	PHONEBLOCK.prototype.startPhoneCall=function(){
		try{
			if(!this.phoneNumber){
				$.showMsg("呼叫号码为空，请重新选择！");
				return false;
			}
			//var uuid = $.uniqueId();
			//var reg = new RegExp("-","g");//g,表示全部替换。
			//uuid = uuid.replace(reg,'');
			this.serverConnection.send(JSON.stringify({ 'makecall': { 'action': this.startcall, 'phonenumber': this.phoneNumber},  'uuid': this.uuid }));
			return this.uuid;
			}catch(e){
				console.error(e);
				$.showMsg("一键通话拨号失败，请重新呼叫！");
				return false;	
			}
		//this.serverConnection.send(JSON.stringify({'startmonitor': {'fdid':fdid||this.getFdId(), 'channelid':channelid||this.getChannelId(), 'subid':( subid || 0)}, 'uuid': channelname||this.uuid}));
	}
	//挂掉电话
	PHONEBLOCK.prototype.stopPhoneCall=function(){
		try{
			if(!this.phoneNumber){
				$.showMsg("呼叫号码为空，请重新选择！");
				return false;
			}
			this.serverConnection.send(JSON.stringify({ 'makecall': { 'action': this.stopcall, 'phonenumber': this.phoneNumber } }));
			return true;
		}catch(e){
			console.error(e);
			$.showMsg("结束通话失败，请重新操作！");
			return false;
		}
		//this.serverConnection.send(JSON.stringify({'stopmonitor': {'monid':this.getMonId() }, 'uuid': this.getUuId()}));
		//return this;
	}
	
	PHONEBLOCK.prototype.getPhoneNumber=function(undefined){
		return this.phoneNumber;
	}

	PHONEBLOCK.prototype.setPhoneNumber=function(phoneNumber){
		this.phoneNumber = phoneNumber;
		return this;
	}
	
	$.phoneBlock = function(_) {
		return !$.isEmptyObject(_) ? new PHONEBLOCK(_) : null;
	};
})(jQuery, window, top);