var allFavoritesArray;
var favoritesInList
var allListsArray;

function initProfileDocument(){


   
   jQuery(document).ready( function(){
   
   
      this.allFavoritesArray = new Array();
      this.allListsArray =  new Array() ;
        	
          
       var lastName = getCustomerInfo().lastName;
       
             if( getCustomerInfo().lastName == 'User'){
             
                    showLibraryLogin();
                    
                 
              }
              else{
         
       	       
       	         
       	            loadMyProfilePage();
       	         
       	         
             
              }//else
             
            
         
     
     });//end document ready
          
    
}//end initDocument



function loadMyProfilePage(){

     jQuery("#mainTabs" ).hide();
     jQuery("#players").children().remove();     
     jQuery("#myMusic" ).append( printPlayers() );
     jQuery("#playerWidget").css( {
                                          "position":"absolute",
                                          "top":"200px",
                                          "left":"0px",
                                          "border":"1px solid #999999",
                                          "background":"#86C8F2",
                                          "z-index":"1000",
                                          "opacity":"1",
                                          "height":"40px",
                                          "width":"800px" } );
       hideListPlayer();
    
    
    jQuery("#myProfile").children().remove();
    jQuery("#myProfile").append( "<div>Name:"  + this.customerInfo.firstName + " " + this.customerInfo.lastName+" </div>"     +
                                 "<div>Email:" + this.customerInfo.email +     " <button name=\"email\">Edit</button</div>" +
                                 "<div>Password:********<button name=\"password\">Edit</button></div>"  );
                                
    jQuery("#myProfile").css({ "width":"500px", "border":"1px solid #666666","font-size":"10pt" });
    
    jQuery("#myProfile button[name='email']").click(    function(){  editEmail();    }  );//end click 
    jQuery("#myProfile button[name='email']").hover(    function(){  jQuery(this).addClass("ui-state-hover")   },
    	                                                function(){  jQuery(this).removeClass("ui-state-hover") })  ;

    jQuery("#myProfile button[name='password']").click( function(){  editPassword()  }  );//end click 
    jQuery("#myProfile button[name='password']").hover( function(){  jQuery(this).addClass("ui-state-hover")   },
    	                                                function(){  jQuery(this).removeClass("ui-state-hover") } )  ;

    
    jQuery("#myMusic").append("<button name=\"addFavorites\" class=\"ui-state-default\">Add Favorites</button>");
    jQuery("#myMusic").append("<button name=\"manageLists\"  class=\"ui-state-default\">Manage Playlists</button>");
   
    jQuery("#myMusic button").hover( function(){  jQuery(this).addClass("ui-state-hover")   },
    	                             function(){  jQuery(this).removeClass("ui-state-hover") } )  ;
    	                               
    	                               
    jQuery("#myMusic button[name='addFavorites']").click( function(){  jQuery("#mainTabs" ).show();
                                                                       document.location="/ballroom-library"  }  );//end click                                
    jQuery("#myMusic button[name='manageLists']" ).click(  function(){ 
                                                                    // jQuery("#listsAccordion").css({'opacity':'1'});
                                                                     jQuery("#listsAccordion").toggle('down');//css({'opacity':'1'});
                                                                     jQuery("#hideListsAccordionButton").css({'opacity':'1'});  });//end click
    
   
   
    
    jQuery("#hideListsAccordionButton").css({'opacity':'0'});
    
    jQuery("#hideListsAccordionButton").hover( function(){  jQuery(this).addClass("ui-state-hover")   },
        	                               function(){  jQuery(this).removeClass("ui-state-hover") } )  ;
        	                               
        	                               
    jQuery("#hideListsAccordionButton").click( function(){ jQuery(this).css({'opacity':'0'});
                                                           jQuery("#listsAccordion").toggle("up");     });//end click                                
    
    jQuery("#listsAccordion").append( "<h3><a style=\"font-size:10pt\" href=\"#\">Manage Favorites</a></h3>"+
			              "<div id=\"manageFavorites\" >"+//content
			              "<select></select>"+
			              "<button class=\"ui-state-default ui-corner-all\" name=\"edit\">Edit</button>"+
			              "<button class=\"ui-state-default ui-corner-all\" name=\"reset\">Reset</button>"+
			              "</div>"+ //end content
			       
			              "<h3><a style=\"font-size:10pt\" href=\"#\">Create New List</a></h3>"+
			              "<div id=\"createNew\">"+////contentselect
			              "Available Lists</br>"+
			               "<select></select>"+
			               "<button class=\"ui-state-default ui-corner-all\" name=\"create\">Create new</button>\n"+
			               "</div>"+ //end content
			              "<h3><a style=\"font-size:10pt\" href=\"#\">Manage My Lists</a></h3>"+
			               "<div id=\"adminList\">"+//content  /select
			              "<select></select>"+
			              "<button class=\"ui-state-default ui-corner-left\"  name=\"rename\" >Rename</button>"+
			              "<button class=\"ui-state-default\"                 name=\"edit\"   >Edit</button>"+
			              "<button class=\"ui-state-default\"                 name=\"delete\" >Delete</button>"+
			              "<button class=\"ui-state-default ui-corner-right\" name=\"play\"   >Play</button>\n"+
			              "</div>"    ); //append
                                
     
     
     
      jQuery("#playerWidget button[name='play']" ).click( function(){  var listName = getSelectedList();
            
                                                    jQuery("#playerWidget input[name='playerStatus']").val("loading list:"+ listName );
          	 			            loadListEntries( listName);   
          	 			            
          	 			            } );
          	 	           
      jQuery("#playerWidget button").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") } );
     
     
     
               
                          activateMyLists(); 
                          
        
}//end 



  function activateMyLists(){  
  
        
                
	       	setCustomersLists();			
	    		
    	        jQuery("#manageFavorites select").children().remove();
    	        jQuery("#createNew select").children().remove();
    	        jQuery("#adminList select").children().remove();
    	        var resHTML="";
    	        
    	        jQuery("#manageFavorites select").append("<option value=\"allFavorites\">allFavorites</option>");
    	         	for( var i=0; i< this.allListsArray.length; i++){
		                     
		          
		          jQuery("#createNew select").append("<option value=\""+this.allListsArray[i]+"\">"+ this.allListsArray[i] +"</option>");
                          jQuery("#adminList select").append("<option value=\""+this.allListsArray[i]+"\">"+ this.allListsArray[i] +"</option>");

					  			  		   		
			}//end  for
					      	                       
		  
                          
    		jQuery("#listsAccordion").accordion({  collapsible:true  } );
    		
    		
    		
    		jQuery("#manageFavorites button" ).hover( function(){ jQuery(this).addClass("ui-state-hover") },
				    		          function(){    jQuery(this).removeClass("ui-state-hover") } );
		    		                                        
    		jQuery("#manageFavorites button").click(   function(){
	                                                                 manageFavorites();
							                 
							              });//click end   
		                                                          
		                                                              	
    		
    		
    		
    		jQuery("#createNew button[name='create']" ).hover( function(){ jQuery(this).addClass("ui-state-hover") },
    		                                                   function(){ jQuery(this).removeClass("ui-state-hover") } );
    		                                        
	       	jQuery("#createNew button").click( function(){     initInputDialog( "Create New List","New Name" , "create" ) ;});
	       	                                                     
	       	
	       	
	       	
	       	jQuery("#adminList button" ).hover( function(){   jQuery(this).addClass("ui-state-hover") },
    		                                      function(){ jQuery(this).removeClass("ui-state-hover") } );
	        jQuery("#adminList button[name='rename']").click(   function(){
	                                                                 listName =  jQuery('#adminList select').val();
	                                				  if( listName=="allFavorites"){
	                                				  
	                                				  
									       
									       
									        initConfirmDialog( "\"All Favorites\" can not be modified!\n"+
												   "Select different list or\n"+
									      	                   "go to \"Manage Favorites\" to Modify \"allFavorites\" ");
									        
									           
									  }//end if
                                                                         else{
	                                				
	                                				         
										
										initInputDialog( "Rename List","Old Name: "+listName, "rename" ) ;
							                 }
							                 
							                 
							              });//click end   
							                 
							                 
							                 
		jQuery("#adminList button[name='edit']").click(  				                 
							          function(){       
							                     
							                    
							                      listName =  jQuery('#adminList select').val();
							                    
							                      if( listName=="allFavorites"){
									      									        
									      	 
									     
									        initConfirmDialog( "\"All Favorites\" can not be modified!\n"+
												   "Select different list or\n"+
									      	                   "go to \"Manage Favorites\" to Modify \"allFavorites\" ");
									        
									      									        
									      									           
									     }//end if
							                     else{
							                        
							                          
							                          
	                                				          editList( listName);
	                                				    
	                                				       }//end if
	                                				       
	                                			    } );//end click
	                                				       
	       
	       
	       jQuery("#adminList button[name='delete']").click(  function(){    
	       
	                                                                      listName =  jQuery('#adminList select').val();
	                                                                      if( listName=="allFavorites"){
	                                                                      
	                                                                      
	                                                                      
									      	   							      									        
									      	  
									      	  initConfirmDialog( "\"All Favorites\" can not be modified!\n"+
												   "Select different list or\n"+
									      	                   "go to \"Manage Favorites\" to Modify \"allFavorites\" ");
									      									        
									      									      									        
									      									      									           
									    }//end if
									    else {
																				        
										       listName =  jQuery('#adminList select').val();
										       jQuery("#dialog").children().remove();
										       jQuery("#dialog").append(  printYesNoDialog("Deleting List \""+listName+"\"- Are You Sure?" ) );
										       initYesNoDialog( "Deleting List "+listName+"- Are You Sure?", listName ) ;									      
										       
										                                				 	
	                                				 }//end else
	                                
	                                   			} //end function
	                                   			
	            
	                                     			          ); //click
	                                     			          
	                                     			          
	                                     			          
	         jQuery("#adminList button[name='play']").click( function(){  
    		                                                  setSelectedSearch('playRadio');
    		                                                   var listName = jQuery("#adminList select").val();
    		                                                      		                                                   
    		                                                    setSelectedList( listName );
                                                                  
                                                                    jQuery("#playerWidget").animate({"top":"100px"},1000);
                                                                    jQuery("#playerWidget").animate({"top":"-90px"},2000);
                                                                    initListPlayer( true );
		                                                     
		                                                          }  );//endd click
		                                                                                      			          
	                                     			          
	                                    			          
	                                   		          
	               jQuery("#listsAccordion").toggle('up');     
	               jQuery("#dialog").fadeOut("slow");
	              
		            
                
	                  
	                                
 }//end activateLists
	                              
	                                      


