diff --git a/CRM/Batch/Form/Batch.php b/CRM/Batch/Form/Batch.php
index 3af565e66a13c428cbd0c4e81bb43717d9f4f777..58e4f33abf46e7e81305265aed5ef12cf842d81a 100644
--- a/CRM/Batch/Form/Batch.php
+++ b/CRM/Batch/Form/Batch.php
@@ -63,7 +63,7 @@ class CRM_Batch_Form_Batch extends CRM_Admin_Form {
     $attributes = CRM_Core_DAO::getAttribute('CRM_Batch_DAO_Batch');
     $this->add('text', 'title', ts('Batch Name'), $attributes['name'], TRUE);
 
-    $batchTypes = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'type_id');
+    $batchTypes = CRM_Batch_BAO_Batch::buildOptions('type_id');
 
     // unset non-related types
     unset($batchTypes[3]);
@@ -96,8 +96,6 @@ class CRM_Batch_Form_Batch extends CRM_Admin_Form {
     else {
       $defaults = $this->_values;
     }
-
-
     return $defaults;
   }
 
diff --git a/CRM/Batch/Form/Entry.php b/CRM/Batch/Form/Entry.php
index 39c0be96ef11e38523e788242c74626e24c4fddc..505b7d2dd59136ec67b2c710da3ec25017521ce4 100644
--- a/CRM/Batch/Form/Entry.php
+++ b/CRM/Batch/Form/Entry.php
@@ -100,14 +100,18 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form {
       $params = array('id' => $this->_batchId);
       CRM_Batch_BAO_Batch::retrieve($params, $this->_batchInfo);
 
-      $this->assign('batchTotal', $this->_batchInfo['total']);
+      $this->assign('batchTotal', !empty($this->_batchInfo['total']) ? $this->_batchInfo['total'] : NULL);
       $this->assign('batchType', $this->_batchInfo['type_id']);
 
       // get the profile id associted with this batch type
       $this->_profileId = CRM_Batch_BAO_Batch::getProfileId($this->_batchInfo['type_id']);
     }
     CRM_Core_Resources::singleton()
