// JavaScript Document

// for form expansion/contraction 
function HidePart(d) { document.getElementById(d).style.display = "none";  }
function ShowPart(d) { document.getElementById(d).style.display = "block"; }
function CheckboxChecked(b,d)  {
   if(b) { ShowPart(d); }
   else  { HidePart(d); }
}

// script to validate email address, user name and password 
function FormValidatorQuick(theForm){
  if (theForm.Email_Default.value.length < 8){
    alert("Please enter a valid email address in the \"E-Mail\" field.");
    theForm.Email_Default.focus(); 
    return false;}
  var j = 0; var k = 0;
  for (var i = 0; i <= theForm.Email_Default.value.length; i++){
    if (theForm.Email_default.value.charAt(i) == "\@" && i > 0){
      j += 1;
      if (k > 0){j = 0;}
      k = i + 1;
      if (theForm.Email_Default.value.charAt(k) != "\."){j += 1;}} // end if
    if (theForm.Email_Default.value.charAt(i) == "\." && i > 3){
      j += 1;
      h = i + 3;
      if (h > theForm.Email_Default.value.length){j = 0;}}} // end if and for loop	
  if (j < 3){
    alert("The email you have entered is not valid.");
    theForm.Email_Default.focus();
    return false;}
  if (theForm.User_Name.value.length < 3) {
    alert("Please enter at least 3 characters in the \"User Name\" field.");
    theForm.username.focus();
    return false;}
  if (theForm.Password1.value != theForm.Password2.value){
    alert("Your Passwords did not match.");
    theForm.Password1.focus(); 
    return false;}
return true;}

// script to validate email address and question when submitting a question or ensures valid question ID number 
function FormValidator(theForm){if (theForm.email.value.length < 8){ alert("Please enter a valid email address in the \"Email\" field."); theForm.email.focus(); return false;}
	var j = 0; var k = 0;
	for (var i = 0; i <= theForm.email.value.length; i++){
		if (theForm.email.value.charAt(i) == "\@" && i > 0){ j += 1;
			if (k > 0){j = 0;}
			k = i + 1;
			if (theForm.email.value.charAt(k) != "\."){j += 1;}}
		if (theForm.email.value.charAt(i) == "\." && i > 3){j += 1;	h = i + 3;
			if (h > theForm.email.value.length){j = 0;}}}	
	if (j < 3){alert("The email you have entered is not valid."); theForm.email.focus(); return false;}
if (theForm.name.value.length < 1) {
    alert("Please enter a valid name for the event in the \"Event Name\" field."); theForm.name.focus();
    return false;} return true;}	

// script to validate user name 
function FormValidatorUserName(theForm){if (theForm.Current_User_Name.value.length < 3) {
    alert("Please enter at least 3 characters in the \"Current User Name\" field."); theForm.username.focus();
    return false;}
if (theForm.User_Name.value.length < 3) {
    alert("Please enter at least 3 characters in the \"New User Name\" field."); theForm.username.focus();
    return false;}
 return true;}
 
// script to validate user name when resetting password
function FormValidatorReset(theForm){if (theForm.User_Name.value.length < 3) {alert("Please enter at least 3 characters in the \"User Name\" field."); theForm.username.focus();
    return false;}
 return true;}

// script to validate user name when submitting log in information 
function FormValidatorLogIn(theForm){if (theForm.username.value.length < 1){ alert("Please enter a valid user name in the \"User Name\" field."); theForm.username.focus(); return false;} return true;}

// Checks to see if proper email address is used for answer rating
function FormValidatorRate(theForm)
{
  if (theForm.email.value.length < 8)
  {
    alert("Please enter a valid email address in the \"E-Mail\" field.");
    theForm.email.focus();
    return (false);
  }
  var j = 0;
  var k = 0;
  for (var i = 0; i <= theForm.email.value.length; i++){
		if (theForm.email.value.charAt(i) == "\@" && i > 0){
			j += 1;
			if (k > 0){
				j = 0;
				}
			k = i + 1;
			if (theForm.email.value.charAt(k) != "\."){
				j += 1;
				}
			}
		if (theForm.email.value.charAt(i) == "\." && i > 3){
			j += 1;
			h = i + 3;
			if (h > theForm.email.value.length){
				j = 0;
				}
			}
		}	
	if (j < 3){
		alert("The email you have enterd is not valid.");
		theForm.email.focus();
    	return false;
		}
	if (theForm.comments.value.length < 2){
		alert("Please provide us some feedback in the \"Comments\" box.");
		theForm.comments.focus();
		return (false);
		}
	var g=0;
	for (var i=0; i < 10; i++){
		if (theForm.rating[i].checked){
			g=1;
			}
		}
	if (g==0){
		alert("Please rate the answer using the radio buttons in the blue boxes");
			return (false);
		}
  return (true);}

