//  Quick Search
	function suggest(inputString){
		if (inputString!="Quick Search") {
		if(inputString.length > 2) {
		ClientID=$("#CID").val();
		WSID=$("#WSID").val();
		Home=$("#Home").val();
		$.get("/SharedJavascript/Ajax/AjaxSearchResults.php", {Search: ""+inputString+"", ClientID: ""+ClientID+"", WSID: ""+WSID+"", H:""+Home+""}, function(data){
				if(data.length >0) {
					var position = $('#QuickSearch').position();
					position.left=position.left-5;
					var width=$('#QuickSearchBox').width();
					$('#suggestions').html(data);
					var height=$('#suggestions').height();
					if ( position.top / $("body").height() > .6) position.top=position.top - height -10;
					else position.top=position.top + 15;
					$('#suggestions').css(position) ;
					$('#suggestions').width(width) ;
					$('#suggestions').fadeIn();
				}
			});
		}}
	}
	
	
 
	function fill(thisValue) {
		$('#QuickSearch').val(thisValue);
		setTimeout("$('#suggestions').fadeOut();", 100);
		 if($('#QuickSearch').val() === '') $('#QuickSearch').val("Quick Search");
	}
	
	function clearSearchText() {
		 if($('#QuickSearch').val() === 'Quick Search') $('#QuickSearch').val('');
	}
	
	
	$(document).ready(function() {
		 if($('#QuickSearch').val() === '') $('#QuickSearch').val("Quick Search");
		 if ($.cookie('SortOrder')) $('#SortOptions').val($.cookie('SortOrder')) ;
		 $('#SortOptions').change( function() {
						  var SortOrder= $(this).val();
						  var href = window.location.href;
						//	href=href+'&SortOrder='+SortOrder;
							$.cookie('SortOrder', SortOrder);
						  	window.location.href = href; 
						 
						  })
		});

// End Quick Search

function MM_openBrWindow(theURL,features) { //v2.0
  imw = window.open(theURL,'PopUp',features);
  imw.focus();
}

$(function() {
	$('.LightBox').lightBox(); // Select all links with lightbox class
	$('.example5').colorbox({initialWidth:"50%", initialHeight:"50%", opacity:.8});  //, iframe:true
});



//VALIDATE QUANTITY WHEN ADDING TO CART
function validateQuantity(index, minOrder, AddQty, StockControl, CartonQty)
{
	//alert('Qty Changed');
	// get controls
    quantityBox = document.getElementById(index);
    if (minOrder==0) minOrder=1;
	var quantitycheck;
	var allowSubmit;
	allowSubmit=true;
	minOrder=parseFloat(minOrder);
	AddQty=parseFloat(AddQty);
    // invalid if text box not found
    if (!quantityBox) {
			alert ('error');
            return false;
	} else {
            quantity = parseFloat(quantityBox.value);
            // only check further if have a value
            if (quantity) {
                    //check that quantity is a whole number
                 //   if (isNaN(quantity) || (parseInt(quantity) != quantity-0)) {
                 //           alert("You must enter a whole number!");
                //            quantityBox.value="";
                 //           quantityBox.focus();
                //            return false;
                //    }
                    //check that quantity is greater or equal to minorder
                    if ((quantity == 0) || (quantity<minOrder)) {
                            alert("This product has a minimum order of " + minOrder + "!\nPlease enter a new quantity or click the Update Cart button again to add the revised Quantity.");
                            quantityBox.value=minOrder;
                            quantityBox.focus();
							allowSubmit=false;
                            return false;
							
                    }  
					
					//check that quantity is a multiple of minorder
					if (AddQty>0) {
						if (AddQty==0) AddQty=1;
						quantitycheck=quantity-minOrder;
					   // if ((quantity == 0) || (quantity%AddQty != 0)) {
						  if (quantitycheck%AddQty != 0) {
								alert("This product can only be purchased in Additional lots of " + AddQty + "!\nPlease enter a new quantity.");
								quantityBox.value="";
								quantityBox.focus();
								allowSubmit=false;
								return false;
								
						}   
					}
					// Check if qty hits carton pricing
					if (CartonQty>0 & quantity>=CartonQty) {
							cartonremainintgitems=(quantity%CartonQty);
							totalcartonitems=Math.floor(quantity / CartonQty);
							totalcartonitems=totalcartonitems*CartonQty;
						alert(totalcartonitems+" items qualify for carton pricing\nSavings will be applied at checkout.");
					} else if (CartonQty>0 & (quantity/CartonQty >= .8) ) {
						extraforcarton=	CartonQty - quantity;
						alert("You would qualify for carton pricing if you ordered "+ extraforcarton +" more item(s).");
					}					
					
					
					if(StockControl!='OFF')  {
						if (quantity>StockControl) {
							alert("You cannot order more than we currently have in stock.\nPlease order a maximum quantity of "+StockControl);
							quantityBox.value="";
							quantityBox.focus();
							allowSubmit=false;
							return false;
							
						}
					}
            }
    }
	this.form.submit();
	alert("Item has been added to your cart.");
   	return true;
   // alert( allowSubmit );    
}

function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}

jQuery.fn.center = function () { 
    this.css("position","absolute"); 
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px"); 
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px"); 
    return this; 
} 


