
 

 var yearSelected = 'false';
 var monthSelected = 'false';
 var locationSelected = 'false';



//pass true to reset all boxes - reset button,
//pass false to update boxes after page load - read querystring and populate post data
var forceReset = false;
 
 
  function archiveReset()
  {
	if (forceReset == true)
	{
		yearSelected = 'false';
		monthSelected = 'false';
		locationSelected = 'false';
		concertArchiveGetValueFromUrl('/wcm/site/pages/concertArchiveOptions.aspx');
	}
	else
	{
		yearSelected = 'false';
		monthSelected = 'false';
		locationSelected = 'false';
		
		var _location = GetQuerystringValue ("location");
		_location = _location.replace(",","");
		
		var _url = '/wcm/site/pages/concertArchiveOptions.aspx?location=' + _location + "&year=" + GetQuerystringValue ("year") + "&month=" + GetQuerystringValue ("month") 
		concertArchiveGetValueFromUrl(_url);
	}
  }
  
  
  
  
 //selected a year
 function concertArchiveYear()
 {
 
	if  (document.frmConcertArchive.year.options[document.frmConcertArchive.year.selectedIndex].value != '')
	{
		yearSelected = 'true';
		var year = document.frmConcertArchive.year.options[document.frmConcertArchive.year.selectedIndex].value;
		var month = document.frmConcertArchive.month.options[document.frmConcertArchive.month.selectedIndex].value;
		var location = document.frmConcertArchive.location.options[document.frmConcertArchive.location.selectedIndex].value;
		location = location.replace(",","");
		var querystring = "";
		//if (monthSelected == 'true')
			querystring += "&month=" + escape(month);
		//if (locationSelected == 'true')
			querystring += "&location=" + escape(location);
			
		var _url = '/wcm/site/pages/concertArchiveOptions.aspx?year=' + escape(year) + querystring;
		//alert (querystring);
		concertArchiveGetValueFromUrl(_url);
	}
	
 }
 
 
 
  //selected a month
 function concertArchiveMonth()
 {
	 if  (document.frmConcertArchive.month.options[document.frmConcertArchive.month.selectedIndex].value != '')
	{
		monthSelected = 'true';
		var year = document.frmConcertArchive.year.options[document.frmConcertArchive.year.selectedIndex].value;
		var month = document.frmConcertArchive.month.options[document.frmConcertArchive.month.selectedIndex].value;
		var location = document.frmConcertArchive.location.options[document.frmConcertArchive.location.selectedIndex].value;
		location = location.replace(",","");
		var querystring = "";
		//if (yearSelected == 'true')
			querystring += "&year=" + escape(year);
		//if (locationSelected == 'true')
			querystring += "&location=" + escape(location);
			
		var _url = '/wcm/site/pages/concertArchiveOptions.aspx?month=' + escape(month) + querystring;
		//alert (_url);
		concertArchiveGetValueFromUrl(_url);
	}
 }
 
 
function concertArchiveLocation()
 {
	if  (document.frmConcertArchive.location.options[document.frmConcertArchive.location.selectedIndex].value != '')
	{
		locationSelected = 'true';
		var year = document.frmConcertArchive.year.options[document.frmConcertArchive.year.selectedIndex].value;
		var month = document.frmConcertArchive.month.options[document.frmConcertArchive.month.selectedIndex].value;
		var location = document.frmConcertArchive.location.options[document.frmConcertArchive.location.selectedIndex].text;
		location = location.replace(",","");
		
		var querystring = "";
		//if (yearSelected == 'true')
			querystring += "&year=" + escape(year);
		//if (monthSelected == 'true')
			querystring += "&month=" + escape(month);
			
		var _url = '/wcm/site/pages/concertArchiveOptions.aspx?location=' + escape(location) + querystring;
		//alert (_url);
		concertArchiveGetValueFromUrl(_url);
		
	}
 }
 
 

 
 
 
 
	
 
 
