var params = document.location.search
function imgSwap(ID, SRC) {
	document[ID].src=SRC;
}
function writeYear() {
	var vDate = new Date();
	//document.write(vDate.getFullYear());
	return vDate.getFullYear();
}
function getParamValue(v) {
	var p_a = params.substring(params.indexOf("?")+1, params.length).split("&");
	for (var i=0; i<p_a.length; i++){
		var s_a = p_a[i].split("=");
		if(s_a[0] == v){
			return s_a[1];
			break;
		}
	}
}
function detailProduct(PID, CAT, B, NAME, CATNAME) {
	if(B != "1") {
		if(CATNAME) {
			location.href = "/"+CATNAME.toLowerCase()+"/"+NAME.toLowerCase()+".html";
		} else {
			location.href = "/belli/"+NAME.toLowerCase()+".html";
		}
	} else {
		var f1 = document.getElementById("benefit_forward");

		if(CATNAME) {
			f1.action = "/"+CATNAME.toLowerCase()+"/"+NAME.toLowerCase()+".html";
		} else {
			f1.action = "/belli/"+NAME.toLowerCase()+".html";
		}

		// Set the variables
		document.getElementById("benefit").value = B;
		document.getElementById("benefit_code").value = CAT;
		document.getElementById("product_id").value = PID; 

		f1.submit();
	}
}
function detailProductS(NAME, CATNAME) {
	location.href = "/"+CATNAME.toLowerCase()+"/"+NAME.toLowerCase()+".html";
}
function detailProductB(PID, CAT) {
	if(!CAT){
		location.href = "productdetails.php?G=1&B=1&S="+getParamValue('S')+"&ID="+PID;
	}else{
		location.href = "productdetails.php?G=1&B=1&S="+CAT+"&ID="+PID;
	}
}
function swfObjectEmbed(swf, vars, w, h, bg) {
	document.write("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" width=\""+w+"\" height=\""+h+"\"><param name=\"movie\" value=\""+swf+"\" /><param name=\"flashvars\" value=\""+vars+"\" /><param name=\"quality\" value=\"high\" /><param name=\"menu\" value=\"false\" /><param name=\"bgcolor\" value=\""+bg+"\" /><param name=\"allowScriptAccess\" value=\"sameDomain\" /><embed src=\""+swf+"\" flashvars=\""+vars+"\"quality=\"high\" menu=\"false\" bgcolor=\""+bg+"\" width=\""+w+"\" height=\""+h+"\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" /></object>");
}
var selectedPanel = 1;
var panelId = new Array(['pnlbtn_description','description.gif'],['pnlbtn_ingredients','ingredients.gif'],['pnlbtn_safety','safety.gif'],['pnlbtn_testimonials','testimonials.gif']);
function getProductType() {
	var prodtype = getParamValue('S');
	if(prodtype != "mth" && prodtype != "bby" && prodtype != "prg") {
		prodtype = "prg"
	}
	return prodtype
}
function updateText(div,text,num) {
	if(selectedPanel != num){
		prodtype = getProductType();
		imgSwap(panelId[selectedPanel-1][0],'/images/products/detailspanel/'+prodtype+'/'+panelId[selectedPanel-1][1]);
		document.getElementById(div).innerHTML = text;
		selectedPanel = num;
	}
}
function getProductCSS() {
	switch (getParamValue('S')) {
		case 'prg':
			return "productprg";
			break;
		case 'mth':
			return "productmth";
			break;
		case 'bby':
			return "productbby";
			break;
		default:
			return "productprg";
			break;
		
	}
}
function getProductHdr() {
	switch (getParamValue('S')) {
		case 'prg':
			return "hdr_prgproducts";
			break;
		case 'mth':
			return "hdr_mthproducts";
			break;
		case 'bby':
			return "hdr_bbyproducts";
			break;
		default:
			return "hdr_prgproducts";
			break;
		
	}
}
function getLetterHdr() {
	switch (getParamValue('S')) {
		case 'prg':
			return "letterprgheader";
			break;
		case 'mth':
			return "lettermthheader";
			break;
		case 'bby':
			return "letterbbyheader";
			break;
		default:
			return "letterprgheader";
			break;
		
	}
}
function getAddToCartBtn(HREF, ID) {
	var imgDirectory = getParamValue('S');
	if(imgDirectory != "bby" && imgDirectory != "prg" && imgDirectory != "mth"){
		imgDirectory = "bby/";
	}
	document.write("<a href=\""+HREF+"\" onMouseOver=\"imgSwap('"+ID+"','/images/products/"+imgDirectory+"/btn_addtocart-on.gif');\" onMouseOut=\"imgSwap('"+ID+"','/images/products/"+imgDirectory+"/btn_addtocart.gif');\"><img src=\"images/products/"+imgDirectory+"/btn_addtocart.gif\" width=\"101\" height=\"27\" border=\"0\" name=\""+ID+"\"></a>");
	//document.write("<a href=\"#\" onMouseOver=\"imgSwap('"+ID+"','/images/products/"+imgDirectory+"/btn_addtocart-on.gif');\" onMouseOut=\"imgSwap('"+ID+"','/images/products/"+imgDirectory+"/btn_addtocart.gif');\" onClick=\"addItemToCart('1058')\"><img src=\"images/products/"+imgDirectory+"/btn_addtocart.gif\" width=\"101\" height=\"27\" border=\"0\" name=\""+ID+"\"></a>");
}
function validateAddCheck(formname){
//tells if at least one checkbox is checked;
	for(i=0;i<document[formname].elements.length;i++){
		var el=document[formname].elements[i];
		if(stristr("check",el.type)){
			if(el.checked){
				return true;
			}
		}
	}
	alert("You haven't selected anything to add to your cart.");
	return false;
}
function addItemToCart(item_id,redirect){
	var quantity_elem = document.getElementById("quantity");
	var quantity = 1;
	if(quantity_elem) {
		quantity = quantity_elem.value;
	} 
	var url = "/store.redir.php?action=add&inv_id=" + item_id + "&quantity=" + quantity + "&refer=" + redirect;
	document.location = url;
}
function addItemsToCart(item_ids,redirect){
	var url = "/store.redir.php?action=addmulti&quantity=1&refer=" + redirect;
	for(i = 0; i < item_ids.length;i++){
		url += "&inv_ids["+i+"]="+item_ids[i];			
	}
	document.location = url;
}
function showChoice(product_id) {
	document.getElementById("choice" + product_id).style.display="block";
}
function hideChoice(product_id) {
	document.getElementById("choice" + product_id).style.display="none";
}
function highlightChoice(inv_id) {
	document.getElementById("choicesel" + inv_id).className = "choicesel";
}
function clearChoice(inv_id) {
	document.getElementById("choicesel" + inv_id).className = "choicedesel";
}