function setCustomersLists(){ 


        
        
        var pageUrl="http://www.ballroomlibrary.com/php/proxy.php?url=http://www.ballroomLibrary.com/managelistserver/FindUsersLists_PlayerServlet"+
		         "%3FuserName%3D"+ getCustomerInfo().id;
			                 
		                   
	
		jQuery.ajax({
		
		  type:"POST",
		  url: pageUrl,
		  cache: false,
		  async:false,
		  success: function(html){
		    
		    
		    parseLists( html );
		    setListsOptions();
		    
		   
		    
		    
		  }//end success
		  
		});//end ajax

     

}//end set all Lists




function setListsOptions(){		
	
	         
	         jQuery("#manageFavorites select").children().remove();
	
		   
		   	listName="allFavorites";
			jQuery("#manageFavorites select").append( new Option( listName , listName) );
					   		
		   	
	
	
                 jQuery("#createNew select").children().remove();
	           	for( var i=0; i<this.allListsArray.length; i++){
		   	
		   		var listName = this.allListsArray[i];
		   		jQuery("#createNew select").append( new Option( listName , listName) );
		   		
		   	}//end  for
	
	        
		    jQuery("#adminList select").children().remove();
			           	for( var i=0; i<this.allListsArray.length; i++){
				   	
				   		var listName = this.allListsArray[i];
				   		jQuery("#adminList select").append( new Option( listName , listName) );
				   		
				   	}//end  for
	

}






function editEmail(){

   alert( "Edit email comming soon!");
  
}







function editPassword(){


  alert( "Edit Pasword comming soon!");



}






function showYouTube( movieUrl ){


    newWindow=window.open();
    newWindow.document.location=movieUrl;



}// end function




/**
 * Loads the Google Developers Event Calendar
 */
