function pop_shipping_alert() {
	 window.open("https://www.bacchusandvenus.com/cgi-bin/shop/shop.cgi?choice=shipping_alert","","height=330,width=450,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,history=no");
}
//global variable for error flag
var errfound = false;
//function to validate by length
function validlength(item, len) {
   return (item.length >= len);
}
function error(elem, text) {
// abort if we already found an error
   if (errfound) return;
   window.alert(text);
   elem.focus();
   errfound = true;
   mail=0;
}
//function to validate an email address
function validemail(item) {
   if (!validlength(item, 5) && item != "none" ) return false;
   if (item.indexOf ('\@', 0) == -1 && item != "none" ) return false;
   return true;
}    
function error2(elem, text) {
// abort if we already found an error
   if (errfound) return;
   window.alert(text);
   elem.focus();
   errfound = true;
}
// main validation function
function validate_zip() {
   errfound = false;
                         if
(!validlength(document.zip.ship_zip.value,5))
                             error(document.zip.ship_zip,"Sorry, a Shipping Zip Code is required to continue.\\n\\nWe need this information to provide you with various shipping methods and costs.\\n\\nSorry, at this time we do not ship internationally. Call the winery for details.");
 			if (document.zip.ship_state.selectedIndex==0)
                                error2(document.zip.ship_state,"Sorry, Invalid State.\\n\\nThis field is required.\\n\\nThank you.");
  
   return !errfound; /* true if there are no errors */

}
function validate_state() {
   errfound = false;
                         if
(!document.zip.ship_state.value)
                             error(document.zip.ship_state,"Sorry, the Shipping State is required to continue.");
  
   return !errfound; /* true if there are no errors */

}

function validate_options() {
   errfound = false;
                       if (document.specs.option_1.selectedIndex==0)
                                error(document.specs.option_1,"Please, select a Color!");
                       if (document.specs.option_2.selectedIndex==0)
                                error(document.specs.option_2,"Please, select a !");
   return !errfound; /* true if there are no errors */
}
function validate_option_1() {
   errfound = false;
                       if (document.specs.option_1.selectedIndex==0)
                                error(document.specs.option_1,"Please, select a Color!");

   return !errfound; /* true if there are no errors */
}
function validate_option_2() {
   errfound = false;
                       if (document.specs.option_2.selectedIndex==0)
                                error(document.specs.option_2,"Please, select a !");

   return !errfound; /* true if there are no errors */
}
var radio=0;
// main validation function
function validate_shipping() {
   errfound = false;
                       if (document.order.shipping.selectedIndex==0)
                                error(document.order.shipping_cost,"Sorry, Invalid Shipping Method.\\n\\nPlease select the Shipping Method.\\n\\nThank you.");
						if (document.order.payment_method.selectedIndex==0)
                                error(document.order.payment_method,"Sorry, Invalid Payment Type.\\n");
                        if (!validlength(document.order.cc_number.value,8) && document.order.payment_method.selectedIndex!=4)
                           error(document.order.cc_number,"Sorry, Invalid Credit Card Number.\\n");
                        if (document.order.cc_expmonth.selectedIndex==0 && document.order.payment_method.selectedIndex!=4)
                                error(document.order.cc_expmonth,"Sorry, Invalid Expiration Month.\\n");
                        if (document.order.cc_expyear.selectedIndex==0 && document.order.payment_method.selectedIndex!=4)
                                error(document.order.cc_expyear,"Sorry, Invalid Expiration Year.\\n");
                         if (!validlength(document.order.bill_first_name.value,2))
                            error(document.order.bill_first_name,"Sorry, Invalid Billing Fisrt Name");
                         if
(!validlength(document.order.bill_last_name.value,2))
                             error(document.order.bill_last_name,"Sorry, Invalid Billing Last Name");
                        if (!validlength(document.order.bill_street.value,2))
                                error(document.order.bill_street,"Sorry, Invalid Billing Street");
                        if (!validlength(document.order.bill_city.value,2))
                                error(document.order.bill_city,"Sorry, Invalid Billing City");
                        if (document.order.bill_state.selectedIndex==0)
                                error(document.order.bill_state,"Sorry, Invalid Billing State/Province.");
                        if (!validlength(document.order.bill_zip.value,5))
                                error(document.order.bill_zip,"Sorry, Invalid Billing Zip Code");
                        if (!validlength(document.order.bill_country.value,2))
                                error(document.order.bill_country,"Sorry, Invalid Billing Country");
                        if (!validlength(document.order.bill_phone.value,10))
                                error(document.order.bill_phone,"Sorry, Invalid Billing Phone Number");
                        if (!validemail(document.order.bill_email.value))
                                error(document.order.bill_email,"Sorry, Invalid Billing Email Address.\\n\\nIf you don't have an e-mail, type in:\\n\\nnone");
                       if (!validlength(document.order.ship_first_name.value,2))
                                error(document.order.ship_first_name,"Sorry, Invalid Shipping First Name");
                       if (!validlength(document.order.ship_last_name.value,2))
                                error(document.order.ship_last_name,"Sorry, Invalid Shipping Last Name");
                        if (!validlength(document.order.ship_street.value,2))
                                error(document.order.ship_street,"Sorry, Invalid Shipping Street");
                        if (!validlength(document.order.ship_city.value,2))
                                error(document.order.ship_city,"Sorry, Invalid Shipping City");
                        if (document.order.ship_state.selectedIndex==0)
                                error(document.order.ship_state,"Sorry, Invalid  Shipping State/Province.\\n");
                        if (!validlength(document.order.ship_country.value,2))
                                error(document.order.ship_country,"Sorry, Invalid Shipping Country");
                        if (!validlength(document.order.ship_phone.value,10))
                                error(document.order.ship_phone,"Sorry, Invalid Shipping Phone Number");
                        if (!validemail(document.order.ship_email.value))
                                error(document.order.ship_email,"Sorry, Invalid Shipping Email Address.\\n\\nIf you don't have an e-mail, type in:\\n\\nnone");

   return !errfound; /* true if there are no errors */

}

        function copyAddress() {
                document.order.ship_company_name.value = document.order.bill_company_name.value
                document.order.ship_first_name.value = document.order.bill_first_name.value
                document.order.ship_last_name.value = document.order.bill_last_name.value
                document.order.ship_street.value = document.order.bill_street.value
                document.order.ship_city.value = document.order.bill_city.value
                document.order.ship_state.value = document.order.bill_state.value
                document.order.ship_country.value = document.order.bill_country.value
                document.order.ship_phone.value = document.order.bill_phone.value
                document.order.ship_email.value = document.order.bill_email.value
        }
