function initsubmit()

{

	var classno = $('classNo');

	$('submit').onclick = function (e)

	{

		if (!e) var e = window.event;

		initEvents();

		recalc();

	}		

	if ($('submit').captureEvents) $('submit').captureEvents(Event.ONCLICK);

	

	$('residence').onchange = function (e)

	{

		if (!e) var e = window.event;

		if($('residence').selectedIndex == 3 && $('level').selectedIndex == 1)

		{

			classno.value = '3';

			classno.style.border = '1px solid #666666';

			classno.onselect = function () { return false; }

			classno.onmousedown = function () { return false; }

			classno.style.backgroundColor = "#e3e3e3";

			classno.style.color = "#666666";

			classno.onkeyup = function (e)

			{

				if (!e) var e = window.event;

				this.value = '3';

			}		

			if (classno.captureEvents) classno.captureEvents(Event.ONKEYUP);

		}

		else if($('residence').selectedIndex == 3 && $('level').selectedIndex == 2)

		{

			classno.value = '5';

			classno.style.border = '1px solid #666666';

			classno.onselect = function () { return false; }

			classno.onmousedown = function () { return false; }

			classno.style.backgroundColor = "#e3e3e3";

			classno.style.color = "#666666";

			classno.onkeyup = function (e)

			{

				if (!e) var e = window.event;

				this.value = '5';

			}		

			if (classno.captureEvents) classno.captureEvents(Event.ONKEYUP);

		}

		else

		{

			classno.onselect = function () { return true; }

			classno.onmousedown = function () { return true; }

			classno.style.backgroundColor = "#ffffff";

			classno.style.color = "#000000";

			classno.onkeyup = function (e)

			{

				if (!e) var e = window.event;

				this.value =  this.value.replace(/[^0-9]/g,'');

			}		

			if (classno.captureEvents) classno.captureEvents(Event.ONKEYUP);

		}

	}		

	if ($('residence').captureEvents) $('residence').captureEvents(Event.ONCHANGE);

	

	$('level').onchange = function (e)

	{

		if (!e) var e = window.event;

		if(this.selectedIndex == 1 && $('residence').selectedIndex == 3)

		{

			$('classNo').value = '5';

			classno.style.border = '1px solid #666666';

			classno.onselect = function () { return false; }

			classno.onmousedown = function () { return false; }

			classno.style.backgroundColor = "#e3e3e3";

			classno.style.color = "#666666";

			classno.style.fontWeight = 'normal';

			classno.onkeyup = function (e)

			{

				if (!e) var e = window.event;

				this.value = '5';

			}

		}

		else if(this.selectedIndex == 2 && $('residence').selectedIndex == 3)

		{

			$('classNo').value = '3';

			classno.style.border = '1px solid #666666';

			classno.onselect = function () { return false; }

			classno.onmousedown = function () { return false; }

			classno.style.backgroundColor = "#e3e3e3";

			classno.style.color = "#666666";

			classno.style.fontWeight = 'normal';

			classno.onkeyup = function (e)

			{

				if (!e) var e = window.event;

				this.value = '3';

			}

		}

		else

		{

			classno.onselect = function () { return true; }

			classno.onmousedown = function () { return true; }

			classno.style.backgroundColor = "#ffffff";

			classno.style.color = "#000000";

		}

	}		

	if ($('level').captureEvents) $('level').captureEvents(Event.ONCHANGE);

	

}



function initEvents()