function loadEventsToday(root){

    var date = new Date();
    var day= date.getDate();
    var month=date.getMonth()+1;
    var year = 1900 + date.getYear();
    
    var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
    var dayOfWeek = new Date( year,month-1,day).getDay();
    var dayString = days[ dayOfWeek];
  
    
    var todayCount = 0;
    var upcomingCount = 0;
    
    	if( month < 10 ){
    	
    	   month = "0"+month;
    	   
    	}
    	if( day < 10 ){
    	
    	    day = "0"+day;
    	    
    	 }
  
    
    var today = year+"-"+month+"-"+day; 
   
    var feed = root.feed;
    var entries = feed.entry || [];
    
    var todayHtml = ['<h4>Schedule Today</h4>'];
        todayHtml.push(dayString+', '+ today);
       
    var upcomingHtml = ['<h4>Upcoming Classes</h4>'];
    for (var i = 0; i < entries.length; ++i) {


      var entry = entries[i];
      var title = entry.title.$t;

      var start = ( entry['gd$when']) ? entry['gd$when'][0].startTime : "";
      var startDate = start.split("T")[0];
      var startTime= start.split("T")[1].split("\.")[0];
      var link = entry['link'][0].href;
      //var event={"title":title,"startDate":startDate,"startTime":startTime,"link":link};
      		  
     	if( today == startDate ){
     	
      		todayHtml.push('<br>','StartTime:', startTime,'<br>');
      		todayHtml.push('<a href=\"javascript:showEventDetail(\''+link+'&ctz=America/New_York\')\">'+title +'</a>','<br>','<br>','<br>');
      		todayCount++;
      		
      	
      	}
      	
      	
      	else if( title.indexOf("First") !=-1 ){

      	
      	
      	
      	
      	            	
      	
      	
      	         if( title.indexOf("Introductory I") != -1 ){
      	         
      	         
      	
      	           this.customerInfo = { title:"", 
      	                                firstName:"", 
      	                                lastName:"", 
      	                                email:"",
      	                                phone:['','',''], 
      	                                classID:"INTRO_I_"+ startDate, 
      	                                className:"Introductory I", 
      	                                classDuration:"5 Weeks", 
      	                                startDate: startDate, 
      	                                price:"85" };

      	           
      	         } //end if
      	         else if( title.indexOf("Introductory II") != -1 ){
      	
      	             this.customerInfo = { title:"", 
      	                                  firstName:"", 
      	                                  lastName:"", 
      	                                  email:"",
      	                                  phone:['','',''], 
      	                                  classID:"INTRO_II_"+startDate, 
      	                                  className:"Introductory II", 
      	                                  classDuration:"8 Weeks", 
      	                                  startDate: startDate, 
      	                                  price:"120" };

      	           
      	           
      	          }//end else
      	
      	          else if( ( title.indexOf("Bronze") != -1 )||
      	                   ( title.indexOf("Silver") != -1 )||
      	                   ( title.indexOf("Gold"  ) != -1 )      ){
		        	
		        	             this.customerInfo = { title:"", 
		        	                                  firstName:"", 
		        	                                  lastName:"", 
		        	                                  email:"",
		        	                                   phone:['','',''],  
		        	                                  classID:"MEDAL_"+startDate, 
		        	                                  className:"", 
		        	                                  classDuration:"", 
		        	                                  startDate: startDate, 
		        	                                  price:"120" };
		  
		        	           
		        	           
      	          }//end else
      	          
      	          
      	          
		upcomingHtml.push('Start Date:', startDate,'<br>',
		                  '<a href=\"javascript:showEventDetail(\''+link+'&ctz=America/New_York\')\">'+title +'</a>',
		                  '<br>',
		                  '<button class=\"ui-state-default\">Signup for this class</button>',
		                  '<br>','<br>','<br>');
      	        upcomingCount++;
      	
      	
      	
      	
      	
      	
      	
      	}//end else if
      	
      	

    }//end for

    	if( todayCount==0 ){
    	
    		todayHtml.push( "There are no events scheduled for today." );
    		
    	}
    	
        
        if( upcomingCount==0 ){
        
	    	
	    	upcomingHtml.push( "Currently there are no upcoming events." );
	    		
    	}
    	    	        
                
                
                jQuery("#today").html( todayHtml.join("") );
               
        	jQuery("#upcoming").html(  upcomingHtml.join("")  ); 
        	
        	
        	
        	
       

       	    	
	    	 
	    	
    	

}//end function












function loadEventsByDate( year,month,day,desc ){

  
 
  var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
  
  var date = year+"-"+month+"-"+day;
  
  
  var dayOfWeek = new Date( year,month-1,day).getDay();
  var nameOfDay = days[ dayOfWeek ];
  this.selectedDate = { date: date,
                        nameOfDay: nameOfDay };
                           
   
   jQuery( "#events").children().remove();
   jQuery( "#events").append("<div>loading events...</div>");
   
   // Atom feed for the Google Doodle calendar
    var feedUrl = "http://www.google.com/calendar/feeds/hm6t5e5ck8kcc8tlu9ild0m460%40group.calendar.google.com/public/full";
                   
  
  
  
   // var startDate = new Date(1998, 9, 1);
   // var endDate = new Date();
  
    var getParams = '?start-min='+ date+'T00:00:00.000-05:00'+
                    '&start-max=' +  date +'T23:59:59.000-05:00'+
                    '&alt=json-in-script' +
                    '&callback=processJSON' +
                    '&orderby=starttime'+
                    '&singleevents=true'+
                    '&sortorder=ascending'+
                    '&futureevents=true'+
                    '&max-results=20'; // choose 5000 as an arbitrarily large number
    feedUrl += getParams;
    
    

	jQuery("#events").append( "<script src="+ feedUrl +"></script>");
	
}//end calendarByDate



function processJSON(root){
 
 
  var feed = root.feed;
  var startDate;
  var endDate;
  var startTime;
  var endTime;
  var start;
  var end;
  var link;
  var event;
  var desc;
  
    
     var entries = feed.entry || [];
     var html = new Array();
 
 	if( entries.length==0 ){
 	
 		html.push('<div>There is no event scheduled<br> for this day</div>');
 	
 	}
 	else{
 	
 		html.push( '<div>');
 		html.push( '<div>Events for:'+ this.selectedDate.nameOfDay+', '+ this.selectedDate.date+'</div>' );
 		
 		for (var i = 0; i < entries.length; ++i) {
 
 
 			                 
       			var entry = entries[i];
       			title = entry.title.$t;
       			
       			
       			if( entry.gd$when != null ){
       			
       			  start = (entry['gd$when']) ? entry['gd$when'][0].startTime : "";
       			  end   = (entry['gd$when']) ? entry['gd$when'][0].endTime : "";
       			  
       			 
       			  startDate = start.split("T")[0];
       			  endDate   = end.split("T")[0];
       			  startTime= start.split("T")[1].split("\.")[0];
       			  var selectedDate  = this.selectedDate.date;
       			  
       			
       			         
       			         //"\n - selectedDate:"+ this.selectedDate.nameOfDay+": "+selectedDate );
       			         
       			         if( selectedDate.substring(0,4) >= startDate.substring(0,4) && 
       			             selectedDate.substring(5,7) >= startDate.substring(5,7) &&
       			             selectedDate.substring(8,11)>= startDate.substring(8,11) && 
       			             selectedDate.substring(0,4) <= endDate.substring(0,4) && 
       			             selectedDate.substring(5,7) <= endDate.substring(5,7) &&
       			             selectedDate.substring(8,11)<= endDate.substring(8,11) ){
       			         
                              
       				   				  	
				  	//startTime= start.split("T")[1].split("\.")[0];
				  	link = entry['link'][0].href;
				  	
		  	      		
		  	      		   html.push('<br>','StartTime:', startTime,'<br>');
                                           html.push("<a href=\"javascript:showEventDetail('"+link+"&ctz=America/New_York')\">"+title +"</a>");
				  	
				  
				    
      	                                				  
       				  }//end if
       			
      					
      			}//end if
      			
      			
 
     		}//end for
     		
     		
     		
     	}//end else
 
 	
         html.push( '<div id=\"closeEvents\"><a href="">close</a></div>');
         html.push( '</div>');
         html.push( '<div style=\"height:20px\"></div>' );
         jQuery("#events").children().remove();
         jQuery("#events" ).html( html.join("") );
         jQuery("#events").css({"color":"#ccccff"});
        
         
         
         jQuery("#events a").hover(  function () {  jQuery(this).fadeTo("slow",1)   } ,
                                         function () {  jQuery(this).fadeTo("slow",0.5) }  );//end hover
	 	                                                              
         
         
        
         
         
         jQuery("#closeEvents a").css({"color":"green","opacity":"0.5"} );
         jQuery("#closeEvents a").hover( function () {  jQuery(this).fadeTo("slow",1)   } ,
                                         function () {  jQuery(this).fadeTo("slow",0.5) }  );//end hover
	 	                                                            
	                      
         jQuery("#closeEvents a").click( function(){
         
                   jQuery("#events").children().remove();
                   
                                                             } );//end click
                                                             
         
                                    
	   
          
 

 }//end processJSON





