function validate_login(){
   if ( document.login_form.email.value == '' ){
      alert('Please provide your email address to login.');
      document.login_form.email.focus();
      return;
   }
   else{
      var amp_index = document.login_form.email.value.indexOf("@",1);
      var per_index = document.login_form.email.value.indexOf(".", amp_index) ;

      if ( amp_index == -1 || per_index == -1 ){
         alert('Please provide a proper email address to login.');
         document.login_form.email.focus();
         return;
      }
   }
   
   if ( document.login_form.password.value == '' ){
      alert('Please provide your member password to login.');
      document.login_form.password.focus();
      return;
   }
   
   document.login_form.submit();
}

function validate_forgot(){
   if ( document.login_form.email.value == '' ){
      alert('Please provide your EMAIL address and then click the "Forgot Password" button to initiate the forgot password process.');
      document.login_form.email.focus();
      return;
   }
   else{
      var amp_index = document.login_form.email.value.indexOf("@",1);
      var per_index = document.login_form.email.value.indexOf(".", amp_index) ;

      if ( amp_index == -1 || per_index == -1 ){
         alert('Please provide a proper EMAIL address and then click the "Forgot Password" button to initiate the forgot password process.');
         document.login_form.email.focus();
         return;
      }
   }

   document.login_form.action = 'forgot_password.php';
   document.login_form.submit();
}

function validate_password(){
   if ( document.password_form.opwd.value == '' ){
      alert('Please provide your old password.');
      document.password_form.opwd.focus();
      return;
   }

   if ( document.password_form.npwd.value == '' ){
      alert('Please provide your new password.');
      document.password_form.npwd.focus();
      return;
   }

   if ( document.password_form.cpwd.value == '' ){
      alert('Please confirm your new password.');
      document.password_form.cpwd.focus();
      return;
   }

   if ( document.password_form.npwd.value != document.password_form.cpwd.value ){
      alert('Your confirmation password does not match the new password you provided.');
      document.password_form.cpwd.focus();
      return;
   }
   
   if ( document.password_form.npwd.value == document.password_form.opwd.value ){
      alert('Your new password matches your old password. No update required unless the new password is different.');
	  document.password_form.cpwd.value = '';
	  document.password_form.npwd.value = '';
      document.password_form.npwd.focus();
      return;
   }

   document.password_form.submit();
}

function validate_signup(){
	if ( document.signup_form.email.value == "" ){
		alert('Please provide an EMAIL address to register.');
		document.signup_form.email.focus();
		return;
	}
	else{
		var amp_index = document.signup_form.email.value.indexOf("@",1);
		var per_index = document.signup_form.email.value.indexOf(".", amp_index) ;
	
		if ( amp_index == -1 || per_index == -1 ){
			alert('Please provide a proper EMAIL address to register.');
			document.signup_form.email.focus();
			return;
		}
	}

	if ( document.signup_form.cemail.value == "" ){
		alert('Please provide a CONFIRMATION EMAIL address to register.');
		document.signup_form.cemail.focus();
		return;
	}
	else{
		if ( document.signup_form.email.value != document.signup_form.cemail.value ){
			alert('The CONFIRM EMAIL address does not match the EMAIL address provided. Please correct to register.');
			document.signup_form.cemail.focus();
			return;
		}
	}

	if ( document.signup_form.password.value == "" ){
		alert('You must provide a password to protect your account.');
		document.signup_form.password.focus();
		return;
	}

	if ( document.signup_form.cpassword.value == "" ){
		alert('You must provide a confirmation password ensure your password is correct.');
		document.signup_form.cpassword.focus();
		return;
	}
	else{
		if ( document.signup_form.password.value != document.signup_form.cpassword.value ){
			alert('Your confirmation password does not match the password you provided.');
			document.signup_form.password.focus();
			return;
		}
	}

	if ( document.signup_form.user_name.value == "" ){
		alert('You must provide your USER NAME to register.');
		document.signup_form.user_name.focus();
		return;
	}

	document.signup_form.submit();
}

