<script language="JavaScript">

function BasketViewDeliveryCharges()
{
	document.location.href = 'dynamiccontent.aspx?loc=4&menuId=73&pmenuId=0'
}

function HTMLPopup(path,width,height)
{
	window.open(path,"",'dependent=1,height=' + height +',width=' + width + ',titlebar=no,toolbar=0,resizable=0,left=100,top=150,scrollbars=1');}
function catchKeyPress(code, sender) { var ret=null;testForEnterAndEsc();if(code == '13') {switch (sender.name) {case 'searchtext':ret=document.getElementById("btnSearch");break;case 'txtEmail':ret=document.getElementById("bttnSubscribe");break;}                if(ret){ret.click();}} else if(code == '27'){ret=document.getElementById("btnCancel");if(ret) { ret.click(); }}}
function testForEnterAndEsc() {    if (event.keyCode == 13 || event.keyCode == 27) {event.cancelBubble = true; event.returnValue = false;}} 
function ChooseDelivery(){ document.forms[0].delid.value = document.forms[0].deliveryType.value;document.forms[0].action = "checkout3.aspx?&loc=t";document.forms[0].submit(this);}
function ChooseSpecialDelivery(){	document.forms[0].delid.value = document.forms[0].deliveryType.value;var btn=document.forms[0].SpecialDel;for (var i=0; i<btn.length;i++){if (btn[i].checked){specialdeliveryTypeId = btn[i].value;}}document.forms[0].action = "checkout3.aspx?&loc=t&spdid=" + specialdeliveryTypeId;document.forms[0].submit(this);}
function fnBuy4NowSearch(){var searchword;if (!(document && document.forms[0] &&  document.forms[0].b4nSearch)){}else{searchword =document.forms[0].b4nSearch.value;document.location.href = "http://www.buy4now.ie/index.asp?st=1&stid=ALL&sv=" + searchword;}}
function BuyButton(productID){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";	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";	document.forms[0].submit(this);}else{alert('Please select your preferred option(s)');}}}}
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 MoreFromCategory(productID){document.location.href = "shopping.aspx?catid=" + productID + "&loc=C";}
function ReturnToPrevious(){history.go(-1);}
function BasketRemove(basketid){document.location.href="basket.aspx?loc=B&a=1&bid=" + basketid;}
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 BasketChangeQuantity(basketid,qty){document.location.href="basket.aspx?loc=B&a=2&bid=" + basketid + "&qty=" + qty;	}
function SaveGiftNotes(loc,url){var frm = document.forms[0];var strNote = "";	for(i=0;i< frm.length;i++){e=frm.elements[i];		if ( e.type=='textarea' && e.name.indexOf("note_") != -1 ){	if(e.value.length > 1800){alert('Please keep your note less than 1800 characters. \nYou currently have ' + e.value.length + ' characters');}	else{strNote += e.id + ":" + e.value + "|";}}}document.forms[0].action = url;	document.forms[0].submit(this);	}
function BasketGiftNote(basketid,act){var frm = document.forms[0];var note;note = "note_" + basketid;if (act == "0"){   for(i=0;i< frm.length;i++){e=frm.elements[i];if ( e.type=='textarea' && e.name.indexOf(note) != -1 )	{e.disabled = false;e.value += "|";document.forms[0].action = "basket.aspx?loc=B&a=5&bid=" + basketid + "&act=" + act;	document.forms[0].submit(this);	}}}else if (act == "1"){document.forms[0].action = "basket.aspx?loc=B&a=5&bid=" + basketid + "&act=" + act;	document.forms[0].submit(this);	}else if (act == "2"){for(i=0;i< frm.length;i++){e=frm.elements[i];if ( e.type=='textarea' && e.name.indexOf(note) != -1 ){e.disabled = false;document.forms[0].action = "basket.aspx?loc=B&a=5&bid=" + basketid + "&act=" + act;	document.forms[0].submit(this);	}}}}
function CheckoutGiftNote(basketid,act){var frm = document.forms[0];var note;note = "note_" + basketid;if (act == "0"){for(i=0;i< frm.length;i++){e=frm.elements[i];if ( e.type=='textarea' && e.name.indexOf(note) != -1 ){e.disabled = false;e.value += "|";document.forms[0].action = "checkout3.aspx?loc=B&a=5&bid=" + basketid + "&act=" + act;	document.forms[0].submit(this);	}}}else if (act == "1"){document.forms[0].action = "checkout3.aspx?loc=B&a=5&bid=" + basketid + "&act=" + act;	document.forms[0].submit(this);}else if (act == "2"){for(i=0;i< frm.length;i++){e=frm.elements[i];if ( e.type=='textarea' && e.name.indexOf(note) != -1 ){e.disabled = false;document.forms[0].action = "checkout3.aspx?loc=B&a=5&bid=" + basketid + "&act=" + act;	document.forms[0].submit(this);	}}		}	}
function BasketRemoveAll(){document.location.href="basket.aspx?loc=B&a=3";}
//function BasketContinueShopping(){var sUrl;var index = 0;var index2 = 0;var index3 = 0;if (document != null && document.referrer != null){sUrl = document.referrer;if (sUrl == ""){sUrl =	"home.aspx?loc=H";}index = sUrl.indexOf("basket.aspx");if(index != -1){sUrl =	"home.aspx?loc=H";}index2 = sUrl.indexOf("productdetail.aspx");if(index2 != -1){index3 = sUrl.indexOf("catid=");if(index3 != -1){sUrl = sUrl.replace(/productdetail/gi, "shopping"); sUrl = sUrl.replace(/loc=P/gi, "loc=C");} }document.location.href = sUrl;}else{document.location.href = "home.aspx?loc=H";}}
function BasketContinueShopping(){document.location.href = "home.aspx?loc=H";}
function BasketGoToCheckout(url){SaveGiftNotes('',url)}
// VS. 2007.03.14, Bug 3876. Made many changes. 
// Now supporting calculation of promotion and changing Was and Ex. PRF price
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, promotionBasePrice,
	promotionRRPPrice, promotionBaseAttributeId, promotionRewardTypeId, promotionReward,
	currencyRate, promotionWasPrice, EXPRFPrice, PRFPrice, thisProductEXPRFPrice, thisProductPRFPrice;
	
	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);
	thisProductEXPRFPrice = eval(document.getElementById("ExEMCPrice_" + hProductID));
	thisProductPRFPrice = eval(document.getElementById("EMCPrice_" + hProductID));
	thisProductWasPrice = eval(document.getElementById("WasPrice_" + hProductID));	
	
	
	promotionBasePrice = parseFloat(eval("document.forms[0].promotionBasePrice.value"));
	promotionRRPPrice = parseFloat(eval("document.forms[0].promotionRRPPrice.value"));	
	promotionBaseAttributeId = parseInt(eval("document.forms[0].promotionBaseAttributeId.value")); 	
	promotionRewardTypeId = parseInt(eval("document.forms[0].promotionRewardTypeId.value"));
	promotionReward = parseFloat(eval("document.forms[0].promotionReward.value"));	
	currencyRate = parseFloat(eval("document.forms[0].promotionCurrencyRate.value"));
	if(thisProductPRFPrice)
	{
		EXPRFPrice = parseFloat(thisProductEXPRFPrice.innerText.replace(m_currencySymbol,''));
		PRFPrice = parseFloat(thisProductPRFPrice.innerText.replace(m_currencySymbol,''));	
	}
	
	BasePriceRunningTotal = promotionBasePrice * currencyRate;
	RRPPriceRunningTotal = promotionRRPPrice * currencyRate;	
	
	if(thisDropDown != "none")
	{
		//hide "From" text 
		if(document.forms[0].fromText)
		{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);
		
		if(thisDropDown != "none")
		{				
			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;
			}
		}
		
	}

	//base price
	if(promotionBaseAttributeId == 19)
	{
		if(thisProductWasPrice)
		{
			promotionWasPrice = BasePriceRunningTotal;
		}
		BasePriceRunningTotal = PromotionCalculation(BasePriceRunningTotal, promotionRewardTypeId, promotionReward);
		if(thisProductPRFPrice)
		{
			EXPRFPrice = BasePriceRunningTotal - PRFPrice;
		}
	}
	
	//RRP price
	if(promotionBaseAttributeId == 20)
	{
		if(thisProductWasPrice)
		{
			promotionWasPrice = RRPPriceRunningTotal;
		}
		RRPPriceRunningTotal = PromotionCalculation(RRPPriceRunningTotal, promotionRewardTypeId, promotionReward);
		if(thisProductPRFPrice)
		{
			EXPRFPrice = RRPPriceRunningTotal - PRFPrice;
		}
	}
	
	if(ValidateExclusions(noRows) == true)
	{
		if(thisProductBasePrice)
		{
			thisProductBasePrice.value = m_currencySymbol + FormatNum(BasePriceRunningTotal,2);				
		}
		if(thisProductRRPPrice)
		{
			thisProductRRPPrice.value = "RRP " + m_currencySymbol + FormatNum(RRPPriceRunningTotal,2);
		}	
		if(thisProductPRFPrice)
		{
			thisProductEXPRFPrice.innerText = m_currencySymbol + FormatNum(EXPRFPrice,2);	
		}
		if(thisProductWasPrice)
		{
			thisProductWasPrice.innerText = m_currencySymbol + FormatNum(promotionWasPrice,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 PromotionCalculation(price, rewardTypeID, reward)
{
	// money off
	if(rewardTypeID == "1")
	{
		price = price - reward;
	}
	// percent off
	if(rewardTypeID == "2")
	{
		price = price * (1 - (reward/100));
	}

	return price;	
}
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 = "Each";}
	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 == "Each" || p_UNIT == ""))
	{
		
		uppm_obj.value = "(" + m_currencySymbol + FormatNum(p_UPPM,2) + " per " + p_UNIT + ")";
		uppm_obj.height = 15;
	}
	else
	{
		uppm_obj.height = 0;
	}
}

