﻿
booShowFull = true;
booBalloonShow = true;

function checkit(passed) {

 for (i=1; i<passed.length; i++){
     if (passed[i].name == "quantity"){
         passedamount = passed.quantity.selectedIndex;
         if (passedamount == 0){
            alert("You Have Not Selected Your Required Quantity");
            return false;
            }
     }
     if (passed[i].name == "Attribute1"){
         passedamount = passed.Attribute1.selectedIndex;
         if (passedamount == 0){
            almsg = "You Have Not Selected Your Required " + passed.att1.value
            alert(almsg);
            return false;
            }
     }
     if (passed[i].name == "Attribute2"){
         passedamount = passed.Attribute2.selectedIndex;
         if (passedamount == 0){
            almsg = "You Have Not Selected Your Required " + passed.att2.value
            alert(almsg);
            return false;
            }
     }
     if (passed[i].name == "Attribute3"){
         passedamount = passed.Attribute3.selectedIndex;
         if (passedamount == 0){
            almsg = "You Have Not Selected Your Required " + passed.att3.value
            alert(almsg);
            return false;
            }
     }
     if (passed[i].name == "Attribute4"){
         passedamount = passed.Attribute4.selectedIndex;
         if (passedamount == 0){
            almsg = "You Have Not Selected Your Required " + passed.att4.value
            alert(almsg);
            return false;
            }
     }
 }
return true;
}

function showHideDescription()
{

    //Set the style of the description object
    
    styleSwitch('product_info', booShowFull, 'height:auto', 'height:55px');
    styleSwitch('product_info', booShowFull, 'overflow:visible', 'overflow:hidden');
    
    
    
    if (booShowFull == true)
    {
        booShowFull = false;
        document.getElementById('btnShowHide').src = "/images/loadbuy7/showHideBG_reverse.gif";
        document.getElementById('lnkShowHide').innerHTML = "Hide Full Description";
    }
    else
    {
        booShowFull = true;
        document.getElementById('btnShowHide').src = "/images/loadbuy7/showHideBG.gif";
        document.getElementById('lnkShowHide').innerHTML = "Show Full Description";
    }

return true

}


function styleSwitch(objTarget, objEvent, strOnStyle, strOffStyle)
    {
    
    var arrStyleOn, arrStyleOff;
    
    arrStyleOn      = strOnStyle.split(':');
    arrStyleOff     = strOffStyle.split(':');
    
    
    
    if (objEvent == true) 
        {
         eval('document.getElementById(' + '\'' + objTarget + '\'' + ').style.' + arrStyleOn[0] + '=' + '\'' + arrStyleOn[1] + '\'');
        }
    else
        {
         eval('document.getElementById(' + '\'' + objTarget + '\'' + ').style.' + arrStyleOff[0] + '=' + '\'' + arrStyleOff[1] + '\'');
        }
    
    return true;
    
    }

function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + num + '.' + cents);
}



