
function BuyButtonCategory(productID,catid){var noRows, validchoice;validchoice = true;if (!(document && document.forms[0] &&  document.forms[0].hMVCount)){}else{noRows = document.forms[0].hMVCount.value;}if (!(document && document.forms[0] &&  document.forms[0].hCanBuy)){document.forms[0].action = "productdetail.aspx?pid=" + productID + "&loc=P&add=1&catid=" + catid;	document.forms[0].submit(this);}else{if(document.forms[0].hCanBuy.value == "N"){alert('There is no product available for these options.\n\nPlease choose again.');}else{for(i=0; i < noRows; i++){thisDropDown = "document.forms[0].mv_" + i + "[document.forms[0].mv_" + i + ".selectedIndex].value";thisDropDown = eval(thisDropDown);if(thisDropDown == "none"){validchoice = false;}}	if (validchoice == true){document.forms[0].action = "productdetail.aspx?pid=" + productID + "&loc=P&add=1&catid=" + catid;	document.forms[0].submit(this);}else{alert('Please select your preferred option(s)');}}}}
function MoreDetail(productID,catID){var catpage ="";if (!(document && document.forms[0] &&  document.forms[0].hCatId)){}else{catpage = document.forms[0].hCatId.value;}if(catID == ""){catID = catpage;}document.location.href = "productdetail.aspx?pid=" + productID + "&loc=P&catid=" + catID;}
function SmallBasketRemove(basketid){var rExp = /&/gi;var url = document.location.href;url = url.replace(rExp,"||");document.location.href="basket.aspx?loc=B&a=4&bid=" + basketid  + "&url=" + url ;	}
function MoreFromCategory(productID){document.location.href = "shopping.aspx?catid=" + productID + "&loc=C";}
function ViewRange(categoryID,type){if(type == "cat"){document.location.href = "category.aspx?catid=" + categoryID + "&loc=R";}if(type == "list"){document.location.href = "shopping.aspx?catid=" + categoryID + "&loc=C";}	}

function ChangeDropDown(m_mvCount,m_imagePath,m_currencySymbol)
{
	/* changed 01.02.2005 to include thisProductWasPrice*/
	
	var hProductID, thisDropDown,splitString,noRows,BasePriceRunningTotal,RRPPriceRunningTotal,p_affectsBase,p_affectsRRP,
	thisProductBasePrice, thisProductRRPPrice;//thisProductWasPrice_obj, WasPriceRunningTotal
	p_affectsBase = "";
	p_affectsRRP = "";	
	noRows = document.forms[0].hMVCount.value;
	hProductID = document.forms[0].hProductID.value;
	thisDropDown = "document.forms[0].mv_" + m_mvCount + "[document.forms[0].mv_" + m_mvCount + ".selectedIndex].value";
	thisDropDown = eval(thisDropDown);	
	thisProductBasePrice = eval("document.forms[0].productBasePrice_" + hProductID);
	thisProductRRPPrice = eval("document.forms[0].productRRPPrice_" + hProductID);
	//thisProductWasPrice_obj = eval("document.forms[0].productBasePriceWAS_" + hProductID); //change
	BasePriceRunningTotal = parseFloat(eval("document.forms[0].hBasePrice_" + hProductID + ".value"));
	RRPPriceRunningTotal = parseFloat(eval("document.forms[0].hRRPPrice_" + hProductID + ".value"));
	//WasPriceRunningTotal = parseFloat(eval("document.forms[0].hWasPrice_" + hProductID + ".value"));

	
	
	if(thisDropDown != "none")
	{		
		//hide "From" text 
		document.forms[0].fromText.value = "";
		
		
		
		splitString = thisDropDown.split("|");
		if(splitString[3] != "")
		{
			document.forms[0].LargeProductImage.src = m_imagePath + splitString[3];
		}	
		
		for(i=0; i < noRows; i++)
		{
			thisDropDown = "document.forms[0].mv_" + i + "[document.forms[0].mv_" + i + ".selectedIndex].value";
			thisDropDown = eval(thisDropDown);
			splitString = thisDropDown.split("|");
			p_affectsBase = parseFloat(splitString[1]);
			p_affectsRRP = parseFloat(splitString[2]);
			
			if((thisDropDown != "none") && (!(isNaN(p_affectsBase))))// && thisProductWasPrice_obj
			{
				BasePriceRunningTotal = BasePriceRunningTotal + p_affectsBase;
				//thisProductWasPrice_obj.value = m_currencySymbol + FormatNum((WasPriceRunningTotal + p_affectsBase),2);//change	
			}
			
			
			if((thisDropDown != "none") && (!(isNaN(p_affectsRRP))))
			{
				RRPPriceRunningTotal = RRPPriceRunningTotal + p_affectsRRP;
			}
			
			
		}
		
		if(ValidateExclusions(noRows) == true)
		{
			if(thisProductBasePrice)
			{
				thisProductBasePrice.value = m_currencySymbol + FormatNum(BasePriceRunningTotal,2);
			}
			if(thisProductRRPPrice)
			{
				thisProductRRPPrice.value = "RRP " + m_currencySymbol + FormatNum(RRPPriceRunningTotal,2);
			}			
		}	
		
		if(ValidateExclusions(noRows) == false)
		{
			thisProductBasePrice.value = "Not Available";
			alert('There is no product available for these options.\n\nPlease choose again.');
			document.forms[0].hCanBuy.value = "N";
		}
	
		ChangeUPPMText(m_currencySymbol,hProductID); //change john 02.02.2005
		
	}
}



