

function showRecipients(max3Title,sentTo)
{
	var recipients = sentTo.split(',');
	var msg = "The max3 '"+max3Title+"' was sent to the following recipients:\r\n";
	msg = msg + recipients.join(',\r\n');
	alert(msg);
}

/**
 * Called when a max3 is to be downloaded.
 * Hides download icon as appropriate according to number of downloads remaining.
 *
 * @param A       a     A element.
 * @param string  url   URL to use to download max3.
 * @param string  num   Number of download element.
 */
function downloadMax3(url, num)
{
   var elem = document.getElementById('numDownloads' + num)
   var numDownloads = 0;
   var allow = false;

   if (elem)
   {
      numDownloads = parseInt(elem.value);
	  
      if (numDownloads)
      {
         numDownloads--;
         allow = true;
         elem.value = numDownloads;
         elem = document.getElementById('link' + num);

         if (elem)
         {
            elem.title = numDownloads + ' downloads remaining.';
         }
      }
   }
	
   if (numDownloads <= 0)
   {
      elem = document.getElementById('link' + num);

      if (elem)
      {
         elem.style.display = 'none';
      }
   }

   if (allow)
   {
      document.location = url;
   }
}

function toggleContents(elementid)
{
	var elem;
	elem = document.getElementById(elementid);
	if(elem.style.display == 'none')
			elem.style.display = '';
	else
			elem.style.display = 'none';
}

/**
	Following function composes a comma separated string from the options added in the Send to drop down on
	forward max3 page and assigns that string to the hidden variable 'sendTo'
*/
function composeSendToList()
{
	var reciverList = document.getElementById('reciverList');
	var emailIds = Array();
	var contactIds = Array();
	for(var i=0;i<reciverList.options.length;i++)
	{
		emailIds[i] = reciverList.options[i].id;
		contactIds[i] = reciverList.options[i].value;
	}
	document.getElementById('sendTo').value = emailIds.join(",");
	document.getElementById('selectedRecivers').value = contactIds.join(",");
		
}

/**
 * Updates the contact select box depending on what genre is selected.
 *
 * @param INPUT   input             Input that has genres that are selected.
 * @param Array   contacts          Array of contacts.
 * @param Array   contactsByGenre   Array of contacts for each genre.
 */
function updateContacts(input, contacts, contactsByGenre)
{
   
   var elem = document.getElementById('contactIds');
   if (elem)
   {
      // start from scratch.
      removeChildren(elem);

      if (input.value)
      {
         if (input.value in contactsByGenre)
         {
            // selected a genre - add all contacts for that genre..
            for (var j = 0; j < contactsByGenre[input.value].length; j++)
            {
               if (contactsByGenre[input.value][j] in contacts && !optionPresentIn('reciverList',contactsByGenre[input.value][j]))
               {
                  var i = contactsByGenre[input.value][j];
                  var option = document.createElement('option');
                  option.value = i;
				  option.id = contacts[i].email;
                  //option.setAttribute('ondblclick', "addContactToSendTo(this, '" + contacts[i].name + "', '" + contacts[i].email + "');");
		  option.setAttribute('ondblclick', "shiftSelectedItems('contactIds','reciverList');composeSendToList();");
                  elem.appendChild(option);
                  
                  option.appendChild(document.createTextNode(contacts[i].name+'<'+(contacts[i].email)+'>'));
               }
            }
         }

         if (!elem.length)
         {
            var option = document.createElement('option');
            elem.appendChild(option);

            option.appendChild(document.createTextNode('- no contacts for genre -'));
	    option.value= '';
         }
      }
      else
      {
         // no genre - add all contacts.
         for (var i in contacts)
         {
	    if(!optionPresentIn('reciverList',i) && contacts[i].email)
	    {
	
			 var option = document.createElement('option');
			 option.value = i;
			 option.id = contacts[i].email;
			//option.setAttribute('ondblclick', "addContactToSendTo(this, '" + contacts[i].name + "', '" + contacts[i].email + "');");
			option.setAttribute('ondblclick', "shiftSelectedItems('contactIds','reciverList');composeSendToList();");	
			elem.appendChild(option);
			
			option.appendChild(document.createTextNode(contacts[i].name+'<'+(contacts[i].email)+'>'));
			 }
         }

         if (!elem.length)
         {
            var option = document.createElement('option');
            elem.appendChild(option);

            option.appendChild(document.createTextNode('- add contacts below -'));
	    option.value= '';	
         }
      }
   }
}


