
var progressInterval;
var listEntriesArray;
var selectedLetter;
var selectedList="";
var selectedDance="";
var selectedSearch;
var selectedType="";
var searchTitle="";
var totalEntries;
var currentSong = new Object();;
var isPlaylist = false;
var pageObjectsArray = new Array();


function initBallroomLibraryPage( ){

     
     
    
 	
      jQuery( document ).ready( function(){
      
      
           checkLoginCookie();
         
            
          printSearchTabs();
          jQuery("#tabs").tabs();
          jQuery("#tabs").css( {"background":"#ffffff",
                                "border":"1px solid #cccccc",
                                "width":"400px",
                                "height":"150px",
                                "margin":"20px"                              
                                                            }  );
                                                            
       jQuery("#players").children().remove();                                                     
                                                     
       jQuery( "#players" ).append( printPlayers() );
       jQuery( "#playerWidget").draggable();
       jQuery( "#playerWidget").css( {
                                      "position":"absolute",
                                      "top":"200px",
                                      "left":"100px",
                                      "border":"1px solid #999999",
                                      "background":"#86C8F2",
                                      "z-index":"5000",
                                      "opacity":"1",
                                      "height":"40px",
                                      "width":"800px" } );
       hideListPlayer();
            
       
       jQuery("#resultsHeader").append( printResultsHeader() );
       jQuery('#results').hide();
       jQuery("#resultsHeader input[name='searchStatus']").val( 'selected search' );
       jQuery('#dialog').hide();
       jQuery('#albumInfo' ).hide();
      
      
      
      
       jQuery("#playerWidget button[name='play']" ).click( function(){  var listName = getSelectedList();
       
                                           
     	             jQuery("#playerWidget input[name='playerStatus']").val("loading list:"+ listName );
     	             loadListEntries( listName);   } );
     	 	           
       jQuery("#playerWidget button[name='play']").hover( function(){ jQuery(this).addClass("ui-state-hover") },
     	 		       function(){ jQuery(this).removeClass("ui-state-hover") } );
     	 		
     	 		
     	jQuery("#playerWidget button[name='pause']" ).click( function(){ pauseSong() } );
     	jQuery("#playerWidget button[name='pause']" ).hover( function(){ jQuery(this).addClass("ui-state-hover") },
     	  function(){ jQuery(this).removeClass("ui-state-hover") } );
     	 
     	 
     	jQuery("#playerWidget button[name='stop']" ).click( function(){ stopList()  } );	
     	jQuery("#playerWidget button[name='stop']" ).hover( function(){ jQuery(this).addClass("ui-state-hover") },
     	 function(){ jQuery(this).removeClass("ui-state-hover") } );
     	 	               	
	                	
       	 jQuery("#go").click( function(){
		       	   	   
		 		           	  
		  var newPage = jQuery("#resultsHeader select").val();
		       	             
		       	            		       	             
	   if( getSelectedSearch() == "catalogByDance"){ 
		       	             
		findSongByDance( newPage );
		       	             	
           }//end if
           else if( getSelectedSearch() == "songsByTitle" ){
		       	             
		       	                  
		    findSongsByTitle( newPage );
		                             
	   }
	    else if( getSelectedSearch() == "albumsByTitle" ){
		    		
    	
		    	
		    findAlbumsByTitle( newPage );
		    		       	             
		       	             
	   }//end if
	   else if( getSelectedSearch() == "performersByLetter" ){
	     		    		
	         	
	     		    	
	     	    findPerformersByLetter( newPage );
	     	    		           		        
	     }//function
	     
	    else if( getSelectedSearch() =="internetAlbum" ||
	   		                       getSelectedSearch() =="internetTrack" ||
	   		                       getSelectedSearch() =="internetArtist"    )	{
	   		              
	   		              
	   		                     gracenoteQuery( newPage );
	   		                     
	   		                     
	   		                     
	     }//end else if
	             		       	                        
		       	        
		       	        }//function
		       	        
		       	                   );//end click
		       	                   
		       	                   
		       	                   
		       	                   
	jQuery("#go" ).hover( function(){ jQuery(this).addClass("ui-state-hover") },
     	 		      function(){ jQuery(this).removeClass("ui-state-hover") } );
     	 	           	       	                   
	jQuery("#closeButton").click( function(){
		       	   	   
		           	    
		       	             jQuery("#resultsHeader select").children().remove();
		       	             jQuery("#resultsHeader select").append("<option>filter</option>");
		       	             jQuery("#results").children().remove();
		       	             jQuery("#results").hide();
		       	             jQuery("#album").children().remove();
		       	             jQuery("#albumTracks").remove();
		       	             jQuery("#albumInfo").hide();
		       	             jQuery("#tabs").toggle('down');
		       	             jQuery("#tabs").fadeTo('slow',1);
		       	             
		       	        }//function
		       	        
		       	                   );//end click
		       	                   
		       	                   
		       	                   
		       	                   
	jQuery("#closeButton" ).hover( function(){ jQuery(this).addClass("ui-state-hover") },
     	 		               function(){ jQuery(this).removeClass("ui-state-hover") }  );
     	 	           	       	               	                   
		       	                   
		       	                   
	                     
       
        jQuery("#closeAlbumButton").click( function(){
                                                          hideListPlayer();
                                                          jQuery("#album").children().remove();
		       	                                  jQuery("#albumTracks").children().remove();
		       	                                  jQuery("#albumInfo").fadeTo("slow",0 );
		       	                                  jQuery("#albumInfo").hide();
		       	                                  jQuery("#results").show();
                                                          jQuery("#results").fadeTo("slow",1);
                                                          
                                                          
                                                          } ); //end click
         
        
        
        
        jQuery("#closeAlbumButton" ).hover( function(){ jQuery(this).addClass("ui-state-hover") },
	     	 		            function(){ jQuery(this).removeClass("ui-state-hover") }  );
	     	 	           	       	               	                   
	
	
      
       
    
                           } );//document ready
      
      

}//end init page


 
 function printPlayers(){
 
 
 
     var pageHTML =     "<script language=\"VBS\">\n"+
		        "Sub player_OnShowStatus(byVal text)"+
		          "call showPlayerStatus()"+
		         "End Sub"+
           	     "</script>"+
                     "<div id=\"listPlayer\" >"+
           		   	printListPlayer()+
           	     "</div>"+
                     
           	      "<div id=\"realPlayer\">"+   
 		        printRealPlayer();
                       "</div>";
 
 
       return pageHTML;
 
 
 }

 		    
 function printSearchTabs(){
 	
 	
 	
 	resHTML = 
        //create layer
       
	"<ul class=\"ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all\">" +
	"<li><a href=\"#tab1\">performers</a></li>"+
	"<li><a href=\"#tab2\">genres</a></li>"+
	"<li><a href=\"#tab3\">publishers</a></li>"+
	"</ul>"+
	"<div id=\"tab1\">"+ //tab1   	
	"<div id=\"performers\">"+ 
	"<div id=\"selectLetter\">"+
	"<label>Last Name</label>" +    
    	//select
    	  "<select>" +
    	                 getAlphabetOptions()+
    	   "</select>" +
	   "<button class=\"ui-widget ui-state-default\" value=\"submit\">submit</button>"+
		"</div>" + //end tab1
	       "<div id=\"tab2\">"+               
	           "<div id=\"genres\"></div>"+
	       "</div>"+ //end tab2
	       "<div id=\"tab3\">"+ //end tab3
	       "<div id=\"publishers\"></div>" +
	       "</div> "; //end tab3
	  
	      
	   jQuery("#tabs").append( resHTML );
	   jQuery("#selectStyle").children("select").change( 
	          		
	          function(){ 
	          		
	          	
	          	 var style = jQuery("#selectStyle option:selected").val();
	          	 var dances = getDances( style );
	          
	                 
	                  jQuery("#selectDance select").children().remove();
	          	  for( var i=0; i<dances.length; i++){
	          	
	          		jQuery("#selectDance select").append( "<option value=\""+ dances[i]+"\">"+dances[i]+"</option>" );  		         
	          	                		 
	          	  }//for
	          	  
	          	  
	                       
	          		  	}//function
	          	                                  
	                                       ); //change
	                
	          	
	          	
	  jQuery( "#selectDance button" ).click( 
	          	
	          		function(){
	          		
	          		       
	          		        initProgressDialog("Searching");
	          	                setSelectedSearch( "catalogByDance");
	          	                setSelectedDance( jQuery( "#selectDance select").val() );
	          	                jQuery("#tabs").toggle("up");
	          	                
	          	                findSongByDance( 1 );
	          	                
	           	        return true;// false;
	          	
	          	
	          	
	          		}//end function
	          	
	          	
	          	);//end click
	          	                             
	          	
	  jQuery( "#selectDance button" ).hover( function(){   jQuery(this).addClass   (  "ui-state-hover"  ) },
	          	 	                 function(){   jQuery(this).removeClass(  "ui-state-hover"  ) } );
	          	 	  	  
	          	 		
	     	
	  //************************Search By Performer *******************************************************	
	          	
	          	      	
	  jQuery( "#selectLetter button" ).hover( function(){   jQuery(this).addClass ("ui-state-hover") },
	   	        	                  function(){   jQuery(this).removeClass("ui-state-hover") } );
	   	        	  	  
	   	       	 		
	   	       		
	          	
	  jQuery( "#selectLetter button" ).click( 
	   	       
	   	       	 function(){
	   	       
	   	                     setSelectedSearch( "performersByLetter");
	   	       		     setSelectedLetter( jQuery("#selectLetter select").val() );
	   	       		     findPerformersByLetter( 1 );
	   	       		
	   	       		 	               
	   	       
	   	       
	   	       
	   	       	}//end function
	   	       
	   	       
	   	       );//end click
	   	                                    
	   	       
	
	}//end function
	
	
	
	function printResultsHeader(){
	
	var resHTML = 
	"<div id=\"ie\"></div>"+
 	"<div id=\"resultsHeader\" class=\"ui-widget ui-widget-header ui-corner-top\" >"+ //header
 	
 	"<div id=\"resultTop\" class=\"ui-widget ui-widget-header ui-widget-content\">"+ //resultsTop 
 	
 	"<span>Results</span>"+
 	"<button id=\"closeButton\" style=\"margin-left:10px\" class=\"ui-widget ui-state-default\">close</button>"+
 	"<span style=\"margin-left:10px\">"+
 	"      Selected search<input type    =\"text\" class=\"ui-widget ui-corner-all\" "+
 		 	                                  "name   =\"searchStatus\" "+
 		 	                                  "value   =\"selected search\" "+
 		 	                                  "style   =\"margin-left:20px;background:#292929; color:orange\"/>"+
 	"</span>"+
 	"<span>&nbsp; page &nbsp;"+
 	"<select>"+
 	"<option value=\"filter\">filter</option>"+
 	"</select>"+
 	"<button id=\"go\" class=\"ui-widget ui-state-default ui-corner-all\">go</button>"+
 	"</span>"+
 	
        "</div>"+//result top
 		 
 	 "</div>"+ //end resulHeader
 	
 	"<div id=\"albumInfo\" style=\"margin-left:30px; width:900px; height:700px\">"+ //albumInfo
 	"<button id=\"closeAlbumButton\" style=\"margin-left:10px\" class=\"ui-widget ui-state-default\">close album</button>"+
 		"<div id=\"album\" style=\"position:relative;float:left; width:420px; height:700px\"></div>"+
 		"<div id=\"albumTracks\" style=\"float:left; position:relative;width:400px;height:450px\"></div>"+
 	"</div>";  //end albumINfo
 	
  	
 	
 	
 	
 	return resHTML;
 	
 }//end function
 
 

  function initInputDialog( dialogTitle , textFieldLabel, type){ 
  
         
         
        jQuery("#dialog").children().remove(); 
        jQuery("#dialog").append( printInputDialog( "Enter name" ) );
	jQuery("#dialog").dialog({  "title": dialogTitle,
	                            "modal": true     });//end dialog()
	                                      	
        jQuery("#dialog").dialog('open');

       jQuery("#listNameForm button" ).hover( function(){ jQuery(this).addClass("ui-state-hover") },
                                       function(){ jQuery(this).removeClass("ui-state-hover") } );
                                       
       jQuery("#listNameForm button").click( function(){

	
	
	if( type=="create"){
		    
	   listName = jQuery("#listNameForm input[name='listName']").val();
	   
	   jQuery('#dialog').dialog('close');
	   createList( listName);
	   
	   
		   
		   
	}//end if
	    
	else if( type=="rename"){
	
	  listName =  jQuery('#adminList option:selected').val();
	  var newName = jQuery("#listNameForm input[name='listName']").val();
	  jQuery('#dialog').dialog('close');
	  renameList( listName , newName );
	  
	  
	
	}//end else if*/
	
	
   		 } //end functio
    
    
    	);//end click
    	
		
	}//end init dialog
	
	
	

	function printInputDialog( textFieldLabel ){
	
	 var resHTML=  "<div style=\"width:200px; height:150px\" class=\"ui-widget-content ui-dialog-content\">"+
	                 "<div id=\"dialogOutput\"></div>"+
         "<div id=\"listNameForm\">"+
	textFieldLabel+"<input value=\"text input\" name=\"listName\"><br>"+
         "<button class=\"ui-state-default ui-corner-all\" value=\"create\" >submit</button>"+
         "</div>"+
          "</div><!-- End sample page content -->";


	
	
		return resHTML;
	
	
	
	
	}
	



	function initYesNoDialog( message ){


     
	 jQuery("#dialog").css({"zIndex":"150"});
	 jQuery("#dialog").dialog({ "title": "Confirmation Required",
	                            "modal":true,
	                            "open":function( event,ui){
	                                      	   
	                                      	   
	                                           jQuery("#tabs").fadeTo("slow",0.3  );
	                                         
	                                      	                           	
	                                      	                           		},
	                            "close":function(event,uil){
	                                                   
	                                      	                                  jQuery(this).dialog('destroy');
	                                      	                                  jQuery("#tabs").fadeTo("slow",1 );
	                                      	                                  
	                                      	                                },//end close
	                                      	                           
	                                      	                          
	                              buttons : { "Yes" : function() {              

                                                                
	         jQuery("#tabs").fadeTo("slow",0.3  );
	 
	          deleteList( listName);
	          jQuery(this).dialog('destroy');

                                                                },
                                                     
                                                   "Cancel" : function() {

                                                                   jQuery('#dialog').dialog('destroy');
                                                                   jQuery('#tabs' ).show();
	           jQuery("#tabs").fadeTo("slow",1);
                                                                 }
                                                                 
                                                      }//buttons
                                                                 

                                                     } );//dialog            	



	}//end init dialog
	
	
	

	function printYesNoDialog( message ){
	
	
	 var resHTML=  "<div style=\"width:200px; height:150px\" class=\"ui-widget ui-widget-content ui-dialog-content\">"+
	               "<div style=\"color:white\">"+message+"</div>"+
	               "</div><!-- End sample page content -->";


	
	
		return resHTML;
	
	
	
	
	}
	




     function initConfirmDialog( message ){


     
	  jQuery("#dialog").append( printConfirmDialog( message ) );
	  jQuery("#dialog").dialog({ "title": "Confirmation",
	 	                     "modal":true,
	 	                      buttons : { "Ok" : function() {  jQuery(this).dialog('close');    } }//en dbuttons
	                                                   
	                                             } );//dialog 
	  jQuery("#dialog").dialog('open');                                           
	 
	 


	}//end init dialog
	
	
	

	function printConfirmDialog( message ){
	
	 jQuery("#dialog").children().remove();
	 var resHTML=  "<div class=\"ui-widget ui-widget-content ui-dialog-content\">"+
	                "<div >"+message+"</div>"+
	                "</div>";


	
	
		return resHTML;
	
	
	
	
	}
	
	
	
	
	
	
	
	
	

        function initListPlayer( isPlaylist ){
        
         this.isPlaylist = isPlaylist;
       
         setListPlayer();
         
         jQuery("#playerWidget").animate({top:"500px"},500 );
         jQuery("#playerWidget").animate({top:"300px"},1000 );
         jQuery("#playerWidget").animate({top:"550px"},1000 );
         jQuery("#playerWidget").animate({top:"300px"},1000 );
  	
	        	
       	
         
        
        }


         function hideListPlayer(){
         
         	jQuery("#playerWidget").animate({top:"400px"},300 );
         	jQuery("#playerWidget").animate({top:"-650px" },2000 );
         	
         	
         	
         
         }
         
         
         
         function printListPlayer(){
	  
	  
	  var resHTML =  "<div  id=\"playerWidget\" class=\"ui-widget-content ui-draggable ui-corner-all\" >"+ //header
	  	                        "<span>      "+
	  	                             "playlist<input type    =\"text\" "+
	 	     "               class   =\"ui-widget ui-corner-all\" "+
	 	     "               name   =\"playlistField\" "+
	              "               value   =\"no name\" "+
	 	     "               style   =\"font-size:10pt;width:80px; margin-left:20px; background:#000000; color:blue\"/>"+
	           "</span>"+
	           "<span style=\"margin-left:20px\">"+
	 	     "entry#<input type    =\"text\" "+
	 	     "               class  =\"ui-widget ui-corner-all\" "+
	 	     "               name   =\"playlistEntryField\" "+
	 	      "               value   =\" \" "+
	 	      "               style   =\"font-size:10pt;width:40px; margin-left:20px; background:#000000; color:green\"/>"+
	             "</span>"+
	              "<button name=\"play\" style=\"margin:3px\" class=\"ui-state-default ui-corner-all\">"+
	              "<span  class=\"ui-icon ui-icon-play\"></span>"+
	               "</button>"+
	               "<button name=\"pause\" style=\"margin:3px\" class=\"ui-state-default ui-corner-all\">"+
	 	                            "<span class=\"ui-icon ui-icon-pause\"></span>"+
	 	                              "</button>"+
	 	                              "<button name=\"stop\" style=\"margin:3px\" class=\"ui-state-default ui-corner-all\">"+
	 	                            "<span id=\"close\"  class=\"ui-icon ui-icon-stop\"></span>"+
	 	                              "</button>"+
	 	
	 	
	              "<span style=\"margin-left:10px\">"+
	               "player status<input type    =\"text\" "+
	               "                    class   =\"ui-widget ui-corner-all\" "+
	               "                    name   =\"playerStatus\" "+
	                                   "value   =\"\" "+
	                                   "style   =\"width:200px;font-size:10pt; margin-left:20px; background:#000000; color:orange\"/>"+
	              "</span>"+
	               //"<span>"+ filter + "&nbsp;"+
	 		                   
	 	              "</div>";
	  
	  
	  	return resHTML;
	  
	  
	  
	  
        }//end print listPlayer
         
         
        
        
        
  function printAlbum( iconUrl, albumID, albumName,amazonURL, itunesURL  ){
	
	
	 jQuery("#results").fadeTo("slow",0.4 );	
	 var resHTML = " <div style=\"width:400px\" height:600px; class=\"ui-widget ui-widget-header ui-corner-top\">Album Info</div>"+//header
	                "<div style=\"float:left; width:400px; height:200px\" class=\"ui-widget-content\">"+//widget
	                
	                "<div style=\"float:left; width:200px; height:200px; background:#000000\" class=\"ui-widget-content\">"+ //album image 
	                "<img src=\"" + iconUrl + "\"  alt=\""+albumName+"\"  width=\"150\">"+
	                "</div>"+                     //album image
	            
	                "<div style=\"float:left; width:190px; height:200px\" class=\"ui-widget-content\">"+ //controlls
	                
	                "<div id=\"playTracks\" style=\"width:150px; height:50px; margin:10px; font-size:10pt\"   "+ 
	                "                       class=\"ui-widget ui-widget-content ui-corner-all\">"+//play tracks
	          
	                 "&nbsp;play tracks:<br>"+
	                 "&nbsp;<button style=\"width:50px\" class=\"ui-state-default ui-corner-all\">"+
	                 "<img src=\"/wordpress/wp-content/uploads/2010/03/speakerIcon.jpg\" height=\"15\"></button>"+
	                 "</div>";   //play tracs end
	            
	            if( amazonURL != "NA"){
	            
	              	resHTML+= "<div id=\"amazon\" style=\"margin:10px;width:150px;height:50px;font-size:10pt\" class=\"ui-widget ui-widget-content\" >"+//amazon
	            		  "Order from Amazon:<br>"+
	            		  "&nbsp;"+
	            		  "<button style=\"width:100px\" class=\"ui-state-default ui-corner-all\">"+
	            		  "<img class=\"ui-state-default ui-corner-all\" src=\"http://www.ballroomradio.com/albums/AMAZON/icon/icon.jpg\" height=\"20\">"+
	            		  "</button>"+
	            		  "</a>"+
	                           "</div>"; //amazon end
	            }//end if
	            if( itunesURL != "NA" ){
	            
	                 resHTML += "<div id=\"itunes\" style=\"margin:10px;width:150px;height:50px;font-size:10pt\" class=\"ui-widget ui-widget-content\" >"+ //itunes
	            	           "Order from iTunes:<br>"+
	            		   "&nbsp;"+
	            		   "<button style=\"width:100px\" class=\"ui-state-default ui-corner-all\" >"+
	            	           "<img src=\"http://www.ballroomradio.com/albums/ITUNES/icon/icon.jpg\" height=\"20\">"+
	            	           "</button>"+
	            	           "</div>";  //itunes end
	            	
	            }// end if
	            
	            resHTML+=	"</div>"+
	                        "</div>";  ;//+ //controlls end
	                       
	            
	                       
	 
	   	   return resHTML;
	 
	 
	
	 
	 }
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 function initAlbum( iconUrl, albumID, albumName,amazonURL, itunesURL){
	 
	           
	    	        
	                                                                                                   
	                                                                                                   
	        jQuery("#playTracks button").click( function(){
	        
	                                       
	 
	                            playTracks(  albumID );
	                                                  
	                    } ); //end click
	                                                  
	                                                  
	                                                  
	                                                  
	          jQuery("#playTracks button").hover( function(){  jQuery(this).addClass("ui-state-hover");      },
		                                      function(){  jQuery(this).removeClass("ui-state-hover");     }
	           
	        
	                                                                      );//end hover
	                                                  
	                                                  
	                                                  
	        jQuery("#itunes button").click( function(){
		                                                 goITunes( itunesURL );
		                                                  
	                                                  } ); //end click
	        
	        
	        
	        jQuery("#amazon button").click( function(){
		                                                 goAmazon( amazonURL );
		                                                  
	                                                  } ); //end click*/
	        
	        
	        jQuery("#album button").hover( function(){  jQuery(this).addClass("ui-state-hover");      },
		       
		                              function(){  jQuery(this).removeClass("ui-state-hover");     }
	           
	        
	                                                                      );//end hover
	        
	        
	
	        
	       
    } //end activateAlbum
	         
	
        
        
   function printGracenoteAlbum( albumName, albumUrl, iconUrl,  albumPerformer, amazonUrl, itunesUrl  ){
		
		
		
		                
		                
		var resHTML = " <div style=\"width:400px\" height:600px; class=\"ui-widget ui-widget-header ui-corner-top\">Album Info</div>"+//header
		                "<div style=\"float:left; width:400px; height:200px\" class=\"ui-widget-content\">"+//widget
		                
		                "<div style=\"float:left; width:200px; height:200px; background:#000000\" class=\"ui-widget-content\">"+ //album image 
		                "<img src=\"http://www.gracenote.com"+iconUrl + "\"  alt=\""+albumName+"\"  width=\"150\">"+
		                "</div>"+                     //album image
		            
		                "<div style=\"float:left; width:190px; height:200px\" class=\"ui-widget-content\">"+ //controlls
		                
		                "<div id=\"playTracks\" style=\"width:150px; height:50px; margin:10px; font-size:10pt\"   "+ 
		                "                       class=\"ui-widget ui-widget-content ui-corner-all\">"+//play tracks
		          
		                 "&nbsp;play tracks:<br>"+
		                 "&nbsp;<button style=\"width:50px\" class=\"ui-state-default ui-corner-all\">"+
		                 "<img src=\"/images/assets/speakerIcon.jpg\" height=\"15\"></button>"+
		                 "</div>";   //play tracs end
		            
		            if( amazonUrl != "NA"){
		            
		              	resHTML+= "<div id=\"amazon\" style=\"margin:10px;width:150px;height:50px;font-size:10pt\" class=\"ui-widget ui-widget-content\" >"+//amazon
		            		  "Order from Amazon:<br>"+
		            		  "&nbsp;"+
		            		  "<button style=\"width:100px\" class=\"ui-state-default ui-corner-all\">"+
		            		  "<img class=\"ui-state-default ui-corner-all\" src=\"http://www.ballroomradio.com/albums/AMAZON/icon/icon.jpg\" height=\"20\">"+
		            		  "</button>"+
		            		  "</a>"+
		                           "</div>"; //amazon end
		            }//end if
		            if( itunesUrl != "NA" ){
		            
		                 resHTML += "<div id=\"itunes\" style=\"margin:10px;width:150px;height:50px;font-size:10pt\" class=\"ui-widget ui-widget-content\" >"+ //itunes
		            	           "Order from iTunes:<br>"+
		            		   "&nbsp;"+
		            		   "<button style=\"width:100px\" class=\"ui-state-default ui-corner-all\" >"+
		            	           "<img src=\"http://www.ballroomradio.com/albums/ITUNES/icon/icon.jpg\" height=\"20\">"+
		            	           "</button>"+
		            	           "</div>";  //itunes end
		            	
		            }// end if
		            
		            resHTML+=	"</div>"+ //controlls end
		                        "<div style=\"width:400px; height:400px\">"+ //google add
		                         "<iframe src=\"/googleAdds336x280.html\" "+
		  	"        scrolling=\"no\" "+
		  	"       FRAMEBORDER=\"0\" "+
		  	"style=\"height:400px; width:350px; "+
		  	 "border: 1px solid #292929\">"+
		 "</iframe>"+
                 "</div>"+ //google add end
		            
		            
		            
		            
		            
		            
		            
		                        "</div>"; //widget end
		                        
		                       
		                       
		 
		   	   return resHTML;
		 
		          
		 
		 }//end print gracenote
		 
	 
        
        
        
         function initGracenoteAlbum( itunesURL, amazonURL  ){
         
         
         
         
         	                                                                                             
		jQuery("#playTracks button").click( function(){
        
                                            
 
//  viewGracenoteTracks(userName, subscription, albumID );
                                                  
		  } ); //end click
		                                           
		 jQuery("#playTracks button").hover( function(){  jQuery(this).addClass("ui-state-hover");      },
		                                     function(){  jQuery(this).removeClass("ui-state-hover");     }
           
        
	);//end hover
                                                  
                                                  
                                                  
		jQuery("#itunes button").click( function(){
	                                                 goITunes( itunesURL );
	                                                  
                                                  } ); //end click
        
        
        
		 jQuery("#amazon button").click( function(){
	                                                 goAmazon( amazonURL );
	                                                  
                                                  } ); //end click*/
        
        
		 jQuery("#album button").hover( function(){  jQuery(this).addClass("ui-state-hover");      },
	       
	                function(){  jQuery(this).removeClass("ui-state-hover");     }
           
        
                                                                      );//end hover
	        
         
         
         
         
         
         
         
         
         }//ed initGracenote
        
        
        
        
         function parseGracenoteAlbum( htmlText ){
         
         
       
           var albumObject;
           var tracksArray = new Array();
           var itunesUrl ="";
           var amazonUrl ="";
           
             var dataArray = htmlText.split("<div>");
            
             for( var i = 1; i < dataArray.length; i++ ){
             
             	if( dataArray[i].indexOf( "Track:" ) !=-1 ){
             	
             	  tracksArray.push( dataArray[i].split("</div>")[0] );
                 
             
                 }//end if
                 if( dataArray[i].indexOf( "itunes" ) != -1 ){
                 
                 
                    itunesUrl = dataArray[i];
                    if( itunesUrl.indexOf("href=\"\"") != -1 ){
                    
                    
                        itunesUrl="NA";
                        
                     }//end if
                     else{
                     
                        itunesUrl = itunesUrl.split( "<a href=\"")[1].split(" target=\"_blank\"" )[0];
                     
                     }//else
                   
                 }//end if
                 if( dataArray[i].indexOf( "amazon" ) != -1 ){
		                  
		                  
		    amazonUrl = dataArray[i];
		    if( amazonUrl.indexOf("href=\"\"") != -1 ){
		                        
		                        
		         amazonUrl ="NA";
		                            
                     }//end if
                     else{
                     
                     
                         amazonUrl = amazonUrl.split( "<a href=\"")[1].split(" target=\"_blank\"" )[0];
		    }//else
             
             
                 }//end if
                 
                 
                }//end for
         
          
              albumObject = { itunesUrl:itunesUrl, amazonUrl:amazonUrl }; 
         
           return albumObject;
         
         }
        
        
        
        
        
        
         
	
	function initProgressDialog( message ){ 
	
	
	    if( !message){ 
	    
	            message = "Loading data, please wait...";
	            
	     }
	     
	     jQuery("#dialog").children().remove();
	
	     jQuery("#dialog").append("<p>"+message+"...</p>"+
	                              "<p><img src=\"http://www.ballroomlibrary.com/wordpress/wp-content/uploads/2010/03/loadingImg.gif\"/></p>" );
	     jQuery("#dialog").dialog({title:'Progress Status',
	                               modal:true} );
	     jQuery("#dialog").dialog('open');
		 	  
		   
		   
	
	}//end init ProgressDialog


	function hideProgressDialog(){
	
	        jQuery("#dialog").dialog('close');
	     
	  	        
	      
	
	}
		
	



