/* Swap the active CSS */
function setActiveStyleSheet(title) {
	if (document.getElementsByTagName) {
		for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
			if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) a.disabled = true;
			if (a.getAttribute("title") == title) a.disabled = false;
		}
	}
}

/* validate the registration form */
function validateRegister(oForm) {
	if (oForm.terms.checked == false) {
		alert('You must state that you agree to the terms and conditions to register.');
		return false;
	} else {
		var bValid = true;

		//check for security code
		if (oForm.code.value.length < 4) {
			alert('Please enter the security code');
			return false;
		}

		//check for registration and password
		if (oForm.password.value.length < 5) {
			alert('Your password must be 5 or more characters');
			return false;
		}
		if (oForm.password.value != oForm.confirm.value) {
			alert('Your password and confirmation do not match');
			return false;
		}

		//check for valid username
		if (oForm.username.value.length < 5) {
			alert('Your username must be 5 or more charachters');
			return false;
		}

		//check normal form
		if (oForm.name.value == '' || 
			oForm.address1.value == '' || 
			oForm.postcode.value == '' ||
			oForm.artistType.options[oForm.artistType.selectedIndex].value == '[please select]' ||
			oForm.dobDD.value == '' ||
			oForm.dobYYYY.value == '') {
			bValid = false;
		}
		//check email
		if (oForm.email.value == '') {
			bValid = false;
		}

		//return correctly
		if (bValid == false) {
			alert('Please fill out all required fields *');
			return false;
		}
	}
}

/* validate the gallery registration form */
function validateRegisterGallery(oForm) {
	if (oForm.terms.checked == false) {
		alert('You must state that you agree to the terms and conditions to register.');
		return false;
	} else {
		var bValid = true;

		//check for security code
		if (oForm.code.value.length < 4) {
			alert('Please enter the security code');
			return false;
		}

		//check for registration and password
		if (oForm.password.value.length < 5) {
			alert('Your password must be 5 or more characters');
			return false;
		}
		if (oForm.password.value != oForm.confirm.value) {
			alert('Your password and confirmation do not match');
			return false;
		}

		//check for valid username
		if (oForm.username.value.length < 5) {
			alert('Your username must be 5 more more charachters');
			return false;
		}

		//check normal form
		if (oForm.name.value == '' || 
			oForm.address1.value == '' || 
			oForm.postcode.value == '') {
			bValid = false;
		}
		//check email
		if (oForm.email.value == '') {
			bValid = false;
		}

		//return correctly
		if (bValid == false) {
			alert('Please fill out all required fields *');
			return false;
		}
	}
}

/* validate the profile form */
function validateProfile(oForm) {
	var bValid = true;

	//check normal form
	if (oForm.name.value == '' || 
		oForm.artistType.options[oForm.artistType.selectedIndex].value == '[please select]') {
		bValid = false;
	}

	//return correctly
	if (bValid == false) {
		alert('Please fill out all required fields *');
		return false;
	}
}

/* validate the settings form */
function validateSettings(oForm) {
	var bValid = true;

	//check for registration and password
	if (oForm.password.value.length < 5) {
		alert('Your password must be entered to update this page');
		return false;
	}

	//check normal form
	if (oForm.name.value == '' || 
		oForm.address1.value == '' || 
		oForm.postcode.value == '') {
		bValid = false;
	}

	//return correctly
	if (bValid == false) {
		alert('Please fill out all required fields *');
		return false;
	}
}

/* validate change login form */
function validateChangeLogin(oForm) {

	//check for registration and password
	if (oForm.newPassword.value.length < 5) {
		alert('Your new password must be 5 or more characters');
		return false;
	}
	if (oForm.newPassword.value != oForm.confirmPassword.value) {
		alert('Your new password and confirmation do not match');
		return false;
	}
}

/* validate gallery upload form */
function validateGalleryUpload(oForm) {
	//check normal form
	if (oForm.image.value == '' || 
		oForm.title.value == '' ||
		oForm.artCategory.options[oForm.artCategory.selectedIndex].value == '[please select]') {

		alert('Please fill out all required fields *');
		return false;
	}
}

/* validate sale item upload form */
function validateSaleItemUpload(oForm) {
	//check price
	if (isNaN(oForm.price.value) || oForm.price.value == '') {
		alert('Please enter a numeric price for the item.');
		return false;
	}

	//check normal form
	if (oForm.image.value == '' || 
		oForm.title.value == '' ||
		oForm.artCategory.options[oForm.artCategory.selectedIndex].value == '[please select]') {

		alert('Please fill out all required fields *');
		return false;
	}
}

/* validate showcase upload form */
function validateShowcaseUpload(oForm) {
	//check normal form
	if (oForm.image.value == '' || 
		oForm.title.value == '' ||
		oForm.article.value == '' ||
		isNaN(oForm.artCategory.value) || 
		oForm.artCategory.value == '[please select]' ||
		oForm.artCategory.options[oForm.artCategory.selectedIndex].value == '[please select]') {

		alert('Please fill out all required fields *');
		return false;
	}
}

