/*
通用软件javascript检测类
运行环境：jquery 1.2
版本：1.2.0
日期：Oct 28, 2008
*/
function _Univsoft()
{
	this.common = new Univsoft_Common();
}

function Univsoft_Common()
{
	var messageTitle = "System information"; 
	//检测是否是邮箱
	this.isEmail = function( paraEmail ){
		var reg_email = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
		if( reg_email.test(paraEmail) ){
			return true;
		}
		return false;
	};
	
	//弹出信息提示框
	this.showMessage = function( msg ){
		//alert( "[ "+messageTitle+" ]\n\n" + msg );
		alert(  msg );
	};
	
	//是否是日期
	this.IsDate = function( str )
	{
		var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/); 
		if(r==null)return false;
		var d = new Date(r[1], r[3]-1, r[4]); 
		return (
			d.getFullYear()==r[1]
			&& (d.getMonth()+1)==r[3]
			&& d.getDate()==r[4]
		);
	};
	this.CheckSpace = function( str ){
		str= $.trim(str);
		var i;
		for(i=0;i<str.length;i++){
			if(str.charAt(i)==" ") return true;
		}
		return false;
	};
	this.CheckPassword = function( str ){
		var reg_password = /^[0-9a-zA-Z]{6,16}$/;
		return reg_password.test( str );
	};
	
	//是否是数字
	this.IsNumeric = function( expression ){
		var isPassed = false;
		var re=/^\d*\.?\d*$/;
		
		if (expression!="" && re.test( expression.replace(/,/g,'') ))
		{
			isPassed = true;
		}
		return isPassed;
	};
	this.IsURL = function( str ){
		var r = str.match(/^https?:\/\/.+\..+/); 
		if(r==null)return false;
		return true;
	};
	this.IsPhoneNumber = function( str ){
		var r = str.match(/^\+?[-_0-9\s\(\)]+$/); 
		if(r==null)return false;
		return true;
	};
	//字节长度，中文为2
	this.bytesLength = function( str ) {
		var bytes = 0;
		for(i=0; i<str.length; i++)
		{
			ascii = str.charCodeAt(i);
			bytes += (ascii < 255 ? 1 : 2);
		}
		return bytes;
	};
	this.checkboxCheck = function( checkboxObj ){
		var count = 0;
		for(i=0;i<checkboxObj.length;i++)
		{
			if(checkboxObj[i].checked==true)
			{
				count++;
			}
		}
		return count;
	};
	this.radioboxCheck = function( radioboxObj ){
		if(typeof(radioboxObj.length)=="undefined")
		{
			if(radioboxObj.checked == true)
			{
			return true;
			}    	
		} else {
			for(i=0;i<radioboxObj.length;i++)
			{
				if(radioboxObj[i].checked==true)
				{
					return radioboxObj[i].value;
				}
			}
		}
		return false;
	};
	//全选
	this.checkAll = function( headerCheckBoxName, rowCheckBoxName, parentID){
		if( headerCheckBoxName == undefined || parentID == ""){
			headerCheckBoxName = "cbHeaderChecked";
		}
		if(rowCheckBoxName == undefined || parentID == ""){
			rowCheckBoxName = "cbRowChecked";
		}
		
		if( parentID != undefined && parentID != "")
		{
			if( $("#"+parentID)[0] != undefined)
			{
			}
			parentID = "#"+parentID + " ";
		} else {
			parentID = "";
		}
		
		$.each($(parentID+"input:checkbox[name^='"+rowCheckBoxName+"']"), function(i, n){
			$(n).attr("checked", $("#" + headerCheckBoxName).attr("checked"));
		});
	};
	
	this.checkConfirmNumber = function( tipName, checkedNumber, checkBoxId ){
		if( checkBoxId == undefined){
			checkBoxId = new Array("cbRowChecked");
		}
		
		var m =0;
		
		for(var i=0; i< checkBoxId.length; i++){
			m += $("input:checkbox:checked[name^='"+checkBoxId[i]+"']").length;
		}
		
		if (m == 0)
		{
			this.showMessage("Please select [ " + tipName + " ] items!");
			return false;
		} else if( checkedNumber != 0 && checkedNumber != m)
		{
			this.showMessage("Number of [ " + tipName + " ] mini. " + checkedNumber + " !");
			return false;
		} else {
			 return confirm("Are you sure you want to [ " + tipName + " ] the selected items?");  
		}
	};
}

var honghui = new _Univsoft();
var common = honghui.common;
var Univsoft = common;
