function openWin(){
aWindow=window.open("wildcards.html","thewindow","toolbar=no,width=350,height=400,status=no,scrollbars=yes,resize=yes,menubar=no");
}

//
// This function will determine which kind of query is wanted and submit the
// form to one perl script which will call the appropriate perl script
//
// Possibilities are:
//	3b Network - list summary for a network
//  3d Station - list summary for a station regardless of network
//  3c Network & Station - list summary for a given network and station
//  3a Comprehensive - summary for one or all of the query paramenters for
//		network, station, and channel
//
//function summary_Submit( theForm )
function validateAndSubmit( theForm )
{
	select = new String( "select " );
	from   = new String( "from all_channel_summary a, networks n " );
	where  = new String();
	orderby = new String( " order by nickname," );
	groupby = new String( " group by nickname," );

	//////////////////////////////////////////////////////////////////
	//  FORM THE SELECT CLAUSE
	//////////////////////////////////////////////////////////////////

	select = "select ";
	if( theForm.cnet.checked )
	{
		select  += "a.network,";
		groupby = " group by a.network, nickname,";
		orderby = " order by a.network,nickname,";
	}
	if( theForm.csta.checked )
	{
		select  += "a.station,";
		groupby += "a.station,";
		orderby += "a.station,";
	}
	if( theForm.cloc.checked )
	{
		select  += "a.location,";
		groupby += "a.location,";
		orderby += "a.location,";
	}
	if( theForm.ccha.checked )
	{
		select  += "a.channel,";
		groupby += "a.channel,";
		orderby += "a.channel,";
	}

	if( select == "select " )
	{
		alert("You have not checked any select fields.");
		return false;
	}
	select += "min(earliest) \"EARLIEST\", max(latest) \"LATEST\", restricted,";
	select += "nickname \"NET_ABBR\",name ";

	// get rid of trailing ,
	//groupby = groupby.substring(0,(groupby.length - 1));
	orderby += "EARLIEST";
	groupby += "name,restricted";

	//////////////////////////////////////////////////////////////////
	//  FORM THE WHERE CLAUSE
	//////////////////////////////////////////////////////////////////
	where = "where a.network = n.network and ";
	where += "to_char(a.earliest,'YYYY') between n.startyr and n.endyr ";

	//////////////////////////////////////////////////////////////////
	//  Get the network part, multiple values separated by comma
	//////////////////////////////////////////////////////////////////
	var conjunct = " and ";
	if( theForm.net.value != "" )
	{
		var networks = theForm.net.value.split(",");
		if( networks.length == 1 )
		{
			where += conjunct + "a.network like '" +
									theForm.net.value+ "'";
		}
		else
		{
			var net_clause = "a.network in (";
			for( var i=0; i< networks.length; i++ )
			{
				if( i == 0 ) net_clause += "'"+networks[i]+"'";
				else net_clause += ",'"+networks[i]+"'";
			}
			net_clause += ") ";
			where += conjunct + net_clause
		}
		conjunct = " and ";
	}
	if( theForm.sta.value != "" )
	{
		var stations = theForm.sta.value.split(",");
		if( stations.length == 1 )
		{
			where += conjunct + "a.station like '" +
									theForm.sta.value+ "'";
		}
		else
		{
			var sta_clause = "a.station in (";
			for( var i=0; i< stations.length; i++ )
			{
				if( i == 0 ) sta_clause += "'"+stations[i]+"'";
				else sta_clause += ",'"+stations[i]+"'";
			}
			sta_clause += ") ";
			where += conjunct + sta_clause
		}
		conjunct = " and ";
	}
	if( theForm.loc.value != "" )
	{
		var locations = theForm.loc.value.split(",");
		if( locations.length == 1 )
		{
			where += conjunct + "a.location like '" +
									theForm.loc.value+ "'";
		}
		else
		{
			var loc_clause = "a.location in (";
			for( var i=0; i< locations.length; i++ )
			{
				if( i == 0 ) loc_clause += "'"+locations[i]+"'";
				else loc_clause += ",'"+locations[i]+"'";
			}
			loc_clause += ") ";
			where += conjunct + loc_clause
		}
		conjunct = " and ";
	}
	if( theForm.cha.value != "" )
	{
		var channels = theForm.cha.value.split(",");
		if( channels.length == 1 )
		{
			where += conjunct + "a.channel like '" +
									theForm.cha.value+ "'";
		}
		else
		{
			var cha_clause = "a.channel in (";
			for( var i=0; i< channels.length; i++ )
			{
				if( i == 0 ) cha_clause += "'"+channels[i]+"'";
				else cha_clause += ",'"+channels[i]+"'";
			}
			cha_clause += ") ";
			where += conjunct + cha_clause
		}
		conjunct = " and ";
	}

	if( ( where == "" ) 
	 && ( theForm.net.value == "" ) 
	 && ( theForm.sta.value == "" ) 
	 && ( theForm.loc.value == "" ) 
	 && ( theForm.cha.value == "" ) 
	)
	{
		alert("You have not supplied enough search criteria. You must set at least one parameter in the network, station OR channel box" );
		return false;
	}

	theForm.sqlcmd.value = select + from + where + groupby + orderby;
	//alert( theForm.sqlcmd.value );
	// return false;
	
	theForm.submit();
	return true;
}
