function hilite(oid) {
  if (document.getElementById) {
    document.getElementById(oid).style.background = "#fafafa";
    document.getElementById(oid).style.border = "0px solid #9b9b9b";
  } else if (document.all) {
    document.all[oid].style.background = "#fafafa";
    document.all[oid].style.border = "0px solid #9b9b9b";
  }
}

function unhilite(oid) {
  if (document.getElementById) {
    document.getElementById(oid).style.background = "transparent";
    document.getElementById(oid).style.border = "1px none #000000";
  } else if (document.all) {
    document.all[oid].style.background = "transparent";
    document.all[oid].style.border = "1px none #000000";
  }
}

function expand(pid,mid) {
  if (document.getElementById) {
    document.getElementById(pid).style.left = (document.getElementById(mid).offsetLeft + 10) +"px";
    document.getElementById(pid).style.top = (document.getElementById(mid).offsetTop + 20) +"px";    
    document.getElementById(pid).style.visibility="visible";
    if (document.getElementById('hide1')) { document.getElementById('hide1').style.visibility="hidden"; }
   
  } else if (document.all) {
     document.all[pid].style.left = (document.all[mid].offsetLeft + 10) +"px";
     document.all[pid].style.top = (document.all[mid].offsetTop + 20) +"px";     
     document.all[pid].style.visibility="visible";
  } 
}


function contract(pid) {
  if (document.getElementById) {
    document.getElementById(pid).style.visibility="hidden";
  } else if (document.all) {
    document.all[pid].style.visibility="hidden";    
  } else if (document.layers) {
    document.layers[pid].visibility="hidden";
  }
}

function clearPopups(except) {
  if (except!='sub1') { contract('sub1'); }
  if (except!='sub2') { contract('sub2'); }
  if (except!='sub3') { contract('sub3'); }
  if (except!='sub4') { contract('sub4'); }
  if (except!='sub5') { contract('sub5'); }      
  if (document.getElementById('hide1')) document.getElementById('hide1').style.visibility="visible"; 
  if (document.getElementById('hide2')) document.getElementById('hide2').style.visibility="visible"; 
  if (document.getElementById('hide3')) document.getElementById('hide3').style.visibility="visible";  

  
}

function contains(a, b) {
  // Return true if node a contains node b.
  while (b.parentNode)
    if ((b = b.parentNode) == a)
      return true;
  return false;
}

function closeMenu(evnt) {
  var current, related;
  if (window.event) {
    current = this;
    related = window.event.toElement;
  if (current != related && !contains(current, related))
     current.style.visibility = "hidden";   
  } 
  if (current) {
    if ((current.style.visibility == "hidden") && (document.getElementById('hide1')) ) { document.getElementById('hide1').style.visibility="visible"; }
    if ((current.style.visibility == "hidden") && (document.getElementById('hide2')) ) { document.getElementById('hide2').style.visibility="visible"; }  
	if ((current.style.visibility == "hidden") && (document.getElementById('hide3')) ) { document.getElementById('hide3').style.visibility="visible"; }  
  }
}


function assignEvents() {
    var tmpid = "sub1"
	for (var i=1; i<=2; i++) {
	   	tmpid = "sub"+i;
	   	        if (document.all) {
			  document.all[tmpid].onmouseout = closeMenu;
                        } else if (document.getElementById) {
	   	          document.getElementById(tmpid).addEventListener("mouseout",closeMenu,true);
	   	        } else if (document.layers) {
				document.layers[tmpid].onmouseout = closeMenu;
			} 
			 
        }
}

function imgLite(cur) {
  if (cur.style.MozOpacity) cur.style.MozOpacity="1"
  else if (cur.filters) cur.filters.alpha.opacity="100"
}