function concertArchiveHandleResponse(responseText) 
{
	
	var month_names = new Array(12)
	month_names[0] = "January"
	month_names[1] = "February"
	month_names[2] = "March"
	month_names[3] = "April"
	month_names[4] = "May"
	month_names[5] = "June"
	month_names[6] = "July"
	month_names[7] = "August"
	month_names[8] = "September"
	month_names[9] = "October"
	month_names[10] = "November"
	month_names[11] = "December"
	
	//get arrrays 
	var oType = responseText.split ('\r\n');
	var yearList = oType[0].split('|');
	var monthList = oType[1].split('|');
	var locationList = oType[2].split('|');
	
	
	
	//get the selected text
	var nSelectedIndex = document.frmConcertArchive.location.selectedIndex;
	var _selectedText  = "";
	if (nSelectedIndex > 0)
		_selectedText = document.frmConcertArchive.location.options[document.frmConcertArchive.location.selectedIndex].text;
	
		
		
		
	
	//clear all dropdowns
	document.frmConcertArchive.year.options.length=0;
	document.frmConcertArchive.month.options.length=0;
	document.frmConcertArchive.location.options.length=0;
	
	
	//add a counter instead of using nCount
	//DONT USE NCOUNT TO ADD NEW OPTIONS
	var nComboCount = 0;
	var previousYear = "";
	if (yearSelected == 'false')
	{
		document.frmConcertArchive.year.options[nComboCount] = new Option("Please Select","");
		nComboCount =1;
	}
	
	//year dropdown
	for (var nCount=0;nCount<yearList.length-1;nCount++)
	{
		if (previousYear != yearList[nCount])
			if (AlreadyExists(document.frmConcertArchive.year, yearList[nCount]) == 'false' && yearList[nCount] != '')
				if (yearList[nCount] != '')
					if (forceReset == true || (GetQuerystringValue("year") == "" || (GetQuerystringValue("year") != "" && GetQuerystringValue("year") == yearList[nCount])))
					{
						document.frmConcertArchive.year.options[nComboCount] = new Option(yearList[nCount].replace('&amp;', '&'),yearList[nCount]);
						nComboCount=nComboCount+1;
					}
					
		previousYear= yearList[nCount];
	}
	
	
	
	
	//month
	var nComboCount = 0;
	var previousMonth = "";
	if (monthSelected == 'false')
	{
		document.frmConcertArchive.month.options[nComboCount] = new Option("Please Select","");
		nComboCount =1;
	}
	for (var nCount=0;nCount<monthList.length-1;nCount++)
	{
		if (previousMonth != monthList[nCount])
			if (AlreadyExists(document.frmConcertArchive.month, monthList[nCount]) == 'false' && monthList[nCount] != '')
				if (monthList[nCount] != '')
					if (forceReset == true || (GetQuerystringValue("month") == "" || (GetQuerystringValue("month") != "" && GetQuerystringValue("month") == monthList[nCount])))
					{
						document.frmConcertArchive.month.options[nComboCount] = new Option(month_names [monthList[nCount]-1],monthList[nCount]);
						nComboCount=nComboCount+1;
					}
					
		previousMonth= monthList[nCount];
	}
	
	
	//location
	var nComboCount = 0;
	var previousLocation = "";
	if (locationSelected == 'false')
	{
		document.frmConcertArchive.location.options[nComboCount] = new Option("Please Select","");
		nComboCount =1;
	}
	
	for (var nCount=0;nCount<locationList.length-1;nCount++)
	{
		
		if (previousLocation != locationList[nCount])
			if (AlreadyExists(document.frmConcertArchive.location, locationList[nCount]) == 'false' && locationList[nCount] != '')
				if (locationList[nCount] != '')
				{
					//get location name from array
					var _locationName = locationList[nCount];
					
					//strip comma_space if at front
					if (_locationName.substring(0, 2) == ', ')
						_locationName = _locationName.substring(2);
						
					if (_locationName != "")
					{
					//build hidden value - strip commas
						var locationValue = _locationName.replace(",","");
						
						if (forceReset == true || (GetQuerystringValue("location") == "" || (GetQuerystringValue("location") != "" && GetQuerystringValue("location") == locationValue)))
						{
							document.frmConcertArchive.location.options[nComboCount] = new Option(locationValue, _locationName); //locationList[nCount] is the hidden value
							nComboCount=nComboCount+1;
						}
					}
				}
				
		previousLocation= locationList[nCount];
	}
	
	
		
		
		
	//sort options
	var obj = document.frmConcertArchive.location;
    var values = new Array();
    for(var no=0;no<obj.options.length;no++)
        values.push(obj.options[no].value.replace(",", "#") + "," + obj.options[no].text.replace(",","#"));
    values = values.sort();
    obj.options.length=0;
    obj.options[obj.options.length] = new Option("Please Select", "");
    for(var no=0;no<values.length;no++)
    {
        valueArray = values[no].split(',');
        if (valueArray[0].replace("#" , ",") != "")
        	obj.options[obj.options.length] = new Option(valueArray[0].replace("#", ","), valueArray[1].replace("#",","));
	}




	if (locationSelected == 'true')
	{
		//re-select the option that was selected before the refresh
		for (var nCounter=0; nCounter<document.getElementById('location').options.length-1;nCounter++)
    		if 	(document.getElementById('location').options[nCounter+1].text == _selectedText)
				document.getElementById('location').selectedIndex=nCounter+1;
	}	
	
	
	
	//if not a complete reset, show the options that were posted when the screen was refreshed
	
	if (forceReset == false)
	{
	
		if (locationSelected == 'false')
		{
			selectedLocation = GetQuerystringValue ('location');
			for (var nCounter=0; nCounter<document.getElementById('location').options.length-1;nCounter++)
				if 	(document.getElementById('location').options[nCounter+1].value == selectedLocation)
					document.getElementById('location').selectedIndex=nCounter+1;
		}
		if (yearSelected == 'false')
		{
			selectedYear = GetQuerystringValue ('year');
			for (var nCounter=0; nCounter<document.getElementById('year').options.length-1;nCounter++)
				if (document.getElementById('year').options[nCounter+1].value == selectedYear)
					document.getElementById('year').selectedIndex = nCounter+1;
		}
		if (monthSelected == 'false')
		{
			selectedMonth = GetQuerystringValue ('month');
			for (var nCounter=0; nCounter<document.getElementById('month').options.length-1;nCounter++)
				if (document.getElementById('month').options[nCounter+1].value == selectedMonth)
					document.getElementById('month').selectedIndex = nCounter+1;
		}
		
	}
	forceReset == false;
	
}


 
                
        
        