//**********************************************************************************************

     

function downloadSong( amazonUrl, itunesUrl, songTitle ){
 
   
       if( itunesUrl != "NA" ){
       
       
           
               goITunes( itunesUrl );
               
               
        }
        else{
        
        
            if( amazonUrl != "NA" ){
            
            
               goAmazon( amazonUrl );
               
               
             }
             else{
             
                 
                  // initConfirmDialog( "List Renamed To "+"\""+listName+"\"" );
                  var pageUrl="http://www.ballroomlibrary.com/radioinfoserver/SearchGraceNoteJSONServlet?type=album&query="+  songTitle;
                  
		   	  		jQuery.ajax({
		   	  		
		   	  		  type:"POST",
		   	  		  url: pageUrl,
		   	  		  cache: false,
		   	  		  async: false,
		   	  
		   	  		  success: function(html){
		   	  		  var albums = html.split("<album>");
	      		 	  	                          var resHTML = parseGracenoteQuery( albums, 1);  
		   	  		  if( html == "" ){
		   	  		  
		   	  		     alert( "Song is currently not available for download"  );
		  
		   	  		     
		   	  		   
		   	  		  }//end if
		   	  		  else{
		   	  		  
		   	  		     newWindow.document.write( html);
		   	  		  
		   	  		  }//end else
		   	  		  
		   	  		  
		   	  		  }//end function
		   	  		  
		   	  		});//end ajax
 	  		
             
             }//end else
      }//else

}