function ChangeUPPMText(m_currencySymbol,pid)
{
	
	var uppm_obj, base_uppm_obj, thisDropDown, m_mvCount, noRows, unit, p_UPPM, p_UNIT, splitString, m_mvCount_obj;
	
	thisDropDown = "";
	m_mvCount = "";
	noRows = 0;
	unit = "";
	p_UPPM = "";
	p_UNIT = "";
	
	//pid = document.forms[0].hProductID.value;
	uppm_obj = eval("document.forms[0].uppmText_" + pid); //UPPM column in b4nattributeproductfamily
	
	base_uppm_obj = eval("document.forms[0].baseUPPM_" + pid); 
	unit_obj = eval("document.forms[0].unitType_" + pid); //Kg, L, M, Each

	m_mvCount_obj = document.forms[0].hMVCount;
	
	if (!m_mvCount_obj && m_mvCount_obj != null && m_mvCount_obj != "undefined")
	{	
		m_mvCount = document.forms[0].hMVCount.value;
		noRows = document.forms[0].hMVCount.value;
	}
	
	for(i=0; i < noRows; i++)
	{
		thisDropDown = "document.forms[0].mv_" + i + "[document.forms[0].mv_" + i + ".selectedIndex].value";
		thisDropDown = eval(thisDropDown);
		
		if (thisDropDown && thisDropDown != "none")
		{
			splitString = thisDropDown.split("|");
			p_UPPM = parseFloat(splitString[4]);
		}
	}
	
	if (!p_UPPM || p_UPPM == "" || p_UPPM == "NaN")
	{
		if (base_uppm_obj && base_uppm_obj != null && base_uppm_obj != "undefined")
			p_UPPM = parseFloat(base_uppm_obj.value);
		else
			p_UPPM = 0;
	}

	if (unit_obj && unit_obj.value)
	{
		p_UNIT = unit_obj.value;
	}
	
	/*
	0	Each
	1	Kg
	2	Litre
	3	Metre
	4	SQ Metre
	*/
		

	if (p_UNIT == "0")
	{p_UNIT = "None";}
	else if (p_UNIT == "1")
	{p_UNIT = "Kg";}
	else if (p_UNIT == "2")
	{p_UNIT = "Litre";}
	else if (p_UNIT == "3")
	{p_UNIT = "Metre";}
	else if (p_UNIT == "4")
	{p_UNIT = "SQ Metre";}
	else
	{p_UNIT = "";}
	
	/*
		for (i=0;i<1000;i++)
		{
			if (document.forms[0].elements[i])
			{
				var x = document.forms[0].elements[i];
				if (x.name == 'uppmText_774')
					alert(x.name)s
			
			}
		}
	*/
	if (!(p_UNIT == "None" || p_UNIT == ""))
	{
		
		uppm_obj.value = "(" + m_currencySymbol + FormatNum(p_UPPM,2) + " per " + p_UNIT + ")";
		uppm_obj.height = 15;
	}
	else
	{
		uppm_obj.height = 0;
	}
	
}

function FormatNum(expr,decplaces){var str = "" + Math.round(eval(expr) * Math.pow(10,decplaces));while ( str.length <= decplaces  ){str = "0" + str}	var decpoint = str.length - decplaces;return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);}



