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];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function nameCheck()
{
    var q1 = document.wine_us.email.value;
    var q2 = document.wine_us.name.value;

    if ( q1 == null || q1 == "" )
    {
        alert("Please enter - Email");
		return;
    }
    else if ( q2 == null || q2 == "" )
    {
        alert("Please enter - Name");
		return;
    }

	document.wine_us.submit();
}

function getTotal()
{
	var total1 = 0;
	var total2 = 0;
	var total3 = 0;
	var total4 = 0;
	var total5 = 0;
	var total6 = 0;
	var grand_total = 0;
	var qty_case = 0;
	var price1 = 24;
	var price2 = 23;
	var price3 = 21;
	var price4 = 23;
	var price5 = 23;
	var price6 = 30;
	var delivery = 0;
	
	var qty1 = document.order.qty1.options[document.order.qty1.selectedIndex].value;
	var qty2 = document.order.qty2.options[document.order.qty2.selectedIndex].value;
	var qty3 = document.order.qty3.options[document.order.qty3.selectedIndex].value;
	var qty4 = document.order.qty4.options[document.order.qty4.selectedIndex].value;
	var qty5 = 0; //document.order.qty5.options[document.order.qty5.selectedIndex].value;
	var qty6 = 0; //document.order.qty6.options[document.order.qty6.selectedIndex].value;
	
	total1 = Math.round(qty1*price1*100)/100;
	total2 = Math.round(qty2*price2*100)/100;
	total3 = Math.round(qty3*price3*100)/100;
	total4 = Math.round(qty4*price4*100)/100;
	//total5 = Math.round(qty5*price5*100)/100;
	//total6 = Math.round(qty6*price6*100)/100;
	
	qty_case = Math.round(((qty1*1 + qty2*1 + qty3*1 + qty4*1 + qty5*1 + qty6*1)/12));
	
	if (qty_case > 0)
	{
		delivery = (25 + Math.round((qty_case-1)*1000)/100)*1.05;
	}

	document.order.total1.value = "$" + total1;
	document.order.total2.value = "$" + total2;
	document.order.total3.value = "$" + total3;
	document.order.total4.value = "$" + total4;
	//document.order.total5.value = "$" + total5;
	//document.order.total6.value = "$" + total6;
	
	//if (document.order.delivery_type[2].checked == true)
	//{
	//	delivery = 0;
	//}
	
	document.order.delivery.value = "$" + delivery;
	document.order.qty_case.value = qty_case + " case(s)";
				
	grand_total = total1 + total2 + total3 + total4 + total5 + total6 + delivery;
	document.order.grand_total.value = "$" + grand_total;
}

function orderCheck()
{
    var q1 = document.order.billing_name.value;
    var q2 = document.order.billing_address.value;
    var q3 = document.order.billing_city.value;
    var q4 = document.order.billing_province.value;
    var q5 = document.order.card_email.value;
    var q6 = document.order.card_name.value;
    var q7 = document.order.card_number.value;
    var q8 = document.order.delivery_phone.value;
    var q9 = document.order.card_exp_month.value;
    var q10 = document.order.card_exp_year.value;
    var q11 = document.order.billing_postal_code.value;
	
	var qty1 = document.order.qty1.options[document.order.qty1.selectedIndex].value;
	var qty2 = document.order.qty2.options[document.order.qty2.selectedIndex].value;
	var qty3 = document.order.qty3.options[document.order.qty3.selectedIndex].value;
	var qty4 = document.order.qty4.options[document.order.qty4.selectedIndex].value;
	var qty5 = 0; //document.order.qty5.options[document.order.qty5.selectedIndex].value;
	var qty6 = 0; //document.order.qty6.options[document.order.qty6.selectedIndex].value;
	
	var qty_case = (qty1*1 + qty2*1 + qty3*1 + qty4*1 + qty5*1 + qty6*1)/12;


	if (isInteger(qty_case))
	{
        alert("All orders must be in multiples of 12 for shipping.");
		return;
	}
    else if ( isEmpty(q1) )
    {
        alert("Please enter - Name");
		document.order.billing_name.focus();				
		return;
    }
    else if ( isEmpty(q2) )
    {
        alert("Please enter - Address");
		document.order.billing_address.focus();				
		return;
    }
    else if ( isEmpty(q3) )
    {
        alert("Please enter - City");
		document.order.billing_city.focus();				
		return;
    }
    else if ( isEmpty(q4) )
    {
        alert("Please enter - Province");
		document.order.billing_province.focus();				
		return;
    }
    else if ( isEmpty(q11) )
    {
        alert("Please enter - Postal Code");
		document.order.billing_postal_code.focus();				
		return;
    }
    else if ( echeck(q5) )
    {
        alert("Please enter - Email");
		document.order.card_email.focus();				
		return;
    }
    else if ( isEmpty(q6) )
    {
        alert("Please enter - Name on Card");
		document.order.card_name.focus();				
		return;
    }
    else if ( isNotInteger(q7) )
    {
        alert("Please enter - Valid Card Number (do not use dots, spaces or dashes)");
		document.order.card_number.focus();				
		return;
    }
    else if ( isEmpty(q8) )
    {
        alert("Please enter - Phone Number. It is Mandatory for Courier Delivery");
		document.order.card_security_code.focus();				
		return;
    }
    else if ( isNotInteger(q9) )
    {
        alert("Please enter - Month");
		document.order.card_exp_month.focus();				
		return;
    }
    else if ( isNotInteger(q10) )
    {
        alert("Please enter - Year");
		document.order.card_exp_year.focus();				
		return;
    }

	document.order.submit();
}

function isInteger(s)
{
      var i;
	  s = "" + s;
      if (isEmpty(s))
      if (isInteger.arguments.length == 1) return 0;
      else return (isInteger.arguments[1] == true);

      for (i = 0; i < s.length; i++)
      {
         var c = s.charAt(i);

         if (!isDigit(c)) return true;
      }

      return false;
}

function isNotInteger(s)
{
	var i;
	s = "" + s;
	if (isEmpty(s))
	{
		return true;
	}
	
	for (i = 0; i < s.length; i++)
	{
		var c = s.charAt(i);
	
		if (!isDigit(c)) 
		{
			return true;
		}
	}
	
	return false;
}

function isEmpty(s)
{
	return ((s == null) || (s.length == 0));
}

function isDigit (c)
{
	return ((c >= "0") && (c <= "9"));
}

function echeck(str) 
{
	if (isEmpty(str))
	{
	   return true;
	}
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){
	   return true;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return true;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return true;
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    return true;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return true;
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    return true;
	 }
	
	 if (str.indexOf(" ")!=-1){
	    return true;
	 }

		 return false;					
}

function go_to_page()
{
	var box2 = document.select_location.selecttogo;
	var gotohere = box2.options[box2.selectedIndex].value;
	document.location = gotohere;			
}			