function openForwardMail(subject,body)
{
	//Get the email addresses from the SendTo list.
	
	var emailIds = trim(document.getElementById('sendTo').value);
    if(emailIds=='')
    {
        smdAlert("SMD Alert", "<span class='formerror'>Please specify the recipients.</span>"); 
        return false;
    }
    
	var to = document.getElementById('sendTo').value;
	var subject = subject;
	var cc = '';
	var bcc = '';
	var body = '';
	sendMailThroughClient(to,cc,bcc,subject,body)
}

function sendMailThroughClient(subject,body)
{          
    location.href = "mailto:?Subject=" + escape(subject) + "&Body=" + escape(body);     
}

/*
function sendMailThroughClient(to,cc,bcc,subject,body)
{
	var mailIds = to.split(",");
	var emails = Array();
	if(mailIds[0])
	{
		
		for(var i = 0;i<mailIds.length;i++)
		{
			emails[i] = trim(mailIds[i]);
		}
					
		
		
	}
	window.location.href = "mailto:"+(emails.join(","))+"?Subject=" + escape(subject) + "&Body=" + escape(body);
	
}
*/

function createForwardMax3Elink()
{
	//Get the email addresses from the SendTo list.
	var emailIds = trim(document.getElementById('sendTo').value);

	if(emailIds=='')
	{
		smdAlert("SMD Alert", "<span class='formerror'>Please specify the recipients.</span>");
		return false;
	}
	return true;

}


/*
functions used in the MV forward page.1
*/

function centerMsgDivMV()
{
	var pageScrollStats = getScrollStats();
	var windowWidth = GetWindowWidth();
	var windowHeight = GetWindowHeight();
	document.getElementById('msgDiv').style.top = ''+(pageScrollStats[1]+(windowHeight*0.20))+'px';
	document.getElementById('msgDiv').style.left = ''+(pageScrollStats[0]+(windowWidth*0.20))+'px';
}


function centerMsgDivMVElink()
{
	var pageScrollStats = getScrollStats();
	var windowWidth = GetWindowWidth();
	var windowHeight = GetWindowHeight();
	document.getElementById('msgDiv').style.top = ''+(pageScrollStats[1]+(windowHeight*0.80))+'px';
	document.getElementById('msgDiv').style.left = ''+(pageScrollStats[0]+(windowWidth*0.20))+'px';
}

function updateForwardId(strElink,strResponse)
{
	document.getElementById('forwardid').value = strResponse;
	document.getElementById('max3ELink').value = strElink + strResponse;
    document.getElementById('max3ELink').select();
	if (window.clipboardData)
		document.getElementById('copyclip').innerHTML = 'Link is copied to clipboard';
	copyToClipboard(document.getElementById('max3ELink').value);
}


function addContactItem(response,idMessage,idname,idemail,to,from){
		
		var strname = document.getElementById(idname).value;	
		var stremail = document.getElementById(idemail).value;	
		var strMessage;
		if(response == -2)
        {
			strMessage = "<span class='formerror'>This contact already exists.</span>";
        }
		else if(response == -1)
			strMessage = "<span class='formerror'>Insufficient data while adding contact.</span>";
		else if(response == -3)
			strMessage = "<span class='formerror'>Please enter valid contact details.</span>";
		else if(response > 0)
		{	
			strMessage = "<span class='notice'>New contact added successfully.</span>";
			var toDD = document.getElementById(to);	
			toDD.options[toDD.options.length] = new Option(strname + '<' + stremail + '>',response);
			toDD.options[toDD.options.length-1].setAttribute('id', stremail);			
			toDD.setAttribute('OnDblClick', "shiftSelectedItems('"+to+"','"+from+"');composeSendToList();");
		}
		//document.getElementById(idMessage).innerHTML = strMessage;
        document.getElementById(idMessage).innerHTML = '';
        smdAlert('SMD Alert', strMessage);
}
/*
end of functions used in the MV forward page.1
*/

