function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

$(document).ready(function() {
    $('.scrolling_news').SetScroller({
        velocity: 60,
        direction: 'horizontal',
        startfrom: 'right',
        loop: 'infinite',
        movetype: 'linear',
        onmouseover: 'pause',
        onmouseout: 'play',
        onstartup: 'play',
        cursor: 'pointer'
    });

    $("#brands li img").each(function() {
        var height = parseInt($(this).height());
        var need_margin = 0;
        if (height < 40) {
            var margin = parseInt($(this).css("margin-top"));
            need_margin = (40 - height) / 2;
            margin = margin + need_margin;
            $(this).css("margin-top", margin + "px");
        }
    });

    //This function will check text box on focus, and clean it
    $(".search_input").focus(function() {
        if ($(this).val() == "Enter keyword or code") {
            $(this).val("");
        }
    });

    //This function check the input value on focus over
    $(".search_input").focusout(function() {
        if ($(this).val() == "") {
            $(this).val("Enter keyword or code");
        }
    });
	
	
	 //This function will check code box on focus, and clean it
    $(".inf2 .pinput").focus(function() {
        if ($(this).val() == "Code") {
            $(this).val("");
        }
    });

    //This function check the code input value on focus over
    $(".inf2 .pinput").focusout(function() {
        if ($(this).val() == "") {
            $(this).val("Code");
        }
    });	
	

    //This function will check text box on focus, and clean it
    $(".newsletter_input").focus(function() {
        if ($(this).val() == "Enter your email") {
            $(this).val("");
        }
    });

    //This function check the input value on focus over
    $(".newsletter_input").focusout(function() {
        if ($(this).val() == "") {
            $(this).val("Enter your email");
        }
    });

    $(".numericonly").keypress(function(e) {
        console.log(e);
        if (!String.fromCharCode(e.keyCode).match(/[^0-9]/g))
            return false;
    });


});

function HideStockError(pos) {
	$('#'+pos).fadeOut('fast');
}

function ShowStockError(pos) {
	$('.jGrowl').not('#'+pos).css("display","none");
	$('#'+pos).fadeIn('slow');
}

function SimpleSwap(el,which,large){	
	document.getElementById(el).src=which;
	LargeImage=large; 
  return true;
}

function updatecart(sku,minqty,pricelist) {
	qty=document.getElementById("prdqty"+sku).value;
	var enpricelist = pricelist.replace(/>/gi, "%3E");
	window.location = '/add_to_cart_ajax.asp?order_prod=' + sku + '&order_qty=' + qty + '&mode=addtocart&price=' + enpricelist + '&location=' + encodeURI(window.location);
}

function mathAddToField(pFieldId, pAmount, pMinValue){
	var elm = document.getElementById(pFieldId);
	if (elm)
		elm.value = parseInt(elm.value) + pAmount;
	if (pMinValue && elm.value < pMinValue)
		elm.value = pMinValue;
}

            function CheckOrderAmount(total)
            {
                if(total<30)
                {
                      alert('The minimum goods order value is \u00A3 30 excluding VAT. Please increase your quantity or add further items');
                      return false;
                }
                document.frmcart.m.value='checkcart';
                document.frmcart.submit();
                return true;
            }
			
			function mathAddToField(pFieldId, pAmount, pMinValue)
			{
				var elm = document.getElementById(pFieldId);
				
				if (elm)
					elm.value = parseInt(elm.value) + pAmount;
					
				if (pMinValue && elm.value < pMinValue)
					elm.value = pMinValue;
			}
			
			function doBasketUpdate()
			{
				var frm = document.getElementById('frmcart');
				var frmact = document.getElementById("m");
				frmact.value = 'update';
				frm.submit();
			}
			
			function doCartAction(pAction)
			{
				var frm = document.getElementById('frmcart');
				var frmact = document.getElementById("m");
				frmact.value = pAction;
				frm.submit();
}

function CheckNum(e) {
    IsValidate(e, '0123456789.,-+', false);
}
function IsValidate(e, pattern, bspacebar) {
    var keynum;
    if (window.event) {
        keynum = e.keyCode;
    } else {
        if (e.which) {
            keynum = e.which;
        }
    }
    var key = String.fromCharCode(keynum);
    if (keynum == 13) {
        e.returnValue = keynum;
        return true;
    } else if (keynum == 32) {
        if (bspacebar == false) {
            if (e.stopPropagation) {
                e.stopPropagation();
            }
            e.cancelBubble = true;
            if (e.preventDefault) {
                e.preventDefault();
            }
            e.returnValue = false;
            return false;
        } else {
            e.returnValue = keynum;
            return true;
        }
    } else if ((e.keyCode > 7 && e.keyCode < 10) || (e.keyCode > 27 && e.keyCode < 30) || (e.keyCode == 46) || e.keyCode > 47 && e.keyCode < 58) {
        window.status = '';
        return true;
    } else {
        if (pattern.indexOf(key) == -1) {
            if (e.stopPropagation) {
                e.stopPropagation();
            }
            e.cancelBubble = true;
            if (e.preventDefault) {
                e.preventDefault();
            }
            e.returnValue = false;
            return false;
        } else {
            e.returnValue = keynum;
            return true;
        }
    }
} 
