﻿ /* productcategory scripts start */
 function CompareProduct(hiddenChannelid,e)
 {
    var comparecount = $("input.compare:checked").length;
         if (!($(e).next("input").is(":checked")))//can click compare button only if the 
         //  corresponding check box is selected
         {

             alert("You need to select the product for comparison.");
             return false;

         }
         if (comparecount == 0) {
             alert("You have to select minimum one item to view comparison.");
             return false;
         }
         if (comparecount > 3) {
             alert("You can compare maximum three products only.");
             $(e).find(">input.compare").attr("checked", "");
             return false;
         }
         $("input#hdnmodels").val("");
         var comparemodels = "";

         $("input.compare:checked:not(:last)").each(function() {
             comparemodels += $(this).attr("value") + ","

         })
         comparemodels += $("input.compare:checked:last").attr("value");
         var hiddenChannelName = $("input#" + hiddenChannelid).val();

         $("input#hdnmodels").val(comparemodels); //store seelcted model numbers in hidden control
         if (hiddenChannelName != '') {
             $("input#hdnProdGroup").val(hiddenChannelName);

         }
         else {

             $("input#hdnProdGroup").val("Thermostats"); //default value

         }
         $("form").attr("action", "/Home/applications/ProductComparison.aspx");
         $("form").submit();
 
 }
 //function to initially hide FAQ content
 function hideFAQ()
 {
 
       $('div.collapse').hide().end()
            .find('h4.expand').css('cursor', 'pointer')
            .wrapInner('<a style="display:block" href="#expand/collapse" title="expand/collapse"></a>');
 
 
 }
 //function to attach expand c ollapse event to each '+' element
 function InitExpandCollapse()
 {
    $('h4.expand').click(function() {
         $(this).toggleClass('open')
                         .next('.collapse').slideToggle();
     });
 
 
 }
   
   //Filter Do-It-yourself Or Professionally Install SelectionChange
function filterDiyOrProInstallSelectionChange(obj,diyFilter,professionallyInstallFilter) 
{
  if(obj.options[obj.selectedIndex].value ==diyFilter)
  {
    $(".DIY").show();
    $(".ProfessionallyInstall").hide();
  }
  else if(obj.options[obj.selectedIndex].value == professionallyInstallFilter)
  {
    $(".ProfessionallyInstall").show();
    $(".DIY").hide();
  }
  else
  {
    $(".DIY").show();
    $(".ProfessionallyInstall").show();
  }
}
 
 /* productcategory scripts end */
 
/* product details script  start*/
  function productDetailCompareModel()
  {
     var model=$("input.hiddenModel").val();
    $("input#hdnmodels").val(model);

     var productGroup=$("input.hiddenChannel").val();
    $("input#hdnProdGroup").val(productGroup);
 
 
     $("form").attr("action","/Home/applications/ProductComparison.aspx");
      $("form").submit();
  
  
  }



/*   Product details script  end */     



/* smart search scripts start */

//Function to initialize smart search UI

