// FUNCTION MANIFEST
//
// MAJOR FUNCTIONS
// ---------------
//
//	ValidateAddressInfo(callingElement)
//	ValidateForm_register(callingElement, checkContactFields)
//	ValidateForm_adminCreateUser(callingElement, checkContactFields)
//	ValidateForm_adminEditUser(callingElement, checkContactFields)
//	ValidateForm_private(callingElement)
//	ValidateForm_search(callingElement)
//	ValidateForm_payment(callingElement)
//	ValidateForm_payment_forInstantPurchase(callingElement)
//	ValidateForm_adduser(callingElement)
//	ValidateForm_email(callingElement)
//	ValidateForm_addfunds(callingElement)
//	ValidateForm_broadcastapp(callingElement)
//	ValidateForm_login(callingElement)
//	ValidateForm_changepassword(callingElement)
//	emailCheck (emailStr, checkTLD)
//
//	SUB-FUNCTIONS
//	-------------
//	isEmailValid(sString)
//	isStringLengthValid(sString, num1, num2)
//	isStringLengthNotZero(sString)
//	isPasswordValid(sString)
//	isPasswordDuplicateValid(sString1, sString2)
//	isAccountNumberValid(sString)
//	isNumberValid(sString)
//	isZipValid(sString)
//	isPhoneValid(sString)
//	isMoneyNumberValid(sString)
//	isInlineDateRangeHoursValid()
//	isInlineDateRangeDaysValid()
//	isOnlySpaces(sString)
//	addMessage(callingElement)



// Static constants
PASSWORD_MIN_LENGTH = 5;
PASSWORD_MAX_LENGTH = 35;
//SCREENNAME_MAX_LENGTH = 20;
FIRSTNAME_MAX_LENGTH = 20;
LASTNAME_MAX_LENGTH = 20;
FULLNAME_MAX_LENGTH = 80;
COMPANY_MAX_LENGTH = 50;
ADDRESS1_MAX_LENGTH = 100;
ADDRESS2_MAX_LENGTH = 100;
CITY_MAX_LENGTH = 50;
STATE_MAX_LENGTH = 50;
COUNTRY_MAX_LENGTH = 50;
ZIP_MAX_LENGTH = 10;
PHONE_MAX_LENGTH = 15;
FAX_MAX_LENGTH = 15;
LOGIN_MAX_LENGTH = 128;

ERROR_TEXT = "You have the following error(s): \n\n";
EMAIL_ERROR = " - You have entered an improperly formatted e-mail address.";
PASSWORD_LENGTH_ERROR = " - Your password must be between " + PASSWORD_MIN_LENGTH + " and " + PASSWORD_MAX_LENGTH + " characters.";
PASSWORD_SPACE_ERROR = " - Your password cannot contain spaces.";
PASSWORD_DUPLICATE_ERROR = " - The passwords you supplied do not match.";
INVALID_STRING_ERROR = "must be between";
TOO_LONG_STRING_ERROR = "cannot be longer than";

ENDSTRING_ERROR = "";

