﻿ //global vars 
 var songStatus="";
 function playListToolBarClick(obj,buttonTdId,divId)
   {
     
        var div=parent.document.getElementById(divId);
         var divButton = parent.document.getElementById(buttonTdId);
        if(div.style.display=='none')
        {
         var x = findPosX(obj);
         var y = findPosY(obj);
      
         div.style.display='block';
           div.style.top = y-div.offsetHeight;
         div.style.left = x-2;
         
         divButton.style.backgroundColor='white';
        }
        else 
        {
        div.style.display='none';
        divButton.style.backgroundColor='';  
        } 
        
   }
   function CloseDiv(buttonTdId,divId)
   {
     var div=parent.document.getElementById(divId);
     var divButton = parent.document.getElementById(buttonTdId);
     div.style.display='none';
      divButton.style.backgroundColor='';  
      if(divId=="divPlayList")
         parent.playlistButtonClick=false;
   }
    //event handler for main tool bar button click
    function  ToolBarClick(obj,buttonTdId,divId)
   {
     
      
        var div=parent.document.getElementById(divId);
         var divButton = parent.document.getElementById(buttonTdId);
                if(div.style.display=='none')
                    {
                         div.style.display='block';
                         divButton.style.backgroundColor='#DCDCDC';
                        
                    }
                else 
                    {
                        div.style.display='none';
                        divButton.style.backgroundColor='';  
                    }   
        //set only one window open 
        switch (divId)
        {
            case "divPlayList":
                {
                    parent.document.getElementById('divSendSong').style.display = 'none';
                    parent.document.getElementById('tdToolBarSendSong').style.backgroundColor = '';
                    //set playlist button click flag - to handler the show up  timers
                    if (div.style.display == 'block') {
                        parent.playlistButtonClick = true;
                        parent.$get('tdToolBarPlayList').backgroundColor = '#DCDCDC';
                    }
                    else if (div.style.display == 'none') {
                    parent.playlistButtonClick = false;
                    parent.$get('tdToolBarPlayList').style.backgroundColor = ''; 
                    }

                }
                break;
                case "divSendSong" : {
                                       parent.document.getElementById('divPlayList').style.display='none' ;
                                       parent.document.getElementById('tdToolBarPlayList').style.backgroundColor='';
                                       parent.playlistButtonClick=false;
                                     } 
                                     break;
        }//end switch  
      
     
   };
    function OpenSendThisSongDiv()
   { 
       parent.document.getElementById('tableSendSongNoContent').style.display='none';
       parent.document.getElementById('tableSendSongContent').style.display='none';
       var artistImage= parent.document.getElementById('imgSendSongSongImage');
       var artistName=parent.document.getElementById('spanSendSongArtistName');
       var songName=parent.document.getElementById('spanSendSongSongName');
   if (currentSong!=null)
   {
       artistImage.src=currentSong.image;
       artistName.innerHTML=currentSong.description ; 
       songName.innerHTML=currentSong.author;
       }
   else 
   {
       parent.document.getElementById('tableSendSongNoContent').style.display='block';
       parent.document.getElementById('tableSendSongContent').style.display='none';
      
   }
   //check if user is loggedin 
    if (currentSong!=null)
   {
    parent.PageMethods.CheckLoggedUser(CheckLoggedUserSendThisSongSucceedHandler,CheckLoggedUserSendThisSongFailedHandler);
    parent.document.getElementById('tableSendSongPleaseWait').style.display='block';
   }
}
 

  
   //send this song div Button click event Handler 
   function SendThisSongClickButton()
 {
 
   
         //for logged in user - Jumbey will send the song
          if (userLogedIn)
          {
             if (RequiredFieldValidatorEmailSong.isvalid&&RegularExpressionValidatorEmailAddress.isvalid)
             {
                    var sendtoemail = parent.document.getElementById('TextBoxEmailSong').value;
                
                     var morecontext = parent.document.getElementById('TextBoxSendSongAdditionalData').value;
                     UpdateProgressDiv("Please Wait - sending song",0);
                     parent.document.getElementById('spanSendThisSongStatus').innerHTML= 'Sending ...'; 
                     parent.PageMethods.SendThisSong(currentSong.id,sendtoemail,1,morecontext,SendThisSongSucceededHandler,SendThisSongFailedHandler);
              }
          }
          else  //for anonymous user - the song will sent by his localmail acount 
          {
          var daReferrer = document.referrer;
 
 
           var body_message = "http://www.jumbey.com/SendSongPage.aspx?songid=" + currentSong.id + "\&widgetid=1" ;
            var subject = "You have recived the song: |" + currentSong.title + "| from Jumbey.com";
            var mailto_link = 'mailto:?subject='+subject+'&body='+body_message; 
            win = window.open(mailto_link,'emailWindow'); 
          }
         
          
      
 }