// ensures a rating is added
function checkRadio(){
	var j=0;
	for (var i=0; i < 10; i++){
		if (thisForm.rating[i].checked){j=1;}}
	if (j==0){alert("Please rate the site using the radio buttons in the blue boxes"); return false;}
	if (theForm.email.value.length < 8){ alert("Please enter a valid email address in the \"E-Mail\" field."); theForm.email.focus(); return false;}
	var j = 0; var k = 0;
	for (var i = 0; i <= theForm.email.value.length; i++){
		if (theForm.email.value.charAt(i) == "\@" && i > 0){ j += 1;
			if (k > 0){j = 0;}
			k = i + 1;
			if (theForm.email.value.charAt(k) != "\."){j += 1;}}
		if (theForm.email.value.charAt(i) == "\." && i > 3){j += 1;	h = i + 3;
			if (h > theForm.email.value.length){j = 0;}}}	
	if (j < 3){alert("The email you have entered is not valid."); theForm.email.focus(); return false;}
		return true;}
		
		
// Javascript to ensure break time isn't greater than total time calculated for question 
function  checkFormTime(_CF_this){
	while(_CF_this.minutes.length < _CF_this.totalTime.length){
		_CF_this.minutes.value = "0" + _CF_this.minutes.value
		}
    if  (_CF_this.totalTime.value < _CF_this.minutes.value){
        alert('you have asked to subtract more minutes than you worked.  Please check your math')
        return false;    
        }
	return true;
	}

// open link in new browser javascript 
function MM_openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}

// directory home specific javascript
function oWin(theURL,winName,features) {window.open(theURL,winName,features);}



// Section to expand directory to a specific category 
function catTreeNodeSelection(catID){
   tree = ColdFusion.Tree.getTreeObject("Web_Directory_Tree");
   me = tree.getNodeByProperty('id',catID);
   me.parent.expand();
   me.tree.fireEvent("labelClick", me);
}

// Ensure break time isn't greater than total time calculated for question
function  checkFormEmployeeTime(_CF_this){
	while(_CF_this.minutes.length < _CF_this.totalTime.length){
		_CF_this.minutes.value = "0" + _CF_this.minutes.value
		}
    if  (_CF_this.totalTime.value < _CF_this.minutes.value){
        alert('you have asked to subtract more minutes than you worked.  Please check your math')
        return false;    
        }
	return true;}
	
// Section to test expanding directory to a specific category 
function catTreeNodeSelection(catID){
   tree = ColdFusion.Tree.getTreeObject("Web_Directory_Tree");
   me = tree.getNodeByProperty('id',catID);
   var i=1;
   var nodedepth = me.depth - 1;
   if (nodedepth < 0)
    {me.expand();}
   else if (nodedepth > 0)
     {for (i=nodedepth;i>=1;i--)
      {var meparent = me.getAncestor(i);
       meparent.expand();};
     meparent.parent.expand();}
   else 
     {me.parent.expand();
	 me.expand();};
   me.tree.fireEvent("labelClick", me);}
   
// script to get fitness chart to display in cflayoutarea 
function CF_RunContent(theDiv,src){
setTimeout(function(){document.getElementById(theDiv).innerHTML = src;},5);
}

// Script to confirm selection to delete item 
function GP_popupConfirmMsg(msg) {
  document.MM_returnValue = confirm(msg);
}

