newgrp_saving = 0;
var ab_last_click_grp = false;
var ab_cur_sel_list = false;
alt_down = 0;
shift_down = 0;
var mmi = false;
contact_drag = 0;
var vcard_move = false;
group_drop_id = "";
var group_before_drag = false;
group_drop_made = 0;
var group_on_edit = false;
var newgrp = false;
var contacts_array = [];
ab_first_drag = 0;
var Unselectable = {
	enable : function(e) {
		var e = e ? e : window.event;
		if (e.button != 1) {
			if (e.target) {
				var targer = e.target;
			}
			else if (e.srcElement) {
				var targer = e.srcElement;
			}
			var targetTag = targer.tagName.toLowerCase();
			if ((targetTag != "input") && (targetTag != "textarea")) {
				return false;
			}
		}
	},
	disable : function () {
		return true;
	}
}

function ab_set_contacts_array() {
  contacts_array = [];
  el = $('ab_contacts_list');
  $(el).getElements('li').each(function(el, i) {
  	contacts_array.push(el.get('id'));
  });
}

function ab_rel_sel_group() {
  ab_cur_sel_list = false;
}

function ab_load_groups(defsel) {
  new Request({
    url: '/ajax/ab_groups.php?rn='+Math.floor(Math.random()*11),
    onSuccess: 	function(txt) {
	  $('ab_groups').set('html',txt);
	  ab_init_groups(defsel);
    }
  }).send();
}

function ab_select_group(item) {
  ab_clear_sel_group();
  ab_last_click_grp = item;
  item.setStyles({'background-color':'#0F77E4', 'color':'#FFF'});
}

function ab_load_contacts(group_id,selcontact) {
  if (!group_id) {
    group_id = "all";
  }
  mysearch = "";
  if (($('ab_search').value != "") && ($('ab_search').value != "Search")) {
    mysearch = '&mysearch='+URLEncode($('ab_search').value);
  }
  new Request({
    url: '/ajax/ab_contacts.php?group_id='+group_id+mysearch+'&rn='+Math.floor(Math.random()*11),
    onSuccess: 	function(txt) {
	  $('ab_contacts').set('html',txt);
	  ab_init_contacts();
	  ab_set_contacts_array();
	  if (selcontact) {
	    if ($(selcontact)) {
	      ab_clear_contact_sel();
	      $(selcontact).set('class','ab_contact_sel');
	      ab_cur_sel_list = $(selcontact);
	      ab_edit_contact(selcontact);
	      new Fx.Scroll($('ab_contacts')).toElement($(selcontact));
	    }
	  }
	  if ($('ab_msg').getStyle('display') != 'none') {
	    ab_dim_ab_msg();
	  }
    }
  }).send();
}

function ab_add_group() {
  ab_clear_sel_group();
  ab_last_click_grp = false;
  ab_cur_sel_list = false;
  if (newgrp) {
	newgrp.dispose();
  }
  if (group_on_edit) {
	group_on_edit.setStyle('display','');
  }
  newgrp = new Element('li').set('class','ab_group').injectAfter($('ab_group_all'));
  newinp = new Element('input').set({'class':'newinput', 'value':'Untitled', 'maxlength':'60'}).addEvent('keydown', function(event) {
    if (event.key == "enter") {
      ab_save_new_group(newgrp,this.value);
    }
    if (event.key == "esc") {
      newgrp.dispose();
    }
  })
  .inject(newgrp);
  newinp.focus();
  newinp.select();
}

function ab_save_new_group(newgrp,gn) {
  group_on_edit = false;
  if ((gn == "") || (gn == "Untitled")) {
    newgrp.dispose();
  }
  else {
    gn = URLEncode(gn);
    if (newgrp_saving == 0) {
      newgrp_saving = 1;
	  new Request({
	    url: '/ajax/ab_groups.php?action=add&name='+gn+'&rn='+Math.floor(Math.random()*11), 
	    onSuccess: 	function(txt) {
		  $('ab_groups').set('html',txt);
		  ab_init_groups();
		  newgrp_saving = 0;
	    }
	  }).send();
    }
  }
}

function ab_save_group_changes(newgrp,gn,id) {
  group_on_edit = false;
  if ((gn == "") || (gn == "Untitled")) {
    faction = "";
  }
  else {
    gn = URLEncode(gn);
    faction = "&action=save&id="+id+"&name="+gn;
  }
  if (newgrp_saving == 0) {
    newgrp_saving = 1;
	new Request({
	  url: '/ajax/ab_groups.php?rn='+Math.floor(Math.random()*11)+''+faction,
	  onSuccess: 	function(txt) {
		$('ab_groups').set('html',txt);
		ab_init_groups(id);
	    newgrp_saving = 0;
	  }
	}).send();
  }
}

