gt: 		else if (runName.equals(RUN_LAUGAVEGUR)) {
context: /*
   * Created on Jun 30, 2004
   */
  package is.idega.idegaweb.marathon.business;
  
  import is.idega.block.family.business.FamilyLogic;
  import is.idega.block.family.business.NoParentFound;
  import is.idega.idegaweb.marathon.data.Charity;
  import is.idega.idegaweb.marathon.data.Distance;
  import is.idega.idegaweb.marathon.data.Participant;
  import is.idega.idegaweb.marathon.data.ParticipantHome;
  import is.idega.idegaweb.marathon.data.Run;
  import is.idega.idegaweb.marathon.data.Year;
  import is.idega.idegaweb.marathon.data.YearBMPBean;
  import is.idega.idegaweb.marathon.glitnirws.MarathonWS2Client;
  import is.idega.idegaweb.marathon.presentation.CreateYearForm;
  import is.idega.idegaweb.marathon.util.IWMarathonConstants;
  
  import java.rmi.RemoteException;
  import java.sql.Date;
  import java.text.MessageFormat;
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.Collections;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.LinkedHashMap;
  import java.util.List;
  import java.util.Locale;
  import java.util.Map;
  
  import javax.ejb.CreateException;
  import javax.ejb.EJBException;
  import javax.ejb.FinderException;
  import javax.transaction.UserTransaction;
  
  import com.idega.block.creditcard.business.CreditCardAuthorizationException;
  import com.idega.block.creditcard.business.CreditCardBusiness;
  import com.idega.block.creditcard.business.CreditCardClient;
  import com.idega.block.creditcard.data.CreditCardMerchant;
  import com.idega.block.creditcard.data.KortathjonustanMerchant;
  import com.idega.block.creditcard.data.KortathjonustanMerchantHome;
  import com.idega.business.IBOLookup;
  import com.idega.business.IBOLookupException;
  import com.idega.business.IBORuntimeException;
  import com.idega.business.IBOServiceBean;
  import com.idega.core.accesscontrol.business.LoginDBHandler;
  import com.idega.core.accesscontrol.data.LoginTable;
  import com.idega.core.location.data.Address;
  import com.idega.core.location.data.AddressHome;
  import com.idega.core.location.data.Country;
  import com.idega.core.location.data.CountryHome;
  import com.idega.core.location.data.PostalCode;
  import com.idega.core.location.data.PostalCodeHome;
  import com.idega.core.messaging.MessagingSettings;
  import com.idega.data.IDOAddRelationshipException;
  import com.idega.data.IDOCreateException;
  import com.idega.data.IDOException;
  import com.idega.data.IDOLookup;
  import com.idega.data.IDOLookupException;
  import com.idega.idegaweb.IWResourceBundle;
  import com.idega.presentation.IWContext;
  import com.idega.user.business.GroupBusiness;
  import com.idega.user.business.UserBusiness;
  import com.idega.user.data.Gender;
  import com.idega.user.data.Group;
  import com.idega.user.data.GroupHome;
  import com.idega.user.data.User;
  import com.idega.util.Age;
  import com.idega.util.IWTimestamp;
  import com.idega.util.LocaleUtil;
  import com.idega.util.Timer;
  import com.idega.util.text.Name;
  
  /**
   * Description: Business bean (service) for run... <br>
   * Copyright: Idega Software 2004 <br>
   * Company: Idega Software <br>
   * 
   * @author birna
   */
  public class RunBusinessBean extends IBOServiceBean implements RunBusiness {
  
  	private static final String RUN_ROLLER_SKATE = "Roller Skate";
  	private static final String RUN_MIDNIGHT_RUN = "Midnight Run";
  	private static final String RUN_LAUGAVEGUR = "Laugavegur";
  	private static final String RUN_RVK_MARATHON = "Reykjavik Marathon";
  	private static final String RUN_OSLO_MARATHON = "Oslo Marathon";
  	private static final String RUN_LAZY_TOWN_RUN = "Lazy Town Run";
  	private static final String RUN_LAZY_TOWN_MINIMARATON_OSLO = "Lazy Town Minimaraton Oslo";
  
  	/**
  	 * Comment for <code>serialVersionUID</code>
  	 */
  	private static final long serialVersionUID = 3105168986587179336L;
  
  	private final static String IW_BUNDLE_IDENTIFIER = IWMarathonConstants.IW_BUNDLE_IDENTIFIER;
  
  	private static String DEFAULT_SMTP_MAILSERVER = "mail.idega.is";
  	private static String DEFAULT_MESSAGEBOX_FROM_ADDRESS = "marathon@marathon.is";
  	private static String DEFAULT_CC_ADDRESS = "marathon@marathon.is";
  
  	private AddressHome addressHome;
  	private ParticipantHome participantHome;
  
  	/**
  	 * saves information on the user - creates a new user if he doesn't exsist..
  	 */
  	public User saveUser(String name, String ssn, IWTimestamp dateOfBirth, Gender gender, String address, String postal, String city, Country country) {
  		User user = null;
  		try {
  			if (dateOfBirth == null) {
  				dateOfBirth = getBirthDateFromSSN(ssn);
  			}
  			Name fullName = new Name(name);
  			user = getUserBiz().createUser(fullName.getFirstName(), fullName.getMiddleName(), fullName.getLastName(), fullName.getName(), ssn, gender, dateOfBirth);
  			user.store();
  
  			if (address != null && !address.equals("")) {
  				AddressHome addressHome = (AddressHome) getIDOHome(Address.class);
  				Address a = addressHome.create();
  				a.setStreetName(address);
  				a.setCity(city);
  				a.setCountry(country);
  				a.setAddressType(getAddressHome().getAddressType2());
  				a.store();
  
  				PostalCodeHome postalHome = (PostalCodeHome) getIDOHome(PostalCode.class);
  				Integer countryID = (Integer) country.getPrimaryKey();
  				PostalCode p = null;
  				try {
  					p = postalHome.findByPostalCodeAndCountryId(postal, countryID.intValue());
  				}
  				catch (FinderException fe) {
  					p = postalHome.create();
  					p.setCountry(country);
  					p.setPostalCode(postal);
  					p.setName(city);
  					p.store();
  				}
  				if (p != null) {
  					a.setPostalCode(p);
  				}
  				a.store();
  				try {
  					user.addAddress(a);
  				}
  				catch (IDOAddRelationshipException idoEx) {
  				}
  			}
  			user.store();
  		}
  		catch (RemoteException rme) {
  		}
  		catch (CreateException cre) {
  		}
  		return user;
  	}
  	
  	public boolean isRegisteredInRun(int runID, int userID) {
  		try {
  			User user = getUserBiz().getUserHome().findByPrimaryKey(new Integer(userID));
  			
  			return getUserBiz().isMemberOfGroup(runID, user);
  		}
  		catch (RemoteException re) {
  			log(re);
  		}
  		catch (FinderException fe) {
  			//User does not exist in database...
  		}
  		return false;
  	}
  	
  	public boolean isRegisteredInRun(String year, Group run, User user) {
  		try {
  			Group runYear = null;
  			String[] types = { IWMarathonConstants.GROUP_TYPE_RUN_YEAR };
  			Collection years = getGroupBiz().getChildGroups(run, types, true);
  			Iterator iter = years.iterator();
  			while (iter.hasNext()) {
  				Group yearGroup = (Group) iter.next();
  				if (yearGroup.getName().equals(year)) {
  					runYear = yearGroup;
  					break;
  				}
  			}
  			
  			if (runYear == null) {
  				return false;
  			}
  			
  			((ParticipantHome) IDOLookup.getHome(Participant.class)).findByUserAndRun(user, run, runYear);
  			return true;
  		}
  		catch (FinderException fe) {
  			return false;
  		}
  		catch (RemoteException ile) {
  			throw new IBORuntimeException(ile);
  		}
  	}
  	
  	public boolean doesGroupExist(Object distancePK, String groupName) {
  		try {
  			return ((ParticipantHome) IDOLookup.getHome(Participant.class)).getCountByDistanceAndGroupName(distancePK, groupName) > 0;
  		}
  		catch (IDOException ie) {
  			ie.printStackTrace();
  			return false;
  		}
  		catch (IDOLookupException ile) {
  			throw new IBORuntimeException(ile);
  		}
  	}
  	
  	public boolean isRegisteredInRun(int runID, String personalID) {
  		try {
  			User user = getUserBiz().getUserHome().findByPersonalID(personalID);
  			
  			return getUserBiz().isMemberOfGroup(runID, user);
  		}
  		catch (RemoteException re) {
  			log(re);
  		}
  		catch (FinderException fe) {
  			//User does not exist in database...
  		}
  		return false;
  	}
  
  	/**
  	 * 
  	 * @param pin -
  	 *            a social security number - format ddmmyyxxxx or ddmmyyyy
  	 * @return IWTimstamp - the date of birth from the pin..
  	 */
  	private IWTimestamp getBirthDateFromSSN(String pin) {
  		//pin format = 14011973
  		if (pin.length() == 8) {
  			int edd = Integer.parseInt(pin.substring(0, 2));
  			int emm = Integer.parseInt(pin.substring(2, 4));
  			int eyyyy = Integer.parseInt(pin.substring(4, 8));
  			IWTimestamp dob = new IWTimestamp(edd, emm, eyyyy);
  			return dob;
  		}
  		//  pin format = 140173xxxx ddmmyyxxxx
  		else if (pin.length() == 10) {
  			int dd = Integer.parseInt(pin.substring(0, 2));
  			int mm = Integer.parseInt(pin.substring(2, 4));
  			int yy = Integer.parseInt(pin.substring(4, 6));
  			int century = Integer.parseInt(pin.substring(9, 10));
  			int yyyy = 0;
  			if (century == 9) {
  				yyyy = yy + 1900;
  			}
  			else if (century == 0) {
  				yyyy = yy + 2000;
  			}
  			IWTimestamp dob = new IWTimestamp(dd, mm, yyyy);
  			return dob;
  		}
  		else {
  			return null;
  		}
  	}
  	
  	public int getAgeFromPersonalID(String personalID) {
  		if (personalID != null) {
  			IWTimestamp dateOfBirth = getBirthDateFromSSN(personalID);
  			if (dateOfBirth != null) {
  				Age age = new Age(dateOfBirth.getDate());
  				return age.getYears();
  			}
  		}
  		return -1;
  	}
  	
  	public Participant importParticipant(User user, Group run, Group year, Group distance) throws CreateException {
  		try {
  			Group ageGenderGroup = getAgeGroup(user, run, distance);
  			ageGenderGroup.addGroup(user);
  
  			ParticipantHome runHome = (ParticipantHome) getIDOHome(Participant.class);
  			Participant participant = runHome.create();
  			participant.setUser(user);
  			participant.setRunTypeGroup(run);
  			participant.setRunDistanceGroup(distance);
  			participant.setRunYearGroup(year);
  			participant.setRunGroupGroup(ageGenderGroup);
  			
  			boolean enableCustomerWebservice = "true".equalsIgnoreCase(getIWMainApplication().getSettings().getProperty("MARATHON_ENABLE_CUSTOMER_WS","false"));
  			if (user.getPersonalID() != null && enableCustomerWebservice) {
  				Timer wsTimer = new Timer();
  				wsTimer.start();
  				try{
  					MarathonWS2Client wsClient = new MarathonWS2Client(getIWMainApplication());
  					if (getUserBiz().hasValidIcelandicSSN(user)) {
  						
  						if(wsClient.erIVidskiptumVidGlitni(user.getPersonalID())){
  							participant.setCustomer(true);
  						}
  						else{
  							participant.setCustomer(false);
  						}
  					} else {
  						participant.setCustomer(false);
  					}
  				}
  				catch(Exception e){
  					System.out.println("Lookup to the GlitnirCustomerWebService failed: " + e.getMessage());
  					//e.printStackTrace();
  				}
  				wsTimer.stop();
  				System.out.println("Time to execute GlitnirCustomerWebService was: " + wsTimer.getTimeString());
  			}
  
  			participant.store();
  			
  			return participant;
  		}
  		catch (RemoteException re) {
  			throw new IBORuntimeException(re);
  		}
  	}
  	
  	public Collection saveParticipants(Collection runners, String email, String hiddenCardNumber, double amount, IWTimestamp date, Locale locale, boolean disableSendPaymentConfirmation) throws IDOCreateException {
  		Collection participants = new ArrayList();
  
  		UserTransaction trans = getSessionContext().getUserTransaction();
  		try {
  			trans.begin();
  			Iterator iter = runners.iterator();
  			Group run = null;
  			Group distance = null;
  			Run selectedRun = null;
  			while (iter.hasNext()) {
  				Runner runner = (Runner) iter.next();
  				User user = runner.getUser();
  				String personalId = null;
  				if (user == null) {
  					personalId = runner.getPersonalID();
  					user = saveUser(runner.getName(), personalId, new IWTimestamp(runner.getDateOfBirth()), runner.getGender(), runner.getAddress(), runner.getPostalCode(), runner.getCity(), runner.getCountry());
  				} else {
  					personalId = user.getPersonalID();
  				}
  				String userNameString = "";
  				String passwordString = "";
  
  				if (getUserBiz().hasUserLogin(user)) {
  					try {
  						LoginTable login = LoginDBHandler.getUserLogin(user);
  						userNameString = login.getUserLogin();
  						passwordString = LoginDBHandler.getGeneratedPasswordForUser();
  						LoginDBHandler.changePassword(login, passwordString);
  					} catch (Exception e) {
  						System.out.println("Error re-generating password for user: " + user.getName());
  						e.printStackTrace();
  					}
  				} else {
  					try {
  						LoginTable login = getUserBiz().generateUserLogin(user);
  						userNameString = login.getUserLogin();
  						passwordString = login.getUnencryptedUserPassword();
  					} catch (Exception e) {
  						System.out.println("Error creating login for user: " + user.getName());
  						e.printStackTrace();
  					}
  				}
  				
  				Group ageGenderGroup = getAgeGroup(user, runner.getRun(), runner.getDistance());
  				ageGenderGroup.addGroup(user);
  				Group yearGroup = (Group) runner.getDistance().getParentNode();
  				run = runner.getRun();
  				distance = runner.getDistance();
  				selectedRun = null;
  				try {
  					selectedRun = ConverterUtility.getInstance().convertGroupToRun(run);
  				} catch (FinderException e) {
  					//Run not found
  				}
  				
  				try {
  					ParticipantHome runHome = (ParticipantHome) getIDOHome(Participant.class);
  					Participant participant = runHome.create();
  					participant.setUser(user);
  					participant.setRunTypeGroup(run);
  					participant.setRunDistanceGroup(distance);
  					participant.setRunYearGroup(yearGroup);
  					participant.setRunGroupGroup(ageGenderGroup);
  					participant.setMaySponsorContact(runner.isMaySponsorContactRunner());
  					if(runner.isParticipateInCharity()){
  						Charity charity = runner.getCharity();
  						if(charity!=null){
  							participant.setCharityId(charity.getOrganizationalID());
  						}
  					}
  					if (runner.getCategory()!= null) {
  						participant.setCategoryId(((Integer)runner.getCategory().getPrimaryKey()).intValue());
  					}
  					if (runner.getAmount() > 0) {
  						participant.setPayedAmount(String.valueOf(runner.getAmount()));
  					}
  					
  					participant.setShirtSize(runner.getShirtSize());
  					if (runner.isOwnChip()) {
  						participant.setChipOwnershipStatus(IWMarathonConstants.CHIP_OWN);
  					}
  					else if (runner.isRentChip()) {
  						participant.setChipOwnershipStatus(IWMarathonConstants.CHIP_RENT);
  					}
  					else if (runner.isBuyChip()) {
  						participant.setChipOwnershipStatus(IWMarathonConstants.CHIP_BUY);
  					}
  					participant.setChipNumber(runner.getChipNumber());
  					participant.setUserNationality(runner.getNationality().getName());
  					if (runner.getDistance() != null) {
  						participant.setParticipantNumber(getNextAvailableParticipantNumber(runner.getDistance()));
  					}
  					participant.setTransportOrdered(String.valueOf(runner.isTransportOrdered()));
  					participant.setApplyForDomesticTravelSupport(runner.isApplyForDomesticTravelSupport());
  					participant.setApplyForInternationalTravelSupport(runner.isApplyForInternationalTravelSupport());
  					participant.setSponsoredRunner(runner.isSponsoredRunner());
  					participant.setAllowsEmails(runner.getAllowsEmails());
  					participant.setQuestion1Hour(runner.getQuestion1Hour());
  					participant.setQuestion1Minute(runner.getQuestion1Minute());
  					participant.setQuestion1Year(runner.getQuestion1Year());
  					participant.setQuestion1NeverRan(runner.getQuestion1NeverRan());
  					participant.setQuestion2Hour(runner.getQuestion2Hour());
  					participant.setQuestion2Minute(runner.getQuestion2Minute());
  					participant.setQuestion3Hour(runner.getQuestion3Hour());
  					participant.setQuestion3Minute(runner.getQuestion3Minute());
  					participant.setQuestion3Year(runner.getQuestion3Year());
  					participant.setQuestion3NeverRan(runner.getQuestion3NeverRan());
  					//check customer:
  					boolean enableCustomerWebservice = "true".equalsIgnoreCase(getIWMainApplication().getSettings().getProperty("MARATHON_ENABLE_CUSTOMER_WS","false"));
  					if (personalId != null && enableCustomerWebservice) {
  						Timer wsTimer = new Timer();
  						wsTimer.start();
  						try{
  							MarathonWS2Client wsClient = new MarathonWS2Client(getIWMainApplication());
  							if (getUserBiz().hasValidIcelandicSSN(user)) {
  								
  								if(wsClient.erIVidskiptumVidGlitni(user.getPersonalID())){
  									participant.setCustomer(true);
  								}
  								else{
  									participant.setCustomer(false);
  								}
  							} else {
  								participant.setCustomer(false);
  							}
  						}
  						catch(Exception e){
  							System.out.println("Lookup to the GlitnirCustomerWebService failed: " + e.getMessage());
  							//e.printStackTrace();
  						}
  						wsTimer.stop();
  						System.out.println("Time to execute GlitnirCustomerWebService was: " + wsTimer.getTimeString());
  					}
  
  					
  					if (runner.getRelayLeg() != null & !"".equals(runner.getRelayLeg())) {
  						participant.setRelayLeg(runner.getRelayLeg());
  
  						if (runner.getPartner1SSN() != null & !"".equals(runner.getPartner1SSN())) {						
  							participant.setRelayPartner1SSN(runner.getPartner1SSN());
  							participant.setRelayPartner1Name(runner.getPartner1Name());
  							participant.setRelayPartner1Email(runner.getPartner1Email());
  							participant.setRelayPartner1ShirtSize(runner.getPartner1ShirtSize());
  							participant.setRelayPartner1Leg(runner.getPartner1Leg());
  							
  							if (runner.getPartner2SSN() != null & !"".equals(runner.getPartner2SSN())) {
  								participant.setRelayPartner2SSN(runner.getPartner2SSN());
  								participant.setRelayPartner2Name(runner.getPartner2Name());
  								participant.setRelayPartner2Email(runner.getPartner2Email());
  								participant.setRelayPartner2ShirtSize(runner.getPartner2ShirtSize());
  								participant.setRelayPartner2Leg(runner.getPartner2Leg());
  
  								if (runner.getPartner3SSN() != null & !"".equals(runner.getPartner3SSN())) {
  									participant.setRelayPartner3SSN(runner.getPartner3SSN());
  									participant.setRelayPartner3Name(runner.getPartner3Name());
  									participant.setRelayPartner3Email(runner.getPartner3Email());
  									participant.setRelayPartner3ShirtSize(runner.getPartner3ShirtSize());
  									participant.setRelayPartner3Leg(runner.getPartner3Leg());								
  								}
  							}												
  						}
  					}
  					
  					participant.store();
  					participants.add(participant);
  					
  					getUserBiz().updateUserHomePhone(user, runner.getHomePhone());
  					getUserBiz().updateUserMobilePhone(user, runner.getMobilePhone());
  					getUserBiz().updateUserMail(user, runner.getEmail());
  
  					if (runner.getEmail() != null) {
  						IWResourceBundle iwrb = getIWApplicationContext().getIWMainApplication().getBundle(IWMarathonConstants.IW_BUNDLE_IDENTIFIER).getResourceBundle(locale);
  						String distanceString = iwrb.getLocalizedString(distance.getName(),distance.getName());
  						if (runner.isTransportOrdered()) {
  							distanceString = distanceString + " (" + iwrb.getLocalizedString("run_reg.with_bus_trip","with bus trip") + ")";
  						}
  						String informationPageString = "";
  						String greeting = "";
  						String runHomePageString = "";
  						String receiptInfo = "";
  						if (selectedRun != null) {
  							runHomePageString = selectedRun.getRunHomePage();
  							if (locale.equals(LocaleUtil.getIcelandicLocale())) {
  								informationPageString = selectedRun.getRunInformationPage();
  								greeting = selectedRun.getRunRegistrationReceiptGreeting();
  								receiptInfo = selectedRun.getRunRegistrationReceiptInfo();
  							} else {
  								informationPageString = selectedRun.getEnglishRunInformationPage();
  								greeting = selectedRun.getRunRegistrationReceiptGreetingEnglish();
  								receiptInfo = selectedRun.getRunRegistrationReceiptInfoEnglish();
  							}
  							
  							if (informationPageString == null) {
  								informationPageString = " ";
  							}
  							if (greeting == null) {
  								greeting = " ";
  							}
  							if (receiptInfo == null) {
  								receiptInfo = " ";
  							}
  						}
  						Object[] args = { user.getName(), iwrb.getLocalizedString(run.getName(),run.getName()) + " " + yearGroup.getName(), distanceString, iwrb.getLocalizedString("shirt_size." + runner.getShirtSize(), runner.getShirtSize()), String.valueOf(participant.getParticipantNumber()), runHomePageString, informationPageString, userNameString, passwordString, greeting, receiptInfo };
  						String subject = iwrb.getLocalizedString("registration_received_subject_mail_" + selectedRun.getPrimaryKey().toString(), "Your registration has been received.");
  						String body = MessageFormat.format(localizeForRun("registration_received_body_mail_" + selectedRun.getPrimaryKey().toString(), "Your registration has been received.", runner, iwrb), args);
  						sendMessage(runner.getEmail(), subject, body);
  					}
  					
  
  					
  					sendSponsorEmail(runner,locale);
  				}
  				catch (CreateException ce) {
  					ce.printStackTrace();
  				}
  				catch (RemoteException re) {
  					throw new IBORuntimeException(re);
  				}
  			}
  			if (email != null && !disableSendPaymentConfirmation && amount > 0) {
  				IWResourceBundle iwrb = getIWApplicationContext().getIWMainApplication().getBundle(IWMarathonConstants.IW_BUNDLE_IDENTIFIER).getResourceBundle(locale);
  				String runName = "";
  				String runHomePage = "";
  				if (selectedRun != null) {
  					runName = iwrb.getLocalizedString(selectedRun.getName(), selectedRun.getName());
  					runHomePage = selectedRun.getRunHomePage();
  				}
  				
  				Object[] args = { hiddenCardNumber, String.valueOf(amount), date.getLocaleDateAndTime(locale, IWTimestamp.SHORT, IWTimestamp.SHORT), runName, runHomePage };
  				String subject = iwrb.getLocalizedString("receipt_subject_mail", "Your receipt for registration");
  				String body = MessageFormat.format(iwrb.getLocalizedString("receipt_body_mail", "Your registration has been received."), args);
  				sendMessage(email, subject, body);
  			}
  			trans.commit();
  		}
  		catch (Exception ex) {
  			try {
  				trans.rollback();
  			}
  			catch (javax.transaction.SystemException e) {
  				throw new IDOCreateException(e.getMessage());
  			}
  			ex.printStackTrace();
  			throw new IDOCreateException(ex);
  		}
  		
  		return participants;
  	}
  	
  	private void sendSponsorEmail(Runner runner,Locale locale) {
  		
  		if(runner.isMaySponsorContactRunner()){
  			try{
  				User user = runner.getUser();
  				if(user!=null){
  					String name = runner.getUser().getName();
  					String personalId = runner.getPersonalID();
  					String sAddress = "";
  					Collection addresses = runner.getUser().getAddresses();
  					if(addresses.size()>0){
  						for (Iterator iter = addresses.iterator(); iter.hasNext();) {
  							Address address = (Address) iter.next();
  							sAddress=address.getName()+" "+address.getPostalAddress();
  						}
  						
  					}
  					String phone = runner.getHomePhone();
  					String mobilePhone = runner.getMobilePhone();
  					String runnerEmail = runner.getEmail();
  					String sponsorEmail = getIWApplicationContext().getIWMainApplication().getSettings().getProperty("MARATHON_SPONSOR_EMAIL");
  					
  					IWResourceBundle iwrb = getIWApplicationContext().getIWMainApplication().getBundle(IWMarathonConstants.IW_BUNDLE_IDENTIFIER).getResourceBundle(locale);
  					Object[] args = { name, personalId, sAddress, phone, mobilePhone,runnerEmail };
  					String subject = iwrb.getLocalizedString("sponsor_mail_subject", "Request for invitation to be a customer from marathon.is");
  					String body = MessageFormat.format(iwrb.getLocalizedString("sponsor_mail_body", "Name: {0}\nPersonal ID: {1}\nAddress: {2}\nPhone: {3}\nMobile Phone: {4}\nE-mail: {5}"), args);
  					sendMessage(sponsorEmail, subject, body);
  				}
  				else{
  					logWarning("User is null in sendSponsorEmail for runner: "+runner.getName()+", "+runner.getEmail());
  				}
  			}
  			catch(Exception e){
  				e.printStackTrace();
  			}
  		}
  		
  	}
  
  	public synchronized int getNextAvailableParticipantNumber(Distance distance) {
  		int number = distance.getNextAvailableParticipantNumber();
  		int minNumber = distance.getMinimumParticipantNumberForDistance();
  		int maxNumber = distance.getMaximumParticipantNumberForDistance();
  		if (minNumber == -1) {
  			minNumber = 1;
  		}
  		if (number == -1) {
  			number = minNumber;
  		}
  		if (maxNumber != -1 && number > maxNumber) {
  			return minNumber;
  		}
  		
  		try {
  			ParticipantHome runHome = (ParticipantHome) getIDOHome(Participant.class);
  			while (number <= (maxNumber == -1 ? 999999 : maxNumber)) {
  				if (runHome.getCountByDistanceAndNumber(distance.getPrimaryKey(), number) == 0) {
  					distance.setNextAvailableParticipantNumber(number + 1);
  					distance.store();
  					return number;
  				}
  					
  				number++;
  			}
  		}
  		catch (RemoteException re) {
  			throw new IBORuntimeException(re);
  		}
  		catch (IDOException ie) {
  			ie.printStackTrace();
  		}
  		return minNumber;
  	}
  	
  	public void addParticipantsToGroup(String[] participants, String groupName) {
  		try {
  			ParticipantHome runHome = (ParticipantHome) getIDOHome(Participant.class);
  			
  			for (int i = 0; i < participants.length; i++) {
  				try {
  					Participant participant = runHome.findByPrimaryKey(new Integer(participants[i]));
  					participant.setRunGroupName(groupName);
  					participant.store();
  				}
  				catch (FinderException fe) {
  					fe.printStackTrace();
  				}
  			}
  		}
  		catch (RemoteException re) {
  			throw new IBORuntimeException(re);
  		}
  	}
  	
  	public boolean isCrewLabelAlreadyExistsForRun(int runId, int yearId, String crewLabel) {
  		try {
  			ParticipantHome runHome = (ParticipantHome) getIDOHome(Participant.class);
  			return runHome.findCrewLabelAlreadyExistsForRun(runId, yearId, crewLabel);
  		} catch (RemoteException re) {
  			throw new IBORuntimeException(re);
  		} catch (FinderException re) {
  			throw new IBORuntimeException(re);
  		}
  	}
  	
  	private Group getAgeGroup(User user, Run run, Distance distance) {
  		return getAgeGroup(user, (Group) run, distance);
  	}
  	
  	public Group getAgeGroup(User user, Group run, Group distance) {
  		Year year = null;
  		try {
  			year = ConverterUtility.getInstance().convertGroupToYear((Group) distance.getParentNode());
  		}
  		catch (FinderException fe) {
  			fe.printStackTrace();
  		}
  
  		IWTimestamp runDate = new IWTimestamp();
  		runDate.setYear(Integer.parseInt(year.getName()));
  		if (year != null && year.getRunDate() != null) {
  			runDate = new IWTimestamp(year.getRunDate());
  		}
  		IWTimestamp dateOfBirth = new IWTimestamp(user.getDateOfBirth());
  		dateOfBirth.setDay(1);
  		dateOfBirth.setMonth(1);
  		Age age = new Age(dateOfBirth.getDate());
  		
  		String[] groupType = { IWMarathonConstants.GROUP_TYPE_RUN_GROUP };
  		try {
  			Collection groups = getGroupBiz().getChildGroupsRecursive(distance, groupType, true);
  			
  			Iterator groupsIter = groups.iterator();
  			while (groupsIter.hasNext()) {
  				Group group = (Group) groupsIter.next();
  				if (group.getName().equals(getGroupName(age.getYears(runDate.getDate()), run, user.getGenderID(), distance))) {
  					return group;
  				}
  			}
  		}
  		catch (RemoteException re) {
  			throw new IBORuntimeException(re);
  		}
  		return null;
  	}
  	
  	public void finishPayment(String properties) throws CreditCardAuthorizationException {
  		try {
  			CreditCardClient client = getCreditCardBusiness().getCreditCardClient(getCreditCardMerchant());
  			client.finishTransaction(properties);
  		}
  		catch (CreditCardAuthorizationException ccae) {
  			throw ccae;
  		}
  		catch (Exception e) {
  			e.printStackTrace(System.err);
  			throw new CreditCardAuthorizationException("Online payment failed. Unknown error.");
  		}
  	}
  	
  	/**
  	 * @deprecated use authorizePayment with expiresDate parameter
  	 */
  	public String authorizePayment(String nameOnCard, String cardNumber, String monthExpires, String yearExpires, String ccVerifyNumber, double amount, String currency, String referenceNumber) throws CreditCardAuthorizationException {
  		try {
  			CreditCardClient client = getCreditCardBusiness().getCreditCardClient(getCreditCardMerchant());
  			return client.creditcardAuthorization(nameOnCard, cardNumber, monthExpires, yearExpires, ccVerifyNumber, amount, currency, referenceNumber);
  		}
  		catch (CreditCardAuthorizationException ccae) {
  			throw ccae;
  		}
  		catch (Exception e) {
  			e.printStackTrace(System.err);
  			throw new CreditCardAuthorizationException("Online payment failed. Unknown error.");
  		}
  	}
  	
  	/**
  	 * 
  	 * @param nameOnCard
  	 * @param cardNumber
  	 * @param expiresDate - only year and month are relevant
  	 * @param ccVerifyNumber
  	 * @param amount
  	 * @param currency
  	 * @param referenceNumber
  	 * @return
  	 * @throws CreditCardAuthorizationException
  	 */
  	public String authorizePayment(String nameOnCard, String cardNumber, java.util.Date expiresDate, String ccVerifyNumber, double amount, String currency, String referenceNumber) throws CreditCardAuthorizationException {
  	
  		IWTimestamp expirationDate = new IWTimestamp(expiresDate);
  		String yearPostfix = String.valueOf(expirationDate.getYear() % 100);
  		String monthPostfix = String.valueOf(expirationDate.getMonth());
  		
  		if(yearPostfix.length() != 2)
  			yearPostfix = "0"+yearPostfix;
  		
  		if(monthPostfix.length() != 2)
  			monthPostfix = "0"+monthPostfix;
  		
  		try {
  			CreditCardClient client = getCreditCardBusiness().getCreditCardClient(getCreditCardMerchant());
  			return client.creditcardAuthorization(nameOnCard, cardNumber, monthPostfix, yearPostfix, ccVerifyNumber, amount, currency, referenceNumber);
  		}
  		catch (CreditCardAuthorizationException ccae) {
  			throw ccae;
  		}
  		catch (Exception e) {
  			e.printStackTrace(System.err);
  			throw new CreditCardAuthorizationException("Online payment failed. Unknown error.");
  		}
  	}
  	
  	public float getPriceForRunner(Runner runner, Locale locale, float chipDiscount, float chipPrice) {
  		Age age = null;
  		if (runner.getUser() != null) {
  			int groupID = Integer.parseInt(getIWApplicationContext().getApplicationSettings().getProperty(IWMarathonConstants.PROPERTY_SPONSOR_GROUP_ID, "-1"));
  			if (groupID != -1 && runner.getYear().isSponsoredRun()) {
  				try {
  					if (getUserBiz().isMemberOfGroup(groupID, runner.getUser())) {
  						runner.setSponsoredRunner(true);
  						return 0;
  					}
  				}
  				catch (RemoteException e) {
  					e.printStackTrace();
  				}
  			}
  			
  			age = new Age(runner.getUser().getDateOfBirth());
  		}
  		else {
  			age = new Age(runner.getDateOfBirth());
  		}
  		boolean isChild = age.getYears() <= 16;
  		
  		float runnerPrice = isChild ? runner.getDistance().getChildrenPrice(locale) : runner.getDistance().getPrice(locale);
  		if (runner.isOwnChip() || runner.isBuyChip()) {
  			runnerPrice = runnerPrice - chipDiscount;
  			if (runner.isBuyChip()) {
  				runnerPrice += chipPrice;
  			}
  		}
  		return runnerPrice;
  	}
  	
  	public int getNumberOfSiblings(Collection children) throws RemoteException {
  		int numberOfSiblings = 0;
  		
  		Iterator iter = children.iterator();
  		HashMap childCounter = new HashMap();
  		int counter = 0;
  		// Making sure I check all the children, since not all may be siblings
  		while (iter.hasNext()) {
  			Runner child = (Runner) iter.next();
  			try {
  				User user = child.getUser();
  				if (user != null) {
  					Collection uPats = getFamilyLogic().getParentsFor(user);
  					Iterator piter = uPats.iterator();
  					while (piter.hasNext()) {
  						User pat = (User) piter.next();
  						if (!childCounter.containsKey(pat)) {
  							childCounter.put(pat, new Integer(1));
  						} else {
  							childCounter.put(pat, new Integer(((Integer) childCounter.get(pat)).intValue()+1));
  						}
  					}
  				}
  			} catch (NoParentFound e) {
  			}
  			++counter;
  		}
  		
  		Collection values = childCounter.values();
  		if (values != null && !values.isEmpty()) {
  			Iterator viter = values.iterator();
  			Integer val = (Integer) viter.next();
  			numberOfSiblings = val.intValue();
  			while (viter.hasNext()) {
  				val = (Integer) viter.next();
  				numberOfSiblings = Math.max(numberOfSiblings, val.intValue());
  			}
  		}
  		
  		return numberOfSiblings;
  	}
  	
  	public int getNumberOfChildren(Collection runners) {
  		int numberOfChildren = 0;
  
  			Iterator iter = runners.iterator();
  			while (iter.hasNext()) {
  				Runner runner = (Runner) iter.next();
  				Age age = null;
  				if (runner.getUser() != null) {
  					age = new Age(runner.getUser().getDateOfBirth());
  				}
  				else {
  					age = new Age(runner.getDateOfBirth());
  				}
  				if (age.getYears() <= 12) {
  					numberOfChildren++;
  				}
  			}
  		
  		return numberOfChildren;
  	}
  	
  	private FamilyLogic getFamilyLogic() {
  		try {
  			return (FamilyLogic) getServiceInstance(FamilyLogic.class);
  		}
  		catch (IBOLookupException ile) {
  			throw new IBORuntimeException(ile);
  		}
  	}
  
  	public CharityBusiness getCharityBusiness() {
  		try {
  			return (CharityBusiness) getServiceInstance(CharityBusiness.class);
  		}
  		catch (IBOLookupException ile) {
  			throw new IBORuntimeException(ile);
  		}
  	}
  	
  	public Collection getCreditCardImages() {
  		try {
  			return getCreditCardBusiness().getCreditCardTypeImages(getCreditCardBusiness().getCreditCardClient(getCreditCardMerchant()));
  		}
  		catch (FinderException fe) {
  			fe.printStackTrace();
  		}
  		catch (Exception e) {
  			e.printStackTrace();
  		}
  		return new ArrayList();
  	}
  	
  	private CreditCardMerchant getCreditCardMerchant() throws FinderException {
  		String merchantPK = getIWApplicationContext().getIWMainApplication().getBundle(IWMarathonConstants.IW_BUNDLE_IDENTIFIER).getProperty(IWMarathonConstants.PROPERTY_MERCHANT_PK);
  		if (merchantPK != null) {
  			try {
  				return ((KortathjonustanMerchantHome) IDOLookup.getHome(KortathjonustanMerchant.class)).findByPrimaryKey(new Integer(merchantPK));
  			}
  			catch (IDOLookupException ile) {
  				throw new IBORuntimeException(ile);
  			}
  		}
  		return null;
  	}
  	
  	public void savePayment(int userID, int distanceID, String payMethod, String amount) {
  		try {
  			ParticipantHome runHome = (ParticipantHome) getIDOHome(Participant.class);
  			Participant run = runHome.findByUserIDandDistanceID(userID,distanceID);
  			if(run != null) {
  				run.setPayMethod(payMethod);
  				run.setPayedAmount(amount);
  				run.store();
  			}
  		}
  		catch (RemoteException e) {
  			e.printStackTrace();
  		}
  		catch (FinderException e) {
  			e.printStackTrace();
  		}
  	}
  
  	public void updateRunForParticipant(Participant participant, int bibNumber, String runTime, String chipTime, String splitTime1, String splitTime2) {
  		if(runTime != null) {
  			runTime = runTime.trim();
  			if (!runTime.equals("")) {
  				participant.setRunTime(convertTimeToInt(runTime));
  			}
  		}
  		if(chipTime != null) {
  			chipTime = chipTime.trim();
  			if(!chipTime.equals("")) {
  				participant.setChipTime(convertTimeToInt(chipTime));
  			}
  		}
  		if(splitTime1 != null) {
  			splitTime1 = splitTime1.trim();
  			if(!splitTime1.equals("")) {
  				participant.setSplitTime1(convertTimeToInt(splitTime1));
  			}
  		}
  		if(splitTime2 != null) {
  			splitTime2 = splitTime2.trim();
  			if(!splitTime2.equals("")) {
  				participant.setSplitTime2(convertTimeToInt(splitTime2));
  			}
  		}
  		participant.setParticipantNumber(bibNumber);
  		participant.store();
  	}
  	
  	private int convertTimeToInt(String time) {
  		if (time == null || time.equals("-1")) {
  			return -1;
  		}
  		int index = time.lastIndexOf(":");
  		if (index == -1) {
  			return Integer.parseInt(time);
  		}
  		int hours = 0;
  		int minutes = 0;
  		int seconds = Integer.parseInt(time.substring(index + 1));
  		time = time.substring(0, index);
  		if (time.indexOf(":") != -1) {
  			hours = Integer.parseInt(time.substring(0, time.indexOf(":")));
  			minutes = Integer.parseInt(time.substring(time.indexOf(":") + 1));
  		}
  		else {
  			minutes = Integer.parseInt(time);
  		}
  		seconds += hours * 60 * 60;
  		seconds += minutes * 60;
  		
  		return seconds;
  	}
  	
  	public Participant getRunObjByUserIDandYearID(int userID, int yearID) {
  		try {
  			ParticipantHome runHome = (ParticipantHome) getIDOHome(Participant.class);
  			return runHome.findByUserIDandYearID(userID,yearID);
  		}
  		catch (RemoteException e) {
  			log(e);
  		}
  		catch (FinderException e) {
  			log(e);
  		}
  		 
  		return null;
  	}
  	
  	public Participant getRunObjByUserIDandDistanceID(int userID, int distanceID) {
  		try {
  			ParticipantHome runHome = (ParticipantHome) getIDOHome(Participant.class);
  			return runHome.findByUserIDandDistanceID(userID,distanceID);
  		}
  		catch (RemoteException e) {
  			log(e);
  		}
  		catch (FinderException e) {
  			log(e);
  		}
  		 
  		return null;
  	}
  	
  	public Participant getParticipantByDistanceAndParticipantNumber(Object distancePK, int participantNumber) throws FinderException {
  		try {
  			ParticipantHome runHome = (ParticipantHome) getIDOHome(Participant.class);
  			return runHome.findByDistanceAndParticipantNumber(distancePK, participantNumber);
  		}
  		catch (RemoteException e) {
  			throw new IBORuntimeException(e);
  		}
  	}
  	
  	public Collection getParticipantsByYearAndTeamName(Object yearPK, String teamName) throws FinderException {
  		try {
  			ParticipantHome runHome = (ParticipantHome) getIDOHome(Participant.class);
  			return runHome.findByYearAndTeamName(yearPK, teamName);
  		}
  		catch (RemoteException e) {
  			throw new IBORuntimeException(e);
  		}
  	}
  	
  	public Collection getParticipantsByYearAndCrewInOrCrewInvitationParticipantId(Object yearPK, Integer crewParticipantId) throws FinderException {
  		try {
  			ParticipantHome runHome = (ParticipantHome) getIDOHome(Participant.class);
  			return runHome.findByYearAndCrewInOrCrewInvitationParticipantId(yearPK, crewParticipantId);
  		}
  		catch (RemoteException e) {
  			throw new IBORuntimeException(e);
  		}
  	}
  	
  	public Collection getParticipantsByUser(User user) throws FinderException {
  		try {
  			ParticipantHome runHome = (ParticipantHome) getIDOHome(Participant.class);
  			return runHome.findByUserID(((Integer)user.getPrimaryKey()).intValue());
  		}
  		catch (RemoteException e) {
  			throw new IBORuntimeException(e);
  		}
  	}
  	
  	/**
  	 * 
  	 * @param yearPK
  	 * @param searchQuery
  	 * @return - participants, where search query matches either participant user full name, or personal id, or participant number
  	 * @throws FinderException
  	 */
  	public Collection getParticipantsBySearchQuery(Object yearPK, String searchQuery) throws FinderException {
  		try {
  			ParticipantHome participantHome = (ParticipantHome) getIDOHome(Participant.class);
  			return participantHome.findByYearAndFullNameOrPersonalIdOrParticipantNumberOrParentGroup(yearPK, searchQuery);
  		}
  		catch (RemoteException e) {
  			throw new IBORuntimeException(e);
  		}
  	}
  
  	public Participant getParticipantByRunAndYear(User user, Group run, Group year) throws FinderException {
  		try {
  			ParticipantHome runHome = (ParticipantHome) getIDOHome(Participant.class);
  			return runHome.findByUserAndRun(user, run, year);
  		}
  		catch (RemoteException e) {
  			throw new IBORuntimeException(e);
  		}
  	}
  	
  	public Group getRunGroupByGroupId(Integer groupId) {
  		try {
  			GroupHome groupHome = (GroupHome) getIDOHome(Group.class);
  			return groupHome.findByPrimaryKey(groupId);
  		}
  		catch (RemoteException e) {
  			log(e);
  		}
  		catch (FinderException e) {
  			log(e);
  		}
  		return null;
  	}
  	public Participant getRunObjByUserAndGroup(int userID, int groupID) {
  		Participant run = null;
  		int yearGroupID = -1;
  		int distanceGroupID = -1;
  		int runGroupID = -1;
  		Group group = null;
  		Collection parentGroups = null;
  		try {
  			group = getGroupBiz().getGroupByGroupID(groupID);
  			if(group != null) {
  				parentGroups = getGroupBiz().getParentGroupsRecursive(group);
  			}
  		}
  		catch (IBOLookupException e) {
  			e.printStackTrace();
  		}
  		catch (RemoteException e) {
  			e.printStackTrace();
  		}
  		catch (FinderException e) {
  			e.printStackTrace();
  		}
  		if(parentGroups != null && !parentGroups.isEmpty()) {
  			Iterator groupIter = parentGroups.iterator();
  			while(groupIter.hasNext()) {
  				Group parentGroup = (Group) groupIter.next();
  				if(parentGroup.getGroupType().equals(IWMarathonConstants.GROUP_TYPE_RUN)) {
  					runGroupID = Integer.parseInt(parentGroup.getPrimaryKey().toString());
  				}
  				else if(parentGroup.getGroupType().equals(IWMarathonConstants.GROUP_TYPE_RUN_YEAR)) {
  					yearGroupID = Integer.parseInt(parentGroup.getPrimaryKey().toString());
  				}
  				else if(parentGroup.getGroupType().equals(IWMarathonConstants.GROUP_TYPE_RUN_DISTANCE)) {
  					distanceGroupID = Integer.parseInt(parentGroup.getPrimaryKey().toString());
  				}
  			}
  		}
  		try {
  			ParticipantHome runHome = (ParticipantHome) getIDOHome(Participant.class);
  			if(runGroupID != -1 && yearGroupID != -1 && distanceGroupID != -1) {
  				Collection runObjs = runHome.findByUserAndParentGroup(userID,runGroupID,2004,distanceGroupID);
  				if(runObjs != null && !runObjs.isEmpty()) {
  					Iterator runIt = runObjs.iterator();
  					while(runIt.hasNext()) {
  						Participant runObj = (Participant) runIt.next();
  						run = runObj;
  					}
  				}
  			}
  		}
  		catch (RemoteException e1) {
  			e1.printStackTrace();
  		}
  		catch (FinderException e1) {
  			e1.printStackTrace();
  		}
  		return run;
  	}
  	
  	public Collection getRunnersByDistance(Group distance, Group runGroup) {
  		try {
  			ParticipantHome runHome = (ParticipantHome) getIDOHome(Participant.class);
  			return runHome.findAllByDistanceAndGroup(distance, runGroup);
  		}
  		catch (RemoteException e) {
  			log(e);
  		}
  		catch (FinderException e) {
  			log(e);
  		}
  		 
  		return new ArrayList();
  	}
  	
  	public void setParticipantNumber(Participant participant, String run) {
  		participant.setParticipantNumber(getNextAvailableParticipantNumber(participant.getRunDistanceGroup()));
  		participant.store();
  	}
  
  	public void sendMessage(String email, String subject, String body) {
  		boolean sendEmail = true;
  		String sSendEmail = this.getIWMainApplication().getBundle(IW_BUNDLE_IDENTIFIER).getProperty(IWMarathonConstants.PROPERTY_SEND_EMAILS);
  		if ("no".equalsIgnoreCase(sSendEmail)) {
  			sendEmail = false;
  		}
  		
  		if (sendEmail) {
  			String mailServer = DEFAULT_SMTP_MAILSERVER;
  			String fromAddress = DEFAULT_MESSAGEBOX_FROM_ADDRESS;
  			String cc = DEFAULT_CC_ADDRESS;
  			try {
  				MessagingSettings messagingSetting = getIWApplicationContext().getIWMainApplication().getMessagingSettings();
  				mailServer = messagingSetting.getSMTPMailServer();
  				fromAddress = messagingSetting.getFromMailAddress();
  				cc = getIWApplicationContext().getIWMainApplication().getSettings().getProperty("messagebox_cc_receiver_address","");
  			}
  			catch (Exception e) {
  				System.err.println("MessageBusinessBean: Error getting mail property from bundle");
  				e.printStackTrace();
  			}
  			
  			try {
  				com.idega.util.SendMail.send(fromAddress, email.trim(), cc, "", mailServer, subject, body);
  			}
  			catch (javax.mail.MessagingException me) {
  				System.err.println("MessagingException when sending mail to address: " + email + " Message was: " + me.getMessage());
  			}
  			catch (Exception e) {
  				System.err.println("Exception when sending mail to address: " + email + " Message was: " + e.getMessage());
  			}
  		}
  	}
  
  	/**
  	 * @param age
  	 * @param nameOfGroup
  	 * @return
  	 */
  	private String getGroupName(int age, Group group, int genderID, Group distance) {
  		String runName = group.getName();
  		String nameOfGroup = "";
  		if (runName.equals(RUN_RVK_MARATHON) || runName.equals(RUN_ROLLER_SKATE)) {
  			if (distance.getName().equals(IWMarathonConstants.DISTANCE_1_5)) {
  				if (genderID == 2) {
  					nameOfGroup = IWMarathonConstants.FEMALE_11;
  				} else {
  					nameOfGroup = IWMarathonConstants.MALE_11;
  				}
  			} else {
  				if (age <= 14) {
  					if (genderID == 2) {
  						nameOfGroup = IWMarathonConstants.FEMALE_14;
  					}
  					else {
  						nameOfGroup = IWMarathonConstants.MALE_14;
  					}
  				}
  				else if (age > 14 && age <= 17) {
  					if (genderID == 2) {
  						nameOfGroup = IWMarathonConstants.FEMALE_15_17;
  					}
  					else {
  						nameOfGroup = IWMarathonConstants.MALE_15_17;
  					}
  				}
  				else if (age > 17 && age <= 39) {
  					if (genderID == 2) {
  						nameOfGroup = IWMarathonConstants.FEMALE_18_39;
  					}
  					else {
  						nameOfGroup = IWMarathonConstants.MALE_18_39;
  					}
  				}
  				else if (age > 39 && age <= 49) {
  					if (genderID == 2) {
  						nameOfGroup = IWMarathonConstants.FEMALE_40_49;
  					}
  					else {
  						nameOfGroup = IWMarathonConstants.MALE_40_49;
  					}
  				}
  				else if (age > 49 && age <= 59) {
  					if (genderID == 2) {
  						nameOfGroup = IWMarathonConstants.FEMALE_50_59;
  					}
  					else {
  						nameOfGroup = IWMarathonConstants.MALE_50_59;
  					}
  				}
  				else if (age > 59) {
  					if (genderID == 2) {
  						nameOfGroup = IWMarathonConstants.FEMALE_60;
  					}
  					else {
  						nameOfGroup = IWMarathonConstants.MALE_60;
  					}
  				}
  			}
  		}
  		if (runName.equals(RUN_LAZY_TOWN_RUN)) {
  			if (distance.getName().equals(IWMarathonConstants.DISTANCE_1)) {
  				if (genderID == 2) {
  					nameOfGroup = IWMarathonConstants.FEMALE_9;
  				} else {
  					nameOfGroup = IWMarathonConstants.MALE_9;
  				}
  			}
  		}
  		else if (runName.equals(RUN_LAZY_TOWN_MINIMARATON_OSLO)) {
  			if (distance.getName().equals(IWMarathonConstants.DISTANCE_0_5)) {
  				if (genderID == 2) {
  					nameOfGroup = IWMarathonConstants.FEMALE_9;
  				} else {
  					nameOfGroup = IWMarathonConstants.MALE_9;
  				}
  			}
  		}
  		else if (runName.equals(RUN_OSLO_MARATHON)) {
  			if (age >= 18 && age <= 22) {
  				if (genderID == 2) {
  					nameOfGroup = IWMarathonConstants.FEMALE_18_22;
  				}
  				else {
  					nameOfGroup = IWMarathonConstants.MALE_18_22;
  				}
  			}
  			else if (age > 22 && age <= 34) {
  				if (genderID == 2) {
  					nameOfGroup = IWMarathonConstants.FEMALE_23_34;
  				}
  				else {
  					nameOfGroup = IWMarathonConstants.MALE_23_34;
  				}
  			}
  			else if (age > 34 && age <= 39) {
  				if (genderID == 2) {
  					nameOfGroup = IWMarathonConstants.FEMALE_35_39;
  				}
  				else {
  					nameOfGroup = IWMarathonConstants.MALE_35_39;
  				}
  			}
  			else if (age > 39 && age <= 44) {
  				if (genderID == 2) {
  					nameOfGroup = IWMarathonConstants.FEMALE_40_44;
  				}
  				else {
  					nameOfGroup = IWMarathonConstants.MALE_40_44;
  				}
  			}
  			else if (age > 44 && age <= 49) {
  				if (genderID == 2) {
  					nameOfGroup = IWMarathonConstants.FEMALE_45_49;
  				}
  				else {
  					nameOfGroup = IWMarathonConstants.MALE_45_49;
  				}
  			}
  			else if (age > 49 && age <= 54) {
  				if (genderID == 2) {
  					nameOfGroup = IWMarathonConstants.FEMALE_50_54;
  				}
  				else {
  					nameOfGroup = IWMarathonConstants.MALE_50_54;
  				}
  			}
  			else if (age > 54 && age <= 59) {
  				if (genderID == 2) {
  					nameOfGroup = IWMarathonConstants.FEMALE_55_59;
  				}
  				else {
  					nameOfGroup = IWMarathonConstants.MALE_55_59;
  				}
  			}
  			else if (age > 59 && age <= 64) {
  				if (genderID == 2) {
  					nameOfGroup = IWMarathonConstants.FEMALE_60_64;
  				}
  				else {
  					nameOfGroup = IWMarathonConstants.MALE_60_64;
  				}
  			}
  			else if (age > 64 && age <= 69) {
  				if (genderID == 2) {
  					nameOfGroup = IWMarathonConstants.FEMALE_65_69;
  				}
  				else {
  					nameOfGroup = IWMarathonConstants.MALE_65_69;
  				}
  			}
  			else if (age > 69 && age <= 74) {
  				if (genderID == 2) {
  					nameOfGroup = IWMarathonConstants.FEMALE_70_74;
  				}
  				else {
  					nameOfGroup = IWMarathonConstants.MALE_70_74;
  				}
  			}
  			else if (age > 74 && age <= 79) {
  				if (genderID == 2) {
  					nameOfGroup = IWMarathonConstants.FEMALE_75_79;
  				}
  				else {
  					nameOfGroup = IWMarathonConstants.MALE_75_79;
  				}
  			}
  			else if (age > 79 && age <= 84) {
  				if (genderID == 2) {
  					nameOfGroup = IWMarathonConstants.FEMALE_80_84;
  				}
  				else {
  					nameOfGroup = IWMarathonConstants.MALE_80_84;
  				}
  			}
  			else if (age > 84 && age <= 99) {
  				if (genderID == 2) {
  					nameOfGroup = IWMarathonConstants.FEMALE_85_99;
  				}
  				else {
  					nameOfGroup = IWMarathonConstants.MALE_85_99;
  				}
  			}
  		}
  		else if (runName.equals(RUN_MIDNIGHT_RUN)) {
  			if (age <= 18) {
  				if (genderID == 2) {
  					nameOfGroup = IWMarathonConstants.FEMALE_18;
  				}
  				else {
  					nameOfGroup = IWMarathonConstants.MALE_18;
  				}
  			}
  			else if (age > 18 && age <= 39) {
  				if (genderID == 2) {
  					nameOfGroup = IWMarathonConstants.FEMALE_19_39;
  				}
  				else {
  					nameOfGroup = IWMarathonConstants.MALE_19_39;
  				}
  			}
  			else if (age > 39 && age <= 49) {
  				if (genderID == 2) {
  					nameOfGroup = IWMarathonConstants.FEMALE_40_49;
  				}
  				else {
  					nameOfGroup = IWMarathonConstants.MALE_40_49;
  				}
  			}
  			else if (age > 49) {
  				if (genderID == 2) {
  					nameOfGroup = IWMarathonConstants.FEMALE_50;
  				}
  				else {
  					nameOfGroup = IWMarathonConstants.MALE_50;
  				}
  			}
  		}
  