﻿// JScript File
function confirmAddToFavourite(line1, price, quantityTextBox,minimum, increment, units)
{
    if(confirmQuantity(quantityTextBox,minimum, increment) == false)
    {
        return false;
    }
    
    var qTextBox = document.getElementById(quantityTextBox);
    var quantity = parseFloat(qTextBox.value);
      
    var total = price * quantity;
    var textToDisplay = line1 + " " + "A$" + total.toFixed(2) + "(inc) will be added to your favourite order";
    return confirm(textToDisplay);
}

function confirmAddToBasket(line1, price, quantityTextBox,minimum, increment, units)
{
    if(confirmQuantity(quantityTextBox,minimum, increment) == false)
    {
        return false;
    }
    
    var qTextBox = document.getElementById(quantityTextBox);
    var quantity = parseFloat(qTextBox.value);
      
    var total = price * quantity;
    var textToDisplay = line1 + " " + "A$" + total.toFixed(2) + "(inc) will be added to your cart";
    return confirm(textToDisplay);
}

function confirmAddBoxItemsToBasket(boxTypeName, line1, price, quantityTextBox,minimum, increment, units)
{
    if(confirmQuantity(quantityTextBox,minimum, increment) == false)
    {
        return false;
    }
    
    var qTextBox = document.getElementById(quantityTextBox);
    var quantity = parseFloat(qTextBox.value);
      
    var total = price * quantity;
    //var textToDisplay = line1 + " " + "A$" + total.toFixed(2) + "(inc) will be added to your cart";
    var textToDisplay = "Items from your " + boxTypeName + " will be added to your cart.";
    return confirm(textToDisplay);
}

function confirmQuantity(quantityTextBox,minimum, increment)
{
    var qTextBox = document.getElementById(quantityTextBox);
    if(qTextBox.value == '')
    {
        alert('Please select a valid amount');
        return false;
    }

    var quantity = parseFloat(qTextBox.value);

    if(quantity < minimum)
    {
        alert('Please select a valid amount, the minimum quantity is ' + minimum);
        return false;
    }

    if((((quantity * 1000).toFixed(0) / (increment * 1000).toFixed(0)) % 1) > 0)
    {
        alert('Please select a valid amount, use increments of ' + increment);
        return false;
    }
    return true;
}


function ToggleMoreLess(linkId,label1Id, label2Id)
{
    var theLink = document.getElementById(linkId);
    var label1 = document.getElementById(label1Id);
    var label2 = document.getElementById(label2Id);
   // alert(label2Id);
    if(label1.style.display == "none")
    {
        //link.innerText = "...More";
        label2.style.display = "none";
        label1.style.display = "inline";
		theLink.style.background='transparent url(images/global/icons/icon_plus_blue.gif) no-repeat left 2px';
		$(theLink).empty();
		$(theLink).prepend("more");
    }
    else
    {
        //link.innerText = "...Close";
        label1.style.display = "none";
        label2.style.display = "inline";
		theLink.style.background='transparent url(images/global/icons/icon_minus_blue.gif) no-repeat left 2px';
		$(theLink).empty();
		$(theLink).prepend("less");
    }
}

function startJS() {
	$(".button").each(function(i){
		if( $(this).attr("disabled") == true) {
			//alert( $(this).attr("id") );
			$(this).addClass("disabled-btn")
		}
	});
	$('a[rel="external"]').click( function() {
        window.open( $(this).attr('href'), 'Lettuce Deliver','directories=no,location=no,menubar=no,resizable=no,status=no,toolbar=no,scrollbars=yes,width=500,height=500');
        return false;
    });

}

function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/-/g, "\-");
	var oRegExp = new RegExp("(^|\s)" + strClassName + "(\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}


function openpopup(url, windowtarget) 
{
    window.open(url, windowtarget, 'width=550,height=600,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0');
}
function openpopupsmall(url, windowtarget) 
{
    window.open(url, windowtarget, 'width=350,height=300,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0');
}
