diff --git a/apps/contacts/ajax/deletecard.php b/apps/contacts/ajax/deletecard.php
index e26dfd6ebfebc20fc2f498b029cb37803cc59284..5675aef5f15143d1ca5ade32a2a6b161a644d426 100644
--- a/apps/contacts/ajax/deletecard.php
+++ b/apps/contacts/ajax/deletecard.php
@@ -19,6 +19,11 @@
  * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
  *
  */
+function bailOut($msg) {
+	OC_JSON::error(array('data' => array('message' => $msg)));
+	OC_Log::write('contacts','ajax/saveproperty.php: '.$msg, OC_Log::DEBUG);
+	exit();
+}
 
 // Init owncloud
 require_once('../../../lib/base.php');
@@ -27,7 +32,10 @@ require_once('../../../lib/base.php');
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('contacts');
 
-$id = $_GET['id'];
+$id = isset($_GET['id'])?$_GET['id']:null;
+if(!$id) {
+	bailOut(OC_Contacts_App::$l10n->t('id is not set.'));
+}
 $card = OC_Contacts_App::getContactObject( $id );
 
 OC_Contacts_VCard::delete($id);
diff --git a/apps/contacts/js/contacts.js b/apps/contacts/js/contacts.js
index e1827027453c0436e1f16216e4ca36fba6ef265c..d314878cc0a0d89ebccfd7ed451dd4b0142efe9a 100644
--- a/apps/contacts/js/contacts.js
+++ b/apps/contacts/js/contacts.js
@@ -213,19 +213,27 @@ Contacts={
 			honpre:'',
 			honsuf:'',
 			data:undefined,
-			update:function() {
+			update:function(id) {
 				// Make sure proper DOM is loaded.
-				console.log('Card.update(), #n: ' + $('#n').length);
+				var newid;
+				console.log('Card.update(), id: ' + id);
 				console.log('Card.update(), #contacts: ' + $('#contacts li').length);
-				if($('#n').length == 0 && $('#contacts li').length > 0) {
+				if(id == undefined) {
+					newid = $('#contacts li:first-child').data('id');
+				} else {
+					newid = id;
+				}
+				if($('#contacts li').length > 0) {
 					$.getJSON(OC.filePath('contacts', 'ajax', 'loadcard.php'),{},function(jsondata){
 						if(jsondata.status == 'success'){
 							$('#rightcontent').html(jsondata.data.page);
 							Contacts.UI.loadHandlers();
 							if($('#contacts li').length > 0) {
-								var firstid = $('#contacts li:first-child').data('id');
-								console.log('trying to load: ' + firstid);
-								$.getJSON(OC.filePath('contacts', 'ajax', 'contactdetails.php'),{'id':firstid},function(jsondata){
+								//var newid = $('#contacts li:first-child').data('id');
+								//$('#contacts li:first-child').addClass('active');
+								$('#leftcontent li[data-id="'+newid+'"]').addClass('active');
+								console.log('trying to load: ' + newid);
+								$.getJSON(OC.filePath('contacts', 'ajax', 'contactdetails.php'),{'id':newid},function(jsondata){
 									if(jsondata.status == 'success'){
 										Contacts.UI.Card.loadContact(jsondata.data);
 									} else{
@@ -300,35 +308,49 @@ Contacts={
 					}
 				});
 			},
-			delete: function() {
+			delete:function() {
 				$('#contacts_deletecard').tipsy('hide');
-				$.getJSON('ajax/deletecard.php',{'id':this.id},function(jsondata){
-					if(jsondata.status == 'success'){
-						$('#leftcontent [data-id="'+jsondata.data.id+'"]').remove();
-						$('#rightcontent').data('id','');
-						//$('#rightcontent').empty();
-						this.id = this.fn = this.fullname = this.shortname = this.famname = this.givname = this.addname = this.honpre = this.honsuf = '';
-						this.data = undefined;
-						// Load first in list.
-						if($('#contacts li').length > 0) {
-							Contacts.UI.Card.update();
-						} else {
-							// load intro page
-							$.getJSON('ajax/loadintro.php',{},function(jsondata){
-								if(jsondata.status == 'success'){
-									id = '';
-									$('#rightcontent').data('id','');
-									$('#rightcontent').html(jsondata.data.page);
+				OC.dialogs.confirm(t('contacts', 'Are you sure you want to delete this contact?'), t('contacts', 'Warning'), function(answer) {
+					if(answer == true) {
+						$.getJSON('ajax/deletecard.php',{'id':Contacts.UI.Card.id},function(jsondata){
+							if(jsondata.status == 'success'){
+								var newid = '';
+								var curlistitem = $('#leftcontent [data-id="'+jsondata.data.id+'"]');
+								var newlistitem = curlistitem.prev();
+								console.log('Previous: ' + newlistitem);
+								if(newlistitem == undefined) {
+									newlistitem = curlistitem.next();
 								}
-								else{
-									OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
+								curlistitem.remove();
+								if(newlistitem != undefined) {
+									newid = newlistitem.data('id');
 								}
-							});
-						}
-					}
-					else{
-						OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
-						//alert(jsondata.data.message);
+								$('#rightcontent').data('id',newid);
+								//$('#rightcontent').empty();
+								this.id = this.fn = this.fullname = this.shortname = this.famname = this.givname = this.addname = this.honpre = this.honsuf = '';
+								this.data = undefined;
+								// Load first in list.
+								if($('#contacts li').length > 0) {
+									Contacts.UI.Card.update(newid);
+								} else {
+									// load intro page
+									$.getJSON('ajax/loadintro.php',{},function(jsondata){
+										if(jsondata.status == 'success'){
+											id = '';
+											$('#rightcontent').data('id','');
+											$('#rightcontent').html(jsondata.data.page);
+										}
+										else{
+											OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
+										}
+									});
+								}
+							}
+							else{
+								OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
+								//alert(jsondata.data.message);
+							}
+						});
 					}
 				});
 				return false;
@@ -1232,6 +1254,7 @@ $(document).ready(function(){
 	 */
 	$('#leftcontent li').live('click',function(){
 		var id = $(this).data('id');
+		$(this).addClass('active');
 		var oldid = $('#rightcontent').data('id');
 		if(oldid != 0){
 			$('#leftcontent li[data-id="'+oldid+'"]').removeClass('active');
diff --git a/apps/contacts/templates/part.contact.php b/apps/contacts/templates/part.contact.php
index a93069fa7227dcb514168309db93ec2b95fa2028..7e6dedb843b22e378cfae76b1340a8095890c89c 100644
--- a/apps/contacts/templates/part.contact.php
+++ b/apps/contacts/templates/part.contact.php
@@ -131,6 +131,7 @@ $(document).ready(function(){
 	if('<?php echo $id; ?>'!='') {
 		$.getJSON(OC.filePath('contacts', 'ajax', 'contactdetails.php'),{'id':'<?php echo $id; ?>'},function(jsondata){
 			if(jsondata.status == 'success'){
+				$('#leftcontent li[data-id="<?php echo $id; ?>"]').addClass('active');
 				Contacts.UI.Card.loadContact(jsondata.data);
 			}
 			else{