function checkInput(fields) {
	if (!fields.name.value || !fields.contact.value || !fields.subject.value || !fields.review.value) {
		alert('Name, Contact, Subject and Comment\n are all required.\nPlease correct this and try again.');
		return false;
	} else {
		var reg = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
		if(!reg.test(fields.contact.value)) {
			alert('You must use valid email address.\nPlease correct this and try again.');
			fields.contact.focus();
			fields.contact.select();
			return false;
		}
	}
}

function checkInput2(fields) {
	if (!fields.name.value || !fields.subject.value || !fields.comment.value) {
		alert('Name, Subject and Comment\n are all required.\nPlease correct this and try again.');
		return false;
	} else if (fields.notify.checked && !fields.contact.value) {
		alert("You have selected to receive the email notifications\nabout comments on your posting.\nPlease enter your email if you'd like to receive them,\nor uncheck the notify option.");
		return false;
	} else if (fields.contact.value) {
		var reg = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
		if(!reg.test(fields.contact.value)) {
			alert('You must use valid email address.\nPlease correct this and try again.');
			fields.contact.focus();
			fields.contact.select();
			return false;
		}
	}
}

function checkInput3(fields) {
	if (!fields.name.value || !fields.contact.value || !fields.lyric.value) {
		alert('All fieds are required.\nPlease correct this and try again.');
		return false;
	} else if (!fields.newtitle.value || !fields.newalbum.value || !fields.newartist.value) {
		alert('You have to all lyric information,\nincluding artist, album and title.\nPlease correct this and try again.');
		return false;
	} else {
		var reg = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
		if(!reg.test(fields.contact.value)) {
			alert('You must use valid email address.\nPlease correct this and try again.');
			fields.contact.focus();
			fields.contact.select();
			return false;
		}
	}
}

function checkInput4(fields) {
	if (!fields.name.value) {
		alert('Your name is required.\nPlease correct this and try again.');
		return false;
	} else if (fields.contact.value) {
		var reg = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
		if(!reg.test(fields.contact.value)) {
			alert('You must use valid email address.\nPlease correct this and try again.');
			fields.contact.focus();
			fields.contact.select();
			return false;
		}
	}
}

function checkInput5(fields) {
	if (!fields.name.value || !fields.contact.value || !fields.message.value) {
		alert('Your name, email and message are all required.\nPlease correct this and try again.');
		return false;
	} else {
		var reg = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
		if(!reg.test(fields.contact.value)) {
			alert('You must use valid email address.\nPlease correct this and try again.');
			fields.contact.focus();
			fields.contact.select();
			return false;
		}
	}
}

function checkEmail(fields) {
	if (fields.contact.value) {
		var reg = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
		if(!reg.test(fields.contact.value)) {
			alert('You must use valid email address.\nPlease correct this and try again.');
			fields.contact.focus();
			fields.contact.select();
			return false;
		}
	}
}

function alertKeywords() {
	alert("Please don't use dirty words on our site...");
}

function checkUncheckAll(theElement) {
	var theForm = theElement.form, z = 0;
	for(z=0; z<theForm.length;z++){
		if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
			theForm[z].checked = theElement.checked;
		}
	}
}

function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) {
	var i, j;
	var prompt;
	// empty existing items
	for (i = selectCtrl.options.length; i >= 0; i--) {
		selectCtrl.options[i] = null; 
	}
	prompt = (itemArray != null) ? goodPrompt : badPrompt;
	if (prompt == null) {
		j = 0;
	} else {
		selectCtrl.options[0] = new Option(prompt);
		j = 1;
	}
	if (itemArray != null) {
		selectCtrl.options[1] = new Option('-- New artist --');
		selectCtrl.options[1].value = '-1';
		j=2;
		// add new items
		for (i = 0; i < itemArray.length; i++) {
			selectCtrl.options[j] = new Option(itemArray[i][0]);
			if (itemArray[i][1] != null) {
				selectCtrl.options[j].value = itemArray[i][1];
			}
			j++;
		}
		// select first item (prompt) for sub list
		selectCtrl.options[0].selected = true;
	}
}
