function imagewindow(url) {
  popupWin = window.open(url, 'popup', 'status,scrollbars,resizable,width=500,height=400,left=10,top=10')
}
function labratDesc(productid) {
  popupWin = window.open('labratinfo.php?product_id=' + productid, 'labrat', 'status,scrollbars,resizable,width=375,height=225,left=10,top=10')
}
function seasonPopup(url) {
  popupWin = window.open(url,'seasons','status,scrollbars,resizable,width=475,height=350,left=10,top=10')
}
var win=null;
function PopUpWin(pageref,pagetitle,w,h,LeftPos,TopPos) {
settings='width='+w+',height='+h+',top='+TopPos+',left='+LeftPos+',scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(pageref,pagetitle,settings);}

function checkDropdown(choice,optionname) {
	if (choice.selectedIndex == 0) {
	   alert("You must choose an " + optionname + " option.");
	   return false;
	} else {
		return true;
	}
}

function cvvPopup(url) {
window.open(url,'cvvWindow','toolbar=no,location=no,directories=no status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=450,height=450,screenX=150,screenY=150,top=150,left=150');
}

function itemPopup(url) {
window.open(url,'itemWindow','toolbar=no,location=no,directories=no status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=575,height=475,screenX=50,screenY=50,top=50,left=50');
}


/* Site Nav */
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


/* Create A Gift */
function removeAddon(addon_id,price) {
	var items_block = document.getElementById('addon-items-block');
	var items_list = document.getElementById('addon-items-list');
	var existing_list = items_list.innerHTML;
	var product_price = document.getElementById('product-price').innerHTML;
	var addon_block = document.getElementById('addon-' + addon_id);
	
	product_price = parseFloat(product_price);
	price = parseFloat(price);
	
	// Set new product price.
	document.getElementById('product-price').innerHTML = (product_price - price).toFixed(2);
	
	// Remove addon
	throwaway_node = items_list.removeChild(addon_block);
}

function addAddon(addon_id,title,price,option_id,option_type_id, option_name) {
	var items_block = parent.document.getElementById('addon-items-block');
	var items_list = parent.document.getElementById('addon-items-list');
	var existing_list = items_list.innerHTML;
	var product_price = parent.document.getElementById('product-price').innerHTML;
	
	product_price = parseFloat(product_price);
	price = parseFloat(price);
	
	// Set new product price.
	parent.document.getElementById('product-price').innerHTML = (product_price + price).toFixed(2);
	
	// Show addon block
	items_block.style.display = "inline";
	
	// Add new item to addon list.
	if(option_name!='') {
		items_list.innerHTML = existing_list + "\n<span id=\"addon-" + addon_id + "\">(<a href=\"javascript:removeAddon('" + addon_id + "'," + price + ");\">remove</a>) " + title + " (" + option_name + ") - $" + price + "<input type=\"hidden\" name=\"bookcake_addons[]\" value=\"" + addon_id + "\" /><input type=\"hidden\" name=\"arroptions[" + addon_id + "][" + option_type_id + "]\" value=\"" + option_id + "\" /><br /></span>";		
	} else {
		items_list.innerHTML = existing_list + "\n<span id=\"addon-" + addon_id + "\">(<a href=\"javascript:removeAddon('" + addon_id + "'," + price + ");\">remove</a>) " + title + " - $" + price + "<input type=\"hidden\" name=\"bookcake_addons[]\" value=\"" + addon_id + "\" /><br /></span>";
	}
}

function updateAddonLink(sku, name, price, link, option_type_id, sel) {
	var option_id = sel.options[sel.selectedIndex].value;
	var option_name = sel.options[sel.selectedIndex].innerHTML;
	
	document.getElementById(link).innerHTML = "<a href=\"javascript:addAddon('" + sku + "','" + name + "'," + price + ", " + option_id + ", " + option_type_id + ", '" + option_name + "');\">Add</a>";
	
}

function updatePaypalNotes() {
  var comment = "Comments: " + document.getElementById('comment').value;
  var gift_message = ", Gift Message: " + document.getElementById('gift_message').value;
  var findus = ", Find us: " + document.getElementById('findus').options[document.getElementById('findus').selectedIndex].value;
  
  var sendnewsletter = document.getElementById('sendnewsletter');
  if (sendnewsletter.checked==true) {
    var sendnewsletter = ", Send Newsletter: Yes"; 
  } else {
    var sendnewsletter = ", Send Newsletter: No"; 
  }

  var vic_club_yes = document.getElementById('vic_club_yes');
  if (vic_club_yes.checked==true) {
    var vic_club = ", VIC Club: Yes"; 
  } else {
    var vic_club = ", VIC Club: No"; 
  }  
  
  document.getElementById('paypal_note').value = comment + gift_message + findus + sendnewsletter + vic_club;
}

function changePayment(radiobox) {
  document.getElementById('cc_payment').style.display = 'none';
  document.getElementById('paypal_payment').style.display = 'none';
  
  if(radiobox.value=="paypal") {
    document.getElementById('paypal_payment').style.display = 'block';
  } else {    
    document.getElementById('cc_payment').style.display = 'block';
  }
}