function ValidateExclusions(noRows){	var exCount,p_exID,p_attID,p_attRowID;var arrAttValues = new Array(noRows);var isValid = true;exCount = parseFloat(eval("document.forms[0].hExCount.value"));	exTotal = parseFloat(eval("document.forms[0].hExTotal.value"));	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_attRowID = parseFloat(splitString[0]);		if(!(isNaN(p_attRowID))){arrAttValues[i] = p_attRowID;}}var currentExID = 0;var matchCount = 0;var recCount = 0;for(j=0; j < exCount; j++){thisDropDown = "document.forms[0].ex_" + j + ".value";thisDropDown = eval(thisDropDown);splitString = thisDropDown.split("|");p_exID = parseFloat(splitString[0]);p_attID = parseFloat(splitString[1]);p_attRowID = parseFloat(splitString[2]);		if(currentExID != 0){currentExID = p_exID;}	for(k=0; k < noRows; k++){		if(arrAttValues[k] == p_attRowID){matchCount = matchCount + 1;}	if(currentExID != p_exID){currentExID = p_exID;matchcount = 0;recCount = 0;}}		if(matchCount == exCount){isValid=false;break;}matchcount = 0;recCount = 0;}return isValid;}		
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);}
function IncreaseQty(productID){var obj, x;obj = eval("document.forms[0].qty_" + productID);x = obj.value;x = parseInt(x) + 1;	if ( x > 999 ){x = 999;}obj.value = x;}
function DecreaseQty(productID){var obj,x;obj = eval("document.forms[0].qty_" + productID);x = obj.value;if ( x > 1 ){x = parseInt(x) - 1;}obj.value = x;}
function BasketChangeQty(productID,qty){var obj, x;obj = eval("document.forms[0].qty_" + productID);x = obj.value;x = parseInt(x) + parseFloat(qty);	if ( x > 999 ) {x = 999;}if (x < 1){BasketRemove(productID);}else{obj.value = x;BasketChangeQuantity(productID,x);}}
function BasketGiftWrap(origin,productID,action){var obj,cbox, x,wraptype;obj = eval("document.forms[0].qty_" + productID);x = obj.value;	cbox = eval("document.forms[0].gifttype_" + productID);wraptype = cbox.value;document.forms[0].action = "modify.aspx?loc=B&origin=" + origin + "&bid=" + productID + "&qty=" + x + "&action=" + action + "&wraptype=" + wraptype;	document.forms[0].submit(this);}
function UpdateVoucher(){var vCode = "";vCode = document.forms[0].txtVoucherCode.value;if (vCode != ""){document.location.href = "checkout3.aspx?loc=T&vc=" + vCode;}}
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 ViewAllReviews(pid,catid){document.location.href = "productdetail.aspx?pid=" + pid + "&loc=P&catid=" + catid + "&showRevAll=Y#linkReviews";}
function SubmitReview(){var validchoice = true;if(document.forms[0].txtReviewText.value == ""){alert('Please fill in your review');validchoice=false;document.forms[0].txtReviewText.focus();return false;}if(document.forms[0].txtName.value == ""){alert('Please fill in your name');validchoice=false;document.forms[0].txtName.focus();return false;}if(document.forms[0].txtLocation.value == ""){alert('Please fill in your location');validchoice=false;document.forms[0].txtLocation.focus();return false;}if(validchoice ==true){document.forms[0].action = "reviewSubmit.aspx?loc=S";document.forms[0].submit(this);}
function ChangeSortBy(){}
}


