//function to open up the flash demos in the help folder
function fncOpenFlashDemo(strFlashDemo)
{
	HelpTopicWindow = window.open("/lelImages/flash/help/" + strFlashDemo + "/index.html", "HelpTopic", "width=998,height=614,scrollbars=no");
	HelpTopicWindow.focus();
}

function fncOpenJCADemo(strFlashDemo)
{
	HelpTopicWindow = window.open("/lelImages/flash/JCA/" + strFlashDemo + "/index.html", "HelpTopic", "width=800,height=600,scrollbars=no");
	HelpTopicWindow.focus();
}

//function to show or hide all the pages that use expand collapse functionality.
function showHide(section)
{
	objTbody = document.getElementById('tbody_' + section);
	objTbody_2 = document.getElementById('tbody2_' + section);

	objAnchor = document.getElementById('anchor_' + section);

	if(objTbody.style.display == "none") {
		objTbody.style.display = "";
		if (objTbody_2) objTbody_2.style.display = "none";
		if (objAnchor) {
			objAnchor.className = "text-expand";
			objAnchor.title = "Collapse";
		}
	} else {
		if (objTbody_2) objTbody_2.style.display = "";
		objTbody.style.display = "none";
		if (objAnchor) {
			objAnchor.className = "text-collapse";
			objAnchor.title = "Expand";
		}
	}
}

//function to clear out the input on the search, if it is the default value.
function clearSearchInput()
{
	if(document.frmSearch.strSearchTerm.value == "Search...") {
		document.frmSearch.strSearchTerm.value = "";
	}
}

// Login form validation
function checkLogin() {
	if(document.f1.username.value == "" || document.f1.password.value == "") {
		alert("Please enter a Username and Password.");
		return false;
	}
	return true;
}

function checkEmailAddress() {
	var reg = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; 
	if (!reg.test(document.getElementById('emailAddress').value)) {
		alert('Please enter a valid email address.');
		document.getElementById('emailAddress').focus();
		return false;
	}
	
	return true;
}

function checkCustomerSupport() {
	//first thing is to trim left and right to get out any whitespace.
	document.f1.fullname.value = trim(document.f1.fullname.value);
	document.f1.username.value = trim(document.f1.username.value);
	document.f1.libraryName.value = trim(document.f1.libraryName.value);
	
	if (document.f1.fullname.value == '' || document.f1.username.value == '' || document.f1.libraryName.value == '') {
		alert('Please fill in all required fields.');
		return false;
	}
	
	if (!checkEmailAddress()) return false;
	
	return true;
}


//check the update Password form
function checkUpdatePassword() {
	
	//first thing is to trim left and right to get out any whitespace.
	document.f1.strCurrentPassword.value = trim(document.f1.strCurrentPassword.value);
	document.f1.strNewPassword.value = trim(document.f1.strNewPassword.value);
	document.f1.strNewPassword2.value = trim(document.f1.strNewPassword2.value);
	
	if(document.f1.strCurrentPassword.value == "" || document.f1.strNewPassword.value == "" || document.f1.strNewPassword2.value == "") {
		alert("Please fill in all the required fields.");
		return false;
	}
	else if(document.f1.strNewPassword.value != document.f1.strNewPassword2.value) {
		alert("The new passwords you entered did not match.");
		return false;
	}
	
	return true;
}

// Registration form validation
function checkRegistration() {
	//first thing is to trim left and right to get out any whitespace.
	document.f1.username.value = trim(document.f1.username.value);
	document.f1.password.value = trim(document.f1.password.value);
	document.f1.password2.value = trim(document.f1.password2.value);
	
	if(document.f1.username.value == "" || document.f1.password.value == "" || document.f1.password2.value == "") {
		alert("Please fill in all the required fields.");
		return false;
	}
	else if(document.f1.password.value != document.f1.password2.value) {
		alert("The passwords you entered did not match.");
		return false;
	} else if (document.f1.password.value.length < 6 || document.f1.username.value.length < 6 || document.f1.password.value.indexOf(' ') != -1 || document.f1.username.value.indexOf(' ') != -1) {
		alert("Both your username and password must be a minimum of 6 characters and should not include spaces.");
		return false;
	}
	
	if (document.getElementById('emailAddress').value != '' && !checkEmailAddress()) return false;
	
	
	return true;
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}