	var thisDate=new Date();
	var PayPalWin; 



//view cart, place order
function openPayPal(URL1) {
	var thisStr = String(URL1)
	URL1 = thisStr.replace("*","\'")
	//alert(URL1)
	window.location=URL1
}

		function popWin(url, winName, scroll) {
			var sw = screen.width;
			var sh = screen.height;
			var w = sw-150
			var h = sh-250;
			var cx = (.5 * sw) - (w * .5);
			var cy = (.5 * sh) - (h * .5);
			var values = 'toolbar=no,status=yes,menubar=no,scrollbars=' + scroll + ',resizable=yes,screenX=' + cx + ',screenY=' + cy + ',left=' + cx + ',top=' + cy + ',width=' + w + ',height=' + h + '';
			try	{
				child = window.open(url, winName, values);
				}
			catch (e)
			{
				window.alert("For the Best Enjoyment of This Site, Please Enable Popups!");
			}
		}


function isMSIE(){

	var ie_start = navigator.appVersion.indexOf("MSIE")

	if ( ie_start  != -1) {
		var versionstr = navigator.appVersion.substring(ie_start +5)
		var majorver = parseInt(versionstr)
		if (majorver >= 6) {
			return(true)
		}
	}else{
		return(false)
	
	}
	
}

//Add Beans validates the blender to make sure an origin and roast were picked
function AddBeans(){
	var thisOrigin = document.blender.Origin.value;
	//alert(thisOrigin);
	var thisRoast = document.blender.Roast.value;
	//alert(thisRoast);
	
	if (thisOrigin != 0 && thisRoast != 0) {
		document.blender.submit();
	}else {
		alert('Please select a coffee and a roast!');
	}

}

function AddBlendtoCart(){
//this is just used to keep the type of request the same
//submit through JS create a querystring instead of form key
//add validation later if needed
		document.blender.action='buycoffee.asp'
		document.blender.submit();
}

		function popWin(url, winName, w, h, offset, scroll) {
			var sw = screen.width;
			var sh = screen.height;
			if (w==''){
				w = sw-50
			}
			if (h==''){
				h = sh-150;
			}
			var cx = (.5 * sw) - (w * .5);
			var cy = (.5 * sh) - (h * .5) - offset;
			var values = 'toolbar=no,status=yes,menubar=no,scrollbars=' + scroll + ',resizable=yes,screenX=' + cx + ',screenY=' + cy + ',left=' + cx + ',top=' + cy + ',width=' + w + ',height=' + h + '';
			try	{
				child = window.open(url, winName, values);
				}
			catch (e)
			{
				window.alert("For the Best Enjoyment of This Site, Please Enable Popups!");
			}
		}
		
function openBlender(){
	opener.focus();
	//popWin('customcoffee.asp',  'Blender', '','560',0, 'No')  
}

function openCoffeeToGo(){
	popWin('coffeetogo.asp', 'Coffee2Go', '', '', 0, 'No');
}
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_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_nbGroup(event, grpName) { //v6.0
var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])?args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) { img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr) for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

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];}}
}

      var arGrind = new Array();
      arGrind[1] = "Whole";
      arGrind[2] = "French Press";
      arGrind[3] = "Espresso";
      arGrind[4] = "Filter";
      arGrind[5] = "Turkish";
	  
      var arRoast = new Array();
      arRoast[1] = "Light";
      arRoast[2] = "Full City";
      arRoast[3] = "Dark";
      arRoast[4] = "Espresso";
	  
	var coffees= new Array();
	coffees[0]="Interstellar Coffee Blend";
	coffees[1]="Quintessence Coffee Blend";
	coffees[2]="Liberating the Taste Genie Coffee Blend";
 	coffees[3]="Costa Rica";
	coffees[4]="Columbia";
	coffees[5]="Brazil";
	coffees[6]="Mexico";
	coffees[7]="Guatemala Decaf";
	coffees[8]="Guatemala";
	coffees[9]="Java Estate";
	coffees[10]="Ethiopia Sidamo";
	coffees[11]="Kenya AA";
	coffees[12]="Kona Blend";
	coffees[13]="Sumatra Decaf";
	coffees[14]="Sumatra Madheling";
	coffees[15]="Vienna Reoast";
	coffees[16]="Moka Java Blend";
	coffees[17]="Espresso Blend";
	coffees[18]="Italian Roast";
	coffees[19]="French Roast Decaf";
	coffees[20]="French Roast";
	coffees[21]="House Blend";
	coffees[22]="House Blend Decaf";
	coffees[23]="Colombia Decaf";
	
	var arItemid= new Array();
	arItemid[0]="Interstellar";
	arItemid[1]="Quintessence";
	arItemid[2]="Liberating";
 	arItemid[3]="Costa_Rica";
	arItemid[4]="Columbia";
	arItemid[5]="Brazil";
	arItemid[6]="Mexico";
	arItemid[7]="Guatemala_Decaf";
	arItemid[8]="Guatemala";
	arItemid[9]="Java_Estate";
	arItemid[10]="Ethiopia_Sidamo";
	arItemid[11]="Kenya_AA";
	arItemid[12]="Kona_Blend";
	arItemid[13]="Sumatra Decaf";
	arItemid[14]="Sumatra";
	arItemid[15]="Vienna";
	arItemid[16]="Moka_Java";
	arItemid[17]="Espresso_Blend";
	arItemid[18]="Italian";
	arItemid[19]="French_Decaf";
	arItemid[20]="French";
	arItemid[21]="House";
	arItemid[22]="House_Decaf";
	arItemid[23]="Colombia_Decaf";
