window.onload = LoadInitialState;

function LoadInitialState()
{
	if (course_id != '0')
	{
		PopulateTarget(course_id, sCourseDate ,aIterations);
		SelectDate(iteration_id);
	}
}
function SetSelectedItem(itemID, value)
{
	//alert(itemID +" and "+ value);
	var oSelect = GetMyObjectByID(itemID);
		
	for (var loop=0; loop<oSelect.options.length; loop++) {
		if(oSelect.options[loop].value == value)
			oSelect.selectedIndex = loop;	
	}
}
function GetDDSelectedValue(itemID)
{
	//alert("Getting value for ="+ itemID)
	
	var oProp  = GetMyObjectByID(itemID);
	
	var propCode = oProp.options[oProp.selectedIndex].value;
		
	//alert(itemID +" = "+ propCode);
	
	return propCode;
}

function SelectDate(itID)
{
	var s = GetMyObjectByID(sCourseDate);
	for (x=0; x < s.options.length; x++)
	{
		if (s.options[x].value == itID)
		{
			s.options[x].selected = true;
			var t = GetMyObjectByID(txtCourseDate);
			t.value = s.options[x].text;
		}
	}
}


function OpenNew(field)
{
	// get the Current selected Date...
	var sdate;
	if(field == "in")
	{
	
		var o = getAnchorPosition("inLink");
		alert(1);
		var options = "width=245,height=157,left=270,top=180,top="+ o.y +",left="+ o.x;
		alert(2);
		sdate = GetDDSelectedValue("ddInDay") +"/"+ months[GetDDSelectedValue("ddInMonth")-1] +"/"+ GetDDSelectedValue("ddInYear");
		alert(3);
		var url = "Calendar.aspx?textbox="+ field +"&date="+ sdate;
		alert(4);
		win = window.open(url,'cal',options);
		win.focus();
		alert(5);
	}

}
function SetField(field,day,month,year)
{
	if(field == "in")
	{
		SetSelectedItem("ddInDay",day);
		SetSelectedItem("ddInMonth",month);
		SetSelectedItem("ddInYear",year);		
	}

	if(win !=null)
	{
		win.close();
		win = null;
		this.focus();
	}
}
function setDateField(e)
{
	//var s = e.options[e.selectedIndex].value;
	var t = e.options[e.selectedIndex].text;
	if(t.length > 0)
	{
		//document.forms[0].txtCourseDate.value = t;
		GetMyObjectByID(txtCourseDate).value = t;
	}

}
			