function ab_init_groups(defsel) {
  var item = $('ab_group_all');
  if (item) {
    item.removeEvents();
    item.addEvent('click', function() {
      $('ab_search').value = "Search";
	  if (group_on_edit) {
		if (newgrp) {
		  newgrp.dispose();
		}
		group_on_edit.setStyle('display','');
	  }
      ab_load_contacts();
	  ab_select_group(item);
	  ab_cur_sel_list = false;
    });
  }

  $$('li.ab_group').each(function(item){
    item.removeEvents();
	item.addEvent('click', function() {
	
	    $('ab_search').value = "Search";
	
		if (newgrp) {
		  newgrp.dispose();
		}
		if (group_on_edit) {
		  group_on_edit.setStyle('display','');
		}
	    if (ab_last_click_grp == item) {
	      ab_edit_group(item);
	    }
	    else {
	      ab_load_contacts(item.get('id'));
	      ab_select_group(item);
		  ab_cur_sel_list = item;
		}
	});
	item.addEvent('mouseup', function() {
        if (group_drop_id == item.get('id')) {
//          group_drop_made = 1; // prevents returning to last selected group (before drop)
          contact_ids = "";
		  $$('#ab_contacts li.ab_contact_sel').each(function(item){
		    contact_ids += "|"+item.get('id');
		  });
		  new Request({
		    url: '/ajax/ab_contacts.php?action=assign&group_id='+group_drop_id+'&rn='+Math.floor(Math.random()*11)+'&contact_ids='+contact_ids,
		    onSuccess: 	function(txt) {
//			  ab_load_groups(item.get('id')); // jumps to new dropped group
			  if (group_before_drag) {
			    ab_load_groups(group_before_drag.get('id'));
			    group_before_drag = false;
			  }
			  else {
			    ab_load_groups();
			  }
		    }
		  }).send();
        }
        group_drop_id = "";
	});
	item.addEvent('mouseleave', function() {
	    group_drop_id = "";
	});
  });
  if (!defsel) {
    defsel = 'ab_group_all';
  }
  ab_select_group($(defsel));
  ab_cur_sel_list = $(defsel);
  new Fx.Scroll($('ab_groups')).toElement($(defsel));
}

function ab_edit_group(item) {
  new Request.JSON({
    url:		'/ajax/ab_groups.php',
    data:		'&action=pulledit&rn='+Math.floor(Math.random()*11)+'&id='+item.get('id'),
    onSuccess:	function(editinfo, html) {
      if (editinfo.status == 'success') {
        edit_name = editinfo.name.replace(/%22/g,'"');
	    ab_clear_sel_group();
	    ab_cur_sel_list = false;
	    newgrp = new Element('li').set('class','ab_group').injectAfter(item);
	    newinp = new Element('input').set({'class':'newinput', 'value':edit_name, 'maxlength':'60'})
	    .addEvent('keydown', function(event) {
	      if (event.key == "enter") {
	        ab_save_group_changes(newgrp,this.value,item.get('id'));
	      }
	      if (event.key == "esc") {
	        newgrp.dispose();
	        item.setStyle('display','');
	        group_on_edit = false;
	      }
	    }).inject(newgrp);
	    newinp.focus();
	    newinp.select();
	    group_on_edit = item;
	    item.setStyle('display','none');
		// item.dispose();
      }
      else {
        alert("Operation Error 001");
      }
	},
    onFailure: 	function() {
       alert("Operation Error 002");
     }
  }).get();
}

function ab_clear_sel_group() {
  if (ab_last_click_grp) {
	ab_last_click_grp.setStyles({'background-color':'#FFF', 'color':'#000'});
  }
}