function ValidateAddressInfo(callingElement){
	
	var errorMessage = ERROR_TEXT;
		
	if (!isStringLengthValid(callingElement.company.value, 0, COMPANY_MAX_LENGTH)) {
		errorMessage += " - Company " + TOO_LONG_STRING_ERROR + " " + COMPANY_MAX_LENGTH + " characters.\n"; 
	} 
	if (!isStringLengthValid(callingElement.address1.value, 1, ADDRESS1_MAX_LENGTH)) {
		errorMessage += " - Address 1 " + INVALID_STRING_ERROR + " 1 and " + ADDRESS1_MAX_LENGTH + " characters.\n"; 
	} 
	
	if (!isStringLengthValid(callingElement.address2.value, 0, ADDRESS2_MAX_LENGTH)) {
		errorMessage += " - Address 2 " + TOO_LONG_STRING_ERROR + " " + ADDRESS2_MAX_LENGTH + " characters.\n"; 
	}
	if (!isStringLengthValid(callingElement.city.value, 1, CITY_MAX_LENGTH)) {
		errorMessage += " - City " + INVALID_STRING_ERROR + " 1 and " + CITY_MAX_LENGTH + " characters.\n"; 
	} 
	if (!isStringLengthValid(callingElement.state.value, 1, STATE_MAX_LENGTH)) {
		errorMessage += " - State " + INVALID_STRING_ERROR + " 1 and " + STATE_MAX_LENGTH + " characters.\n"; 
	} 
	if (!isStringLengthValid(callingElement.country.value, 1, COUNTRY_MAX_LENGTH)) {
		errorMessage += " - Country " + INVALID_STRING_ERROR + " 1 and " + COUNTRY_MAX_LENGTH + " characters.\n"; 
	}
	if (!isStringLengthValid(callingElement.postalCode.value, 1, ZIP_MAX_LENGTH)) {
		errorMessage += " - Postal Code " + INVALID_STRING_ERROR + " 1 and " + ZIP_MAX_LENGTH + " characters.\n"; 
	}  
	if (!isStringLengthValid(callingElement.phone.value, 1, PHONE_MAX_LENGTH)) {
		errorMessage += " - Phone " + INVALID_STRING_ERROR + " 1 and " + PHONE_MAX_LENGTH + " characters.\n"; 
	} 
	if (!isStringLengthValid(callingElement.fax.value, 0, FAX_MAX_LENGTH)) {
		errorMessage += " - Fax " + TOO_LONG_STRING_ERROR + " " + FAX_MAX_LENGTH + " characters.\n"; 
	} 
	if (!isPhoneValid(callingElement.phone.value)) {
		errorMessage += " - Please check your phone number. It may only contain numbers, spaces, dashes and parentheses \n";
	}
	if (!isPhoneValid(callingElement.fax.value))	{
		errorMessage += " - Please check your fax number. It may only contain numbers, spaces, dashes and parentheses \n";
	}
		
	if (errorMessage != ERROR_TEXT) {
		errorMessage = addMessage(errorMessage); 
		alert(errorMessage);
		return false;
	}
	
	return true;
}

// Form-specific validation functions
function ValidateForm_register(callingElement, checkContactFields) {
	
	var errorMessage = ERROR_TEXT; 
	
/******* COMMENT OUT SCREEN NAME
	if (!isStringLengthValid(callingElement.screenName.value, 1, SCREENNAME_MAX_LENGTH)) {
		errorMessage += " - Screen Name " + INVALID_STRING_ERROR + " 1 and " + SCREENNAME_MAX_LENGTH + " characters.\n"; 
	}
**** END COMMENT OUT ************/
	if (!isStringLengthValid(callingElement.login.value, 1, LOGIN_MAX_LENGTH)) {
		errorMessage += " - Email Address " + INVALID_STRING_ERROR + " 1 and " + LOGIN_MAX_LENGTH + " characters.\n"; 
	}


	if (!isStringLengthValid(callingElement.firstName.value, 1, FIRSTNAME_MAX_LENGTH)) {
		errorMessage += " - First Name " + INVALID_STRING_ERROR + " 1 and " + FIRSTNAME_MAX_LENGTH + " characters.\n"; 
	}
	
	if (!isStringLengthValid(callingElement.lastName.value, 1, LASTNAME_MAX_LENGTH)) {
		errorMessage += " - Last Name " + INVALID_STRING_ERROR + " 1 and " + LASTNAME_MAX_LENGTH + " characters.\n"; 
	}
	
	if (!isEmailValid(callingElement.login.value)) {
		errorMessage += EMAIL_ERROR + "\n";
	}
	
	if (!isStringLengthValid(callingElement.password.value, PASSWORD_MIN_LENGTH, PASSWORD_MAX_LENGTH)) {
		errorMessage += PASSWORD_LENGTH_ERROR + "\n";
	}
	
	if (!isPasswordValid(callingElement.password.value)) {
		errorMessage += PASSWORD_SPACE_ERROR + "\n";
	}
	
	if (!isPasswordDuplicateValid(callingElement.password.value, callingElement.confirmPassword.value)) {
		errorMessage += PASSWORD_DUPLICATE_ERROR + "\n";
	}
	

	if (errorMessage != ERROR_TEXT) {
		errorMessage = addMessage(errorMessage); 
		alert(errorMessage);
		return false;
	}else if(checkContactFields){
		return ValidateAddressInfo(callingElement);
	}else{
		return true;
	}
	
} // end ValidateForm_register