function loadBuyerContent(actionName, queryString)
{          
        setCursorStyle('wait');
        $('indicator').innerHTML = 'loading data...please wait...';
        var url = '/agent.php/musiclover/' + actionName + queryString;
        
        new Ajax.Updater('buyerContent', url,
                        {               
                            asynchronous:true,
                            evalScripts:true, 
                            onComplete:function(request,json)
                                {
                                    setCursorStyle('default');
                                                                 
                                }                             
                        }
                      );

}

function loadBuyerContentUploaderPaging(actionName, queryString)
{       
        var assetCheck=getSelectedCheckbox();
        setCursorStyle('wait');
        $('indicator').innerHTML = 'loading data...please wait...';
        var url = '/max3/' + actionName + queryString +'&assetCheck='+assetCheck;
        new Ajax.Updater('buyerContent', url,
												{               
													asynchronous:true,
													evalScripts:true, 
													method:'get',
													onComplete:function(request,json)
														{
															setCursorStyle('default');
																						 
														}                             
												}
                         );

}

function loadBuyerContentUploader(actionName, queryString)
{       
        
        setCursorStyle('wait');
        $('indicator').innerHTML = 'loading data...please wait...';
        var url = '/max3/' + actionName + queryString;
        new Ajax.Updater('buyerContent', url,
												{               
													asynchronous:true,
													evalScripts:true, 
													onComplete:function(request,json)
														{
															setCursorStyle('default');
																						 
														}                             
												}
                         );

}

function loadBuyerContentUploaderNew(actionName, queryString)
{       
        var assetCheck = getSelectedCheckbox();
        setCursorStyle('wait');
        $('indicator').innerHTML = 'loading data...please wait...';
        var url = '/max3/' + actionName + queryString +'&assetCheck='+assetCheck;
        new Ajax.Updater('buyerContent', url,
												{               
													asynchronous:true,
													evalScripts:true, 
													method:'get',
													onComplete:function(request,json)
														{
															setCursorStyle('default');
																						 
														}                             
												}
                         );

}


function showSavedMax3DeletConfirmation(actionName, queryString)
 {          	    
     document.getElementById('savedMax3DeleteConfirmationBox').style.display = '';
     document.getElementById('savedMax3DeleteConfirmationBox').style.zIndex = '9000';
     
     if( screen.width > 1024  )
     {
      document.getElementById('savedMax3DeleteConfirmationBox').style.marginLeft = '-150px';  
     }
     
     if(navigator.appName != "Microsoft Internet Explorer")
     {
        disableUserActions();    
     }
                     
     document.getElementById('max3DeleteConfirmed').onclick = function()
                                                                {                                                                                                                                                                                                            
                                                                    var t = new Effect.Fade('savedMax3DeleteConfirmationBox',{});
                                                                    loadBuyerContent(actionName, queryString); 
																	enableUserActions(); 
                                                                    return false;
                                                                }
     centerDiv('savedMax3DeleteConfirmationBox');  
 }

 function showSavedPlaylistDeletConfirmation(actionName, queryString)
 {          	    
     document.getElementById('savedPlaylistDeleteConfirmationBox').style.display = '';
     document.getElementById('savedPlaylistDeleteConfirmationBox').style.zIndex = '9000';
     
     if( screen.width > 1024  )
     {
      document.getElementById('savedPlaylistDeleteConfirmationBox').style.marginLeft = '-150px';  
     }
     
     if(navigator.appName != "Microsoft Internet Explorer")
     {
        disableUserActions();    
     }
                     
     document.getElementById('max3DeleteConfirmed').onclick = function()
                                                                {                                                                                                                                                                                                            
                                                                    var t = new Effect.Fade('savedPlaylistDeleteConfirmationBox',{});
                                                                    loadBuyerContent(actionName, queryString); 
																	enableUserActions(); 
                                                                    return false;
                                                                }
     centerDiv('savedPlaylistDeleteConfirmationBox');  
 }