-    ->addSetting(array('batch' => array('type_id' => $this->_batchInfo['type_id'])));
+    ->addScriptFile('civicrm', 'templates/CRM/Batch/Form/Entry.js')
+    ->addSetting(array('batch' => array('type_id' => $this->_batchInfo['type_id'])))
+    ->addSetting(array('setting' => array('monetaryThousandSeparator' => CRM_Core_Config::singleton()->monetaryThousandSeparator)))
+    ->addSetting(array('setting' => array('monetaryDecimalPoint' => CRM_Core_Config::singleton()->monetaryDecimalPoint)));
+
   }
 
   /**
@@ -202,7 +206,8 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form {
 
       foreach ($this->_fields as $name => $field) {
         if (in_array($field['field_type'], $contactTypes)) {
-          $this->_contactFields[$field['name']] = 1;
+          $fld = explode('-', $field['name']);
+          $contactReturnProperties[$field['name']] = $fld[0];
         }
         CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, NULL, FALSE, FALSE, $rowNumber);
 
@@ -213,7 +218,11 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form {
     }
 
     $this->assign('fields', $this->_fields);
-    $this->assign('contactFields', $this->_contactFields);
+    CRM_Core_Resources::singleton()
+    ->addSetting(array('contact' => array(
+      'return' => implode(',', $contactReturnProperties),
+      'fieldmap' => array_flip($contactReturnProperties),
+    )));
 
     // don't set the status message when form is submitted.
     $buttonName = $this->controller->getButtonName('submit');
diff --git a/CRM/Campaign/Page/AJAX.php b/CRM/Campaign/Page/AJAX.php
index eb36cfab6c8b256fce949ac127b3dbdfb254af1c..1aa7f363d5dc98a4c26c0d4ab2abbf451a80a511 100644
--- a/CRM/Campaign/Page/AJAX.php
+++ b/CRM/Campaign/Page/AJAX.php
@@ -432,7 +432,7 @@ class CRM_Campaign_Page_AJAX {
           $activityParams['skipRecentView'] = 1;
           $activityParams['activity_date_time'] = date('YmdHis');
           $activityParams['activity_type_id'] = $activityTypeId;
-          $activityParams['campaign_id'] = $surveyValues['campaign_id'];
+          $activityParams['campaign_id'] = isset($surveyValues['campaign_id']) ? $surveyValues['campaign_id'] : NULL;
 
           $activity = CRM_Activity_BAO_Activity::create($activityParams);
           if ($activity->id) {
diff --git a/CRM/Member/Page/AJAX.php b/CRM/Member/Page/AJAX.php
index e93814df79c84df8b06b721fbc27ad76db2221f3..83707e4b67e8e30172f2ec7799422c327129a6a5 100644
--- a/CRM/Member/Page/AJAX.php
+++ b/CRM/Member/Page/AJAX.php
@@ -67,7 +67,7 @@ WHERE   id = %1";
     // fix the display of the monetary value, CRM-4038
     $details['total_amount'] = CRM_Utils_Money::format($details['total_amount'], NULL, '%a');
     $options = array(ts('No auto-renew option'), ts('Give option, but not required'), ts('Auto-renew required '));
-    $details['auto_renew'] = $options[$details['auto_renew']];
+    $details['auto_renew'] = CRM_Utils_Array::value('auto_renew', $options[$details]);
     echo json_encode($details);
     CRM_Utils_System::civiExit();
   }
diff --git a/api/api.php b/api/api.php
index 76637548ce14bd15f3499bf7737436abe82c2364..60d95f63a2d16ad8e0e10342ac19ac4e6bbe752a 100644
--- a/api/api.php
+++ b/api/api.php
@@ -123,7 +123,12 @@ function civicrm_api($entity, $action, $params, $extra = NULL) {
       $data["sql"] = $error->getDebugInfo();
     }
     if (CRM_Utils_Array::value('debug', $apiRequest['params'])) {
-      $data['debug_info'] = $error->getUserInfo();
+      if(method_exists($e, 'getUserInfo')) {
+        $data['debug_info'] = $error->getUserInfo();
+      }
+      if(method_exists($e, 'getExtraData')) {
+        $data['debug_info'] = $data + $error->getExtraData();
+      }
       $data['trace'] = $e->getTraceAsString();
     }
     else{
diff --git a/templates/CRM/Batch/Form/Entry.js b/templates/CRM/Batch/Form/Entry.js
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..6268ea446b56f652e4c154a6cb21a0e6a1243598 100644
--- a/templates/CRM/Batch/Form/Entry.js
+++ b/templates/CRM/Batch/Form/Entry.js
@@ -0,0 +1,343 @@
+//@todo functions partially moved from tpl but still need an enclosure / cleanup
+// jslinting etc
+cj(function () {
+  cj('.selector-rows').change(function () {
+    var options = {
+      'url': CRM.url('civicrm/ajax/batch')
+    };
+
+    cj("#Entry").ajaxSubmit(options);
+
+    // validate rows
+    checkColumns(cj(this));
+  });
+
+  cj('input[name^="soft_credit_contact["]').change(function(){
+    var rowNum = cj(this).attr('id').replace('soft_credit_contact_','');
+    var totalAmount = cj('#field_'+rowNum+'_total_amount').val();
+    //assign total amount as default soft credit amount
+    cj('#soft_credit_amount_'+ rowNum).val(totalAmount);
+  });
+
+  // validate rows
+  validateRow();
+
+  //calculate the actual total for the batch
+  calculateActualTotal();
+
+  cj('input[id*="_total_amount"]').bind('keyup change', function () {
+    calculateActualTotal();
+  });
+
+  if (CRM.batch.type_id == 1) {
+    // hide all dates if send receipt is checked
+    hideSendReceipt();
+
+    // hide the receipt date if send receipt is checked
+    cj('input[id*="][send_receipt]"]').change(function () {
+      showHideReceipt(cj(this));
+    });
+
+  }
+  else{
+    cj('select[id^="member_option_"]').each(function () {
+      if (cj(this).val() == 1) {
+        cj(this).attr('disabled', true);
+      }
+    });
+
+  // set payment info accord to membership type
+  cj('select[id*="_membership_type_0"]').change(function () {
+    setPaymentBlock(cj(this), null);
+  });
+
+  cj('select[id*="_membership_type_1"]').change(function () {
+    setPaymentBlock(cj(this), cj(this).val());
+  });
+
+  }
+
+  // line breaks between radio buttons and checkboxes
+  cj('input.form-radio').next().after('<br />');
+  cj('input.form-checkbox').next().after('<br />');
+
+  //set the focus on first element
+  cj('#primary_contact_1').focus();
+
+});
+
+
+function updateContactInfo(blockNo, prefix) {
+  var contactHiddenElement = 'input[name="' + prefix + 'contact_select_id[' + blockNo + ']"]';
+  var contactId = cj(contactHiddenElement).val();
+
+  var profileFields = CRM.contact.fieldmap;
+
+  CRM.api('Contact', 'get', {
+      'sequential': '1',
+      'contact_id': contactId,
+      'return': CRM.contact.return },
+    { success: function (data) {
+      cj.each(data.values[0], function (key, value) {
+        // set the values
+        var actualFldName = profileFields[key];
+        if (key == 'country' || key == 'state_province') {
+          idFldName = key + '_id';
+          value = data.values[0][idFldName];
+        }
+        setFieldValue(actualFldName, value, blockNo)
+      });
+
+      // for membership batch entry based on contact we need to enable / disable
+      // add membership select
+      if(CRM.batch.type_id == 2) {
+      CRM.api('Membership', 'get', {
+          'sequential': '1',
+          'contact_id': contactId,
+        },
+        { success: function (data) {
+          if (data.count > 0) {
+            //get the information on membership type
+            var membershipTypeId = data.values[0].membership_type_id;
+            var membershipJoinDate = data.values[0].join_date;
+            CRM.api('MembershipType', 'get', {
+                'sequential': '1',
+                'id': membershipTypeId
+              },
+              { success: function (data) {
+                var memTypeContactId = data.values[0].member_of_contact_id;
+                cj('select[id="member_option_' + blockNo + '"]').removeAttr('disabled').val(2);
+                cj('select[id="field_' + blockNo + '_membership_type_0"]').val(memTypeContactId).change();
+                cj('select[id="field_' + blockNo + '_membership_type_1"]').val(membershipTypeId).change();
+                setDateFieldValue('join_date', membershipJoinDate, blockNo)
+              }
+              });
+          }
+        }
+        });
+      }
+    }
+    });
+}
+
+function setPaymentBlock(form, memType) {
+  var rowID = form.closest('div.crm-grid-row').attr('entity_id');
+  var dataUrl = CRM.url('civicrm/ajax/memType');
+
+  if (!memType) {
+    memType = cj('select[id="field_' + rowID + '_membership_type_1"]').val();
+  }
+
+  cj.post(dataUrl, {mtype: memType}, function (data) {
+    cj('#field_' + rowID + '_financial_type').val(data.financial_type_id);
+    cj('#field_' + rowID + '_total_amount').val(data.total_amount).change();
+  }, 'json');
+}
+
+function hideSendReceipt() {
+  cj('input[id*="][send_receipt]"]').each(function () {
+    showHideReceipt(cj(this));
+  });
+}
+
+function showHideReceipt(elem) {
+  var rowID = elem.closest('div.crm-grid-row').attr('entity_id');
+  if (elem.prop('checked')) {
+    cj('.crm-batch-receipt_date-' + rowID).hide();
+  }
+  else {
+    cj('.crm-batch-receipt_date-' + rowID).show();
+  }
+}
+
+function validateRow() {
+  cj('.selector-rows').each(function () {
+    checkColumns(cj(this));
+  });
+}
+
+function checkColumns(parentRow) {
+  // show valid row icon if all required data is field
+  var validRow = 0;
+  var inValidRow = 0;
+  var errorExists = false;
+  var rowID = parentRow.closest('div.crm-grid-row').attr('entity_id');
+
+  parentRow.find('div .required').each(function () {
+    //special case to handle contact autocomplete select
+    var fieldId = cj(this).attr('id');
+    if (fieldId.substring(0, 16) == 'primary_contact_') {
+      // if display value is set then make sure we also check if contact id is set
+      if (!cj(this).val()) {
+        inValidRow++;
+      }
+      else {
+        if (cj(this).val() && !cj('input[name="primary_contact_select_id[' + rowID + ']"]').val()) {
+          inValidRow++;
+          errorExists = true;
+        }
+      }
+    }
+    else {
+      if (!cj(this).val()) {
+        inValidRow++;
+      }
+      else {
+        if (cj(this).hasClass('error') && !cj(this).hasClass('valid')) {
+          errorExists = true;
+        }
+        else {
+          validRow++;
+        }
+      }
+    }
+  });
+
+  // this means user has entered some data
+  if (errorExists) {
+    parentRow.find("div:first span").prop('class', 'batch-invalid');
+  }
+  else {
+    if (inValidRow == 0 && validRow > 0) {
+      parentRow.find("div:first span").prop('class', 'batch-valid');
+    }
+    else {
+      parentRow.find("div:first span").prop('class', 'batch-edit');
+    }
+  }
+}
+
+function calculateActualTotal() {
+  var total = 0;
+  cj('input[id*="_total_amount"]').each(function () {
+    if (cj(this).val()) {
+      total += parseFloat(cj(this).val());
+    }
+  });
+
+  cj('.batch-actual-total').html(formatMoney(total));
+}
+
+//money formatting/localization
+function formatMoney(amount) {
+  var c = 2;
+  var t = CRM.setting.monetaryThousandSeparator;
+  var d = CRM.setting.monetaryDecimalPoint;
+
+  var n = amount,
+    c = isNaN(c = Math.abs(c)) ? 2 : c,
+    d = d == undefined ? "," : d,
+    t = t == undefined ? "." : t, s = n < 0 ? "-" : "",
+    i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
+    j = (j = i.length) > 3 ? j % 3 : 0;
+
+  return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
+}
+
+/**
+ * This function is use to setdefault elements via ajax
+ *
+ * @param fname string field name
+ * @return void
+ */
+function setFieldValue(fname, fieldValue, blockNo) {
+  var elementId = cj('[name="field[' + blockNo + '][' + fname + ']"]');
+
+  if (elementId.length == 0) {
+    elementId = cj('input[type=checkbox][name^="field[' + blockNo + '][' + fname + ']"][type!=hidden]');
+  }
+
+  // if element not found than return
+  if (elementId.length == 0) {
+    return;
+  }
+
+  //check if it is date element
+  var isDateElement = elementId.attr('format');
+
+  // check if it is wysiwyg element
+  var editor = elementId.attr('editor');
+
+  //get the element type
+  var elementType = elementId.attr('type');
+
+  // set the value for all the elements, elements needs to be handled are
+  // select, checkbox, radio, date fields, text, textarea, multi-select
+  // wysiwyg editor, advanced multi-select ( to do )
+  if (elementType == 'radio') {
+    if (fieldValue) {
+      elementId.filter("[value=" + fieldValue + "]").prop("checked", true);
+    }
+    else {
+      elementId.removeProp('checked');
+    }
+  }
+  else {
+    if (elementType == 'checkbox') {
+      // handle checkbox
+      elementId.removeProp('checked');
+      if (fieldValue) {
+        cj.each(fieldValue, function (key, value) {
+          cj('input[name="field[' + blockNo + '][' + fname + '][' + value + ']"]').prop('checked', true);
+        });
+      }
+    }
+    else {
+      if (editor) {
+        switch (editor) {
+          case 'ckeditor':
+            var elemtId = elementId.attr('id');
+            oEditor = CKEDITOR.instances[elemtId];
+            oEditor.setData(htmlContent);
+            break;
+          case 'tinymce':
+            var elemtId = element.attr('id');
+            tinyMCE.get(elemtId).setContent(htmlContent);
+            break;
+          case 'joomlaeditor':
+          // TO DO
+          case 'drupalwysiwyg':
+          // TO DO
+          default:
+            elementId.val(fieldValue);
+        }
+      }
+      else {
+        elementId.val(fieldValue);
+      }
+    }
+  }
+
+  // since we use different display field for date we also need to set it.
+  // also check for date time field and set the value correctly
+  if (isDateElement && fieldValue) {
+    setDateFieldValue(fname, fieldValue, blockNo)
+  }
+}
+
+function setDateFieldValue(fname, fieldValue, blockNo) {
+  var dateValues = fieldValue.split(' ');
+
+  var actualDateElement = cj('#field_' + blockNo + '_' + fname);
+  var date_format = actualDateElement.attr('format');
+  var altDateFormat = 'yy-mm-dd';
+
+  var actualDateValue = cj.datepicker.parseDate(altDateFormat, dateValues[0]);
+
+  // format date according to display field
+  var hiddenDateValue = cj.datepicker.formatDate('mm/dd/yy', actualDateValue);
+
+  actualDateElement.val(hiddenDateValue);
+
+  var displayDateValue = actualDateElement.val();
+  if (date_format != 'mm/dd/yy') {
+    displayDateValue = cj.datepicker.formatDate(date_format, actualDateValue);
+  }
+
+  cj('#field_' + blockNo + '_' + fname + '_display').val(displayDateValue);
+
+  // need to fix time formatting
+  if (dateValues[1]) {
+    cj('#field_' + blockNo + '_' + fname + '_time').val(dateValues[1].substr(0, 5));
+  }
+}
diff --git a/templates/CRM/Batch/Form/Entry.tpl b/templates/CRM/Batch/Form/Entry.tpl
index 29c8527e05c2c8f0e676f8b024e5a620adacf053..b8ce7f0127ce731f5dd9438c658ab040928af8c9 100644
--- a/templates/CRM/Batch/Form/Entry.tpl
+++ b/templates/CRM/Batch/Form/Entry.tpl
@@ -101,367 +101,6 @@
   </div>
   <div class="crm-submit-buttons">{if $fields}{$form._qf_Batch_refresh.html}{/if} &nbsp; {$form.buttons.html}</div>
 </div>