/* Enlarge Image JS */

function init() {    
    if (GetEnlargedImage() == null) {
        document.getElementById('enlargeButton').style.display = 'none';
    }
}

function GetLargeImage() {
    return document.getElementById("hLargeImage")
}

function GetImageLocation() {
    return document.getElementById("hImageLocation").getAttribute("value");
}

function GetProductID() {
    return document.getElementById("hProductID").getAttribute("value");
}

function GetEnlargedImage() {
    return document.getElementById("hEnlargedImage")
}

function GetLargeButton() {
    return document.getElementById("enlargeImageLink")
}

function IsImageEnlarged() {
    return document.getElementById("IsImageEnlarged").getAttribute("value");
}

function fnEnlargeImage() {
    var numberForms = document.forms.length, formIndex = 0, cformIndex = 0;
    if (numberForms > 1) {
        for (formIndex = 0; formIndex < numberForms; formIndex++) {
            if (document && document.forms[formIndex] && document.forms[formIndex].b4nfindform) {
                cformIndex = formIndex;
            }
        }
    }
    var url = "";
    var imageUrl, buttonImage, isEnlarged, newimagename;
    buttonImage = GetLargeButton();

    if (IsImageEnlarged() == "false") {
        newimagename = GetEnlargedImage();
        buttonImage.src = "images/bttnReduceImage.gif";
        buttonImage.alt = "Reduce Image"
        document.getElementById("IsImageEnlarged").setAttribute("value", "true");
    }
    else {
        newimagename = GetLargeImage();
        buttonImage.src = "images/bttnEnlargeImage.gif";
        buttonImage.alt = "Enlarge Image"
        document.getElementById("IsImageEnlarged").setAttribute("value", "false");
    }
    imageUrl = eval("document.images.largeImage_" + GetProductID());
    imageUrl.src = GetImageLocation() + newimagename.value;
}

