function fnEnlargeImage(productid,imageloc,imagename,focusType){var obj,obj2,obj3,obj4,x;var url="";obj = eval("document.forms[0].largeImage_" + productid);obj.src = "images/spacer.gif";obj2 = eval("document.forms[0].enlargedImage_" + productid);obj2.src = imageloc + imagename;obj3 = eval("document.forms[0].enlargeImageLink");obj3.src = "images/spacer.gif";obj4 = eval("document.forms[0].reduceImageLink");obj4.src = "images/bttnReduceImage.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 + "#linkReduce";}else{url = url + "#Top";}document.location.href = url;}
function fnReduceImage(productid,imageloc,imagename,focusType){var obj,obj2,obj3,obj4,x,url="";	obj = eval("document.forms[0].largeImage_" + productid);obj.src = imageloc + imagename;obj2 = eval("document.forms[0].enlargedImage_" + productid);obj2.src = "images/spacer.gif";obj3 = eval("document.forms[0].enlargeImageLink");obj3.src = "images/bttnEnlargeImage.gif";obj4 = eval("document.forms[0].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;}
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 = "modify.aspx?loc=N&goto=" + loc + "&str=" + strNote + "&url=" + 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 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 sUrl;
    var index = 0;
    var index2 = 0;
    var index3 = 0;

    if (document != null && document.referrer != null)
    {            
        var previousUrl = document.getElementById("_hiddenReferrer");
        var previousUrlLink = previousUrl.innerHTML;

        var amp = new RegExp("&amp;", "g");
        var updatedUrl = previousUrlLink.replace(amp, "&");

        previousUrlLink = updatedUrl;

        if (previousUrlLink != "" || previousUrl != null)
        { 
            sUrl = previousUrlLink;
        } 
        else
        {
            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 BasketGoToCheckout(url){document.location.href=  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";
	}
}

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 CheckBoxChange(){}

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";}	}