-{literal}
-<script type="text/javascript">
-cj(function () {
-  cj('.selector-rows').change(function () {
-    var options = {
-      'url': CRM.url('civicrm/ajax/batch')
-    };
-
-    cj("#Entry").ajaxSubmit(options);
-
-    // validate rows
-    checkColumns(cj(this));
-  });
-
-  cj('input[name^="soft_credit_contact["]').change(function(){
-    var rowNum = cj(this).attr('id').replace('soft_credit_contact_','');
-    var totalAmount = cj('#field_'+rowNum+'_total_amount').val();
-    //assign total amount as default soft credit amount
-    cj('#soft_credit_amount_'+ rowNum).val(totalAmount);
-  });
-
-  // validate rows
-  validateRow();
-
-  //calculate the actual total for the batch
-  calculateActualTotal();
-
-  cj('input[id*="_total_amount"]').bind('keyup change', function () {
-    calculateActualTotal();
-  });
-
-  if (CRM.batch.type_id == 1) {
-    // hide all dates if send receipt is checked
-    hideSendReceipt();
-
-    // hide the receipt date if send receipt is checked
-    cj('input[id*="][send_receipt]"]').change(function () {
-      showHideReceipt(cj(this));
-    });
-
-  }
-  else{
-    cj('select[id^="member_option_"]').each(function () {
-      if (cj(this).val() == 1) {
-        cj(this).attr('disabled', true);
-      }
-    });
-
-  // set payment info accord to membership type
-  cj('select[id*="_membership_type_0"]').change(function () {
-    setPaymentBlock(cj(this), null);
-  });
-
-  cj('select[id*="_membership_type_1"]').change(function () {
-    setPaymentBlock(cj(this), cj(this).val());
-  });
-
-  }
-
-  // line breaks between radio buttons and checkboxes
-  cj('input.form-radio').next().after('<br />');
-  cj('input.form-checkbox').next().after('<br />');
-
-  //set the focus on first element
-  cj('#primary_contact_1').focus();
-
-});
-
-function setPaymentBlock(form, memType) {
-  var rowID = form.closest('div.crm-grid-row').attr('entity_id');
-  var dataUrl = CRM.url('civicrm/ajax/memType');
-
-  if (!memType) {
-    memType = cj('select[id="field_' + rowID + '_membership_type_1"]').val();
-  }
-
-  cj.post(dataUrl, {mtype: memType}, function (data) {
-    cj('#field_' + rowID + '_financial_type').val(data.financial_type_id);
-    cj('#field_' + rowID + '_total_amount').val(data.total_amount).change();
-  }, 'json');
-}
-
-function hideSendReceipt() {
-  cj('input[id*="][send_receipt]"]').each(function () {
-    showHideReceipt(cj(this));
-  });
-}
-
-function showHideReceipt(elem) {
-  var rowID = elem.closest('div.crm-grid-row').attr('entity_id');
-  if (elem.prop('checked')) {
-    cj('.crm-batch-receipt_date-' + rowID).hide();
-  }
-  else {
-    cj('.crm-batch-receipt_date-' + rowID).show();
-  }
-}
-
-function validateRow() {
-  cj('.selector-rows').each(function () {
-    checkColumns(cj(this));
-  });
-}
-
-function checkColumns(parentRow) {
-  // show valid row icon if all required data is field
-  var validRow = 0;
-  var inValidRow = 0;
-  var errorExists = false;
-  var rowID = parentRow.closest('div.crm-grid-row').attr('entity_id');
-
-  parentRow.find('div .required').each(function () {
-    //special case to handle contact autocomplete select
-    var fieldId = cj(this).attr('id');
-    if (fieldId.substring(0, 16) == 'primary_contact_') {
-      // if display value is set then make sure we also check if contact id is set
-      if (!cj(this).val()) {
-        inValidRow++;
-      }
-      else {
-        if (cj(this).val() && !cj('input[name="primary_contact_select_id[' + rowID + ']"]').val()) {
-          inValidRow++;
-          errorExists = true;
-        }
-      }
-    }
-    else {
-      if (!cj(this).val()) {
-        inValidRow++;
-      }
-      else {
-        if (cj(this).hasClass('error') && !cj(this).hasClass('valid')) {
-          errorExists = true;
-        }
-        else {
-          validRow++;
-        }
-      }
-    }
-  });
-
-  // this means user has entered some data
-  if (errorExists) {
-    parentRow.find("div:first span").prop('class', 'batch-invalid');
-  }
-  else {
-    if (inValidRow == 0 && validRow > 0) {
-      parentRow.find("div:first span").prop('class', 'batch-valid');
-    }
-    else {
-      parentRow.find("div:first span").prop('class', 'batch-edit');
-    }
-  }
-}
-
-function calculateActualTotal() {
-  var total = 0;
-  cj('input[id*="_total_amount"]').each(function () {
-    if (cj(this).val()) {
-      total += parseFloat(cj(this).val());
-    }
-  });
-
-  cj('.batch-actual-total').html(formatMoney(total));
-}
-
-//money formatting/localization
-function formatMoney(amount) {
-  var c = 2;
-  var t = '{/literal}{$config->monetaryThousandSeparator}{literal}';
-  var d = '{/literal}{$config->monetaryDecimalPoint}{literal}';
-
-  var n = amount,
-    c = isNaN(c = Math.abs(c)) ? 2 : c,
-    d = d == undefined ? "," : d,
-    t = t == undefined ? "." : t, s = n < 0 ? "-" : "",
-    i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
-    j = (j = i.length) > 3 ? j % 3 : 0;
-
-  return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
-}
-
-function updateContactInfo(blockNo, prefix) {
-  var contactHiddenElement = 'input[name="' + prefix + 'contact_select_id[' + blockNo + ']"]';
-  var contactId = cj(contactHiddenElement).val();
-
-  var returnProperties = '';
-  var profileFields = new Array();
-  {/literal}
-  {if $contactFields}
-  {foreach from=$contactFields item=val key=fldName}
-  var fldName = "{$fldName}";
-  {literal}
-  if (returnProperties) {
-    returnProperties = returnProperties + ',';
-  }
-  var fld = fldName.split('-');
-  returnProperties = returnProperties + fld[0];
-  profileFields[fld[0]] = fldName;
-  {/literal}
-  {/foreach}
-  {/if}
-  {literal}
-
-  CRM.api('Contact', 'get', {
-      'sequential': '1',
-      'contact_id': contactId,
-      'return': returnProperties },
-    { success: function (data) {
-      cj.each(data.values[0], function (key, value) {
-        // set the values
-        var actualFldName = profileFields[key];
-        if (key == 'country' || key == 'state_province') {
-          idFldName = key + '_id';
-          value = data.values[0][idFldName];
-        }
-        setFieldValue(actualFldName, value, blockNo)
-      });
-
-      // for membership batch entry based on contact we need to enable / disable
-      // add membership select
-      if(CRM.batch.type_id == 2) {
-      CRM.api('Membership', 'get', {
-          'sequential': '1',
-          'contact_id': contactId,
-        },
-        { success: function (data) {
-          if (data.count > 0) {
-            //get the information on membership type
-            var membershipTypeId = data.values[0].membership_type_id;
-            var membershipJoinDate = data.values[0].join_date;
-            CRM.api('MembershipType', 'get', {
-                'sequential': '1',
-                'id': membershipTypeId
-              },
-              { success: function (data) {
-                var memTypeContactId = data.values[0].member_of_contact_id;
-                cj('select[id="member_option_' + blockNo + '"]').removeAttr('disabled').val(2);
-                cj('select[id="field_' + blockNo + '_membership_type_0"]').val(memTypeContactId).change();
-                cj('select[id="field_' + blockNo + '_membership_type_1"]').val(membershipTypeId).change();
-                setDateFieldValue('join_date', membershipJoinDate, blockNo)
-              }
-              });
-          }
-        }
-        });
-      }
-    }
-    });
-}
-
-/**
- * This function is use to setdefault elements via ajax
- *
- * @param fname string field name
- * @return void
- */
-function setFieldValue(fname, fieldValue, blockNo) {
-  var elementId = cj('[name="field[' + blockNo + '][' + fname + ']"]');
-
-  if (elementId.length == 0) {
-    elementId = cj('input[type=checkbox][name^="field[' + blockNo + '][' + fname + ']"][type!=hidden]');
-  }
-
-  // if element not found than return
-  if (elementId.length == 0) {
-    return;
-  }
-
-  //check if it is date element
-  var isDateElement = elementId.attr('format');
-
-  // check if it is wysiwyg element
-  var editor = elementId.attr('editor');
-
-  //get the element type
-  var elementType = elementId.attr('type');
-
-  // set the value for all the elements, elements needs to be handled are
-  // select, checkbox, radio, date fields, text, textarea, multi-select
-  // wysiwyg editor, advanced multi-select ( to do )
-  if (elementType == 'radio') {
-    if (fieldValue) {
-      elementId.filter("[value=" + fieldValue + "]").prop("checked", true);
-    }
-    else {
-      elementId.removeProp('checked');
-    }
-  }
-  else {
-    if (elementType == 'checkbox') {
-      // handle checkbox
-      elementId.removeProp('checked');
-      if (fieldValue) {
-        cj.each(fieldValue, function (key, value) {
-          cj('input[name="field[' + blockNo + '][' + fname + '][' + value + ']"]').prop('checked', true);
-        });
-      }
-    }
-    else {
-      if (editor) {
-        switch (editor) {
-          case 'ckeditor':
-            var elemtId = elementId.attr('id');
-            oEditor = CKEDITOR.instances[elemtId];
-            oEditor.setData(htmlContent);
-            break;
-          case 'tinymce':
-            var elemtId = element.attr('id');
-            tinyMCE.get(elemtId).setContent(htmlContent);
-            break;
-          case 'joomlaeditor':
-          // TO DO
-          case 'drupalwysiwyg':
-          // TO DO
-          default:
-            elementId.val(fieldValue);
-        }
-      }
-      else {
-        elementId.val(fieldValue);
-      }
-    }
-  }
-
-  // since we use different display field for date we also need to set it.
-  // also check for date time field and set the value correctly
-  if (isDateElement && fieldValue) {
-    setDateFieldValue(fname, fieldValue, blockNo)
-  }
-}
-
-function setDateFieldValue(fname, fieldValue, blockNo) {
-  var dateValues = fieldValue.split(' ');
-
-  var actualDateElement = cj('#field_' + blockNo + '_' + fname);
-  var date_format = actualDateElement.attr('format');
-  var altDateFormat = 'yy-mm-dd';
-
-  var actualDateValue = cj.datepicker.parseDate(altDateFormat, dateValues[0]);
-
-  // format date according to display field
-  var hiddenDateValue = cj.datepicker.formatDate('mm/dd/yy', actualDateValue);
-
-  actualDateElement.val(hiddenDateValue);
-
-  var displayDateValue = actualDateElement.val();
-  if (date_format != 'mm/dd/yy') {
-    displayDateValue = cj.datepicker.formatDate(date_format, actualDateValue);
-  }
-
-  cj('#field_' + blockNo + '_' + fname + '_display').val(displayDateValue);
-
-  // need to fix time formatting
-  if (dateValues[1]) {
-    cj('#field_' + blockNo + '_' + fname + '_time').val(dateValues[1].substr(0, 5));
-  }
-}
-
-</script>
-{/literal}
 
 {*include batch copy js js file*}
 {include file="CRM/common/batchCopy.tpl"}