function downloadFavorite(userName, subscription, songId, albumID, publisher ){
   
             
       
       	 pageUrl = "/radioinfoserver/DownloadAppletServlet?userName="+userName+"&subscription="+ subscription+"&songID="+songId+"&amount=0.99";        
         // callAjax( pageUrl);
          newWindow=window.open();
          newWindow.location= pageUrl ;
          
      
}




  function activateGracenote(){
       
       
       	
       	
       
       	
       jQuery("#gracenoteAccordion").accordion({ animated: 'bounceslide', autoheight:false} );
      
      
       	//***************Search by dance *************************************************************
       		
       		
       		
       	
       
       	
       	//************************Search By Title *******************************************************	
       		
       		
       		jQuery( "#gracenoteTitleInput button" ).click( 
       
       	function(){
       
                       
       		var selectedType = jQuery("#gracenoteSelectType select").val();
       		var query = jQuery("#gracenoteTitleInput input").val();
       		setSearchTitle( query );
       		
       		if( selectedType=="internetAlbum" ){
       		
       		
       		   setSelectedSearch( "internetAlbum" );
       		   
       		   
       		}
       		else if( selectedType == "internetTrack" ){
       		
       		   setSelectedSearch( "internetTrack" );
       		   
       		   
       		 }
       		 else if( selectedType == "internetArtist" ){
       		
       		   setSelectedSearch( "internetArtist" );
       		   
       		   
       		 } 
       		
                       gracenoteQuery(1);
       		
       		 	                return false;
       
       
       
       	}//end function
       
       
       );//end click
                                    
       
       		jQuery( "#gracenoteTitleInput button" ).hover( function(){   jQuery(this).addClass ("ui-state-hover")   },
        	  		               function(){   jQuery(this).removeClass("ui-state-hover") } );
        	  	  
       	 		
       		
       	
       	
       	
       	
       	
       	
       	
       	//************************Search By Performer *******************************************************	
       	
       	      	
       	jQuery( "#gracenoteSelectLetter button" ).hover( function(){   jQuery(this).addClass ("ui-state-hover") },
	        	  		 function(){   jQuery(this).removeClass("ui-state-hover") } );
	        	  	  
	       	 		
	       		
       	
       	jQuery( "#gracenoteSelectLetter button" ).click( 
	       
	       	function(){
	       
	                       setSelectedSearch( internetPerformer );
	       		setSelectedLetter(  jQuery("#gracenoteSelectLetter select").val() );
	       		findGracenotePerformersByLetter( getSelectedLetter() );
	       		
	       		 	                return false;
	       
	       
	       
	       	}//end function
	       
	       
	       );//end click
	                                    
	      
       		
       }//end activate Gracenote
       	
       	
       	
       	
       	
       	
       function printGracenote(){	
       	
       
       var resHTML =   "<h3 class=\"ui-accordion-header ui-helper-reset ui-corner-all\">"+
                       "<a style=\"font-size:10pt\" href=\"#\">Search By Title</a>"+
                       "</h3>"+
                      "<div class=\"ui-widget-content ui-accordion-content ui-helper-reset ui-corner-bottom\">"+          //content
                      "<div id=\"gracenoteSelectType\" >Search options:</br>"+   //select type
                       "  <select>"+
                       "  <option value=\"none\" >Search type</option>"+
                       "  <option value=\"internetArtist\">artist</option>" +
                       "  <option value=\"internetAlbum\">album</option>" +
                       "  <option value=\"internetTrack\">track</option>" +
                       "  </select>"+
                       "  </div>"+                                                  //select type end
                
                
                      "  <div id=\"gracenoteTitleInput\" >Name( Title) </br>"+
                      "  <input type=\"text\" width=\"120\" length=\"30\" name=\"gracenoteTitleField\"/>" +
       	  	      "  <button class=\"ui-widget ui-corner-all ui-state-default\" value=\"submit\">submit</button>"+
                      "  </div>"+     //input title end 
                      
                     "  </div>"+                                              //content end
               
              
                   "<h3 class=\"ui-accordion-header ui-helper-reset ui-corner-bottom\">"+
                   "<a style=\"font-size:10pt\" href=\"#\">Search By Performer</a>"+
                   "</h3>"+
                  "<div class=\"ui-widget-content ui-accordion-content ui-helper-reset ui-corner-bottom\">"+  //content
                   "<div id=\"gracenoteSelectLetter\">Performer Last Name</br>" +    //select
                   "<select name=\"startingLetter\">" +
                              getAlphabetOptions()+
       
                  "</select>" +
                  "<button class=\"ui-widget ui-state-default\" value=\"submit\">submit</button>"+
                  "</div>"+          //end select
              
              
                 " </div>";  //end content
       
            
       
              return resHTML;
       
       }//end printCatallog
       
       

    