// script to validate email address, web site and description for gift list
function FormValidatorGiftList(theForm){if (theForm.email.value.length < 8){ alert("Please enter a valid email address in the \"Email\" field."); theForm.email.focus(); return false;}
	var j = 0; var k = 0;
	for (var i = 0; i <= theForm.email.value.length; i++){
		if (theForm.email.value.charAt(i) == "\@" && i > 0){ j += 1;
			if (k > 0){j = 0;}
			k = i + 1;
			if (theForm.email.value.charAt(k) != "\."){j += 1;}}
		if (theForm.email.value.charAt(i) == "\." && i > 3){j += 1;	h = i + 3;
			if (h > theForm.email.value.length){j = 0;}}}	
	if (j < 3){alert("The email you have entered is not valid."); theForm.email.focus(); return false;}
		if (theForm.description.value.length < 3) {
    alert("Please enter some sort of gift description in the \"Description of Item\" field."); theForm.description.focus();
    return false;} return true;}

// script to validate link submission data
function FormValidatorLinkSubmission(theForm){if (theForm.email.value.length < 8){ alert("Please enter a valid email address in the \"E-Mail\" field."); theForm.email.focus(); return false;}
	var j = 0; var k = 0;
	for (var i = 0; i <= theForm.email.value.length; i++){
		if (theForm.email.value.charAt(i) == "\@" && i > 0){ j += 1;
			if (k > 0){j = 0;}
			k = i + 1;
			if (theForm.email.value.charAt(k) != "\."){j += 1;}}
		if (theForm.email.value.charAt(i) == "\." && i > 3){j += 1;	h = i + 3;
			if (h > theForm.email.value.length){j = 0;}}}	
	if (j < 3){alert("The email you have entered is not valid."); theForm.email.focus(); return false;}
	if (theForm.hyperlink.value.length < 16) {
    alert("Please enter a valid web site address including the HTTP:// in the \"Web Site Address\" field."); theForm.hyperlink.focus();
    return false;}
		if (theForm.title.value.length < 3) {
    alert("Please enter a valid web site title in the \"Web Site Title\" field."); theForm.title.focus();
    return false;}
		if (theForm.title.value.indexOf("http://") != -1) {
    alert("Please do not enter a URL in the \"Web Site Title\" field."); theForm.title.focus();
    return false;}	
		if (theForm.title.value.indexOf("www.") != -1) {
    alert("Please do not enter a web site address in the \"Web Site Title\" field."); theForm.title.focus();
    return false;}
		if (theForm.description.value.length < 5) {
    alert("Please enter a web site description in the \"Web Site Description\" field."); theForm.description.focus();
    return false;} 
		if (theForm.description.value.indexOf("http://") != -1) {
    alert("Please do not enter a URL in the \"Web Site Description\" field."); theForm.description.focus();
    return false;}	
		if (theForm.description.value.indexOf("www.") != -1) {
    alert("Please do not enter a web site address in the \"Web Site Description\" field."); theForm.description.focus();
    return false;}
		if (theForm.Country.value.indexOf("http://") != -1) {
    alert("Please do not enter a URL in the \"Web Site Country\" field."); theForm.Country.focus();
    return false;}	
		if (theForm.Country.value.indexOf("www.") != -1) {
    alert("Please do not enter a web site address in the \"Web Site Country\" field."); theForm.Country.focus();
    return false;}	
		if (theForm.City.value.indexOf("http://") != -1) {
    alert("Please do not enter a URL in the \"Web Site City\" field."); theForm.City.focus();
    return false;}	
		if (theForm.City.value.indexOf("www.") != -1) {
    alert("Please do not enter a web site address in the \"Web Site City\" field."); theForm.City.focus();
    return false;}		
		if (theForm.Postal_Code.value.indexOf("http://") != -1) {
    alert("Please do not enter a URL in the \"Web Site Postal Code\" field."); theForm.Postal_Code.focus();
    return false;}	
		if (theForm.Postal_Code.value.indexOf("www.") != -1) {
    alert("Please do not enter a web site address in the \"Web Site Postal Code\" field."); theForm.Postal_Code.focus();
    return false;}	return true;}
// script to hide images that do not load	
	function Image_OnError(image) { 
    image.onerror = ""; 
    image.style.visibility = "hidden"; 
    return true; 
} 

