function remove_value(obj,val) {
	if (obj.value==val) {
		obj.value = "";
	}
}
function add_value(obj,val) {
	if (obj.value=="") {
		obj.value = val;
	}
}
function validate_email(p_sEmail) {
	var regEmail = /^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$/;
	return regEmail.test (p_sEmail);
}
function retrievepassword(path) {
	if (!validate_email(document.loginForm.Email.value)) {
		alert("Please enter a valid email address in the login form to retrieve your password!");
	} else {
		document.location.href = '/retrievepassword.php?path=' + path + '&em=' + document.loginForm.Email.value;
	}
}
function validate(obj) {
	var valid = true;
	var errorStr = "Please fix the following errors in the form\n\n";
	for(var i=0; i<jsvalidarray.length; i++) {
		var arr = jsvalidarray[i].split("|");
		var field = arr[3];
		var label = arr[0];
		var type = arr[1];
		var min_length = arr[5];
		if (type=="text"||type=="textarea"||type=="select"||type=="file") {
			if (obj[field].value.length<min_length) {
				valid = false;
				errorStr += label + " invalid\n";
			} else if (field=="Email") {
				var em_valid = validate_email(obj.Email.value);
				if (!em_valid) {
					valid = false;
					errorStr += "Email invalid\n";
				}
			}
		} else if (type=="password") {
			if(obj.Password.value.length<min_length) {
				valid = false;
				errorStr += "Password invalid\n";
			}
		} else if (type=="boolean"||type=="radio") {
			radchecked = false;
			for(b=0; b<obj[field].length; b++) {
				if (obj[field][b].checked) {
					radchecked = true;
					break;
				}
			}
			if (!radchecked) {
				valid = false;
				errorStr += label+" invalid\n";
			}
		}
	}
	if (!valid) {
		alert(errorStr);
		return false;
	} else {
		return true;
	}
}
function doadmin(qs) {
	var url = "/admin/index.php"+qs;
	var adminwin = window.open(url,"adminwin","width=700,height=500,scrollbars=1,toolbar=1,menu=1,status=1,location=0,screenx=0,screeny=0,top=0,left=0");
	adminwin.focus();
}
function logout() {
	if (confirm("Logging out will empty the items in your cart. Are you sure you want to logout?")) {
		document.location.href='/logout.php';
	}
}
function deleteprod(prodid) {
	if (confirm("Are you sure you want to delete this product?")) {
		document.location.href = "/deleteprod.php?ProdID="+prodid;
	}
}
