﻿// JScript File

function Left(str, n) {
  if (n <= 0)
    return "";
  else if (n > String(str).length)
    return str;
  else // Valid bound, return appropriate substring
    return String(str).substring(0,n);
}


function ShowFAQ(x_strFAQClicked) {
  var el, i = 0;

  // Hide ALL of the FAQs except the one that is clicked
  var obj2Hide = document.getElementsByTagName('tr');
  if (obj2Hide) {
    if (obj2Hide.length) {
      while (el = obj2Hide.item(i++)) {
        if (Left(el.id,3) == 'faq' && el.id != x_strFAQClicked && el.id != x_strFAQClicked + '_line') {
          ShowHideObj(el.id, 'hide');
        }
      }
    } else {
      if (Left(obj2Hide.id,3) == 'faq' && el.id != x_strFAQClicked && el.id != x_strFAQClicked + '_line') {
        ShowHideObj(obj2Hide.id, 'hide');
      }
    }
  }

  ShowHideObj(x_strFAQClicked, 'alt');
  ShowHideObj(x_strFAQClicked + '_line', 'alt');
}


//x_strAction = 'show', 'hide', or 'alt'
function ShowHideObj(x_strObjToShowHide, x_strAction) {
  var el, i = 0;
  var obj2ShowHide = document.getElementById(x_strObjToShowHide);
  if (obj2ShowHide) {
    if (obj2ShowHide.length) {
      while (el = obj2ShowHide.item(i++)) {
        if (x_strAction == 'alt') {
          if (el.style.display == 'block' || el.style.display == '') {
            el.style.display = 'none';
            Img2Change(x_strObjToShowHide + 'Img', 'images/button-plus-black.gif');
          } else {
            el.style.display = '';
            Img2Change(x_strObjToShowHide + 'Img', 'images/button-minus-black.gif');
          }
        } else if (x_strAction == 'show') {
          el.style.display = '';
          Img2Change(x_strObjToShowHide + 'Img', 'images/button-minus-black.gif');
        } else if (x_strAction == 'hide') {
          el.style.display = 'none';
          Img2Change(x_strObjToShowHide + 'Img', 'images/button-plus-black.gif');
        }
      }
    } else {
      if (x_strAction == 'alt') {
        if (obj2ShowHide.style.display == 'block' || obj2ShowHide.style.display == '') {
          obj2ShowHide.style.display = 'none';
          Img2Change(x_strObjToShowHide + 'Img', 'images/button-plus-black.gif');
        } else {
          obj2ShowHide.style.display = '';
          Img2Change(x_strObjToShowHide + 'Img', 'images/button-minus-black.gif');
        }
      } else if (x_strAction == 'show') {
        obj2ShowHide.style.display = '';
        Img2Change(x_strObjToShowHide + 'Img', 'images/button-minus-black.gif');
      } else if (x_strAction == 'hide') {
        obj2ShowHide.style.display = 'none';
        Img2Change(x_strObjToShowHide + 'Img', 'images/button-plus-black.gif');
      }
    }
  }
}

function Img2Change(x_strObjImgToChange, x_strNewImageSrc) {
  var el, i = 0;
  var objImg2Change = document.getElementsByTagName('img');
  if (objImg2Change) {
    if (objImg2Change.length) {
      while (el = objImg2Change.item(i++)) {
        if (el.id == x_strObjImgToChange) {
          el.src = x_strNewImageSrc;
        }
      }
    } else {
      if (objImg2Change.id == x_strObjImgToChange) {
        objImg2Change.src = x_strNewImageSrc;
      }
    }
  }
}

// ********************************************************************************************************************************************************************************
// ********************************************************************************************************************************************************************************
// Added By DCS 02-11-2011 to get queryString values for JS
// 04-07-2011 DCS This was moved from the <head> tag becuase Dreamweaver overwrites the Head section with its own data
// These functions kept "disappearing" from the staging site.  But other changes remained.
function SelectInspectionType() {
    // will create a single selected option based on querystring value in SelectedInspection
    // USE LOWERCASE for EVALUATIONS queryStringValue uses toLowerCase
    var SelectedInspection = queryStringValue("SelectedInspection");
    // alert("SelectedInspection = " + SelectedInspection)
    if (SelectedInspection == "oovi") {
        document.write('<option selected value="Verification (Interior)">Verification (Interior) $65.00</option>');
    }
    else if (SelectedInspection == "eovi") {
        document.write('<option selected value="Evidence only (Exterior)">Evidence only (Exterior) $45.00</option>');
    }
    else if (SelectedInspection == "ooviid") {
        document.write('<option selected value="Verification w/ID (Interior)">Verification w/ID (Interior) $75.00</option>');
    }
    else if (SelectedInspection == "oovirush") {
        document.write('<option value="PMC Rush: Owner Occupancy Verification (Interior)">PMC Rush: Owner Occupancy Verification (Interior) $75.00</option>');
    }
    else if (SelectedInspection == "oovipmc") {
        document.write('<option value="PMC Verification (Interior)">PMC Verification (Interior) $50.00</option>');
    }
    else if (SelectedInspection == "testorder") {
        document.write('<option value="Test Order $1">Test Order $1 $1.00</option>');
    }
}

function queryStringValue(findName) {
    var name = new String();
    var value = new String();
    var querystring = document.location.href;
    if (querystring.indexOf("?") == -1) {
        return "null";
    }
    querystring = querystring.split("?");
    querystring = querystring[1].split("&");
    for (q = 0; q < querystring.length; q++) {
        var pair = querystring[q].split("=");
        name = pair[0].toLowerCase();
        value = pair[1].toLowerCase();
        if (findName.toLowerCase() == name) {
            return value;
        }
    }
}
// ********************************************************************************************************************************************************************************
// ********************************************************************************************************************************************************************************

