<!--
/* Email Validation written by PerlScriptsJavaScripts.com 
 * All other functions by TypingMaster, Inc.
 * Author: Tuomas Tanner
 * all functions return false if a null field is given
 */


function invalidEmail(field) {
    if(field == null) {
        return false;
    }
    
    var e = field.value;
        //first trim the email
    e = e.replace(/^\s+/,'').replace(/\s+$/,'');
    
    var ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

    for(i=0; i < e.length; ++i){
        if(ok.indexOf(e.charAt(i))<0){ 
            return true;
        }
    } 

    if (document.images) {
        re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
        re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
        
        if (!e.match(re) && e.match(re_two)) {
            return false;
        }
    }
    
    return true;
}

function optionalInvalidEmail(field) {
    if(field == null || field.value == null || field.value == "") {
        return false;
    }
    
    return invalidEmail(field);
}


function fieldIsEmpty(field) {
    if(field == null) {
        return false;
    }
    
    return field.value.length < 1;
}

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;
}

-->