function GetQuerystringValue (sIn)
{
	var returnValue = "";
	
	var qsArray = new Array();
	for(var i=0; i < location.search.substring (1).split("&").length; i++) 
	{
		qsArray[i] = location.search.substring (1).split("&")[i];
		if (qsArray[i].split("=")[0] == sIn) 
			returnValue = unescape(qsArray[i].split("=")[1]);
			while (returnValue.indexOf("+") >0)
				returnValue = returnValue.replace('+', ' ');
	}
	return returnValue;
}


function AlreadyExists(oControl, value)
	{
		var ncounter = 0;
		for (ncounter=0; ncounter<oControl.options.length-1;ncounter++)
		{
				if (oControl.options[ncounter].value == value)
					return 'true';
		}
		return 'false';			
	}
	

function concertArchiveGetValueFromUrl(Url) 
	{   
	
            var Request = getXMLHTTPRequest();
            
            Request.open('GET', Url, true);
            Request.onreadystatechange=function() {
                        if (Request.readyState==4) {
									
                                    concertArchiveHandleResponse(Request.responseText)
                        }
            }
            Request.send(null)
}
 






// INSTANCIATE AN OBJECT
function getXMLHTTPRequest()
{
            var xmlhttp=false;
            // JScript gives us Conditional compilation, we can cope with old IE versions.
            // and security blocked creation of the objects.
            try{
                        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            }catch(e){
                        try {
                                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                        }catch(e){
                                    xmlhttp = false;
                        }
            }
            if(!xmlhttp && typeof XMLHttpRequest!='undefined') {
                        xmlhttp = new XMLHttpRequest();
            }
            return(xmlhttp);
}

 

 

 

 