function printGoogleAdd(){


 var resHTML  = "<div style=\"height:20px;background:#ff6633;width:850px\"></div>";
 
return resHTML;


}//google add





function printUserDetails(){


	var resHTML = "User Name: <font color=\"blue\">"+this.userName+"</font>" +
                     
                      " <font color=\"gray\"> Subscription:</font> <font color=\"green\">"+this.subscription+"</font>"+
                      " All Favorites: <font color=\"brown\">"+this.allFavoritesArray.length+ "</font>"+
                      " All Lists: <font color=\"brown\">"+this.allListsArray.length+" </font>"+
                      "<font color=\"gray\">Total Lists Allowed:"+"NA</font>" ;


	return resHTML;
}




//SETTERS//***********************************************************************************






function setFavoritesArraySelection( index, value ){

	favoritesArray[index].isSelected = value;


}


function setSelectedLetter( value ){



	this.selectedLetter = value;



}

function setFavoritesArray( favArray){

	this.allFavoritesArray = favArray;
	
}



function setTotalEntries( value){

	this.totalEntries = value;

}


function setSearchTitle( value ){



	this.searchTitle = value;


}




function setSelectedSearch( value ){

        
	this.selectedSearch = value;
        jQuery("#resultsHeader input[name='searchStatus']").val( value );
        jQuery("#playerWidget input[name='playerStatus']").val( value );


}



function setCurrentSong( title, url ){

    this.currentSong =  { songTitle: title, libraryUrl: url };
}


function setSelectedList( value ){

   this.selectedList = value;
   this.isPlaylist = true;
   jQuery("#playerWidget input[name='playlistField']").val( value );
   

}

function setSelectedDance(value){


	this.selectedDance = value;


}

function setSelectedTitle( value ){


	this.selectedTitle = value;

}


function setGoogleSearchKeyword( keyword ){


        jQuery("#googleSearchKeyword").children().remove();
	jQuery("#googleSearchKeyword").append("<a href=\"javascript:searchWord('"+keyword+"')\">"+keyword+"</a></span>");
        jQuery('#googleSearchKeyword a').css({"color":"green","margin-left":"10px","opacity":"0.8","font-family":"georgia","font-size":"10pt" });
	jQuery('#googleSearchKeyword a').hover( 
	       
	                                         function(){ 
	                                                     jQuery(this).css({ "opacity":"0.1"});
	                                                     jQuery(this).css({ "color":"green", "background":"#ffffcc"})
	                                                     jQuery(this).animate({ opacity:"1"},1000 ) 
	                                                     
	                                                     },
	       
	                                         function(){ 
	                                                     jQuery(this).css({ "opacity":"0.1"});
	                                                     jQuery(this).css({ "color":"green","background":"orange"})
	                                                     jQuery(this).animate({ opacity:"1"},1000 ); 
	                                                     
	                                                     }
	                                                     
	                                                     
	                                                     );//end hover
           






}//end google SearchKeywor




function setListPlayer(){


       
       
       
        if( getSelectedSearch()=="playRadio"){
        
          
          jQuery("#playerWidget input[name='playerStatus']").val( getSelectedSearch() );
          
        
        
        }
	else{
	
	      
	       jQuery("#playerWidget input[name='playerStatus']").val( getCurrentSong().songTitle+" selected");
	

          }


}




//END SETTERS**************************************************************************


//GETTERS********************************************************



function getTotalEntries(){


	return totalEntries;
	
	
}


function getCurrentSong(){

  return this.currentSong;


}




function getSearchTitle(){


	return this.searchTitle;



}

function getSelectedSearch(){



	return this.selectedSearch;



}


function getSelectedDance(){

	return this.selectedDance;

}

function getSelectedLetter(){


	return this.selectedLetter;



}


function getSelectedList(){

	return this.selectedList;


}

function getAllFavoritesArray(){

	return this.allFavoritesArray;
	
}

function getallFavoritesArray(){

  return this.allFavoritesArray;

}

function getProgressInterval(){


	return this.progressInterval;
	
	
}



function getProgressInterval(){


	return this.progressInterval;
	
	
}

		
function getListEntriesArray(){


         return this.listEntriesArray;
         
         
}




function getPerformersByLetterResult( rowObject, page){

        
    	                                 
    	var resHTML = "<div style=\"float:left; height:40px; width:100px; border-left:1px solid #cccccc; border-right:2px solid #000000\">&nbsp;" + rowObject.lastName+" "+ rowObject.firstName+"</div>"+
    	              "<div style=\"float:left; height:40px; width:150px; border-left:1px solid #cccccc; border-right:2px solid #000000; color:#ffffcc\">"+
    	              "<button onClick=\"findAlbumsByPerformer('"+ rowObject.performerId +"',"+
    	              "                                        '"+ page +"')\">find albums</button></div>";
    	    	                                                
    	return resHTML;
    	    	                                                
    	    	                                                
 }//end function
 	


function getCatalogPageObject( html, page){

    
     var lowIndex = (page-1)*10+1 ;
     var highIndex = (page -1)*10 +11;
     var resultArray = new Array();
     var trimedText = html .split("<allAlbums>")[1].split( "</allAlbums>")[0];
     var rowsArray = trimedText.split( "<album>");
     
     
     this.totalEntries = rowsArray.length-1;
     
    
     
        if( highIndex >= this.totalEntries ){
        
             highIndex = this.totalEntries;
             
         }
         
         
     var idString ="";
     
        
         
    		for( var i= lowIndex; i<= highIndex; i++ ){
    	
    	
    	       
    		var row = rowsArray[i];
    		
    		
    		var entry = i;
    		
    		var dance = row.split("<dance>" )[1].split("</dance>")[0];
    		var albumId = row.split("<albumID>")[1].split("</albumID>")[0];
    		var albumName = row.split("<name>")[1].split("</name>")[0];
    		var performerId = row.split("<performerID>")[1].split("</performerID>")[0];
    		var itunesUrl = row.split("<itunesUrl>")[1].split("</itunesUrl>")[0];
    		var amazonUrl = row.split("<amazonURL>")[1].split("</amazonURL>")[0];
    		var libraryUrl = row.split("<libraryUrl>")[1].split("</libraryUrl>")[0];
    		var art = libraryUrl+"/icon/icon.jpg";
    		var otherUrl = "NA";
    		
    		
    	        
    	        var albumObject = { entry:      entry, 
    	                            dance:      dance,
    	                            art:        art, 
    	                            albumId:    albumId,
    	                            albumName:  albumName,
    	                            songTitle:  "-------",
    	                            performerId: performerId,
    	                            libraryUrl: libraryUrl,
    	                            itunesUrl:  itunesUrl,
    	                            amazonUrl:  amazonUrl,
    	                            otherUrl : otherUrl    };
    	        resultArray.push( albumObject );
    	
    	}//end for

         
         
	return resultArray;


}




function getPerformersPageObject( html, page){

  
      
     var lowIndex = (page-1)*10 +1;
     var highIndex = (page -1)*10 +11;
     var resultArray = new Array();
     var trimedText = html .split("<allPerformers>")[1].split( "</allPerformers>")[0];
     var rowsArray = trimedText.split( "<performer>");
     this.totalEntries = rowsArray.length-1;
     
        if( highIndex >= this.totalEntries ){
        
             highIndex = this.totalEntries;
             
         }
         
         
     var idString ="";
     
         
    	for( var i=lowIndex ; i< highIndex; i++ ){
	     	
	     	
	     	        
	     		var row = rowsArray[i];
	     		
	     		
	     		
	     		var performerId = row.split("<performerID>")[1].split("</performerID>")[0];
	     		var firstName = row.split("<firstName>")[1].split("</firstName>")[0];
	     		var lastName = row.split("<lastName>")[1].split("</lastName>")[0];
	     		
	     	        
	     	        var albumObject = { entry:      i, 
	     	                            performerId: performerId,
	     	                            firstName: firstName,
	     	                            lastName:  lastName     };
	     	                            
	     	                            
	     	        resultArray.push( albumObject );
	     	
	}//end for

     
          
   
        
	return resultArray;


}






function getFavoritesPageObject( html){


        
        var trimedText = html .split("<result>")[1].split( "</result>")[0];
        this.totalEntries = new Number( trimedText.split("<totalEntries>")[1].split("</totalEntries>")[0] );
         
       
	var rowsArray = trimedText.split( "<album>");
	var idString ="";
	
	        for ( var i=1; i< rowsArray.length; i++ ){
	                       
	                      idString +=rowsArray[i].split("<albumId>")[1].split("</albumId>")[0] +"@";
	                     
	        }//end for
	
	
	var pageUrl = "/php/proxy.php?url=http://www.ballroomlibrary.com/radioinfoserver/PrintAlbumServlet?"+
		    	                                    "albumID="+ idString +"&userName=&subscription=";
		    	                                    
		    	                                    
	        var resultArray = new Array();
	      jQuery.ajax({
		    	    	
		    	   
		    	    		  url: pageUrl,
		    	         	  cache: false,
		    	    		  async: false,
		    	    		  success: function(html){
		    	        
		 
		                            var rowsArray = html.split("<album>");
		    	    		    
	
	
    	for( var i=1; i< rowsArray.length; i++ ){
    	
    	
    	        
    		var row = rowsArray[i];
    		
    		
    		var entry = i;
    		var art = row.split("<icon>" )[1].split("</icon>")[0];
    		var albumId = row.split("<albumId>")[1].split("</albumId>")[0];
    		var albumName = row.split("<name>")[1].split("</name>")[0];
    		var performerId = row.split("<performerID>")[1].split("</performerID>")[0];
    		var itunesUrl = row.split("<itunesURL>")[1].split("</itunesURL>")[0];
    		var amazonUrl = row.split("<amazonURL>")[1].split("</amazonURL>")[0];
    		//var libraryUrl = row.split("<libraryURL>")[1].split("</libraryURL>")[0];
    		var otherUrl = row.split("<otherURL>")[1].split("</otherURL>")[0];
    		
    		
    	        
    	        var albumObject = { entry:      entry, 
    	                            art:        art, 
    	                            albumId:    albumId,
    	                            albumName:  albumName,
    	                            performerId: performerId,
    	                            libraryUrl: "",
    	                            itunesUrl:  itunesUrl,
    	                            amazonUrl:  amazonUrl,
    	                            otherUrl : otherUrl    };
    	        resultArray.push( albumObject );
    	
    	}

           	
	   	                                  }//end success
	   	                                  
	   	                         });//ajax end   
	                            
        
	return resultArray;


}


function getTracksPageObject( html){


        
           
	var rowsArray = html.split( "<song>");
	this.totalEntries = rowsArray.length -1;
	var resultArray = new Array();
	
    	for( var i=1; i< rowsArray.length; i++ ){
    	
    	
    	        
    		var row = rowsArray[i];
    		
    		
    		var entry = i;
    		var songId = row.split("<songId>")[1].split("</songId>")[0];
    		var albumId = row.split("<album>")[1].split("</album>")[0];
    		var dance = row.split("<dance>")[1].split("</dance>")[0];
    		var songTitle = row.split("<title>")[1].split("</title>")[0];
    		var performerId = row.split("<performer>")[1].split("</performer>")[0];
    		var track = row.split("<track>")[1].split("</track>")[0];
    		
    		    	        
    	        var trackObject = { entry:     entry, 
    	                            songId:    songId,
    	                            songTitle: songTitle,
    	                            dance:     dance,
    	                            performerId: performerId,
    	                            track : track    };
    	                            
    	                           
    	        resultArray.push( trackObject );
    	
    	}//end for
        
	return resultArray;


}