function fnReduceImage() {
    var numberForms = document.forms.length, formIndex = 0, cformIndex = 0;

    if (numberForms > 1) {
        for (formIndex = 0; formIndex < numberForms; formIndex++) {
            if (!(document && document.forms[formIndex] && document.forms[formIndex].b4nfindform)) {
            }

            else {
                cformIndex = formIndex;
            }
        }
    }
    var obj, obj2, obj3, obj4, x, url = "";
    obj = eval("document.forms[cformIndex].largeImage_" + GetProductID());
    obj.src = imageloc + imagename;
    //  obj2 = eval("document.forms[cformIndex].enlargedImage_" + productid);
    //   obj2.src = "../images/spacer.gif";
    obj3 = eval("document.forms[cformIndex].enlargeImageLink");
    obj3.src = "../images/bttnEnlargeImage.gif";
    obj4 = eval("document.forms[cformIndex].reduceImageLink");
    obj4.src = "../images/spacer.gif";
    url = (document.location.href);
    var re = new RegExp('#linkReduce', 'gi');
    var re2 = new RegExp('#linkEnlarge', 'gi');
    var re3 = new RegExp('#Top', 'gi');
    url = url.replace(re, '');
    url = url.replace(re2, '');
    url = url.replace(re3, '');

    if (focusType == 1) {
        url = url + "#linkEnlarge";
    }

    else {
        url = url + "#Top";
    }

    document.location.href = url;
}


</script>


