var FAQTabbing = false;
function FAQExpand(type, item) {
  if (type == 0) {
    item.parentNode.className = item.parentNode.className.replace(' faqSetClosed', '');
    item.onclick = function() {FAQCollapse(0,this);};
    item.src = 'style/collapse.png';
    var Heading = item.parentNode.getElementsByTagName('H4')[0];
    Heading.onclick = function() {FAQCollapse(1,this);};
    } else
  if (type == 1) {
    item.parentNode.className = item.parentNode.className.replace(' faqSetClosed', '');
    item.onclick = function() {FAQCollapse(1,this);};
    var ExpandCollapseImage = item.parentNode.getElementsByTagName('IMG')[1];
    ExpandCollapseImage.src = 'style/collapse.png';
    ExpandCollapseImage.onclick = function() {FAQCollapse(0,this);};
    }
  }
function FAQCollapse(type, item) {
  if (type == 0) {
    item.parentNode.className += ' faqSetClosed';
    item.onclick = function() {FAQExpand(0,this);};
    item.src = 'style/expand.png';
    var Heading = item.parentNode.getElementsByTagName('H4')[0];
    Heading.onclick = function() {FAQExpand(1,this);};
    } else
  if (type == 1) {
    item.parentNode.className += ' faqSetClosed';
    item.onclick = function() {FAQExpand(1,this);};
    var ExpandCollapseImage = item.parentNode.getElementsByTagName('IMG')[1];
    ExpandCollapseImage.src = 'style/expand.png';
    ExpandCollapseImage.onclick = function() {FAQExpand(0,this);};
    }
  }