var price= new Array();
	price[0]=12.00;
	price[1]=12.00;
	price[2]=12.00;
 	price[3]=11.00;
	price[4]=11.00;
	price[5]=11.00;
	price[6]=11.00;
	price[7]=11.00;
	price[8]=11.00;
	price[9]=11.00;
	price[10]=11.00;
	price[11]=11.00;
	price[12]=11.00;
	price[13]=11.00;
	price[14]=11.00;
	price[15]=11.00;
	price[16]=11.00;
	price[17]=11.00;
	price[18]=11.00;
	price[19]=11.00;
	price[20]=11.00;
	price[21]=11.00;
	price[22]=11.00;
	price[23]=11.00;
	
var code= new Array();
	code[0]='0';
	code[1]='1';
	code[2]='2';
	code[3]="3";
	code[4]="4";
	code[5]="5";
	code[6]="6";
	code[7]="7";
	code[8]="8";
	code[9]="9";
	code[10]="10";
	code[11]="11";
	code[12]="12";
	code[13]="13";
	code[14]="14";
	code[15]="15";
	code[16]="16";
	code[17]="17";
	code[18]="18";
	code[19]="19";
	code[20]="20";
	code[21]="21";
	code[22]="22";
	code[23]="23";
	
	var arFrequency= new Array();
	arFrequency[1]="Weekly";
	arFrequency[2]="Every Other Week";
	arFrequency[3]="Monthly";
	
	var arFreqCode= new Array();
	arFreqCode[1]="1";
	arFreqCode[2]="2";
	arFreqCode[3]="1";
	
	var arFreqPeriod= new Array();
	arFreqPeriod[1]="W";
	arFreqPeriod[2]="W";
	arFreqPeriod[3]="M";
	
function BuyCoffee(blend, include_roast) {
    // types
    // 0=12 oz
    // 1=5 lb
    // 2=12 oz weekly
    // 3=2 weeks
    // 4=monthly
	//var blendname = escape(document.order.coffee.value);
	var blendname = escape(coffees[blend]);
	var itemid = escape(arItemid[blend]);
	var sSessionID =itemid[blend];
	var grind =  document.getElementById("grind_" + code[blend]).value;
	//var grind =  eval("document.order.grind_" + code[blend]).value;
	var size = 0;
	var blenddesc = blendname;
	var qty =  document.getElementById("quantity_" + code[blend]).value;
	var roast =0;
	if (include_roast==1){
		roast =  document.getElementById("roast_" + code[blend]).value;
		blenddesc = blenddesc + "+" + arRoast[roast] + "+Roast";
	}
	//var qty =  1;
	// Add all genral info
	if (grind>0) {
		if (qty>0) {
			//alert(size)
			
			var PurchaseStr
			PurchaseStr= '&item_name='+ blendname//origin name
			PurchaseStr= PurchaseStr + '&item_number='+itemid ; //itemID = itemid;
	
			//order specific
			PurchaseStr= PurchaseStr + 	'&quantity=' + qty //qty
			PurchaseStr= PurchaseStr + 	'&amount='+ price[blend]; //price
			//PurchaseStr= PurchaseStr + 	'&amount=0.01' //price
			PurchaseStr= PurchaseStr + 	'&on0=Roast'
			PurchaseStr= PurchaseStr + 	'&os0=' + '12+oz.+bag+'+ blenddesc; //blend descript
			PurchaseStr= PurchaseStr + 	'&on1=Grind';
			PurchaseStr= PurchaseStr + 	'&os1='+ arGrind[grind];
			PurchaseStr= PurchaseStr + 	'&invoice=' + sSessionID;  //SessionID
	
			//All orders
			//PurchaseStr= PurchaseStr + 	'&image_url=http://www.coffeeq.com/images/cqlogo.gif';
			PurchaseStr= PurchaseStr + 	'&cancel_return=http%3A//www.coffeeq.com/fail.asp';
			PurchaseStr= PurchaseStr +  '&return=http%3A//www.coffeeq.com/orderthanks.asp';
			PurchaseStr= PurchaseStr + 	'&no_note=1';
			PurchaseStr= PurchaseStr + 	'&shipping=5';
			PurchaseStr= PurchaseStr + 	'&shopping_url=http%3A//www.coffeeq.com/BuyCoffeeQ.asp';
			// 
		
				//purchase
				var paypalUrl
				paypalUrl='https://www.paypal.com/cart/add=1&business=pay@coffeeq.com';
				//paypalUrl='http://starbase/cq/testpaypal.asp?add=1&business=JMQ%40cyberidian.net';
				var URLtoOpen= paypalUrl+PurchaseStr;
			window.location=URLtoOpen
	
			//self.close();
		}
	  }else{
		alert('Please choose a grind!');
	  
	  }
}