function ab_init_keys() {
  document.addEvent('keydown', function(event){
    if ((event.alt) || (event.shift) || (event.code == 224)) { // alt, shift or open apple/command
      alt_down = 1;
    }
    if (event.shift) {
      shift_down = 1;
    }
    if ((event.key == "delete") || (event.key == "backspace")) {
    
	  if (list_delete_focus != "") {
    
		if (list_delete_focus == "group") {
	      trgid = ab_cur_sel_list.get('id');
	      ids = trgid.split(/_/);
	      var kk = confirm("Are you sure you want to delete this group?\n\nNOTE: This does NOT delete the contacts assigned to it.");
	      if (kk == true) {
		    new Request({
		      url: '/ajax/ab_groups.php?action=delete&id='+ids[1]+'&rn='+Math.floor(Math.random()*11),
		      onSuccess: 	function(txt) {
		  	    $('ab_groups').set('html',txt);
		  	    ab_init_groups();
		  	    ab_load_contacts();
		      }
		    }).send();
	      }
	    }
	    
		if (list_delete_focus == "contact") {
	      killids = [];
		  $$('#ab_contacts li.ab_contact_sel').each(function(item){
		    killids.push(item.get('id'));
		  });
	      if (killids.length > 0) {
	        if ($('showing_group_id')) { // unassign
		      new Request({
		        url: '/ajax/ab_contacts.php?action=unassign&group_id='+$('showing_group_id').value+'&contact_ids='+killids.join('|')+'&rn='+Math.floor(Math.random()*11),
		        onSuccess: function(txt) {
		          for (i=0; i<killids.length; i++) {
		            $(killids[i]).dispose();
			        ab_cur_sel_list = false;
			      }
			      ab_load_groups('group_'+$('showing_group_id').value);
			      ab_add_contact();
		        }
		      }).send();
		    }
		    else { // delete
		      var kk = confirm("Are you sure you want to permanently delete these selected contacts?");
		      if (kk == true) {
		        new Request({
		          url: '/ajax/ab_contacts.php?action=delete&contact_ids='+killids.join('|')+'&rn='+Math.floor(Math.random()*11),
		          onSuccess: function(txt) {
		            for (i=0; i<killids.length; i++) {
		              $(killids[i]).dispose();
			          ab_cur_sel_list = false;
			        }
			        ab_load_groups();
			        ab_add_contact();
		          }
		        }).send();
		      } // end IF confirm
		    } // end delete
	      } // end array length check
	    }
	    return false;
	  }
    }
  });
  document.addEvent('keyup', function(event){
    alt_down = 0;
    shift_down = 1;
  });
  
  $('ab_search').addEvent('keydown', function(event){  
    if (event.key == "enter") {
      ab_do_search();
    }
  });  
}

function ab_do_search() {
  $('ab_msg').set('html','Searching contacts...').setStyles({'display':'', 'opacity':'1.0'});
  if ($('showing_group_id')) {
    ab_load_contacts($('showing_group_id').value);
  }
  else {
	ab_load_contacts(0);
  }
}

function ab_edit_contact(id) {
  new Request({
    url: '/ajax/ab_contact_form.php?action=edit&id='+id+'&rn='+Math.floor(Math.random()*11),
    onSuccess: 	function(txt) {
	  $('ab_details').set('html',txt);
	  ab_init_input_keys();
	  ab_create_date_sel('ab_bday', $('eab_bday_mon').value, $('eab_bday_day').value, $('eab_bday_year').value);
	  ab_create_date_sel('ab_anniv', $('eab_anniv_mon').value, $('eab_anniv_day').value, $('eab_anniv_year').value);
	  ab_init_family_bdays();
    }
  }).send();
}

function ab_init_input_keys() {
  $$('#ab_details input').each(function(item){
    item.addEvent('keydown', function(event) {
      if (event.key == "enter") {
        ab_save_contact_form();
      }
    });
  });
  $('ab_city').addEvent('keydown', function(event) {
    if ((event.key == "tab") && (event.shift)) {
      $('ab_address2').focus();
      return false;
    }
    else {
      if (event.key == "tab") {
        $('ab_state').focus();
        return false;
      }
    }
  });
}

function ab_init_contacts() {
  $$('#ab_contacts li').each(function(item){
    item.removeEvents(); // clear events
	item.addEvent('click', function() {
	  if (alt_down == 0) {
	    ab_clear_contact_sel();
	    item.set('class','ab_contact_sel');
	    ab_cur_sel_list = item;
	    ab_edit_contact(item.get('id'));
	  }
	  else {
		ab_cur_sel_list = false;
	  }
	});
	item.addEvent('mousedown', function() {
	  if (item.get('class') == 'ab_contact_sel') {
	    if (!vcard_move) {
	      group_before_drag = ab_last_click_grp;
	      total_selected_items = 0;
		  $$('#ab_contacts li.ab_contact_sel').each(function(item){
		    total_selected_items++;
		  });
	      vcard_move = new Element('div').set({
	      	'class':	'vcard_move',
	      	'html':		total_selected_items
	      }).inject(document.body);
	    }
	  }
	  else {
	    if (alt_down == 0) {
	      ab_clear_contact_sel();
	    }
	    item.set('class','ab_contact_sel');
        contact_drag = 1;
      }
    });
  });
  new Fx.Scroll($('ab_contacts')).toTop();
}