{

	var selects = new Array();

	selects.push($('level'));

	selects.push($('semester'));

	selects.push($('residence'));

	var classno = $('classNo');	

	

	for(var i=0; i<selects.length; i++)

	{

		selects[i].onchange = function (e)

		{

			if (!e) var e = window.event;

			if(this.id == 'level')

			{

				if(this.selectedIndex == 1 && $('residence').selectedIndex == 3)

				{

					$('classNo').value = '5';

					classno.style.border = '1px solid #666666';

					classno.onselect = function () { return false; }

					classno.onmousedown = function () { return false; }

					classno.style.backgroundColor = "#e3e3e3";

					classno.style.color = "#666666";

					classno.style.fontWeight = 'normal';

					classno.onkeyup = function (e)

					{

						if (!e) var e = window.event;

						this.value = '5';

					}

				}

				if(this.selectedIndex == 2 && $('residence').selectedIndex == 3)

				{

					$('classNo').value = '3';

					classno.style.border = '1px solid #666666';

					classno.onselect = function () { return false; }

					classno.onmousedown = function () { return false; }

					classno.style.backgroundColor = "#e3e3e3";

					classno.style.color = "#666666";

					classno.style.fontWeight = 'normal';

					classno.onkeyup = function (e)

					{

						if (!e) var e = window.event;

						this.value = '3';

					}

				}

			}

			recalc();

		}		

		if (selects[i].captureEvents) selects[i].captureEvents(Event.ONCHANGE);

	}

	



	classno.onkeyup = function (e)

	{

		if (!e) var e = window.event;

		recalc();

	}		

	if (classno.captureEvents) classno.captureEvents(Event.ONKEYUP);

}



function highlighterror(node, iserred)

{

	if(iserred)

	{

		node.style.border = "1px solid #FF0000";

		node.style.color = "#ff0000";

		node.style.fontWeight = 'bold';

	}

	else

	{

		node.style.border = "1px solid #666666";

		node.style.color = "#000000";

		node.style.fontWeight = 'normal';

	}

}



function validate()

{

	var level = $('level');

	var semester = $('semester');

	var residence = $('residence');

	var classno = $('classNo');



	level.selectedIndex == 0 ? highlighterror(level,true) : highlighterror(level,false)

	semester.selectedIndex == 0 ? highlighterror(semester,true) : highlighterror(semester,false) 

	residence.selectedIndex == 0 ? highlighterror(residence,true) : highlighterror(residence,false) 

	classno.value == '' ? highlighterror(classno,true)  : highlighterror(classno,false) 

	classno.value= classno.value.replace(/[^0-9]/g,'');

	

	if(residence.selectedIndex == 3 && level.selectedIndex == 1)

	{

		classno.value = '5';

		classno.style.border = '1px solid #666666';

		classno.onselect = function () { return false; }

		classno.onmousedown = function () { return false; }

		classno.style.backgroundColor = "#e3e3e3";

		classno.style.color = "#666666";

		classno.style.fontWeight = 'normal';

	}

	else if(residence.selectedIndex == 3 && level.selectedIndex == 2)

	{

		classno.value = '3';

		classno.style.border = '1px solid #666666';

		classno.onselect = function () { return false; }

		classno.onmousedown = function () { return false; }

		classno.style.backgroundColor = "#e3e3e3";

		classno.style.color = "#666666";

		classno.style.fontWeight = 'normal';

	}

	else

	{

		//classno.disabled = false;

		classno.onselect = function () { return true; }

		classno.onmousedown = function () { return true; }

		classno.style.backgroundColor = "#ffffff";

		classno.style.color = "#000000";

	}

	

	if(level.selectedIndex == 0 || semester.selectedIndex == 0 || residence.selectedIndex == 0 || classno.value == '')

	{

		$('dynamic_content').innerHTML = '';

		return false;

	}

	else

	{

		return true;

	}

}





function recalc()

{

	//alert(validate());

	$('dynamic_content').innerHTML = '';

	

	if(validate())

	{

		new Ajax.Updater('dynamic_content','/admissions/uicomponents/scripts/calcTuition.php',

		{

			method:'post',

			parameters: $('tuition_calc').serialize(),

			evalScripts:true,

			onSuccess: function(transport){

				var response = transport.responseText || "no response text";

			},

			onFailure: function(){ alert('Something went wrong...'); }

		});

	}

	else

	{

		$('dynamic_content').innerHTML = "<div class=\"errormsg\">You have errors in your form, please correct and resubmit.</div>"

	}

}



function init_contentlayout() {

	if($('left_hand_col'))

	{

		$('content_div').style.marginLeft = "180px";

	}

	if($('right_hand_col'))

	{

		$('content_div').style.marginRight = "165px";

		$('content_bg').style.backgroundImage = "url(http://www.njit.edu/corporate/uicomponents/mstoner/images/righthandnav_bg.gif)";

	}

}
