DD_roundies.addRule('.Information', '10px', true);
DD_roundies.addRule('.button, .button_disabled, .button_warning', '5px', true);
DD_roundies.addRule('.panel', '10px', true);
DD_roundies.addRule('.message', '10px', true);
DD_roundies.addRule('.resources', '10px', true);

// Default Value
$(document).ready(function() {
    $('.default-value').each(function() {
        var default_value = this.value;
        $(this).focus(function() {
            if (this.value == default_value) {
                this.value = '';
            }
        });
        $(this).blur(function() {
            if (this.value == '') {
                this.value = default_value;
            }
        });
    });
});

// Suckerfish JavaScript
sfHover = function () {
    if (document.getElementById("MainMenu")) {
        var sfEls = document.getElementById("MainMenu").getElementsByTagName("LI");
        for (var i = 0; i < sfEls.length; i++) {
            sfEls[i].onmouseover = function () {
                this.className += " sfhover";
            }
            sfEls[i].onmouseout = function () {
                this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
            }
        }
    }
}

function trim(str) {
	str = str.replace(/^\s+/, '');
	for (var i = str.length - 1; i >= 0; i--) {
		if (/\S/.test(str.charAt(i))) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;
}

function confirm_delete () {
	if (confirm("Are you SURE you want to delete this record?"))
		return true;
	else
		return false;
}

function confirm_reset() {
	return confirm('Are you SURE you wish to discard your changes?');
}

var intSubmitCount = 0;
function prevent_double_submit(btnClicked) {
    intSubmitCount++;
    if (intSubmitCount == 1) {
        return true;
    }
    return false;
}

function allow_numbers_only(ctrl) {
    var txtEntry = ctrl.value;
    if (txtEntry.length < 1) {
        return;
    }
    var strMostRecentCharacter = txtEntry.substring(txtEntry.length - 1, txtEntry.length);
    if (is_numeric(strMostRecentCharacter) == false) {
        txtEntry = txtEntry.substring(0, txtEntry.length - 1);
        ctrl.value = txtEntry;
        return;
    }
}

function is_numeric(input) {
    var valid_chars = "0123456789";
    var is_number = true;
    var char;

    for (i = 0; i < input.length && is_number == true; i++) {
        char = input.charAt(i);
        if (valid_chars.indexOf(char) == -1) {
            is_number = false;
        }
    }
    return is_number;
}

var time_field_length = 0;
function tab_next(obj, event, len, next_field) {
    if (event == "down") {
        time_field_length = obj.value.length;
    }
    else if (event == "up") {
        if (obj.value.length != time_field_length) {
            time_field_length = obj.value.length;
            if (time_field_length == len) {
                next_field.focus();
            }
        }
    }
}

function check_on_check(chkbox1, chkbox2) {
    if (chkbox1.checked == true) {
        chkbox2.checked = true;
    }
}
function uncheck_on_check(sender, chkbox2) {
    if (chkbox1.checked == true) {
        chkbox2.checked = false;
    }
}
function uncheck(chkbox) {
    chkbox.checked = false;
}
function check(chkbox) {
    chkbox.checked = true;
}
function check_on_change(ddl, chkbox) {
    chkbox.checked = true;
}

function toggle_more_less(a) {
    if (a.innerHTML.indexOf('More') != -1)
        a.innerHTML = '&laquo; Read Less'
    else
        a.innerHTML = 'Read More &raquo;'
}

function toggle_display(ctrl) {
    if (ctrl.style.display == 'inline')
        ctrl.style.display = 'none';
    else
        ctrl.style.display = 'inline';
}

// |||||||||||||||||||||||||||||||||||||||||||||||||||||
//
// Coded by Travis Beckham
// http://www.squidfingers.com | http://www.podlob.com
// If want to use this code, feel free to do so, but
// please leave this message intact.
//
// |||||||||||||||||||||||||||||||||||||||||||||||||||||
// --- version date: 11/21/02 --------------------------

// returns true if the string is empty
function trimNumber(s) {
  while (s.substr(0,1) == '0' && s.length>1) { s = s.substr(1,9999); }
  return s;
}
function isEmpty(str){
  return (str == null) || (trim(str).length == 0);
}
// returns true if the string is a valid email
function isEmail(str){
  if(isEmpty(str)) return false;
  var re = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i
  return re.test(str);
}
// returns true if the string only contains characters A-Z or a-z
function isAlpha(str){
  var re = /[^a-zA-Z]/g
  if (re.test(str)) return false;
  return true;
}
// returns true if the string only contains characters 0-9
function isNumeric(str){
  var re = /[\D]/g
  if (re.test(str)) return false;
  return true;
}
// returns true if the string only contains characters A-Z, a-z or 0-9
function isAlphaNumeric(str){
  var re = /[^a-zA-Z0-9]/g
  if (re.test(str)) return false;
  return true;
}
// returns true if the string's length equals "len"
function isLength(str, len){
  return str.length == len;
}
// returns true if the string's length is between "min" and "max"
function isLengthBetween(str, min, max){
  return (str.length >= min)&&(str.length <= max);
}
// returns true if the string is a US phone number formatted as...
// (000)000-0000, (000) 000-0000, 000-000-0000, 000.000.0000, 000 000 0000, 0000000000
function isPhoneNumber(str){
  var re = /^\(?[2-9]\d{2}[\)\.-]?\s?\d{3}[\s\.-]?\d{4}$/
  return re.test(str);
}
// returns true if the string is a valid date formatted as...
// mm dd yyyy, mm/dd/yyyy, mm.dd.yyyy, mm-dd-yyyy
function isDate(str){
  var re = /^(\d{1,2})[\s\.\/-](\d{1,2})[\s\.\/-](\d{4})$/
  if (!re.test(str)) return false;
  var result = str.match(re);
  if (result[1])
  var m = parseInt(trimNumber(result[1]));
  var d = parseInt(trimNumber(result[2]));
  var y = parseInt(result[3]);
  if(m < 1 || m > 12 || y < 1900 || y > 2100) return false;
  if(m == 2){
          var days = ((y % 4) == 0) ? 29 : 28;
  }else if(m == 4 || m == 6 || m == 9 || m == 11){
          var days = 30;
  }else{
          var days = 31;
  }
  return (d >= 1 && d <= days);
}
// returns true if "str1" is the same as the "str2"
function isMatch(str1, str2){
  return str1 == str2;
}
// returns true if the string contains only whitespace
// cannot check a password type input for whitespace
function isWhitespace(str){ // NOT USED IN FORM VALIDATION
  var re = /[\S]/g
  if (re.test(str)) return false;
  return true;
}
// removes any whitespace from the string and returns the result
// the value of "replacement" will be used to replace the whitespace (optional)
function stripWhitespace(str, replacement){// NOT USED IN FORM VALIDATION
  if (replacement == null) replacement = '';
  var result = str;
  var re = /\s/g
  if(str.search(re) != -1){
    result = str.replace(re, replacement);
  }
  return result;
}
function alert_format(str){
  	var result = str;
	do {
    	result = result.replace("_", " ");
	} while (result.search("_") != -1);
	do {
    	result = result.replace("'", "/'");
	} while (result.search("'") != -1);
	return result;
}

// validate the form
function validateForm(f, preCheck, defaultOK){
  var errors = '';
  if(preCheck != null) errors += preCheck;
  var i,e,t,n,v;
  for(i=0; i < f.elements.length; i++){
    e = f.elements[i];
    if(e.optional && e.value == '') {
		continue;
	}
    t = e.type;
    n = e.name;
    v = e.value;
    if(t == 'text' || t == 'password' || t == 'textarea'){
      if(isEmpty(v)){
        errors += alert_format(n)+' is required.\n'; continue;
      }
      if(v == e.defaultValue && ! ( defaultOK || e.defaultOK)){
        errors += alert_format(n)+' cannot use the default value.\n'; continue;
      }
      if(e.isAlpha){
        if(!isAlpha(v)){
          errors += alert_format(n)+' can only contain characters A-Z a-z.\n'; continue;
        }
      }
      if(e.isNumeric){
        if(!isNumeric(v)){
          errors += alert_format(n)+' can only contain characters 0-9.\n'; continue;
        }
      }
      if(e.isAlphaNumeric){
        if(!isAlphaNumeric(v)){
          errors += alert_format(n)+' can only contain characters A-Z a-z 0-9.\n'; continue;
        }
      }
      if(e.isEmail){
        if(!isEmail(v)){
          errors += alert_format(v)+' is not a valid email.\n'; continue;
        }
      }
      if(e.isLength != null){
        var len = e.isLength;
        if(!isLength(v,len)){
          errors += alert_format(n)+' must contain only '+len+' characters.\n'; continue;
        }
      }
      if(e.isLengthBetween != null){
        var min = e.isLengthBetween[0];
        var max = e.isLengthBetween[1];
        if(!e.optional && !isLengthBetween(v,min,max)){
          errors += alert_format(n)+' cannot contain less than '+min+' or more than '+max+' characters.\n'; continue;
        }
      }
      if(e.isPhoneNumber){
        if(!isPhoneNumber(v)){
          errors += alert_format(v)+' is not a valid US phone number.\n'; continue;
        }
      }
      if(e.isDate){
        if(!isDate(v)){
          errors += alert_format(v)+' is not a valid date.\n'; continue;
        }
      }
      if(e.isMatch != null){
        if(!isMatch(v, e.isMatch)){
          errors += alert_format(n)+' does not match.\n'; continue;
        }
      }
    }
    if(t.indexOf('select') != -1){
      if(isEmpty(e.options[e.selectedIndex].value)){
        errors += alert_format(n)+' is required.\n'; continue;
      }
    }
    if(t == 'file'){
      if(isEmpty(v)){
        errors += alert_format(n)+' needs a file to upload.\n'; continue;
      }
    }
  }
  if(errors != '') alert("Please correct the following:\n\n" + errors);
  return errors == '';
}

/*
The following elements are not validated...

button   type="button"
checkbox type="checkbox"
hidden   type="hidden"
radio    type="radio"
reset    type="reset"
submit   type="submit"

All elements are assumed required and will only be validated for an
empty value or defaultValue unless specified by the following properties.

isEmail = true;          // valid email address
isAlpha = true;          // A-Z a-z characters only
isNumeric = true;        // 0-9 characters only
isAlphaNumeric = true;   // A-Z a-z 0-9 characters only
isLength = number;       // must be exact length
isLengthBetween = array; // [lowNumber, highNumber] must be between lowNumber and highNumber
isPhoneNumber = true;    // valid US phone number. See "isPhoneNumber()" comments for the formatting rules
isDate = true;           // valid date. See "isDate()" comments for the formatting rules
isMatch = string;        // must match string
optional = true;         // element will not be validated
*/