function ab_init_drag_monitor() {
  document.addEvent('mousemove', function(event) {
    if (vcard_move) { // multiple selected contacts, icon created, make follow cursor
      vcard_move.setStyles({
      	'top':	(event.page.y + 3),
      	'left':	(event.page.x + 3)
      });
      if (event.target) {
        dropclass = $(event.target).get('class');
        dropid = $(event.target).get('id');
        if (dropclass == "ab_group") {
          group_drop_id = dropid;
		  ab_select_group($(dropid));
        }
      }
    } // end multi-select move
  
    if (contact_drag == 1) {

      if (event.target) {
        elemid = $(event.target).get('id');
        if ($(elemid)) {

	      if (!mmi) {
	        mmi = new Element('div').set('class','mmi').setStyle('opacity','0.7').inject(document.body);
	      }
	      gc = $('ab_contacts_list').getCoordinates();
	      mmi.setStyles({
	      	'top':	(event.page.y - 4),
	      	'left':	gc['left']
	      });

	      for (i=0; i<contacts_array.length; i++) {
	        if (contacts_array[i] == $(event.target).get('id')) {
	          thisi = i;
	        }
	      }
    
          if (thisi) {
	        if (ab_first_drag == 0) {
	          ab_first_drag = thisi;
	        }
	        if (thisi < ab_first_drag) {
	          ab_first_drag = thisi;
	        }
    
            if (thisi) {
		      for (i=ab_first_drag; i<contacts_array.length; i++) {
		        if (i <= thisi) {
		          if ($(contacts_array[i])) {
		            $(contacts_array[i]).set('class','ab_contact_sel');
		          }
		        }
		      }
		    }
		  }
		  
        }
      }

    }
  });
  
  
  if (typeof(document.onselectstart) != "undefined") {
	document.onselectstart = Unselectable.enable;
  }

  if (!$('safari3')) { // <select> bug in Safari v3
    document.onmousedown = Unselectable.enable;
  }
  document.onmouseup = Unselectable.disable;
  
  document.addEvent('mousedown', function(event) {
    objclass = $(event.target).get('class');
    
    if (objclass == "ab_contact_sel") {
      list_delete_focus = "contact";
    }
    else if (objclass == "ab_group") {
      list_delete_focus = "group";
    }
    else {
      list_delete_focus = "";
    }
  });
  
  document.addEvent('mouseup', function(event) {
    ab_first_drag = 0;
    contact_drag = 0;
    if (mmi) { mmi.dispose(); mmi = false; }
    if (vcard_move) {
      vcard_move.dispose();
      vcard_move = false;
    }
  });
}

function ab_dim_ab_msg() {
  myfx = function() { new Fx.Morph('ab_msg', {}).start({'opacity':[1,0]}); };
  myfx.delay(500);
}

function ab_clear_contact_sel() {
  $$('#ab_contacts li').each(function(item){
    item.set('class','ab_contact');
  });
}

function ab_add_contact() {
  new Request({
    url: '/ajax/ab_contact_form.php?rn='+Math.floor(Math.random()*11),
    onSuccess: 	function(txt) {
	  $('ab_details').set('html',txt);
	  ab_init_input_keys();
	  ab_create_date_sel('ab_bday');
	  ab_create_date_sel('ab_anniv');
	  ab_init_family_bdays();
    }
  }).send();
}

