var req;

function loadXMLDoc(url) {
	req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest && !(window.ActiveXObject)) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
		}
    }
	if(req) {
		req.onreadystatechange = processReqChange;
		req.open("GET", url, true);
		req.send("");
	}
}



function processReqChange() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            // ...processing statements go here...
			//theXML = req.responseXML;
			
			createTable(req);
			
        } else {
            alert("There was a problem retrieving the XML data:\n" +
                req.statusText);
        }
    }
}



function createTable(req)
{
	var theXML = (new DOMParser()).parseFromString(req.responseText, "text/xml");
			myHTMLOutput = '';
			var x = theXML.getElementsByTagName('pp');
			//alert(x.length);
			for(u=0; u<x.length; ++u) {
				var myArray = null;
				var myArray = new Array();
				for (j=0;j<x[u].childNodes.length;j++)
				{
					if (x[u].childNodes[j].nodeType != 1) continue;
					myArray[x[u].childNodes[j].nodeName] = x[u].childNodes[j].firstChild.nodeValue;			
				}
				
				
				pattern = new RegExp('yes', 'gi');
				pattern2 = new RegExp('yes', 'gi');
				
				
				if(pattern.test(myArray["l2"])) {
					//alert(pattern.test(myArray["l2"]));
					name = myArray["l1"];
					age = myArray["l3"];
					infants = myArray["l4"];
					siblings = myArray["l5"];
					license = myArray["l6"];
					country = myArray["l8"];
					arrival = myArray["l7"];
					photo = myArray["l9"];			
					shortBio = myArray["l10"];
					pdf = myArray["l12"];
					
		
					mydata = BuildStudentHTML(name,age,infants,siblings,license,country,photo,shortBio);
					myHTMLOutput = myHTMLOutput + mydata;			
				}
			
			
			}
			//alert(myHTMLOutput);
	document.getElementById("ContentArea").innerHTML = myHTMLOutput;
}

 function BuildStudentHTML(name,age,infants,siblings,license,country,photo,shortBio){
	
output = '<table width="349" border="0" cellpadding="0" cellspacing="0">         <tr>            <td width="107" valign="top" align="center"><img src="../put_gallery_files_in_here/' + photo + '" width="100"><br><a href="../put_gallery_files_in_here/' + pdf + '" target="_blank">View Full Profile</a></td>            <td width="236" valign="top">Name: <b>' + name + '</b><br>              Age: <b>' + age + '</b><br>              Country: <b>' + country + '</b><br>              Infant Qualified: <b>' + infants + '</b><br>              Siblings: <b>' + siblings + '</b><br>              Driver  License: <b>' + license + '</b><br>              Arrival Month(s): <b>' + arrival + '</b><br>              Profile: ' + shortBio + '<br><a href="../put_gallery_files_in_here/' + pdf + '" target="_blank">View Full Profile</a></td>            </tr>          <tr>            <td valign="top" colspan="2"><br /><hr /><br /></td>            </tr>        </table>';	// Build HTML string and return
	return output;
}

if (typeof DOMParser == "undefined") {
   DOMParser = function () {}

   DOMParser.prototype.parseFromString = function (str, contentType) {
      if (typeof ActiveXObject != "undefined") {
         var d = new ActiveXObject("MSXML.DomDocument");
         d.loadXML(str);
         return d;
      } else if (typeof XMLHttpRequest != "undefined") {
         var req = new XMLHttpRequest;
         req.open("GET", "data:" + (contentType || "application/xml") +
                         ";charset=utf-8," + encodeURIComponent(str), false);
         if (req.overrideMimeType) {
            req.overrideMimeType(contentType);
         }
         req.send(null);
         return req.responseXML;
      }
   }
}
