function PutDate(iMonth, iDay, iYear, sMonthCtrlName, sDayCtrlName, sYearCtrlName) {
	var sMonth, sDay, sYear;
	
	sMonth 	= 'opener.' + sMonthCtrlName;
	sDay 	= 'opener.' + sDayCtrlName;
	sYear 	= 'opener.' + sYearCtrlName;
	
	if (typeof(opener.document) != 'object') { window.close(); return; }
	if (opener.document == null) { window.close(); return; }
	
    // SET THE VALUE OF THE FIELD THAT WAS PASSED TO THE CALENDAR
	if (typeof(eval(sMonth)) == "object") eval(sMonth + '.selectedIndex = ' + iMonth);
	if (typeof(eval(sDay)) == "object") eval(sDay + '.value = ' + iDay);
	if (typeof(eval(sYear)) == "object") eval(sYear + '.selectedIndex = ' + (iYear-2000));

    // GIVE FOCUS BACK TO THE DATE FIELD
	if (typeof(eval(sMonth)) == "object") eval(sMonth + '.focus()');

	window.close();
}

function PickDate(iMonth, iDay, iYear, sMonthCtrlName, sDayCtrlName, sYearCtrlName) {
	var sURL;
	
	sURL = '/include/datepicker.asp?MONTH=' + iMonth + '&DAY=' + iDay + '&YEAR=' + iYear + '&M_NAME=' + sMonthCtrlName + '&D_NAME=' + sDayCtrlName + '&Y_NAME=' + sYearCtrlName;
	var newwin = window.open(sURL, 'calendar', 'TOP=150,LEFT=300,WIDTH=170,HEIGHT=220,RESIZABLE=yes,SCROLLBARS=no,STATUS=0');
	if (newwin != null)
	{
		if (newwin.opener == null)
			newwin.opener = self;
	}
}


function getIndex(arrayName, value) {
	for (var i=0; i < arrayName.length; i++) if(value == arrayName[i]) return i;
	return -1;
}

function push(arrayName,value) {
	arrayName[arrayName.length+1] = value;
}

function remove(arrayName, index) {
	for (i=index; i< arrayName.length-1; i++) {
		arrayName[i] = arrayName[i+1];
	}
	arrayName.length = arrayName.length -1;	
}

function getAllCheckboxValues(saved, form, prefix) {
	savedArray = saved.split(",");

	// for each element on the form
	for (var i=0; i< form.elements.length; i++) {
		element = form.elements[i];
		name = new String(element.name);

		if (name.indexOf(prefix) >=0 ) {

			j = getIndex(savedArray, element.value);
			if (element.checked) {
				// Add element but only when doesn't exist in the savedArray
				if ( j < 0 ) push(savedArray, element.value);
			}else{
				// Delete element when exists in the savedArray
				if ( j >= 0) remove(savedArray,j);
			}
		}
	}
	result = ""
	connstr = "";

	for(i = 0; i< savedArray.length; i++) {
		if (!isEmpty(savedArray[i])) {
			result = result + connstr + savedArray[i];
			connstr = ","
		}
	}
	return result;
}

function getValue(Field) {
	fieldType = Field.type;

	if (fieldType == "text") {
		return getTextValue(Field);
	} else if (fieldType == "hidden") {
		return getTextValue(Field);
	} else if (fieldType == "select-one") {
		return getListValue(Field);
	} else if (fieldType == "textarea") {
		return getTextValue(Field);
	} else if (fieldType == "file") {
		return getTextValue(Field);
	} else if (fieldType == "password") {
		return getTextValue(Field);
	} else if (fieldType == "checkbox") {
		return getCheckboxValue(Field);
	} else if (isNaN(fieldType)) {
		return getRadioValue(Field);
	} else {
		return getTextValue(Field);
	}
}

function isEmptyField(Field) {
	fieldType = Field.type;

	if (fieldType == "text") {
		return isEmptyText(Field);
	} else if (fieldType == "hidden") {
		return isEmptyText(Field);
	} else if (fieldType == "file") {
		return isEmptyText(Field);
	} else if (fieldType == "select-one") {
		return isEmptyList(Field);
	} else if (fieldType == "select-multiple") {
		return isEmptyMultipleList(Field);
	} else if (fieldType == "textarea") {
		return isEmptyText(Field);
	} else if (fieldType == "password") {
		return isEmptyText(Field);
	} else if (fieldType == "checkbox") {
		return isEmptyCheckbox(Field)
	} else if (isNaN(fieldType)) {
		return isEmptyRadio(Field)
	} else {
		return isEmptyText(Field);
	}
}

function isCurrency(Field) {
	strValue = Field.value;

	regexp = /^(([0-9]{1,3}(\,[0-9]{3})*)|([0-9]{0,3}))(\.[0-9]{2})?$/

	if (isEmpty(strValue)) {
		return false;
	}
	return regexp.test(strValue);
}


function isFloat(Field) {
	strValue = Field.value;

	regexp = /^(\+|\-)?([0-9]+)(((\.|\,)?([0-9]+))?)$/

	if (isEmpty(strValue)) {
		return false;
	}
	return regexp.test(strValue);
}	

function isInteger(Field) {
	strValue = getValue(Field);

	regexp = /^(\+|\-)?([0-9]+)$/
	if (isEmpty(strValue)) {
		return false;
	}
	return regexp.test(strValue);
}	

