
function fieldIsEmpty(field) {
    if(field == null) {
        return false;
    }
    return field.value.length < 1;
}
function shortField(field, len) {
    if(field == null) {
        return false;
    }
    return field.value.length < len;
}

function notChecked(field) {
    if(field == null) {
        return false;
    }
    
    return !field.checked;
}


function fieldShorterThan(field, len) {
    if(field == null) {
        return false;
    }
    
    return field.value.length < len;
}

function fieldsDifferent(field1, field2) {
    if(field1 == null || field2 == null) {
        return false;
    }
    var string1 = field1.value;
    var string2 = field2.value;
    
    if(string1.length != string2.length) {
        return true;
    }
        
    for(i = 0; i < string1.length; ++i) {
       if(string1.charAt(i) != string2.charAt(i) ) {
           return true;
       }
    }
    return false;
}


function numberNotBetween(field, lower, upper) {
    if(field == null) {
        return false;
    }
    
    var number = parseFloat(field.value);
    if(isNaN(number)) {
        return true;
    }
    
    if(number < lower || number > upper) {
        return true;
    }
    else {
        return false;
    }
    
}
function isInteger(fvalue, minVal, maxVal) {
	if (fvalue == null || fvalue.length < 1) {
		return false;
	}
	//does it only contain numbers?
    var ok = "1234567890";
    for(i = 0; i < fvalue.length; ++i){
        if(ok.indexOf(fvalue.charAt(i)) < 0){ 
            return false;
        }
    }
	//check bounds
	if (minVal != null && maxVal != null) {
		intvalue = parseInt(fvalue);
		if (intvalue < minVal || intvalue > maxVal) {
			return false;
		}
	}
	return true;
}

function showAlert(message, field, color) {
    alert(message);
    // if the browser is Netscape 6 or IE (i.e. supports DOM)    
    if(document.all || document.getElementById) {
        field.style.background = color;
    }
    field.focus(); // put the prompt in the field
}

function showAlert2(message, field1, field2, color) {
    alert(message);
    // if the browser is Netscape 6 or IE (i.e. supports DOM)    
    if(document.all || document.getElementById) {
        field1.style.background = color;
        field2.style.background = color;
    }
    field1.focus();
}

function removeChars(str, rchr) {
  rstr = "";
  for(var i=0;i<str.length;i++) {
     chr=str.substring( i, i+1 );
     if( chr != rchr ) { rstr += chr; }
  }
  return rstr;
}
function optionalInvalidEmail(field) {
    if(field == null || field.value == null || field.value == "") {
        return false;
    }
    return invalidEmail(field);
}

function invalidEmail(field) {
    if(field == null) {
        return false;
    }
    
    var e = field.value;
        //first trim the email
    e = e.replace(/^\s+/,'').replace(/\s+$/,'');
    
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(2([0-4]\d|5[0-5])|1?\d{1,2})(\.(2([0-4]\d|5[0-5])|1?\d{1,2})){3} \])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
	
    return !re.test(e);
}

