package org.ofbiz.opentravelsystem;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class UtilValidate extends org.ofbiz.base.util.UtilValidate{
	public static boolean isCreditCard(String stPassed) {
        if (org.ofbiz.base.util.UtilValidate.isEmpty(stPassed)) 
        	return false;
        String st = org.ofbiz.base.util.UtilValidate.stripCharsInBag(stPassed, org.ofbiz.base.util.UtilValidate.creditCardDelimiters);
        if (st.length() != 16) return false;
        
        if(st.charAt(0) == '0')
        	return false;
        return org.ofbiz.base.util.UtilValidate.sumIsMod10(org.ofbiz.base.util.UtilValidate.getLuhnSum(st));
    }
	
	/** isDate returns true if string argument date forms a valid date. */
    public static boolean isDate(String dateString, String format) {
        if (isEmpty(dateString)) return defaultEmptyOK;
        String month;
        String day;
        String year;
        
        SimpleDateFormat dateFormatter = new SimpleDateFormat(format);
        try {
			Date date = dateFormatter.parse(dateString);
			Calendar cal = Calendar.getInstance();
			cal.setTime(date);
			year = ""+ cal.get(Calendar.YEAR);
			month = ""+ (cal.get(Calendar.MONTH)+1);
			day = "" + cal.get(Calendar.DATE);
			return isDate(year, month, day);
		} catch (ParseException e) {
			return false;
		}
        //int dateSlash1 = date.indexOf(fieldSeparator);
        //int dateSlash2 = date.lastIndexOf(fieldSeparator);

        

        //return isDate(year, month, day);
    }
}
