//this.onload = clearIncome;
function show_div(id)
{
	div = document.getElementById(id);
	div.style.display = "block";

}

function setIncome(){
	
	document.forms[0].hidIncomeInfo.value="1";
	//alert('OK');
}
function clearIncome(){

	
		document.forms[0].hidIncomeInfo.value="0";
		//alert('Clear info');
}
function clearAllIncome(){

	var xForm = document.forms[0];
	xForm.how_often.selectedIndex = 0;
	clearIncome();


}

function hide_div(id)

{

	div = document.getElementById(id);

	if (div.style == null)
		alert(id + " is not a div!");

	div.style.display = "none";

}



function _how_often(val)

{
	clearIncome();

	hide_div("paydate_monthly");

	hide_div("paydate_weekly");

	hide_div("paydate_biweekly");

	hide_div("paydate_twicemonthly");



	switch(val)

	{

	case "WEEKLY":

		show_div("paydate_weekly");

		break;

	case "BI_WEEKLY":

		show_div("paydate_biweekly");

		break;

	case "TWICE_MONTHLY":

		show_div("paydate_twicemonthly");

		// This sucks but you can't use arrays in Javascipt so the paydate[twicemonthly] radio boxes cannot be manipulated by JS

		// So, we have to assign the first element of paydate[twicemonthly] an id and then erase it if it is checked

		twice_day = document.getElementById("twicemonthly_type").checked;

		if(twice_day=='biweekly')

		{

			document.getElementById("twicemonthly_type").checked = '';

			hide_div("twicemonthly_biweekly");

		}

		break;

	case "MONTHLY":

		show_div("paydate_monthly");

		break;

	}

}



function _biweekly_day(val)

{

	clearIncome();
	twice_day = document.getElementById("biweekly_twice_day");

	eow_day = document.getElementById("biweekly_day");

	twice_day.selectedIndex = eow_day.selectedIndex;

	hide_div("paydate_biweekly_MON");

	hide_div("paydate_biweekly_TUE");

	hide_div("paydate_biweekly_WED");

	hide_div("paydate_biweekly_THU");

	hide_div("paydate_biweekly_FRI");

	show_div("paydate_biweekly_" + val);

	hide_div("paydate_twice_biweekly_MON");

	hide_div("paydate_twice_biweekly_TUE");

	hide_div("paydate_twice_biweekly_WED");

	hide_div("paydate_twice_biweekly_THU");

	hide_div("paydate_twice_biweekly_FRI");

	show_div("paydate_twice_biweekly_" + val);

}



function _biweekly_twice_day(val)

{
	
	clearIncome();
	twice_day = document.getElementById("biweekly_twice_day");

	eow_day = document.getElementById("biweekly_day");

	eow_day.selectedIndex = twice_day.selectedIndex;

	hide_div("paydate_biweekly_MON");

	hide_div("paydate_biweekly_TUE");

	hide_div("paydate_biweekly_WED");

	hide_div("paydate_biweekly_THU");

	hide_div("paydate_biweekly_FRI");

	show_div("paydate_biweekly_" + val);

	hide_div("paydate_twice_biweekly_MON");

	hide_div("paydate_twice_biweekly_TUE");

	hide_div("paydate_twice_biweekly_WED");

	hide_div("paydate_twice_biweekly_THU");

	hide_div("paydate_twice_biweekly_FRI");

	show_div("paydate_twice_biweekly_" + val);

}



function twicemonthly_biweekly_show()

{	// This value has to be set to every other week to process correctly, even though it is in twice per month

	clearIncome();
	document.getElementById("how_often").selectedIndex = 2;

	hide_div("twicemonthly_day");

	hide_div("twicemonthly_date");

	show_div("twicemonthly_biweekly");

}



function twicemonthly_date_show()

{
	clearIncome();

	document.getElementById("how_often").selectedIndex = 3;

	hide_div("twicemonthly_day");

	hide_div("twicemonthly_biweekly");

	show_div("twicemonthly_date");

}



function twicemonthly_day_show()

{
	clearIncome();

	document.getElementById("how_often").selectedIndex = 3;

	hide_div("twicemonthly_biweekly");

	hide_div("twicemonthly_date");

	show_div("twicemonthly_day");

}



function monthly_date_show()

{
	clearIncome();
	show_div("monthly_date");

	hide_div("monthly_day");

	hide_div("monthly_after");

}



function monthly_day_show()

{

	clearIncome();
	hide_div("monthly_date");

	show_div("monthly_day");

	hide_div("monthly_after");

}



function monthly_after_show()

{

	clearIncome();
	hide_div("monthly_date");

	hide_div("monthly_day");

	show_div("monthly_after");

}

