function search_pselected(index){chk=$("picb_"+index);qty=$("piqn_"+index);if( chk.checked == true ){if(qty.value.length==0){if($("pipc_"+index)!=null){qty.value=$("pipc_"+index).value;}else{qty.value=1;}}}else{qty.value="";}}
function search_quantity_update(index){val=$("piqn_"+index).value;if(val.length>0){$("picb_" + index).checked = true;}else{$("picb_" + index).checked = false;}}
function search_vatc(){validated = false;total=parseInt($("pTotal").value);for(i=0;i<total;i++){if($("picb_"+i).checked==true){qval=$("piqn_"+i);if(qval.value.length==0||isNaN(qval.value)){alert("Please enter a valid number");qval.value="";qval.focus();return false;}else{qty=parseInt(qval.value);if(qty<=0){qval.value = 1;}validated = true;}}else{$("piqn_"+i).value="";}}if(validated==false){alert("Please select some parts to add to cart");return false;}return true;}

var StoreSearch = {
	PageNav:function(pnum){url = "search.jsp?term="+$F('term')+"&requestId="+$F('requestId')+"&p="+pnum;location.href=url;},
	SearchValidate:function(){v=""+$F('ssearchinput');if(v.length==0){alert("Please enter a part number or keyword to search for");$('ssearchinput').focus();return false;}return true;},
	AddToCartReset:function(index){$('cartAddedMessageTxt_'+index).hide();},
	AddToCartMessageDa:function(rowIndex,okMessage){closeBtnMsg = '<a href="#" onClick="StoreSearch.AddToCartReset('+rowIndex+');return false;" title="Dismiss this message"><img src="' + $F("imgcheckurl") + '" border="0" style="vertical-align:middle" /></a>&nbsp;&nbsp;' + okMessage;$('cartAddedMessageDiv_'+rowIndex).update(closeBtnMsg);new Effect.Appear('cartAddedMessageRow_'+rowIndex);new Effect.Highlight('cartAddedMessageDiv_'+rowIndex,{startcolor:'#9AC166'});},
	AddToCartMessageNyet:function(rowIndex, eMessage){closeBtnMsg = '<a href="#" onClick="StoreSearch.AddToCartReset('+rowIndex+');return false;" title="Dismiss this message"><img src="' + $F("imgcrossurl") + '" border="0" style="vertical-align:middle" /></a>&nbsp;&nbsp;' + eMessage;$('cartAddedMessageDiv_'+rowIndex).update(closeBtnMsg);new Effect.Appear('cartAddedMessageRow_'+rowIndex);new Effect.Highlight('cartAddedMessageDiv_'+rowIndex,{startcolor:'#FFCCCC'});},
	AddToCart:function(pindex){quan="" + $F('pq_'+pindex);if(quan.length == 0 || isNaN($F('pq_'+pindex))){quan=1;$('pq_'+pindex).value = 1;}new Ajax.Request($F('carturl'),{method:'post',parameters:{mode:'addtocart',partIndex:pindex,requestId:$F('requestId'),quantity:quan,branch:$F('branch_'+pindex)},onSuccess:function(transport){var json = transport.responseText.evalJSON(true);if(json.added != null){StoreSearch.AddToCartMessageDa(pindex,'Part added to Shopping Cart. Proceed to <a href="' + $F('shoppingcarturl') + '">Cart</a>.');FamilyPricing.OpenFamilyPricingUpdate();}else if(json.error != null){StoreSearch.AddToCartMessageNyet(pindex,""+json.error);}else{StoreSearch.AddToCartMessageNyet(pindex,"Unable to add part to Shopping Cart");}},onFailure:function(transport){StoreSearch.AddToCartMessageNyet("Unable to add part to Shopping Cart");}});return false;}
}