diff --git a/tests/phpunit/CRM/Core/Payment/BaseIPNTest.php b/tests/phpunit/CRM/Core/Payment/BaseIPNTest.php
index 3c883b7180af06321022cf9c246c11102021abd6..b883ca4e9dff8660d94bec115b35b428c771bb57 100644
--- a/tests/phpunit/CRM/Core/Payment/BaseIPNTest.php
+++ b/tests/phpunit/CRM/Core/Payment/BaseIPNTest.php
@@ -87,7 +87,7 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase {
     $this->_contributionParams = array(
       'contact_id' => $this->_contactId,
       'version' => 3,
-                                     'financial_type_id'   => $this->_contributionTypeId,
+      'financial_type_id'   => $this->_contributionTypeId,
       'recieve_date' => date('Ymd'),
       'total_amount' => 150.00,
       'invoice_id' => 'c8acb91e080ad7bd8a2adc119c192885',
@@ -485,7 +485,7 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase {
      */
   function _setUpMembershipObjects() {
     try {
-      $this->_membershipTypeID = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID));
+      $this->_membershipTypeID = $this->membershipTypeCreate();
       $this->_membershipStatusID = $this->membershipStatusCreate('test status');
     }
     catch(Exception$e) {
@@ -505,8 +505,7 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase {
       'version' => 3,
     );
 
-    $membership = civicrm_api('membership', 'create', $this->_membershipParams);
-    $this->assertAPISuccess($membership, 'line ' . __LINE__ . ' set-up of membership');
+    $membership = $this->callAPISuccess('membership', 'create', $this->_membershipParams);
 
     $this->_membershipId = $membership['id'];
     //we'll create membership payment here because to make setup more re-usable