
function chkLength(field, msg, minLength, maxLength)
{
	checkOk=true;
	if (!minLength) minLength =1;	
	
	if (checkOk && field.value.length < minLength)  checkOk=false;
	if (checkOk && maxLength>minLength && field.value.length>maxLength) checkOk=false;
	
	return chkReturn(field,checkOk, msg);
}

function chkSelected(field,msg,minValueLen){
	checkOk=true;	
	
	if(checkOk && field.selectedIndex<0) checkOk=false;
	if(checkOk && minValueLen && 
		minValueLen > field.options[field.selectedIndex].value.length) checkOk=false;	
	
	return chkReturn(field,checkOk, msg);
}

function chkEmail(field,msg) {
	var str=field.value;
	var checkOk=true;	
	var supported = 0;
	if (window.RegExp) {
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	
  	if (!supported) {
		checkOk=(str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  	} else {
	  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	  checkOk=(!r1.test(str) && r2.test(str));
	}
  return chkReturn(field,checkOk, msg);
}



function chkAnyCheck(checkBoxObj, msg)
{
	// Check browser
	var agt=navigator.userAgent.toLowerCase();
	// mac not support yet
	var is_mac    = (agt.indexOf("mac")!=-1);
	if(is_mac) return(true);

	ch_len = checkBoxObj.length;
	checkOk=false;
	for(i=0; i<ch_len;i++)
	{
		if(checkBoxObj[i].checked) {
			checkOk=true;
			break;
		}
	}
	
	return chkReturn(checkBoxObj,checkOk, msg, true);
}

function chkReturn(field,checkOk, msg, nofocus) {
	if (!checkOk){
   	alert(msg);
   	if(!nofocus)
   		field.focus();
    	return false;
    }
	return true;
}

function isAlphaNumeric(str,msg) {
 
 var validchars = /^[-a-zA-Z0-9_]+$/
 if(validchars.test(str)) {
   return(true);
 }else {
   alert(msg); 
	return(false);
 }   
}

function isAlpha(str,msg) {
  var validchars = /^[a-zA-Z0-9]+$/
 if(validchars.test(str)) {
   return(true);
 }else {
   alert(msg); 
	return(false);
 }   
} 

function isValidString(field,msg){
 var validchars = /www.|\.com|\.net|\.cn|\.hk|\.tw|\.org|@|\/>|<\//
 if(validchars.test(field.value)) {
   alert(msg); 
	field.focus();
	return(false);
	
 }else {
	return(true);
 }   
}


function isChecked(field,msg){
	if (field.checked){
		return(true);
	}else{
		alert(msg);
		field.focus();
		return(false);
	}
}

function textLimit(field,maxlimit) {
if (field.value.length > maxlimit) {
	field.value = field.value.substring(0, maxlimit);
	}
}


