function searchTopic(fld) {
	
	var url = "http://" + window.location.host + "/catalog-comp-search.asp?goComp=Search&";
	url += fld.name + "=" + fld.options[fld.selectedIndex].value;
	window.location.href = url;
}

function searchDate(frm) {
	
	var url = "http://" + window.location.host + "/catalog-comp-search.asp?goDate=Search&";
	var mo, yr, da, ok = false, msg1 = "", msg2 = "";

	mo = frm.start1.value;
	da = frm.start2.value;
	yr = frm.start3.value;

	if( isValidDate(mo, da, yr) ) {
		url += "start1=" + mo + "&start2=" + da + "&start3=" + yr;

		mo = frm.end1.value;
		da = frm.end2.value;
		yr = frm.end3.value;

		if( isValidDate(mo, da, yr) || ((mo == null && da == null && yr == null) || (mo == "" && da == "" & yr == "")) ) {
			url += "&end1=" + mo + "&end2=" + da + "&end3=" + yr;
			window.location.href = url;
			return false;
		} else {
			msg2 = "Please specify a valid end date, using numbers for month, day and year."
		}
	} else {
		msg1 = "Please specify a valid start date, using numbers for month, day and year."
	}

	if( msg1.length > 0 )
		msg1 += "\n";

	alert(msg1 + msg2);

	return false;
}

function isValidDate(mo, da, yr) {
	if( mo != null && da != null && yr != null && !isNaN(parseInt(mo)) && !isNaN(parseInt(da)) && !isNaN(parseInt(yr)) ) {
		mo = parseInt(mo);
		da = parseInt(da);
		yr = parseInt(yr);

		if( mo <= 0 || mo > 12 || da <= 0 || da > 31 || yr <= 0 )
			return false;

		if( yr < 2000 ) yr += 2000;

		if( yr > 2010 )
			return false;

		switch( mo ) {
			case 1:
			case 3:
			case 5:
			case 7:
			case 8:
			case 10:
			case 12:
				return true;
			case 2:
				if( da > 29 )
					return false;
				if( da <= 28 )
					return true;
				return (yr % 4 == 0 && yr % 100 != 0) || yr % 400 == 0;
				break;
			case 4:
			case 6:
			case 9:
			case 11:
				if( da > 30 )
					return false;
				else
					return true;
		}
	} else {
		return false;
	}

	return false;
}

function searchKeyword(fld) {

	if( !fld.value || null != fld.value.match(/^\s+$/) ) {
		fld.value = "";
	}

	/*
	// searching with leading or tailing spaces might be useful.
	var m = fld.value.match(/^(\s*)([^\s].*[^\s])(\s*)$/);

	if( m != null )
		fld.value = m[2];
	*/

	if( fld.value && fld.value.length > 3 ) {
		var url = "http://" + window.location.host + "/catalog-training-search.asp?goKeyword=Search&";
		url += fld.name + "=" + escape(fld.value);
		window.location.href = url;
	} else {
		alert("Please specify a non-blank keyword of at least 4 characters.")
	}

	return false;
}
function searchKeyword1(fld) {
	

	if( !fld.value || null != fld.value.match(/^\s+$/) ) {
		fld.value = "";
	}

	/*
	// searching with leading or tailing spaces might be useful.
	var m = fld.value.match(/^(\s*)([^\s].*[^\s])(\s*)$/);

	if( m != null )
		fld.value = m[2];
	*/

	if( fld.value && fld.value.length > 3 ) {
		var url = "http://" + window.location.host + "/new_search.asp?goKeyword=Search&";
		url += fld.name + "=" + escape(fld.value);
		window.location.href = url;
	} else {
		alert("Please specify a non-blank keyword of at least 4 characters.")
	}

	return false;
}
function searchKeywordr(fld) {
	

	if( !fld.value || null != fld.value.match(/^\s+$/) ) {
		fld.value = "";
	}

	/*
	// searching with leading or tailing spaces might be useful.
	var m = fld.value.match(/^(\s*)([^\s].*[^\s])(\s*)$/);

	if( m != null )
		fld.value = m[2];
	*/

	if( fld.value && fld.value.length > 3 ) {
		var url = "http://" + window.location.host + "/new_search.asp?goKeyword=Search&";
		url += fld.name + "=" + escape(fld.value);
		window.location.href = url;
	} else {
		alert("Please specify a non-blank keyword of at least 4 characters.")
	}

	return false;
}
function searchKeywordw(fld) {
	alert(fld);

	if( !fld.value || null != fld.value.match(/^\s+$/) ) {
		fld.value = "";
	}

	/*
	// searching with leading or tailing spaces might be useful.
	var m = fld.value.match(/^(\s*)([^\s].*[^\s])(\s*)$/);

	if( m != null )
		fld.value = m[2];
	*/

	 
		var url = "http://" + window.location.host + "/new_search.asp?goKeyword=Search&";
		url += fld.name + "=" + escape(fld.value);
		window.location.href = url;
	

	return false;
}
function searchTrainingProv(fld) {
	
	if( !fld.value || null != fld.value.match(/^\s+$/) ) {
		fld.value = "";
	}

	/*
	// searching with leading or tailing spaces might be useful.
	var m = fld.value.match(/^(\s*)([^\s].*[^\s])(\s*)$/);

	if( m != null )
		fld.value = m[2];
	*/

	if( fld.value && fld.value.length > 3 ) {
		
		var url = "http://" + window.location.host + "/catalog-training-search-by-prov.asp?goTrainingProv=Search&";
		url += fld.name + "=" + escape(fld.value);
		window.location.href = url;
	} else {
		alert("Please specify a non-blank provider name of at least 4 characters.")
	}

	return false;
}

function popDetails(id,w,h){
	var url = "training-details.asp?trainingID=" + id;
	window.open(url,"TrainingDetails","resizable=no,toolbar=no,scrollbars=yes,menubar=no,status=no,directories=no,width="+w+",height="+h);
	return false;
}

function popTContact(id,tid,w,h){
	var url = "contact-training-details.asp?contactID=" + id + "&trainingID=" + tid;
	window.open(url,"ContactDetails","resizable=no,toolbar=no,scrollbars=yes,menubar=no,status=no,directories=no,width="+w+",height="+h);
	return false;
}

function popContact(id){
	var url = "contact-details.asp?contactID=" + id;
	window.open(url,"ContactDetails","resizable=no,toolbar=no,scrollbars=yes,menubar=no,status=no,directories=no,width="+400+",height="+450);
	return false;
}

function popEmail(id,tid,w,h) {
	var url = "email-provider.asp?contactID=" + id;

	if( tid > 0 ) {
		url += "&trainingID=" + tid;
	}

	window.open(url,"EmailProvider","resizable=no,toolbar=no,scrollbars=yes,menubar=no,status=no,directories=no,width="+w+",height="+h);
	return false;
}

function popOtherProv(tid) {
	var topicID = parseInt(tid);

	if( !isNaN(topicID) ) {
		var url="additional-topic-providers.asp?topicID=" + topicID;
		window.open(url,"EmailProvider","resizable=tes,toolbar=no,scrollbars=yes,menubar=no,status=no,directories=no,width="+500+",height="+450);
	}

	return false;
}
