/**
 * General javascript functions...
 */

/* Trim function */

function trim(s) {
	// Remove leading spaces and carriage returns...
	while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r')) {
		s = s.substring(1,s.length);
	}
	
	// Remove trailing spaces and carriage returns...
	while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r')) {
		s = s.substring(0,s.length-1);
	}
	return s;
}





/**
 * Application-specific javascript functions...
 */


/* Validate login form - /cust_inc/func.php */

function valLogin(frm) {
	if (frm.user.value == '') {
		if (frm.pass.value == '') {
			alert("Please enter a User Name and Password to log in.");
			return false;
		} else {
			alert("Please enter a User Name to log in.");
			return false;
		}
	} else {
		if (frm.pass.value == '') {
			alert("Please enter a Password to log in.");
			return false;
		} else {
			return true;
		}
	}
}



/* Validate contact us form - /cust_inc/contact.php */

function valContactUs(frm) {

	if (frm.email.value != "") {
		if (frm.email.value.indexOf('@') == -1 || frm.email.value.indexOf('.') == -1) {
			alert("The E-mail Address field does not contain a valid E-mail Address."
				+ "\nPlease be sure you enter the address in the following format:"
				+ "\nname@domain.com"
				+ "\n\nThank You.");
			return false;
		}
	} else {
		areYouSure = window.confirm("Are you sure you want to send this message anonymously?"
			+ "\n" + "Unless you provide a phone number in the Comments area, we will not be able to contact you."
			+ "\n"
			+ "\n" + "Click 'OK' to send the message anyway."
			+ "\n" + "Click 'Cancel' to return without sending the message.");
		if (!areYouSure) {
			return false;
		}
	}
	
	if (frm.comments.value == '') {
		alert("Please enter a comment or question before trying to send your message."
			+ "\n\nThank You.");
		return false;
	}
	
	return true;
}

