function openPDF(threadId, programId){
	window.open("/file/viewTool.html?program_id="+programId+"&thread_id="+threadId, "pdfWinID", "width=800, height=700,  scrollbars=no,  resizable=yes");
}

function openCoachPDF(threadId, conditionId){
	window.open("/file/viewTool.html?condition_id="+conditionId+"&thread_id="+threadId, "pdfWinID", "width=800, height=700,  scrollbars=no,  resizable=yes");
}

function createPDF(collectionId){
	window.open("/file/getSummary.html?collection_id="+collectionId, "pdfWinID", "width=800, height=700, menubar=yes, status=yes, scrollbars=no, toolbar=yes,location=no, resizable=yes");
}

function openLibraryItem(libItemId){
	window.open("/file/viewLibraryItem.html?item_id="+libItemId, "pdfWinID", "width=800, height=700, scrollbars=no, resizable=yes");
}

function openSpotlight(spotlightFile){
	window.open("/file/viewSpotlight.html?spotlightResource="+spotlightFile, "pdfWinID", "width=600, height=400, menubar=yes, status=yes, scrollbars=no, toolbar=yes,location=no, resizable=yes");
}

function popUpFAQs(URL) {
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=520,height=600');");
}

function popUpInfo(URL) {
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=520,height=480');");
}

/*
 * Add an exists() function to jquery.  It returns true if the object passed in is not null.
 */
jQuery.fn.exists = function(){return jQuery(this).length>0;}


/*
 * Returns a list of all the checked checkboxes in the form.
 * Assumes only one form exists on the page.  The form name/id is not important.
 * Takes a regular expression as an argument.  This must match the ids of the
 * checkbox elements you want to select.
 */
function getSelectedCheckboxes(exp){
	var theForm = document.forms[0];
	var re = new RegExp(exp);
	var results = new Array();
	for(i = 0; i < theForm.elements.length; i++){
		var element = theForm.elements[i];
		if (re.test(element.id)) {
			if (element.checked) {
				results[i] = element;
			}
		}
	}
	return results;
}


/*
 * Returns true if the date string is a valid mm/dd/yyyy date.
 */
function validDate(dateValue){
	var objRegExp = /^\d{1,2}(\/)\d{1,2}\1\d{4}$/;
	if(!objRegExp.test(dateValue)) {
		return false; //doesn't match pattern, bad date
	}
	else {
		var arrayDate = dateValue.split("/");
		if(arrayDate[0].charAt(0) == '0'){
			var tempMonth = arrayDate[0];
			tempMonth = tempMonth.substr(1);
			arrayDate[0] = tempMonth;
		}
		//create a lookup for months not equal to Feb.
		var arrayLookup = {'1':31,'3':31,'4':30,'5':31,'6':30,'7':31,'8':31,'9':30,'10':31,'11':30,'12':31}
		var intDay = parseInt(arrayDate[1],10);

		//check if month value and day value agree
		if(arrayLookup[arrayDate[0]] != null) {
			if(intDay <= arrayLookup[arrayDate[0]] && intDay != 0)  {
				return true; //found in lookup table, good date
			}
		}

		//check for February
		var intMonth = parseInt(arrayDate[0],10);
		if (intMonth == 2) {
			var intYear = parseInt(arrayDate[2]);
			if (intDay > 0 && intDay < 29) {
				return true;
			}
			else if (intDay == 29) {
				if ((intYear % 4 == 0) && (intYear % 100 != 0) || (intYear % 400 == 0)) {
					return true;
				}
			}
		}
	}
	return false; //any other values, bad date
}

/*
 * Compare two valid times (see validTime) return true if time1 is before time2.
 */
function compareTimes(time1,time2){
	var timePat = /^(\d{1,2}):(\d{2})(\s(AM|am|PM|pm))$/;
	var timeStr1 = time1;
	var timeStr2 = time2;

	var matchArray1 = timeStr1.match(timePat);
	hour1 = matchArray1[1];
	if(hour1.charAt(0) == '0'){
		hour1 = hour1.substr(1);
	}
	minute1 = matchArray1[2];
	ampm1 = matchArray1[4];

	var matchArray2 = timeStr2.match(timePat);
	hour2 = matchArray2[1];
	if(hour2.charAt(0) == '0'){
		hour2 = hour2.substr(1);
	}
	minute2 = matchArray2[2];
	ampm2 = matchArray2[4];

	hour1 = hour1 * 1;
	hour2 = hour2 * 1;
	minute1 = minute1 * 1;
	minute2 = minute2 * 1;

	if(ampm1.toLowerCase() == 'pm' && ampm2.toLowerCase() == 'am'){
		return false;
	}
	if(ampm1.toLowerCase() == 'pm' && ampm2.toLowerCase() == 'pm'){
		if(hour1==12){
			hour1 = 0;
		}
		if(hour2==12){
			hour2 = 0;
		}

		if(hour1>hour2){
			return false;
		}else if(hour1==hour2){
			if(minute1 >=minute2){
				return false;
			}
		}
	}
	if(ampm1.toLowerCase() == 'am' && ampm2.toLowerCase() == 'am'){
		if(hour1>hour2){
			return false;
		}else if(hour1==hour2){
			if(minute1 >= minute2){
				return false;
			}
		}
	}
	return true;
}

/*
 * Return true if the time string is a valid time in the form of "1:00 am"
 */
function validTime(timeStr) {
	if (timeStr == null)
		return false;
	
	var timePat = /^(\d{1,2}):(\d{2})(\s(AM|am|PM|pm))$/;
	var matchArray = timeStr.match(timePat);
	if (matchArray == null) {
		return false;
	}
	hour = matchArray[1];
	minute = matchArray[2];
	ampm = matchArray[4];

	if (ampm=="" || ampm == null) {
		return false;
	}
	if (hour <=0  || hour > 12) {
		return false;
	}
	if (minute<0 || minute > 59) {
		return false;
	}

	return true;
}


/*
 * Examine a named group of radio buttons.  Return true if any one of them is checked.
 */
function checkRadio (frmName, rbGroupName) {
	var radios = document[frmName].elements[rbGroupName];
	for (var i=0; i <radios.length; i++) {
		if (radios[i].checked) {
			return true;
		}
	}
	return false;
}

