function check_empty(fieldName) {
    if (trim(document.getElementById(fieldName).value) == "") {	  	
        return true;
    }
    return false;
}

function check_empty_forArrayItem(field) {
    if (trim(field.value) == "") {	  	
        return true;
    }
    return false;
}

function checkEmail(email) {
	var emailStr = document.getElementById(email).value;
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailStr)) {
        return true;
    }
    return false;
}

//int ==> type=1
//float ==>type==2
function check_amountInvaild(fieldName,type) {
	if (parseInt(type) == 1) {
        if (document.getElementById(fieldName).value.match(/[^1234567890]/) != null) {	  	
            return true;
		}
	} else {
        if (document.getElementById(fieldName).value.match(/[^1234567890.]/) != null) {	  	
            return true;
        } else {
	        var num = document.getElementById(fieldName).value;
		    var i=num.length;
		    var count;
		    count = 0;
		    if (num.charAt(i-1) == '.') {
                return true;
            }
		    for (j = 0; j < i; j++) {
                if (num.charAt(j) == '.') {
                    count++;
                }
                if (count > 1) {
                   return true; 
                }
            }
	    }
	}
    return false;
}

//int ==> type=1
//float ==>type==2
function check_amountInvaild_by_value(value,type) {
	if (parseInt(type) == 1) {
        if (value.match(/[^1234567890]/) != null) {	  	
            return true;
		}
	} else {
        if (value.match(/[^1234567890.]/) != null) {	  	
            return true;
        } else {
	      var num = value;
		    var i=num.length;
		    var count;
		    count = 0;
		    if (num.charAt(i-1) == '.') {
                return true;
            }
		    for (j = 0; j < i; j++) {
                if (num.charAt(j) == '.') {
                    count++;
                }
                if (count > 1) {
                   return true; 
                }
            }
	    }
	}
    return false;
}

//int ==> type=1
//float ==>type==2
function check_amountInvaild_forArrayItem(field,type) {
	if (parseInt(type) == 1) {
        if (field.value.match(/[^1234567890]/) != null) {	  	
            return true;
		}
	} else {
        if (field.value.match(/[^1234567890.]/) != null) {	  	
            return true;
        } else {
	        var num = field.value;
		    var i=num.length;
		    var count;
		    count = 0;
		    if (num.charAt(i-1) == '.') {
                return true;
            }
		    for (j = 0; j < i; j++) {
                if (num.charAt(j) == '.') {
                    count++;
                }
                if (count > 1) {
                   return true; 
                }
            }
	    }
	}
    return false;
}


function checkIpAddress(ipAddress) {
	var ipAddressStr = document.getElementById(ipAddress).value;
    var reg =/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
    if (reg.test(ipAddressStr)) {
        var ary = ipAddressStr.split('.');
        for (key in ary) {
            if ((parseInt(ary[key]) > 255) || (parseInt(ary[0]) == 0) || (parseInt(ary[key]) < 0)) {
			    return false;
			}
       }
	} else {
	    return false;	
	}
    return true;	
}

function checkRange(fieldName,max,min) {
    if ((parseInt(document.getElementById(fieldName).value, 10) > parseInt(max, 10)) || 
        (parseInt(document.getElementById(fieldName).value, 10) < parseInt(min, 10))) {
        return true;
    }
    return false;    
}

function checkRange_forArrayItem(field,max,min) {
    if ((parseInt(field.value, 10) > parseInt(max, 10)) || (parseInt(field.value, 10) < parseInt(min, 10))) {	  	
        return true;
    }
    return false;    
}

function trim(str){
	return str.replace(/(^\s*)|(\s*$)/g, "");
}