function BuyCoffeeSubscription() {
    // types
    // 0=12 oz
    // 1=5 lb
    // 2=12 oz weekly
    // 3=2 weeks
    // 4=monthly
	//var blendname = escape(document.order.coffee.value);
	var coffee =  document.getElementById("coffee").value;
	var blendname = escape(coffees[coffee]);
	var itemid = escape(arItemid[coffee]);
	var sSessionID =arItemid[coffee];
	var grind =  document.getElementById("grind").value;
	//var grind =  eval("document.order.grind_" + code[blend]).value;
	var size = 0;
	var qty =  1;
	var roast =  document.getElementById("roast").value;
	var frequency =  document.getElementById("frequency").value;
	var blenddesc = blendname + "+" + arRoast[roast] + "+Roast";
	//var qty =  1;
	// Add all genral info
	if (grind>0) {
		if (qty>0) {
			//alert(size)
			
			var PurchaseStr
			PurchaseStr= '&item_name='+ blendname + ' ' + escape(arFrequency[frequency]);//origin name
			PurchaseStr= PurchaseStr + '&item_number='+itemid ; //itemID = itemid;
	
			//subscription info
			PurchaseStr= PurchaseStr + 	'&a3=' + eval(price[coffee] + 5); //amount
			PurchaseStr= PurchaseStr + 	'&p3=' + arFreqCode[frequency]; //frequency
			PurchaseStr= PurchaseStr + 	'&t3=' + arFreqPeriod[frequency]; //period
			PurchaseStr= PurchaseStr + 	'&src=1'; //recurring payments
			PurchaseStr= PurchaseStr + 	'&sra=1'; //retry on payment failure
			PurchaseStr= PurchaseStr + 	'&usr_manage=0'; //do not generate password

			//PurchaseStr= PurchaseStr + 	'&amount=0.01' //price
			PurchaseStr= PurchaseStr + 	'&on0=Roast'
			PurchaseStr= PurchaseStr + 	'&os0=' + '12+oz.+bag+'+ blenddesc; //blend descript
			PurchaseStr= PurchaseStr + 	'&on1=Grind';
			PurchaseStr= PurchaseStr + 	'&os1='+ arGrind[grind];
			PurchaseStr= PurchaseStr + 	'&invoice=' + sSessionID;  //SessionID
			
	
			//All orders
			//PurchaseStr= PurchaseStr + 	'&image_url=http://www.coffeeq.com/images/cqlogo.gif';
			PurchaseStr= PurchaseStr + 	'&cancel_return=http%3A//www.coffeeq.com/fail.asp';
			PurchaseStr= PurchaseStr +  '&return=http%3A//www.coffeeq.com/orderthanks.asp';
			PurchaseStr= PurchaseStr + 	'&no_note=1';
			PurchaseStr= PurchaseStr + 	'&shopping_url=http%3A//www.coffeeq.com/BuyCoffeeQ.asp';
			// 
		
				//purchase
				var paypalUrl
				paypalUrl='https://www.paypal.com/subscriptions/&business=pay@coffeeq.com';
				//paypalUrl='http://starbase/cq/testpaypal.asp?add=1&business=JMQ%40cyberidian.net';
				var URLtoOpen= paypalUrl+PurchaseStr;
				
			window.location=URLtoOpen
	
			//self.close();
		}
	  }else{
		alert('Please choose a grind!');
	  
	  }
}
