/******************************************************************************
function write_cookie (name, value);
function write_cookie (name, value, path);

write_cookie creates a cookie with the name, value, and path given in the
parameters.  If no path is supplied, write_cookie uses the document's default
cookie path.  Each cookie is set with an expiration time of 1 year.
******************************************************************************/

function write_cookie(name, value, path, cookietype)
{
	// Build the expiration date string:

		var expiration_date = new Date();
		if(cookietype == "delete")
		{
			expiration_date.setYear (expiration_date.getYear() - 1);
			expiration_date = expiration_date.toGMTString();		
			expires_str = "; expires=" + expiration_date;		
		}
		else 
		{
			if(cookietype == "1year")
			{
				expiration_date.setYear (expiration_date.getYear() + 1);
				expiration_date = expiration_date.toGMTString();		
				expires_str = "; expires=" + expiration_date;		
			}
			else
				expires_str = "";
		}
	
	// Build the set-cookie string:
	var cookie_string = escape(name) + "=" + escape(value) + expires_str ;	
	if (path != null)
		cookie_string += "; path=" + path;

	// Create/update the cookie:	
	document.cookie = cookie_string;
	return;
}

/******************************************************************************
function read_cookie (key)
function read_cookie (key, skips)

read_cookie searches through the current document's cookie string (i.e., the
concatenation of all cookies readable by the current document) for a cookie
whose name is identical to key.  If read_cookie finds a matching cookie, it
returns a string containing the value of cookie.  If read_cookie cannot find a
match, it returns null instead.

An optional skips parameter may be supplied if there is a need to select among
multiple cookies with the same name.  If a skips parameter is supplied,
read_cookie will skip that many occurrences of matching cookies and then return
the next one it finds, or null if there aren't any more.
******************************************************************************/

function read_cookie (key, skips)
{
	// Set skips to 0 if parameter was omitted:
	if (skips == null)
	        skips = 0;
	
	// Get cookie string and separate into individual cookie phrases:
	var cookie_string = "" + document.cookie;
	var cookie_array = cookie_string.split("; ");
	
	// Scan for desired cookie:
	for (var i = 0; i < cookie_array.length; ++ i)
	{
	        var single_cookie = cookie_array [i].split("=");
	        if (single_cookie.length != 2)
	                continue;
	        var name  = unescape(single_cookie [0]);
	        var value = unescape(single_cookie [1]);
	
	        // Return cookie if found:
	        if (key == name && skips -- == 0)
	                return value;
	}
	
	// Cookie was not found:
	return null;
}
/////////////////////////////////////////////////////////////////////////////////
//依照年月show正確日期
function showday(str,selectday)
{	
	var year = str.Birthyear.value;
	var month = str.Birthmonth.value;
	if(year != 0 && month != 0)
	{		
		for(i = 28;i <= 31;i ++)
		{		
			day1 = new Date(year,month-1,i);
			day2 = day1.getDate();		
			if (day2 != i)		
				break;			
			else
				daynum = i+1;
		}				
		str.Birthday.length = daynum;		
		for(i = 1 ;i <= daynum; i++)
		{					
			if(i == 1)
			{								
				str.Birthday.options[i-1].value = i-1;
				str.Birthday.options[i-1].text = '請選擇';	
			}
			else
			{
				str.Birthday.options[i-1].value = i-1;
				str.Birthday.options[i-1].text = i-1;
				if(selectday != '' && selectday == i-1)
					str.Birthday.options[i-1].selected = true;
			}
		}
	}
	else
	{
		str.Birthday.length = 32;
		for(i = 1 ;i <= 32; i++)
		{					
			if(i == 1)
			{								
				str.Birthday.options[i-1].value = i-1;
				str.Birthday.options[i-1].text = '請選擇';	
			}
			else
			{
				str.Birthday.options[i-1].value = i-1;
				str.Birthday.options[i-1].text = i-1;
			}
		}
	}		
} 

function showtheday(yearstr,monthstr,daystr,selectday)
{	
	var yearobj = document.getElementById(yearstr);
	var monthobj = document.getElementById(monthstr);
	var dayobj = document.getElementById(daystr);
	var year = yearobj.value;
	var month = monthobj.value;
	if(year != 0 && month != 0)
	{		
		for(i = 28;i <= 31;i ++)
		{		
			day1 = new Date(year,month-1,i);
			day2 = day1.getDate();		
			if (day2 != i)		
				break;			
			else
				daynum = i+1;
		}				
		dayobj.length = daynum;		
		for(i = 1 ;i <= daynum; i++)
		{					
			if(i == 1)
			{								
				dayobj.options[i-1].value = i-1;
				dayobj.options[i-1].text = '請選擇';	
			}
			else
			{
				dayobj.options[i-1].value = i-1;
				dayobj.options[i-1].text = i-1;
				if(selectday != '' && selectday == i-1)
					dayobj.options[i-1].selected = true;
			}
		}
	}
	else
	{
		dayobj.length = 32;
		for(i = 1 ;i <= 32; i++)
		{					
			if(i == 1)
			{								
				dayobj.options[i-1].value = i-1;
				dayobj.options[i-1].text = '請選擇';	
			}
			else
			{
				dayobj.options[i-1].value = i-1;
				dayobj.options[i-1].text = i-1;
			}
		}
	}		
} 

function showtheday_new(yearobj,monthobj,dayobj,selectday)
{		
	var year = yearobj.value;	
	var month = monthobj.value;	
	if(year != 0 && month != 0)
	{		
		for(i = 28;i <= 31;i ++)
		{		
			day1 = new Date(year,month-1,i);
			day2 = day1.getDate();		
			if (day2 != i)		
				break;			
			else
				daynum = i+1;
		}							
		for(i = 1 ;i < daynum; i++)
		{								
			if(i == 1)
				dayobj.options[i-1] = new Option( '請選擇' , '0' );
			dayobj.options[i] = new Option( i , i );;			
			if(selectday != '' && selectday == i)
				dayobj.options[i].selected = true;			
		}
		dayobj.length = daynum;			
	}
	else
	{		
		for(i = 1 ;i <= 32; i++)
		{					
			if(i == 1)
				dayobj.options[i-1] = new Option( '請選擇' , '0' );			
			dayobj.options[i] = new Option( i , i );;			
		}
		dayobj.length = 31;
	}		
}