function callAjaxForLists( pageUrl,page ){   
    	    
    	 
    	  var url = "/php/proxy.php?url="+ pageUrl;
    	  
    	   
    	        initProgressDialog("Loading data please wait...");
    	       	jQuery.ajax({
    	    	
    	    	          type:"POST",
    	    		  url: pageUrl,
    	         	  cache: false,
    	    		  async: false,
    	    		  success: function(html){
    	        
 
                           
    	     this.pageObjectsArray  = getFavoritesPageObject( html);
    	     if( getTotalEntries() == 0 ){
    	     
    	     
    	     	alert( "No entries found for this search");
    	     
    	     
    	     }
    	     else{
    	     
    	      jQuery("#resultTop select").children().remove();
    	      var optionsText="";
    	      
    	      var pages = new Number( getTotalEntries()/10 );
    	     
    	     
    	      
    	      if( ( getTotalEntries() % 10) > 0 ){
    	      
    	      	pages++;
    	      }
    	      
    	    
    	      for ( var i= 1; i<= pages; i++ ){
	    		
	    		
	    		     
	    		                if( i== new Number(page) ){
	    		                
	    		                    optionsText+= "<option value="+(i)+" selected>"+(i)+"</option>";
	    		                    
	    		                 //new Option( i , i)                 
	    		  		 ////newOption ); 
	    	  }
	    	  else{
	    	  
	    	    optionsText+= "<option value="+(i)+" >"+(i)+"</option>";
	    	  	 
	    	}
	    	  
	    	  	                     
	    	                  }//end for
	    	
	    	
	    	     
	    	
	    	        jQuery("#resultTop select").append( optionsText);
	     		jQuery("#tabs").fadeTo("slow",0.3);
	     		
    	    		
    	      
    	    		var pageHTML ="<div style=\"float:left;height:20px; width:900px; background:darkblue; color:#ffffcc; font-size:10pt;font-family:tahoma\">"+
    	    		              "<div style=\"float:left; border-left:1px solid #cccccc; border-right:2px solid #000000;height:20px; width:40px\">entry</div>";
    	    		              
    	    		               if( getSelectedSearch() == "performersByLetter"  ){
    	    		               
    	    		               	pageHTML+= "<div style=\"float:left; border-left:1px solid #cccccc; border-right:2px solid #000000;height:20px ;width:100px\">performer</div>"+
                                                   "<div style=\"float:left; border-left:1px solid #cccccc; border-right:2px solid #000000;height:20px ;width:100px\">albums</div>";

    	    		               
    	    		               }
    	    		               
    	    		               else{
    	    		               
    	    		                
    	    		                  pageHTML+=
    	    		               
    	    		              "<div style=\"float:left; border-left:1px solid #cccccc; border-right:2px solid #000000;height:20px ;width:50px\">art</div>"+
    	    		              "<div style=\"float:left; border-left:1px solid #cccccc; border-right:2px solid #000000;height:20px;width:100px\">album Id</div>"+
    	    		              "<div style=\"float:left; border-left:1px solid #cccccc; border-right:2px solid #000000;height:20px ;width:200px\">album title</div>"+
    	    		              "<div style=\"float:left; border-left:1px solid #cccccc; border-right:2px solid #000000;height:20px ;width:200px\">song title</div>"+
    	    		              "<div style=\"float:left; border-left:1px solid #cccccc; border-right:2px solid #000000;height:20px ;width:100px\">performer</div>"+
    	    		              "<div style=\"float:left; border-left:1px solid #cccccc; border-right:2px solid #000000;height:20px ;width:50px\">dance</div>";
    	    		              pageHTML+= "</div>";
    	    		      
    	    		               }//end else
    	    		      
    	    	               for( var i=0; i< pageObjects.length; i++ ){
    	    	          
    	    	                 var line="<div style=\"float:left; height:40px; width:850px; background:#292929; border-top:1px solid #cccccc;"+ 
    	    	                                   "border-bottom:2px solid #000000;"+
    	    	                                   "font-size:10pt;"+ 
    	    	                                   "font-family:tahoma\">"+
    	    	                       "<div style=\"float:left; height:40px; width:40px;  border-left:1px solid #cccccc; border-right:2px solid #000000\">&nbsp;"+ pageObjects[i].entry+"</div>";
    	    	                       
    	    	                       
    	    	                       if( getSelectedSearch() == "performersByLetter"  ){
    	    	                       
    	    	                          line+= getPerformersByLetterResult( this.pageObjectsArray[i], page );
    	    	                          
    	    	                              

    	    	                        }
    	    	                       
    	    	                        else{
    	    	                        
    	    	                        
    	    	                           
    	    	                             line+= "<div style=\"float:left; height:40px; width:50px;  border-left:1px solid #cccccc; border-right:2px solid #000000\"><img src=\"" + pageObjects[i].art+"\" height=\"40\" alt=\"album image\"></div>"+
    	    	                                    "<div style=\"float:left; height:40px; width:100px; border-left:1px solid #cccccc; border-right:2px solid #000000\">"+
    	    	                                    "&nbsp;<button onClick=\"goAlbum('"+ pageObjects[i].art     + "','" + 
    	    	                                                                            pageObjects[i].albumId + "','" + 
    	    	                                                                            pageObjects[i].albumName +"','"+ 
    	    	                                                                            pageObjects[i].amazonUrl +"','"+
    	    	                                                                            pageObjects[i].itunesUrl +"')\"   class=\"ui-state-default\">preview</button>"+
    	    	                                                                            
    	    	                                    "&nbsp;<button onClick=\"addToYourFavorites('"+    pageObjects[i].albumId + "')\"  class=\"ui-state-default\">add</button>"+
    	    	                                    "</div>"+                                    
		            "<div style=\"float:left; height:40px; width:200px; border-left:1px solid #cccccc; border-right:2px solid #000000;background:#000000; color:green\">&nbsp;" + pageObjects[i].albumName+"</div>"+
		            "<div style=\"float:left; height:40px; width:200px; border-left:1px solid #cccccc; border-right:2px solid #000000;color:green; background:#000000\">&nbsp;" + pageObjects[i].songTitle+"</div>"+
		            "<div style=\"float:left; height:40px; width:100px; border-left:1px solid #cccccc; border-right:2px solid #000000; color:#cccccc\">&nbsp;" + pageObjects[i].performerName+"</div>"+
    	    	                                    "<div style=\"float:left; height:40px; width:50px;  border-left:1px solid #cccccc; border-right:2px solid #000000; color:#ffffcc\">&nbsp;" + pageObjects[i].detail+"</div>";
    	    	                                  

    	    	                        }//end else
    	    	                        
    	    	                        
                                       line+= "</div>";
    	    	          
    	    	                        
    	    	                        pageHTML += line;
    	    	              
    	    	              
    	    	            }//end for
    	    	          
    	    	               
    	     
    	      jQuery("#results").show();
	      jQuery("#results").children().remove();
    	      jQuery("#results").append( pageHTML );
    	      jQuery("#results div").children('a').css( { "color":"orange","background":"#292929"});
	  
	     jQuery("#results div").children('a'). hover( function(){ 
	                                                                               jQuery(this).css({ "opacity":"0.1"});
	                                                                               jQuery(this).css({ "color":"#cccccc", "background":"000000"})
	                                                                               jQuery(this).animate({ opacity:"1"},1000 ) 
	                                                       
	                                                                               },
	         
	                                               function(){ 
	                                                                               jQuery(this).css({ "opacity":"0.1"});
	                                                                               jQuery(this).css({ "color":"orange","background":"#292929"})
	                                                                               jQuery(this).animate({ opacity:"1"},1000 ); 
	                                                       
	                                                                               }
	             
    	    	); //end hover
    	      
    	    	 
    	      
    	      
    	      
    	      
    	      
    	      
    	      
    	      }//end else
    	      
    	      
    	      
    	      
    	      
    	  jQuery("#results").css({"height":"900px"});
    	  jQuery("#results").fadeTo("slow",1);
    	  
    	   hideProgressDialog();
                   
    	     }//end success
    	        
    	        
    	        
    	               } );//end ajax
    	               
    	    
    
    
	    
}//callAjaxForListsEnd
    




function playTracks(  albumID ){

               
               
       pageUrl = "http://www.ballroomlibrary.com/php/proxy.php?url=http://www.ballroomlibrary.com:8080/CatalogServer/FindSongByAlbumServlet?albumID="+ albumID; 
       
      
       //document.location.href="#results";
       initProgressDialog();
       jQuery.ajax({
           	    	
           	    	          type:"GET",
           	    		  url: pageUrl,
           	         	  cache: false,
           	    		  async: false,
           	    		  success: function(html){
           	        
        				
                                 
           	    		 var pageObjects = getTracksPageObject( html);
           	    		
           	    		
           	    		
           	      
           	    		var pageHTML ="<div style=\"float:left;height:20px; width:450px; background:darkblue; color:#ffffcc; font-size:10pt;font-family:tahoma\">"+
           	    		              "<div style=\"float:left; border-left:1px solid #cccccc; border-right:2px solid #000000;height:20px; width:40px\">entry</div>"+
           	    		              "<div style=\"float:left; border-left:1px solid #cccccc; border-right:2px solid #000000;height:20px ;width:200px\">song title</div>"+
           	    		              "<div style=\"float:left; border-left:1px solid #cccccc; border-right:2px solid #000000;height:20px ;width:60px\">dance</div>"+
           	    		              "<div style=\"float:left; border-left:1px solid #cccccc; border-right:2px solid #000000;height:20px ;width:50px\">select</div>"+
           	    		              "<div style=\"float:left; border-left:1px solid #cccccc; border-right:2px solid #000000;height:20px; width:50px\">dwnld</div>"+
           	    		              "</div>";
           	    		      
           	    		   
           	    		  
           	    	          for( var i=0; i< pageObjects.length; i++ ){
           	    	          
           	    	          
           	    	            var line="<div style=\"float:left; height:20px; width:450px; background:#292929; border-top:1px solid #cccccc;"+ 
           	    	                                   "border-bottom:2px solid #000000;"+
           	    	                                   "font-size:10pt;"+ 
           	    	                                   "font-family:tahoma\">"+
           	    	                                   
           	    	                       	"<div style=\"float:left; height:20px; width:40px;  border-left:1px solid #cccccc; border-right:2px solid #000000;color:#cccccc\">&nbsp;"+ pageObjects[i].entry+"</div>" +
           	    	                       	"<div style=\"float:left; height:20px; width:200px; border-left:1px solid #cccccc; border-right:2px solid #000000;color:green; background:#000000\">&nbsp;" + pageObjects[i].songTitle+"</div>"+
           	    	                       	"<div style=\"float:left; height:20px; width:60px; border-left:1px solid #cccccc; border-right:2px solid #000000; color:#ffffcc\">&nbsp;" + pageObjects[i].dance+"</div>"+
           	    	                       	"<div style=\"float:left; height:20px; width:50px; border-left:1px solid #cccccc; border-right:2px solid #000000; color:#ffffcc\">&nbsp;"+
           	    	                       	   "<button class=\"ui-state-default\"  onClick=\"javascript:selectSong('" +  pageObjects[i].songTitle.replace("\'","\\\'") + "','"+pageObjects[i].libraryUrl +"')\">"+
           	    	                       	     "<span style=\"float:left\" class=\"ui-icon ui-icon-circle-plus ui-state-default\"></span>"+
           	    	                       	     "</button>"+
           	    	                       	 "</div>"+
           	    	                       	"<div style=\"float:left; height:20px; width:50px; border-left:1px solid #cccccc; border-right:2px solid #000000; color:#ffffcc\">"+                                                
           	    	                       	   "<button onClick=\"javascript:downloadSong('" +pageObjects[i].amazonUrl+"','"+ pageObjects[i].itunesUrl+"','"+pageObjects[i].songTitle+"')\">"+
           	    	                       	     "<span style=\"float:left\" class=\"ui-icon ui-icon-transfer-e-w\"></span>"+ 
           	    	                       	   "</button>"+
           	    	                       	    
           	    	                       	"</div>"+
           	    	                       	
                                               "</div>";
           	    	          
           	    	                        pageHTML += line;
           	    	              
           	    	               
           	    	            }//end for
           	    	          
           	    	               
           	     
           	      
           	      jQuery("#albumTracks").html( pageHTML );
           	      jQuery("#albumTracks div").children('button').css( { "color":"orange","background":"#292929"});
       	  
       	              jQuery("#albumTracks div").children('button'). hover( function(){ 
       	                                                                                jQuery(this).css({ "opacity":"0.1"});
       	                                                                               jQuery(this).css({ "color":"#cccccc", "background":"000000"})
       	                                                                               jQuery(this).animate({ opacity:"1"},1000 ) 
       	                                                       
       	                                                                               },
       	         
       	                                               function(){ 
       	                                                                               jQuery(this).css({ "opacity":"0.1"});
       	                                                                               jQuery(this).css({ "color":"orange","background":"#292929"})
       	                                                                               jQuery(this).animate({ opacity:"1"},1000 ); 
       	                                                       
       	                                                                               }
       	             
           	    	); //end hover
           	      
           	    	 
           	    
           	      jQuery(".ui-icon" ).hover( function(){ jQuery(this).addClass("ui-state-hover") },
		      	 		     function(){ jQuery(this).removeClass("ui-state-hover") } );//end hover
     	 		
           	    
           	      
                          
           	     }//end success
           	        
           	        
           	        
           	               } );//end ajax
           	               
           	    
                
       	    
      hideProgressDialog();
      initListPlayer(false);     
      this.counter=0;
      
               
  }//end play tracks








