// JavaScript Document
function bulinker(where) {
			window.location = where
		}
function delcheated(page, intDeleteID, strDeleteTitle, queryChar) {
			input_box=confirm("Are you sure that you want to delete the " + strDeleteTitle + "?");
				if (input_box==true) { 
					// Output when OK is clicked
					window.location = page + '?action=delete&' + queryChar + '=' + intDeleteID; 
					}
		}
function editNotes(yesPage, noPage, userID, userName) {
	input_box=confirm("Would you like to edit the note for " + userName + "? (Click cancel for no.)");
		if (input_box==true) { 
			// Output when OK is clicked
			window.location = yesPage + '?action=editnotes&u=' + userID; 
		} else {
			window.location = noPage;
		}
}
function get_radio_gender()
{
for (var i=0; i < document.consultForm.consultGender.length; i++)
   {
   if (document.consultForm.consultGender[i].checked)
      {
      return(document.consultForm.consultGender[i].value);
      }
   }
}
function get_radio_calltime()
{
for (var i=0; i < document.consultForm.consultCallTime.length; i++)
   {
   if (document.consultForm.consultCallTime[i].checked)
      {
      return(document.consultForm.consultCallTime[i].value);
      }
   }
}


function isValid(n,pattern) {
  var re;
  if (pattern == "phone" ) {
    re = /(([01][\.\- +]\(\d{3}\)[\.\- +]?)|([01][\.\- +]\d{3}[\.\- +])|(\(\d{3}\) ?)|(\d{3}[- \.]))?\d{3}[- \.]\d{4}/
  } else if (pattern == "email" ) {
    re = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/
  } else if (pattern == "date" ) {
    re = /^(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/
  } else if (pattern == "zip" ) {
    re = /^(\d{5}-\d{4}|\d{5})$|^([a-zA-Z]\d[a-zA-Z] \d[a-zA-Z]\d)$/
  } else if (pattern == "card" ) {
    re = /^((4\d{3})|(5[1-5]\d{2})|(6011))-?\d{4}-?\d{4}-?\d{4}|3[4,7]\d{13}$/
  } else if (pattern == "domain") {
    re = /^([a-zA-Z0-9][-a-zA-Z0-9]*[a-zA-Z0-9]\.)+([a-zA-Z0-9]{2,5})$/
  } else if (pattern == "url") {
    re = /^(http|https|ftp)\:\/\/((([a-z_0-9\-]+)+(([\:]?)+([a-z_0-9\-]+))?)(\@+)?)?(((((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5]))))|((([a-z0-9\-])+\.)+([a-z]{2}\.[a-z]{2}|[a-z]{2,4})))(([\:])(([1-9]{1}[0-9]{1,3})|([1-5]{1}[0-9]{2,4})|(6[0-5]{2}[0-3][0-6])))?\/?$/
  } else if (pattern == "ssn") {
    re = /^(?=((0[1-9]0)|([1-7][1-7]\d)|(00[1-9])|(0[1-9][1-9]))-(?=(([1-9]0)|(0[1-9])|([1-9][1-9]))-(?=((\d{3}[1-9])$|([1-9]\d{3})$|(\d[1-9]\d{2})$|(\d{2}[1-9]\d)$))))/
  } else if (pattern == "text") {
    re = /\w/
  } else if (pattern == "int") {
	re = /^[\+\-]?\d*$/
  }
  if (!re.test(n)) {
	return false;
  } else {
	return true;
  }
}
function openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}
function deleteConfirm(page, intDeleteID, strDeleteTitle, strType, strTypeID, url) {
			input_box=confirm("Are you sure that you want to delete " + strDeleteTitle + "?");
				if (input_box==true) { 
					// Output when OK is clicked
						if (url!="") {
							url = "&url=" + url
						}
					window.location = isVirtual + '/' + page + '.asp?type=' + strType + '&action=delete&' + strTypeID + '=' + intDeleteID + url; 
					}
		}
function restoreConfirm(page, intDeleteID, strDeleteTitle, strType, strTypeID, url) {
	input_box=confirm("Are you sure that you want to restore " + strDeleteTitle + "?");
		if (input_box==true) { 
			// Output when OK is clicked
				if (url!="") {
					url = "&url=" + url
				}
			window.location = isVirtual + '/' + page + '.asp?type=' + strType + '&action=restore&' + strTypeID + '=' + intDeleteID + url; 
			}
}
function hideShow(el) {
	obj = document.getElementById(el);
	if (obj.style.display == 'block') {
		obj.style.display = 'none';
	}else{
		if (obj.style.display == 'none' || obj.style.display == null || obj.style.display == '') {
			obj.style.display = 'block';
		}
	}
}
function showError(el) {
	el.style.backgroundColor = '#9FE0EC';
}
function hideError(el) {
	el.style.backgroundColor = '#FFFFFF';
}