/* This function is written for deleting content from asset folder alert box */
 function showAssetUploadDeletConfirmation(actionName, queryString)
 {          	    
     document.getElementById('assetUploaderDeleteConfirmationBox').style.display = '';
     document.getElementById('assetUploaderDeleteConfirmationBox').style.zIndex = '9000';
     
     if( screen.width > 1024  )
     {
      document.getElementById('assetUploaderDeleteConfirmationBox').style.marginLeft = '-150px';  
     }
     
     if(navigator.appName != "Microsoft Internet Explorer")
     {
        disableUserActions();    
     }
                     
     document.getElementById('max3DeleteConfirmed').onclick = function()
                                                                {                                                                                                                                                                                                            
                                                                    var t = new Effect.Fade('assetUploaderDeleteConfirmationBox',{});
                                                                    loadBuyerContentUploader(actionName, queryString); 
																	enableUserActions(); 
                                                                    return false;
                                                                }
     centerDiv('assetUploaderDeleteConfirmationBox');  
 }

 /* This function is written for deleting content from asset folder alert box */
 function showStep1AssetDeletConfirmation(actionName, queryString)
 {          	    
     document.getElementById('assetUploaderDeleteConfirmationBox').style.display = '';
     document.getElementById('assetUploaderDeleteConfirmationBox').style.zIndex = '9000';
     
     if( screen.width > 1024  )
     {
      document.getElementById('assetUploaderDeleteConfirmationBox').style.marginLeft = '-150px';  
     }
     
     if(navigator.appName != "Microsoft Internet Explorer")
     {
        disableUserActions();    
     }
                     
     document.getElementById('max3DeleteConfirmed').onclick = function()
                                                                {                                                                                                                                                                                                            
                                                                    var t = new Effect.Fade('assetUploaderDeleteConfirmationBox',{});
                                                                    loadBuyerContentUploader(actionName, queryString); 
																	enableUserActions(); 
                                                                    return false;
                                                                }
     centerDiv('assetUploaderDeleteConfirmationBox');  
 }
 

function old_showSavedMax3DeletConfirmation(actionName, queryString)
 {      
   
     document.getElementById('savedMax3DeleteConfirmationBox').style.display = '';
     centerDiv('savedMax3DeleteConfirmationBox');
     var eff = new Effect.Shake('savedMax3DeleteConfirmationBox',{});
        
     document.getElementById('max3DeleteConfirmed').onclick = function()
                                                                {
                                                                    this.blur();
                                                                    var t = new Effect.Fade('savedMax3DeleteConfirmationBox',{});
                                                                    loadBuyerContent(actionName, queryString);                                                                       
                                                                    return false;
                                                                }
 
 }


function showSavedMax3DeletConfirmation(actionName, queryString)
 {          	    
     document.getElementById('savedMax3DeleteConfirmationBox').style.display = '';
     
     if( screen.width > 1024  )
     {
      document.getElementById('savedMax3DeleteConfirmationBox').style.marginLeft = '-150px';  
     }
     
     if(navigator.appName != "Microsoft Internet Explorer")
     {
        disableUserActions();    
     }
              
     document.getElementById('max3DeleteConfirmed').onclick = function()
                                                                {                                                                                                                                                                                                            
                                                                    var t = new Effect.Fade('savedMax3DeleteConfirmationBox',{});
                                                                    loadBuyerContent(actionName, queryString); 
																	enableUserActions(); 
                                                                    return false;
                                                                }
     centerDiv('savedMax3DeleteConfirmationBox');  
 }
 
