﻿function GenSecurityDropDownList()
			{
				var thruDate = new Date();
				var year = thruDate.getFullYear() - 2009;
				var month = thruDate.getMonth();
				var vol = year * 26 + month * 3;
				var maxVol = 0;
				
				var volString = "";
				do
				{
					volString = vol.toString();
					
					while(volString.length < 4)
					{
						volString = "0" + volString;
					}
					
					var testUrl = "gss_security_" + volString + ".htm";
						
					if(UrlTester(testUrl))
					{
						if(maxVol == 0)
							maxVol = vol;
						
						var optionName = "GSS資安電子報 第" + volString + "期"
						$("#menu").append($("<option name='" + vol.toString() + "'></option>").val(testUrl).html(optionName));
					}
					
					vol--;
					
				} while(vol > 0);
				
				var path = location.pathname;
				var start = path.search(/\d{4}/);
				var selectedVol = parseInt(path.substr(start, 4), 10);
				var total = document.getElementById('menu').options.length;
				
  			document.getElementById('menu').selectedIndex = total - selectedVol;
			}

			function UrlTester(testUrl)
			{
				var connection = null;
				try
				{
					connection = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e)
				{
					try
					{
						connection = new ActiveXObject("Msxml2.XMLHTTP");
					}
					catch(e)
					{
						try
						{
							connection = new window.XMLHttpRequest();
						}
						catch(e)
						{
					
						}
					}
				}
				
				if(connection != null)
				{
					connection.open("GET", testUrl, false);
					connection.send(null);
					return connection.status != 404;
				}
			}
			
			function menuOnChanged(obj)
			{
  			eval("parent.location='" + obj.options[obj.selectedIndex].value + "'");
			}