function test(){
	if (f.paydate_frequency.value == "") {

		retValue = false;

		f.paydate_frequency.focus();

		alert("Please select how often you're getting paid");
		
		return false;

	}



	if (f.paydate_frequency.value == "WEEKLY") {

		if (f.paydate_weekly_day.value == "") {

			retValue = false;

			f.paydate_weekly_day.focus();

			alert("Please select the day you get paid");

			return false;

		}

	}

		

	if (f.paydate_frequency.value == "BI_WEEKLY") {

		if (f.paydate_biweekly_day.value == "") {

			retValue = false;

			f.paydate_biweekly_day.focus();

			alert("Please select the day you get paid");

			return false;

		} else {

			// set var radio_choice to false

			var radio_choice = false;

					

			// Loop from zero to the one minus the number of radio button selections

			for (counter = 0; counter < f.paydate_biweekly_date.length; counter++)

			{

			// If a radio button has been selected it will return true

			// (If not it will return false)

			if (f.paydate_biweekly_date[counter].checked)

				radio_choice = true; 

			}

			if (!radio_choice) {

				// If there were no selections made display an alert box 

				alert("Please select Last Paydate");

				return false;

			}

			

		}

	}

	

	if (f.paydate_frequency.value == "TWICE_MONTHLY") {

		// set var radio_choice to false

		radio_choice = false;

				

		// Loop from zero to the one minus the number of radio button selections

		for (counter = 0; counter < f.paydate_twicemonthly_type.length; counter++)

		{

		// If a radio button has been selected it will return true

		// (If not it will return false)

		if (f.paydate_twicemonthly_type[counter].checked)

			radio_choice = true; 

		}

		if (!radio_choice) {

			// If there were no selections made display an alert box 

			alert("Please select twice monthly option");

			return false;

		}

	}

	

	if (f.paydate_frequency.value == "TWICE_MONTHLY") {

		if (f.paydate_twicemonthly_type[1].checked) {

			if (f.paydate_twicemonthly_date1.value == "") {

				retValue = false;

				f.paydate_twicemonthly_date1.focus();

				alert("Please choose Date 1");

				return false;

			}

			if (f.paydate_twicemonthly_date2.value == "") {

				retValue = false;

				f.paydate_twicemonthly_date2.focus();

				alert("Please choose Date 2");

				return false;

			}

		}

	}

	

	if (f.paydate_frequency.value == "TWICE_MONTHLY") {

		if (f.paydate_twicemonthly_type[2].checked) {

			if (f.paydate_twicemonthly_week.value == "") {

				retValue = false;

				f.paydate_twicemonthly_week.focus();

				alert("Please choose Date 1");

				return false;

			}

			if (f.paydate_twicemonthly_day.value == "") {

				retValue = false;

				f.paydate_twicemonthly_day.focus();

				alert("Please choose Date 2");

				return false;

			}

		}

	}

	

	if (f.paydate_frequency.value == "MONTHLY") {

		// set var radio_choice to false

		radio_choice = false;

				

		// Loop from zero to the one minus the number of radio button selections

		for (counter = 0; counter < f.paydate_monthly_type.length; counter++)

		{

		// If a radio button has been selected it will return true

		// (If not it will return false)

		if (f.paydate_monthly_type[counter].checked)

			radio_choice = true; 

		}

		if (!radio_choice) {

			// If there were no selections made display an alert box 

			alert("Please select monthly option");

			return false;

		}

	}

	

	if (f.paydate_frequency.value == "MONTHLY") {

		if (f.paydate_monthly_type[0].checked) {

			if (f.paydate_monthly_date.value == "") {

				retValue = false;

				f.paydate_monthly_date.focus();

				alert("Please choose monthly Date");

				return false;

			}

		}

	}

	

	if (f.paydate_frequency.value == "MONTHLY") {

		if (f.paydate_monthly_type[1].checked) {

			if (f.paydate_monthly_week.value == "") {

				retValue = false;

				f.paydate_monthly_week.focus();

				alert("Please choose monthly Week");

				return false;

			}

			if (f.paydate_monthly_day.value == "") {

				retValue = false;

				f.paydate_monthly_day.focus();

				alert("Please choose monthly Day");

				return false;

			}

		}

	}

	

	if (f.paydate_frequency.value == "MONTHLY") {

		if (f.paydate_monthly_type[2].checked) {

			if (f.paydate_monthly_after_day.value == "") {

				retValue = false;

				f.paydate_monthly_after_day.focus();

				alert("Please choose a day");

				return false;

			}

			if (f.paydate_monthly_after_date.value == "") {

				retValue = false;

				f.paydate_monthly_after_date.focus();

				alert("Please choose a date");

				return false;

			}

		}

	}
}
