/// <reference path="jquery-1.4.1-vsdoc.js"/>




$(document).ready(function () {


    addMinCartEvent();
    addMianNavEvents();

    $('a').click(function () { $(this).blur(); });
    $('img').click(function () { $(this).blur(); });

    // Your code here
});    // JavaScript Document


//add mouse over event to mini cart and whish list
function addMinCartEvent(){

    $('#basketdrop').mouseenter(function (event) {

        $('#basketexpand').slideDown('fast', function () { });

    });


    $('#basketdrop').mouseleave(function (event) {

        $('#basketexpand').slideUp('fast', function () { });

    });

    $('#wishdrop').mouseenter(function (event) {

        $('#wishexpand').slideDown('fast', function () { });

    });

        
    $('#wishdrop').mouseleave(function (event) {

        $('#wishexpand').slideUp('fast', function () { });

    });


 }



//  add mouseover events for main nave
 function addMianNavEvents() {

     // Bind events to parts drop down
     var bolpartsDrop = 'false';
     var bolpartsTrigger = 'false';


    //slide down on ouse over
//    $('#parstTrigger').mouseenter(function (event) {
//        bolpartsTrigger = 'true'
//        $('#partsDrop').fadeIn('fast', function () { });
     //    });


     //slide down on ouse over
     var ptEnter = false;
     $('#parstTrigger').mouseenter(function (event) {

         ptEnter = true;
         var pTimeDelay = setTimeout(function () {

            if (ptEnter){
             bolpartsTrigger = 'true'
             $('#partsDrop').fadeIn('fast', function () { });
             }

         }, 400);
     });


    //slide up when leave but wai to see if moused over drop dobw
     $('#parstTrigger').mouseleave(function (event) {
         ptEnter = false;
         bolpartsTrigger = 'false'
         var timDelay = setTimeout(function () {
             if (bolpartsDrop == 'false') {
                 $('#partsDrop').fadeOut('fast', function () { });
             }
         }, 50);

     });




    //set true when mouse over drop down
    $('#partsDrop').mouseenter(function (event) {
        $('#parstTrigger').css("background-color", "#d4d4d5");
        bolpartsDrop = 'true';
    });

    //slide up if not moused over trigger or drop down
    $('#partsDrop').mouseleave(function (event) {
        bolpartsDrop = 'false';
        $('#parstTrigger').css("background-color", "");

        var timDelay = setTimeout(function () {
            if (bolpartsTrigger == 'false') {
                $('#partsDrop').fadeOut('fast', function () { });
            }
        }, 50);         

    });



    // Bind events to parts drop down
    var bolToolsDrop = 'false';
    var bolToolsTrigger = 'false';


    var ttEnter = false;
    $('#toolsTrigger').mouseenter(function (event) {

        ttEnter = true;
        var pTimeDelay = setTimeout(function () {

            if (ttEnter) {
                bolpartsTrigger = 'true'
                $('#toolsDrop').fadeIn('fast', function () { });
            }

        }, 400);
    });



///    slide down on ouse over
//    $('#toolsTrigger').mouseenter(function (event) {
//        bolToolsTrigger = 'true'
//        $('#toolsDrop').fadeIn('fast', function () { });
//    });


    //slide up when leave but wai to see if moused over drop dobw
    $('#toolsTrigger').mouseleave(function (event) {

        ttEnter = false;
        bolToolsTrigger = 'false'
        var timDelay = setTimeout(function () {
            if (bolToolsDrop == 'false') {
                $('#toolsDrop').fadeOut('fast', function () { });
            }
        }, 50);

    });

    //set true when mouse over drop down
    $('#toolsDrop').mouseenter(function (event) {
        $('#toolsTrigger').css("background-color", "#d4d4d5");
        bolToolsDrop = 'true';
    });

    //slide up if not moused over trigger or drop down
    $('#toolsDrop').mouseleave(function (event) {
        $('#toolsTrigger').css("background-color", "");
        bolToolsDrop = 'false';
        var timDelay = setTimeout(function () {
            if (bolToolsTrigger == 'false') {
                $('#toolsDrop').fadeOut('fast', function () { });
            }
        }, 50);

    });



    // Bind events to parts drop down
    var bolInfoDrop = 'false';
    var bolInfoTrigger = 'false';


    var itEnter = false;
    $('#infoTrigger').mouseenter(function (event) {

        itEnter = true;
        var pTimeDelay = setTimeout(function () {

            if (itEnter) {
                bolpartsTrigger = 'true'
                $('#infoDrop').fadeIn('fast', function () { });
            }

        }, 400);
    });



//    //slide down on ouse over
//    $('#infoTrigger').mouseenter(function (event) {
//        bolInfoTrigger = 'true'
//        $('#infoDrop').fadeIn('fast', function () { });
//    });


    //slide up when leave but wai to see if moused over drop dobw
    $('#infoTrigger').mouseleave(function (event) {
        itEnter = false;
        bolInfoTrigger = 'false'
        var timDelay = setTimeout(function () {
            if (bolInfoDrop == 'false') {
                $('#infoDrop').fadeOut('fast', function () { });
            }
        }, 50);

    });

    //set true when mouse over drop down
    $('#infoDrop').mouseenter(function (event) {
        $('#infoTrigger').css("background-color", "#d4d4d5");
        bolInfoDrop = 'true';
    });

    //slide up if not moused over trigger or drop down
    $('#infoDrop').mouseleave(function (event) {
        $('#infoTrigger').css("background-color", "");
        bolInfoDrop = 'false';
        var timDelay = setTimeout(function () {
            if (bolInfoTrigger == 'false') {
                $('#infoDrop').fadeOut('fast', function () { });
            }
        }, 50);

    });




 }



 function showDiv(id) {
         $('#' + id + '').show();

 }


 function hideDiv(id) {

     $('#' + id + '').hide();

 }



 function bindPorductTabs(){

     $('#infotabs a').click(function (e) {
         $('#infotabs a').removeClass("active");

         $(this).addClass('active')

         $('#infoTabsInfo div').hide();
         var theDiv = '#' + $(this).attr('id') + 'Div';
         $(theDiv).show();

     })


 }

 function bindRelatedTabs() {

     $('#alternateTabs a').click(function (e) {
         $('#alternateTabs a').removeClass("active");

         $(this).addClass('active')

         $('#alternateTabsInfo .info').hide();
         var theDiv = '#' + $(this).attr('id') + 'Div';
         $(theDiv).show();
         $(theDiv + ' .info').show();

     })

 }

 function bindProductCartButtons() {


     $('#Product .imgcart').click(

            function () {

                var id = $(this).parent().parent().find('.txtqty').attr('id');
                var link = $(this).parent().parent().find('.txtqty').attr('link');

                var value = $(this).parent().parent().find('.txtqty').attr('value');
                var title = $(this).parent().parent().find('.txtqty').attr('title');
                var code = $(this).parent().parent().find('.txtqty').attr('code');

                if ($(this).parent().parent().find('.options').length) {



                    var sVal = $(this).parent().parent().find('.options').val();
                    var arrVal = sVal.split('^');

                    id = arrVal[0];
                    link = arrVal[1];

                    //var value = arrVal[3];
                    title = arrVal[2];
                    code = arrVal[3];





                }



                // var url = '/cart.aspx?id=' + id.replace('qty_', '') + '&qty=' + value;
                //window.location= url;
                // var call = id.replace('qty_', '') + ',' + price + ',' + title + ',cart'
                //                var call = id.replace('qty_', '') + ',' + code + ',' + title + ',' + link + ',' + value + ',' + 'cart';

                //                alert(call);
                addToWishList(id.replace('qty_', ''), code, title, link, value, 'cart');

            }

        );

            $('#Product .imgwishlist').click(

            function () {

                var id = $(this).parent().parent().find('.txtqty').attr('id');
                var link = $(this).parent().parent().find('.txtqty').attr('link');

                var value = $(this).parent().parent().find('.txtqty').attr('value');
                var title = $(this).parent().parent().find('.txtqty').attr('title');
                var code = $(this).parent().parent().find('.txtqty').attr('code');

                if ($(this).parent().parent().find('.options').length) {



                    var sVal = $(this).parent().parent().find('.options').val();
                    var arrVal = sVal.split('^');

                     id = arrVal[0];
                     link = arrVal[1];

                    //var value = arrVal[3];
                     title = arrVal[2];
                     code = arrVal[3];




                }



                // var url = '/cart.aspx?id=' + id.replace('qty_', '') + '&qty=' + value;
                //window.location= url;
                // var call = id.replace('qty_', '') + ',' + price + ',' + title + ',cart'
                // alert(call);
                 // alert('wish');

                addToWishList(id.replace('qty_', ''), code, title, link, value, 'wish');

            }

        );



 }

 function bindProds() {

     $('.prod').unbind();
     $('.prod .imgcart').unbind();
     $('.prod .imgwishlist').unbind();


         // bind the cart drop down
         $('.prod').hover(
      function () {
          $(this).find('.cartinfo').show();
      },
        function () {
            $(this).find('.cartinfo').hide();
        }

      );

        $('.prod .imgcart').click(

            function () {

                var id = $(this).parent().parent().find('.txtqty').attr('id');
                var link = $(this).parent().parent().find('.txtqty').attr('link');
                var value = $(this).parent().parent().find('.txtqty').attr('value');
                var title = $(this).parent().parent().find('.txtqty').attr('title');
                var code = $(this).parent().parent().find('.txtqty').attr('code');

                if ($(this).parent().parent().find('.options').length) {



                    var sVal = $(this).parent().parent().find('.options').val();
                    var arrVal = sVal.split('^');

                    id = arrVal[0];
                    link = arrVal[1];

                    //var value = arrVal[3];
                    title = arrVal[2];
                    code = arrVal[3];




                }








                // var url = '/cart.aspx?id=' + id.replace('qty_', '') + '&qty=' + value;
                //window.location= url;
//                var call = id.replace('qty_', '') + ',' + code + ',' + title + ',' + link + ',' + value + ',' + 'cart';
//                 alert(call);

                addToWishList(id.replace('qty_', ''), code, title, link, value, 'cart');

                
                //if pop up thne close
//                if ($(this).parent().parent().find('.txtqty').attr('popup').length) {

//                     window.opener.location.reload();
//                     window.close();

               // }


            }

        );

            $('.prod .imgwishlist').click(

            function () {

                var id = $(this).parent().parent().find('.txtqty').attr('id');
                var link = $(this).parent().parent().find('.txtqty').attr('link');

                var value = $(this).parent().parent().find('.txtqty').attr('value');
                var title = $(this).parent().parent().find('.txtqty').attr('title');
                var code = $(this).parent().parent().find('.txtqty').attr('code');

                if ($(this).parent().parent().find('.options').length) {

                    



                    var sVal = $(this).parent().parent().find('.options').val();
                    var arrVal = sVal.split('^');
                    
                    id = arrVal[0];
                    link = arrVal[1];

                    //var value = arrVal[3];
                    title = arrVal[2];
                    code = arrVal[3];



                }



                // var url = '/cart.aspx?id=' + id.replace('qty_', '') + '&qty=' + value;
                //window.location= url;
                // var call = id.replace('qty_', '') + ',' + price + ',' + title + ',cart'
                // alert(call);
               // alert('wish');
                addToWishList(id.replace('qty_', ''), code, title, link, value, 'wish');

            }

        );


        }