function fnShowSentTo(strForwardId,strPath)
 {
    openPopup(strPath+'/musiclover/showSentTo?fid='+strForwardId, 'Recipients', 450, 300, 1);
 }
 
 function showHide( obj)
 {    
  
    if(obj.checked)
     {
      if(document.getElementById('producerAccount')) {
		  document.getElementById('producerAccount').style.display = ''
	  }
       if(document.getElementById('musicLoverAccount')) {
		   document.getElementById('musicLoverAccount').style.display = 'none';       
	   }
       if(document.getElementById('leftBox')) {
		   document.getElementById('leftBox').style.display = '';  
	   }
       
     }
    else
     {
		if(document.getElementById('producerAccount')) {
			document.getElementById('producerAccount').style.display = 'none';
		}
		 if(document.getElementById('musicLoverAccount')) {
		       document.getElementById('musicLoverAccount').style.display = ''
		 }
		 if(document.getElementById('leftBox')) {
			document.getElementById('leftBox').style.display = 'none'; 
		 }
     } 
 }
 
 /**
 * Called when a max3 is to be downloaded.
 * Hides download icon as appropriate according to number of downloads remaining.
 *
 * @param A       a     A element.
 * @param string  url   URL to use to download max3.
 * @param string  num   Number of download element.
 */
function downloadPurchaseMax3(url, num)
{
    
   var elem = document.getElementById('numDownloads' + num)
   var numDownloads = 0;
   var allow = false;
   
   $('max3DownloadDiv').innerHTML = '';

   if (elem)
   {
      numDownloads = parseInt(elem.value);
      
      if (numDownloads)
      {
         numDownloads--;
         allow = true;
         elem.value = numDownloads;
         elem1 = document.getElementById('link' + num);

         if (elem1)
         {
            elem1.title = numDownloads + ' downloads remaining.';
         }
      }
   }
    
   if (numDownloads <= 0)
   {
      elem2 = document.getElementById('link' + num);
     
      if (elem2)
      {
         elem2.style.display = 'none';
      } 
     
      $('msgDownloadDiv'+ num).innerHTML = "no downloads <br /> remaining";
      $('msgDownloadDiv'+ num).style.display = 'block';
      
   }

   if (allow)
   {
      document.location = url; 
	  /**
      var loadingImage = '<img src="/images/loadingStar.gif" alt="Loading..." title="Loading..." />';
      new Ajax.Updater('max3DownloadDiv',url,
                 {
                   asynchronous:true, 
                   evalScripts:true,                   
                   onComplete:function()
                              { 
                                
                                turnOffProcessIndicator(); 
                                if($('max3DownloadDiv').innerHTML) {                          
                                     numDownloads++;  
                                    
                                     elem.value = numDownloads;
                                    //elem = document.getElementById('link' + num);

                                     if (elem1)
                                     {
                                        elem1.title = numDownloads + ' downloads remaining.';
                                     }
                                } 
                                 
                                waitAndInitScrollLayer(700);                                                             
                              },
                   onFailed: function() { turnOffProcessIndicator(); smdAlert('Download Error', '<span class="error">Request Failed. Please try again.</span>'); },
                   onLoading:function()
                            {turnOnProcessIndicator('<span class="notice">Requesting download...please wait..</span>');  }
                 }
                );  
		*/
   
     
   }
}

/**
* @desc Function fnGetScreenName() - This function will return a screen name for the user
*/
function fnGetMusicloverScreenName( userEmail )
{
   var domainName = document.domain;  
   var url = '/musiclover/musicloverScreenName?userEmail='+ userEmail;  
   //$('screenName').innerHTML = '<div style="width: 100%;text-align: center;position: absolute; top: 50%;display: table-cell; vertical-align: middle;">Loading screen name....</div>';
   new Ajax.Updater('screenName',url,
                 {
                   asynchronous:true, 
                   evalScripts:true, 
                   onComplete:function(request, json)
                              { 
									$('screenName').innerHTML = request.responseText;
                              }    
                 }
                );
}
/* end of fnGetScreenName() function */
 