// ---------------------------------------------------------------------------------
// ASK A QUESTION
// developed by Digital Valley (www.digitalvalley.co.za)
// ---------------------------------------------------------------------------------

// variables
var xQuestion;
var xKeywordsIndex = 0;
var xSuccess = false;

// array variable containing all the redirect pages
var aRedirect = new Array();
aRedirect[0] = "franchise.php";
aRedirect[1] = "paint_panache.php";
aRedirect[2] = "paint_plascon.php";
aRedirect[3] = "paint_dulux.php";
aRedirect[4] = "hardware.php";
aRedirect[5] = "troubleshooting_exterior.php";
aRedirect[6] = "troubleshooting_interior.php";
aRedirect[7] = "tips.php";
aRedirect[8] = "ask.php";

// array variables containing all the keywords
var aKeywords_Paint_Panache = new Array();
aKeywords_Paint_Panache[0] = "panache";
aKeywords_Paint_Panache[1] = "vinyl silk";
aKeywords_Paint_Panache[2] = "stoep enamel";
aKeywords_Paint_Panache[3] = "vinyl matt";
aKeywords_Paint_Panache[4] = "pigmented plaster primer";
aKeywords_Paint_Panache[5] = "high gloss enamel";
aKeywords_Paint_Panache[6] = "bonding liquid";
aKeywords_Paint_Panache[7] = "polyglo polyurethane enamel";
aKeywords_Paint_Panache[8] = "universal undercoat";
aKeywords_Paint_Panache[9] = "general purpose pva";
aKeywords_Paint_Panache[10] = "white wood primer";
aKeywords_Paint_Panache[11] = "general purpose gloss enamel";
aKeywords_Paint_Panache[12] = "anti corrosive metal primer";
aKeywords_Paint_Panache[13] = "general purpose eggshell enamel";
aKeywords_Paint_Panache[14] = "pink wood primer";
aKeywords_Paint_Panache[15] = "coverkote";
aKeywords_Paint_Panache[16] = "multipurpose primer";
aKeywords_Paint_Panache[17] = "roof acrylic";
aKeywords_Paint_Panache[18] = "paint";

var aKeywords_Paint_Plascon = new Array();
aKeywords_Paint_Plascon[0] = "plascon";
aKeywords_Paint_Plascon[1] = "double velvet";
aKeywords_Paint_Plascon[2] = "super universal enamel";
aKeywords_Paint_Plascon[3] = "velvaglo";
aKeywords_Paint_Plascon[4] = "super acrylic polvin";
aKeywords_Paint_Plascon[5] = "wall 'n all";
aKeywords_Paint_Plascon[6] = "nuroof";
aKeywords_Paint_Plascon[7] = "micatex";

var aKeywords_Paint_Dulux = new Array();
aKeywords_Paint_Dulux[0] = "dulux";
aKeywords_Paint_Dulux[1] = "wash 'n wear silk";
aKeywords_Paint_Dulux[2] = "weatherguard";
aKeywords_Paint_Dulux[3] = "acrylic pva";
aKeywords_Paint_Dulux[4] = "roofguard";
aKeywords_Paint_Dulux[5] = "gloss enamel";
aKeywords_Paint_Dulux[6] = "wash 'n wear matt";
aKeywords_Paint_Dulux[7] = "pearlglo";
aKeywords_Paint_Dulux[8] = "varnishes and wood preservatives";
aKeywords_Paint_Dulux[9] = "wall guard";

