function isEmail(obj){
	return isEmailStr(obj.value);
}

function isEmailStr(str){
	return (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str));
}

function isBlankComboBoxGroup(objElement){
  obj=eval("document."+objElement.form.name+"."+objElement.name);
  result=false;
  for (var i = 0; i < obj.length; i++) { 
    objname=obj[i].name;     
    result=result||eval("document."+obj[i].form.name+"."+objname+"[" + i + "].checked"); 
  }  
  return !result;
}

function isBlankText(str){
	return !(str.value.length>0);
}

function isBlankSelectionBox(sel){
	return sel.options[sel.selectedIndex].value=="";
}

function getBlankComboBoxGroup(objElement){
  obj=eval("document."+objElement.form.name+"."+objElement.name);
  result="";
  for (var i = 0; i < obj.length; i++) { 
    objname=obj[i].name;     
    if (eval("document."+obj[i].form.name+"."+objname+"[" + i + "].checked"))
    	result=eval("document."+obj[i].form.name+"."+objname+"[" + i + "].value")
  }  
  return result;
}

function getValue(tempobj){
	var result;
	var obj_type=tempobj.type+"";
	if (obj_type=="hidden")
		result=tempobj.value;	
    if (obj_type=="text"||obj_type=="textarea"||obj_type=="password")
		result=tempobj.value;
	if (obj_type.indexOf("select")>=0)
		result=(tempobj.selectedIndex==-1?"":tempobj.options[tempobj.selectedIndex].value);		
	if (obj_type=="radio")
		result=getBlankComboBoxGroup(tempobj);	
	if (obj_type=="undefined" && tempobj.length>0 && tempobj[0].type=="radio")
		result=getBlankComboBoxGroup(tempobj[0]);
        if (obj_type=="checkbox"){
		if (tempobj.checked) result=tempobj.value;
		if (!tempobj.checked) result="";
	}
	if (obj_type=="file")
		result=tempobj.value;	
	return result;
}

function isBlank(tempobj){
	result=true;
	var obj_type=tempobj.type+"";
	if (obj_type=="hidden")
		result=result&&isBlankText(tempobj);			
    if (obj_type=="text"||obj_type=="textarea"||obj_type=="password")
		result=result&&isBlankText(tempobj);
	if (obj_type.indexOf("select")>=0)
		result=result&&isBlankSelectionBox(tempobj);
	if (obj_type=="radio")
		result=result&&isBlankComboBoxGroup(tempobj);	
	if (obj_type=="undefined" && tempobj.length>0 && tempobj[0].type=="radio")
		result=result&&isBlankComboBoxGroup(tempobj[0]);
	if (obj_type=="file")
		result=result&&isBlankText(tempobj);			
	return result;
}

function isNumber(obj){
	return isNumberStr(obj.value);
}

function isNumberStr(str){
	if (str && str.indexOf("..")>0) return false;
	if (str && str.indexOf(",")>0) return false;	
	return str==""||!isNaN(parseInt(str, 10));
}

function isAlpha(obj,acceptableChar){
	return isAlphaStr(obj.value,acceptableChar);
}

function isAlphaStr(str,acceptableChar){
	temp="*"+acceptableChar+"*";
	if (temp=="*undefined*") acceptableChar="";
    result=true;
	for (i=0; i<str.length; i++){
		if ((str.charAt(i)>='a' && str.charAt(i)<='z') || (str.charAt(i)>='A' && str.charAt(i)<='Z')
			|| acceptableChar.indexOf(str.charAt(i))>=0	)
			;
		else {
			return false;		
		}
	}
	return result;
}

function isAlphaNumeric(str,acceptableChar){
	return isAlphaNumericStr(str.value,acceptableChar);
}

function isAlphaNumericStr(str,acceptableChar){
	temp="*"+acceptableChar+"*";
	if (temp=="*undefined*") acceptableChar="";

    result=true;
	for (i=0; i<str.length; i++){
		if ((str.charAt(i)>='a' && str.charAt(i)<='z') || (str.charAt(i)>='A' && str.charAt(i)<='Z')
			|| (str.charAt(i)>='0' && str.charAt(i)<='9')
			|| acceptableChar.indexOf(str.charAt(i))>=0	)
			;
		else
			return false;
	}
	return result;
}

