﻿// Copyright by JerryYan QQ:855222
// 移动顶部
function top(selectId) {
	var selectedOption = $("#" + selectId + ">option[@selected]");
	if (selectedOption.get(0).index != 0) {
		selectedOption.each(function() {
			selectedOption.insertBefore($("#" + selectId + ">option:first-child"));
		});
	}
}
// 上移
function up(selectId) {
	//var nSelectedIndex = $('#<%=lbPics.ClientID%>').attr("selectedIndex");
	var selectedOption = $("#" + selectId + ">option[@selected]");
	if(selectedOption.get(0).index != 0) {
		selectedOption.each(function() {
			$(this).insertBefore($(this).prev());
		});
	}
}
// 下移
function down(selectId) {
	var allOptions = $("#" + selectId + ">option");
	var selectedOption = $("#" + selectId + ">option[@selected]");
	if (selectedOption.get(0).index != allOptions.length - 1) {
		var item = $(selectedOption.get(0));
		item.insertAfter(item.next());
	}
}
// 移动到底部
function bottom(selectId) {
	var allOptions = $("#" + selectId + ">option");
	var selectedOption = $("#" + selectId + ">option[@selected]");
	if (selectedOption.get(0).index != allOptions.length - 1) {
		selectedOption.insertAfter($("#" + selectId + ">option:last-child"));
	}
}


// 将列表A中的所有元素移动到列表B中
function addAll(sourceId, targetId) {
	if ($("#" + sourceId + ">option").length < 1)
		return;
		
	$("#" + sourceId + ">option").each(function (){
		if ($("#" + targetId + ">option").length == 0)
			$(this).appendTo($("#" + targetId));
		else
			$(this).insertAfter($("#" + targetId + ">option:last-child"));
	});
}
// 将列表A中指定的元素移动到列表B中
function add(sourceId, targetId) {
	var selectedOption = $("#" + sourceId + ">option[@selected]");
	if (selectedOption.text() == "")
		return;
		
	if ($("#" + targetId + ">option").length == 0)
		selectedOption.appendTo($("#" + targetId));
	else
		selectedOption.insertAfter($("#" + targetId + ">option:last-child"));
}


// 全选
function selectAll(parentId) {
	$("#" + parentId + " input[type=checkbox]").each(function() {
		$(this).attr("checked", true)
	});
}
// 反选
function reverseSelect(parentId) {
	$("#" + parentId + " input[type=checkbox]").each(function() {
		if ($(this).attr("checked"))
			$(this).attr("checked", false);
		else
			$(this).attr("checked", true);
	});
}
// 取消全选
function unSelectAll(parentId) {
	$("#" + parentId + " input[type=checkbox]").each(function() {
		$(this).attr("checked", false)
	});
}

////获取点击次数
//function getClickCount(strUrl, strAction, strSpanId) {
//	$.ajax({
//		type: "get",
//		url: strUrl,
//		timeout: 5000,
//		//data: { strAction },
//		beforeSend: function() { },
//		error: function() { },
//		success: function(result) {
//			$("#" + strSpanId).html(result);
//		}
//	});
//}