

<div id="actions">
	
	<ul id="for_messages">
		<li id="action_contact_new" title="<?php echo $this->translate("New Contact") ?>"><a href="#" tabindex="0"><span><strong><?php print $this->translate('New Contact')?></strong></span></a></li>
		<li id="action_contact_newgroup" title="<?php echo $this->translate("New Group") ?>"><a href="#" tabindex="0"><span><strong><?php print $this->translate('New Group')?></strong></span></a></li>
		<li id="action_contact_edit" title="<?php echo $this->translate("Edit") ?>"><a href="#" tabindex="0"><span><strong><?php print $this->translate('Edit')?></strong></span></a></li>
		<li id="action_contact_delete" title="<?php echo $this->translate("Delete") ?>"><a href="#" tabindex="0"><span><strong><?php print $this->translate('Delete')?></strong></span></a></li>
		<li id="action_contact_mail" title="<?php echo $this->translate("Mail") ?>"><a href="#" tabindex="0"><span><strong><?php print $this->translate('Mail')?></strong></span></a></li>
		<li id="action_contact_import" title="<?php echo $this->translate("Import") ?>"><a href="#" tabindex="0"><span><strong><?php print $this->translate('Import')?></strong></span></a></li>
		<li id="action_contact_export" title="<?php echo $this->translate("Export") ?>"><a href="#" tabindex="0"><span><strong><?php print $this->translate('Export')?></strong></span></a></li>
		<li id="action_share_contacts" title="<?php echo $this->translate("Share") ?>"><a href="#" tabindex="0"><span><strong><?php print $this->translate('Share')?></strong></span></a></li>
		
		<li id="action_view_sync" title="<?php echo $this->translate("Help") ?>"><a href="#" tabindex="0"><span><strong><?php print $this->translate('Help')?></strong></span></a></li>
	</ul>

	<!-- <ul id="jsddm" class="move-contacts-button">
		<li id="action_more_contacts" title="Share Contacts"><a id="move-contacts-dropdown" class="moredrop" href="#" tabindex="0"><span><strong><?php print $this->translate('More')?><span class="arrow">▼</span></strong></span></a>
			<ul class="menu_drop_more">
			 <li id='action_more_sendcontacts' class="bottom"><a href="#" tabindex="0"><?php print $this->translate('Send Contact(s)')?></a></li>
			</ul>
		</li>
	</ul> -->
	
<!-- <ul id="jsddm">
    <li id="action_share_contacts" title="<?php echo $this->translate("More") ?>"><a class="moredrop" id="move-contacts-dropdown" href="#" tabindex="0"><span><strong><?php print $this->translate('More')?><span class="arrow">▼</span></strong></span></a>
      <ul class="menu_drop_more">
        <li id='action_more_sharecontact'><a href="#"  id="shareContactButton" tabindex="0"><?php print $this->translate('Share Contact(s)')?></a></li>
       
      </ul>
    </li>
  </ul>	 -->

	<ul id="jsddm">
    <li id="action_more_contacts" title="<?php echo $this->translate("More") ?>"><a class="moredrop" href="#" tabindex="0"><span><strong><?php print $this->translate('More')?><span class="arrow">▼</span></strong></span></a>
      <ul class="menu_drop_more">
        <li id='action_more_selectall'><a href="#" tabindex="0"><?php print $this->translate('Select All')?></a></li>
        <li id='action_more_deselectall'><a href="#" tabindex="0"><?php print $this->translate('Deselect')?></a></li>
        <li id='action_more_exportall' class="bottom"><a href="#" tabindex="0"><?php print $this->translate('Export All')?></a></li>
      </ul>
    </li>
  </ul>	
	
</div>

<div id="primary">
	<div id="primary_header">
		<h1><?php print $this->translate('Contacts'); ?> <span id='abookstatus'></span></h1>
	</div>
	<div id="contact-hold">
		<div id="primary_content">
			<div id="primary_content_inner">
				<div id="address_contacts">
					<?php echo $this->render('contacts/listcontacts.phtml'); ?>
				</div>
			</div>
			<div id="contact_info">
				<?php if( !$this->addNewContact ) : ?>
				<?php echo $this->render('contacts/viewcontact.phtml'); ?>
				<?php endif; ?>
			</div>
		</div>
	</div>
</div>

<div id="secondary">
<?php echo $this->render('contacts/listgroups.phtml'); ?>
</div>


<script type="text/javascript" language="JavaScript">

