﻿// JScript 文件

function validString(value,minLength,maxLength,baseString,badString)
{
	var sString = new String(value);
	//最短要求

	if (minLength > 0) if (sString.length < minLength) return false;
	//最长要求

	if (maxLength > 0) if (sString.length > maxLength) return false;
	var i = 0;
	//基础字符串检查

	if (baseString.length> 0)
	{
		for (i=0;i<sString.length;i++)
			if (baseString.indexOf(sString.substr(i,1)) < 0) return false; 
	}
	//非法字符串检查

	for (i=0;i<badString.length;i++)
		if (sString.indexOf(badString.substr(i,1)) >= 0) return false; 

	return true;
	
}

function validEmail(Email)
{
	if (document.layers||document.getElementById||document.all)
	{
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		if (filter.test(Email))
			return true;
		else
			return false;
	}
	else
		return true;

	
}


function PickRadioGroupByValue(oRadioGroup,RadioValue)
{
	if (!oRadioGroup) return (false);

	if (oRadioGroup.length)
	{
	//多个
		var intLoop;
		for (intLoop=0;intLoop<oRadioGroup.length;intLoop++)
		{
			if (oRadioGroup[intLoop].value == RadioValue)
			{
				oRadioGroup[intLoop].checked = true;
				return;
			}
		}
		
	}
	else
	{
	//一个

		oRadioGroup.checked = true;
	}
	return;

}	//PickRadioGroup


function PickSelectElementByValue(oSelectElement,OptionValue)
{
	if (!(oSelectElement)) return;
	if(oSelectElement.tagName != "SELECT") return;
	var oOptions = oSelectElement.options;
	var intIndex = 0;
	
	
	for (intIndex = 0;intIndex<oOptions.length;intIndex++)
	{
		if (oOptions[intIndex].value == OptionValue)
		{
			oOptions[intIndex].selected = true;
			return;
		}
	}
	
	
}

function PickSelectElementByIndex(oSelectElement,OptionIndex)
{
	if (!(oSelectElement)) return;
	if(oSelectElement.tagName != "SELECT") return;
	var oOptions = oSelectElement.options;
	if (oOptions.length < 1) return;
	
	if (OptionIndex < 0 )
	{ 
		oSelectElement.selectedIndex = 0;
		return;
	}
	
	if (OptionIndex >= oOptions.length)
		oSelectElement.selectedIndex = oOptions.length - 1
	else
		oSelectElement.selectedIndex = OptionIndex;
	 OptionIndex = oOptions.length -1;
	
	
	
	
	for (intIndex = 0;intIndex<oOptions.length;intIndex++)
	{
		if (oOptions[intIndex].value == OptionValue) oOptions[intIndex].selected = true;
	}
	
	
}