function initializeFAQs() {
  var FAQResource = document.getElementById('FAQModResource');
  var FAQSets = new Array();
  var TabsFAQs = new Array();
  for (var i=0; i<FAQResource.getElementsByTagName('DIV').length; i++) {
    if (FAQResource.getElementsByTagName('DIV')[i].className && FAQResource.getElementsByTagName('DIV')[i].className.indexOf('FAQSet') >= 0) {
      FAQSets[i] = FAQResource.getElementsByTagName('DIV')[i];
      }
    }
  for (i in FAQSets) {
    var Heading = null;
    for (var n=0; n<FAQSets[i].getElementsByTagName('H4').length; n++) {
      if (FAQSets[i].getElementsByTagName('H4')[n].className && FAQSets[i].getElementsByTagName('H4')[n].className.indexOf('faqHeading') >= 0) {
        Heading = FAQSets[i].getElementsByTagName('H4')[n].innerHTML;
        break;
        }
      }
    for (var n=0; n<FAQSets[i].getElementsByTagName('LI').length; n++) {
      if (
        FAQSets[i].getElementsByTagName('LI')[n].parentNode &&
        FAQSets[i].getElementsByTagName('LI')[n].parentNode.className &&
        FAQSets[i].getElementsByTagName('LI')[n].parentNode.className.indexOf('faqList') >= 0
        ) {
          var FAQClass = FAQSets[i].getElementsByTagName('LI')[n].className.split(' ');
          var TabIndex = 0;
          for (var t in FAQClass) if (FAQClass[t].indexOf('tabIndex') >= 0) TabIndex = parseInt(FAQClass[t].replace('tabIndex',''));
          if (!TabsFAQs[TabIndex]) TabsFAQs[TabIndex] = new Array();
          if (!TabsFAQs[TabIndex][Heading]) TabsFAQs[TabIndex][Heading] = new Array();
          TabsFAQs[TabIndex][Heading][i+''+n]
            = FAQSets[i].getElementsByTagName('LI')[n];
          TabsFAQs[TabIndex][Heading][i+''+n].EID = parseInt(FAQSets[i].getElementsByTagName('LI')[n].id.replace('faq'+TabIndex+'-',''))
          }
      }
    }
  for (var i in TabsFAQs) {
    if (
      document.getElementById('faqtab'+i) &&
      document.getElementById('faqtab'+i).className &&
      document.getElementById('faqtab'+i).className.indexOf('FAQModuleDisplay') >= 0
      ) {
      var FAQContainer = document.getElementById('faqtab'+i);
      var Build = '';
      var cat = 1;
      for (var n in TabsFAQs[i]) {
        Build += '<div class="faqSet faqSetClosed">'+
                 '<h4 onmouseover="if (this.className.indexOf(\' FSHhover\') < 0) this.className+=\' FSHhover\'" '+
                 'onmouseout="this.className = this.className.replace(\' FSHhover\',\'\')"'+
                 ' onclick="FAQExpand(1,this)" class="faqSetHeading">'+
                 '<img hspace="4" src="images/faq-bullet.png" alt="'+n+'" />'+n+'</h4>';
            Build += '<img onclick="FAQExpand(0,this)" class="expandCollapseSet" height="10" src="style/expand.png" />';
        Build += '<div class="faqSetItems"><ul>';
        var item = 1;
        for (var t in TabsFAQs[i][n]) {
          var T = TabsFAQs[i][n][t].EID;
          var Question = TabsFAQs[i][n][t].getElementsByTagName('H5')[0];
          var Answer = TabsFAQs[i][n][t].getElementsByTagName('DIV')[0];
          if (Answer.nextSibling) var Votes = Answer.nextSibling.innerHTML.split(':');
          Build += '<li>';
          Build += '<p class="fssmall dark faqQuestion"><strong>'+cat+'.'+item+' '+Question.innerHTML+'</strong></p>';
          Build += '<div class="faqAnswer">'+Answer.innerHTML+'<div class="clear">&nbsp;</div></div>';
          Build += '<div class="feedback">';
          Build += '<span class="voteFAQ" id="FAQvoter'+T+'">';
          if (Votes[0] > 0 && Votes[1]) Build += '<b class="FAQvotesUp">('+Votes[0]+')</b> ';
          Build += '<a href="javascript:;" onclick="FAQVoteUp('+T+')">';
          Build += '<img src="style/thumbsup.png" alt="Vote up" /></a>';
          Build += '<a href="javascript:;" onclick="FAQVoteDown('+T+')">';
          Build += '<img src="style/thumbsdown.png" alt="Vote down" /></a>';
          if (Votes[0] > 0 && Votes[1]) Build += ' <b class="FAQvotesDown">('+Votes[1]+')</b>';
          Build += ' &nbsp; - &nbsp; Was this answer helpful?</span>';
          Build += 'Comment or ask a question';
          Build += '<a id="toggleFAQComment'+T+'" href="javascript:;" onclick="openFAQComment('+T+')">';
          Build += '<img src="style/comment.png" alt="Comment or Ask a question" /></a>';
          Build += '<div class="clear">&nbsp;</div>';
          Build += '<div id="feedBackFAQcomment'+T+'" class="comments"><div id="feedBackFAQcommentInner'+T+'">';
          Build += '<label for="FAQCommentName'+T+'">Your Name</label>';
          Build += '<input type="text" name="FAQCommentName'+T+'" id="FAQCommentName'+T+'" />';
          Build += '<div class="clear">&nbsp;</div>';
          Build += '<label for="FAQCommentEmail'+T+'">Email Address</label>';
          Build += '<input type="text" name="FAQCommentEmail'+T+'" id="FAQCommentEmail'+T+'" />';
          Build += '<div class="clear">&nbsp;</div>';
          Build += '<textarea onkeyup="FAQcommentEdit('+T+')" id="FAQcommentText'+T+'"></textarea><br />';
          Build += '<span id="FAQCommentEditCHR'+T+'">130 Characters</span>';
          Build += '<button type="button" onclick="submitFAQComment('+T+')">Submit</button>';
          Build += '<button type="button" onclick="closeFAQComment('+T+')">Cancel</button>';
          Build += '</div></div>';
          Build += '<div class="clear">&nbsp;</div></div>';
          Build += '</li>';
          item++;
          }
        Build += '</ul></div>';
        Build += '</div>';
        cat++;
        }
      FAQContainer.innerHTML = Build;
      }
    }
  }
function FAQCommentLimit() {
  return 160;
  }
function FAQcommentEdit(cid) {
  if (document.getElementById('FAQcommentText'+cid))
    if (document.getElementById('FAQcommentText'+cid).value.length > FAQCommentLimit())
      document.getElementById('FAQcommentText'+cid).value = document.getElementById('FAQcommentText'+cid).value.substr(0,FAQCommentLimit());
  if (document.getElementById('FAQcommentText'+cid) && document.getElementById('FAQCommentEditCHR'+cid))
    document.getElementById('FAQCommentEditCHR'+cid).innerHTML =
    (FAQCommentLimit() - document.getElementById('FAQcommentText'+cid).value.length) + ' Characters';
  }
function openFAQComment(cid) {
  if (document.getElementById('feedBackFAQcomment'+cid))
    document.getElementById('feedBackFAQcomment'+cid).style.display = 'block';
  document.getElementById('toggleFAQComment'+cid).onclick = function() {closeFAQComment(cid);};
  }
function closeFAQComment(cid) {
  if (document.getElementById('FAQCommentName'+cid)) document.getElementById('FAQCommentName'+cid).value = '';
  if (document.getElementById('FAQCommentEmail'+cid)) document.getElementById('FAQCommentEmail'+cid).value = '';
  if (document.getElementById('FAQcommentText'+cid)) document.getElementById('FAQcommentText'+cid).value = '';
  if (document.getElementById('FAQCommentEditCHR'+cid))
    document.getElementById('FAQCommentEditCHR'+cid).innerHTML = FAQCommentLimit()+ ' Characters';
  if (document.getElementById('feedBackFAQcomment'+cid))
    document.getElementById('feedBackFAQcomment'+cid).style.display = 'none';
  document.getElementById('toggleFAQComment'+cid).onclick = function() {openFAQComment(cid);};
  }
