
/**
 * 项目名
 * 
 * @type
 */
var appPath;

var picUrl_middles = new Array();
var totalVotePicCount;

// =======================前台页面==========================//

/**
 * 首页 ———— 初始化投票选手列表 ———— 设置缩略图、设置投票游客信息输入框 ———— 闪动图片
 * 
 * @param {}
 *            voterName 是否记名投票
 * @param {}
 *            voterInfo 投票游客信息名称
 * @param {}
 *            path 项目名
 */
function initIndex(voterName, voterInfo, path, isExpert) {
	appPath = path;
	rollpicService.queryDBRP(setPic);
	setVoter(voterName, voterInfo, isExpert);
}

/**
 * 投票区 ———— 初始化投票选手列表 ———— 设置缩略图、设置投票游客信息输入框
 * 
 * @param {}
 *            voterName 是否记名投票
 * @param {}
 *            voterInfo 投票游客信息名称
 */
function initListVoteInfos(voterName, voterInfo, isExpert) {
	setVoter(voterName, voterInfo, isExpert);
}

/**
 * 详细信息页面 ———— 初始化投票信息名称 ———— 设置投票游客信息输入框
 * 
 * @param {}
 *            voterName
 * @param {}
 *            voterInfo
 */
function initVoteInfo(voterName, voterInfo, voteInfoTitle, picUrl_middle,totalVotePicCount, isExpert) {
	var titles = voteInfoTitle.split("&");
	$.each(titles, function(i, n) {
				var cell = n.split("$");
				if (cell[0] != 1 && cell[0] == i + 1) {
					$("#title" + (i + 1)).prepend(cell[1] + "：");
				} else if (cell[0] == 0 && cell[0] != "") {
					$("#title" + (i + 1)).hide();
				}
			});
	setVoter(voterName, voterInfo, isExpert);
	this.totalVotePicCount = totalVotePicCount;
	var pic_middle = picUrl_middle.split("&");
	$.each(pic_middle, function(i, n) {
				picUrl_middles[i] = n;
			});
}

/**
 * 改变投票选项排列方式
 * 
 * @param {}
 *            url
 */
function changeArrange(url) {
	var arrange = $("#arrange");
	url += "&arrange=" + arrange.val();
	window.location = url;
}

/**
 * 设置投票游客信息输入框
 * 
 * @param {}
 *            voterName 是否记名投票
 * @param {}
 *            voterInfo 投票游客信息名称
 */
function setVoter(voterName, voterInfo, isExpert) {
	if (isExpert == 1) {
		// 专家投票
		var voter = $("#voter");
		voter
				.append("<tr><td align='right'>投票专家身份证：</td><td><input type='text' name='expert_info' value='' class='voterName' /></td></tr>");
		var myDiv = $(".mydiv");
		myDiv.height(myDiv.height() + 27);
		return;
	}
	if (voterName == 1) {
		// 记名投票
		var voter = $("#voter");
		var infos = voterInfo.split("&");
		$.each(infos, function(i, n) {
					var cell = n.split("$");
					if (cell[0] == (i + 1)) {
						voter.append("<tr><td align='right'>" + cell[1]
								+ "：</td><td><input type='text' name='info"
								+ (i + 1)
								+ "' value='' class='voterName' /></td></tr>");
						var myDiv = $(".mydiv");
						myDiv.height(myDiv.height() + 27);
					}
				});
	}
}

/**
 * 显示半透明层，设置参数voteInfoId ———— 首页、投票区、详细信息页面，点击“我要投票”
 * 
 * @param {}
 *            voteInfoId
 */
function showDiv(voteInfoId) {
	document.getElementById("popDiv").style.display = "block";
	document.getElementById("bg").style.display = "block";
	$(".voterName")[0].focus();
	// 设置参数voteInfoId
	var id = $("#voteInfoId");
	id.val(voteInfoId);
}

/**
 * 显示半透明层 ———— 首页、投票区，点击“我要投票”(同时投多个选手)
 * 
 * @param {}
 *            voteInfoId
 */
function showDiv_noneId(voteMode) {
	var voteInfoIds = $("input[name=voteInfoId]:checked");
	if (voteInfoIds.size() == 0) {
		alert("请先选择！");
		return false;
	}
	if (voteInfoIds.size() > voteMode) {
		alert("每次最多只能选择" + voteMode + "个选手！");
		return false;
	}

	document.getElementById("popDiv").style.display = "block";
	document.getElementById("bg").style.display = "block";
	$(".voterName")[0].focus();
}

/**
 * 隐藏半透明层 ———— 点击取消
 */
function closeDiv() {
	document.getElementById("popDiv").style.display = "none";
	document.getElementById("bg").style.display = "none";
}

/**
 * 投票表单验证
 * 
 * @return {Boolean}
 */
function checkVote() {
	var flag = 0;
	var input = $(".voterName");
	input.each(function(i) {
				if ($(this).val() == null || $(this).val() == "") {
					flag = 1;
					$(this).focus();
					return false;
				}
			});
	if (flag == 1) {
		alert("请输入所有信息！");
		return false;
	} else {
		$("#vote_submit").attr("disabled", "disabled");
		return true;
	}
}

/**
 * 首页闪动图片
 * 
 * @param {}
 *            obj
 */
function setPic(obj) {
	$("#content_1_pic").html(setScrollPhoto(obj, 300, 150, 4, 3000, 1,
			'000000', 'dddddd', appPath));
}