function ValidateForm_adminCreateUser(callingElement, checkContactFields) {
	
	var errorMessage = ERROR_TEXT; 
	
	
	if (!isStringLengthValid(callingElement.login.value, 1, LOGIN_MAX_LENGTH)) {
		errorMessage += " - Email Address " + INVALID_STRING_ERROR + " 1 and " + LOGIN_MAX_LENGTH + " characters.\n"; 
	}
	
	if (!isEmailValid(callingElement.login.value)) {
		errorMessage += EMAIL_ERROR + "\n";
	}
	
	if (!isStringLengthValid(callingElement.password.value, PASSWORD_MIN_LENGTH, PASSWORD_MAX_LENGTH)) {
		errorMessage += PASSWORD_LENGTH_ERROR + "\n";
	}
	
	if (!isPasswordValid(callingElement.password.value)) {
		errorMessage += PASSWORD_SPACE_ERROR + "\n";
	}
	
	if (!isPasswordDuplicateValid(callingElement.password.value, callingElement.confirmPassword.value)) {
		errorMessage += PASSWORD_DUPLICATE_ERROR + "\n";
	}
	
/******* COMMENT OUT SCREEN NAME
	if (!isStringLengthValid(callingElement.screenName.value, 1, SCREENNAME_MAX_LENGTH)) {
		errorMessage += " - Screen Name " + INVALID_STRING_ERROR + " 1 and " + SCREENNAME_MAX_LENGTH + " characters.\n"; 
	}
**** END COMMENT OUT **********/

	if (!isStringLengthValid(callingElement.firstName.value, 1, FIRSTNAME_MAX_LENGTH)) {
		errorMessage += " - First Name " + INVALID_STRING_ERROR + " 1 and " + FIRSTNAME_MAX_LENGTH + " characters.\n"; 
	}
	
	if (!isStringLengthValid(callingElement.lastName.value, 1, LASTNAME_MAX_LENGTH)) {
		errorMessage += " - Last Name " + INVALID_STRING_ERROR + " 1 and " + LASTNAME_MAX_LENGTH + " characters.\n"; 
	}

	if (errorMessage != ERROR_TEXT) {
		errorMessage = addMessage(errorMessage); 
		alert(errorMessage);
		return false;
	}else if(checkContactFields){
		return ValidateAddressInfo(callingElement);
	}else{
		return true;
	}
	
} // end ValidateForm_adminCreateUser

function ValidateForm_adminEditUser(callingElement, checkContactFields) {
	
	var errorMessage = ERROR_TEXT; 
	
	if (!isStringLengthValid(callingElement.login.value, 1, LOGIN_MAX_LENGTH)) {
		errorMessage += " - Email Address " + INVALID_STRING_ERROR + " 1 and " + LOGIN_MAX_LENGTH + " characters.\n"; 
	}

	if (!isStringLengthValid(callingElement.firstName.value, 1, FIRSTNAME_MAX_LENGTH)) {
		errorMessage += " - First Name " + INVALID_STRING_ERROR + " 1 and " + FIRSTNAME_MAX_LENGTH + " characters.\n"; 
	}
	
	if (!isStringLengthValid(callingElement.lastName.value, 1, LASTNAME_MAX_LENGTH)) {
		errorMessage += " - Last Name " + INVALID_STRING_ERROR + " 1 and " + LASTNAME_MAX_LENGTH + " characters.\n"; 
	}

	if (errorMessage != ERROR_TEXT) {
		errorMessage = addMessage(errorMessage); 
		alert(errorMessage);
		return false;
	}else if(checkContactFields){
		return ValidateAddressInfo(callingElement);
	}else{
		return true;
	}
	
} // end ValidateForm_adminEditUser