//BEGIN FORM VALIDATIONS
function validateSessionReplyForm() {
		var bolErr = 0;
		var loc = document.editReplyForm;
		var errField = document.getElementById("formError");
		if (!isValid(loc.reply_body.value, 'text')) {
			showError(loc.reply_body);
			bolErr = 1;
		} else {
			hideError(loc.reply_body);
		}
		if (bolErr != 0) {
			//errField.style.display = 'block';
		} else {
			//errField.style.display = 'none';
			loc.submit();
		}
}
function validateConsultForm() {
		var bolErr = 0;
		var loc = document.consultForm;
		var genderText = document.getElementById("genderText");
		var bestTimeText = document.getElementById("bestTimeText");
		if (!isValid(loc.consultFirstName.value, 'text')) {
			showError(loc.consultFirstName);
			bolErr = 1;
		} else {
			hideError(loc.consultFirstName);
		}
		if (!isValid(loc.consultAge.value, 'int')) {
			showError(loc.consultAge);
			bolErr = 1;
		} else {
			hideError(loc.consultAge);
		}
		if (get_radio_gender() == null) {
			showError(genderText);
			bolErr = 1;
		} else {
			hideError(genderText);
		} 
		if (!isValid(loc.consultPrompting.value, 'text')) {
			showError(loc.consultPrompting);
			bolErr = 1;
		} else {
			hideError(loc.consultPrompting);
		}
		if (get_radio_calltime() == null) {
			showError(bestTimeText);
			bolErr = 1;
		} else {
			hideError(bestTimeText);
		}
		if (!isValid(loc.consultPhoneNumber.value, 'phone')) {
			showError(loc.consultPhoneNumber);
			bolErr = 1;
		} else {
			hideError(loc.consultPhoneNumber);
		}
		if (loc.consultEmailInfo.checked == true){
			if (!isValid(loc.consultEmail.value, 'email')) {
				showError(loc.consultEmail);
				bolErr = 1;
			} else {
				hideError(loc.consultEmail);
			}
		} else {
			hideError(loc.consultEmail);
		}
		if (bolErr != 0) {
			//errField.style.display = 'block';
		} else {
			//errField.style.display = 'none';
			loc.submit();
		}
}
function clearConsultForm() {
	var loc = document.consultForm;
	var genderText = document.getElementById("genderText");
	var bestTimeText = document.getElementById("bestTimeText");
	hideError(loc.consultFirstName);
	hideError(loc.consultAge);
	hideError(genderText);
	hideError(loc.consultPrompting);
	hideError(bestTimeText);
	hideError(loc.consultPhoneNumber);
	hideError(loc.consultEmail);
	loc.reset();
}
function validateActivateForm() {
	var bolErr = 0;
	var loc = document.userActivateForm;
	var errField = document.getElementById("formError");
	if (!isValid(loc.userPassword.value, 'text')) {
		showError(loc.userPassword);
		bolErr = 1;
	} else {
		hideError(loc.userPassword);
	}
	if (!isValid(loc.userPassword2.value, 'text')) {
		showError(loc.userPassword2);
		bolErr = 1;
	} else {
		hideError(loc.userPassword2);
	}
	if (bolErr != 0) {
		//errField.style.display = 'block';
	} else {
		//errField.style.display = 'none';
		loc.submit();
	}
}
function validateUserForm() {
		var bolErr = 0;
		var loc = document.addEditUserForm;
		var errField = document.getElementById("formError");
		if (!isValid(loc.userFirstname.value, 'text')) {
			showError(loc.userFirstname);
			bolErr = 1;
		} else {
			hideError(loc.userFirstname);
		}
		if (!isValid(loc.userLastname.value, 'text')) {
			showError(loc.userLastname);
			bolErr = 1;
		} else {
			hideError(loc.userLastname);
		}
		if (!isValid(loc.userEmail.value, 'email')) {
			showError(loc.userEmail);
			bolErr = 1;
		} else {
			hideError(loc.userEmail);
		}
		if (!isValid(loc.userMonthlylimit.value, 'int')) {
			showError(loc.userMonthlylimit);
			bolErr = 1;
		} else if (loc.userMonthlylimit.value == '') {
			showError(loc.userMonthlylimit);
			bolErr = 1;
		} else {
			hideError(loc.userMonthlylimit);
		}
		if (bolErr != 0) {
			//errField.style.display = 'block';
		} else {
			//errField.style.display = 'none';
			loc.submit();
		}
}
function validateSessionForm() {
		var bolErr = 0;
		var loc = document.addEditForm;
		var errField = document.getElementById("formError");
		if (!isValid(loc.session_body.value, 'text')) {
			showError(loc.session_body);
			bolErr = 1;
		} else {
			hideError(loc.session_body);
		}
		if (loc.session_clientId.value == 'selectaclient') {
			showError(loc.session_clientId);
			bolErr = 1;
		} else {
			hideError(loc.session_clientId);
		}
		if (bolErr != 0) {
			//errField.style.display = 'block';
		} else {
			//errField.style.display = 'none';
			loc.submit();
		}
}
function validateStoryForm() {
		var bolErr = 0;
		var loc = document.storyForm;
		var errField = document.getElementById("formError");
		if (!isValid(loc.story_subject.value, 'text')) {
			showError(loc.story_subject);
			bolErr = 1;
		} else {
			hideError(loc.story_subject);
		}
		if (!isValid(loc.story_body.value, 'text')) {
			showError(loc.story_body);
			bolErr = 1;
		} else {
			hideError(loc.story_body);
		}
		if (bolErr != 0) {
			//errField.style.display = 'block';
		} else {
			//errField.style.display = 'none';
			loc.submit();
		}
}
function validateReplyForm() {
		var bolErr = 0;
		var loc = document.replyForm;
		var errField = document.getElementById("formError");
		if (!isValid(loc.reply_body.value, 'text')) {
			showError(loc.reply_body);
			bolErr = 1;
		} else {
			hideError(loc.reply_body);
		}
		if (bolErr != 0) {
			//errField.style.display = 'block';
		} else {
			//errField.style.display = 'none';
			loc.submit();
		}
}
function validateQuestionForm() {
		var bolErr = 0;
		var loc = document.questionForm;
		var errField = document.getElementById("formError");
		if (!isValid(loc.question_body.value, 'text')) {
			showError(loc.question_body);
			bolErr = 1;
		} else {
			hideError(loc.question_body);
		}
		if (bolErr != 0) {
			//errField.style.display = 'block';
		} else {
			//errField.style.display = 'none';
			loc.submit();
		}
}
function validateDiaryForm() {
		var bolErr = 0;
		var loc = document.diaryForm;
		var errField = document.getElementById("formError");
		if (!isValid(loc.diary_body.value, 'text')) {
			showError(loc.diary_body);
			bolErr = 1;
		} else {
			hideError(loc.diary_body);
		}
		if (bolErr != 0) {
			//errField.style.display = 'block';
		} else {
			//errField.style.display = 'none';
			loc.submit();
		}
}
function validateLoginAdm() {
		var bolErr = 0;
		var loc = document.adminloginform;
		var errField = document.getElementById("formError");
		if (!isValid(loc.user_email.value, 'email')) {
			showError(loc.user_email);
			bolErr = 1;
		} else {
			hideError(loc.user_email);
		}
		if (loc.user_password.value == 'Enter password') {
			showError(loc.user_password);
			bolErr = 1;
		} else {
			hideError(loc.user_password);
		}
		if (bolErr != 0) {
			//errField.style.display = 'block';
		} else {
			//errField.style.display = 'none';
			loc.submit();
		}
}
function validateLogin() {
		var bolErr = 0;
		var loc = document.clientloginform;
		var errField = document.getElementById("formError");
		if (!isValid(loc.user_email.value, 'email')) {
			showError(loc.user_email);
			bolErr = 1;
		} else {
			hideError(loc.user_email);
		}
		if (loc.user_password.value == 'Enter password') {
			showError(loc.user_password);
			bolErr = 1;
		} else {
			hideError(loc.user_password);
		}
		if (bolErr != 0) {
			//errField.style.display = 'block';
		} else {
			//errField.style.display = 'none';
			loc.submit();
		}
}
function validatePassRetrieve() {
		var bolErr = 0;
		var loc = document.passwordretrieveform;
		var errField = document.getElementById("formError");
		if (!isValid(loc.email_password.value, 'email')) {
			showError(loc.email_password);
			bolErr = 1;
		} else {
			hideError(loc.email_password);
		}
		if (bolErr != 0) {
			//errField.style.display = 'block';
		} else {
			//errField.style.display = 'none';
			loc.submit();
		}
}

