// Java Document


function loadXMLDoc(url,cfunc)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=cfunc;
xmlhttp.open("GET",url,true);
xmlhttp.send();
}

function Song(form)
{
            { 
document.getElementById("tabletrack").style.display = "none"; 
            } 
            { 
document.getElementById("remove").style.display = "none"; 
            } 			
			

     {
    var TestVar9=form.inputbox.value;      
     }	 
	 //code to eliminate space as a input	 
	 if (TestVar9=="")
	                  {
                      loadXMLDoc("Text.txt",function()
                              {  
                      if (xmlhttp.readyState==4 && xmlhttp.status==200)
                                 {
                      document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
                                 }	
                              });                      
                      }		          
	 else
  {	
//code to evaluate form.inputbox.value which should give either a "true" or "false" result
 var TestVar8=new RegExp(TestVar9,"i"); 
      {
loadXMLDoc("XMLData.xml",function()
         {
   if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
      var xmlDoc=xmlhttp.responseXML;
      var x=xmlDoc.getElementsByTagName("track");	 	 
      var trackValue8;
	  var flag=false;
      for (var i=0;i<x.length;i++)
                {				
         trackValue8 = (x[i].getElementsByTagName("songtitle")[0].childNodes[0].nodeValue);			   
		 	if (TestVar8.test(trackValue8) == true)			
                    {
			 flag=true;	
			          {
                      loadXMLDoc("Textresults.txt",function()
                              {  
                      if (xmlhttp.readyState==4 && xmlhttp.status==200)
                                 {
				      //alert (flag);
			
                      document.getElementById("results").innerHTML=xmlhttp.responseText;
					  
                                 }	
                              });                      
                      }		  	 
           // alert ("You Have A Match That is True: " + trackValue + flag + i );	
			                            {     
			//Declare variables and create table, tableheader and tablebody
			var oTable=document.createElement("table");
			var oThead=document.createElement("thead");	
			var oTbody=document.createElement("tbody");
			//var oRow,oCell;
			//var i,j;
			
			//Set the table's width and color
			oTable.style.width = '926px';
            oTable.style.backgroundColor='#c0c0c0';
					
			              {
			//Declare Table Headings
			var heading = new Array();
			heading[0] = "Track";
			heading[1] = "Song Title";
			heading[2] = "Artist";
			heading[3] = "Key";
			heading[4] = "Buy Now";
			heading[5] = "View Cart";	
						            
			//Insert the created elements into header
			oTable.appendChild(oThead);
						
			//Insert a row into the header and set its background color
			oRow=document.createElement("tr");
			oRow.style.height= '28px'
			oRow.style.backgroundColor='#a8a8a8';
			oRow.style.borderCollapse="collapse";
			oRow.style.border = '4px solid #a8a8a8';
			oThead.appendChild(oRow);
			oThead.style.width = '926px';
		
		    //Create and insert cells into the header Row	
				
			{
			oCell=document.createElement("th");
			oCell.innerHTML=heading[0];
			oCell.style.width = '67px';
			oCell.className = 'style2';
			oCell.style.border="2px solid #0000FF";
			oRow.appendChild(oCell);
			}			
			{
			oCell=document.createElement("th");
			oCell.innerHTML=heading[1];
			oCell.style.width = '399px';
			oCell.className = 'style2';
			oCell.style.border="2px solid #0000FF";
			oRow.appendChild(oCell);
			}			
			{
			oCell=document.createElement("th");
			oCell.innerHTML=heading[2];
			oCell.style.width = '163px';
			oCell.className = 'style2';
			oCell.style.border="2px solid #0000FF";
			oRow.appendChild(oCell);
			}			
			{
			oCell=document.createElement("th");
			oCell.innerHTML=heading[3];
			oCell.style.width = '29px';
			oCell.className = 'style2';
			oCell.style.border="2px solid #0000FF";
			oRow.appendChild(oCell);
			}			
			{
			oCell=document.createElement("th");
			oCell.innerHTML=heading[4];
			oCell.style.width = '121px';
			oCell.className = 'style2';
			oCell.style.border="2px solid #0000FF";
			oRow.appendChild(oCell);
			}			
			{
			oCell=document.createElement("th");
			oCell.innerHTML=heading[5];
			oCell.style.width = '107px';
			oCell.className = 'style2';
			oCell.style.border="2px solid #0000FF";
			oRow.appendChild(oCell);
			}	
			
					              
			               }
			var x=xmlDoc.getElementsByTagName("track");
			var trackValue8;			     
			for (var i=0;i<x.length;i++) 
			              {
			 trackValue8 = (x[i].getElementsByTagName("songtitle")[0].childNodes[0].nodeValue);			   
		 	if (TestVar8.test(trackValue8) == true)
			         {  			  
			//Insert the created elements into body
			oTable.appendChild(oTbody);
			
			//Insert a row into the body and set its background color
			oRow1=document.createElement("tr");			
			oRow1.style.height= '28px';
			oRow1.style.backgroundColor='#d8d8d8';
			oRow1.style.borderCollapse="collapse";
			oRow1.style.border = '4px solid #a8a8a8';
			oTbody.appendChild(oRow1);			
			
			//Create and insert cells into the body Row			
			{
			oData=document.createElement("td");
			oData.innerHTML=(x[i].getElementsByTagName("number")[0].childNodes[0].nodeValue);			
			oData.style.borderTop="1px groove #505050";
			oData.style.borderRight="1px solid #a8a8a8";
			oData.style.borderBottom="1px solid #b8b8b8";
			oData.style.borderLeft="1px groove #505050";			
			oData.style.fontWeight="bold";
			oData.style.textAlign="center";
			oData.style.width = '67px';
			oData.className = 'style4';
			oRow1.appendChild(oData);			
			}			
		    {
			oData=document.createElement("td");
			oData.innerHTML=(x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue);
			oData.style.borderTop="1px groove #505050";
			oData.style.borderRight="1px solid #a8a8a8";
			oData.style.borderBottom="1px solid #b8b8b8";
			oData.style.borderLeft="1px groove #505050";
			oData.style.fontWeight="bold";
			oData.style.textAlign="left";			
			oData.style.width = '399px';
			oData.className = 'style4';
			oRow1.appendChild(oData);
			}		 
			{
			oData=document.createElement("td");
			oData.innerHTML=(x[i].getElementsByTagName("artist")[0].childNodes[0].nodeValue);
			oData.style.borderTop="1px groove #505050";
			oData.style.borderRight="1px solid #a8a8a8";
			oData.style.borderBottom="1px solid #b8b8b8";
			oData.style.borderLeft="1px groove #505050";
			oData.style.fontWeight="bold";
			oData.style.textAlign="left";			
			oData.style.width = '163px';
			oData.className = 'style4';
			oRow1.appendChild(oData);
			}			
			{
			oData=document.createElement("td");
			oData.innerHTML=(x[i].getElementsByTagName("key")[0].childNodes[0].nodeValue);
			oData.style.borderTop="1px groove #505050";
			oData.style.borderRight="1px solid #a8a8a8";
			oData.style.borderBottom="1px solid #b8b8b8";
			oData.style.borderLeft="1px groove #505050";
			oData.style.fontWeight="bold";
			oData.style.textAlign="center";
			oData.style.width = '29px';
			oData.className = 'style4';
			oRow1.appendChild(oData);
			}
			{
			oData=document.createElement("td");
			oData.innerHTML=(x[i].getElementsByTagName("buy")[0].childNodes[0].nodeValue);
			oData.style.borderTop="1px groove #505050";
			oData.style.borderRight="1px solid #a8a8a8";
			oData.style.borderBottom="1px solid #b8b8b8";
			oData.style.borderLeft="1px groove #505050";
			oData.style.width = '121px';
			oData.className = 'style4';
			oRow1.appendChild(oData);
			}
		    {
			oData=document.createElement("td");
			oData.innerHTML=(x[i].getElementsByTagName("view")[0].childNodes[0].nodeValue);
			oData.style.borderTop="1px groove #505050";
			oData.style.borderRight="1px solid #a8a8a8";
			oData.style.borderBottom="1px solid #b8b8b8";
			oData.style.borderLeft="1px groove #505050";
			oData.style.width = '107px';
			oData.className = 'style4';
			oRow1.appendChild(oData);
			}
			          }								
                            }                 
            document.getElementById("myTablesong").appendChild(oTable);

			                         }
			
                    }			       
                }
		 if (flag==false)//Fail Message Code      	
	                  {
                      loadXMLDoc("Text.txt",function()
                              {  
                      if (xmlhttp.readyState==4 && xmlhttp.status==200)
                                 {
				      //alert (flag);
			
                      document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
					  
                                 }	
                              });                      
                      }		  	  
             }
         }); 
      } 
   }                              		         	    
}