function ab_save_contact_form() {
  if ($('ab_fname').value == "") {
    alert("Please enter a first name for this contact.");
    $('ab_fname').focus();
    return false;
  }
  else if ($('ab_lname').value == "") {
    alert("Please enter a last name for this contact.");
    $('ab_lname').focus();
    return false;
  }
  else if ($('ab_address1').value == "") {
    alert("Please enter a mailing address for this contact.");
    $('ab_address1').focus();
    return false;
  }
  else if ($('ab_city').value == "") {
    alert("Please enter the city for this contact's mailing address.");
    $('ab_city').focus();
    return false;
  }
  else if ($('ab_state').value == "") {
    alert("Please select a state for this contact's mailing address.");
    $('ab_state').focus();
    return false;
  }
  else if ($('ab_zip').value == "") {
    alert("Please enter the zip code for this contact's mailing address.");
    $('ab_zip').focus();
    return false;
  }
  else {
    postdata  = '&action='+$('ab_action').value;
    postdata += '&id='+$('ab_contact_id').value;
    postdata += '&rn='+Math.floor(Math.random()*11);
    postdata += '&fname='+URLEncode($('ab_fname').value);
    postdata += '&lname='+URLEncode($('ab_lname').value);
    postdata += '&company='+URLEncode($('ab_company').value);
    postdata += '&address1='+URLEncode($('ab_address1').value);
    postdata += '&address2='+URLEncode($('ab_address2').value);
    postdata += '&city='+URLEncode($('ab_city').value);
    postdata += '&state='+URLEncode($('ab_state').value);
    postdata += '&zip='+URLEncode($('ab_zip').value);
    postdata += '&bday_mon='+$('ab_bday_mon').value;
    postdata += '&bday_day='+$('ab_bday_day').value;
    postdata += '&bday_year='+$('ab_bday_year').value;
    postdata += '&anniv_mon='+$('ab_anniv_mon').value;
    postdata += '&anniv_day='+$('ab_anniv_day').value;
    postdata += '&anniv_year='+$('ab_anniv_year').value;
    
    ifail = 0;
	tf = $('ab_total_family').value.toInt();
  	postdata += '&total_family='+tf;
    if (tf > 0) {
      i = 1;
	  $$('div.ab_fam').each(function(item){
        id = item.get('id');
        if ($(id+'_name').value == "") {
          alert("Please enter a family member name. Delete if this member is no longer wanted.");
          $(id+'_name').focus();
          ifail = 1;
        }
        else {
          postdata += '&ab_fam_'+i+'_name='+URLEncode($(id+'_name').value);
        }
	    postdata += '&ab_fam_'+i+'_mon='+$(id+'_mon').value;
	    postdata += '&ab_fam_'+i+'_day='+$(id+'_day').value;
	    postdata += '&ab_fam_'+i+'_year='+$(id+'_year').value;
	    i++;
      });
    }

    if (ifail == 0) {
      $('ab_loader').setStyle('display','');
      $('ab_subtn').value = "saving...please wait";
      $('ab_subtn').disabled = true;

      $('ab_msg').set('html','Saving contact...').setStyles({'display':'', 'opacity':'1.0'});
    
      new Request.JSON({
        url:		'/ajax/ab_contact_form.php',
        data:		postdata,
        onSuccess:	function(saveinfo, html) {
          if (saveinfo.status == 'success') {
            if ($('showing_group_id')) {
              iii = $('showing_group_id').value;
            }
            else {
              iii = 0;
            }
		    ab_load_contacts(iii,"contact_"+$('ab_contact_id').value);
		    ab_add_contact();
		    ab_init_input_keys();
		    $('ab_msg').set('html','Changes saved!');
		    ab_dim_ab_msg();
		    if ($('showing_group_id')) {
		      ab_load_groups('group_'+$('showing_group_id').value);
		    }
		    else {
		      ab_load_groups();
		    }
		    ab_create_date_sel('ab_bday');
		    ab_create_date_sel('ab_anniv');
		    ab_init_family_bdays();
          }
          else {
            alert("Operation Error 001");
          }
	    },
        onFailure: 	function() {
          alert("Operation Error 002");
        }
      }).post();
    }
  }
}

function ab_create_date_sel(prefx,mm,dd,yy) {
  if (!mm) { mm = ""; }
  if (!dd) { dd = ""; }
  if (!yy) { yy = ""; }
  
  selM = new Element('select').set({'class':'ab_input', 'id':prefx+'_mon'});
  new Element('option').set({'value':'', 'html':'--'}).inject(selM);
  atn = 1;
  while (atn <= 12) {
	sel = "";
	if (mm == atn) {
	  sel = "selected";
	}
    new Element('option').set({'value':atn, 'selected':sel, 'html':atn}).inject(selM);
	atn++;
  }
  selM.inject($(prefx));

  selD = new Element('select').set({'class':'ab_input', 'id':prefx+'_day'});
  new Element('option').set({'value':'', 'html':'--'}).inject(selD);
  atn = 1;
  while(atn <= 31) {
	sel = "";
	if (dd == atn) {
	  sel = "selected";
	}
    new Element('option').set({'value':atn, 'selected':sel, 'html':atn}).inject(selD);
	atn++;
  }
  selD.inject($(prefx));

  selY = new Element('select').set({'class':'ab_input', 'id':prefx+'_year'});
  new Element('option').set({'value':'', 'html':'----'}).inject(selY);
  atn = $('this_year').value.toInt();
  while(atn >= 1920) {
	sel = "";
	if (yy == atn) {
	  sel = "selected";
	}
    new Element('option').set({'value':atn, 'selected':sel, 'html':atn}).inject(selY);
    atn--;
  }
  selY.inject($(prefx));
}