var aKeywords_Hardware = new Array();
aKeywords_Hardware[0] = "hardware";
aKeywords_Hardware[1] = "diy";
aKeywords_Hardware[2] = "materials";
aKeywords_Hardware[3] = "screw driver";
aKeywords_Hardware[4] = "hammers";
aKeywords_Hardware[5] = "plumbing";
aKeywords_Hardware[6] = "supplies";
aKeywords_Hardware[7] = "drill";
aKeywords_Hardware[8] = "bit";
aKeywords_Hardware[9] = "square";
aKeywords_Hardware[10] = "rule";
aKeywords_Hardware[11] = "chisel";
aKeywords_Hardware[12] = "mallet";
aKeywords_Hardware[13] = "tool";
aKeywords_Hardware[14] = "glueing";
aKeywords_Hardware[15] = "staple";
aKeywords_Hardware[16] = "gun";
aKeywords_Hardware[17] = "equipment";
aKeywords_Hardware[18] = "sprinkler";
aKeywords_Hardware[19] = "broom";
aKeywords_Hardware[20] = "rake";
aKeywords_Hardware[21] = "security";
aKeywords_Hardware[22] = "lock";
aKeywords_Hardware[23] = "door";
aKeywords_Hardware[24] = "jigsaw";
aKeywords_Hardware[25] = "handheld";
aKeywords_Hardware[26] = "electrical";

var aKeywords_TroubleshootingExterior = new Array();
aKeywords_TroubleshootingExterior[0] = "troubleshooting";
aKeywords_TroubleshootingExterior[1] = "alligatoring";
aKeywords_TroubleshootingExterior[2] = "dirt pick up";
aKeywords_TroubleshootingExterior[3] = "efflorescence";
aKeywords_TroubleshootingExterior[5] = "cracking & flaking";
aKeywords_TroubleshootingExterior[6] = "frosting";
aKeywords_TroubleshootingExterior[7] = "peeling";
aKeywords_TroubleshootingExterior[8] = "poor alkali resistance";
aKeywords_TroubleshootingExterior[9] = "poor galvanised metal adhesion";
aKeywords_TroubleshootingExterior[10] = "rust";
aKeywords_TroubleshootingExterior[11] = "wrinkling";
aKeywords_TroubleshootingExterior[12] = "nailhead rusting";
aKeywords_TroubleshootingExterior[13] = "substrate cracking";
aKeywords_TroubleshootingExterior[14] = "blistering";
aKeywords_TroubleshootingExterior[15] = "surfactant leaching";
aKeywords_TroubleshootingExterior[16] = "paint incompatibility";
aKeywords_TroubleshootingExterior[17] = "mildew";

var aKeywords_TroubleshootingInterior = new Array();
aKeywords_TroubleshootingInterior[0] = "blistering";
aKeywords_TroubleshootingInterior[1] = "blocking";
aKeywords_TroubleshootingInterior[2] = "burnishing";
aKeywords_TroubleshootingInterior[3] = "cracking";
aKeywords_TroubleshootingInterior[4] = "flaking";
aKeywords_TroubleshootingInterior[5] = "substrate cracking";
aKeywords_TroubleshootingInterior[6] = "distemper";
aKeywords_TroubleshootingInterior[7] = "foaming and cratering";
aKeywords_TroubleshootingInterior[8] = "poor hiding";
aKeywords_TroubleshootingInterior[9] = "mildew";
aKeywords_TroubleshootingInterior[10] = "mud cracking";
aKeywords_TroubleshootingInterior[11] = "poor print resitance";
aKeywords_TroubleshootingInterior[12] = "roller marks";
aKeywords_TroubleshootingInterior[13] = "stppling";
aKeywords_TroubleshootingInterior[14] = "rust";
aKeywords_TroubleshootingInterior[15] = "poor scrub resistance";
aKeywords_TroubleshootingInterior[16] = "surfactant leaching";
aKeywords_TroubleshootingInterior[17] = "wrinkling";
aKeywords_TroubleshootingInterior[18] = "yellowing";
aKeywords_TroubleshootingInterior[19] = "sagging";
aKeywords_TroubleshootingInterior[20] = "picture framing";
aKeywords_TroubleshootingInterior[21] = "roller splatter";