//Math funtion
function currencyPad(anynum,width) {
                //returns number as string in $xxx,xxx.xx format.
                anynum = "" + eval(anynum)
                //evaluate (in case an expression sent)
                intnum=0
                if (anynum >= 1) {
                         intnum = parseInt(anynum)
                }    
                //isolate integer portion
                intstr = ""+intnum
                //add comma in thousands place.
                if (intnum >= 1000) {
                        intlen = intstr.length
                        temp1=parseInt(""+(intnum/1000))
                        temp2=intstr.substring(intlen-3,intlen)
                        intstr = temp1+","+temp2
                }
                if (intnum >= 1000000) {
                        intlen = intstr.length
                        temp1=parseInt(""+(intnum/1000000))
                        temp2=intstr.substring(intlen-7,intlen)
                        intstr = temp1+","+temp2        
                }
                decnum = Math.abs(parseFloat(anynum)-intnum) //isolate decimal portion
                decnum = decnum * 100 // multiply decimal portion by 100.
                decstr = "" + Math.abs(Math.round(decnum))
                while (decstr.length < 2) {
                        decstr = "0" + decstr
                }
                retval = intstr + "." + decstr
                if (intnum < 0) {
                        retval=retval.substring(1,retval.length)
                        retval="("+retval+")"        
                }       
                retval = "\$"+retval
                while (retval.length < width){
                        retval=" " + retval
                }
                return retval
        }

function updateTotals(shipping) {
volume_discount = eval(document.order.volume_discount.value);
salestax = eval(document.order.tax.value);
subtotal = eval(document.order.subtotal.value);
inselect = shipping.options[shipping.selectedIndex].value
inse = inselect.indexOf('|',1);
insecost = inselect.substring(inse+1,inselect.length);
document.order.shipping_cost.value = currencyPad(insecost,10)
shippingcharge=eval(insecost)
document.order.total.value = currencyPad(subtotal-volume_discount+salestax+shippingcharge,10)
radio=1
}

//date
date=new Date();
var time=new Date(), year;
if (time.getFullYear)
  year=time.getFullYear();
else
{
  year=time.getYear();
  if (year<2000)
  year=year+1900;
}
var created ="";
if (year!=2000) { created = "2000 - ";}

function mois() {
  argnr = mois.arguments.length
  for (var i = 0; i < argnr; i++)
  this[i+1] = mois.arguments[i]
  }
var isnMonths= new mois("January","February","March","April","May","June","July","August","September","October","November","December");

var jours= new mois("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");
jours[0]="Sunday";

// open window
function newwin(page,name,attributes)
{
        window.open(page,name,attributes);
}

function quick_nav (url) {
	var jumpto = url.options[url.selectedIndex].value;
	if (jumpto != "") {
		top.location.href = jumpto
	}
	return true;
}
function validate_options() {
   errfound = false;
                       if (document.specs.option_1.selectedIndex==0)
                                error(document.specs.option_1,"Please, select a Color!");
                       if (document.specs.option_2.selectedIndex==0)
                                error(document.specs.option_2,"Please, select a !");
   return !errfound; /* true if there are no errors */
}
function validate_option_1() {
   errfound = false;
                       if (document.specs.option_1.selectedIndex==0)
                                error(document.specs.option_1,"Please, select a " + option1 +"!");

   return !errfound; /* true if there are no errors */
}
function validate_option_2() {
   errfound = false;
                       if (document.specs.option_2.selectedIndex==0)
                                error(document.specs.option_2,"Please, select a " + option2 +"!");

   return !errfound; /* true if there are no errors */
}

