/**
  * 
  * Add email address to the contact
  * @param string $value
  * @param boolean $isMain
  * @author pepe
  */
 function addEmail($value, $email_type, $isMain = false)
 {
     $value = trim($value);
     $email = new ContactEmail();
     $email->setEmailTypeId(EmailTypes::getEmailTypeId($email_type));
     $email->setEmailAddress($value);
     $email->setContactId($this->getId());
     $email->setIsMain($isMain);
     $email->save();
 }
 function save_non_main_emails($contact_data, $contact)
 {
     $emails_data = array_var($contact_data, 'emails');
     if (is_array($emails_data)) {
         foreach ($emails_data as $data) {
             $obj = null;
             if ($data['id'] > 0) {
                 $obj = ContactEmails::findById($data['id']);
             } else {
                 if (trim($data['email_address']) == '') {
                     continue;
                 }
             }
             if ($data['deleted'] && $obj instanceof ContactEmail) {
                 $obj->delete();
                 continue;
             }
             if (!$obj instanceof ContactEmail) {
                 $obj = new ContactEmail();
                 $obj->setContactId($contact->getId());
             }
             $obj->setEmailTypeId($data['type']);
             $obj->setEmailAddress($data['email_address']);
             $obj->save();
         }
     }
 }