function isMemberUserName(Field) {
	strValue = getValue(Field);

	regexp = /^[^*]([^$@\\ ]+)$/
	if (isEmpty(strValue)) {
		return false;
	}
	return regexp.test(strValue);
}	

function isUserName(Field) {
	strValue = getValue(Field);

	regexp = /^([^$@\\ ]+)$/
	if (isEmpty(strValue)) {
		return false;
	}
	return regexp.test(strValue);
}	

function isEmail(Field) {
	strValue = getValue(Field);

	regexp = /^([^$@\\ ]+)@((([^$@\\ \.]+)\.)+)([A-Za-z0-9]+)$/
	if (isEmpty(strValue)) {
		return false;
	}
	return regexp.test(strValue);
}	

function isURL(Field) {
	strValue = getValue(Field);

	regexp = /^http(s?):\/\/([^$@\\ ]+)$/i
	if (isEmpty(strValue)) {
		return false;
	}
	return regexp.test(strValue);
}	

function isEmailList(Field) {
	strValue = getValue(Field);
	strArray = strValue.split(";");

	regexp = /^([^$@\\ ]+)@((([^$@\\ \.]+)\.)+)([A-Za-z0-9]+)$/

	for (i=0; i < strArray.length; i++) {
		if (isEmpty(strArray[i])) return false;
		if (!regexp.test(strArray[i])) return false;
	}
	return true;
}	

function isEmptyCheckbox(Field) {
	return !Field.checked;
}

function isEmptyRadio(Field) {
	found = false;
	for(i=0; i< Field.length; i++) {
		if ( Field[i].checked ) {
			found = true;
			break;
		}
	}	
	return !found;
}

function getListValue(Field) {
	return Field[Field.selectedIndex].value;
}

function getTextValue(Field) {
	return Field.value;
}

function getCheckboxValue(Field) {

	if (Field.checked) return Field.value;
	return '';
}

function getRadioValue(Field) {
	found = false;
	for(i=0; i< Field.length; i++) {
		if ( Field[i].checked ) {
			return Field[i].value;
			break;
		}
	}	
	return !found;
}

function isZip(Field) {
	strValue = getValue(Field);

	regexp = /^\d{5}|\d{5}-\d{4}$/
	if (isEmpty(strValue)) {
		return false;
	}
	return regexp.test(strValue);
}

function isPhone(Field) {
	strValue = getValue(Field);

	regexp = /^\d{3}-\d{3}-\d{4}$/
	if (isEmpty(strValue)) {
		return false;
	}
	return regexp.test(strValue);
}

function isFax(Field) {
	strValue = getValue(Field);

	regexp = /^\d{3}-\d{3}-\d{4}$/
	if (isEmpty(strValue)) {
		return false;
	}
	return regexp.test(strValue);
}

function isEmptyList(Field) {
	if (Field.selectedIndex == -1) return true;
	return isEmpty(Field[Field.selectedIndex].value);
}

function isEmptyMultipleList(Field) {
	if (Field.selectedIndex == -1) return true;
	return isEmpty(Field[Field.selectedIndex].value);
}

function isEmptyText(Field) {
	return isEmpty(Field.value)
}

function isEmpty(s) {
	if (s == null || s == '') {
		return true;
	}else{
		return false;
	}
}

function convertYear(y) {
	var borderYEAR = 40;

	yearvalue = parseInt(y,10);
	if (isNaN(yearvalue)) return y;

	if (yearvalue - borderYEAR <= 0) {
		yearvalue = yearvalue + 2000
	} else if (yearvalue - 100 < 0) {
		yearvalue = yearvalue + 1900
	}

	return yearvalue;
}

function CheckTime(hh,mm,ampm) {
	if (isNaN(parseInt(hh,10))) return false;
	if (isNaN(parseInt(mm,10))) return false;
	if (isEmpty(ampm)) return false;

	hh = parseInt(hh,10);
	mm = parseInt(mm,10);
	
	if (ampm == 'PM' && hh > 12) return false;
	return true;
}

function CheckDate(m,d,y) {
	Months = "31/!/28/!/31/!/30/!/31/!/30/!/31/!/31/!/30/!/31/!/30/!/31";
	MonthArray  = Months.split("/!/");

	if (isNaN(parseInt(m,10))) return false;
	if (isNaN(parseInt(d,10))) return false;
	if (isNaN(parseInt(y,10))) return false;

	d = parseInt(d,10);
	y = parseInt(y,10);
	m = parseInt(m,10);

	y = convertYear(y);

	if (y <= 1900 ) return false;
	if (m < 1 || m > 12 ) return false;
	if ( isLeapYear(y)) MonthArray[1] = eval(eval(MonthArray[1]) + 1);

	if (d<1 || MonthArray[m-1] < d ) return false;
	return true;
}

function isLeapYear(Year)
{
	if(Math.round(Year/4) == Year/4){
		if(Math.round(Year/100) == Year/100){
			if(Math.round(Year/400) == Year/400)
				return true;
			else return false;
		}else return true;
	}
	return false;
}


function trim(str) {
	while (str.substring(0,1) == " ") {
		str = str.substring(1,str.length);
	}
	while (str.substring(str.length-1,str.length) == " ") {
		str = str.substring(0,str.length-1);
	}
	return str;
}