﻿function HeaderTextLoader(url, rootElement){
    // create downloader
    this.control = rootElement.getHost();
    this.downloader = this.control.createObject("downloader");
    
    this.HeaderTextAttract = new Array();
    this.HeaderTextQ1 = new Array();
    this.HeaderTextQ2 = new Array();
    this.HeaderTextQ3 = new Array();
    this.HeaderTextQ4 = new Array();
    // attach event handlers
    this.downloader.addEventListener("downloadFailed", Silverlight.createDelegate(this, this.OnHeaderTextDownloadFailed));
    this.downloader.addEventListener("completed", Silverlight.createDelegate(this, this.OnHeaderTextDownloadComplete));
    this.url = url;  
   // download
    this.downloader.open("GET", url);
    this.downloader.send();
 
}
HeaderTextLoader.prototype.OnHeaderTextDownloadComplete = function(sender, args)
{ 
    var xml = sender.responseText;
    var doc;
    // create appropiate XML document
    if (window.ActiveXObject) {
        // IE 6 (and 7)
        doc = new ActiveXObject("Microsoft.XMLDOM");
        doc.async="false";
        doc.loadXML(xml);
        if (!doc.loadXML(xml)){
            // handle parse error
            throw doc.parseError.reason;
        }
    }
    else {
        // Firefox and others
        var parser = new DOMParser();
        doc = parser.parseFromString(xml, "text/xml");
    }

    var xmlNodes = doc.getElementsByTagName("attract");
     for(i=0;i<xmlNodes.length;i++){
        this.HeaderTextAttract.push(xmlNodes[i].childNodes[0].nodeValue);
        
    }
    var xmlNodes = doc.getElementsByTagName("q1");
     for(i=0;i<xmlNodes.length;i++){
        this.HeaderTextQ1.push(xmlNodes[i].childNodes[0].nodeValue);
        
    }
    var xmlNodes = doc.getElementsByTagName("q2");
     for(i=0;i<xmlNodes.length;i++){
        this.HeaderTextQ2.push(xmlNodes[i].childNodes[0].nodeValue);
        
    }
    var xmlNodes = doc.getElementsByTagName("q3");
     for(i=0;i<xmlNodes.length;i++){
        this.HeaderTextQ3.push(xmlNodes[i].childNodes[0].nodeValue);
        
    }
    var xmlNodes = doc.getElementsByTagName("q4");
     for(i=0;i<xmlNodes.length;i++){
        this.HeaderTextQ4.push(xmlNodes[i].childNodes[0].nodeValue);
        
    }
}
HeaderTextLoader.prototype.getValues = function(section)
{   
    if (section == "attract"){
    return this.HeaderTextAttract;
    }
    if (section == "q1"){
    return this.HeaderTextQ1;
    }
    if (section == "q2"){
    return this.HeaderTextQ2;
    }
    if (section == "q3"){
    return this.HeaderTextQ3;
    }
    if (section == "q4"){
    return this.HeaderTextQ4;
    }
}
HeaderTextLoader.prototype.OnHeaderTextDownloadFailed = function(sender, args)
{
    alert("download failed: "+ this.url);
}
 



		