function viewEvents(){  
        window.location = URL_BASE + "calendar/" +  getCategorySelected() + "/" + getCountySelected() + "/" + getDateRange() + "&filter1=" + getKeyWords();
}

function getDateRange(){
        var range = document.getElementById("eventDateStart").value.substring(6,10) + "-" + document.getElementById("eventDateStart").value.substring(0,2) + "-" + document.getElementById("eventDateStart").value.substring(3,5)+ "/" + document.getElementById("eventDateEnd").value.substring(6,10) + "-" +  document.getElementById("eventDateEnd").value.substring(0,2) + "-" +  document.getElementById("eventDateEnd").value.substring(3,5);
        return "?filter0="+ range;
}

function getKeyWords(){
var myTest = document.getElementById("keywords").value;
	//alert(myTest);
	if (myTest === undefined) {myTest = "";}
	return myTest;
	//alert(myTest);
   //return document.getElementById("keywords").value;

}

function getCategorySelected(){
    var categoryControl = document.getElementById("category");
    return categoryControl.options[categoryControl.selectedIndex].value;
}


function getCountySelected(){
        //var countyControl = document.getElementById("county");
   // if (countyControl != null) {
          //  return countyControl.options[countyControl.selectedIndex].value;
   // } else {
    //    return "all";
    //}
	return document.eventsearch.counties.value;
}

function getEditionSelected(){
        //var editionControl = document.getElementById("edition");
       // return editionControl.options[editionControl.selectedIndex].value;
	   return document.eventsearch.editions.value;
} 





function fillCategoryCombo(selected) {
	var categoryControl=document.getElementById("category");
        var category = new Array();
		 category[0] = new Array("--Categories--","all");
        category[1] = new Array("Community","90");
        category[2] = new Array("Arts & Ent.","83");
        category[3] = new Array("Politics","106");
        category[4] = new Array("Business","86");
        category[5] = new Array("Health","99");
        category[6] = new Array("Volunteer","116");
        category[7] = new Array("Religion","107");
        category[8] = new Array("Family Friendly","200");
	category[9] = new Array("Education","181");
        category[10] = new Array("All categories","all");

        for(i=0;i<category.length;i+=1) {
                categoryControl.options[i] = new Option(category[i][0],category[i][1], selected==i);
        }
}

function fillCountyCombo() {
	var countyControl=document.getElementById("county");
        var county = new Array();
		
		county[0] = new Array("--Communities--","all");
        county[1] = new Array("All counties","all");
        county[2] = new Array("Carroll","80");
		county[3] = new Array("--Eldersburg","1400");
	    county[4] = new Array("--Mount Airy","1401");
	    county[5] = new Array("--Sykesville","1402");
	
        county[6] = new Array("Frederick","73");
		county[7] = new Array("--Brunswick","1393");
	    county[8] = new Array("--Frederick","1394");
	    county[9] = new Array("--Middletown","1395");
	    county[10] = new Array("--New Market","1396");
	    county[11] = new Array("--Thurmont","1397");
	    county[12] = new Array("--Urbana","1398");
	    county[13] = new Array("--Walkersville","1399");

        county[14] = new Array("Montgomery","41");
        county[15] = new Array("--Aspen Hill","1362");
        county[16] = new Array("--Bethesda","1363");
        county[17] = new Array("--Burtonsville","1364");
        county[18] = new Array("--Chevy Chase","1365");
        county[19] = new Array("--Damascus","1366");
        county[20] = new Array("--Gaithersburg","1367");
	    county[21] = new Array("--Germantown", "1368");
        county[22] = new Array("--Kensington","1369");
        county[23] = new Array("--Montgomery Village", "1370");
	    county[24] = new Array("--North Potomac", "1372");
	    county[25] = new Array("--Olney", "1373");
	    county[26] = new Array("--Poolesville","1374");
        county[27] = new Array("--Potomac","1375");
	    county[28] = new Array("--Rockville","1376");
        county[29] = new Array("--Silver Spring","1377");
        county[30] = new Array("--Takoma Park","1378");
        county[31] = new Array("--Wheaton","1379");
		
        county[32] = new Array("Prince George's","59");
		county[33] = new Array("--Bowie","1380");
	    county[34] = new Array("--Clinton","1381");
	    county[35] = new Array("--College Park","1382");
	    county[36] = new Array("--Ft Washington","1383");
	    county[37] = new Array("--Greenbelt","1384");
        county[38] = new Array("--Hyattsville","1385");
	    county[39] = new Array("--Landover","1386");
        county[40] = new Array("--Lanham","1387");
	    county[41] = new Array("--Largo","1388");
        county[42] = new Array("--Laurel","1389");
	    county[43] = new Array("--New Carrollton","1390");
	    county[44] = new Array("--Port Towns", "1391");
	    county[45] = new Array("--Upper Marlboro","1392");


        for(i=0;i<county.length;i+=1) {
                countyControl.options[i] = new Option(county[i][0],county[i][1]);
        }
		 
}





