//  De Luca's Fine Wine Inc. JavaScript ----------
//requires JavaScript1.1 or greater

//Preload images functions
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// validate form to make sure it's not empty (Contact Form)
function valEmpty(form1)
{
	var address = document.form1.address.value;
	var phone = document.form1.phone.value;
	var fax = document.form1.fax.value;
	var email = document.form1.email.value;
	var comment = document.form1.comment.value;
	var econtact = "a way to contact you";
	var ecomment = "a comment";
	var pErr = "Please enter ";
	var bErr = " before submitting form.";

	if ((address == "") && (phone == "") && (fax == "") && (email == ""))
	{
		alert(pErr + econtact + bErr);
		document.form1.address.focus();
		return false;
	}
	if (comment == "")
	{
		alert(pErr + ecomment + bErr);
		document.form1.comment.focus();
		return false;
	}
}

// check that the valEmpty function worked (Contact Form)
function valForm(form1)
{

	if (valEmpty() == false)
	{
		return false;
	} else
	  {
		return true;
	  }
}

// validate form to make sure it's not empty (CGI Login)
function valEmptyAdmin(form1)
{
	var username = document.form1.username.value;
	var passwd = document.form1.passwd.value;
	var eusername = "a User Name";
	var epasswd = "a Password";
	var pErr = "Please enter ";
	var bErr = " before submitting form.";

	if (username == "")
	{
		alert(pErr + eusername + bErr);
		document.form1.username.focus();
		return false;
	}
	if (passwd == "")
	{
		alert(pErr + epasswd + bErr);
		document.form1.passwd.focus();
		return false;
	}
}

// check that the valEmpty function worked (CGI Login)
function valFormAdmin(form1)
{

	if (valEmptyAdmin() == false)
	{
		return false;
	} else
	  {
		return true;
	  }
}

// validate form to make sure it's not empty (CGI Edit)
function valEmptyEdit(form1)
{
	var item_name = document.form1.item_name.value;
	var item_desc = document.form1.item_desc.value;
	var item_price = document.form1.item_price.value;
	var eitem_name = "an Item Name";
	var eitem_desc = "an Item Description";
	var eitem_price = "an Item Price";
	var pErr = "Please enter ";
	var bErr = " before submitting form.";

	if (item_name == "")
	{
		alert(pErr + eitem_name + bErr);
		document.form1.item_name.focus();
		return false;
	}
	if (item_desc == "")
	{
		alert(pErr + eitem_desc + bErr);
		document.form1.item_desc.focus();
		return false;
	}
	if (item_price == "")
	{
		alert(pErr + eitem_price + bErr);
		document.form1.item_price.focus();
		return false;
	}
	if(isNaN(document.form1.item_price.value)==true)
	{
		alert('Price must be numeric, please try again!')
		document.form1.item_price.value = "";
		document.form1.item_price.focus();
		return false;
	}
}

// check that the valEmptyEdit function worked (CGI Edit)
function valFormEdit(form1)
{

	if (valEmptyEdit() == false)
	{
		return false;
	} else
	  {
		return true;
	  }
}

// validate form to make sure it's not empty (CGI Add)
function valEmptyAdd(form1)
{
	var end_date = document.form1.end_date.value;
	var item_name = document.form1.item_name.value;
	var item_desc = document.form1.item_desc.value;
	var item_price = document.form1.item_price.value;
	var eend_date = "a valid End Date";
	var eitem_name = "an Item Name";
	var eitem_desc = "an Item Description";
	var eitem_price = "an Item Price";
	var pErr = "Please enter ";
	var bErr = " before submitting form.";

	if (end_date == "")
	{
		alert(pErr + eend_date + bErr);
		document.form1.end_date.focus();
		return false;
	}
	if (item_name == "")
	{
		alert(pErr + eitem_name + bErr);
		document.form1.item_name.focus();
		return false;
	}
	if (item_desc == "")
	{
		alert(pErr + eitem_desc + bErr);
		document.form1.item_desc.focus();
		return false;
	}
	if (item_price == "")
	{
		alert(pErr + eitem_price + bErr);
		document.form1.item_price.focus();
		return false;
	}
	if(isNaN(document.form1.item_price.value)==true)
	{
		alert('Price must be numeric, please try again!')
		document.form1.item_price.value = "";
		document.form1.item_price.focus();
		return false;
	}
}

// check that the valEmptyAdd function worked (CGI Add)
function valFormAdd(form1)
{

	if (valEmptyAdd() == false)
	{
		return false;
	} else
	  {
		return true;
	  }
}

// validate Change Password function
function valEmptyChangePw(form1)
{
	var old_passwd = document.form1.old_passwd.value;
	var new_passwd = document.form1.new_passwd.value;
	var confirm_passwd = document.form1.confirm_passwd.value;
	var eold_passwd = "Old Password";
	var enew_passwd = "New Password";
	var econfirm_passwd = "Confirm New Password";
	var pErr = "Please enter ";
	var bErr = " before submitting form.";

	if (old_passwd == "")
	{
		alert(pErr + eold_passwd + bErr);
		document.form1.old_passwd.focus();
		return false;
	}
	if (new_passwd == "")
	{
		alert(pErr + enew_passwd + bErr);
		document.form1.new_passwd.focus();
		return false;
	}
	if (confirm_passwd == "")
	{
		alert(pErr + econfirm_passwd + bErr);
		document.form1.confirm_passwd.focus();
		return false;
	}
	if (confirm_passwd != new_passwd)
	{
		alert("New Password and Confirm New Password do not match! Please try again.");
		document.form1.confirm_passwd.value = "";
		document.form1.confirm_passwd.focus();
		return false;
	}
}

// check that the valEmpty function worked
function valFormChangePw(form1)
{

	if (valEmptyChangePw() == false)
	{
		return false;
	} else
	  {
		return true;
	  }
}

// validate form to make sure something was selected (CGI List)
function valEmptyList(form1)
{
	var item = document.form1.item.value;
	var eitem = "an Item";
	var pErr = "Please choose ";
	var bErr = " before submitting form.";

	if (item == "Choose an Item")
	{
		alert(pErr + eitem + bErr);
		document.form1.item.focus();
		return false;
	}
}

// check that the valEmptyList function worked (CGI List)
function valFormList(form1)
{

	if (valEmptyList() == false)
	{
		return false;
	} else
	  {
		return true;
	  }
}



//-->