function sendPrice(intPrice, strProductId)
{

    /*
        LivePrice Changing on buy page
        DR: 07-08-07   
    */

    // ---- DECLARE LOCAL VARIABLES
    arrProducts = new Array();
    arrPrices   = new Array();
    
    
    
    
    // ---- SPLIT THE PRICES AND products up from the hidden fields
        arrPrices = document.getElementById("hidPrices_array").value.split("|");
        arrProducts = document.getElementById("hidProducts_array").value.split("|");
    
    intNewPrice     = 0.00;
    strNewProducts  = '';
    strNewPrices    = '';
    booNoNew        = false;
    
    //---- Loop through Array of already selected products
    
    for (var i=0 ; i < arrProducts.length-1 ; i++)
    {
       
       booAddThis = false;                                              // Set the re-add clause to false as default;

       if (arrProducts[i] != strProductId)                              //If this iteration of the array is not the selected prod, re add
        {
            intCurrPrice        = arrPrices[i];
            strCurrProduct      = arrProducts[i];
            booAddThis          = true;
        }
  else 
        {
            if (parseFloat(arrPrices[i]) != parseFloat(intPrice))      //If the price doesn't match (i.e. different size same product)
            {                                                           //Re add the product
            intCurrPrice        = parseFloat(intPrice);
            strCurrProduct      = strProductId;
            booAddThis          = true;
            booNoNew            = true;
            }
         else                                                           //If not just remove it
            {
            booAddThis          = false;
            booNoNew            = true;
            }
            
        }
        
            if (booAddThis == true)                                     //If product is set to be re-added this is the place to do it
            {
            intNewPrice     = parseFloat(intNewPrice) + parseFloat(intCurrPrice);
            strNewPrices    = strNewPrices + intCurrPrice + "|";
            strNewProducts  = strNewProducts + strCurrProduct + "|";
            }
            
    }
            
         if (booNoNew != true)                                          //If no new product is being added don't trigger this
         {
            intNewPrice     = parseFloat(intNewPrice) + parseFloat(intPrice);
            strNewPrices    = strNewPrices + intPrice + "|";
            strNewProducts  = strNewProducts + strProductId + "|";
         }
        
        
        //---- Add the final calculations to the page.
        
        document.getElementById("hidPrices_array").value        = strNewPrices;
        document.getElementById("hidProducts_array").value      = strNewProducts;
        
        document.getElementById("priceTag").innerHTML           = "&pound;" + formatCurrency(intNewPrice);
}

//New function for refresh adds price change to mini basket too
function sendPriceFuneral(intPrice, strProductId)
{

    /*
        LivePrice Changing on buy page
        DR: 07-08-07   
    */

    // ---- DECLARE LOCAL VARIABLES
    arrProducts = new Array();
    arrPrices   = new Array();
    
    
    
    
    // ---- SPLIT THE PRICES AND products up from the hidden fields
        arrPrices = document.getElementById("hidPrices_array").value.split("|");
        arrProducts = document.getElementById("hidProducts_array").value.split("|");
    
    intNewPrice     = 0.00;
    strNewProducts  = '';
    strNewPrices    = '';
    booNoNew        = false;
    
    //---- Loop through Array of already selected products
    
    for (var i=0 ; i < arrProducts.length-1 ; i++)
    {
       
       booAddThis = false;                                              // Set the re-add clause to false as default;

       if (arrProducts[i] != strProductId)                              //If this iteration of the array is not the selected prod, re add
        {
            intCurrPrice        = arrPrices[i];
            strCurrProduct      = arrProducts[i];
            booAddThis          = true;
        }
  else 
        {
            if (parseFloat(arrPrices[i]) != parseFloat(intPrice))      //If the price doesn't match (i.e. different size same product)
            {                                                           //Re add the product
            intCurrPrice        = parseFloat(intPrice);
            strCurrProduct      = strProductId;
            booAddThis          = true;
            booNoNew            = true;
            }
         else                                                           //If not just remove it
            {
            booAddThis          = false;
            booNoNew            = true;
            }
            
        }
        
            if (booAddThis == true)                                     //If product is set to be re-added this is the place to do it
            {
            intNewPrice     = parseFloat(intNewPrice) + parseFloat(intCurrPrice);
            strNewPrices    = strNewPrices + intCurrPrice + "|";
            strNewProducts  = strNewProducts + strCurrProduct + "|";
            }
            
    }
            
         if (booNoNew != true)                                          //If no new product is being added don't trigger this
         {
            intNewPrice     = parseFloat(intNewPrice) + parseFloat(intPrice);
            strNewPrices    = strNewPrices + intPrice + "|";
            strNewProducts  = strNewProducts + strProductId + "|";
         }
        
        
        //---- Add the final calculations to the page.
        
        document.getElementById("hidPrices_array").value        = strNewPrices;
        document.getElementById("hidProducts_array").value      = strNewProducts;
        
        document.getElementById("priceTag").innerHTML           = "&pound;" + formatCurrency(intNewPrice);
        document.getElementById("priceTag1").innerHTML           = "&pound;" + formatCurrency(intNewPrice);
        
        //counts the amount of funeral letters cust is buying
        var letterPrice = document.getElementById("Attribute2_Price").value + 0;
        var letterTotal = document.getElementById("hidPrices_array").value.replace("|", "") + 0;
        
        document.getElementById("quantity").innerHTML =  letterTotal/letterPrice;          
}