function ValidateForm_private(callingElement) {
	
	var errorMessage = ERROR_TEXT;
	
	if (callingElement.accessCode.value.length <= 0) {
		errorMessage += " - Please enter in a valid access code."
	}
	
	if (errorMessage != ERROR_TEXT) {
		errorMessage = addMessage(errorMessage);
		alert(errorMessage);
		return false;
	}
	else return true;
	
}

function ValidateForm_search(callingElement) {

	var errorMessage = ERROR_TEXT;
	
	if (callingElement.keyword.value.length <= 0) {
		errorMessage += " - Please enter in some keywords for your search.";
	}
	
	if (errorMessage != ERROR_TEXT) {
		errorMessage = addMessage(errorMessage);
		alert(errorMessage);
		return false;
	}
	else return true;

}

function ValidateForm_payment(callingElement) {

	var errorMessage = ERROR_TEXT;
	
	if (!isStringLengthValid(callingElement.name.value, 1, 60)) {
		errorMessage += " - Payment Name " + INVALID_STRING_ERROR + " 1 and 60 characters." + "\n";
	}
	
	if (callingElement.acctNumber) {
	if (!isAccountNumberValid(callingElement.acctNumber.value))
		errorMessage += " - Your account number may only contain numbers, spaces and/or dashes." + "\n";
	}
	
	if (callingElement.mType.options[callingElement.mType.selectedIndex].value == ""){
		errorMessage += " - You must select an account type.\n";
	}

	if (!isStringLengthValid(callingElement.holderName.value, 1, 64)) {
		errorMessage += " - Account Holder Name " + INVALID_STRING_ERROR + " 1 and 64 characters." + "\n";
	}
	
	if (!isZipValid(callingElement.billingZip.value)) {
		errorMessage += " - Your zip code must be entirely numbers and an optional dash." + "\n";
	}
	
	if (errorMessage != ERROR_TEXT) {
		errorMessage = addMessage(errorMessage);
		alert(errorMessage);
		return false;
	}
	else return true;
	
}

function ValidateForm_payment_forInstantPurchase(callingElement) {

	var errorMessage = ERROR_TEXT;
	
	if(callingElement.save){
	if(callingElement.save.checked){
		if (!isStringLengthValid(callingElement.name.value, 1, 60)) {
			errorMessage += " - Payment Name " + INVALID_STRING_ERROR + " 1 and 60 characters." + "\n";
		}
	}
	}
	
	if (callingElement.acctNumber) {
	if (!isAccountNumberValid(callingElement.acctNumber.value))
		errorMessage += " - Your account number may only contain numbers, spaces and/or dashes." + "\n";
	}
	
	if (callingElement.mType.options[callingElement.mType.selectedIndex].value == ""){
		errorMessage += " - You must select an account type.\n";
	}

	if (!isStringLengthValid(callingElement.holderName.value, 1, 64)) {
		errorMessage += " - Account Holder Name " + INVALID_STRING_ERROR + " 1 and 64 characters." + "\n";
	}
	
	if (!isZipValid(callingElement.billingZip.value)) {
		errorMessage += " - Your zip code must be entirely numbers and an optional dash." + "\n";
	}
	
	if (errorMessage != ERROR_TEXT) {
		errorMessage = addMessage(errorMessage);
		alert(errorMessage);
		return false;
	}
	else return true;
	
}

function ValidateForm_adduser(callingElement) {

	return ValidateForm_register(callingElement);
	
}

function ValidateForm_email(callingElement) {
	
	var errorMessage = ERROR_TEXT;
	
	if (callingElement.recipient) {
	if (callingElement.recipient.value.length < 1)
		errorMessage += " - Please enter in a recipient for your email. \n";
	}
	
	if (errorMessage != ERROR_TEXT) {
		errorMessage = addMessage(errorMessage);
		alert(errorMessage);
		return false;
	}
	else return true;
}