function smartSearchInit()
 {
      //Checks for result set and hides "allsearchresults" tab headings accordingly.
var productsLength=$(".productswrapper div.demo > table tr:first td ").children().length //=0 means no products results
var problemWesolveLength=$('.pwswrapper').find('#content').length;//==0 means no problem we solve results

var manualsGridlength=$('.AllTabGridView tr').length;
var FAQscount=$("div.FAQWrapper div.demo div.content").length;
if(productsLength==0){
$('div#allresult  div.productswrapper').hide();//hide static headings in products section


}

if(problemWesolveLength==0){
 $('div#allresult  div.pwswrapper').hide();//hide static headings of  PWS section


}
if(manualsGridlength==0){
$('div#allresult div.manualswrapper').hide();//hide static headings of  Manauls section


}
if(FAQscount==0)
{

   $('div#allresult div.FAQWrapper').hide();

}

// doPaging('GridView'); //do paging for Manuals tab
// doPaging('AllTabGridView');//do paging fnctioanlity for manuals grid inside all result tab;


//more/less functionality in all results tab product details  
jQuery("div.all div.moreless >a").unbind('click');

jQuery("div.all div.moreless >a").click(function() {

    var self = this;
    
    //
    var tabs = jQuery(self).parent().prev();

    if (jQuery(tabs).css("display") == "block") {
            
        jQuery(tabs).css("display", "none");
        jQuery(self).html("more");
        jQuery(self).css("background-image", "url(/home/images/arrow_more.gif)");
        /*jQuery(self).parent().parent().css("background-color", "#f9f9f9");*/
        jQuery(tabs).children().not("ul").css("display", "none");
        //Changed below line to fix the issue with ajax tab panel-Jayesh
        jQuery(tabs).children().eq(0).children().eq(0).children().css("background-image", "url(/home/images/tab_bg.gif)");
    } else {
                  
        jQuery(tabs).children().eq(0).css("display", "block");
        //Changed below line to fix the issue with ajax tab panel-Jayesh
        jQuery(tabs).children().eq(0).children().eq(0).children().css("background-image", "url(/home/images/tab_open_bg.gif)");
        jQuery(tabs).css("display", "block");
        jQuery(self).html("less");
        jQuery(self).css("background-image", "url(/home/images/arrow_less.gif)");
        jQuery(self).parent().parent().css("background-color", "#ffffff");
    }
    return false;
});

}
//function for UI functionality for smart search 

function setupUI(manualsCount,pWScount,productsCount)
{

$('div.all').append(''          
         +'<div class="manualswrapper" id="manualswrapper"><p class="expand" ><img src="/Home/Images/close_btn.gif" class="closebutton" title="Close"/><a href="#expand/collapse" title="expand/collapse" class="expcol" style="display:block"></a><span class="searchhead">Manuals</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[&nbsp;'+manualsCount+']</p>'
         +'<div class="demo">' +$('div.manualswrapper').html()+'</div></div>'
         +'<div class="pwswrapper" ><p class="expand" ><img src="/Home/Images/close_btn.gif" class="closebutton" title="Close"/><a  href="#expand/collapse" title="expand/collapse" class="expcol" style="display:block"></a><span class="searchhead">Problems We Solve</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[&nbsp;'+pWScount+']</p>'
         +'<div class="demo">' +$('div.pwswrapper').html()+'</div></div>'
         +'<div class="FAQWrapper"><p class="expand"><img src="/Home/Images/close_btn.gif" class="closebutton" title="Close"/><a  href="#expand/collapse" title="expand/collapse" class="expcol" style="display:block"></a><span class="searchhead">FAQ</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[&nbsp;'+productsCount+'&nbsp;result(s) found&nbsp;]</p>'
         +'<div class="demo">' +$('div.FAQWrapper').html()+'</div></div>'
         +'<img src="/Home/Images/reset_btn.gif" style="float:right;margin-top:5px;cursor:pointer" class="reset"/>'
         );


$('#outer').find('div.collapse').hide().end()
$('#outer').find('h4.expand').css('cursor','pointer').wrapInner('<a style="display:block" href="#expand/collapse" title="expand/collapse"></a>');

 $('#outer  h4.expand').click(function() {
    $(this).toggleClass('open')
    .next('.collapse').slideToggle();
   
});


 //** This required to avoid clash between  manuals datagrid appears in manulas tab and allresult tab
//** assign different class name
$('div#allresult .manualswrapper .GridWrapper table').removeClass("GridView");
$('div#allresult .manualswrapper .GridWrapper table').addClass("AllTabGridView");

var isPaged=false;
$('#outer div.all p.expand a').click(function() {

    if($(this).parent().parent().attr("id")=="manualswrapper")//call paging only when expanded
    {
        if( $(this).parent().next('.demo').is(':hidden') && !isPaged) //if grid is hidden
         {
         
             doPaging('AllTabGridView');
             isPaged=true;
         }
    
    }

   $(this).parent().toggleClass('open').next('.demo').slideToggle();//for click expand/collapse functionalty
       
});

$('#outer div.all div.demo').hide().end();// uncomment this for initially showing alresult sections



//Close individual search reuslts in All results tab
$('p.expand img').click(function(){

 if( $("div.all").find(">div:visible").length==1)//need to have at least one section visible in all result
 {
   return false;
 
 }
 else{
        $(this).parent().parent().slideToggle();
   }
        

})     

    


//reset all functionality in allsearchresults tab
 $('div.all img.reset').click(function(){

     // $("div#outer div.all").find('div.demo:has(*)').parent().show()//Show only items has data
     if($("div[id*=ProductsPanel]>p>span.labelnoresult").text().length==0) //The P containing a span tag wil appear only for showing "no results message"
     {
       $("div#outer div.all div.productswrapper").show();
     }
     if($("div[id*=ManualsPanel]>p>span.labelnoresult").text().length==0)
     {
       $("div#outer div.all div.manualswrapper").show();
     
     }
     if($("div[id*=PWSPanel]>p>span.labelnoresult").text().length==0)
     {
       $("div#outer div.all div.pwswrapper").show();
     
     }
     
     if($("div.FAQWrapper div.demo div.content").length!=0)
     {
       $("div#outer div.all div.FAQWrapper").show();
     
     }
                  

})       
  
 
 }
 
   var isTabPaged=false;
    function ActiveTabChanged(sender,e)
    {

      var activeTabHeader=sender.get_activeTab().get_headerText();
      
      if(activeTabHeader.indexOf("Manuals")!=-1 && !isTabPaged)
        {
             doPaging('GridView'); //do paging for Manuals tab
             isTabPaged=true;
            
        }
     

    }