function sendPriceMiniBasket(intPrice, strProductId, strAttributeDesc, intDiscount)
{

    /*
        LivePrice Changing in minibasket on buy page
        NC: 22-10-08   
    */   
    
    
    // ---- SPLIT THE PRICES AND products up from the hidden fields
        arrPrices1 = document.getElementById("hidPrices_array").value.split("|");
        arrProducts1 = document.getElementById("hidProducts_array").value.split("|");
    
    intNewPrice1     = 0.00;
    strNewProducts1  = '';
    strNewPrices1    = '';
    strAttDes         = "(" + strAttributeDesc + ")";
    
    
    intNewPrice1     = arrPrices1[0];    

    if (strAttDes.toLowerCase() == "(no upgrade)" || strAttDes.toLowerCase() == "(standard)")                                         
    {
        strAttDes         = '';   
    }  
  
        document.getElementById("priceTag1").innerHTML           = "&pound;" + formatCurrency(intNewPrice1);

        if (document.getElementById("priceTag0")) {
            document.getElementById("priceTag0").innerHTML = '<span id="colourgrey">Was: &pound;' + formatCurrency(intDiscount) + "</span>";
        }
        
        document.getElementById("attDescTag").innerHTML           = "&nbsp;" + strAttDes;
}


function sendAddonMiniBasket(strProductId, strAddonDesc, obj)
{

    /*
        Live Add on changing in mini basket
        NC: 22-10-08   
    */
    
    if (obj.checked == true) {
        document.getElementById("hidProductsDesc_array").value        = document.getElementById("hidProductsDesc_array").value + strAddonDesc + "|";
    }
    else{
        document.getElementById("hidProductsDesc_array").value        = document.getElementById("hidProductsDesc_array").value.replace(strAddonDesc+"|", "");
    }
    
    // ---- SPLIT THE products, descriptions, prices up from the hidden fields
        arrProducts2 = document.getElementById("hidProducts_array").value.split("|");
        arrDesc2 = document.getElementById("hidProductsDesc_array").value.split("|");
        arrPrices2 = document.getElementById("hidPrices_array").value.split("|");
        
    //Other vars
        tempBasket = '';
        
    for (var i=1 ; i < arrProducts2.length-1 ; i++)
    {
        tempBasket = tempBasket + '<li class="mainProd">1 x ' + arrDesc2[i] + '</li><li class="mainProdval">&pound;' + arrPrices2[i] + '</li>';
    }
    
   document.getElementById("addonsTag").innerHTML           = '<ul id="basketItems1">' + tempBasket + '</ul>';
}


//displays and hides postcode div

function showPostcodeCheck()
{
    if (document.getElementById("deliveryCheck").style.display!="block"){
        document.getElementById("deliveryCheck").style.display = "block"; 
    }
    else{
        document.getElementById("deliveryCheck").style.display = "none";
    }
}


//This function is to detect any unsupported characters within the funeral tribute box and alert the user.

function RegexCheck(objInput, strRegex)
{

    strInput = document.getElementById(objInput).value;

    rgxAlpha = new RegExp(strRegex);
    
    if(rgxAlpha.test(strInput) == true)
    {
    
    return false;
    
    }    

}

// - PUBLIC VARS FOR CHECK TRIBUTE