function searchWord( keyword ){

        var locUrl = "http://www.google.com/custom?domains=designers.ballroomdress.us&q=\"+keyword+\"&sa=Search&sitesearch=&client=pub-3837358447107106&forid=1&ie=ISO-8859-1&oe=ISO-8859-1&safe=active&cof=GALT%3A%23008000%3BGL%3A1%3BDIV%3A%23336699%3BVLC%3A663399%3BAH%3Acenter%3BBGC%3AFFFFFF%3BLBGC%3A336699%3BALC%3A0000FF%3BLC%3A0000FF%3BT%3A000000%3BGFNT%3A0000FF%3BGIMP%3A0000FF%3BFORID%3A1%3B&hl=en";

   		newWindow=window.open();
   		newWindow.location=locUrl ;
 }
 
 

function writeDate(){



         var date = new Date();
         var day= date.getDate();
         var month=date.getMonth()+1;
         var year = 1900 + date.getYear();
         var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
	 var dayOfWeek = new Date( year,month-1,day).getDay();
	 var dayString = days[ dayOfWeek];
	  
	    
	    var count = 0;
	    
	    	if( month < 10 ){
	    	
	    	   month = "0"+month;
	    	   
	    	}
	    	   
	  
	    
	    var today = year+"-"+month+"-"+day; 
	    var resHTML = 'Today is:'+ dayString+" "+ today;

         
         return resHTML;

    }
    
    


function manageFavorites(){

//***************INIT Part **********************************************************************

        var listName = "allFavorites";
        
                   
        this.allFavoritesArray =    findFavoritesInList("allFavorites"); 
      
            
       	var favoritesInList = new Array();
       	var selectedArray = new Array(); 
       	favoritesInList = findFavoritesInList(listName );
       
      
       
       var favoritesPrint = "<div id=\"favoriteFilter\" style=\"width:200px;height:20px\" class=\"ui-widget ui-widget-header\">"+
                            "Removed Favorites "+
		            "</div>"+
		            "<div id=\"selectFavoriteForListForm\" class=\"ui-widget ui-widget-content\"  >"+
		            "<select multiple=\"true\" class=\"ui-widget ui-widget-content\" size=\"20\">"+
		            "</select>"+
		            "</div>";
		      
	
	var listPrint = "<div class=\"ui-widget-header\">All Favorites:<span style=\"margin-left:5px; background:#292929;color:orange\">"+listName+"</span></div>"+
	       		            "<div id=\"favoritesInListForm\">"+
	       		            "<select multiple=\"true\" class=\"ui-widget ui-widget-content ui-selectable\" size=\"20\">" ;
       	                            "</select>"+
       	                            "</div>";
       	                            
       	
        var resHTML= "<div class=\"ui-widget ui-widget-header \">Search Results</div>"+
                     "<div class=\"ui-widget-content\">"+
                     "<div  id=\"favorites\" ></div>"+
                     "<div  id=\"addToList\" class=\"ui-widget\" >"+
                     "<span class=\"ui-widget-content ui-icon ui-icon-circle-arrow-e\" ></span>"+
                     "</div>"+
                     "<div id=\"remFromList\" class=\"ui-widget\""+
                     "<span  class=\"ui-widget-content ui-icon ui-icon-circle-arrow-w\"></span>"+
                     "</div>"+
                     "<div  id=\"favoritesInList\" ></div>"+
                     "<div id=\"saveList\" class=\"ui-widget ui-state-default\" >"+
		     "<button  class=\"ui-state-default ui-corner-all\" value=\"save\">Save List</button>"+
		     "</div>"+
		     "<div id=\"closeList\" class=\"ui-widget ui-state-default\" >"+
		     "<button  class=\"ui-state-default ui-corner-all\" value=\"close\">Close</button>"+
		     "</div>"+
		     "</div>";//widget content
                     
   
   
       jQuery("#resultTop select").append( "<option selected value=\""+listName+"\">"+ listName +"</option>");
       jQuery("#listsAccordion").toggle("up");
       jQuery("#results").show();
       jQuery("#results").children().remove();
         	    		
      
        jQuery("#results").fadeTo("slow",1);
        jQuery( "#results").append( resHTML );
        
        
        jQuery( "#favorites" ).html( favoritesPrint );
        jQuery( "#favoritesInList" ).html( listPrint );
	jQuery( "#favorites"        ).css(    { "float":"left","margin-left":"10px","border":"1px solid #666666" } );
	jQuery( "#addToList"        ).css(    { "float":"left"}  );
	jQuery( "#remFromList"      ).css(    { "float":"left" } );
	jQuery( "#favoritesInList"  ).css(    { "float":"left","width":"200px", "border":"1px solid #666666" } ); 
	jQuery( "#saveList"         ).css(    { "float":"left"                                               } );
	jQuery( "#closeList"         ).css(   { "float":"left"                                               } );
	
	

		 		
		
		for ( var i = 0; i< this.allFavoritesArray.length; i++ ){
		
		   var albumId = this.allFavoritesArray[i].albumId;
		   var albumName = this.allFavoritesArray[i].albumName;
		   
		   if( albumId=="NA"){ albumId = "NO"; albumName="FAVORITES FOUND"};
					 		
		         
		 	     jQuery("#favoritesInList select").append( new Option( albumId+"_"+albumName ,i ) );
		      
		
	           }//end for i
	 
       
       //*************END INIT PART ************************************************************************
       
       
       //EVENTS************************************************************************************
     
       //Hovers***************************************************************************************
       
       
       
       
       
       jQuery( "#selectFavoriteForListForm option" ).hover( function(){ 
       
                  							if( jQuery(this).css(  "opacity"  ) ==1 ){
                          						    jQuery(this).css( {"color":"orange"}  );
       		
                  							}//end if
                                                             } , 
                                                                        
                                                             function(){ 
                                                             
                                                                          jQuery(this).css( { "color":"black" } );
                                                                          
                                                               }   );//end hover
                                                                         
         
       jQuery( "#favoritesInList option" ).hover( function(){ 
	        
	                                                      	if( jQuery(this).css(  "opacity"  ) ==1 ){
	        	
	        	                                             jQuery(this).css( {"color":"green"}  );
	        		
	                                                         }//end if
	                                                                         
	                                            } , 
	                                            function(){ 
	                                                              
	                                                   jQuery(this).css( { "color":"black" } );
	                                                                           
	                                            }      );//end hover
         
      
	 	  		     
	   jQuery("#remFromList").hover( function(){   jQuery(this).addClass   ("ui-state-hover") },
	 	                         function(){   jQuery(this).removeClass("ui-state-hover")   } );
	 	  		      
	 
	 
	  jQuery("#saveList    button").hover( function(){ jQuery(this).addClass("ui-state-hover") },
	 	 	  		      function(){ jQuery(this).removeClass("ui-state-hover") } );
	 	  		     
	 
	 
	 
	 
	  jQuery("#closeList    button").hover( function(){ jQuery(this).addClass("ui-state-hover") },
	 	 	  		     function(){ jQuery(this).removeClass("ui-state-hover") } );
	 	  		     
	 
	 
	 //Clicks*******************************************************************************************	  		      
	 	  		      
          	
	   jQuery( "#remFromList"         ).click( function(){                                                             
	       	
	       	             
		              	     	            
		              jQuery('#favoritesInList option:selected').each( function(i, selected){
		       		     
		       		          jQuery("#selectFavoriteForListForm select").append( new Option( jQuery(this).text(),i ) );
		       		          jQuery(this).remove();
		       		        
		       		        
		       		              
		       		            		       		             
		       	       } ); //each
		             
		          
	                       
	                       
	           } );//end click
	
	
	
	
	
		   jQuery( "#saveList button" ).click( function(){    
		 	  
		 	  
		 	   initProgressDialog("Saving changes" );
		 	  	var favInList = "";
		 	  	var inList = ""
		 	  	
		 	  	jQuery("#selectFavoriteForListForm option").each( function(){
		 	  	                     
		 	  	                     
		 	  	                     var index =  jQuery(this).val();
		 	  	                     var id = jQuery(this).text().split("_")[0];
		 	  	                   
		 	  	                         inList+= id+"%40";
		 	  	                         
		 	  	                        
		 	  	
		 	          } );//each
		 	  
		 	      
		 	       
		 	       
		 	       
		 	  	var pageUrl="http://www.ballroomlibrary.com/php/proxy.php?url=http://www.ballroomLibrary.com/managelistserver/RemoveFavoriteServlet"+
		 	                     "%3FuserName%3D"+getCustomerInfo().id.replace("@","%40")+
		 	                     "%26favoriteID%3D"+inList;
		 	                     
		 	  		
		 	  		jQuery.ajax({
		 	  		
		 	  		  type:"POST",
		 	  		  url: pageUrl,
		 	  		  cache: false,
		 	  		  async: false,
		 	                  
		 	  		  success: function(html){
		 	  		    
		 	  		     hideProgressDialog();
		 	  		     if(html.indexOf("ok") != -1 ){
		 	  		     
		 	  		       initConfirmDialog("List Saved!");
		 	  		       
		 	  		      }
		 	  		      else{
		 	  		       
		 	  		          initConfirmDialog( "Error Saving List!");
		 	  		       
		 	  		      }
		 	  		   
		 	  		  }//function
		 	  		  
		 	  		  
		 	  		  
		 	  		});//end ajax
		 	  		
		 	   	
		 	   	setCustomersLists();
		 	  
		 	  });//end click
	 
	
	
	
	
	
	             
		  jQuery( "#closeList button" ).click( function(){    
		     		 	  
		  jQuery("#results").children().remove();
		  jQuery("#results").fadeOut("slow");
		  jQuery("#listsAccordion").toggle("down");
		   jQuery("#listsAccordion").fadeTo('slow','1');
 	                 
		 	                                      } ); //click	
	
	
	
	
 }//edit list
