function validate_admin_user(){
   if ( document.user_form.email.value == "" ){
      alert('Please provide an EMAIL address for this account.');
      document.user_form.email.focus();
      return;
   }
   else{
      var amp_index = document.user_form.email.value.indexOf("@",1);
      var per_index = document.user_form.email.value.indexOf(".", amp_index) ;

      if ( amp_index == -1 || per_index == -1 ){
         alert('Please provide a proper email address to update this account.');
         document.user_form.email.focus();
         return;
      }
   }

   if ( document.user_form.name.value == "" ){
      alert('You must provide the User Name for this account.');
      document.user_form.name.focus();
      return;
   }

   document.user_form.submit();
}

function validate_admin_user_update(){
   if ( document.user_update_form.email.value == "" ){
      alert('Please provide an email address to update this account.');
      document.user_update_form.email.focus();
      return;
   }
   else{
      var amp_index = document.user_update_form.email.value.indexOf("@",1);
      var per_index = document.user_update_form.email.value.indexOf(".", amp_index) ;

      if ( amp_index == -1 || per_index == -1 ){
         alert('Please provide a proper email address to update this account.');
         document.user_update_form.email.focus();
         return;
      }
   }

   if ( document.user_update_form.first_name.value == "" ){
      alert('You must provide your First Name to update this account.');
      document.user_update_form.first_name.focus();
      return;
   }

   if ( document.user_update_form.last_name.value == "" ){
      alert('You must provide your Last Name to update this account.');
      document.user_update_form.last_name.focus();
      return;
   }

   document.user_update_form.submit();
}

function validate_profile(){
   if ( document.profile_form.email.value == "" ){
      alert('Please provide an EMAIL address to update this account.');
      document.profile_form.email.focus();
      return;
   }
   else{
      var amp_index = document.profile_form.email.value.indexOf("@",1);
      var per_index = document.profile_form.email.value.indexOf(".", amp_index) ;

      if ( amp_index == -1 || per_index == -1 ){
         alert('Please provide a proper EMAIL address to update this account.');
         document.profile_form.email.focus();
         return;
      }
   }

   if ( document.profile_form.user_name.value == "" ){
      alert('You must provide your USER NAME to update this account.');
      document.profile_form.user_name.focus();
      return;
   }

   document.profile_form.submit();
}

function swap_image( imgid, divid ){
   var img = document.getElementById( imgid );
   if ( img.src.indexOf("expand.gif") != -1 ){
      img.src = "/images/contract.gif";
   }
   else{
      img.src = "/images/expand.gif";
   }
 
   display_div( divid );
}

 
function display_div( divid ){
   var div = document.getElementById( divid );
   if ( div.style.display == "none" ){
      div.style.display = '';
   }
   else{
      div.style.display = 'none';
   }
}

function check_count( text_area_name, span_name, max_size ){
	var textarea = document.getElementById( text_area_name );
	var span = document.getElementById( span_name );
	var count = textarea.value.length;
   
	if ( (max_size - count) <= 0 ){
		span.innerText = 0;
		textarea.value = textarea.value.substring(0, max_size-1);
		alert('You are at or have exceeded the limit of this field.');
		textarea.focus();
	}	
	else{
		span.innerText = max_size-count;
	}

	return;
}

function validate_message(){
	if ( document.message_form.message.value == '' || document.message_form.message.value.length == 0 ){
		alert('Please enter your MESSAGE prior to submitting.');
		document.message_form.message.focus();
		return;
	}
	
	if ( document.message_form.message.value.indexOf('<') != -1 && document.message_form.message.value.indexOf('>') != -1 ){
		alert('Markup Language has been detected in your message. Please this removed prior to your submission.');
		document.message_form.message.focus();
		return;
	}
	
	if ( document.message_form.name.value == '' || document.message_form.name.value.length == 0 ){
		alert('Please enter your display NAME prior to submitting.');
		document.message_form.name.focus();
		return;
	}

	if ( document.message_form.email.value != "" ){
		var amp_index = document.message_form.email.value.indexOf("@",1);
		var per_index = document.message_form.email.value.indexOf(".", amp_index) ;

		if ( amp_index == -1 || per_index == -1 ){
			alert('Please provide a proper EMAIL address to register.');
			document.message_form.email.focus();
			return;
		}
	}
	
	if ( document.getElementById("verify") != null ){
		if ( document.message_form.verify.value == '' ){
			alert('Please enter the Verification code prior to submitting.');
			document.message_form.verify.focus();
			return;
		}
	}
	
	document.message_form.submit();	
}