// function to create product popups for parts list
 function bindPartsPopUps() {
  
 //find the item
     $('.scroll .item').hover(

     //hover function
      function () {
          //   alert('tets'); 
          //get popup
          var $popUp = $(this).find('.popUpProduct');
          $popUp.css('top', $(this).position().top);
          $popUp.show();
          $popUp.html('Loading...');
          // alert($(this).find('.popUpProduct'));
          //  $(popUp).show();
          // alert('test');

          // get prod id
          var prodId = $popUp.attr('id');
          var prodId = prodId.replace('popup_', '');
          // ajax the product

          $.get('/ajax/PopUpProduct.aspx?ProdID=' + prodId, function (data) { $popUp.html(data); });



      },

     //hover out function
        function () {
            var $popUp = $(this).find('.popUpProduct');
            $popUp.hide();
        }

      );



    }


    //get auto products
    function bindPrompt(input, list, output) {




        $(input).keyup(function () {

            //    alert( $(input).val() );


            $(list).show();
            var date = new Date();

            $.get('/ajax/SelectProducts.aspx?output=' + output + '&txt=' + escape($(input).val()) + '&date=' + date.getTime(), function (data) {

                $(list).html(data);

                $(list + ' a').click(function (theLink) {
                    //  alert($(this).attr('itemid'));

                    $(input).val($(this).attr('title'));

                    $(output).val($(this).attr('itemid'));

                    $(list).hide();


                });


            });


        });

}
            //get auto products