//CATALOG SEARCH******************************************************************************

function findSongByDance( page ){

              
      // setGoogleSearchKeyword( getSelectedDance()  );
	  var pageUrl="http://www.ballroomlibrary.com:8080/CatalogServer/FindAlbumByDanceServlet?dance="+ getSelectedDance();
	 
	  callAjaxForCatalog(pageUrl,page);
	   	
	     	
		
}//end findSongByDanxce




function findSongsByTitle( page ){


     
      setGoogleSearchKeyword( this.searchTitle );
      pageUrl="http://www.ballroomlibrary.com/radioinfoserver/PrintSongsByTitleServlet?title="+ this.searchTitle+"&userName="+this.userName+"&subscription="+this.subscription+"&page="+page;
      callAjaxForCatalog(pageUrl,page);
      
    	
    	
    	 
}

function findAlbumsByTitle( page ){


	
    	setGoogleSearchKeyword( searchTitle );
    	pageUrl="http://www.ballroomlibrary.com/radioinfoserver/PrintAlbumByTitleServlet?title="+ this.searchTitle+"&userName="+this.userName+"&subscription="+this.subscription+"&page="+page;
    	callAjaxForCatalog(pageUrl,page);
    	


}


function findPerformersByLetter( page ){


    
    var pageUrl="http://www.ballroomlibrary.com/php/proxy.php?url=http://www.ballroomlibrary.com:8080/CatalogServer/FindPerformerByLetterServlet?letter="+ this.selectedLetter;
                
    callAjaxForPerformers( pageUrl,page );
    	
    

}


function findAlbumsByPerformer( performerID,page ){


   setSelectedSearch( "albumsByPerformer");
  
   var pageUrl= "http://www.ballroomlibrary.com:8080/CatalogServer/FindAlbumByPerformerServlet?performerID="+performerID;
   callAjaxForCatalog(pageUrl,page );
       

}


function addToYourFavorites( albumId ){

 
      var lastName = getCustomerInfo().lastName;
      
      
     
 	if( !getCustomerInfo() || (getCustomerInfo().lastName == "User" ) ){
 
    		alert( "You need to login to add favorite!");
    
  	}
  	else{
  
       		var newWindow = window.open('','','width=1000,scrollbars=yes');
        	newWindow.location="http://www.ballroomlibrary.com/managelistserver/AddFavoriteServlet?userName="+getCustomerInfo().id+
       	                                                                                       "&subscription=basic"+
	                                                               "&songID=&dance="+this.selectedDance+	                                                                       
	                                                               "&songTitle=&albumID="+albumId;
   	}//end else
   	
   	
   	
  
}//end function
















function callAjaxForCatalog( pageUrl,page ){   
    	    
    	 
    	  var url = "http://www.ballroomlibrary.com/php/proxy.php?url="+ pageUrl;
    	  
    	   
    	        initProgressDialog("Loading data please wait...");
    	       	jQuery.ajax({
    	    	
    	    	          type:"GET",
    	    		  url: url,
    	         	  cache: false,
    	    		  async: false,
    	    		  success: function(html){
    	        
 
                       
    	     setPageObjectsArray(  getCatalogPageObject( html,page) );
    	     if( getTotalEntries() == 0 ){
    	     
    	     
    	     	alert( "No entries found for this search");
    	     
    	     
    	     }
    	     else{
    	     
    	      jQuery("#resultTop select").children().remove();
    	      var optionsText="";
    	      
    	      var pages =0;
    	     
    	     
    	     
    	      if( getTotalEntries() <= 10 ){
    	      
    	          pages=1;
    	          
    	       }
    	       else{
    	       
    	       
    	           pages = new Number( getTotalEntries()/10 );
    	           if( ( getTotalEntries() % 10) > 0 ){
    	      
    	      	      pages++;
    	      	    }
    	      	}
    	        
    	        
    	      	for ( var i= 1; i<= pages; i++ ){
	    		
	    		
	    		     
	    		                if( i== new Number(page) ){
	    		                
	    		                    optionsText+= "<option value="+(i)+" selected>"+(i)+"</option>";
	    		                    
	    		                 //new Option( i , i)                 
	    		  		 ////newOption ); 
	    	  			}
	    	  			else{
	    	  
	    	    				optionsText+= "<option value="+(i)+" >"+(i)+"</option>";
	    	  	 
	    				}
	    	  
	    	  	                     
	    	 }//end for
	    	
	    	
	    	     
	    	
	    	        jQuery("#resultTop select").append( optionsText);
	     		jQuery("#tabs").fadeTo("slow",0.3);
	     		
    	    		
    	      
    	    		var pageHTML ="<div style=\"float:left;height:20px; width:900px; background:darkblue; color:#ffffcc; font-size:10pt;font-family:tahoma\">"+
    	    		              "<div style=\"float:left; border-left:1px solid #cccccc; border-right:2px solid #000000;height:20px; width:40px\">entry</div>"+
    	    		              "<div style=\"float:left; border-left:1px solid #cccccc; border-right:2px solid #000000;height:20px ;width:50px\">art</div>"+
    	    		              "<div style=\"float:left; border-left:1px solid #cccccc; border-right:2px solid #000000;height:20px;width:100px\">album Id</div>"+
    	    		              "<div style=\"float:left; border-left:1px solid #cccccc; border-right:2px solid #000000;height:20px ;width:200px\">album title</div>"+
    	    		              "<div style=\"float:left; border-left:1px solid #cccccc; border-right:2px solid #000000;height:20px ;width:200px\">song title</div>"+
    	    		              "<div style=\"float:left; border-left:1px solid #cccccc; border-right:2px solid #000000;height:20px ;width:100px\">performer</div>"+
    	    		              "<div style=\"float:left; border-left:1px solid #cccccc; border-right:2px solid #000000;height:20px ;width:50px\">dance</div>"+
    	    		              "</div>";
    	    		      
    	    		                   	    		      
    	    	               for( var i=0; i< getPageObjectsArray().length; i++ ){
    	    	          
    	    	                 var line="<div style=\"float:left; height:40px; width:850px; background:#292929; border-top:1px solid #cccccc;"+ 
    	    	                                   "border-bottom:2px solid #000000;"+
    	    	                                   "font-size:10pt;"+ 
    	    	                                   "font-family:tahoma\">"+
    	    	                       "<div style=\"float:left; height:40px; width:40px;  border-left:1px solid #cccccc; border-right:2px solid #ffffff;color:#cccccc\">&nbsp;"+ getPageObjectsArray()[i].entry+"</div>"+
    	    	                       "<div style=\"float:left; height:40px; width:50px;  border-left:1px solid #cccccc; border-right:2px solid #000000\"><img src=\"" + getPageObjectsArray()[i].art+"\" height=\"40\" alt=\"album image\"></div>"+
    	    	                        "<div style=\"float:left; height:40px; width:100px; border-left:1px solid #cccccc; border-right:2px solid #000000\">"+
    	    	                                    "&nbsp;<button name='goAlbum' data='"+i+"'  class=\"ui-state-default\">preview</button>"+
    	    	                                                                            
    	    	                                    "&nbsp;<button onClick=\"addToYourFavorites('"+   getPageObjectsArray()[i].albumId + "')\"  class=\"ui-state-default\">add</button>"+
    	    	                                    "</div>"+                                    
		            "<div style=\"float:left; height:40px; width:200px; border-left:1px solid #cccccc; border-right:2px solid #000000;background:#000000; color:green\">&nbsp;" + getPageObjectsArray()[i].albumName+"</div>"+
		            "<div style=\"float:left; height:40px; width:200px; border-left:1px solid #cccccc; border-right:2px solid #000000;color:green; background:#000000\">&nbsp;" + getPageObjectsArray()[i].songTitle+"</div>"+
		            "<div style=\"float:left; height:40px; width:100px; border-left:1px solid #cccccc; border-right:2px solid #000000; color:#cccccc\">&nbsp;" + getPageObjectsArray()[i].performerId+"</div>"+
    	    	                                    "<div style=\"float:left; height:40px; width:50px;  border-left:1px solid #cccccc; border-right:2px solid #000000; color:#ffffcc\">&nbsp;" + getPageObjectsArray()[i].dance+"</div>"+
    	    	                                    "</div>";
    	    	          
    	    	                        
    	    	                        pageHTML += line;
    	    	              
    	    	              
    	    	            }//end for
    	    	          
    	    	               
    	     
    	      jQuery("#results").show();
	      jQuery("#results").children().remove();
    	      jQuery("#results").append( pageHTML );
    	      
    	      
    	      jQuery("#results div").children('button').addClass( 'ui-state-default');
    	      
    	      jQuery("#results div").children("button[name='goAlbum']").click( function(){
    	      
    	                                                                                   var index = new Number ( jQuery(this).attr('data') );
    	                                                                                  
    	                                                                                   
    	                                                                                 
    	                                                                                   
    	                                                                                   goAlbum( getPageObjectsArray()[index].art,
    	                                                                                            getPageObjectsArray()[index].albumId, 
    	                                                                                            getPageObjectsArray()[index].albumName,
    	                                                                                            getPageObjectsArray()[index].amazonUrl, 
    	                                                                                            getPageObjectsArray()[index].itunesUrl      );
    	                                                                                            
    	                                                      
    	                                                                                            
    	                                                                                   jQuery(this).parent().parent().css({'background':'orange'} );
    	                                                                                   
    	                                                                                   } ); //end click
	  
	           jQuery("#results div").children("button").hover( function(){ jQuery(this).addClass("ui-state-hover"); },
    	                                                      function(){ jQuery(this).removeClass("ui-state-hover"); });//end hover
    	      
    	      
    	      }//end else
    	      
    	      
    	      
    	      
    	      
    	  jQuery("#results").css({"height":"900px"});
    	  jQuery("#results").fadeTo("slow",1);
    	  jQuery("#tabs").toggle("up");
    	  
    	   hideProgressDialog();
                   
    	     }//end success
    	        
    	        
    	        
    	               } );//end ajax
    	               
    	    
    
    
	    
}//callAjaxForCatalogEnd
    
    
    
    
    
    
 function callAjaxForPerformers( pageUrl,page ){   
    	    
    	 
    	  var url = "http://www.ballroomlibrary.com/php/proxy.php?url="+ pageUrl;
    	  
    	   
    	        initProgressDialog("Loading data please wait...");
    	       	jQuery.ajax({
    	    	
    	    	          type:"GET",
    	    		  url: url,
    	         	  cache: false,
    	    		  async: false,
    	    		  success: function(html){
    	        
 
                           
    	     setPageObjectsArray(  getPerformersPageObject( html,page) );
    	     if( getTotalEntries() == 0 ){
    	     
    	     
    	     	alert( "No entries found for this search");
    	     
    	     
    	     }
    	     else{
    	     
    	      jQuery("#resultTop select").children().remove();
    	      var optionsText="";
    	      
    	      var pages = new Number( getTotalEntries()/10 );
    	     
    	     
    	      
    	      	if( ( getTotalEntries() % 10) > 0 ){
    	      
    	      	pages++;
    	      	}
    	      
    	    
    	      	for ( var i= 1; i<= pages; i++ ){
	    		
	    		
	    		     
	    		                if( i== new Number(page) ){
	    		                
	    		                    optionsText+= "<option value="+(i)+" selected>"+(i)+"</option>";
	    		                    
	    		                 //new Option( i , i)                 
	    		  		 ////newOption ); 
	    	  			}
	    	  			else{
	    	  
	    	    				optionsText+= "<option value="+(i)+" >"+(i)+"</option>";
	    	  	 
	    					}
	    	  
	    	  	                     
	    	 }//end for
	    	
	    	
	    	     
	    	
	    	        jQuery("#resultTop select").append( optionsText);
	     		jQuery("#tabs").fadeTo("slow",0.3);
	     		
    	    		
    	      
    	    		var pageHTML ="<div style=\"float:left; height:20px; width:900px; background:darkblue; color:#ffffcc; font-size:10pt;font-family:tahoma\">"+
    	    		              "<div style=\"float:left; border-left:1px solid #cccccc; border-right:2px solid #000000;height:20px; width:40px\">entry</div>"+
    	    		              "<div style=\"float:left; border-left:1px solid #cccccc; border-right:2px solid #000000;height:20px ;width:100px\">performer</div>"+
                                      "<div style=\"float:left; border-left:1px solid #cccccc; border-right:2px solid #000000;height:20px ;width:150px\">albums</div>"+
                                      "</div>";
				      
				    
    	    		      
    	    	               for( var i=0; i< getPageObjectsArray().length; i++ ){
    	    	          
    	    	                 var line="<div style=\"float:left; height:40px; width:900px; color:#cccccc; background:#292929; border-top:1px solid #cccccc;"+ 
    	    	                                   "border-bottom:2px solid #000000;"+
    	    	                                   "font-size:10pt;"+ 
    	    	                                   "font-family:tahoma\">"+
    	    	                           "<div style=\"float:left; height:40px; width:40px;  border-left:1px solid #cccccc; border-right:2px solid #ffffff;color:#cccccc\">&nbsp;"+ getPageObjectsArray()[i].entry+"</div>"+
    	    	                           getPerformersByLetterResult( getPageObjectsArray()[i], page ) + 
    	    	                           "</div>";
    	    	                          
    	    	                            
    	    	                        
    	    	                        pageHTML += line;
    	    	              
    	    	              
    	    	              }//end for
    	    	          
    	    	               
    	     
    	      jQuery("#results").show();
	      jQuery("#results").children().remove();
    	      jQuery("#results").append( pageHTML );
    	      
    	      
    	      jQuery("#results div").children('button').addClass( 'ui-state-default');
    	      
    	      jQuery("#results div").children("button[name='goAlbum']").click( function(){
    	      
    	                                                                                   var index = new Number ( jQuery(this).attr('data') );
    	                                                                                  
    	                                                                                   
    	                                                                                 
    	                                                                                   
    	                                                                                   goAlbum( getPageObjectsArray()[index].art,
    	                                                                                            getPageObjectsArray()[index].albumId, 
    	                                                                                            getPageObjectsArray()[index].albumName,
    	                                                                                            getPageObjectsArray()[index].amazonUrl, 
    	                                                                                            getPageObjectsArray()[index].itunesUrl      );
    	                                                                                            
    	                                                      
    	                                                                                            
    	                                                                                   jQuery(this).parent().parent().css({'background':'orange'} );
    	                                                                                   
    	                                                                                   } ); //end click
	  
	           jQuery("#results div").children("button").hover( function(){ jQuery(this).addClass("ui-state-hover"); },
    	                                                      function(){ jQuery(this).removeClass("ui-state-hover"); });//end hover
    	      
    	      
    	      }//end else
    	      
    	      
    	      
    	      
    	      
    	  jQuery("#results").css({"height":"900px"});
    	  jQuery("#results").fadeTo("slow",1);
    	  jQuery("#tabs").toggle("up");
    	  
    	   hideProgressDialog();
                   
    	     }//end success
    	        
    	        
    	        
    	               } );//end ajax
    	               
    	    
    
    
	    
}//callAjaxForCatalogEnd
    
       
 
 
 
 
 
 
 
 
 
    
    
    
    
    
    
    
    