//function for pagination functionality fir gridviews   
var currentsection = 0;
var sectioncount;
function doPaging(grid) 
{

    var rowcount = $("table#manualswrapper ." + grid + " tbody tr").length;
      
    var pagelength = 5
    var pagecount;
    if ((rowcount - 1) % pagelength == 0)
        pagecount = (rowcount - 1) / pagelength;
    else {
        pagecount = parseInt(Math.floor((rowcount - 1) / pagelength));
        pagecount = parseInt(pagecount) + 1;

    }

    if (pagecount > 1 && rowcount > (pagelength + 1)) //pagelength+1 is because of header row excluded
    {
        var displaycount = 6;

        if ((pagecount) % displaycount == 0)
            sectioncount = (pagecount) / displaycount;
        else {
            sectioncount = parseInt(Math.floor((pagecount) / displaycount));
            sectioncount = parseInt(sectioncount) + 1;

        }

        $("table#manualswrapper ." + grid + " > tbody").append("<tr class='Paging' style='background-color:#f1f1f1' id='Paging'></tr>");


        var strHtml;

        $("table#manualswrapper ." + grid + " > tbody tr.Paging").append("<td class='section' align='right' colspan=4></td>");


        for (j = 1; j <= sectioncount; j++) {

            strHtml = "<span class='section'>"
            + "<ul style='padding:1px'><li><a href='javascript:void(0)' class='first'>First</a></li><li><a class='prev' style='text-decoration:none;color:-webkit-link' href='javascript:void(0)'>...</a></li>";
            for (var i = ((j - 1) * displaycount + 1); i <= (j * displaycount); i++) {
                strHtml = strHtml + "<li><a href='javascript:void(0)' class='pager'>" + i + "</a></li>";

                if (i == pagecount)
                    break;

            }
            strHtml = strHtml + "<li><a href=\"javascript:void(0)\" class='next' style='text-decoration:none'>... </a></li><li><a href='javascript:void(0)' class='last'>Last</a></li></ul></span>";
            $("table#manualswrapper ." + grid + " > tbody tr.Paging td.section").append(strHtml);


            strHtml = "";


        }

        $("table#manualswrapper ." + grid + " > tbody tr.Paging td ul li").css("display", "block");
        $("table#manualswrapper ." + grid + " > tbody tr.Paging td ul li a").css("padding", "1px");
        $("table#manualswrapper ." + grid + " > tbody tr.Paging td ul li a").css("color", "#2E5E9E");
        $("table#manualswrapper ." + grid + " > tbody tr.Paging td ul li a").css("border", "0px");
        $("table#manualswrapper ." + grid + " > tbody tr.Paging td ul li a").css("background-color", "#f1f1f1");
        $("table#manualswrapper ." + grid + " > tbody tr.Paging td span ul li").css("list-style", "none");
        $("table#manualswrapper ." + grid + " > tbody tr.Paging td span ul li").css("display","inline");




        $("table#manualswrapper ." + grid + " > tbody tr").slice(1, rowcount).hide();
        $("table#manualswrapper ." + grid + " > tbody tr").slice(1, pagelength + 1).show();

        //The click functionality on paging anchor tags
        $("table#manualswrapper ." + grid + " > tbody tr.Paging td ul li a.pager").click(function() {
            var pagelength = 5
            var pageno = $(this).text();
            var rowcount = $("table#manualswrapper ." + grid + " tbody tr").length;
            $("table#manualswrapper ." + grid + " > tbody tr.Paging td ul li a").removeClass("current"); //this class highlights curent page number
            $(this).addClass("current"); //on click highlight only clicked link
            $("table#manualswrapper ." + grid + " > tbody tr").slice(1, rowcount - 1).hide(); //take a renge of rows to except header row and hide
            var startpage = ((parseInt(pageno) - 1) * pagelength) + 1;
            var endpage = (pageno * pagelength) + 1;
            $("table#manualswrapper ." + grid + " > tbody tr").slice(startpage, endpage).show(); //show only rows falls in the page range

            $("table#manualswrapper ." + grid + " > tbody tr.Paging td.section span.section ul li a.pager").css("cursor", "pointer");
            $("table#manualswrapper ." + grid + " > tbody tr.Paging td.section span.section ul li a.pager").css("color", "#2E5E9E");
            $("table#manualswrapper ." + grid + " > tbody tr.Paging td.section span.section ul li a.pager").css("font-weight", "normal");


            $(this).css("cursor", "default");
            $(this).css("color", "#2E5E9E");
            $(this).css("font-weight", "bold");
        })

            
        $("table." + grid+ " > tbody tr.Paging td.section span.section").hide();

        $("table." + grid+ " > tbody tr.Paging td.section span.section a.prev").hide();
        $("table." + grid+ " > tbody tr.Paging td.section span.section a.next").hide();

        $("table." + grid+ " > tbody tr.Paging td.section span.section a.first").hide();
        $("table." + grid+ " > tbody tr.Paging td.section span.section a.last").hide();

        $("table." + grid+ " > tbody tr.Paging td.section span.section:eq(0)").show(); //first page section

        if (sectioncount > 1) {
            $("table." + grid+ " > tbody tr.Paging td.section span.section:eq(0) a.next").show();
            $("table." + grid+ " > tbody tr.Paging td.section span.section a.last").show();
        }

        $("table#manualswrapper ." + grid + " > tbody tr.Paging td.section span.section a.next").click(function() {

            currentsection += 1;

            if (currentsection == (sectioncount - 1)) {
                $("table." + grid+ " > tbody tr.Paging td.section span.section:eq(" + currentsection + ") a.next").hide();
                $("table." + grid+ " > tbody tr.Paging td.section span.section:eq(" + currentsection + ") a.last").hide();
            }
            else {
                $("table." + grid+ " > tbody tr.Paging td.section span.section:eq(" + currentsection + ") a.next").show();
            }

            if (currentsection == sectioncount) {
                currentsection -= 1; ;
                return;
            }

            $("table." + grid+ " > tbody tr.Paging td.section span.section a.prev").hide();
            $("table." + grid+ " > tbody tr.Paging td.section span.section a.prev").show();

            $("table." + grid+ " > tbody tr.Paging td.section span.section").hide();
            $("table." + grid+ " > tbody tr.Paging td.section span.section:eq(" + currentsection + ") a.first").show();

            $("table." + grid+ " > tbody tr.Paging td.section span.section:eq(" + currentsection + ")").show()
            if ($("table." + grid+ " > tbody tr.Paging td.section span.section:eq(" + currentsection + ") ul li").length < (displaycount / 2)) {

                $("table." + grid+ " > tbody tr.Paging td.section span.section:eq(" + (currentsection - 1) + ")").show();
                $("table." + grid+ " > tbody tr.Paging td.section span.section:eq(" + (currentsection - 1) + ") a.first").hide();
                $("table." + grid+ " > tbody tr.Paging td.section span.section:eq(" + (currentsection - 1) + ") a.last").hide();
                $("table." + grid+ " > tbody tr.Paging td.section span.section:eq(" + (currentsection - 1) + ") a.prev").hide();
                $("table." + grid+ " > tbody tr.Paging td.section span.section:eq(" + (currentsection - 1) + ") a.next").hide();

                var prevsectionpart = Math.ceil(displaycount / 2);

                $("table." + grid+ " > tbody tr.Paging td.section span.section:eq(" + currentsection - 1 + ") ul li:lt(" + prevsectionpart + ")").hide();

            }

            $("table#manualswrapper ." + grid + " > tbody tr.Paging td.section span.section ul li a.pager").css("cursor", "pointer");
            $("table#manualswrapper ." + grid + " > tbody tr.Paging td.section span.section ul li a.pager").css("color", "#2E5E9E");
            $("table#manualswrapper ." + grid + " > tbody tr.Paging td.section span.section ul li a.pager").css("font-weight", "normal");

            var currentpager = $("table." + grid+ " > tbody tr.Paging td.section span.section:eq(" + currentsection + ") ul li:eq(2) a");
            $(currentpager).css("cursor", "default");
            $(currentpager).css("font-weight", "bold");

            var pageno = $("table." + grid+ " > tbody tr.Paging td.section span.section:eq(" + currentsection + ") ul li:eq(2) a").text();


            var rowcount = $("table#manualswrapper ." + grid + " tbody tr").length;

            $("table#manualswrapper ." + grid + " > tbody tr").slice(1, rowcount - 1).hide(); //take a renge of rows to except header row and hide
            var startpage = ((parseInt(pageno) - 1) * pagelength) + 1;
            var endpage = (pageno * pagelength) + 1;
            $("table#manualswrapper ." + grid + " > tbody tr").slice(startpage, endpage).show();

        })



        $("table#manualswrapper ." + grid + " > tbody tr.Paging td.section span.section a.prev").click(function() {


            if (currentsection == 0) {
                return;
            }

            if (currentsection == 1) {
                $("table." + grid+ " > tbody tr.Paging td.section span.section a.prev").hide();
            }

            currentsection -= 1;

            if (currentsection != 0) {
                $("table." + grid+ " > tbody tr.Paging td.section span.section:eq(" + currentsection + ") a.first").show();
                $("table." + grid+ " > tbody tr.Paging td.section span.section:eq(" + currentsection + ") a.prev").show();
            }


            $("table." + grid+ " > tbody tr.Paging td.section span.section").hide();
            $("table." + grid+ " > tbody tr.Paging td.section span.section:eq(" + currentsection + ")").show()
            $("table." + grid+ " > tbody tr.Paging td.section span.section a.next").show();
            $("table." + grid+ " > tbody tr.Paging td.section span.section:eq(" + currentsection + ") a.last").show();


            //set current page color and cursor
            $("table#manualswrapper ." + grid + " > tbody tr.Paging td.section span.section ul li a.pager").css("cursor", "pointer");
            $("table#manualswrapper ." + grid + " > tbody tr.Paging td.section span.section ul li a.pager").css("color", "#2E5E9E");
            $("table#manualswrapper ." + grid + " > tbody tr.Paging td.section span.section ul li a.pager").css("font-weight", "normal");

            var currentpager = $("table." + grid+ " > tbody tr.Paging td.section span.section:eq(" + currentsection + ") ul li:eq(2) a");
            $(currentpager).css("cursor", "default");
            $(currentpager).css("font-weight", "bold");

            var pageno = $("table." + grid+ " > tbody tr.Paging td.section span.section:eq(" + currentsection + ") ul li:eq(2) a").text();

            var rowcount = $("table#manualswrapper ." + grid + " tbody tr").length;

            $("table#manualswrapper ." + grid + " > tbody tr").slice(1, rowcount - 1).hide(); //take a renge of rows to except header row and hide
            var startpage = ((parseInt(pageno) - 1) * pagelength) + 1;
            var endpage = (pageno * pagelength) + 1;
            $("table#manualswrapper ." + grid + " > tbody tr").slice(startpage, endpage).show();
        })


        $("table#manualswrapper ." + grid + " > tbody tr.Paging td.section span.section a.first").click(function() {


            currentsection = 0 //reset global variable
            var endpage = pagelength + 1;
            var rowcount = $("table#manualswrapper ." + grid + " tbody tr").length;

            $("table." + grid+ " > tbody tr.Paging td.section span.section").hide();

            $("table." + grid+ " > tbody tr.Paging td.section span.section:first").show();
            $("table." + grid+ " > tbody tr.Paging td.section span.section:first a.first").hide();
            $("table." + grid+ " > tbody tr.Paging td.section span.section:first a.prev").hide();

            $("table#manualswrapper ." + grid + " > tbody tr").slice(1, rowcount - 1).hide();
            $("table#manualswrapper ." + grid + " > tbody tr").slice(1, endpage).show();


            //set current page color and cursor
            $("table#manualswrapper ." + grid + " > tbody tr.Paging td.section span.section ul li a.pager").css("cursor", "pointer");
            $("table#manualswrapper ." + grid + " > tbody tr.Paging td.section span.section ul li a.pager").css("color", "#2E5E9E");
            $("table#manualswrapper ." + grid + " > tbody tr.Paging td.section span.section ul li a.pager").css("font-weight", "normal");


            var currentpager = $("table." + grid+ " > tbody tr.Paging td.section span.section:eq(0) ul li:eq(2) a");
            $(currentpager).css("cursor", "default");
            $(currentpager).css("font-weight", "bold");
        })



        $("table#manualswrapper ." + grid + " > tbody tr.Paging td.section span.section a.last").click(function() {

            currentsection = sectioncount - 1;

            $("table." + grid+ " > tbody tr.Paging td.section span.section").hide();
            $("table." + grid+ " > tbody tr.Paging td.section span.section:last").show();
            $("table." + grid+ " > tbody tr.Paging td.section span.section:last a.last").hide();
            $("table." + grid+ " > tbody tr.Paging td.section span.section:last a.next").hide();
            $("table." + grid+ " > tbody tr.Paging td.section span.section:last a.prev").show();
            $("table." + grid+ " > tbody tr.Paging td.section span.section:last a.first").show();

            var pageno = $("table." + grid+ " > tbody tr.Paging td.section span.section:last ul li:last").prev().prev().find("a").text();
            var startpage = ((parseInt(pageno) - 1) * pagelength) + 1;


            var endpage = (pageno * pagelength) + 1;
            var rowcount = $("table#manualswrapper ." + grid + " tbody tr").length;
            $("table#manualswrapper ." + grid + " > tbody tr").slice(1, rowcount - 1).hide();

            $("table#manualswrapper ." + grid + " > tbody tr").slice(startpage, endpage).show();


            //set current page color and cursor
            $("table#manualswrapper ." + grid + " > tbody tr.Paging td.section span.section ul li a.pager").css("cursor", "pointer");
            $("table#manualswrapper ." + grid + " > tbody tr.Paging td.section span.section ul li a.pager").css("color", "#2E5E9E");
            $("table#manualswrapper ." + grid + " > tbody tr.Paging td.section span.section ul li a.pager").css("font-weight", "normal");


            var currentpager = $("table." + grid+ " > tbody tr.Paging td.section span.section:last ul li:last").prev().prev().find("a")
            $(currentpager).css("cursor", "default");
            $(currentpager).css("font-weight", "bold");
        })
    }
}


/* smarty search scripts end */ 
