/* */

// the next 2 functions set/swap the checkboxes called "checks" in the form called "xx"
function	setchecks() {
	var xx = document.xx.checks;
	for (i=0; xx[i]; i++) {
		xx[i].checked = true;
	}
}
function	swapchecks() {
	var xx = document.xx.checks;
	for (i=0; xx[i]; i++) {
		xx[i].checked = !xx[i].checked;
	}
}
// this function again works on a form called xx but this adds a number to the boses called "quantity"
function	qtyadd(increment) {
	var xx = document.xx.quantity;
	var qty = 0;
	for (i=0; xx[i]; i++) {
		qty = parseInt(xx[i].value);
		if (qty>0 || increment>0) { xx[i].value = qty + increment; }
	}
}
// --------------------------------------------------------------------------

// fire off a popup window
function popwindow(contentname, titletext) {
	windowHandle=window.open(contentname, titletext,"toolbar=no,scrollbars=yes,menubar=no,width=500,height=300");
	windowHandle.focus();
	windowHandle.document.close();
}

/* Registration form checker */
function checkRegForm() {
	if (checkMail(document.forms[0].email.value)) {
		if (document.forms[0].passwd.value>'') {
			if (document.forms[0].fullname.value) {
				if (document.forms[0].phone.value) {
					return true;
				} else {
					alert('You must enter a phone number');
				}
			} else {
				alert('You must enter you full name');
			}
		} else {
			alert('You must enter a password');
		}
	} 
	return false;
}

/* Profile form checker */
function checkProfileForm() {
	if (checkMail(document.forms[0].email.value)) {
		return true;
	} 
	return false;
}

/* Album form checker */
function checkAlbumForm() {
	if (document.forms[0].description.value>'') {
		return true;
	} else {
		alert('You must enter a name for your album');
	}
	return false;
}

/* Price form checker */
function checkPriceForm() {
	if (document.forms[0].code.value>'') {
		return true;
	} else {
		alert('You must enter a price code');
	}
	return false;
}

/* Shipping form checker */
function checkShipForm() {
	if (document.forms[0].code.value>'') {
		return true;
	} else {
		alert('You must enter a shipping code');
	}
	return false;
}

/* Profile form checker */
function checkOrderForm() {
	if (checkMail(document.forms[0].email.value)) {
		if (document.forms[0].phone.value>'') {
			if (document.forms[0].address.value>'') {
				return true;
			} else {
				alert('You must enter a postal address');
			}
		} else {
			alert('You must enter a phone number');
		}
	} 
	return false;
}

/* Basket form checker */
function checkBasket() {
	var radio_choice = false;
	// Loop from zero to the one minus the number of radio button selections
	for (counter = 0; counter < document.xx.shipopt.length; counter++) {
		if (document.xx.shipopt[counter].checked) {
			radio_choice = true; 
		}
	}
	if (radio_choice) {
		return true;
	} else {
		alert('Please chose a shipping option before proceeding');
	}
	return false;
}

/* checkMail() function used with the permission of the author see:
				http://www.quirksmode.org/js/mailcheck.html
*/
function checkMail(x) {
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) { 
		return true; 
	} else { 	
		alert('Sorry, "'+x+'" is not a valid email address'); 
		return false; 
	}
}

function setPasswd(newpass) {
	document.forms[0].passmd5.value=calcMD5(newpass);
}

/* Routines for handling nevigation menu elements */
function show(element){
	document.getElementById(element).style.visibility = 'visible';
}
	
function hide(element){
	document.getElementById(element).style.visibility = 'hidden';
}
	
function changeClass(element, newClass){
	document.getElementById(element).className= newClass;
}