var intTributePrice = 0;
//added a productid var to fix funeral price bug in brands
function checkTribute(objInput, strAttribute, strProductid)
{

    //Declare local variables
    var strInput        = document.getElementById(objInput).value;    
    var intInputLen     = strInput.length;
    var intFinalPrice   = parseFloat(0.00);
    var intMultiplier   = parseFloat(0.00);
    var strOption       = "";
    
    
    //Make the string for the attribute field
    
    /*  ==  DEPRECATED CODE - does not need to perform this calculation
    var strAttributeName= "attribute" + strAttribute;
    
    var objAttribute    = document.confirm.elements[strAttributeName];
    
    for (k=0; k < objAttribute.length; k++)
    {
        if (objAttribute[k].checked == true)
        {
            strOption = objAttribute[k].value;
        }
        
        
    }
    
    switch(strOption)
        {
            case "M"    :
            
            intMultiplier = parseFloat(39.00);    
            break;
            
            case "O"    :
            
            intMultiplier = parseFloat(30.00);    
            break;        
        }
      
    */
    
    intMultiplier       = parseFloat(document.getElementById(strAttribute).value);
      
    intFinalPrice       = parseFloat(intMultiplier * intInputLen);    
    
    //check for an existing price
    if (intTributePrice == 0)
    {
        intTributePrice = intFinalPrice
    }
    
    
    //do regex check on string
    if (RegexCheck(objInput, "[^A-Za-z0-9_]") == false)
    {
        document.getElementById("msgVerdict").innerHTML = "InCorrect";
        document.getElementById(objInput).style.border = "1px solid #ff0000";
    }
    else
    {
        document.getElementById("msgVerdict").innerHTML = "Correct";
        document.getElementById(objInput).style.border = "1px solid #749F09";
        
        
        // Send price to control    
        if (intFinalPrice != intTributePrice)
        {
        sendPrice(intFinalPrice, strProductid);
        
        intTributePrice = intFinalPrice;
        }
        
        
    }

}


//slightly altered function to accomodate for refresh minibasket
function checkTributeRefresh(objInput, strAttribute, strProductid)
{

    //Declare local variables
    var strInput        = document.getElementById(objInput).value;    
    var intInputLen     = strInput.length;
    var intFinalPrice   = parseFloat(0.00);
    var intMultiplier   = parseFloat(0.00);
    var strOption       = "";
    
    
    //Make the string for the attribute field
    
    /*  ==  DEPRECATED CODE - does not need to perform this calculation
    var strAttributeName= "attribute" + strAttribute;
    
    var objAttribute    = document.confirm.elements[strAttributeName];
    
    for (k=0; k < objAttribute.length; k++)
    {
        if (objAttribute[k].checked == true)
        {
            strOption = objAttribute[k].value;
        }
        
        
    }
    
    switch(strOption)
        {
            case "M"    :
            
            intMultiplier = parseFloat(39.00);    
            break;
            
            case "O"    :
            
            intMultiplier = parseFloat(30.00);    
            break;        
        }
      
    */
    
    intMultiplier       = parseFloat(document.getElementById(strAttribute).value);
      
    intFinalPrice       = parseFloat(intMultiplier * intInputLen);    
    
    //check for an existing price
    if (intTributePrice == 0)
    {
        intTributePrice = intFinalPrice
    }
    
    
    //do regex check on string
    if (RegexCheck(objInput, "[^A-Za-z0-9_]") == false)
    {
        document.getElementById("msgVerdict").innerHTML = "InCorrect";
        document.getElementById(objInput).style.border = "1px solid #ff0000";
    }
    else
    {
        document.getElementById("msgVerdict").innerHTML = "Correct";
        document.getElementById(objInput).style.border = "1px solid #749F09";
        
        
        // Send price to control    
        if (intFinalPrice != intTributePrice)
        {
        sendPriceFuneral(intFinalPrice, strProductid);
        
        intTributePrice = intFinalPrice;
        }
        
        
    }

}


function showOccasion(strObject)
{

    if (booBalloonShow == true) 
    {
        document.getElementById("extras_options").style.display = 'block';
        
        booBalloonShow = false;
        
        document.getElementById(strObject).checked = true;
        
        
    }
 else
    {
        document.getElementById("extras_options").style.display = 'none';
        
        booBalloonShow = true;
        
        document.getElementById(strObject).checked = false;
        
    }
    

}


