d=document;
aPrice=new Array();

aPrice['s06']=25;
aPrice['s06-c']=30;
aPrice['z06']=28;
aPrice['p06-2']=45;
aPrice['p06']=32;
aPrice['g06']=20;

aPrice['p05']=38;
aPrice['p05-c']=25;
aPrice['g05']=25;
aPrice['z05']=25;
aPrice['s05']=35;
aPrice['s05-c']=20;
aPrice['journey']=25;
aPrice['promise']=30;
aPrice['soul']=22;
aPrice['presumed']=25;
aPrice['caught']=25;
aPrice['plead']=20;
aPrice['gifted']=35;
aPrice['wild']=25;
aPrice['patriarch']=25;
aPrice['matriarch']=35;

function updateTotal(poEl) {

   // exit if not a number unless changing state
   if (isNaN(poEl.value) && poEl.name!='state') {
      poEl.value='';
      return false;
   }
   var fTotal=0;
   var fTax=0;
   var sTax=0;
   
   // update order subtotal
   var formObj = d.getElementById('shoppingCartForm');
   var quantityFields = formObj.getElementsByTagName('input');
   var sName = '';
   for (i=0; i<quantityFields.length; i++) {
      if (quantityFields[i].className == 'quantityField') {
         sName = quantityFields[i].name.substr(4);
         fTotal += quantityFields[i].value * aPrice[sName];
      }
   }
   
   d.getElementById('subTotalField').value = fTotal;
   d.getElementById('fld_subtotal').innerHTML = '$'+fTotal;   
      
   // add tax for CA
   if (d.getElementById('stateField').value=='CA') {
      fTax=Math.round( (fTotal * .0875) * 100 )/100;
      fTotal+=fTax;
      if (fTax)
         sTax='$'+fTax
   }  else {
      sTax='0';
   }

   d.getElementById('fld_tax').innerHTML=sTax;  
   d.getElementById('fld_tax').value=fTax;

      // update total   
   if (fTotal)
      var sTotal='$'+fTotal;
   else
      var sTotal='';

   d.getElementById('fld_total').innerHTML = sTotal;
   d.getElementById('totalField').value = fTotal;

   // exit if only changing state
   if (poEl.name=='state')
      return true;   
   
   // update subtotal for this wine
   if (poEl.value)
      var sSubTotal='$' + aPrice[poEl.name.substr(4)]*poEl.value;
   else 
      var sSubTotal='';
   d.getElementById('sub_' + poEl.name.substr(4)).innerHTML=sSubTotal;
}

function validate(poForm) {
   var err = document.getElementById('err'); 
   var errHTML = '';
   if (poForm.first_name.value == '') {
   	 errHTML += '&#149; Please enter a first name<br>';
   }
   if (poForm.last_name.value == '') {
   	 errHTML += '&#149; Please enter a last name<br>';
   }
   if (poForm.address1.value == '') {
   	errHTML += '&#149; Please enter an address<br>';
   }			
   if (poForm.city.value == '') {
   	errHTML += '&#149; Please enter a city<br>';
   }		
   if (poForm.zip.value == '') {
   	errHTML += '&#149; Please enter a zip code<br>';
   }						
   if (poForm.day_phone_a.value == '') {
   	errHTML += '&#149; Please enter a phone number<br>';
   }						
   if (poForm.email.value == '') {
   	errHTML += '&#149; Please enter an email address<br>';
   }
   if (errHTML) {
   	err.innerHTML = 'Please correct the following errors:<br>' + errHTML;
   	return false;
   } else
   	return true; 	
			
}

	var HOST = '<$MTBlogHost$>';
	// Copyright (c) 1996-1997 Athenia Associates.
	// http://www.webreference.com/js/
	// License is granted if and only if this entire
	// copyright notice is included. By Tomer Shiran.
	
	function setCookie (name, value, expires, path, domain, secure) {
	    var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
	    document.cookie = curCookie;
	}
	
	function getCookie (name) {
	    var prefix = name + '=';
	    var c = document.cookie;
	    var nullstring = '';
	    var cookieStartIndex = c.indexOf(prefix);
	    if (cookieStartIndex == -1)
	        return nullstring;
	    var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
	    if (cookieEndIndex == -1)
	        cookieEndIndex = c.length;
	    return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
	}
	
	function deleteCookie (name, path, domain) {
	    if (getCookie(name))
	        document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
	
	function fixDate (date) {
	    var base = new Date(0);
	    var skew = base.getTime();
	    if (skew > 0)
	        date.setTime(date.getTime() - skew);
	}
	
	function rememberMe (f) {
	    var now = new Date();
	    fixDate(now);
	    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
	    setCookie('mtcmtauth', f.author.value, now, '', HOST, '');
	    setCookie('mtcmtmail', f.email.value, now, '', HOST, '');
	    setCookie('mtcmthome', f.url.value, now, '', HOST, '');
	}
	
	function forgetMe (f) {
	    deleteCookie('mtcmtmail', '', HOST);
	    deleteCookie('mtcmthome', '', HOST);
	    deleteCookie('mtcmtauth', '', HOST);
	    f.email.value = '';
	    f.author.value = '';
	    f.url.value = '';
	}
