function setupsWithOutFlowPredict(){
	var result = "";
	if($("#baiduAudiences").val()!=undefined&&$("#baiduAudiences").val()!=""){
		result += ",百度人群设定";
	}
	if($("#audienceWeight").val()!=undefined&&$("#audienceWeight").val()!=""){
		result += ",人群关注度";
	}
	if($("#clickCookieType").val()!=undefined&&$("#clickCookieType").val()!="Na"){
		result += ",点击找回";
	}
	if($("#pyidCategories").val()!=undefined&&$("#pyidCategories").val()!=""){
		result += ",人群分类定向";
	}
	if($("#pyids").val()!=undefined&&$("#pyids").val()!=""){
		result += ",Cookie定向";
	}
	if($("#highQualityMedia").val()!=undefined&&$("#highQualityMedia").val()!="false"){
		result += ",优质媒体定向";
	}
	if(($("#adUnit\\.blackIdsTextArea").val()!=undefined&&$("#adUnit\\.blackIdsTextArea").val()!="")||
		($("#adUnit\\.whiteIdsTextArea").val()!=undefined&&$("#adUnit\\.whiteIdsTextArea").val()!="")){
		result += ",广告位黑白名单";
	}
	if($("#antiCheating").val()!=undefined&&$("#antiCheating").val()!="false"){
		result += ",防作弊";
	}
	if($("#dayPacing").val()!=undefined&&$("#dayPacing").val()!="NotEnabled"){
		result += ",均匀投放";
	}
	if($("#preferDeal").val()!=undefined&&$("#preferDeal").val()!=""){
		result += ",PreferDeal";
	}
	if($("#algorithmCode").val()!=undefined&&$("#algorithmCode").val()!=""){
		result += ",竞价算法";
	}
	if($("#scriptCode").val()!=undefined&&$("#scriptCode").val()!=""){
		result += ",内部设置";
	}
	if(result!=""){
		result=result.substring(1);
	}
	return result;
}
function estimate(result) {
	function Point(x, y) {
		this.x = x;
		this.y = y;
	}

	var tmpl = '<div class="set-title" style="display: none;">' +
		'<strong>根据您的设置：</strong>' +
	'</div>' +
	'<div class="set-content" style="display: none; ">' +
		'<div class="audience-info">' +
			'<span>人群定向</span>' +
		'</div>' +
		'<div class="area-info">' +
			'<span>地域定向</span>' +
		'</div>' +
		'<div class="platform-info">' +
			'<span>平台定向</span>' +
		'</div>' +
		'<div class="adunittype-info">' +
			'<span>广告形式</span>' +
		'</div>' +
		'<div class="appCategories-info">' +
			'<span>APP类型定向</span>' +
		'</div>' +
		'<div class="mobileSets-info">' +
			'<span>移动设备定向</span>' +
		'</div>' +
		'<div class="mobileNetWorks-info">' +
			'<span>移动网络定向</span>' +
		'</div>' +
		'<div class="retarget-info">' +
			'<span>访客找回定向</span>' +
		'</div>' +
		'<div class="blackWhiteUrls-info">' +
			'<span>媒体黑白名单定向</span>' +
		'</div>' +
		'<div class="browsers-info">' +
			'<span>浏览器定向</span>' +
		'</div>' +
		'<div class="osTypes-info">' +
			'<span>操作系统定向</span>' +
		'</div>' +
		'<div class="dayParting-info">' +
			'<span>时段定向</span>' +
		'</div>' +
		'<div class="bid">' +
			'<span>出价</span>' +
		'</div>' +
	'</div>' +
	'<div class="exposure-num" style="display: none; ">' +
		'<strong>预估一天内曝光量为</strong>' +
		'<span class="count">0</span>' +
		'<span class="loading"></span>' +
	'</div>' +
	'<p class="warnsmall" id="warnsmall" style="display: none; "></p>'+
	'<p class="warn" style="display: none; ">曝光过少，建议放宽您的定向条件或提高您的出价。</p>';

	var ele = $('.set-info'),
		range = result.data.range,
		data = result.data.datas;

	if(currentMode) {
		drawPlot();
		drawBtn();
	} else {
		drawText();
	}

	function drawPlot() {
		clear();

		drawBtn();

		ele.css({
			width: 450,
			height: 510,
			'overflow': 'hidden'
		});

		var paper = Raphael(ele[0], ele.width(), ele.height());

		var x0 = 225,
			y0 = 300,
			r = 30,
			n = 10,
			len = data.length,
			x, y;

		paper.text(200, 10, '根据您设置的定向条件，预估一天内曝光量范围为：').attr({
			'font-size': 14,
			'fill': '#cc3433'
		});
		paper.text(200, 35, range).attr({
			'font-size': 20,
			'fill': '#cc3433'
		});
		var string = setupsWithOutFlowPredict();
		if(string!=""){
			var smallinfo =  "由于您在策略中设置的"+string+"，暂时不作为曝光量预估的计算条件，所以展示的预估范围将比实际曝光量偏大。";
			for(var i=0;i<smallinfo.length/30;i++){
				paper.text(200, 60+i*20, smallinfo.substring(30*i,Math.min(30*i+30,smallinfo.length-1))).attr({
					'font-size': 12,
					'fill': '#cc3433'
				});
			}
		}
		var angle = 360 / len;
		a = 90;

		var points = [], polygons = [];

		for(var i=0; i<n; i++) {
			var path = "M",
				ps = [];

			for(var j=0; j<len; j++) {
				x = x0 + Math.round(r * Math.cos((a*Math.PI + j * angle * Math.PI) / 180));
				y = y0 + Math.round(r * Math.sin((a*Math.PI + j * angle * Math.PI) / 180));

				ps.push(new Point(x, y));

				path += x + ' ' + y;

				if(j != (len - 1))
					path += 'L'
				else
					path += 'Z'
			}

			polygons.push(path)
			points.push(ps);
			r += 15;
		}

		var lines = [];
		for(i=0; i<len; i++) {
			var p = 'M' + x0 + ' ' + y0;
			p += 'L' + points[n-1][i].x + ' ' + points[n-1][i].y;
			lines.push(p);
		}

		var path = 'M';

		for(i=0; i<len; i++) {
			var percent = data[i][1];

			if(percent != '0') {
				path += points[percent-1][i].x + ' ' + points[percent-1][i].y;
			} else {
				path += x0 + ' ' + y0;
			}

			if(i != len-1) {
				path += 'L'
			}

			var x = points[9][i].x,
				y = points[9][i].y;

			var ta = 'middle';
			if(x > x0) {
				ta = 'start';
				x += 10;
			} else if(x < x0) {
				ta = 'end';
				x -= 10;
			} else if(x == x0) {
				if(y > y0) y += 20
				else y -= 10;
			}
			paper.text(x, y, data[i][0]).attr({
				'text-anchor': ta,
				'font-size': 12,
				'fill': '#666'
			});
		}

		$.each(polygons, function(index) {
			var p = paper.path(this);
			if(index == polygons.length-1)
				p.attr('stroke', '#c1c1c1');
			else
				p.attr('stroke', '#d1d1d1');

		});

		$.each(lines, function() {
			paper.path(this).attr({
				'stroke': '#d1d1d1'
			})
		})

		paper.path(path).attr({
			'fill': '#f90',
			'stroke-width': 0,
			'fill-opacity': 0.6
		});

		var texts = paper.set();
		texts.push(paper.text(x0-12, y0, '0'));
		var i = 0;
		$.each(points, function() {
			i += 10;
			texts.push(paper.text(this[0].x-12, this[0].y+3, i));
		})
		texts.attr({
			'font-size': 10,
			'fill':'#777'
		});

		//paper.image(setinfoimg, 330, 410, 107, 26);
	}

	function drawText() {
		clear();
		ele.html(tmpl);
		drawBtn();

		var children = $('.set-title, .set-content, .exposure-num, .warn')
		$('.loading').show();
		setPropety();
		$('#set-delete').hide();
		$('#set-big').show();
		children.show();
		setMyInfo(result);
	}

	function drawBtn() {
		ele.prepend('<span id="set-delete" class="close-tag" style="position: absolute; top: 10px; right: 10px; cursor: pointer; z-index: 100; "></span><span id="set-big" style="cursor: pointer; position: absolute; top: 10px; right: 12px; top: 3px; font-size: 20px; display: none; ">+</span>');
		addEvents();
	}

	function addEvents() {
		ele.find('#set-delete').click(function() {
			currentMode = 0;
			ele.animate({
				width: 198,
				height: 427
			}, 3e2, function() {
				drawText();
			});
		});
		ele.find('#set-big').click(function() {
			currentMode = 1;
			ele.animate({
				width: 450,
				height: 480
			}, 2e2, function() {
				drawPlot();
			})
		});
	}

	function clear() {
		ele.html('');
	}
}