function bindProductSearch(input, list) {


    $(list).hover(function () { $(this).show(); }, function () { $(this).hide(); });
    $(input).hover(function () { $(list).show(); }, function () {  $(list).hide(); } );


    $('#searchbox').click(function () { $(this).val(''); $(this).addClass('searchbox2'); });




    $(input).keyup(function () {

        //    alert( $(input).val() );

        var thelength = $(input).val().length;
        if (thelength > 2) {



            $(list).show();

            var date = new Date();

          //  alert('/ajax/ProductSearch.aspx?txt=' + $(input).val() + '&date=' + date.getTime());
            $.get('/ajax/ProductSearch.aspx?txt=' + escape($(input).val()) + '&date=' + date.getTime(), function (data) {
                $(list).html(data);
            });

        }
        else {
            $(list).hide();
        }


    });

}

var ajax1 = 3;
var ajax2 = 3;
var ajax3 = 3;

//get auto products
function bindMainProductSearch(input, list) {


    $(list).hover(function () { $(this).show(); }, function () { $(this).hide(); });
    $(input).hover(function () { $(list).show(); }, function () { $(list).hide(); });


    $('#searchbox').click(function () { $(this).val(''); $(this).addClass('searchbox2'); });




    $(input).keyup(function () {


        //alert(ajax1)


           if (ajax1 != 3){

    //alert('abot');
     ajax1.abort();

 }

 if (ajax2 != 3) {

     //alert('abot');
     ajax2.abort();

 }

 if (ajax3 != 3) {

     //alert('abot');
     ajax3.abort();

 }



        $('#FoundSearch').html('');
        $('#ReplacedSearch').html('');
        $('#FitsSearch').html('');

        //    alert( $(input).val() );

        var thelength = $(input).val().length;
        if (thelength > 2) {



            $(list).show();

            var date = new Date();
            //            //  alert('/ajax/ProductSearch.aspx?txt=' + $(input).val() + '&date=' + date.getTime());
            //            $.get('/ajax/ProductSearch.aspx?txt=' + escape($(input).val()) + '&date=' + date.getTime(), function (data) {
            //                $(list).html(data);
            //            });

            //  alert('/ajax/ProductSearch.aspx?txt=' + $(input).val() + '&date=' + date.getTime());
            //            ajax1 = $.get('/ajax/ProductSearch.aspx?txt=' + escape($(input).val()) + '&date=' + date.getTime(), function (data) {
            //                $('#FoundSearch').html(data);
            //            });

            ajax1 = $.ajax({

                url: '/ajax/ProductSearch.aspx?txt=' + escape($(input).val()) + '&date=' + date.getTime(),

                success: function (data) {
                    $('#FoundSearch').html(data);
                }
            });

            ajax2 = $.ajax({

                url: '/ajax/ProductSearch_partfits.aspx?txt=' + escape($(input).val()) + '&date=' + date.getTime(),

                success: function (data) {
                    $('#ReplacedSearch').html(data);
                }
            });

            ajax3 = $.ajax({

                url: '/ajax/ProductSearch_alternate.aspx?txt=' + escape($(input).val()) + '&date=' + date.getTime(),

                success: function (data) {
                    $('#FitsSearch').html(data);
                }
            });

            //            ajax1 = $.get('/ajax/ProductSearch.aspx?txt=' + escape($(input).val()) + '&date=' + date.getTime(), function (data) {
            //                $('#FoundSearch').html(data);
            //            });



            //            var date2 = new Date();
            //  alert('/ajax/ProductSearch.aspx?txt=' + $(input).val() + '&date=' + date.getTime());
            //            ajax2 = $.get('/ajax/ProductSearch_partfits.aspx?txt=' + escape($(input).val()) + '&date=' + date2.getTime(), function (data) {
            //                $('#ReplacedSearch').html(data);
            //            });
            //            var date3 = new Date();
            //            ajax3 = $.get('/ajax/ProductSearch_alternate.aspx?txt=' + escape($(input).val()) + '&date=' + date3.getTime(), function (data) {
            //                $('#FitsSearch').html(data);
            //            });

        }
        else {
            $(list).hide();
        }


    });

}






    function addtolist(text, output) {

       // alert(output);
       $(output).val(text);

   }

   function getStock(code, callback) {

      // alert(jQuery.trim(code));

       var iStock = 0;
       //$.ajaxSetup({ cache: false });
       var d = $.ajax({
           type: "POST",
           contentType: "application/json; charset=utf-8",
           url: "/webservices/StockCheck.asmx/GetStock",
           data: "{ 'code' : '" + jQuery.trim(code) + "' }",
           dataType: "json",
           success: function (data) {

               //               //data = data.d;
              // alert('got stock');
               iStock = data.d;
               callback(iStock)
//               alert(iStock);

           }
       });

      

 //return iStock;

}