function ValidateForm_addfunds(callingElement) {

	var errorMessage = ERROR_TEXT;
	
	if(!isMoneyNumberValid(callingElement.amount.value) || ((callingElement.amount.value.indexOf(".") > -1)&& !((callingElement.amount.value.length - 1) - callingElement.amount.value.indexOf(".") < 3)) || callingElement.amount.value == "0.00" || callingElement.amount.value == "0" || callingElement.amount.value == "0.0" || callingElement.amount.value == ".00" || callingElement.amount.value == ".0" || callingElement.amount.value == "0." || callingElement.amount.value == ".")
		errorMessage += " - Please enter in a valid positive quantity (up to two decimal places) for Amount to Add ." + "\n";

	if (callingElement.paymentmethod.options.length == 0)
		errorMessage += " - You must have a payment method to add funds to your account. \n";
	
	if (errorMessage != ERROR_TEXT) {
		errorMessage = addMessage(errorMessage);
		alert(errorMessage);
		return false;
	}
	else return true;
}

function ValidateForm_broadcastapp(callingElement) {

	var errorMessage = ERROR_TEXT;
	
	if (!isStringLengthNotZero(callingElement.firstname.value))
		errorMessage += " - Please enter in your first name. \n";
		
	if (!isStringLengthNotZero(callingElement.lastname.value))
		errorMessage += " - Please enter in your last name. \n";
		
	if (!isStringLengthNotZero(callingElement.company.value))
		errorMessage += " - Please enter in your company name. \n";
		
	if (!isStringLengthNotZero(callingElement.address.value))
		errorMessage += " - Please enter in your address. \n";
		
	if (!isStringLengthNotZero(callingElement.city.value))
		errorMessage += " - Please enter in your city. \n";
		
	if (!isStringLengthNotZero(callingElement.state.value))
		errorMessage += " - Please enter in your state. \n";
	
	// using isZipValid even though we are checking for zipcode.  validation is the same.	
	if (!isAccountNumberValid(callingElement.zipcode.value))
		errorMessage += " - Please enter in your zipcode. \n";
		
	if (!isStringLengthNotZero(callingElement.phone.value))
		errorMessage += " - Please enter in your phone number. \n";

	if (!isPhoneValid(callingElement.phone.value))
		errorMessage += " - Please check your phone number. It may only contain numbers, spaces, dashes and parentheses \n";

	if (!isPhoneValid(callingElement.fax.value))
		errorMessage += " - Please check your fax number. It may only contain numbers, spaces, dashes and parentheses \n";
		
	if (!isEmailValid(callingElement.email.value))
		errorMessage += EMAIL_ERROR + "\n";
		
	if (callingElement.companyURL.value == "http://" || callingElement.companyURL.value.length < 1)
		errorMessage += " - Please enter in your Company URL. \n";
	
	var checkbox = false;
	for (var i=1; i<=5; i++) {
		var o = callingElement["mediatypes" + i];
		// alert(o.checked);
		if (o.checked) {
			checkbox = true;
			break;
		}
	}
	
	if (!checkbox)
		errorMessage += " - Please enter in at least one type of Media you wish to broadcast. \n";
		
	if (errorMessage != ERROR_TEXT) {
		errorMessage = addMessage(errorMessage);
		alert(errorMessage);
		return false;
	}
	else return true;

}

function ValidateForm_login(callingElement) {

	var errorMessage = ERROR_TEXT;
	
//	if (!isEmailValid(callingElement.login.value))
//		errorMessage += EMAIL_ERROR + "\n";
		
	if (!isPasswordValid(callingElement.password.value) || callingElement.password.value.length <= 0) 
		errorMessage += " - Please enter in a valid password with no spaces. \n";
		
	if (errorMessage != ERROR_TEXT) {
		errorMessage = addMessage(errorMessage);
		alert(errorMessage);
		return false;
	}
	else return true;
}

