function searchSubmit() {
	if (document.getElementById("searchQuery").value.length) return true;
	document.getElementById("searchQuery").focus();
	return false;
}

function bpass() {
	if (validateComplete(document.loginForm.UserName)) {
		if (emptyField(document.loginForm.Password)) {
			showError("Please fill in password.\nSpaces are not a valid password.");
			document.loginForm.Password.focus();
			return false;
		} else
			//loginSubmit();
			return true;
	} else document.loginForm.UserName.focus();
	return false;
}

// login form validation
function validateComplete(UserName, ErrorMsg) {
	if (ParseResult = badEmailField(UserName)) {
		switch (ParseResult) {
			case 101: {
				AnswerResult = confirm(EmailConfirmMsgTop + '  ' + UserName.value + '\n\nEmail addresses do not typically contain www\n' + EmailConfirmMsgBottom);
				if (AnswerResult == false) return false;
				break;
			}

			case 102: {
				AnswerResult = confirm(EmailConfirmMsgTop + '  ' + UserName.value + '\n\n Email addresses must end in one of the following:  .com, .net, .org, .mil, .edu or a country code\n' + EmailConfirmMsgBottom);
				if (AnswerResult == false) return false;
				break;
			}

			case 103: {
				AnswerResult = confirm(EmailConfirmMsgTop + '  ' + UserName.value + '\n\nAOL appears to be misspelled.\n' + EmailConfirmMsgBottom);
				if (AnswerResult == false) return false;
				break;
			}

			case 104: {
				AnswerResult = confirm(EmailConfirmMsgTop + '  ' + UserName.value + '\n\nYAHOO appears to be misspelled.\n' + EmailConfirmMsgBottom);
				if (AnswerResult == false) return false;
				break;
			}

			case 105: {
				AnswerResult = confirm(EmailConfirmMsgTop + '  ' + UserName.value + '\n\nEXCITE appears to be misspelled\n' + EmailConfirmMsgBottom);
				if (AnswerResult == false) return false;
				break;
			}

			case 106: {
				AnswerResult = confirm(EmailConfirmMsgTop + '  ' + UserName.value + '\n\nWEBTV appears to be misspelled\n' + EmailConfirmMsgBottom);
				if (AnswerResult == false) return false;
				break;
			}

			case true: {
				showError(ErrorMsg);
				return false;
			}
		}
	}

	return true;
}

function loginNewSubmit() {
	return validateComplete(document.loginNewForm.newUserName, "Please Fill In Correct Email as User Name.");
}
function pwdReminderSubmit() {
	return validateComplete(document.pwdReminderForm.UserEmail, "Please Fill In Correct Email as User Name.");
}

// variables for Email Validation entries in validateComplete functions
var EmailConfirmMsgTop = 'There may be an error in the email you entered:';
var EmailConfirmMsgBottom = '\nPlease make sure your email is correct.  We use email to contact prize winners.\n Click "ok" if the email entered was correct.\n Click "Cancel" to go back and edit the address you entered.';
var AnswerResult = -2;
var ParseResult = -2;

function Status(SomeText) {
	if (SomeText) { window.status = SomeText; } else { window.status = ""; }
}

function emptyField(textObj) {
	var thisChar;

	if(textObj.value.length == 0) return true;

	else {

			for (var i=0; i < textObj.value.length; i++)
				{
				thisChar = textObj.value.substring(i, i+1);
				if (thisChar != ' ')
					return false;
				}
		 }

	return true;
}

function badZIPField(textObj) {
	var ValidChr="0123456789-";
	var thisChar;
	var dashCount = 0;

	for (var i=0; i < textObj.value.length; i++)
		{
			thisChar = textObj.value.substring(i, i+1);
			if ( ValidChr.indexOf(thisChar) == -1 )
				return true;
			if ( thisChar == "-" ) dashCount++;
			if ( dashCount > 1 ) return true;
		}

	return false;
}

function badEmailField(textObj) {
	var thisChar;
	var atCount = 0;
	var dotCount = 0;
	var atPos = -2;
	var DotPositionAssigned = 0;
	var atDotPos = -2;
	var lastDotPos = -2;
	var InvalidChr="!#$%&*?()<>,;:\"\\\'[]/`{}~|"

	for (var i=0; i < textObj.value.length; i++)
		{
			thisChar = textObj.value.substring(i, i+1);

			if ( InvalidChr.indexOf(thisChar) > -1 )
				return true;

			if ( thisChar == " " ) return true;

			if ( thisChar == "." )
				{
				if ( (i == textObj.value.length - 1) || (i == 0) ) return true;
				else
					{
					dotCount++;
					// check if prev char is '.'
					// dotCount > 1 condition eliminates incorrect procedure exit in case of 'n.nnnn@nnn.nn'
					if ( ((lastDotPos == i - 1) && (dotCount > 1)) || (atPos == i - 1) ) return true;
					lastDotPos = i;
					// get position of first dot after @
					if (atPos > 0 && DotPositionAssigned == false)
						{
							DotPositionAssigned = true;
							atDotPos = i;
						}
					}
				}

			if ( thisChar == "@" )
				{
				if ( (i == textObj.value.length - 1) || (i == 0) || (lastDotPos == i - 1) ) return true;
				else
					{
					atCount++;
					// get position of @
					if (atCount == 1) atPos = i;
					}
				}


			if ( atCount > 1 ) return true;
		}

	if (atCount == 1 && atDotPos < atPos) return true;

	if ( atCount == 0 ) return true;

	if ( dotCount == 0 ) return true;


	// four first character www. typos
	thisChar = textObj.value.substring(0, 4);

	switch (thisChar) {
		case "www.":
			return 101;
		case "WWW.":
			return 101;
	}


	// second level domains typos
	thisChar = textObj.value.substring(atPos,atDotPos+1);

	switch (thisChar) {
		case "@al.":
			return 103;
		case "@AL.":
			return 103;
		case "@sol.":
			return 103;
		case "@SOL.":
			return 103;
		case "@a0l.":
			return 103;
		case "@A0L.":
			return 103;
		case "@aolc.":
			return 103;
		case "@AOLC.":
			return 103;
		case "@aool.":
			return 103;
		case "@AOOL.":
			return 103;
		case "@yaho.":
			return 104;
		case "@YAHO.":
			return 104;
		case "@yoohoo.":
			return 104;
		case "@YOOHOO.":
			return 104;
		case "@excire.":
			return 105;
		case "@EXCIRE.":
			return 105;
		case "@ebtv.":
			return 106;
		case "@EBTV.":
			return 106;
	}


	// last characters top level domain typos
	thisChar = textObj.value.substring(lastDotPos+1, textObj.value.length);

	switch (thisChar) {
		case "cm":
			return 102;
		case "CM":
			return 102;
		case "con":
			return 102;
		case "CON":
			return 102;
		case "co":
			return 102;
		case "CO":
			return 102;
		case "ocm":
			return 102;
		case "OCM":
			return 102;
		case "ney":
			return 102;
		case "NEY":
			return 102;
		case "ent":
			return 102;
		case "ENT":
			return 102;
		case "comj":
			return 102;
		case "COMJ":
			return 102;
		case "com'":
			return 102;
		case "COM'":
			return 102;
	}


	// no typos found
	return false;
}


function answerNotSelectedRadio(radioObj) {
	for (var i = 0; i < radioObj.length; i++)
		{
			if (radioObj[i].checked == true) return false;
		}

	return true;
}

function answerNotSelectedDropDown(selectObj) {
	if (selectObj.selectedIndex == 0) return true;
	else return false;
}
