Subversion Repositories SmartDukaan

Rev

Rev 10014 | Blame | Compare with Previous | Last modification | View Log | RSS feed

$(function(){
        $("#userSelector .default").truncate({addtitle: true});
        
        function submitSeachForm()      {
                var query = $.trim($('#query').val());
                
                if(query != '' && query != 'Search for more items...')  {
                        $('#formSearch').submit();      
                } else  {
                        $('#query').focus();
                }
        }
        
        /** Search in Header **/
        $('#query').val('Search for more items...')
                .focus(function(){
                        $(this).val('');
                })
                .blur(function(){
                        if ($(this).val() == '')        $(this).val('Search for more items...');
                });
        
        $('#searchButton').click(function(){
                submitSeachForm();
        });
        
        $('input.mk_filter').change(function(){
                var search = window.location.search;
                if(window.location.search=="") {
                        search = "?";
                }
                var currenturl = window.location.pathname + search;
                if(this.checked) {
                        currenturl = (currenturl) + this.value;
                } else {
                        currenturl = (currenturl).replace(this.value, "");
                }
                window.location = currenturl.replace(/&page=./,"");
        });
        $('a.mk_filter').click(function(){
                //first remove all fqs except category and sub category when 
                //any of the category links are clicked
                var search = window.location.search;
                if(window.location.search=="") {
                        search = "?";
                }
                var currenturl = window.location.pathname + search;
                classNames = $(this).attr("class");
                if(classNames.indexOf("mk_bold") >= 0) {
                        //if this is selected category filter, remove subcategory filter from url
                        currenturl = currenturl.replace($(this).closest('ul').find('.mk_bold.mk_subcategory').attr("value"), "");
                }else {
                        //check if sub-category is changed, if yes then remove the previous sub-category and add this sub-category
                        if(classNames.indexOf("mk_subcategory") >= 0) {
                                currenturl = currenturl.replace($(this).closest('ul').find('.mk_bold.mk_subcategory').attr("value"), "") + $(this).attr("value");
                        }else {
                                currenturl = (currenturl).replace($(this).closest('ul').find('.mk_bold.mk_category').attr("value"), "").replace($(this).closest('ul').find('.mk_bold.mk_subcategory').attr("value"),"") + $(this).attr("value");
                        } 
                }
                window.location = currenturl.replace(/&page=./,"");
        });
        
        //also now remove unwanted filters
        $('a.mk_filter_close').click(function(){
                var rootFacets = ["F_50010","F_50011","F_50002", "F_50001", "F_50028"];
                var search = window.location.search;
                if(window.location.search=="") {
                        search = "?";
                }
                var newurl = window.location.pathname + search;
                var filterValue = $(this).attr("value");
                if(filterValue.indexOf("F_50010")>-1){
                        $(this).closest('div').find('.mk_filter_close').each(function(index,value){
                                newurl = newurl.replace($(value).attr("value"), "");
                        });
                } else if(filterValue.indexOf("F_50011")>-1){
                        $(this).closest('#currentFilters').find('.mk_filter_close').each(function(index,value){
                                var regexS = "fq=(.*)%3A";
                                var regex = new RegExp(regexS);
                                var results = regex.exec($(value).attr("value"));
                                if(rootFacets.indexOf(results[1]) == -1){
                                        newurl = newurl.replace($(value).attr("value"), "");
                                }
                        });
                        newurl = newurl.replace($(this).attr("value"), "");
                } else {
                        newurl = newurl.replace($(this).attr("value"), "");
                }
                window.location = newurl.replace(/&page=./,"");
        });
        
        $('body').mouseup(function(){
                var userSelector = $('#userSelector');
                var isMouseOnUserSelector = $(userSelector).data('is_mouse_on_user_selector');
                
                if (typeof(isMouseOnUserSelector) == 'boolean'  && !isMouseOnUserSelector)      {
                        $(userSelector).children('ul').hide();
                        $(userSelector).data('usermenustate', false);
                        $(userSelector).removeClass('active');
                }
        });
        
        $('#userSelector').click(function(){
                        
                var userMenuState = $(this).data('usermenustate');
                
                if (typeof(userMenuState) == 'undefined' || !userMenuState)     {
                        $(this).addClass('active');
                        $(this).children('ul').show();
                        $(this).data('usermenustate', true);
                } else  {
                        $(this).removeClass('active');
                        $(this).children('ul').hide();
                        $(this).data('usermenustate', false);
                }
        }).hover(function(){
                $(this).data('is_mouse_on_user_selector', true);
        }, function(){
                $(this).data('is_mouse_on_user_selector', false);
        });

        /** Press Coverage Section **/
        $('#asSeenOnBS').click(function(){
                window.open('http://www.business-standard.com/article/companies/saholic-com-offering-theft-insurance-for-mobile-handsets-113031100002_1.html', '_blank');
                trackEventWithGA('Press Coverage', 'Logo Click', 'Business Standard');
        });
        
        $('#asSeenOnBT').click(function(){
                window.open('http://businesstoday.intoday.in/story/saholic.com-to-compensate-customers-for-late-deliveries/1/191649.html', '_blank');
                trackEventWithGA('Press Coverage', 'Logo Click', 'Business Today');
        });

        $('#asSeenOnTOI').click(function(){
                window.open("http://articles.timesofindia.indiatimes.com/2012-01-25/telecom/30662542_1_nokia-s-windows-phone-nokia-lumia-smartphone", '_blank');
                trackEventWithGA('Press Coverage', 'Logo Click', 'The Times of India');
        });

        $('#asSeenOnWSJ').click(function(){
                window.open('http://online.wsj.com/article/SB10001424052702304447804576412930555639142.html', '_blank');
                trackEventWithGA('Press Coverage', 'Logo Click', 'The Wall Street Journal');
        });
        
        $('#asSeenOnMC').click(function(){
                window.open("http://www.moneycontrol.com/news/technology/nokia-lumia-710-available-for-approximately-rs15700_655601.html", '_blank');
                trackEventWithGA('Press Coverage', 'Logo Click', 'Money Control');
        });
        
        jQuery("#promotion-banners").find("a, area").click(
                    function(){
                        if($(this).attr("href") != "#") {
                            bannername = $(this).attr("banner-name");
                            url = $(this).attr("href");
                                        trackEventWithGA('Side Banner Region Clicked', bannername, 'Location '+document.URL+' Target Url '+url);
                        }
                    }
                );
        
        jQuery("#banner-menu").find("a, area").click(
                    function(){
                        if($(this).attr("href") != "#") {
                            bannername = $(this).attr("banner-name");
                            url = $(this).attr("href");
                                        trackEventWithGA('Banner Region Clicked', bannername, 'Location '+document.URL+' Target Url '+url);
                        }
                    }
                );      
});