function ValidateForm_changepassword(callingElement) {

	var errorMessage = ERROR_TEXT;
	
	if (!isPasswordValid(callingElement.oldPassword.value) || callingElement.oldPassword.value <= 0)
		errorMessage += " - Please enter in your existing password with no spaces. \n";
		
	if (!isPasswordValid(callingElement.newPassword.value) || callingElement.newPassword.value <= 0)
		errorMessage += " - Please enter in your new password with no spaces. \n";	
		
	if (!isStringLengthValid(callingElement.newPassword.value, PASSWORD_MIN_LENGTH, PASSWORD_MAX_LENGTH)) 
		errorMessage += " - Your new password must be between " + PASSWORD_MIN_LENGTH + " and " + PASSWORD_MAX_LENGTH + " characters. \n";	
	
	if (!isPasswordDuplicateValid(callingElement.newPassword.value, callingElement.confirmPassword.value))
		errorMessage += PASSWORD_DUPLICATE_ERROR + "\n";

	if (errorMessage != ERROR_TEXT) {
		errorMessage = addMessage(errorMessage);
		alert(errorMessage);
		return false;
	}
	else return true;
}


function Validate_LengthAndSpaces(callingElement,label,minVal,maxVal) {

	var errorMessage = ERROR_TEXT;
	
	if (!isStringLengthValid(callingElement.value,minVal,maxVal)) 
		errorMessage += " - The " + label + " must be between " + minVal + " and " + maxVal + " characters. \n";	
	
	else if (!isOnlySpaces(callingElement.value))
		errorMessage += " - The " + label + " is invalid. It cannot contain only spaces. \n";


	if (errorMessage != ERROR_TEXT) {
		errorMessage = addMessage(errorMessage);
		alert(errorMessage);
		return false;
	}
	else return true;
}



// Validation Functions
function isEmailValid(sString) {
	return true;
	if (sString.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9_]+((\.|-)[A-Za-z0-9_]+)*\.[A-Za-z0-9]+$/) > -1)
        return true;
	else return false;
}

function isStringLengthValid(sString, num1, num2) {
	if (sString.length >= num1 && sString.length <= num2) {
		return true;
	}
	else return false;
}

function isStringLengthNotZero(sString) {
	if (sString.length > 0)
		return true;
	else return false;
}

function isPasswordValid(sString) {
	var invalid = " "; // invalid space
	if (sString.indexOf(invalid) < 0)
		return true;
	else return false;
}

function isPasswordDuplicateValid(sString1, sString2) {
	if (sString1 == sString2)
		return true;
	else return false;
}

function isAccountNumberValid(sString) {
	// valid characters are 0-9;
	var validChars = "0123456789";
	var i = 0;
	
	if (sString.length > 0) {
	
		while (i < sString.length) {
			if (validChars.indexOf(sString.charAt(i)) < 0) {
				// have invalid number string!
				return false;
			}
		i++;
		}
	// have valid string		
	return true;
	}
	
	// have invalid string because length is 0
	else return false;
	
}

function isNumberValid(sString) { 
	// valid numbers
	var validNums = "0123456789";
	var i = 0;
	
	if (sString.length > 0) { 
	
		while (i < sString.length) {
			if (validNums.indexOf(sString.charAt(i)) < 0) { 
				// have invalid number string!
				return false;
			}
		i++
		}	
	// have valid string
	return true;
	}
	
	// have invalid string because length is 0
	return false;
}

function isZipValid(sString) { 
	// valid numbers
	var validChars = "0123456789-";
	var i = 0;
	
	if (sString.length > 0) { 
	
		while (i < sString.length) {
			if (validChars.indexOf(sString.charAt(i)) < 0) { 
				// have invalid number string!
				return false;
			}
		i++
		}	
	// have valid string
	return true;
	}
	
	// have invalid string because length is 0
	return false;
}

function isPhoneValid(sString) { 
	// valid numbers
	var validChars = "0123456789- ()";
	var i = 0;
	
	if (sString.length > 0) { 
	
		while (i < sString.length) {
			if (validChars.indexOf(sString.charAt(i)) < 0) { 
				// have invalid number string!
				return false;
			}
		i++
		}	
	// have valid string
	return true;
	}
	
	// have invalid string because length is 0
	return false;
}

function isMoneyNumberValid(sString) { 
	// valid numbers
	var validNums = ".0123456789";
	var i = 0;
	var ch;
	var hasDecimal = false;
	
	if (sString.length > 0) { 
	
		while (i < sString.length) {
			ch = sString.charAt(i);
			if (validNums.indexOf(ch) < 0) { 
				// have invalid number string!
				return false;
			}
			if (ch == '.') {
				if (hasDecimal) {
					//has two decimals
					return false;
				}
				hasDecimal = true;
			}
		i++
		}			
	// have valid string
	return true;
	}
	
	// have invalid string because length is 0
	return false;
}