function fillCombos(){
	var thisday = new Date;
	var tempmonth = thisday.getMonth()+1;
	var tempdate = thisday.getDate();
	if (tempmonth < 10) {tempmonth = "0" + tempmonth;}
	if (tempdate < 10) {tempdate = "0" + tempdate;}
	var defaultstart = tempmonth + "-" + tempdate + "-" + thisday.getFullYear();
	document.eventsearch.eventDateStart.value = defaultstart;
	document.eventsearch.eventDateEnd.value = "";
	document.eventsearch.showDateStart.value = defaultstart;
	document.eventsearch.showDateEnd.value = "";
	document.eventsearch.counties.value = "all";
	document.eventsearch.editions.value = "all";
	fillCategoryCombo(0);
	fillCountyCombo();
	}



function fillBusinessCombos(){
        //fillCategoryCombo(0);
        //fillCountyCombo();
		fillCombos();
      }

function fillPoliticsCombos(){
        //fillCategoryCombo(0);
       // fillCountyCombo();
	   fillCombos();
        }

function fillSportsCombos(){
        //fillCategoryCombo(0);
        //fillCountyCombo();
		fillCombos();
     }

function fillEntertainmentCombos(){
        //fillCategoryCombo(0);
        //fillCountyCombo();
		fillCombos();
        }

function getCode() {
	var countyControl = document.getElementById("county");
	var mycounty=countyControl.options[countyControl.selectedIndex].value;
	
	//if (mycounty.length == 4)
	//{
		//document.eventsearch.counties.value = "all";
		//document.eventsearch.editions.value = mycounty;
	//}
 //if (mycounty.length == 2)
	//{
		//document.eventsearch.editions.value = "all";
		//document.eventsearch.counties.value = mycounty;
		
	//}
	// if (mycounty.value == "all")
	//{
	//	document.eventsearch.editions.value = "all";
		//document.eventsearch.counties.value = "all";
		
	//}
	document.eventsearch.counties.value = mycounty;

}

function checkDates() {
	document.eventsearch.eventDateStart.value = document.eventsearch.showDateStart.value;
	document.eventsearch.eventDateEnd.value = document.eventsearch.showDateEnd.value;
	var msg = "Invalid choice. Your start date cannot \nbe a later date than your end date.";
	var today = new Date;
	var myStartDate = new Date;
	var myEndDate = new Date;
	if (document.getElementById("eventDateStart").value != "") {
		var tempStartMonth = document.getElementById("eventDateStart").value.substring(0,2)-1;
		var tempStartDate = document.getElementById("eventDateStart").value.substring(3,5);
		var tempStartYear = document.getElementById("eventDateStart").value.substring(6,10);
	myStartDate.setFullYear(tempStartYear,tempStartMonth,tempStartDate);
	//myStartDate.setMonth(document.getElementById("eventDateStart").value.substring(0,2)-1);
	//myStartDate.setDate(document.getElementById("eventDateStart").value.substring(3,5));
		}
		var mymonth=myStartDate.getMonth()+1;
		if (mymonth<10) {mymonth="0"+mymonth;}
		var myday=myStartDate.getDate();
			if (myday<10) {myday="0"+myday;}
		document.eventsearch.eventDateStart.value = mymonth + "-" + myday + "-" + myStartDate.getFullYear();
		if (document.getElementById("eventDateEnd").value == "") {
			myEndDate.setFullYear(today.getFullYear());
			myEndDate.setMonth(today.getMonth());
			myEndDate.setDate(today.getDate()+30);}
			else {
				var tempEndMonth = document.getElementById("eventDateEnd").value.substring(0,2)-1;
				var tempEndDate = document.getElementById("eventDateEnd").value.substring(3,5);
				var tempEndYear = document.getElementById("eventDateEnd").value.substring(6,10);
				//alert(tempMonth);
	myEndDate.setFullYear(tempEndYear,tempEndMonth,tempEndDate);
	//myEndDate.setMonth(tempMonth);
	//myEndDate.setMonth(tempMonth);
	//myEndDate.setDate(document.getElementById("eventDateEnd").value.substring(3,5));
			}
			//alert(myEndDate);
			mymonth=myEndDate.getMonth()+1;
			if (mymonth<10) {mymonth="0"+mymonth;}
			myday=myEndDate.getDate();
			if (myday<10) {myday="0"+myday;}
			document.eventsearch.eventDateEnd.value = mymonth + "-" + myday + "-" + myEndDate.getFullYear();;
			if (myStartDate > myEndDate) {
				alert (msg);
				return false;
			}
			else {
				viewEvents();
			}
}