$(function() {
	$('#Address_Book #jsddm > li').bind('mousedown', jsddm_open);
//	$('#Address_Book #jsddm > li').bind('mouseover', jsddm_open)
//	$('#Address_Book #jsddm > li').bind('mouseout',  jsddm_timer)
	
	//$('a.contactLink').bind("dblclick", function() { return editContactDblClick($('#contact_table:first')) } );
	$('#action_contact_edit a').bind("click", function() { $(this).blur(); return editContactDblClick() } );
	$('#action_contact_delete a').bind("click", function() {  $(this).blur(); return deleteContact($('#contact_table:first')); } );
	$('#action_contact_new a').bind("click", function() {  $(this).blur(); return newContact(false, true) } );
	$('#action_contact_export a').bind("click", function() {  $(this).blur(); return exportContact() } );
	$("#action_view_sync a", "#Address_Book").bind('click', function(e) { 
		e.preventDefault();
		e.stopPropagation();
		openHelp('contacts'); 
	});
	$('#action_more_contacts a').keydown(function(e){
		if(e.which == ENTER_KEY){
			e.preventDefault();
			e.stopPropagation();
			$(e.target).parent().mousedown();
		}
	});
	
	
	// Bind for the new Email button
	$('#action_share_contacts').bind('click', function()
    {
        openNewComposerTab();
        $('.menu_drop').hide();
    			}).bind('keydown',function(e){
        if(e.which==ENTER_KEY){
				  e.stopPropagation();
					e.preventDefault();
					$(this).click();
					jsddm_close();
				}
		});
		
	// More menu
	$('#action_more_selectall a').bind("keydown",function(e){ 
		if(e.which==ENTER_KEY){
			e.stopPropagation();
			selectAll();
			$('#action_more_contacts:first').focus();
			$(this).css('outline','none');
			return false; 
		}
	});
	$('#action_more_selectall a').bind("mousedown", function(e) { e.stopPropagation(); return selectAll(); } );
	$('#action_more_deselectall a').bind("keydown",function(e){
		if(e.which==ENTER_KEY){ 
			e.stopPropagation();
			return deselectAll();
		}
	});
	$('#action_more_deselectall a').bind("mousedown", function(e) { e.stopPropagation(); return deselectAll(); } );
	$('#action_more_exportall a').bind("keydown", function(e){ if(e.which==ENTER_KEY){  $(this).blur(); e.stopPropagation(); $(this).click(); }});
	$('#action_more_exportall a').bind("click", function() { deselectAll(); return exportContact() } );

	// Mail button
	$('#action_contact_mail a').bind("click", function() {  $(this).blur(); return emailSelected(); } );

	$('#action_contact_import a').unbind().bind("click", function(e) {
		e.preventDefault();
		e.stopPropagation();
		$('.attach-holder>input[name=ImportFile]').click();
		return false;
	});
	
	//$('#searchQuery').bind("keyup", function() { return searchAbook(this) } );
	
	var search_timeout = undefined;
	resetDroppables();	
	
	// Configure Ajax uploader for image
	new AjaxUpload('#action_contact_import', 
	{
		// Location of the server-side upload script
		action: "<?php echo $this->moduleBaseUrl ?>/contacts/import",
		// File upload name
		name: 'ImportFile',
		// Additional data to send
		//parent: $('#Address_Book #actions'),

		addClass: 'import-holder',
		
		autoSubmit: true,
		onChange: function(file, extension){ },
		onSubmit: function(file, extension) 
		{
			//alert(extension);
			if (! (extension && /^(vcf|vcard|txt)$/.test(extension)))
			{
				// extension is not allowed
				alert('<?php echo addslashes($this->translate("Error: Invalid file extension - Please upload a Vcard/VCF file")) ?>');
				// cancel upload
				return false;
			}
			this.setData({'GroupID': $('li.current', '#Address_Book').attr('groupid')});
		},
	
		// Fired when file upload is completed
		// @param file basename of uploaded file
		// @param response server response
		onComplete: function(file, response) 
		{
			//alert(response);
			if( response == '' )
				return;

			$.simpleFlash(response, 'notice');

			$.jCacher.remove('autocomplete');
			$.jCacher.remove('autocomplete_global');
			
			added = response.split(' <?php print addslashes($this->translate('contacts added.')) ?>');
			if(added.length > 0)
				added = parseInt(added[0]);
			else
				added = 0;
				
			duplicates = response.split(' <?php print addslashes($this->translate('duplicate entries skipped.')) ?>');
			if(duplicates.length > 0)
				duplicates = parseInt(duplicates[0]);
			else
				duplicates = 0;
	
			if(added)
				$('li[GroupName=All] .unread strong').updateCount( added );
			setTimeout( "$.php('<?php echo $this->moduleBaseUrl ?>/contacts/viewcontacts/GroupID/' + $('li.current', '#Address_Book').attr('groupid'))", 800);

		 }
	})
	<?php if( $this->addNewContact ) : ?>
	newContact(false,true);
	<?php endif; ?>

  $('.move-contacts-button')
		.unbind('click')
		.unbind('keydown')
		.bind('click',setMovableGroupsMenu)
		.keydown(function(e){ if(e.which===ENTER_KEY){ setMovableGroupsMenu }});
	
	setMovableGroupsMenu();
	setContactsContextTabOrder();
	$("#skip-link").focus();
});


function moveContacts(){
  jsddm_close();
  var grpid = $(this).attr('data-group-id');
	if($('.contactRow:checked', '#Address_Book').size() > 0){
  	$.php(moduleBaseUrl + '/contacts/addcontacttogroup/GroupID/' + grpid, $("#listcontacts:first").serializeArray())
	}
}

function setMovableGroupsMenu(){
  var $menu = $('.move-contacts-button li:first ul:first');
  $menu.empty();
  $('#nav_secondary li[groupid]')
    .filter( function(){ return $(this).attr('groupid') > 0 } )
    .each(function(i,group){
      var name = $(group).attr('groupname');
      var gpid = $(group).attr('groupid');
      var btn  = $('<a tabindex="0" href="#">'+name+'</a>')
                  .bind('click',moveContacts)
                  .attr('data-group-id',gpid)
									.css('overflow','visible');

      var li   = $('<li></li>').css('overflow','visible').append(btn);
      $menu.append(li);
  });
  $menu.find(':last').addClass('bottom');
	
	setContactsContextTabOrder();
  // $('#action_move_contacts').css('display','inline-block');
}

// $('#nav_add :first-child').focus();
// setFocusableElements();
</script>
<div id="draggableContactsContainer" style="position:absolute;"></div>