function isInlineDateRangeHoursValid() { 
var ihours = document.form1.dur.value;
var duration;
var maxvalue = 24;
var minvalue = 1;

	if (ihours != parseInt(ihours) || 
			ihours == "" ||
            ihours > maxvalue ||
			ihours < minvalue ) 
        {	
		alert("The viewer attendance report time range must be a numeric value between " + minvalue + " and " + maxvalue);


	if (ihours > maxvalue) {	 duration = maxvalue;	 }
	 else if (ihours < minvalue) {	 duration = minvalue;	 }
	 else {	 duration = minvalue;	 }
	 
	 document.form1.dur.value = duration.toString();
	 document.form1.dur.focus();
	return false;
		}
}

function isInlineDateRangeDaysValid() { 
var idays = document.form2.dur.value;
var duration;
var maxvalue = 180;
var minvalue = 1;

	if (idays != parseInt(idays) || 
			idays == "" ||
            idays > maxvalue ||
			idays < minvalue ) 
        {	
		alert("The media viewing report time range must be a numeric value between " + minvalue + " and " + maxvalue);

		
	if (idays > maxvalue) {	 duration = maxvalue;	 }
	 else if (idays < minvalue) {	 duration = minvalue;	 }
	 else {	 duration = minvalue;	 }
	 
		document.form2.dur.value = duration.toString();
		document.form2.dur.focus();	
		return false;
			}
}
	

function addMessage(callingElement) {
	callingElement += ENDSTRING_ERROR;
	return (callingElement);
}

	
function isOnlySpaces(sString){
	
	hasOnlySpaces = new Boolean(true);

		for (var i = 0; i < sString.length; i++) {
			if (sString.charAt(i) != ' ') {
				hasOnlySpaces = false;
				break;
			}
		}
		
	if (hasOnlySpaces) {
		
		return false;
	}

	return true;
}





//  Begin Email Validate-->

/* 

This script and many more are available free online at -->
The JavaScript Source!! http://javascript.internet.com -->

V1.1.3: Sandeep V. Tamhankar (stamhankar@hotmail.com) -->
Original:  Sandeep V. Tamhankar (stamhankar@hotmail.com) -->
Changes:
1.1.4: Fixed a bug where upper ASCII characters (i.e. accented letters
international characters) were allowed.

1.1.3: Added the restriction to only accept addresses ending in two
letters (interpreted to be a country code) or one of the known
TLDs (com, net, org, edu, int, mil, gov, arpa), including the
new ones (biz, aero, name, coop, info, pro, museum).  One can
easily update the list (if ICANN adds even more TLDs in the
future) by updating the knownDomsPat variable near the
top of the function.  Also, I added a variable at the top
of the function that determines whether or not TLDs should be
checked at all.  This is good if you are using this function
internally (i.e. intranet site) where hostnames don't have to 
conform to W3C standards and thus internal organization e-mail
addresses don't have to either.
Changed some of the logic so that the function will work properly
with Netscape 6.

1.1.2: Fixed a bug where trailing . in e-mail address was passing
(the bug is actually in the weak regexp engine of the browser; I
simplified the regexps to make it work).

1.1.1: Removed restriction that countries must be preceded by a domain,
so abc@host.uk is now legal.  However, there's still the 
restriction that an address must end in a two or three letter
word.

1.1: Rewrote most of the function to conform more closely to RFC 822.

1.0: Original  

*/

/* 

emailCheck validates an email address
emailStr is the email addresss to validate

checkTLD tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. 

*/

function emailCheck (emailStr, checkTLD) {
return true;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

alert("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Ths username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Ths domain name contains invalid characters.");
return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

alert("The username doesn't seem to be valid.");
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Destination IP address is invalid!");
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("The domain name does not seem to be valid.");
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
alert("This address is missing a hostname!");
return false;
}

// If we've gotten this far, everything's valid!
return true;
}

//  End Email Validate-->