//CATALOG SEARCH END**********************************************************************









//FAVORITES SEARCH ***************************************************************************



function findFavoritesByDance( page){

        
        
	setGoogleSearchKeyword( this.selectedDance);
	var pageUrl= "http://www.ballroomLibrary.com/managelistserver/FindFavoritesByDanceServlet"+
	                   "?userName="+this.userName+
	                   "&subscription="+this.subscription+
	                   "&dance="+ this.selectedDance +
	                   "&page="+page;
	                   
	             
	callAjaxForLists( pageUrl,page );
       
              

}//end method

 



//END FAVORITES SEARCH*********************************





//LISTS MANAGEMENT**********************************************************************************




function findFavoritesInList(listName){ 

      
	var pageUrl="http://www.ballroomlibrary.com/php/proxy.php?url=http://www.ballroomLibrary.com/managelistserver/FindFavoritesInList_PlayerServlet"+
	                                 
                   "%3FuserName%3D"+getCustomerInfo().id+
                   "%26listName%3D"+listName;
		                           
		
		
		
		
	 var favoritesInListArray = new Array();
	 
		jQuery.ajax({
		
		  type:"POST",
		  url: pageUrl,
		  cache: false,
		  async: false,

		  success: function(html){
		    
		  
		   favoritesInListArray = parseFavorites( html );
		  
		   hideProgressDialog();

		    
		  }//end success
		});

      
      return favoritesInListArray;

}//findFavortiesinList*/



function parseFavorites( html){

      initProgressDialog("Please wait..");
        var favoriteAlbumsInList = new Array();
	var rowsArray = html.split( "<row>");
	var idString ="";
	
	        for ( var i=1; i< rowsArray.length; i++ ){
	                       
	             idString +=rowsArray[i].split("<albumID>")[1].split("</albumID>")[0] +"@";
	                     
	        }//end for
	
	
	
		
		
			var pageUrl = 	"/php/proxy.php?url=http://www.ballroomlibrary.com/radioinfoserver/PrintAlbumServlet%3F"+
		      			"albumID%3D"+ idString +"%26userName%3D%26subscription%3D";
		    	                                    
		                                 
	       
	       		jQuery.ajax({
		    	    	
		    	     
		    	    	url: pageUrl,
		    	        cache: false,
		    	    	async: false,
		    	    	success: function(html){
		    	    		
		    	    		
		    	         	
		                  var rowsArray = html.split("<album>");
		    	    		    
	
	                        	
    	                         for( var i=1; i< rowsArray.length; i++ ){
    	
    	
    	        
    	        
    		                       var row = rowsArray[i];
    		
    		
    		                       var entry = i;
    		                       var art = row.split("<icon>" )[1].split("</icon>")[0];
    		                       var libraryUrl = row.split("<libraryURL>" )[1].split("</libraryURL>")[0];
    		                       var albumId = row.split("<albumId>")[1].split("</albumId>")[0];
    		                       var albumName = row.split("<name>")[1].split("</name>")[0];
    		                       var performerId = row.split("<performerID>")[1].split("</performerID>")[0];
    		                       var itunesUrl = row.split("<itunesURL>")[1].split("</itunesURL>")[0];
    		                       var amazonUrl = row.split("<amazonURL>")[1].split("</amazonURL>")[0];
    		                       var otherUrl = row.split("<otherURL>")[1].split("</otherURL>")[0];
    		    	        
    	        
    	        
    	                               var tracksString = row.split("<tracks>")[1].split("</tracks>")[0];
    	         	            	            
    	      
    	                              var itemsArray = tracksString.split("<song>");
                                      var tracksArray = new Array();
   
                     
    	               			for( var j=1; j< itemsArray.length; j++ ){
    	
    		           
    		              			var songID  = itemsArray[j].split("<songId>")[1].split("</songId>")[0];
    	                      			var dance   = itemsArray[j].split("<dance>")[1].split("</dance>")[0];
    	                      			var title   = itemsArray[j].split("<title>")[1].split("</title>")[0];
    	                      			var trackNr = itemsArray[j].split("<trackNr>")[1].split("</trackNr>")[0];
    	                      			var smil    = libraryUrl + "/smil_full/"+ trackNr+"_full.smil";
    	
    	                 			 var trackObject = { smil:smil, icon:art, songID:songID,dance:dance, title:title };
    	                 			 tracksArray.push ( trackObject );
    	        
    	                 		}//end for
                   
    	                   
    	                        
    	                     		var albumObject = {	entry:      entry, 
    	                            				art:        art, 
    	                            				albumId:    albumId,
    	                            				albumName:  albumName,
    	                            				performerId: performerId,
    	                            				libraryUrl: libraryUrl,
    	                            				itunesUrl:  itunesUrl,
    	                            				amazonUrl:  amazonUrl,
    	                            				otherUrl : otherUrl,
    	                            				tracks   : tracksArray }; //end object    
    	                        
    	                                    
    	                         				favoriteAlbumsInList.push( albumObject );
    	                          
    	               			}//for           
    	                          
    	                          
    	             
    	                    
    	                              hideProgressDialog();
    	                    
    	                    	}//end success
    	                    
    	                    
    	                    });//end ajax
    	                    
    	             
    	                    
	return favoriteAlbumsInList;


}






















function loadListEntries( listName ){

	
	
	
	if( !this.isPlaylist  ){
	
	  
	       
	         var listarray = new Array();
	             listarray.push( this.currentSong );
	             setListArray( listarray );
	
		 playSong( getCustomerInfo().id, getCurrentSong().songTitle, getCurrentSong().libraryUrl );
		
	
	
	
	}
	
	else{
	
	
	
	     favoritesInListArray =  findFavoritesInList( listName );
	     
 	     var listarray = new Array();
	     
	         for( var i =0; i < favoritesInListArray.length; i++ ){
	         
	            
	              var songsArray = favoritesInListArray[i].tracks;
	              for( var j=0; j< songsArray.length; j++ ){
	              
	                  listarray.push( songsArray[j] );
	         
	             }
	       
	         }
	         
	         
	     setListArray( listarray );
	     jQuery("#playerStatus").val( listName+" loaded" );
	     playList();//var playlist = htmlText.split(
		 	  		      
		  	  
	          
		 
	}//end else              	 	  
	  
	                                                                                           

 }//end playList