function imgUnlite(cur) {
  if (cur.style.MozOpacity) cur.style.MozOpacity="0.5"
  else if (cur.filters) cur.filters.alpha.opacity="50"
}


  function updatePrice(cid,val,proc) {
    if (val=='8') {
      if (document.getElementById) {
        if (proc=='R') { tmpid = "d8" + cid; } else { tmpid = "dd8" + cid; }
        document.getElementById(tmpid).style.visibility = "visible";
        tmpid = "d16" + cid;
        document.getElementById(tmpid).style.visibility = "hidden";
        tmpid = "dd16" + cid;
        document.getElementById(tmpid).style.visibility = "hidden";   
        if (proc=='R') { tmpid = "dd8" + cid; } else { tmpid = "d8" + cid; }
        document.getElementById(tmpid).style.visibility = "hidden";             
      }
    } else if (val=='16') {
      if (document.getElementById) {
        if (proc=='R') { tmpid = "d16" + cid; } else { tmpid = "dd16" + cid; }
        document.getElementById(tmpid).style.visibility = "visible";
        tmpid = "d8" + cid;
        document.getElementById(tmpid).style.visibility = "hidden";
        tmpid = "dd8" + cid;
        document.getElementById(tmpid).style.visibility = "hidden";   
        if (proc=='R') { tmpid = "dd16" + cid; } else { tmpid = "d16" + cid; }
        document.getElementById(tmpid).style.visibility = "hidden";      
      }
    } 
  }
  
  
  function updateRoast(cid,proc) 
  {
     if (proc=='D') { tmpid = "D" + cid; } else { tmpid = "R" + cid; }
	 document.getElementById(tmpid).style.visibility = "visible";
	 if (proc=='D') { tmpid = "R" + cid; } else { tmpid = "D" + cid; }
	 document.getElementById(tmpid).style.visibility = "hidden";
  }
  
  function updateShipAddress(tmpid)
  {
	 tmpid = "ShipAddress";
	 document.getElementById(tmpid).style.visibility = "visible"; 
  }
   
   
  function popitup(url)
{
	newwindow=window.open(url,'name','height=500,width=500');
	if (window.focus) {newwindow.focus()}
	return false;
}

 function popitup2(url)
{
	newwindow=window.open(url,'name','height=550,width=750');
	if (window.focus) {newwindow.focus()}
	return false;
}

 function popitup3(url)
{
	newwindow=window.open(url,'name','height=575,width=500');
	if (window.focus) {newwindow.focus()}
	return false;
}

function formvalidator(theForm)
	{
	
		if (theForm.email.value == "")
		{
			alert("A valid email address is required");
			theForm.email.focus();
			return (false);
			}
			
		if (theForm.email.value == "Enter email address")
		{
			alert("A valid email address is required");
			theForm.email.focus();
			return (false);
			}
			
			return (true);
	}
	
function submitForm() {
    document.product_listings_form.submit();
  }
  
// Coffee Selector - select_onchange script

function initSelect()
{
	var theSelect = document.getElementById("selector");
	
	theSelect.changed = false;
	theSelect.onfocus = selectFocussed;
	theSelect.onchange = selectChanged;
	theSelect.onkeydown = selectKeyed;
	theSelect.onclick = selectClicked;
	
	return true;
}




function selectChanged(theElement)
{
	var theSelect;
	
	if (theElement && theElement.value)
	{
		theSelect = theElement;
	}
	else
	{
		theSelect = this;
	}
	
	if (!theSelect.changed)
	{
		return false;
	}

	alert("The select has been changed to " + theSelect.value);
	
	return true;
}




function selectClicked()
{
	this.changed = true;
}




function selectFocussed()
{
	this.initValue = this.value;
	
	return true;
}




function selectKeyed(e)
{
	var theEvent;
	var keyCodeTab = "9";
	var keyCodeEnter = "13";
	var keyCodeEsc = "27";
	
	if (e)
	{
		theEvent = e;
	}
	else
	{
		theEvent = event;
	}

	if ((theEvent.keyCode == keyCodeEnter || theEvent.keyCode == keyCodeTab) && this.value != this.initValue)
	{
		this.changed = true;
		selectChanged(this);
	}
	else if (theEvent.keyCode == keyCodeEsc)
	{
		this.value = this.initValue;
	}
	else
	{
		this.changed = false;
	}
	
	return true;
}



function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

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_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}
