var surveys;
var resources;
//XML PARSER AND LOADER

/**
 * Create a new Document object. If no arguments are specified,
 * the document will be empty. If a root tag is specified, the document
 * will contain that single root tag. If the root tag has a namespace
 * prefix, the second argument must specify the URL that identifies the
 * namespace.
 */
if (document.implementation && document.implementation.createDocument) {
XML.newDocument = function(rootTagName, namespaceURL) {
  if (!rootTagName) rootTagName = "";
  if (!namespaceURL) namespaceURL = "";
  if (document.implementation && document.implementation.createDocument) {
    // This is the W3C standard way to do it
    return document.implementation.createDocument(namespaceURL, rootTagName, null);
  }
  else { // This is the IE way to do it
    // Create an empty document as an ActiveX object
    // If there is no root element, this is all we have to do
    var doc = new ActiveXObject("MSXML2.DOMDocument");
    // If there is a root tag, initialize the document
    if (rootTagName) {
      // Look for a namespace prefix
      var prefix = "";
      var tagname = rootTagName;
      var p = rootTagName.indexOf(':');
      if (p != -1) {
        prefix = rootTagName.substring(0, p);
        tagname = rootTagName.substring(p+1);
      }
      // If we have a namespace, we must have a namespace prefix
      // If we don't have a namespace, we discard any prefix
      if (namespaceURL) {
        if (!prefix) prefix = "a0"; // What Firefox uses
      }
      else prefix = "";
      // Create the root element (with optional namespace) as a
      // string of text
      var text = "&lt;" + (prefix?(prefix+":"):"") +  tagname +
          (namespaceURL
           ?(" xmlns:" + prefix + '="' + namespaceURL +'"')
           :"") +
          "/>";
      // And parse that text into the empty document
      doc.loadXML(text);
    }
    return doc;
  }
};
XML.load = function(url) {
    // Create a new document with the previously defined function
    var xmldoc = XML.newDocument();
    xmldoc.async = false;  // We want to load synchronously
    xmldoc.load(url);      // Load and parse
    return xmldoc;         // Return the document
var title = "";
};
}
function loadXML() {
//load xml file
// code for IE
if (window.ActiveXObject) {
	xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	xmlDoc.async=false;
	xmlDoc.load("mainpagexmlout.php");
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument) {
	var xmlDoc = XML.load("mainpagexmlout.php");
}

//BEGIN SURVEYS

if (xmlDoc.getElementsByTagName("survey")[0] && xmlDoc.getElementsByTagName("survey")[0].childNodes.length != 0) {
var xmlsurveys = xmlDoc.getElementsByTagName("survey");
//Build Arrays
for(var i=0; i<xmlsurveys.length; i++) {
  var output = new Array();
  var survey_id = new Array();
  var survey_name = new Array();
  var survey_time = new Array();
  var s_q_outs = new Array();
}
//Populate Arrays
for(var i=0; i<xmlsurveys.length; i++) {
  output[i] = "<form method=\"post\" action=\"surveys/index.php\">\n";
  var xmlsurvey = xmlsurveys[i];
  survey_id[i] = xmlsurvey.getElementsByTagName('id')[0].childNodes[0].nodeValue;
  survey_name[i] = xmlsurvey.getElementsByTagName('name')[0].childNodes[0].nodeValue;
  survey_time[i] = xmlsurvey.getElementsByTagName('time')[0].childNodes[0].nodeValue;
  var survey_questions = xmlsurvey.getElementsByTagName('question');
  s_q_outs[i] = "";
  for(var x=0; x<survey_questions.length;x++) {
    var survey_question = survey_questions[x];
    var s_q_text = survey_question.getElementsByTagName('text')[0].childNodes[0].nodeValue;
    var s_q_type = survey_question.getElementsByTagName('qtype')[0].childNodes[0].nodeValue;
    var s_q_id = survey_question.getElementsByTagName('qid')[0].childNodes[0].nodeValue;
    var s_q_answers = survey_question.getElementsByTagName('answers')[0];
    var s_q_ans = s_q_answers.getElementsByTagName('answer');
    ansout ="";
    for(var y=0; y < s_q_ans.length; y++) {
      s_q_a = s_q_ans[y];
      s_q_a_text = s_q_a.getElementsByTagName('text')[0].childNodes[0].nodeValue;
      s_q_a_value = s_q_a.getElementsByTagName('value')[0].childNodes[0].nodeValue;
      if (s_q_type == "Radio Buttons") {
        ansout += "<input type=\"radio\" value=\"" + s_q_a_value + "\" name=\"" + s_q_id + "\" /><font style=\"font-size: 13px;\">" + s_q_a_text + "</font><br />\n";
      }
      if (s_q_type == "Check Boxes") {
        ansout += "<input type=\"checkbox\" value=\"" + s_q_a_value + "\" name=\"" + s_q_id + "\"><font style=\"font-size: 13px;\">" + s_q_a_text + "</font><br />\n";
      }
    }
   s_q_outs[i] += "<center><font style=\"font-size: 13px;\">" + s_q_text + "</font></center>\n";
   s_q_outs[i] += ansout;
  }
output[i] += "<img width=\"171\" height=\"19\" border=\"0\" _base_target=\"_top\" src=\"Survey.jpg\" /><br />\n";
output[i] += "<input type=\"hidden\" value=\"" + survey_id[i] + "\" name=\"sid\"/>\n";
//output[i] += "Survey Name: " + survey_name[i] + "<br />\n";
output[i] += s_q_outs[i];
//output[i] += "Should take about " + survey_time[i] + " minute(s)<br />\n";
output[i] += "<center><input type=\"submit\" name=\"submit\" value=\"Vote\" /><br />\n";
output[i] += "<font style=\"font-size: 10px;\">Please take this survey no more<br />then 2 times per household.</font></center></form>";
}
var finalout = "<div style=\"width: 171px;\">\n";
for(var i=0; i<output.length; i++) {
finalout += output[i];
}
finalout += "</div>";
}
if (finalout == null) {
var finalout = "";
}
surveys = finalout;

//END SURVEYS - BEGIN RESOURCES

finalout = "";

if (xmlDoc.getElementsByTagName("resource")[0] && xmlDoc.getElementsByTagName("resource")[0].childNodes.length != 0) {
var xmlresourc = xmlDoc.getElementsByTagName("resource");
//Build Arrays
for(var i=0; i<xmlresourc.length; i++) {
  var r_output = new Array();
}
for(var i=0; i<xmlresourc.length; i++) {
r_output[i] = "";
r_name = xmlresourc[i].getElementsByTagName('name')[0].childNodes[0].nodeValue;
r_link = xmlresourc[i].getElementsByTagName('link')[0].childNodes[0].nodeValue;
r_output[i] = "<option value=\"" + r_link + "\">" + r_name + "</option>\n";
}
finalout += "<select size=\"1\" name=\"Christian Resources\" class=\"com\" id=\"resources\" style=\"width: 165px; overflow: hidden;\" onChange=\"window.open(window.document.getElementById('resources').options[selectedIndex].value);\">\n";
finalout += "<option value=\"http://www.wdac.com\">Select Your Resource</option>\n";
for(var i=0; i<xmlresourc.length; i++) {
finalout += r_output[i];
}
finalout += "</select>\n";
resources = finalout;
}
}