function bindQuickSearch() {

    function OrderNow() {

        var code = $('#txtQuickOrder').val();
        var qty = $('#txtQuickOrderQty').val();

        if (code != '') {


            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "/webservices/StockCheck.asmx/GetPart",
                data: "{ 'code' : '" + jQuery.trim(code) + "' }",
                dataType: "json",
                async: true,
                success: function (data) {

                    $("#lbQOError").hide()

                    data = data.d;

                    if (data.PartName != null) {

                        //alert(data.PartName);

                        addToWishList(data.ProdID + '', data.CompPartNo + '', data.PartName + '', data.PageLink + '', qty + '', 'cart');

                    }
                    else {

                        $("#lbQOError").show()
                    
                    }

                }

            });

        }

    }





    $("#txtQuickOrder").focus();

    $("form").keypress(function (event) {

        if (event.which == 13) {
            event.preventDefault();
            OrderNow();

        }
    });



    $('#btQuickOrder').click(function () {

        OrderNow();


    });


}


function getPrice(code) {

    // alert(jQuery.trim(code));

    var dbPrice = 0;
    //$.ajaxSetup({ cache: false });
    var d = $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/webservices/StockCheck.asmx/GetPrice",
        data: "{ 'code' : '" + jQuery.trim(code) + "' }",
        dataType: "json",
        async: false,
        success: function (data) {

            //               //data = data.d;
            // alert('got stock');
            dbPrice = data.d;
            //               alert(iStock);

        }
    });



    return dbPrice;

}