function restoreFAQComment(cid) {
  document.getElementById('feedBackFAQcommentInner'+cid).innerHTML = document.getElementById('feedBackFAQcommentInner'+cid).inHTML;
  closeFAQComment(cid);
  }
function FAQCommentSent(cid) {
  var Thanks = '<div style="border:1px solid #ddd;padding:4px;float:right;margin:20px 0;"><img src="images/sysok.png" alt="Thank you" /> ';
  Thanks += 'Your comment has been sent.<br />Thank you</div>';
  document.getElementById('feedBackFAQcommentInner'+cid).innerHTML = Thanks;
  setTimeout("restoreFAQComment("+cid+")", 4000);
  }
function FAQCommentFailed(cid) {
  var Thanks = '<div style="border:1px solid #ddd;padding:4px;float:right;margin:20px 0;"><img src="images/syserror.png" alt="Error" /> ';
  Thanks += 'Your comment could not be sent.<br />Sorry for the inconvenience</div>';
  document.getElementById('feedBackFAQcommentInner'+cid).innerHTML = Thanks;
  setTimeout("restoreFAQComment("+cid+")", 4000);
  }
function FAQcontinueSubmit(email,addit) {
  document.getElementById('feedBackFAQcommentInner'+addit[2]).inHTML = document.getElementById('feedBackFAQcommentInner'+addit[2]).innerHTML;
  document.getElementById('feedBackFAQcommentInner'+addit[2]).innerHTML = '<img style="width:24px;height:24px;margin:30px 60px 30px 0" src="images/loading.gif" />';
  var Name = addit[0];
  var Comment = addit[1];
  var xmlobj = new AJAXGetXmlHttp();
  if (xmlobj) {
    var URL = '__ajax/?req=FAQCommentReq&faqid='+addit[2]+'&name='+Name+'&email='+email+'&comment='+urlencode(Comment);
    xmlobj.onreadystatechange=function() {
      if (this.readyState==4) if (this.responseText == '1')
        FAQCommentSent(addit[2]); else
        FAQCommentFailed(addit[2]);
      }
    xmlobj.open("GET",URL,true);
    xmlobj.send(null);
    }
  }
function submitFAQComment(faqID) {
  var Name = document.getElementById('FAQCommentName'+faqID).value;
  var Email = document.getElementById('FAQCommentEmail'+faqID).value;
  var Comment = document.getElementById('FAQcommentText'+faqID).value;
  if (Name.length > 0 && Email.length > 0 && Comment.length> 0) {
    FAQvalidateEmailAddressOK = FAQcontinueSubmit;
    FAQvalidateEmailAddress(Email,[Name,Comment,faqID]);
    } else alert('All fields are mandatory');
  }
function FAQSendVote(faqid, vote) {
  url = '__ajax/?req=voteFAQ&faqid='+faqid+'&vote='+(vote ? '1' : '0');
  var xmlobj = new AJAXGetXmlHttp();
  xmlobj.onreadystatechange = function() {};
  xmlobj.open("GET",url,true);
  xmlobj.send(null);
  }
function FAQVoteUp(faqid) {
  document.getElementById('FAQvoter'+faqid).innerHTML = '<span style="text-align:left;">Thank you for your feedback,<br />If you\'d like, you may<br />comment or request more info on the right</span>';
  FAQSendVote(faqid, 1);
  //openFAQComment(faqid);
  }
function FAQVoteDown(faqid) {
  document.getElementById('FAQvoter'+faqid).innerHTML = '<span style="text-align:left;">Thank you for your feedback,<br />To better our effeciency, please feel<br /> free to leave your comment on the right</span>';
  FAQSendVote(faqid, 0);
  //openFAQComment(faqid);
  }
function FAQvalidateEmailAddressOK() {}
function FAQvalidateEmailAddress(email,addit,state) {
  if (!state) {
    var xmlobj = new AJAXGetXmlHttp();
    if (xmlobj) {
      var URL = '__ajax/?req=vemailadd&text='+email;
      xmlobj.arg1 = email;
      xmlobj.onreadystatechange=function() {
        if (this.readyState==4) if (this.responseText == '1')
          FAQvalidateEmailAddress(email,addit,2); else
          FAQvalidateEmailAddress(email,addit,1);
        };
      xmlobj.open("GET",URL,true);
      xmlobj.send(null);
      }
    } else {
    if (state == 2) FAQvalidateEmailAddressOK(email,addit); else
    alert('"' +email + '" is not a valid email address');
    }
  }
