function getFirstMonday()
{ 
	var d = new Date(); 
	while(d.getDay() != 1)
	{ d.setTime(d.getTime() + 24*60*60*1000); } 
	return d; 
} 

/** 
 * Returns a date string of the form MM/DD/YY
 */ 
function myDateStr(d)
{ 
	var s = d.getDate(); 
	s += "\."; 
	s += d.getMonth()+1; 
	s += "\."; 
	s += d.getFullYear(); 
	return s; 
} 


function formSelect()
{ 	} 

function formSelectApply(fObj)
{ fObj.opts = new Object(); }

formSelect.prototype.formString = function(selectKey)
{ 
	var s = ""; 
	for(var k in this.opts)
	{ 
		//alert("selectKey: " + selectKey);
		//alert("K: " + k);
		if(k == selectKey)
		{ 
			s += "<option selected value='" + k + "'>" + this.opts[k] + "</option>"; 
		} 
		else
		{ 
			s += "<option value=\"" + k + "\">" + this.opts[k] + "</option>";
		} 
	} 
	return s; 
} 

function trainGoal()
{ 
	formSelectApply(this); 
	this.opts["fivk"] = "5 Km"; 
	this.opts["tenk1"] = "8 Km"; 
	this.opts["tenk3"] = "10 Km"; 
	this.opts["tenk4"] = "12 Km"; 
	this.opts["half1"] = "15 Km";
	this.opts["half3"] = "20 Km"; 
	this.opts["half4"] = "Halve-Marathon"; 
	this.opts["mara"] = "Marathon"; 	
} 

trainGoal.prototype = new formSelect(); 

function metrSelect()
{ 
	formSelectApply(this);
	this.opts["km"] = "Metric";
	this.opts["miles"] = "Miles";
} 

metrSelect.prototype = new formSelect(); 


function hourSelect()
{ 
	formSelectApply(this); 
	for(var i = 0; i < 10; i++)
	{ 
		this.opts[i] = i; 
	} 
} 

hourSelect.prototype = new formSelect(); 

function minsecSelect()
{ 
	formSelectApply(this); 
	for(var i = 0; i < 60; i++)
		{ this.opts[i] = i; } 
} 

minsecSelect.prototype = new formSelect(); 

function daySelect()
{ 
	formSelectApply(this); 
	this.opts["0"] = "Zondag";  
	this.opts["1"] = "Maandag"; 
	this.opts["2"] = "Dinsdag";  
	this.opts["3"] = "Woensdag";  
	this.opts["4"] = "Donderdag";  
	this.opts["5"] = "Vrijdag";  
	this.opts["6"] = "Zaterdag";  
} 

daySelect.prototype = new formSelect(); 

function diffSelect()
{ 
	formSelectApply(this);
	this.opts["main"] = "Licht"; 
	this.opts["mod"] = "Matig"; 
	this.opts["hard"] = "Hard"; 
	this.opts["vhard"] = "Heel Hard"; 
} 

diffSelect.prototype = new formSelect(); 

function mpweSelect()
{ 
	formSelectApply(this);
	
	for(var i = 1; i < 12; i++)
	{ 
		this.opts[i*5+1] = (i*5+1) + " - " + (i*5+5) + " Miles     "; 	
	} 
} 

mpweSelect.prototype = new formSelect(); 

function mpweSelectMetric()
{ 
	formSelectApply(this);
	
	for(var i = 1; i < 12; i++)
	{ 
			this.opts[i*5+1] = (i*8+1) + " - " + (i*8+8) + " km     "; 	
	} 
} 

mpweSelectMetric.prototype = new formSelect();

function paceSelect()
{ 
	formSelectApply(this); 
	this.opts["noop"] = "Loop Afstand"; 
	this.opts["onem"] = "1 Km"; 
	this.opts["fivk"] = "5 Km"; 
	this.opts["tenk"] = "10 Km"; 
	this.opts["half"] = "Halve-Marathon"; 
	this.opts["mara"] = "Marathon"; 	
} 

paceSelect.prototype = new formSelect(); 

function slenSelect()
{ 
	formSelectApply(this); 
	for(var i = 2; i < 17; i++)
		{ this.opts[i] = i + " Weken"; } 
} 

slenSelect.prototype = new formSelect(); 

function weekSelect()
{ 
	formSelectApply(this); 
	var d = getFirstMonday(); 
	var pd = new Date(d.getTime() - 7*24*60*60*1000); 
	this.opts["ds" + pd.getTime()] = "Afgelopen Maandag, " + myDateStr(pd);
	this.opts["ds" +  d.getTime()] = "Komende Maandag, " + myDateStr(d);
	var fd = new Date(d.getTime() + 7*24*60*60*1000)
	this.opts["ds" + fd.getTime()] = "Maandag over een week, " + myDateStr(fd); 	
	//var td = new Date();
	//this.opts["ds" + td.getTime()] = "Today, " + myDateStr(td); 	
} 

weekSelect.prototype = new formSelect(); 

