﻿// 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 checkTel (str)
{
	var reg = /^((0\d{2,3}[-|－]{1}\d{7,8})|(0\d{2,3}[-|－]{1}\d{7,8}[-|－]{1}\d{1,4}))$/;
	return check (reg, str);
}
// 检测字符串是否为手机号码
function checkMobil (str)
{
	var reg = /^(013|13|015|15)\d{9}$/;
	return check (reg, str);
}
// 检测字符串是否为邮编
function checkZip (str)
{
	var reg = /^[1-9]{1}\d{5}$/;
	return check (reg, str);
}