function validate_comment(){
	if ( document.comment_form.comment.value == '' || document.comment_form.comment.value.length == 0 ){
		alert('Please enter your COMMENT prior to submitting.');
		document.comment_form.comment.focus();
		return;
	}
	
	if ( document.comment_form.comment.value.indexOf('<') != -1 && document.comment_form.comment.value.indexOf('>') != -1 ){
		alert('Markup Language has been detected in your comment. Please have this removed prior to your submission.');
		document.message_form.message.focus();
		return;
	}
	
	if ( document.getElementById("c_vote_y").checked == false && document.getElementById("c_vote_n").checked == false){
		alert('Please provide your VOTE prior to submitting.');
		return;
	}
	
	if ( document.comment_form.name.value == '' || document.comment_form.name.value.length == 0 ){
		alert('Please enter your display NAME prior to submitting.');
		document.comment_form.name.focus();
		return;
	}

	if ( document.comment_form.email.value != "" ){
		var amp_index = document.comment_form.email.value.indexOf("@",1);
		var per_index = document.comment_form.email.value.indexOf(".", amp_index) ;

		if ( amp_index == -1 || per_index == -1 ){
			alert('Please provide a proper EMAIL address to register.');
			document.comment_form.email.focus();
			return;
		}
	}
	
	if ( document.getElementById("verify") != null ){
		if ( document.comment_form.verify.value == '' ){
			alert('Please enter the Verification code prior to submitting.');
			document.comment_form.verify.focus();
			return;
		}
	}

	document.comment_form.submit();	
}

function validate_vote(){
	if ( document.getElementById("vote_y").checked == false && document.getElementById("vote_n").checked == false){
		alert('Please provide your VOTE prior to submitting.');
		return;
	}
	
	if ( document.vote_form.name.value != '' ||  document.vote_form.email.value != "" ){
		if ( document.vote_form.name.value == '' || document.vote_form.name.value.length == 0 ){
			alert('Please enter your display NAME and EMAIL to register.');
			document.vote_form.name.focus();
			return;
		}

		if ( document.vote_form.email.value != "" ){
			var amp_index = document.vote_form.email.value.indexOf("@",1);
			var per_index = document.vote_form.email.value.indexOf(".", amp_index) ;

			if ( amp_index == -1 || per_index == -1 ){
				alert('Please provide a proper EMAIL address to register.');
				document.vote_form.email.focus();
				return;
			}
		}
	}
	
	document.vote_form.submit();	
}

function validate_disapproval(){
	if ( document.disapproval_form.reason.value == '' || document.disapproval_form.reason.value.length == 0 ){
		alert('You must enter a REASON for disapproval prior to deletion.');
		document.disapproval_form.reason.focus();
		return;
	}
	
	document.disapproval_form.submit();	
}

function action_top_menu( url, category_id ){
	document.top_menu_form.category_id.value = category_id;
	document.top_menu_form.action = url;
	document.top_menu_form.submit();
}

function action_left_menu( url, category_id ){
	document.left_menu_form.category_id.value = category_id;
	document.left_menu_form.action = url;
	document.left_menu_form.submit();
}

function action_users( cmd, url ){
	if ( cmd != 'ADD' && document.user_form.uid.value.length == 0 ){
		alert('Please select a User name prior to clicking View, Edit or Delete');
		return;
	}
	
	if ( cmd == 'DELETE' ){
		var answer = confirm('Are you sure you want to delete this User?');
		if ( !answer ){
			return;
		}
	}
	
	document.user_form.command.value = cmd;
	document.user_form.action = url;
	document.user_form.submit();
}