function validateDocumentForm() {
		var bolErr = 0;
		var loc = document.uploadForm;
		var errField = document.getElementById("formError");
		if (!isValid(loc.form_title.value, 'text')) {
			showError(loc.form_title);
			bolErr = 1;
		} else {
			hideError(loc.form_title);
		}
		//if (!isValid(loc.form_description.value, 'text')) {
			//showError(loc.form_description);
			//bolErr = 1;
		//} else {
			//hideError(loc.form_description);
		//}
		if (isAdd) {
			if (!isValid(loc.form_file.value, 'text')) {
				showError(loc.form_file);
				bolErr = 1;
			} else {
				hideError(loc.form_file);
			}
		}
		if (bolErr != 0) {
			errField.style.display = 'block';
		} else {
			errField.style.display = 'none';
			loc.submit();
			ShowProgress();
		}
}
function validateDocCatForm() {
		var bolErr = 0;
		var loc = document.catForm;
		var errField = document.getElementById("formError");
		if (!isValid(loc.cat_title.value, 'text')) {
			showError(loc.cat_title);
			bolErr = 1;
		} else {
			hideError(loc.cat_title);
		}
		if (bolErr != 0) {
			errField.style.display = 'block';
		} else {
			errField.style.display = 'none';
			loc.submit();
		}
}
function isImage(path) {
	var bolMatch = false;
	var strExtensions = 'jpg,png,gif,bmp,JPG,PNG,GIF,BMP';
	var arrExtensions = strExtensions.split(',');
	var arrPath = path.split('.');
	var strExtension = arrPath[arrPath.length-1];
	for (i=0;i<=arrExtensions.length;i++) {
		if (arrExtensions[i] == strExtension) {
			bolMatch = true;
		}
	}
	return(bolMatch);
}
//END FORM VALIDATIONS