//   function bindStockCheck() {

//       $(".checkStock").mouseover(function () {

//           var code = $('.stockcode').html().trim();
//           var iStock = getStock(code);
//           var txt = "";

//           if (iStock > 0) {

//               txt += '<strong>In Stock</strong> Delivery in 2 - 3 days';

//           }
//           else {
//               txt += '<strong>Out of Stock</strong> Delivery in 5 - 7 days';

//           }

//           txt += ' (' + iStock + ' avialable)';

//           $('.stockCheck').show();
//           $('.stockCheck').html(txt);


//       }).mouseout(function () { $('.stockCheck').hide(); });
//    
//   



//   }

   function bindStockCheck() {

       // alert('bind stock');

       var code = $('.stockcode').html();

       function SetStock(iStock) {

           
           // alert(code);
           //var iStock = getStock(code);
           var txt = "";

           if (iStock > 0) {

               txt += 'Stock: <strong>In Stock</strong> <span>Delivery in 2 - 3 days</span>';

           }
           else {
               txt += 'Stock: <strong>Out of Stock</strong> <span>Call for availability</span>';

           }

           //txt += ' (' + iStock + ' avialable)';

           $('.stockCheck').html(txt);



       }

       getStock(code, SetStock);



   }

   var qBrand = null;
   var qProd = null;
   var qHeightImp = null;
   var qWidthImp = null;
   var qHeightMet = null;
   var qWidthMet = null;
   var qHoles = null;
   var qLengthImp = null;
   var qLengthMet = null;
   var qFunction = null;



   function bindProductFilter() {


       $(".cancelfilter").click(function () {

           if ($(this).attr('id') == 'c_brandfilter') { qBrand = null; }
           if ($(this).attr('id') == 'c_fitsfilter') { qProd = null; }
           if ($(this).attr('id') == 'c_sizeHImpfilter') { qHeightImp = null; }
           if ($(this).attr('id') == 'c_sizeWImpfilter') { qWidthImp = null; }
           if ($(this).attr('id') == 'c_sizeHMetfilter') { qHeightMet = null; }
           if ($(this).attr('id') == 'c_sizeWMetfilter') { qWidthMet = null; }
           if ($(this).attr('id') == 'c_holesfilter') { qHoles = null; }
           if ($(this).attr('id') == 'c_sizeLMetfilter') { qLengthMet = null; }
           if ($(this).attr('id') == 'c_sizeLImpfilter') { qLengthImp = null; }
           if ($(this).attr('id') == 'c_functionfilter') { qFunction = null; }

           sendQ();

       });


       function sendQ() {


           var q = 'cat=' + $('#catid').val();
           
           if (qBrand != null) { q += '&brand=' + qBrand; }
           if (qProd != null) { q += '&prod=' + qProd; }
           if (qWidthImp != null) { q += '&widthI=' + qWidthImp; }
           if (qHeightImp != null) { q += '&heightI=' + qHeightImp; }
           if (qWidthMet != null) { q += '&widthM=' + qWidthMet; }
           if (qHeightMet != null) { q += '&heightM=' + qHeightMet; }
           if (qHoles != null) { q += '&holes=' + qHoles; }

           if (qLengthMet != null) { q += '&lengthM=' + qLengthMet; }
           if (qLengthImp != null) { q += '&lengthI=' + qLengthImp; }
           if (qFunction != null) { q += '&function=' + qFunction; }


           var date = new Date();


          // alert(q);
           $.get('/ajax/AjaxProdFilter.aspx?' + q + '&date=' + date.getTime(), function (data) {

               $('#filter').html(data);

               bindProductFilter();

           });

           $.get('/ajax/AjaxFilteredProducts.aspx?' + q + '&date=' + date.getTime(), function (data) {

               $('#results').html(data);

              // bindProductFilter();

           });

       }

        var sql = ''

        //bind brand
        if ($('.catfilters').length) {

            //on change
            $('.catfilters').change(function () {


                //if there is a value
                if ($(this).val() != 0) {

                    var filterType = $(this).attr('id');

                    if (filterType == 'brandfilter') { qBrand = $(this).val(); }
                    if (filterType == 'fitsfilter') { qProd = $(this).val(); }
                    if (filterType == 'sizeHImpfilter') { qHeightImp = $(this).val(); }
                    if (filterType == 'sizeWImpfilter') { qWidthImp = $(this).val(); }
                    if (filterType == 'sizeHMetfilter') { qHeightMet = $(this).val(); }
                    if (filterType == 'sizeWMetfilter') { qWidthMet = $(this).val(); }
                    if (filterType == 'holesfilter') { qHoles = $(this).val(); }
                    if (filterType == 'sizeLMetfilter') { qLengthMet = $(this).val(); }
                    if (filterType == 'sizeLImpfilter') { qLengthImp = $(this).val(); }
                    if (filterType == 'functionfilter') { qFunction = $(this).val(); }



                    sendQ();

                }
                else {

                    if (filterType == 'brandfilter') { qBrand = null; }
                    if (filterType == 'fitsfilter') { qProd = null; }
                    if (filterType == 'sizeHImpfilter') { qHeightImp = null; }
                    if (filterType == 'sizeWImpfilter') { qWidthImp = null; }
                    if (filterType == 'sizeHMetfilter') { qHeightMet = null; }
                    if (filterType == 'sizeWMetfilter') { qWidthMet = null; }
                    if (filterType == 'holesfilter') { qHoles = null; }
                    if (filterType == 'sizeLMetfilter') { qLengthMet = null; }
                    if (filterType == 'sizeLImpfilter') { qLengthImp = null; }
                    if (filterType == 'functionfilter') { qFunction = null; }


                    sendQ();

                }

            });

        }




    }

    function printThis(id) {





    }

    function bindOptions() {


        $('.options').change(function () {

            var sVal = $('.options').val();
            var arrVal = sVal.split('^');

            //var value = arrVal[3];
            title = arrVal[2];
            code = arrVal[3];


            $('#h1Title').html(title);
            $('#stockCode').html(code);
            var pr = getPrice(code)
            $('.price').html("&pound;" + parseFloat(pr).toFixed(2) + ' <span>inc VAT</span>');
            bindStockCheck();

        });

    }

    function pvGetPrice(partObj, callback) {

        // look up part in company business system using jquery
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "/webservices/StockCheck.asmx/GetOemPart",
            //pass in stripped part no and prefix
            data: "{ 'code' : '" + jQuery.trim(partObj.PartNoStripped) + "', 'prefix' : '" + jQuery.trim(partObj.BrandPrefix) + "' }",
            dataType: "json",
            async: true,
            success: function (data) {

                // returned object from asp.net web service
                data = data.d;

                //chage part name if found to buisness system value
                if (data != null && data.PartName != null) {
                    partObj.PartName = data.PartName;
                }

                //chage part price if found to buisness system value
                if (data != null && data.PartPrice != null && data.PartPrice != 0) {
                    partObj.PartPrice = data.PartPrice;
                }

                //pass the object back
                //IMPORTANT. THIS is required. return an empty object if not found
                callback(partObj);

            }

        });


    }

    function pvAddToCart(partObj) {


        // look up part in company business system using jquery
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "/webservices/StockCheck.asmx/DiagramAddPart",

            //pass in object details to web service. Set up product if needed
            data: "{ 'PartNo' : '" + jQuery.trim(partObj.PartNo) + "', 'BrandPrefix' : '" + jQuery.trim(partObj.BrandPrefix) + "', 'PartName' : '" + jQuery.trim(partObj.PartName) + "', 'PartPrice' : '" + jQuery.trim(partObj.PartPrice.toString()) + "', 'PartPriceSSP' : '" + jQuery.trim(partObj.PartPriceSSP.toString()) + "' }",
            dataType: "json",
            async: true,
            success: function (data) {


                // returned object from asp.net web service
                data = data.d;

                //check the retuned obect has a skew code
                if (data != null && data.CompPartNo != null) {

                    //call your add to cart function
                    addToWishList(data.ProdID + '', data.CompPartNo + '', data.PartName + '', data.PageLink + '', partObj.Qty + '', 'cart');
                    
                }
                else {

                    alert('failed to add to cart');
                }

            }

        });


    }

//    function BindAriCart() {

//        var partObj =;
//        partObj.PartNo = ;
//        partObj.PartName = ;
//        partObj.Qty = 1;
//        partObj.PartPrice = ;
//        partObj.PartPriceSSP = ;
//        partObj.BrandPrefix = ;

//        $('#ariadd').click(function(){pvAddToCart(partObj);});

//    }


    function SetDelAdd(id) {

        $('#' + id + ' .ChooseAdd').click(function () {


            $('#' + id + ' .ChooseAdd').css('background-color', '#ffffff');
            $(this).css('background-color', '#def5fd');
            $(this).find('input:radio').attr('checked', true);
            // $('#' + id + ' .ChooseAdd').find('input:radio').attr('checked', false);


        });



    }




