function isEmpty(inputStr){
	if(inputStr == null || inputStr.length == 0){
		return true;
	}
	else {
		return false;
	}
}

function numeric(evt){
	var charCode = (evt.which) ? evt.which : evt.keyCode;
	if(charCode > 31 && (charCode < 48 || charCode > 57 )){
		return false;
	}
	return true;
}

/**
 * Date validation script for mm/dd/yyyy.
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function validateDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		return "Date values must conform to the following format: mm/dd/YYYY";
	}
	if (strMonth.length<1 || month<1 || month>12){
		return "Date values must contain a valid month";
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		return "Date values must contain a valid day";
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		return "Date values must contain a valid four-digit year between "+minYear+" and "+maxYear;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		return "The date value supplied is invalid";
	}
	return "";
}

function arrayContains(array, value){
	var contains = false;
	for(var i = 0; i < array.length; i++){
		if(array[i] == value){
			contains = true;
			break;
		}
	}
	return contains;
}

function validateTime(time){
	if(time.length > 5 || time.length < 4){
		return "The value contains the wrong number of characters";
	}				
	var amPm = time.toLowerCase().charAt(time.length-1);
	if(amPm != 'a' && amPm != 'p'){
		return "The last character must be 'a' or 'p'";
	}				
	if(isNaN(time.charAt(time.length-2))){
		return "The minutes value must be a number";
	}		
	var minutes1 = time.charAt(time.length-3);
	if(isNaN(minutes1) || minutes1 > 5){
		return "The first digit of the minutes value must be a number less than 5";
	}				
	var hours = time.substring(0, time.length-3);
	if(isNaN(hours)){
		return "The hours value must be a number";
	}				
	if(hours.length > 1){
		if(hours.charAt(0) == 0){
			return "The hours value must not contain a leading zero";
		}
		if(hours.charAt(0) > 1 || hours.charAt(1) > 2){
			return "The hours value must be a number between 1 and 12";
		}
	}
	else{
		if(hours.charAt(0) == 0){
			return "The hours value must be a number between 1 and 12";
		}
	}
	return "";
}

function getMonth(date){
	var strMonth = date.substring(0,date.indexOf(dtCh));
	if(strMonth.charAt(0)=="0" && strMonth.length>1){ 
		strMonth=strMonth.substring(1)
	}
	return strMonth;
}

function getDay(date){
	var pos1=date.indexOf(dtCh);
	var pos2=date.indexOf(dtCh,pos1+1);
	return date.substring(pos1+1,pos2);
}

function getYear(date){
	var pos1=date.indexOf(dtCh);
	var pos2=date.indexOf(dtCh,pos1+1);
	return date.substring(pos2+1)
}

function getHours(time){
	return time.substring(0, time.length-3);	
}

function getHoursIn24HourTime(time){
	var hours = parseInt(time.substring(0, time.length-3));
	var amPm = time.toLowerCase().charAt(time.length-1);
	if(amPm == 'p' && hours != 12){
		hours = hours + 12;
	}				
	else if(amPm == 'a' && hours == 12){
		hours = 0;
	}				
	return hours;	
}

function getMinutes(time){
	var minutes = time.substring(time.length-3, time.length-1);	
	if(minutes.charAt(0) == "0")
		minutes = minutes.substring(1);
	return minutes;
}

function getTimeDifferenceInHours(startTime, endTime){
	var startHours = parseInt(getHoursIn24HourTime(startTime));
	var endHours = parseInt(getHoursIn24HourTime(endTime));
	var startMinutes = parseInt(getMinutes(startTime));
	var endMinutes = parseInt(getMinutes(endTime));
	var hoursDiff;
	var minutesDiff;
	if(endHours >= startHours){
		hoursDiff = endHours - startHours;
	}
	else{
		hoursDiff = (24 - startHours) + endHours;
	}
	if(endMinutes >= startMinutes){
		minutesDiff = endMinutes - startMinutes;
	}
	else{
		hoursDiff = hoursDiff - 1;
		minutesDiff = (endMinutes - startMinutes) + 60;
	}
	return hoursDiff + (minutesDiff/60);
}




