﻿function loadXMLDoc(dname)
{
var xmlDoc;
// code for IE
if (window.ActiveXObject)
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
xmlDoc=document.implementation.createDocument("","",null);
}
else
{
alert('Your browser cannot handle this script');
}
xmlDoc.async=false;
xmlDoc.load(dname);
return(xmlDoc);
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}

function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

String.prototype.objtrim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.objltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.objrtrim = function() {
	return this.replace(/\s+$/,"");
}


function SearchArtist(LookupValue) {
   Searchstr=LookupValue;
   
   
   OpenWindow=window.open("", "OpenWindow","fullWindow=yes,location=false,toolbar=yes,resizable=yes,scrollbars=yes,menubar=yes");
   
   OpenWindow.document.write("<script type=\"text/javascript\" src=\"../scripts/loadxmldoc.js\"></script>\n");
   
   OpenWindow.document.write("<title>Robert Naylor's Artist List</title>\n");
   OpenWindow.document.write("<center><b>Robert Naylor's Artist List</b></center>\n");


   xmlDoc=loadXMLDoc("artist.php");
   
   var x=xmlDoc.getElementsByTagName('author');
  
   var count=0;
   var print_artist="";
   OpenWindow.document.write("<b>Artist</b>");
   OpenWindow.document.write("<hr />");

   for (i=0;i<x.length;i++)
     {
       var str=x[i].childNodes[0].nodeValue.toUpperCase();

       if (str.indexOf(Searchstr.toUpperCase()) >= 0)
         {
           var record_artist=x[i].childNodes[0].nodeValue;
           if (print_artist != record_artist){   
                     
            		  OpenWindow.document.write("&nbsp;&nbsp;&nbsp;","<a href=\"#\" name=\"",record_artist.objtrim(),"\" onclick=\"javascript:SearchXML(\'",record_artist.objtrim().replace(/'/,"\\'"),"\')\">");
                      OpenWindow.document.write(trim(record_artist.italics()),"</a>");
                      OpenWindow.document.write("<br />\n");
                      
                      print_artist=record_artist;
                      count++;
               }
          }
      }
      OpenWindow.document.write("<br /><b>"+"Total Records: "+count+"</b>");
      OpenWindow.document.close();
      self.name="main";
return(count); 
}

function SearchXML(SearchParm) {
   Searchstr=SearchParm;
   
   SearchWindow=window.open("", "SearchWindow","fullWindow=yes,location=false,toolbar=yes,resizable=yes,scrollbars=yes,menubar=yes");
   SearchWindow.document.write("<title>Robert Naylor's Playlist Search Results</title>");
   SearchWindow.document.write("<center><b>Robert Naylor's Playlist Search Results</b></center>");

   xmlDoc=loadXMLDoc("fullplaylist.php");

   var x=xmlDoc.getElementsByTagName('location');
   var count=0;
   var print_category="";
   
   for (i=0;i<x.length;i++)
     {
       var str=x[i].childNodes[0].nodeValue.toUpperCase();

       if (str.indexOf(Searchstr.toUpperCase()) >= 0)
         {
           var full_location=x[i].childNodes[0].nodeValue;
           var short_location=x[i].childNodes[0].nodeValue.slice(13);
           var category=short_location.substr(0,short_location.lastIndexOf("/")).toUpperCase()+":";
           var display_title=short_location.substr(short_location.lastIndexOf("/")+1).replace(".mp3","");
           
           if (print_category != category){
                      SearchWindow.document.write("<br />",category.replace("_"," ").bold());
                      SearchWindow.document.write("<hr />");
                      print_category=category;
           }

			SearchWindow.document.write("&nbsp;&nbsp;&nbsp;","<a href=","\"http://www.rbnaylor.com",full_location,"\">");
            SearchWindow.document.write(display_title.italics(),"</a>");

            SearchWindow.document.write("<br />");
            count++;
          }
      }
      SearchWindow.document.write("<br /><b>"+"Total Records: "+count+"</b>");
      SearchWindow.document.close();
      self.name="main";
return(count); 

}

