global class NewAndEditContactController extends NewAndEditBaseController 
{
    public String unifiedIContactID{set;get;}
	
    public NewAndEditContactController(ApexPages.StandardController controller) {
        
        List<String> fieldList = new List<String>(Schema.getGlobalDescribe().get('Contact').getDescribe().fields.getMap().keyset());  
        // Add fields to controller. This is to avoid the SOQL error in visualforce page
        controller.addFields(fieldList);
        Init(controller.getRecord());
        String contactId = controller.getRecord().Id;
        if(contactId != null){
            Contact c = [select UnifiedI_Contact_ID__c from Contact where Id =:contactId ];
            system.debug('Contact c = '+c);
            unifiedIContactID = c.UnifiedI_Contact_ID__c;
        }

    }
    
    PageReference RedirectStandardPage(){
        Map<string,string> mso = ApexPages.currentPage().getParameters();
        system.debug(mso);
        mso.remove('sfdc.override');
        PageReference pg = new PageReference('/003/e');
        //pg.getParameters().putAll(mso);
        pg.getParameters().put('RecordType',mso.get('RecordType'));
        pg.getParameters().put('accid',mso.get('accid'));
        pg.getParameters().put('nooverride','1');
        pg.setRedirect(true);
        return pg;
    }

    public PageReference PageLoad(){
        system.debug('rtTypeId='+rtTypeId);
        string s = null;
        if(!string.isBlank(rtTypeId)){
            s = Schema.SObjectType.Contact.getRecordTypeInfosById().get(rtTypeId).getDeveloperName();
            if(s == 'Agency' || s == 'Internal_staff'){
                return RedirectStandardPage();
            }
        }
        string accid = ApexPages.currentPage().getParameters().get('accid');
        if(!string.isBlank(accid)){
            List<Account> accs = [select RecordType.DeveloperName from account where id = :accid];
            if(accs.size()>0){
                s = accs[0].RecordType.DeveloperName;
                if(s == 'Office' || s == 'AgencyContact' || s == 'Agency'){
                    return RedirectStandardPage();
                }
            }
            
            
        }
        return null;
    }
    
    @RemoteAction
    global static Response saveContact(String leadJson,String transId,Boolean isNew) {
        return save(new Contact(),leadJson,transId,isNew);
    }
}