/**
 * 首页 ———— 点击展开、收缩注意事项、合作伙伴
 */
function spread() {
	var notice = $("#notice");
	var friendlinks = $("#friendlinks");
	var content_2 = $("#content_2");
	var spread1 = $("#spread1");
	var spread2 = $("#spread2");
	if (notice.css("display") == "none") {
		spread1.html("点击收缩");
		spread2.html("点击收缩");
		content_2.css("height", "113px");
		notice.css("display", "block");
		friendlinks.css("display", "block");
	} else {
		spread1.html("点击展开");
		spread2.html("点击展开");
		content_2.css("height", "28px");
		notice.css("display", "none");
		friendlinks.css("display", "none");
	}
}

/**
 * 点击搜索框清除“输入选手名称”
 */
function cleanTitle1() {
	$("input[name=title1]").val("");
}

/**
 * 搜索投票信息表单验证
 * 
 * @param {}
 *            appPath1
 * @return {Boolean}
 */
function checkSearchVoteInfo() {
	var title1 = $("input[name=title1]").val();
	if (title1 == "输入选手名称" || title1 == "") {
		alert("请输入你想搜索的信息！");
		$("input[name=title1]").focus();
		return false;
	} else {
		return true;
	}
}

// ===========================后台页面============================//

/**
 * 删除项目表单验证
 * 
 * @return {Boolean}
 */
function checkDeleteForm() {
	var checkbox = $(":checkbox");
	var flag = 0;
	checkbox.each(function(i) {
				if ($(this).attr("checked") == true) {
					flag = 1;
				}
			});
	if (flag == 0) {
		alert("请先选择！");
		return false;
	}
}

// ===========================通用============================//

/**
 * 转到其他页面
 * 
 * @param {}
 *            url
 */
function turnTo(url) {
	window.location = url;
}

/**
 * 点击复制按钮
 * 
 * @param {}
 *            id
 */
function jsCopy(id) {
	var e = document.getElementById(id);
	e.select();
	document.execCommand("copy");
}

/**
 * 前台“排行榜”、后台“投票统计” ———— 画投票统计图
 * 
 * @param {}
 *            ballotAmount 票数总和
 * @param {}
 *            width 最大宽度
 */
function drawBar(ballotAmount, width) {
	var bar = $(".bar");
	bar.each(function(i) {
				var thisBallot = $(this).attr("title");
				$(this).css("width", thisBallot / ballotAmount * width);
			});
}

/**
 * 获取下一个组图
 * 
 * @param {}
 *            count
 */
function getNextPic(count) {
	if (count == totalVotePicCount - 1) {
		var cur = 0;
		$("#pic_url").replaceWith("<img id=\"pic_url\" src=\"" + picUrl_middles[count]
				+ "\"  border=\"0\" />");
		$("#next")
				.replaceWith("<a id=\"next\" style=\"cursor: hand\" onclick=\"getNextPic("
						+ cur + ")\">下一张</a>");
		var n = count - 1;
		$("#prev")
				.replaceWith("<a id=\"prev\" style=\"cursor: hand\" onclick=\"getPrevPic("
						+ n + ")\">上一张</a>");

	} else {
		var n = count + 1;
		$("#pic_url").replaceWith("<img id=\"pic_url\" src=\"" + picUrl_middles[count]
				+ "\"  border=\"0\" />");
		$("#next")
				.replaceWith("<a id=\"next\" style=\"cursor: hand\" onclick=\"getNextPic("
						+ n + ")\">下一张</a>");
		var p = count - 1;
		if (p < 0)
			p = totalVotePicCount - 1;
		$("#prev")
				.replaceWith("<a id=\"prev\" style=\"cursor: hand\" onclick=\"getPrevPic("
						+ p + ")\">上一张</a>");

	}
	var c = count + 1;
	$("#countPic").html("第" + c + "张&nbsp;&nbsp;共" + totalVotePicCount + "张");
}

/**
 * 获取上一个组图
 * 
 * @param {}
 *            count
 */
function getPrevPic(count) {
	if (count == 0) {
		var cur = totalVotePicCount - 1;
		$("#pic_url").replaceWith("<img id=\"pic_url\" src=\"" + picUrl_middles[count]
				+ "\"  border=\"0\" />");
		var n = count + 1;
		$("#next")
				.replaceWith("<a id=\"next\" style=\"cursor: hand\" onclick=\"getNextPic("
						+ n + ")\">下一张</a>");
		$("#prev")
				.replaceWith("<a id=\"prev\" style=\"cursor: hand\" onclick=\"getPrevPic("
						+ cur + ")\">上一张</a>");
	} else {
		var p = count - 1;
		$("#pic_url").replaceWith("<img id=\"pic_url\" src=\"" + picUrl_middles[count]
				+ "\"  border=\"0\" />");
		var n = count + 1;
		if (count == totalVotePicCount - 1)
			n = 0;
		$("#next")
				.replaceWith("<a id=\"next\" style=\"cursor: hand\" onclick=\"getNextPic("
						+ n + ")\">下一张</a>");
		$("#prev")
				.replaceWith("<a id=\"prev\" style=\"cursor: hand\" onclick=\"getPrevPic("
						+ p + ")\">上一张</a>");
	}
	var c = count + 1;
	$("#countPic").html("第" + c + "张&nbsp;&nbsp;共" + totalVotePicCount + "张");
}