var aKeywords_Tips = new Array();
aKeywords_Tips[0] = "tips";
aKeywords_Tips[1] = "colour";
aKeywords_Tips[2] = "facts";
aKeywords_Tips[3] = "painting";
aKeywords_Tips[4] = "exterior colours";
aKeywords_Tips[5] = "interior colours";
aKeywords_Tips[6] = "cleaning paint";
aKeywords_Tips[7] = "neat Corners";
aKeywords_Tips[8] = "painting advice";
aKeywords_Tips[9] = "getting rid of that paint smell";
aKeywords_Tips[10] = "temperature to paint ";
aKeywords_Tips[11] = "painting walls and ceilings";
aKeywords_Tips[12] = "painting roofs";
aKeywords_Tips[13] = "painting metals";
aKeywords_Tips[14] = "painting woods";
aKeywords_Tips[15] = "antiquing";
aKeywords_Tips[16] = "blocking";
aKeywords_Tips[17] = "bronzing";
aKeywords_Tips[18] = "colour washing";

// function that initializes and keyword search
function searchKeywords_Init()
{
  // stores the current question
  xQuestion = document.getElementById('search').value.toLowerCase();
  
  // checks question and relates it to a page and then redirects the browser to that page
  if (xQuestion == "type your question here" || xQuestion.length == 0)
  {
    alert("Please ask a question");
    return;
  }
  else
  {
    // runs keyword search
    searchKeywords_Do();
  }
}

// function that checks through all the keywords arrays to look for a match
// may be redundant code, but it works...
function searchKeywords_Do()
{
  // checks the PAINT PANACHE array for keywords
  for (a = 0; a <= aKeywords_Paint_Panache.length; a++)
  {
    if (xQuestion == aKeywords_Paint_Panache[a])
    {
      // stores the success of finding a match
      xSuccess = true;
      
      // takes user to the paint page
      foundMatch(1);
      
      return;
    }
  }
  
  // checks the PAINT PLASCON array for keywords
  for (a = 0; a <= aKeywords_Paint_Plascon.length; a++)
  {
    if (xQuestion == aKeywords_Paint_Plascon[a])
    {
      // stores the success of finding a match
      xSuccess = true;
      
      // takes user to the paint page
      foundMatch(2);
      
      return;
    }
  }
  
  // checks the PAINT DULUX array for keywords
  for (a = 0; a <= aKeywords_Paint_Dulux.length; a++)
  {
    if (xQuestion == aKeywords_Paint_Dulux[a])
    {
      // stores the success of finding a match
      xSuccess = true;
      
      // takes user to the paint page
      foundMatch(3);
      
      return;
    }
  }
  
  // checks the HARDWARE array for keywords
  for (a = 0; a <= aKeywords_Hardware.length; a++)
  {
    if (xQuestion == aKeywords_Hardware[a])
    {
      // stores the success of finding a match
      xSuccess = true;
      
      // takes user to the hardware page
      foundMatch(4);
      
      return;
    }
  }
  
  // checks the TROUBLESHOOTING array for keywords
  for (a = 0; a <= aKeywords_TroubleshootingExterior.length; a++)
  {
    if (xQuestion == aKeywords_TroubleshootingExterior[a])
    {
      // stores the success of finding a match
      xSuccess = true;
      
      // takes user to the troubleshooting page
      foundMatch(5);
      
      return;
    }
  }
  
  // checks the TROUBLESHOOTING array for keywords
  for (a = 0; a <= aKeywords_TroubleshootingInterior.length; a++)
  {
    if (xQuestion == aKeywords_TroubleshootingInterior[a])
    {
      // stores the success of finding a match
      xSuccess = true;
      
      // takes user to the troubleshooting page
      foundMatch(6);
      
      return;
    }
  }
  
  // checks the TIPS array for keywords
  for (a = 0; a <= aKeywords_Tips.length; a++)
  {
    if (xQuestion == aKeywords_Tips[a])
    {
      // stores the success of finding a match
      xSuccess = true;
      
      // takes user to the tips page
      foundMatch(7);
      
      return;
    }
  }
  
  // if the search found no matches / results
  if (xSuccess == false)
  {
    alert("Sorry, your keyword was not found. We will direct you to our DIY questionaire.");
  
    // redirects the user to the correct page
    document.location.href = aRedirect[8]
  }
}

// function that redirects the user to the correct page after a match is found
function foundMatch(xPageIndex)
{
  // redirects the user to the correct page
  document.location.href = aRedirect[xPageIndex];
  return;
}