function pushOccasion(objSelected)
{

    strSelected = document.getElementById(objSelected).options[document.getElementById(objSelected).selectedIndex].value;
    
    if (strSelected != null && strSelected != "")
    {
        document.getElementById("extra_32").value = strSelected;
        
        //Change image too
        document.getElementById("imgBalloon").src = "/products/"  +   strSelected  +   "_add.jpg";
        
        //alert("Product Changed: " + strSelected); 
    }

}


function pushOccasionFD(objSelected)
{

    strSelected = document.getElementById(objSelected).options[document.getElementById(objSelected).selectedIndex].value;
    
    if (strSelected != null && strSelected != "")
    {
        document.getElementById("extra_32").value = strSelected;
        
        //Change image too
        document.getElementById("imgBalloon").src = "/images/loadbuy7/fd/"  +   strSelected  +   "_add.jpg";
        
        //alert("Product Changed: " + strSelected); 
    }

}


/*

Simple Image Trail script- By JavaScriptKit.com

Visit http://www.javascriptkit.com for this script and more

This notice must stay intact

*/



var offsetfrommouse=[15,10]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset

var displayduration=0; //duration in seconds image should remain visible. 0 for always.

var currentimageheight = 130;	// maximum image size.



if (document.getElementById || document.all){

	document.write('<div id="trailimageid">');

	document.write('</div>');

}



function gettrailobj(){

if (document.getElementById)

return document.getElementById("trailimageid").style

else if (document.all)

return document.all.trailimagid.style

}



function gettrailobjnostyle(){

if (document.getElementById)

return document.getElementById("trailimageid")

else if (document.all)

return document.all.trailimagid

}


function truebody(){

return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body

}



function showtrail(imagename){



	document.onmousemove=followmouse;



	newHTML = '<iframe src="' + imagename + '" scrolling="No" id="delivery_dates" height="135" width="265" frameborder="0"   />';



	gettrailobjnostyle().innerHTML = newHTML;



	gettrailobj().visibility="visible";



}





function hidetrail(){

	gettrailobj().visibility="hidden"

	document.onmousemove=""

	gettrailobj().left="-500px"



}



function followmouse(e){



	var xcoord=offsetfrommouse[0]

	var ycoord=offsetfrommouse[1]



	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15

	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)



	//if (document.all){

	//	gettrailobjnostyle().innerHTML = 'A = ' + truebody().scrollHeight + '<br>B = ' + truebody().clientHeight;

	//} else {

	//	gettrailobjnostyle().innerHTML = 'C = ' + document.body.offsetHeight + '<br>D = ' + window.innerHeight;

	//}



	if (typeof e != "undefined"){

		if (docwidth - e.pageX < 380){

			xcoord = e.pageX - xcoord - 250 - offsetfrommouse[0]; // Move to the left side of the cursor

		} else {

			xcoord += e.pageX;

		}

		if (docheight - e.pageY < (currentimageheight + 110)){

			ycoord += e.pageY - Math.max(0,(110 + currentimageheight + e.pageY - docheight - truebody().scrollTop)) + offsetfrommouse[0];

		} else {

			ycoord += e.pageY + offsetfrommouse[1];

		}



	} else if (typeof window.event != "undefined"){

		if (docwidth - event.clientX < 380){

			xcoord = event.clientX + truebody().scrollLeft - xcoord - 250 - offsetfrommouse[0]; // Move to the left side of the cursor

		} else {

			xcoord += truebody().scrollLeft+event.clientX

		}

		if (docheight - event.clientY < (currentimageheight + 110)){

			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(110 + currentimageheight + event.clientY - docheight)) + offsetfrommouse[0];

		} else {

			ycoord += truebody().scrollTop + event.clientY;

		}

	}



	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15

	var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)

		if(ycoord < 0) { ycoord = ycoord*-1; }

	gettrailobj().left=xcoord+"px"

	gettrailobj().top=ycoord+"px"



}