function editList(  listName){

//***************INIT Part **********************************************************************

       
        
        
                   
        this.allFavoritesArray =    findFavoritesInList("allFavorites"); 
               
       	var favoritesInList = new Array();
       	var selectedArray = new Array(); 
       	favoritesInList = findFavoritesInList(listName );
       
      
       
       var favoritesPrint = "<div id=\"favoriteFilter\" style=\"width:200px;height:20px\" class=\"ui-widget ui-widget-header\">"+
                            "Available Favorites "+
		            "</div>"+
		            "<div id=\"selectFavoriteForListForm\" class=\"ui-widget ui-widget-content\"  >"+
		            "<select multiple=\"true\" class=\"ui-widget ui-widget-content\" size=\"20\">"+
		            "</select>"+
		            "</div>";
		      
	
	var listPrint = "<div class=\"ui-widget-header\">Favorites In List:<span style=\"margin-left:5px; background:#292929;color:orange\">"+listName+"</span></div>"+
	       		            "<div id=\"favoritesInListForm\">"+
	       		            "<select multiple=\"true\" class=\"ui-widget ui-widget-content ui-selectable\" size=\"20\">" ;
       	                            "</select>"+
       	                            "</div>";
       	                            
       	
        var resHTML= "<div class=\"ui-widget ui-widget-header \">Search Results</div>"+
                     "<div class=\"ui-widget-content\">"+
                     "<div  id=\"favorites\" ></div>"+
                     "<div  id=\"addToList\" class=\"ui-widget\" >"+
                     "<span class=\"ui-widget-content ui-icon ui-icon-circle-arrow-e\" ></span>"+
                     "</div>"+
                     "<div id=\"remFromList\" class=\"ui-widget\""+
                     "<span  class=\"ui-widget-content ui-icon ui-icon-circle-arrow-w\"></span>"+
                     "</div>"+
                     "<div  id=\"favoritesInList\" ></div>"+
                     "<div id=\"saveList\" class=\"ui-widget ui-state-default\" >"+
		     "<button  class=\"ui-state-default ui-corner-all\" value=\"save\">Save List</button>"+
		     "</div>"+
		     "<div id=\"closeList\" class=\"ui-widget ui-state-default\" >"+
		     "<button  class=\"ui-state-default ui-corner-all\" value=\"close\">Close</button>"+
		     "</div>"+
		     "</div>";//widget content
                     
   
   
       jQuery("#resultTop select").append( "<option selected value=\""+listName+"\">"+ listName +"</option>");
       jQuery("#listsAccordion").toggle("up");
       jQuery("#results").show();
       jQuery("#results").children().remove();
         	    		
      
        jQuery("#results").fadeTo("slow",1);
        jQuery( "#results").append( resHTML );
        
        
        jQuery( "#favorites" ).html( favoritesPrint );
        jQuery( "#favoritesInList" ).html( listPrint );
	jQuery( "#favorites"        ).css(    { "float":"left","margin-left":"10px","border":"1px solid #666666" } );
	jQuery( "#addToList"        ).css(    { "float":"left"});
	jQuery( "#remFromList"      ).css(    { "float":"left" });
	jQuery( "#favoritesInList"  ).css(    { "float":"left","width":"200px", "border":"1px solid #666666" } ); 
	jQuery( "#saveList"         ).css(    { "float":"left"                                               } );
	jQuery( "#closeList"         ).css(  { "float":"left"                                               } );
	
	

		  
	 if( this.allFavoritesArray.length == 0){ 
	 
	 
		     albumId = "NO"; 
		     albumName="FAVORITES FOUND";
		    jQuery("#selectFavoriteForListForm select").append( new Option( albumId+"_"+albumName ,i ) );
		      
		
	   }//end for i
	         
	         
	   else{  
		 
		 
		 for ( var i = 0; i< this.allFavoritesArray.length; i++ ){
		
		   var albumId   = this.allFavoritesArray[i].albumId;
		   var albumName = this.allFavoritesArray[i].albumName;
		   
		        var isInList = false;
		        
			for( var j=0; j< favoritesInList.length; j++ ){	
			
			   
		 		
		           if ( albumId == favoritesInList[j].albumId ){
		 
		 
		 	            isInList = true;
		 	           
		 	            break;
		 		
		 		
		             }//end if
		             
		 		       
		 	}//for j	
		 		
		       if( isInList){
		 		
		 		jQuery("#selectFavoriteForListForm select").append( new Option( albumId+" "+albumName , i ) );
		 		jQuery("#selectFavoriteForListForm option:eq("+i+")").css( {"opacity":"0.4","color":"green" } );
		 		jQuery("#favoritesInList select").append( new Option(  albumId+" "+albumName ,i ) );
		       }
		       else{
 		        
                                jQuery("#selectFavoriteForListForm select").append( new Option( albumId+" "+ albumName,i ) );
 		        
		 	}
		 		 
		 	
		
	           }//end for i
	 
          }//end else
       //*************END INIT PART ************************************************************************
       
       
       //EVENTS************************************************************************************
     
       //Hovers***************************************************************************************
       
       
       
       
       
       jQuery( "#selectFavoriteForListForm option" ).hover( function(){ 
       
                  							if( jQuery(this).css(  "opacity"  ) ==1 ){
                  							
                          						    jQuery(this).css( {"color":"orange"}  );
       		
                  							}//end if
                                                             } , 
                                                                        
                                                             function(){ 
                                                             
                                                                          jQuery(this).css( { "color":"black" } );
                                                                          
                                                               }   );//end hover
                                                                         
         
       jQuery( "#favoritesInList option" ).hover( function(){ 
	        
	                                                      	if( jQuery(this).css(  "opacity"  ) ==1 ){
	        	
	        	                                             jQuery(this).css( {"color":"green"}  );
	        		
	                                                         }//end if
	                                                                         
	                                            } , 
	                                            function(){ 
	                                                              
	                                                 jQuery(this).css( { "color":"black" } );
	                                                                           
	                                            }      );//end hover
         
         
          jQuery("#addToList").hover( function(){   jQuery(this).addClass   ("ui-state-hover") },
	 	  		      function(){   jQuery(this).removeClass("ui-state-hover") } );
	 	  	  
	 
	 	  		     
	   jQuery("#remFromList").hover( function(){   jQuery(this).addClass ("ui-state-hover") },
	 	                         function(){ jQuery(this).removeClass("ui-state-hover")   } );
	 	  		      
	 
	 
	  jQuery("#saveList    button").hover( function(){ jQuery(this).addClass(  "ui-state-hover") },
	 	 	  		      function(){ jQuery(this).removeClass("ui-state-hover") } );
	 	  		     
	 
	 
	 
	 
	  jQuery("#closeList    button").hover( function(){ jQuery(this).addClass("ui-state-hover") },
	 	 	  		        function(){ jQuery(this).removeClass("ui-state-hover") } );
	 	  		     
	 
	 
	 //Clicks*******************************************************************************************	  		      
	 	  		      
          jQuery( "#addToList" ).click( function(){                                                             
       	
       		       
       	     		var favArray = getAllFavoritesArray();
       		        var newFavArray = getAllFavoritesArray();
       	     	        
       	              
       	                	            
       	               jQuery('#selectFavoriteForListForm option:selected').each( function(i, selected){
		             
				if( jQuery(this).css('opacity') ==1 ){
				
				    
				     jQuery("#favoritesInList select").append( new Option( jQuery(this).text() ,i ) );
				     jQuery(this).css( {"opacity":"0.4","color":"green" } );

		               		         
		                }//if
		                
		             
	   		} ); //each
		          
		          
      
          	} );//end click
          	
          	
          	
	jQuery( "#remFromList" ).click( function(){                                                             
	       	
	       	       var newArray  = new Array();
		       var removeFromListArray = new Array();
		       var index;       	     	        
		              	              
		   jQuery('#favoritesInList option:selected').each( function(i, selected){
		       		             
		       	   albumID =  jQuery( this).text().split(" ")[0] ;
		     	   jQuery( '#selectFavoriteForListForm option' ).each( function(j, selected){
		       		  
		       	   
		       	  	if( albumID == jQuery(this).text().split(" ")[0] ){
		       		       
		       		       
		       		       jQuery(this).css( {"opacity":"1","color":"black" } );
		       	               jQuery("#favoritesInList option:eq("+i+")").remove();
		       		         
		       		         
		       		}//end if
		       		         
		       		             
		       	    } ); //each selectFavoriteForListForm
		             
		    
	           	} );//each favoritesInList
	           		
	           		
	} ); //end click
	           		
	           		
	jQuery( "#saveList button" ).click( function(){    
		  
		var favInList = "";
		jQuery("#favoritesInList option").each( function(){
		 	  	                          
		 	favInList+= jQuery(this).text().split(" ")[0] + "and";
		 	  	     
		 	  	 
	         } );//each
		 	  	 
		 	  
		 
		         
		 var pageUrl="http://www.ballroomlibrary.com/php/proxy.php?url=http://www.ballroomLibrary.com/managelistserver/AddListServlet"+
		 	     "%3FuserName%3D"+getCustomerInfo().id.replace("@","%40") +
		 	     "%26listName%3D"+listName+
		 	     "%26favoritesInList%3D"+favInList;
		 	                     
		 	  	initProgressDialog("Saving List");
		 	  		jQuery.ajax({
		 	  		
		 	  		  type:"POST",
		 	  		  url: pageUrl,
		 	  		  cache: false,
		 	  		  async: false,
		 	                  
		 	  		  success: function(html){
		 	  		    
		 	  		 
		 	  		    
		 	  		    hideProgressDialog();
                                            initConfirmDialog("List Saved");
		 	  		   
		 	  		  }//success
		 	  		  
		 	  		});//end ajax
		 	  		
		 	   	
		 	   	setCustomersLists();
		 	  
		 	  });//end click
	 
	
	
	
	
	
	             
		  jQuery( "#closeList button" ).click( function(){    
		     		 	  
		  jQuery("#results").children().remove();
		  jQuery("#results").fadeOut("slow");
		  jQuery("#listsAccordion").toggle("down");
		   jQuery("#listsAccordion").fadeTo('slow','1');
 	                 
		 	                                      } ); //click	
	
	
	
	
 }//edit list
 
 
 function createList(  listName ){

//***************INIT Part **********************************************************************


      
        jQuery("#listsAccordion").toggle("up");
       
             	
        this.allListsArray.push( listName );
        setListsOptions();
        jQuery("#listsAccordion").fadeTo('slow',1 );
        
        this.allFavoritesArray =    findFavoritesInList("allFavorites"); 
        
       
        var favoritesInList = new Array();
	var selectedArray = new Array(); 
	
	       
        
        
         var favoritesPrint = "<div id=\"favoriteFilter\" class=\"ui-widget ui-widget-content\">"+
	                            "Available Favorites "+
       "</div>"+
        "<div id=\"selectFavoriteForListForm\" class=\"ui-widget ui-widget-content\"  >"+
        "<select multiple=\"true\" class=\"ui-widget ui-widget-content ui-selectable\" size=\"20\"></select>"+
        "</div>";
      
		
	
	
	var listPrint = "<div class=\"ui-widget-header\">Favorites In List:<span style=\"margin-left:5px; background:#292929;color:orange\">"+listName+"</span></div>"+
		       	"<div id=\"favoritesInListForm\">"+
		       	"<select multiple=\"true\" class=\"ui-widget ui-widget-content ui-selectable\" size=\"20\">" ;
	       	        "</select></div>";
	       	                            
	       	
	var resHTML= "<div class=\"ui-widget ui-widget-header \">Search Results</div>"+
	                     "<div class=\"ui-widget-content\">"+
	                     "<div  id=\"favorites\" ></div>"+
	                     "<div  id=\"addToList\" class=\"ui-widget\" >"+
	                     "<span class=\"ui-widget-content ui-icon ui-icon-circle-arrow-e\" ></span>"+
	                     "</div>"+
	                     "<div id=\"remFromList\" class=\"ui-widget\""+
	                     "<span  class=\"ui-widget-content ui-icon ui-icon-circle-arrow-w\"></span>"+
	                     "</div>"+
	                     "<div  id=\"favoritesInList\" ></div>"+
	                     "<div id=\"saveList\" class=\"ui-widget ui-state-default\" >"+
     "<button  class=\"ui-state-default ui-corner-all\" value=\"save\">Save List</button>"+
     "</div>"+
     "<div id=\"closeList\" class=\"ui-widget ui-state-default\" >"+
     "<button  class=\"ui-state-default ui-corner-all\" value=\"close\">Close</button>"+
     "</div>"+
     "</div>";//widget content
	                     
	  
	   
	jQuery("#resultTop select").append( "<option selected value=\""+listName+"\">"+listName+"</option>");
	jQuery("#results").show();
	jQuery("#results").children().remove();
	jQuery("#results").fadeTo("slow",1);
	jQuery("#results").append( resHTML );
	        
	 jQuery( "#favorites" ).append( favoritesPrint );
	 jQuery( "#favoritesInList" ).append( listPrint );
	 jQuery( "#favorites"        ).css(    { "float":"left","width":"200px","background":"#292929","margin-left":"10px","border":"1px solid #666666" } );
	 jQuery( "#addToList"        ).css(    { "float":"left"});
	 jQuery( "#remFromList"      ).css(    { "float":"left" });
	 jQuery( "#favoritesInList"  ).css(    { "float":"left","width":"200px", "border":"1px solid #666666" } ); 
	 jQuery( "#saveList"         ).css(    { "float":"left"                                               } );
	 jQuery( "#cancelList"       ).css(    { "float":"left"     } );
		
		
	
 	 if( this.allFavoritesArray.length == 0){ 
				 
				  
				     alert( "No Favorites Found! \nAdd Some Favorites First!") ;
				     albumId = "NO"; 
				     albumName="FAVORITES FOUND";
				    jQuery("#selectFavoriteForListForm select").append( new Option( albumId+"_"+albumName ,i ) );
				      
				
	 }//end for i	
	           
	  else{  
		   for ( var i = 0; i< this.allFavoritesArray.length; i++ ){
		
		   var isInList = false;
		        for( var j=0; j< favoritesInList.length; j++ ){
		   
		   
		          if ( this.allFavoritesArray[i].albumId == favoritesInList[j].albumId ){
		          
		          
		       	          isInList = true;
 	                           break;
 	  
 	  
                             }//end if
  
 		 
 		
		           }//end for j
 		
		   if( isInList){
 		
 	               jQuery("#selectFavoriteForListForm select").append( new Option( this.allFavoritesArray[i].albumName, i ) );
	               jQuery("#selectFavoriteForListForm").children("option:eq("+i+")").css( {"opacity":"0.4","color":"white" } );
 	               jQuery("#favoritesInList select").append( new Option( this.allFavoritesArray[j].albumName ,i ) );
 	 
		    }
		     else{
 		
 	                     jQuery("#selectFavoriteForListForm select").append( new Option( this.allFavoritesArray[i].albumName,i ) );

 		  
		      }
 		
 	

		  }//en for i
		 
	 
	 
	 }//end else 
  //*************END INIT PART ************************************************************************
	       
	       
  //EVENTS************************************************************************************
	     
    //Hovers***************************************************************************************
	       
	       
	       
	       
	       
	       jQuery( "#selectFavoriteForListForm select").children("option" ).hover( function(){ 
	       
	                                                     	       
	                                                        if( jQuery(this).css(  "opacity"  ) ==1 ){
	       	
	       	
	       		 jQuery(this).css( {"color":"orange"}  );
	       		
	                                                                        	
	                                                                        	
	                                                         }//end if
	                                                                        
	                                                                        } , 
	                                                                        
	                                                          function(){ 
	                                                             
	                                                                          jQuery(this).css( { "color":"#292929" } );
	                                                                          
	                                                                         } 
	                                                                         
	                                                             );//end hover
	                                                                         
	         
	         
	         
	         jQuery( "#favoritesInList select").children("option" ).hover( function(){ 
		        
		        
		        
		        		if( jQuery(this).css(  "opacity"  ) ==1 ){
		        	
		        	
		        		 	jQuery(this).css( {"color":"green"}  );
		        		
		                                                                         	
		                                                                         	
		                                          	}//end if
		                                                                         
		                                                                         } , 
		                                                                         
		                                               function(){ 
		                                                              
		                                                                           jQuery(this).css( { "color":"white" } );
		                                                                           
		                                                              } 
		                                                                          
	                                                   );//end hover
	         
	         
	          jQuery("#addToList").hover( function(){   jQuery(this).addClass   ("ui-state-hover") },
		 	  		      function(){  jQuery(this).removeClass("ui-state-hover") } );
		 	  	  
		 
		 	  		     
		   jQuery("#remFromList").hover( function(){   jQuery(this).addClass   ("ui-state-hover") },
		 	   function(){ jQuery(this).removeClass("ui-state-hover") } );
		 	  		      
		 
		 
		  jQuery("#saveList    button").hover( function(){ jQuery(this).addClass("ui-state-hover") },
		 	 	  		      function(){ jQuery(this).removeClass("ui-state-hover") } );
		 	  		     
		 
		 
		 
		 
		  jQuery("#closeList    button").hover( function(){ jQuery(this).addClass("ui-state-hover") },
		 	 	  		     function(){ jQuery(this).removeClass("ui-state-hover") } );
		 	  		     
		 
		 
		 //Clicks*******************************************************************************************	  		      
		 	  		      
	          jQuery( "#addToList" ).click( function(){                                                             
	       	
	       		       
	       	     		var favArray = getAllFavoritesArray();
	       		        var newFavArray = getAllFavoritesArray();
	       	     	        
	       	              
	       	                	            
	       	               jQuery('#selectFavoriteForListForm option:selected').each( function(i, selected){
             
                 var index = ""+jQuery(selected).attr("value");
                 var newTitle = favArray[index].albumName;
                 
               		if( (jQuery.inArray( index, selectedArray )) == -1 ){
               		 
               		         
                		 selectedArray.push( index );
                		 jQuery("#selectFavoriteForListForm option:eq("+index+")").css( {"opacity":"0.4","color":"white" } );
	                         jQuery("#favoritesInList select").append( new Option( newTitle,index ) );
	 
                         }// end if

                  	 else{
                  	 
                  	 	alert( "\""+favArray[ index ].title  +"\" is in list already" ); 
                  	 
                  	 }
             
                   } ); //each
	      
	                       
	                     
	       		        
	       		       
	       		        
	           } );//end click
		
		
		  
		
		
		  jQuery( "#remFromList"         ).click( function(){                                                             
		       	
		       	       var newArray  = new Array();
       var removeFromListArray = new Array();
       var index;       	     	        
              	              
              	                	            
              jQuery('#favoritesInList option:selected').each( function(i, selected){
       		             
       		   
       		          index = jQuery(selected).val();
       		          jQuery("#selectFavoriteForListForm option:eq("+index+")").css( {"opacity":"1","color":"white" } );
       		          removeFromListArray.push( index );
       		         
       		             
       	       } ); //each
             
            var isRemoved;; 
            for (var i=0; i< selectedArray.length ; i++ ){
            
            
            	        isRemoved = false;
            		for( var j=0; j< removeFromListArray.length; j++ ){
            		
            		
            if( selectedArray[i] == removeFromListArray[j] ){
            
             
                    
                    isRemoved=true;
            	break;
            		
            		
            		        }//
            		        
            		
            		}//end for j
            	
            	        if( !isRemoved ){
            	        
            	        	
	;		            	        	
            	               newArray.push( selectedArray[i] );
            	               
            	
            		}
            		
            
            }//end for i
                            
             favArray = getAllFavoritesArray(); 		        
             selectedArray = newArray;
             jQuery('#favoritesInList option').remove();
             
                                                
             for( var i=0; i< selectedArray.length; i++ ){
             
             
                var newTitle =  favArray[ selectedArray[i] ].title;
                var index = selectedArray[i];
                
             	jQuery("#favoritesInList select").append( new Option( newTitle,index ) );
             
             }
	       		        
		                       
		                       
		           } );//end click
		
		
		
		
		
   jQuery( "#saveList button" ).click( function(){    
 	  
 	   	  
 	  	var favInList = "";
 	  	var favArray = getAllFavoritesArray();
 	  	var inList = new Array();
 	  	
 	  	jQuery("#favoritesInList option").each( 
 	  	
 	  	
 	  		function(){
 	  	                     
 	  	                     
 	  	                     var index =  jQuery(this).val();
 	  	         		favInList+= favArray[ index ].albumId+"and";
 	  	
 	  			}  );//each
 	  
 	    
 	       
 	  	var pageUrl="http://www.ballroomlibrary.com/php/proxy.php?url=http://www.ballroomLibrary.com/managelistserver/AddListServlet"+
 	                     "%3FuserName="+getCustomerInfo().id+"%26listName="+listName+
 	                     "%26favoritesInList="+favInList;
 	                  
 	               
 	  		initProgressDialog("Savig List");
 	  		
 	  		jQuery.ajax({
 	  		
 	  		  type:"POST",
 	  		  url: pageUrl,
 	  		   async: false,
 	                  
 	  		  success: function(html){
 	  		    
 	  		   hideProgressDialog();
 	  		    if( html.indexOf("ok")!= -1 ){
 	  		    
 	  		         
	                         initConfirmDialog( "List Saved" );
	                         
	                    }
	                    else{
	                    
	                    
	                       initConfirmDialog("Error:List Not Saved!");
	                       
	                     }//rnd else
 	  		   
 	  		  }//function
 	  		  
 	  		});//end ajax
 	  		
 	   	
 	   	setCustomersLists();
 	   	
 	  
 	  });//end click
		 
		
		
		
		
		
		             
  jQuery( "#closeList button" ).click( function(){    
     		 	  
 	                 jQuery("#results").children().remove();
 	                 jQuery("#results").fadeOut("slow");
 	                 jQuery("#listsAccordion").toggle("down");
 	                 jQuery("#listsAccordion").fadeTo('slow','1');
 	                 
 	  
 	  
 	  }//function
 	  
 	  
		
		);//click
		
		
		
		
	
        
	
	
	
 }//create list


