/*************************************
*** ┌┈┈┈┈┈┈┈┈┈┈┈┈┈┐ ***
*** ┊  Powered By HongRu.DJJ   ┊ ***
*** ┊  Last Modify 2008-06-25  ┊ ***
*** └┈┈┈┈┈┈┈┈┈┈┈┈┈┘ ***
*** ┌┈┈┈┈┈┈┈┈┈┈┈┈┈┐ ***
*** ┊ msn_dujunjie@hotmail.com ┊ ***
*** └┈┈┈┈┈┈┈┈┈┈┈┈┈┘ ***
*************************************/


//弹出模态窗口
function openDialog(url,w,h)
{
	showModalDialog(url,window,'dialogWidth:'+w+'px;dialogHeight:'+h+'px;center:1;scroll:0;help:0;status:0');
	
/*	var ReturnVar=window.showModalDialog(url,window,'dialogWidth:'+w+'px;dialogHeight:'+h+'px;center:1;scroll:0;help:0;status:0')
	if(ReturnVar==0)
	{
		location.href=location.href;
	}
	return false;*/
}	

//弹出确认框
function getConfirm(str)
{
	var box=window.confirm("提示：\n\n"+str);
	if(box){
		return true;}
	else{
		return false;
	}
}


//身份证验证
function isIdCard(s)
{
	if((s.search(/^[1-9]([0-9]{16}|[0-9]{13})[xX0-9]$/)!=-1)||(s.length==18)||(s.length==15))
		return true;
	else
		return false;
}

//整数验证
function isInt(s)
{
	if(s.search(/^[0-9]+$/)!=-1)
		return true;
	else
		return false;
}

//验证实数
function isFloat(snumber){
	var checkOK = "0123456789.";
	var checkStr = snumber;
	var allValid = true;
	var obj;
	for (i = 0;  i < checkStr.length;  i++){
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j)) break;
		if (j == checkOK.length){
			return (false);
		}
	}
	return (true);
}


function isUnderline(s)
{
		
	if(s.search(/^[A-Za-z0-9_]+$/)!=-1)
		return true;
	else
		return false;
	
}
function isIntAndChar(s)
{
		
	if(s.search(/^[A-Za-z0-9]+$/)!=-1)
		return true;
	else
		return false;
	
}

function JHshStrLen(sString){
	var sStr,iCount,i,strTemp ;
	iCount = 0 ;
	sStr = sString.split("");
	for (i = 0 ; i < sStr.length ; i ++){
		strTemp = escape(sStr[i]);
		if (strTemp.indexOf("%u",0) == -1){ 	 // 表示是汉字
			iCount = iCount + 1 ;
		}else{
			iCount = iCount + 2 ;
		}
	}
	return iCount ;
}

//全选
function checkall(idValue){
	var num;
	num =eval(idValue).length;
	if (num==1){
	
		if(eval(idValue).checked==false)
			eval(idValue).checked=true;
		else
			eval(idValue).checked=false;
	}else{

		for(i=0;i<num;i++){

			if(eval(idValue)[i].checked==false){
				flg = "false";}
			else{
				flg = "true";}
		}
		for(i=0;i<num;i++){
			if(flg=="true"){
				eval(idValue)[i].checked=false;}
			else{
				eval(idValue)[i].checked=true;
				}
		}
	
	}
}

//日期验证
function isDate(sDate) {
	var iYear, iMonth, iDay, iIndex

	var	reg
	reg = new RegExp('[^0-9-]','')
	if (sDate.search(reg) >= 0)
		return false;
	
	iIndex = sDate.indexOf('-');
	if ( iIndex == -1 )
		return false;
	else {
		iYear = parseFloat(sDate.substr(0, iIndex));
		if ( isNaN(iYear) || iYear < 1900 || iYear > 2099 )
			return false;
		else
			sDate = sDate.substring(iIndex + 1, sDate.length);
	}
	
	iIndex = sDate.indexOf('-');
	if ( iIndex == -1 )
		return false;
	else {
		iMonth = parseFloat(sDate.substr(0, iIndex));
		if ( isNaN(iMonth) || iMonth < 1 || iMonth > 12 )
			return false;
		else
			sDate = sDate.substring(iIndex + 1, sDate.length);
	}
	
	iIndex = sDate.indexOf('-');
	if ( iIndex >= 0 )
		return false;
	else {
		iDay = parseFloat(sDate);
		if ( isNaN(iDay) || iDay < 1 || iDay > 31 )
			return false;
	}
	
	
	switch(iMonth) {
		case 4:
		case 6:
		case 9:
		case 11:
			if ( iDay > 30 )
				return false;
			else
				break;
		case 2:
			if ( ( ( iYear % 4 == 0 && iYear % 100 != 0 ) || iYear % 400 == 0 ) && iDay > 29 )
				return false;
			else if ( (iYear % 4 != 0 || (iYear % 100 == 0 && iYear % 400 != 0)) && iDay > 28 )
				return false;
			else
				break;
		default:
	}
	return true;
}






//获取下拉选项值
function getSelectedValue(idvalue){
	
	var obj=document.getElementById(idvalue);
	for(i=0;i<obj.length;i++){
		
		if(obj[i].selected==true){
			if(obj[i].value==""){
				
				return obj[i].innerText; //关键是通过option对象的innerText属性获取到选项文本
			
			}else{
				
				return obj[i].value;
			}
		}
	}
	return false;
}

//获取下拉选项值
function getCheckedValue(idvalue){
	
	var obj=document.getElementsByName(idvalue);
	for(i=0;i<obj.length;i++){
		
		if(obj[i].checked==true){
			if(obj[i].value==""){
				
				return obj[i].innerText; //关键是通过option对象的innerText属性获取到选项文本
			
			}else{
				
				return obj[i].value;
			}
		}
	}
	return false;
}

//验证合法邮箱
function isEmail(s)
{
	if (s.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		return true;
	else
		return false;
}


//返回字符长度
function len(s)
{
	if(s==null)
		return 0;
	else
		return s.replace(/[^\x00-\xff]/g,"**").length;
}

//验证是否是双字节
function isDoubleFont(s)
{
	if(s.search(/[^\x00-\xff]/)!=-1)
		return true;
	else
		return false;
}
