// JavaScript Document

function validate_search(){
if (document.quicksearch.keywords.value == ""){
alert("Please enter a keyword or part number to begin your search!");
return false;
}
else
{
return true;
}
}

function login(){
if (document.login.username.value == "" || document.login.password.value == ""){
alert("Please include a user name and password!");
return false;
}
else
{
return true;
}
}

function addProduct(){
if (document.product.secpart.value == "" || document.product.partname.value == "" || document.product.category.options[0].selected == true || document.product.partdescription.value == "" || document.product.image.value == "" || document.product.price.value == "" || document.product.price.value == "0.00" || document.product.reorder.value == "" || document.product.reorder.value == "0" || document.product.reorderqty.value == "" || document.product.reorderqty.value == "0" || document.product.stock.value == "" || document.product.costprice.value == ""){
alert("Please fill in all required fields!");
return false;
}
else if (isNaN(document.product.price.value) || isNaN(document.product.stock.value) || isNaN(document.product.reorder.value) || isNaN(document.product.reorderqty.value) || isNaN(document.product.costprice.value)){
alert("Please enter only numeric values in these fields!");
return false;
}
else
{
return true;
}
}

function editProduct(){
if (document.product.secpart.value == "" || document.product.partname.value == "" || document.product.category.options[0].selected == true || document.product.partdescription.value == "" || document.product.price.value == "" || document.product.price.value == "0.00" || document.product.reorder.value == "" || document.product.reorder.value == "0" || document.product.reorderqty.value == "" || document.product.reorderqty.value == "0" || document.product.stock.value == "" || document.product.costprice.value == ""){
alert("Please fill in all required fields!");
return false;
}
else if (isNaN(document.product.price.value) || isNaN(document.product.stock.value) || isNaN(document.product.reorder.value) || isNaN(document.product.reorderqty.value) || isNaN(document.product.costprice.value)){
alert("Please enter only numeric values in these fields!");
return false;
}
else
{
return true;
}
}

function buyProduct(form,product,stock){
if (form.QUANTITY.value > stock){
	alert("Sorry, you cannot buy that quantity of " + product + ", we only have " + stock + " in stock!");
	return false;
} else {
var agree=confirm("Do you want to add " + form.QUANTITY.value + " " + product + "(s) to your shopping basket?");
if (agree)
	return true;
else
	return false;
}
}

function buyProduct(form,product,stock){
if (form.QUANTITY.value > stock){
	alert("Sorry, you cannot buy that quantity of " + product + ", we only have " + stock + " in stock!");
	return false;
} else {
var agree=confirm("Do you want to add " + form.QUANTITY.value + " " + product + "(s) to your shopping basket?");
if (agree)
	return true;
else
	return false;
}
}

function checkQuantity(quantity,current_quantity,product,stock){
if (quantity.value > stock){
	alert("Sorry, you cannot buy that quantity of " + product + ", we only have " + stock + " in stock!");
	quantity.value = current_quantity;
	return false;
}
}