function LeapYear(YYYY) {
	if (YYYY % 100 == 0) {
		if (YYYY % 400 == 0)  return true; 
	}
	else {
		if ((YYYY % 4) == 0)  return true; 
	}
	return false;
}

function isDate(DD,MM,YYYY){
    if (DD.type=="hidden" && MM.value.length==0 && YYYY.value.length==0) return true;
	return isDateStr(DD.value,MM.value,YYYY.value);
}

function isDateStr(DD,MM,YYYY){
	if (DD.length==0 && MM.length==0 && YYYY.length==0) return true;
	if (!isAlphaNumericStr(DD) || !isAlphaNumericStr(MM) || !isAlphaNumericStr(YYYY)) return false; 
	if (isNaN(parseInt(DD, 10)) || isNaN(parseInt(MM, 10)) || isNaN(parseInt(YYYY, 10))) return false;
	if (MM>12 || MM<1 || DD<1 || DD>31) return false;
	if ((MM == 1 || MM == 3 || MM == 5 || MM == 7 || MM == 8 || MM == 10 || MM == 12) && (DD > 31 || DD < 1)) return false;
	if ((MM == 4 || MM == 6 || MM == 9 || MM == 11) && (DD > 30 || DD < 1)) return false;
	if (MM==2 && LeapYear(YYYY)==true && DD > 29) return false;
		else if (MM==2 && LeapYear(YYYY)==false && DD > 28) return false;
	if (YYYY<1900) return false;
	var year=(new Date()).getYear();if (year<1000) year=year+1900;

	if (YYYY>year+100) return false;	
	return true;
}

function isIDCard(obj1,obj2){
	if (getValue(obj2).length==0 && getValue(obj1).length==0) return true;
	if (getValue(obj1).length!=1 && getValue(obj1).length<=6) return false;
	if (!(getValue(obj2)=='A'||getValue(obj2)=='a'||(getValue(obj2)>='0' && getValue(obj2)<='9'))) return false;
	if (!isNumberStr(getValue(obj1).substring(getValue(obj1).length-6,getValue(obj1).length))) return false;
	if (!isAlphaStr(getValue(obj1).substring(0,getValue(obj1).length-6))) return false;
	if (getValue(obj1).length==8 && !isAlphaStr(getValue(obj1).substring(1,2))) return false;
	return true;
}

function clear(tempobj){
	var obj_type=tempobj.type+"";
	if (obj_type=="hidden")
		tempobj.value="";	
    if (obj_type=="text"||obj_type=="textarea"||obj_type=="password")
		tempobj.value="";
	if (obj_type.indexOf("select")>=0)
		tempobj.options[0].selected=true;
	if (obj_type=="radio")
		tempobj.checked=false;
	if (obj_type=="undefined" && tempobj.length>0 && tempobj[0].type=="radio"){
		obj=eval("document."+tempobj[0].form.name+"."+tempobj[0].name);
  		for (var i = 0; i < obj.length; i++) { 
    		objname=obj[i].name;     
    		leaveObj=eval("document."+obj[i].form.name+"."+objname+"[" + i + "]"); 
    		leaveObj.checked=false;
  		}  
  	};
}

function disable(text){
	text.blur();
}

function grey(obj){
        if (!document.layers) obj.style.backgroundColor ="#999999";
}
function shade(obj){
        if (!document.layers) obj.style.backgroundColor ="#D8D8D8";
}

function isInt(string) {
  if (string.length == 0)
    return false;
  for (var i=0;i < string.length;i++)
    if ((string.substring(i,i+1) < '0') || (string.substring(i,i+1) > '9'))
      return false;
  return true;
}

function isFloat(string) {
  if (string.value.length == 0)
    return true;
  for (var i=0;i < string.value.length;i++) {
    if (string.value.substring(i,i+1) < '0' || 
        string.value.substring(i,i+1) > '9') {
       if (string.value.substring(i,i+1) != ".") {
         return false;
       }
    }
  }
  return true;
}
// script LANGUAGE="JavaScript1.2" src="https://...:8000/docs/js/library.js"
// /script
