// JavaScript Document
function writeSBDateFields(qid, type, options)
{
	// if no options have been passed, the type must be DOB
	if (arguments.length < 2 || arguments.length < 2) type = "dob";
	
	// days
	document.write('<select id="'+ qid +'_day" name="day_'+ qid +'" style="font-family:sans-serif; font-size:10px; color:#666; width: 50px;">\n');
	document.write('<option value="null">dd</option>');
	for (i=1; i<32; i++) document.write('<option value="'+i+'">'+i+'</option>');
	document.write('</select>\n');	
	
	// months
	document.write('<select id="'+ qid +'_month" name="month_'+ qid +'" style="font-family:sans-serif; font-size:10px; color:#666; width: 50px;">\n');
	document.write('<option value="null">mm</option>');
	for (i=1; i<13; i++) document.write('<option value="'+i+'">'+i+'</option>');
	document.write('</select>\n');	
	
	sYearDirection = 'asc';
	
	// years
	switch (type)
	{
		case "dob":
			dateStart = 1900;
			oDate = new Date();
			dateFinish = oDate.getFullYear() - 15;
			break;
		case "future":
			var dobj = new Date();
			dateStart = dobj.getFullYear();
			dateFinish = dobj.getFullYear() + 5;
			break;
		case "pet":
			var dobj = new Date();
			dateStart = dobj.getFullYear() - 25;
			dateFinish = dobj.getFullYear();
			sYearDirection = 'desc';
			break;
		case "range":
			// check options have been passed
			if (arguments.length < 3) return false;
			ar = options.split("-");
			dateStart = ar[0];
			dateFinish = parseInt(ar[1]) + 1;
			break;
	}
	// write HTML
	document.write('<select id="'+ qid +'_year" name="year_'+ qid +'" style="font-family:sans-serif; font-size:10px; color:#666; width: 60px;">\n');
	document.write('<option value="null">yyyy</option>');
	if(sYearDirection == 'asc')
	{
		for (i=dateStart; i<=dateFinish; i++) document.write('<option value="'+i+'">'+i+'</option>');
	}
	else
	{
		for (i=dateFinish; i>=dateStart; i--) document.write('<option value="'+i+'">'+i+'</option>');
	}
	document.write('</select>\n');
}