function ab_add_family() {
  tf = $('ab_total_family').value.toInt();
  if (tf == 0) { $('ab_family').set('html',''); }
  tf++;
  $('ab_total_family').value = tf;
  
  nfe = new Element('div').set({
  	'class':'ab_fam',
  	'id':	'ab_fam_'+tf,
  	'title':'Click to delete this family member'
  }).inject($('ab_family'));
  
  new Element('img').set({
    'src':'/images/icons/icon_delete.png'
  }).addEvent('click', function() {
    ab_delete_family('ab_fam_'+tf);
  }).inject(nfe);

  newi = new Element('input').set({
    'class':'ab_input',
    'id':	'ab_fam_'+tf+'_name',
    'maxlength':'50'
  })
  .inject(nfe);
  
  ab_create_date_sel('ab_fam_'+tf);
  
  new Fx.Scroll($('ab_details')).toElement(nfe);
  setTimeout("newi.focus();",600);
}

function ab_delete_family(id) {
  var kk = confirm("Are you sure you want to delete this family member?\n\nNote: changes aren't saved until you save this contact record.");
  if (kk == true) {
    $(id).dispose();
  }
  tf = 0;
  $$('div.ab_fam').each(function(item){
    tf++;
  });
  $('ab_total_family').value = tf;
  if (tf == 0) { $('ab_family').set('html','<em>No family members created</em>'); }
}

function ab_init_family_bdays() {
  $$('div.ab_fam').each(function(item){
    id = item.get('id');
    ab_create_date_sel(id, $(id+'_mon').value.toInt(), $(id+'_day').value.toInt(), $(id+'_year').value.toInt());
  });
}

function ab_import() {
  alert('Coming soon!');
}

function chkABImport() {
  ff = eval("document.abif");
  if (ff.myfile.value == "") {
    alert("Please select a CSV file to upload.");
    ff.myfile.focus();
    return false;
  }
  else {
    ff.subtn.value = "Uploading...please wait";
    ff.subtn.disabled = true;
    return true;
  }
}

function AB_chk_import() {
  pass			= 1;
  got_fname		= 0;
  got_lname		= 0;
  got_address1	= 0;
  got_city		= 0;
  got_state		= 0;
  got_zip		= 0;
  $$('select.coltype').each(function(item){
    if (item.value == "") {
      pass = 0;
    }
    else {
      if (item.value == "fname")    { got_fname    = 1; }
      if (item.value == "lname")    { got_lname    = 1; }
      if (item.value == "address1") { got_address1 = 1; }
      if (item.value == "city")     { got_city     = 1; }
      if (item.value == "state")    { got_state	   = 1; }
      if (item.value == "zip")      { got_zip	   = 1; }
    }
  });
  if (pass == 0) {
    alert("Please select a data title for each column or select SKIP.");
    return false;
  }
  else if ((got_fname == 0) || (got_lname == 0) || (got_address1 == 0) || (got_city == 0) || (got_state == 0) || (got_zip == 0)) {
    alert("You must select a column name for the following:\n\n1. First Name\n2. Last Name\n3. Address 1\n4. City\n5. State\n6. Zip");
    return false;
  }
  else if (($('assign_group').value == "new") && (($('new_group_name').value == "") || ($('new_group_name').value == "[enter new group name]"))) {
    alert("Please enter a group name.");
    $('new_group_name').focus();
    $('new_group_name').select();
    return false;
  }
  else {
    $('afisubtn').value = "Importing...please wait";
    $('afisubtn').disabled = true;
    return true;
  }
}

function ABI_group() {
  if ($('assign_group').value == "new") {
    $('newgroup').setStyle('display','');
    $('new_group_name').focus();
    $('new_group_name').select();
  }
  else {
    $('newgroup').setStyle('display','none');
  }
}

function chkFirstRow() {
  if ($('row2')) {
    if ($('exempt_first_row').checked) {
      $('row2').setStyle('display','none');
    }
    else {
      $('row2').setStyle('display','');
    }
  }
}