//LISTS MANAGEMENT END*******************************************************************************************















 //GRACENOTE SEARCH******************************************************************************
 
 
 function gracenoteQuery( page ){
 
    var type = ""
    initProgressDialog();
 
            if( getSelectedSearch() == "internetArtist" ){
            
               type = "artist";
               
             }
             else if( getSelectedSearch() == "internetAlbum" ){
              
 	        type = "album"; 
 	        
 	     }
 	     else if( getSelectedSearch() == "internetTrack" ){
 	     
 	         type = "track";
 	         
 	      }
 	      
 	      
     	      setGoogleSearchKeyword( getSearchTitle() );
     	      var query = getSearchTitle().replace(" ","@" );
     	     
              var pageUrl="http://www.ballroomlibrary.com?url=http://www.ballroomlibrary.com/radioinfoserver/SearchGraceNoteJSONServlet"+
                       "%3Ftype%3D"+ type+"%26query%3D"+query;
            
             
              jQuery.ajax({
	      		     type:"POST",
	      		     url: pageUrl,
	      		     cache: false,
	      		     async: false,
	      		     success: function(html){
	      		 	  		    
	      		 	  	
	      		 	  	var albums = html.split("<album>");
	      		 	  	
	      		 	  	var resHTML = parseGracenoteQuery( albums, page);
	      		 	  	
	      		 	  	
	      		 	  	jQuery("#tabs").fadeTo("slow",0.3);
	      		 	  	jQuery("#results").children().remove();
	      		 	  	jQuery("#results").html( resHTML );
	      		 	  	
	      		 	  	       
		jQuery("#results").css({"height":"900px"}) ;
		jQuery("#results div").children("a").css( { "color": "white" } );
		jQuery("#results div").children("a").hover(    function(){ jQuery(this).fadeTo( "slow",0.2 );
		                                                           jQuery(this).fadeTo( "slow",1   );  },
		                                               function(){ jQuery(this).fadeTo( "slow",0.2 );
		                                                           jQuery(this).fadeTo( "slow",1   ); } );
		
		
		
		
		jQuery("#results").show();
		jQuery("#results").fadeTo("slow",1);
		hideProgressDialog();
                              
        	    		       
		jQuery("#resultsHeader select").children().remove();
	      		 	  		       
	      		 	  		       
	      		 	        var pages = albums.length/20;
	      		 	        
	      		 	  	
	      		 	  	 
	      		 	  		if ( albums.length%20  > 0 ){
	      		 	  	             	
	      		 	  	           	
	      		 	  	            pages++;
	      		 	  		                  
	      		 	  		 }
	      		 	  		       
	      		 	  		for( var i=1; i <= pages; i++ ){
	      		 	  		       	
	      		 	  		       	          
	      		 	  		       		
	      		 	  jQuery("#resultsHeader select").append("<option value=\""+ i +"\">"+ i+"</option>");
	      		 	  		       		
	      		 	  		       		
	      		 	  		}
	      		 	  		
	      		 	  		       	
	      		 	  	 }//success function
	      		 	  		  
		        });//end ajax
              
              
              hideProgressDialog();
              
     	
     	 
 }//end method
 
 
 
 
 
   function parseGracenoteQuery( albums, page ){
 	      		 	  		     
 	var albumId = "";
	var albumDetail = "";
	var albumPerformer="";
	var albumArt ="";
	var albumName ="";
	var albumUrl  ="";
	var songTitle = ""; 	 	     
 	 	      
 	 
 	 var resHTML = "<div style=\"float:left;height:20px; width:900px; background:darkblue; color:#ffffcc; font-size:10pt;font-family:tahoma\">"+
 	               "<div style=\"float:left; border-left:1px solid #cccccc; border-right:2px solid #000000;height:20px ;width:50px\">entry</div>"+
		       "<div style=\"float:left; border-left:1px solid #cccccc; border-right:2px solid #000000;height:20px ;width:50px\">art</div>"+
		       "<div style=\"float:left; border-left:1px solid #cccccc; border-right:2px solid #000000;height:20px;width:100px\">album Id</div>"+
		       "<div style=\"float:left; border-left:1px solid #cccccc; border-right:2px solid #000000;height:20px ;width:200px\">album title</div>"+
		       "<div style=\"float:left; border-left:1px solid #cccccc; border-right:2px solid #000000;height:20px ;width:200px\">song title</div>"+
		       "<div style=\"float:left; border-left:1px solid #cccccc; border-right:2px solid #000000;height:20px ;width:100px\">performer</div>"+
		       "</div>";//header;;
 	 
 	 
 	 
 	 
 	 
 	 
 	 
 	 
 	 
 	 
 	 
 	 
 	 
 	 
 	 var onPage = new Number(20);
 	 var indexLow  = ( page -1 )*onPage +1; 
 	 var indexHigh =  (page -1)*onPage+ onPage +1 ;
 	 
 	
 	 
 	 	if( indexHigh > albums.length ){
 	 
 	            indexHigh  = albums.length  ;
 	 
 	 	}//end if
 	 
 	 
 	        
 	        var loop=0;
 	        
 	 	for( var i= indexLow ; i < indexHigh; i++ ){
 	 	
 	 	    
 	 	     albumId = albums[i].split("<albumId>")[1].split("</albumId>")[0];
 	 	     albumDetail = albums[i].split("<albumName>")[1].split("</albumName>")[0];
 	 	     songTitle =albums[i].split("<songTitle>")[1].split("</songTitle>")[0];
 	 	     
 	 	      
 	 	      
 	 	     	if( loop == 0 ){
 	 	
 	 	          
 	 		  var imgSrc = albumDetail.split("<img src=\"")[1].split("\"")[0];
 	 		      albumArt = "http://www.gracenote.com"+ imgSrc;  

 	 		     
 	 		    
 	 		          
 	 		      	 
 	 		    
 	 		   
 	 		}//end if
 	 		if( loop==1 ){
 	 		  
 	 		   
 	 		   albumName = albumDetail;
 	 		   albumUrl  = albums[i].split("<albumUrl>")[1].split("</albumUrl>")[0];
 	                   albumPerformer  = albums[i].split("<albumPerformer>")[1].split("</albumPerformer>")[0];
 	                   resHTML+= "<div style=\"float:left; height:40px; width:850px; background:#292929; border-top:1px solid #cccccc;"+ 
     	    	                                   "border-bottom:2px solid #000000;"+
     	    	                                   "font-size:10pt;"+ 
     	    	                                   "font-family:tahoma\">"+ //row start
     	      "<div style=\"float:left; height:40px; width:50px;  border-left:1px solid #cccccc; border-right:2px solid #000000\">&nbsp;"+ i+"</div>"+
     	      "<div style=\"float:left; height:40px; width:50px;  border-left:1px solid #cccccc; border-right:2px solid #000000\">"+
     	      "<img src=\"" + albumArt+"\" height=\"40\" alt=\"album image\">"+
     	      "</div>"+
     	      "<div style=\"float:left; height:40px; width:100px; border-left:1px solid #cccccc; border-right:2px solid #000000\">"+
     	      "&nbsp;<a href=\"javascript:goGracenoteAlbum('"+ albumName + "','" + 
     	                                                       albumUrl+ "','" +  
     	    	                                               imgSrc + "','" + 
     	     	                                               albumPerformer  +"')\">view album</a>"+
     	      "</div>"+
 	      "<div style=\"float:left; height:40px; width:200px; border-left:1px solid #cccccc; border-right:2px solid #000000;background:#000000; color:green\">&nbsp;" + albumName+"</div>"+
 	      "<div style=\"float:left; height:40px; width:200px; border-left:1px solid #cccccc; border-right:2px solid #000000;color:green; background:#000000\">&nbsp;" + songTitle+"</div>"+
 	      "<div style=\"float:left; height:40px; width:100px; border-left:1px solid #cccccc; border-right:2px solid #000000\">&nbsp;" + albumPerformer+"</div>"+
     	      "</div>"; //row end  
 	                                   
 	                              
 	                                
 	                }//end else
 	                
 	                loop++;
 	                if( loop > 1 ){
 	                
 	                    loop=0;
 	                    
 	                 }
 	                 
 	                  	                 
 	                 

     	    	   
            
		}//end for
     	    	          
     	    	               
		
 	         
 	    
 	  return resHTML;
 	      		 	  		       
   }
 
 
 function findGracenoteSongByDance( dance ){
 
         
         
 	var pageUrl="http://www.ballroomlibrary.com/radioinfoserver/PrintDanceServlet?userName="+this.userName+"&subscription="+this.subscription+"&dance="+dance+"&page=1";
 	   callAjaxForCatalog(pageUrl);
 	     	
 	     	
 		
 }//end findSongByDanxce
 
 
 function findGracenoteAlbumByPerformer( performer,page ){
 
 
 
 
    var pageUrl="http://www.ballroomlibrary.com/radioinfoserver/SearchGraceNoteServlet?type=artist&query="+performer;
     
     callAjaxForCatalog( pageUrl,page );    
        
 
 }
 
 
 
 
 function findGracenotePerformersByLetter( letter ){
 
 
 
   var userName= this.userName;
   var subscription=this.subscription;
 
     alert("coming soon!");
     //var pageUrl="http://www.ballroomlibrary.com/radioinfoserver/SearchGraceNoteServlet?type="+type+"&query="+query;
     
     //callAjax( pageUrl );
     	
     
 
 }
 
 
 
 
 
 //GRACENOTE SEARCH END**********************************************************************
 
 
 function goAlbum( iconUrl, albumID, albumName,amazonURL, itunesURL  ){
 
     
      
     

     jQuery("#albumInfo").show();
     
     jQuery('#album').children().remove();
     jQuery('#album').html( printAlbum ( iconUrl, albumID, albumName,amazonURL, itunesURL ) );
     jQuery("#albumInfo").fadeTo("slow",1);
    
    
     initAlbum( iconUrl, albumID, albumName,amazonURL, itunesURL);
     
    
   
      
}//go album




 function goGracenoteAlbum( albumName,  albumUrl, iconUrl, albumPerformer  ){
 
     
      initProgressDialog();
      var albumObject;
      jQuery("#results").fadeTo("slow",0.4 );
      		 
      		 		jQuery.ajax({
      		 		
      		 		  type:"POST",
      		 		  url: albumUrl,
      		 		  cache: false,
      		 		  async:false,
      		 		  success: function(html){  //success
      		 		    
      		 		     albumObject = parseGracenoteAlbum(  html);
      		 		    
      		 		    
      		 		   }//end success
      		                
      		                
      		                
		                }); //end ajax
      
      
      
      
     jQuery("#albumInfo").show();
     jQuery('#album').children().remove();
     jQuery('#album').html( printGracenoteAlbum ( albumName, albumUrl, iconUrl,  albumPerformer, albumObject.amazonUrl, albumObject.itunesUrl ) );
     jQuery("#albumInfo").fadeTo("slow",1);
    
    
     initGracenoteAlbum( albumObject.itunesUrl, albumObject.amazonUrl );
     hideProgressDialog();
   
      
}//go album







function selectSong( songTitle, songUrl ){

     
        
        jQuery("#selectPlaylist select").children().remove();
        jQuery("#selectPlaylist select").append("<option value=\"singleEntry\" selected>single entry</option>");
        setSelectedSearch("songByAlbum");
	setCurrentSong(  songTitle, songUrl );
	initListPlayer(false);


}

	
 	
 	function goITunes( pageUrl ){
 	
 	 
 	  var newWindow = window.open();
 	      newWindow.location = pageUrl;
 	
 	}
 	
 	function goAmazon( pageUrl ){
 	
 	 
 	  var newWindow = window.open();
 	      newWindow.location = pageUrl;
 	
      }
      
      
      function getPageObjectsArray(){
      
      
         return this.pageObjectsArray;;
        
        
      }
       
      function setPageObjectsArray( value){
             
             
             
             
         this.pageObjectsArray = value;
               
               
      }