function deleteList( listName ){

	
	var pageUrl="http://www.ballroomlibrary.com/php/proxy.php?url=http://www.ballroomLibrary.com/managelistserver/DeleteListServlet"+
 	                     "%3FuserName%3D"+getCustomerInfo().id+
 	                     "%26listName%3D"+listName;
 	                     
 	                 initProgressDialog( "Deleting List" );    
 	  		
 	  		jQuery.ajax({
 	  		
 	  		  type:"POST",
 	  		  url: pageUrl,
 	  		  cache: false,
 	  		  async: false,
 	  
 	  		  success: function(html){
 	  		  
 	  		    hideProgressDialog();
 	  		    initConfirmDialog( "List " +listName+" Deleted ");
 	  		    jQuery("#accordion").fadeIn("slow");
 	  		    jQuery("#accordion").fadeTo("slow",1);
 	  		    setCustomersLists();
 	  		   

 	  		     
 	  		   
 	  		  }//function
 	  		  
 	  		});//end ajax
 	  		
 	   	
		 	   	


}//end delete

   
 


function parseLists( text){

	var resultArray = text.split( "<listItem>");
	this.allListsArray= new Array();
	
		for ( var i=1; i< resultArray.length; i++ ){
		
  this.allListsArray.push( resultArray[i].split("</listItem>")[0]  );
		
		
		}//end for
		
		
}//end parseLiats




function renameList( oldName, newName ){

        initProgressDialog( "Saving Changes");
        var pageUrl="http://www.ballroomlibrary.com/php/proxy.php?url=http://www.ballroomLibrary.com/managelistserver/RenameListServlet"+
	                   "%3FuserName%3D"+getCustomerInfo().id+
	                   "%26oldName%3D"+oldName+
	                   "%26newName%3D"+newName;
	                   
		 var favoritesInListArray = new Array();
		 
   jQuery.ajax({
      url: pageUrl,
      cache: false,
      async: false,
	                  type:"post",
      success: function(html){
    
         hideProgressDialog();
         initConfirmDialog("Changes Saved");
         setCustomersLists();
        
   
    
    
  }//success
  
});
	
	      
      

}//end renameList










