﻿function GetChapterMenu(Chapter)
{   
  WorkmanshipMaterialsGuideSearch.GetChapterMenu(Chapter, DisplayResults, ErrorRetrieving);  
  $get("ctl00_ContentPlaceHolder1_labChapterNav").innerHTML = " > <a href=\"WorkmanshipMaterialsGuideTemplate.aspx?Chapter=" + Chapter +"\"  class=\"navTrail\" >Chapter - " + Chapter + "</a>";  
  $get("ctl00_ContentPlaceHolder1_labSectionNav").innerHTML = "";    
}

function GetChapter(Chapter)
{ 
    var chap;
    var sect;
    index = Chapter.indexOf(".", 0);
    chap = Chapter.substring(0, index);
    sect = Chapter.substring(index + 1); 
    if(chap == 7 || chap == 9 || chap == 11)
    {
        if(chap == 7)
        {
            if(sect <= 22)
            {
                chap = "7a";
            }
            else
            {
                chap = "7b";
            }
        }
        if(chap == 9)
        {
            if(sect <= 12)
            {
                chap = "9a";
            }
            else if(sect > 12 && sect <= 25)
            {
                chap = "9b";
            }
            else
            {
                chap = "9c";
            }
        }
        if(chap == 11)
        {
            if(sect <= 2)
            {
                chap = "11a";
            }
            else if(sect > 2 && sect <= 14)
            {
                chap = "11b";
            }
            else
            {
                chap = "11c";
            }
        }
    }
    WorkmanshipMaterialsGuideSearch.GetChapter(Chapter, DisplayResults, ErrorRetrieving); 
    $get("ctl00_ContentPlaceHolder1_labSectionNav").innerHTML = " > <a href=\"WorkmanshipMaterialsGuideTemplate.aspx?Chapter=" + chap +"\"  class=\"navTrail\" >Chapter - " + chap + "</a> > <a href=\"WorkmanshipMaterialsGuideTemplate.aspx?Chapter=" + chap +"&Section=" + sect + "\" class=\"navTrail\" >Section - " + sect + "</a>";
}

function GetIntroduction()
{
    WorkmanshipMaterialsGuideSearch.GetChapter("Intro", DisplayResults, ErrorRetrieving); 
    $get("ctl00_ContentPlaceHolder1_labSectionNav").innerHTML = " > <a href=\"WorkmanshipMaterialsGuideTemplate.aspx?Chapter=Intro\"  class=\"navTrail\" >Introduction</a>";
}

function GetStartIntroduction()
{
    $get("ctl00_ContentPlaceHolder1_labSectionNav").innerHTML = " > <a href=\"WorkmanshipMaterialsGuideTemplate.aspx\"  class=\"navTrail\" >Introduction</a>";
    var intro;

    intro = "<div style=\"padding-right:10px\"><strong>Workmanship & Material Reference Guide:<br />A review of over 200 performance guidelines.</strong>";
    intro = intro + "<br /><br /> Considering all the details that go into building a new home, it is not surprising that occasionally disparities exist between the expectations of a homebuyer and what the builder delivers. ";
    intro = intro + "<br /><br /> This reference guide addresses over 200 performance guidelines for Workmanship and Material components and systems that make up a finished home. It serves as a benchmark for The Alberta New Home Warranty Program when reviewing a conciliation file, and it is our basis for the 'repair' or 'replace' decision.";
    intro = intro + "<br /><br /> We proudly make this useful tool available to both our Builder Members and homebuyers.";
    intro = intro + "<br /><br /> If you would like to obtain a hard copy version of this guide they are available from our offices in Calgary and Edmonton.";
    intro = intro + "<br /><br /> The books are $41.95 (cash or cheque) and may be picked up at: ";
    intro = intro + "<br /><br /> <strong>Calgary Office</strong> <br /> 233-Mayland Place NE <br /> Calgary, Alberta T2E 7Z8 Ph: (403) 253-3636 <br /> Office hours: 8:00 a.m. - 5:00 p.m."; 
    intro = intro + "<br /><br /> <strong>Edmonton Office</strong> <br /> #204, 10464 Mayfield Road NW <br /> Edmonton, Alberta T5P 4P4 <br /> Ph: (780) 484-0572 <br /> Office hours: 8:00 a.m. - 5:00 p.m.</div>";

    $get("ctl00_ContentPlaceHolder1_labContent").innerHTML = intro;
}

function GetGlossary()
{
    WorkmanshipMaterialsGuideSearch.GetGlossary(DisplayResults, ErrorRetrieving);    
}

function GetSearchResults(startAt)
{
    var searchText = $get("txtSearchText").value;
    WorkmanshipMaterialsGuideSearch.GetSearchResults(searchText, startAt, DisplayResults, ErrorRetrieving); 
}
function DisplayResults(result, userContext, methodName)
{
    $get("ctl00_ContentPlaceHolder1_labContent").innerHTML = result;
}
function ErrorRetrieving(exception)
{
    $get("ctl00_ContentPlaceHolder1_labContent").innerHTML = "No results could be found. An internal error has occurred.";

}

function checkKey(e)
{
    e = e || window.event;
    var code = e.keyCode || e.which;
    if (code == 13)
        GetSearchResults(0); 
}

