var previousQuantity = 1;

function setNumber(obj)
{
    previousQuantity = obj.value;
    //alert("hello...");
}

function checkNumber(obj)
{
    if (isNaN(obj.value) || trim(obj.value) == "")
        obj.value = previousQuantity;
}

// Trims all white space at the beginning and end of a string
function trim(s) 
{
	// Remove whitespace from the start of the string
	while (s.substring(0, 1) == " ") 
	{
		s = s.substring(1, s.length);
	}
  
	// Remove whitespace from the end of the string
	while (s.substring(s.length-1, s.length) == " ") 
	{
		s = s.substring(0, s.length-1);
	}
  
	return s;
}

function openPopup(filename, size)
{
    var url = "thumbnail.aspx?max=" + size + "&filename=" + filename;
    
    window.open(url, null, "height=500,width=500,status=yes,toolbar=no,menubar=no");
}


function showProductsByManufacturer (objDropDown)
{
    if (objDropDown.value != "")
    {
        var url = "product_list.aspx?manufacturerid=" + objDropDown.value;
        
        window.location = url;
    }
}


/*
JDA - 5th February 2011

Work out the next despatch time...
*/
function getNextDespatchTime()
{
    var deliveryHour = 16;

    var targetDateTime = new Date();

    // We need to set the target time of the countdown to 4pm of the next working day (which may be today).
    if (targetDateTime.getHours() >= deliveryHour
            || targetDateTime.getDay() == 0
                || targetDateTime.getDay() == 6)
        targetDateTime.addBusinessDays(1);

    targetDateTime.setHours(deliveryHour, 0, 0, 0);

    return targetDateTime;
}
