

function showDisclaimer(id) {
	var disclaimer = document.getElementById('disclaimer_' + id);
	var disc_bg    = document.getElementById('disclaimer_bg');
	
	var scrollXY   = getScrollXY();
	var viewport   = getSize();
	
	if(disclaimer.style.display == 'none') {
		disclaimer.style.display = 'block';
		disclaimer.style.top = scrollXY[1] + viewport[1] / 2 + "px";
		disc_bg.style.display = 'block';
		disc_bg.style.height = getDocHeight() + "px";
	} else {
		disclaimer.style.display = 'none';
		disc_bg.style.display = 'none';
	}
}

function getDocHeight() {
	var D = document;
	return Math.max(
		Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
		Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
		Math.max(D.body.clientHeight, D.documentElement.clientHeight)
	);
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function getSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [ myWidth, myHeight ];
}

/**********************************************************
 *** FORM VALIDATION FUNCTION: validateForm()           ***
 *** -------------------------------------------------- ***
 *** Calls individual validations for form fields.      ***
 **********************************************************/
function validateForm() {
  // Set object variables for the form fields
  var fm_fname   = document.getElementById('INDIVIDUALCONTROL_fname');
  var fm_lname   = document.getElementById('INDIVIDUALCONTROL_lname');
  var fm_email   = document.getElementById('INDIVIDUALCONTROL_email');
  var fm_agree   = document.forms[0].agree;
  
	var error_msg = "The following errors occured:\n\n";
	var errors    = false;
	
  // Call "Required" validation for First Name field
  if(typeof(fm_fname) != "undefined" && fm_fname != null) {
		if(validateRequired(fm_fname) == false) {
			error_msg += " - First Name is a required field.\n";
			errors = true;

		// Call "Text Only" validation for Name field
		} else if(validateTextOnly(fm_fname) == false) {
			error_msg += " - First Name may only contain the letters A through Z.\n";
			errors = true;
		}
	}

  // Call "Required" validation for Last Name field
  if(typeof(fm_lname) != "undefined" && fm_lname != null) {
		if(validateRequired(fm_lname) == false) {
			error_msg += " - Last Name is a required field.\n";
			errors = true;

		// Call "Text Only" validation for Name field
		} else if(validateTextOnly(fm_lname) == false) {
			error_msg += " - Last Name may only contain the letters A through Z.\n";
			errors = true;
		}
	}

  // Call "Required" validation for Email field
  if(typeof(fm_email) != "undefined" && fm_email != null) {
		if(validateRequired(fm_email) == false) {
			error_msg += " - Email Address is a required field.\n";
			errors = true;

		// Call "Email" validation for Email field
		} else if(validateEmail(fm_email) == false) {
			error_msg += " - Email Address is not formatted correctly.\n";
			errors = true;
		}
	}

  // Call "Required" validation for Agree field
  if(typeof(fm_agree) != "undefined" && fm_agree != null) {
		if(fm_agree.checked == false) {
			error_msg += " - You must agree to the terms to opt in.\n";
			errors = true;
		}
	}
  
  // If there are errors, display them
  if(errors) {
  	alert(error_msg);
  	return false;
	
	// Otherwise, return true...
  } else {
	  return true;
	}

} // End: validateForm()

/**********************************************************
 *** FORM VALIDATION FUNCTION: validateRequired()       ***
 *** -------------------------------------------------- ***
 *** Checks for empty input fields.                     ***
 **********************************************************/
function validateRequired(field) {
  if (field.value == null || field.value == "") {
    return false;
   } else {
    return true;
  }
}

/**********************************************************
 *** FORM VALIDATION FUNCTION: validateTextOnly()       ***
 *** -------------------------------------------------- ***
 *** Checks for non Alpha characters (allows spaces).   ***
 **********************************************************/
function validateTextOnly(field) {
  if(field.value.search(/[^a-zA-Z\s-]/) == -1) {
    return true;
  } else {
    return false;
  }
}

/**********************************************************
 *** FORM VALIDATION FUNCTION: validateEmail()          ***
 *** -------------------------------------------------- ***
 *** Checks for properly forms email addresses x@y.c.   ***
 **********************************************************/
function validateEmail(field) {
  var apos   = field.value.indexOf("@");
  var dotpos = field.value.lastIndexOf(".");
  if (apos < 1 || dotpos - apos < 2) {
    return false;
  } else {
    return true;
  }
}

/**********************************************************
 *** FORM VALIDATION FUNCTION: validateEmail2()         ***
 *** -------------------------------------------------- ***
 *** Checks for properly forms email addresses x@y.c.   ***
 **********************************************************/
function validateEmail2() {
  var fm_email   = document.getElementById('INDIVIDUALCONTROL_email');

	if(fm_email.value == null || fm_email.value == "") {
		alert("The following errors have occurred:\n\n - You must enter a valid email address\n");
		return false;
	}

  var apos   = fm_email.value.indexOf("@");
  var dotpos = fm_email.value.lastIndexOf(".");
  if (apos < 1 || dotpos - apos < 2) {
  	alert("The following errors have occurred:\n\n - You must enter a valid email address\n");
    return false;
  } else {
    return true;
  }
}
