function checkallboxes(formName)
{
	var elForm = document.forms[formName];
	for (i=0;i<elForm.elements.length-1;i++)
	{
		if ((elForm.elements[i].type == "checkbox") && (!elForm.elements[i].checked))
			elForm.elements[i].checked = true;
	}
}

function uncheckallboxes(formName)
{
	var elForm = document.forms[formName];
	for (i=0;i<elForm.elements.length-1;i++)
	{
		if ((elForm.elements[i].type == "checkbox") && (elForm.elements[i].checked))
			elForm.elements[i].checked = false;
	}
}

function checkeMailForm(el)
{
	var fields = "The following field(s) need attention:\n\n";
	var failed = false;
	var isChecked = false;
	var subject = document.getElementById('subject');
	var message = document.getElementById('message');
	
		
	for (i=0;i<el.elements.length-1;i++)
	{
		if ((el.elements[i].type == "checkbox") && (el.elements[i].checked))
			isChecked = true;
	}
	
	if (!isChecked)
	{
		fields += 'Select at least one recipient.\n';
		failed = true;
	}
	if (subject.value == "")
	{
		fields += 'eMail Subject\n';
		failed = true;
	}
	if (message.value == "")
	{
		fields += 'eMail Message\n';
		failed = true;
	}
	if (failed)
	{
		alert(fields);
		return false;
	}
	else
		return true;
}

function form_check()
{
	var fields = "The following field(s) need attention:\n\n";
	var failed = false;
	var ltitle = document.getElementById('lecturetitle');
	var lDate = document.getElementById('date');
	var lPrice = document.getElementById('price');
	var temp = lPrice.value;
	
	temp = temp.replace('$', '');
	temp = temp.replace('.', '');
	temp = temp.replace(',', '');
	
	if (ltitle.value == "")
	{
		fields += 'Lecture Title: Cannot be blank.\n';
		failed = true;
	}
	if (!isDate(lDate.value))
	{
		fields += 'Lecture Date: Invalid Date.\n';
		failed = true;
	}
	if (isNaN(temp))
	{
		fields += 'Lecture Price: Enter as $15.00.\n';
		failed = true;
	}
	if (failed)
	{
		alert(fields);
		return false;
	}
	else
		return true;
}

function choose_ssw(el)
{
	var sswgrp 				= document.getElementById('sswoptions');
	var sswsubgrp		 	= document.getElementById('sswsuboptions');	
	var grpclinician 	= document.getElementById('grpclinician');
	var grpalumni 		= document.getElementById('grpalumni');
	var grpalumniyear = document.getElementById('grpalumniyear');
	var grpother 			= document.getElementById('grpother');
	var grpothertext 	= document.getElementById('grpothertext');
	var grpssw  			= document.getElementById('grpssw');
	var sswsub				= document.getElementsByName('sswsub');
		
	if ((el.name == 'grpssw') && (el.checked))
	{
		sswgrp.style.visibility = 'visible';
		sswsubgrp.style.visibility = 'visible';
		grpclinician.checked = false;
		grpclinician.disabled = true;
		grpalumni.checked = false;
		grpalumni.disabled = true;
		grpalumniyear.value = '';
		grpalumniyear.disabled = true;
		grpother.checked = false;
		grpother.disabled = true;
		grpothertext.value = '';
		grpothertext.disabled = true;
	}
	else
	{
		sswgrp.style.visibility = 'hidden';
		sswsubgrp.style.visibility = 'hidden';
		grpclinician.checked = false;
		grpclinician.disabled = false;
		grpalumni.checked = false;
		grpalumni.disabled = false;
		grpalumniyear.value = '';
		grpalumniyear.disabled = false;
		grpother.checked = false;
		grpother.disabled = false;
		grpothertext.value = '';
		grpothertext.disabled = false;
		grpssw.checked = false;
		for (i=0;i<sswsub.length;i++)
			sswsub[i].checked = false;
		
		lecture_49.checked = false;
		lecture_48.checked = false;
		lecture_47.checked = false;
		lecture_46.checked = false;
		lecture_45.checked = false;
		lecture_44.checked = false;
		lecture_43.checked = false;
		lecture_42.checked = false;		
	}
}

function required()
{
	var total = document.getElementById('total');
	var checks = document.getElementsByTagName('input');
	
	var bChecked = false;
	
	for (i=0;i<checks.length;i++)
	{
		if ((checks[i].name.indexOf('ecture_') > 0) && (checks[i].checked))
		{
			bChecked = true;
			break;
		}
	}
	
	if (!bChecked)
	{
		alert('Please choose a lecture.');
		return false;
	}
		
	var fields = "Please complete the form by entering information in the following field(s)\n\n";
	var failed = false;
	
	/* get the required fields */
	var firstname 	= document.getElementById('firstname');
	var lastname 		= document.getElementById('lastname');
	var address			= document.getElementById('address1');
	var city				= document.getElementById('city');
	var state				= document.getElementById('state');
	var zipcode			= document.getElementById('zipcode');
	var email 			= document.getElementById('email');
	var phone				= document.getElementById('contactphone1');
	
	var clinician		= document.getElementById('grpclinician');
	var alumni			= document.getElementById('grpalumni');
	var alumniyear	= document.getElementById('grpalumniyear');
	var other				= document.getElementById('grpother');
	var othertext 	= document.getElementById('grpothertext');
	var ssw					= document.getElementById('grpssw');
	var pid					= document.getElementById('PID');
	var sswsub			= document.getElementsByName('sswsub');
	
	if (firstname.value == "")
	{
		fields += "First Name\n";
		failed = true;
	}
	if (lastname.value == "")
	{
		fields += "Last Name cannot be blank\n";
		failed = true;
	}
	if (address.value == "")
	{
		fields += "Address Line 1 cannot be blank\n";
		failed = true;
	}
	if (city.value == "")
	{
		fields += "City cannot be blank\n";
		failed = true;
	}
	if (state.value == "")
	{
		fields += "Please choose a state\n";
		failed = true;
	}
	if ((zipcode.value == "") || (!ValidZipCode(zipcode.value)))
	{
		fields += "Invalid Zipcode\n";
		failed = true;
	}
	if ((email.value == "") || (!isEmail(email.value)))
	{
		fields += "Invalid Email address format\n";
		failed = true;
	}
	if ((phone.value == "") || (!ValidPhoneNumber(phone.value)))
	{
		fields += "Invalid phone number format for Contact Phone 1\n";
		failed = true;
	}
	if ((!ssw.checked) &&	(!clinician.checked) && 
			(!alumni.checked) && (!other.checked))
	{
		fields += "Choose an Affiliation\n";
		failed = true;
	}
	if (alumni.checked)
	{
		if ((isNaN(alumniyear.value)) || (alumniyear.value == ""))
		{
			fields += "Alumni Year must be numeric (i.e. 1970 or 85)\n";
			failed = true;
		}
	}
	if ((other.checked) && (othertext.value == ""))
	{
		fields += "Other cannot be blank\n";
		failed = true;
	}
	if (ssw.checked)
	{
		if ((pid.value == "") || (isNaN(pid.value)) || (pid.value.length < 9))
		{
			fields += "Invalid PID\n";
			failed = true;
		}
	}
	if ((ssw.checked) && (!sswsub[0].checked) && (!sswsub[1].checked) && (!sswsub[2].checked)&& (!sswsub[3].checked))
	{
		fields += "Please choose a SSW sub category\n";
		failed = true;
	}
	if (failed)
	{
		alert(fields);
		return false;
	}
	else
		return true;
}
function hilite(el)
{
	el.style.color = '#f00;';
}
function lolite(el)
{
	el.style.color = '#000';
}
function mousein(el)
{
	el.style.background = '#0490c7';
	el.style.color = '#fff';
}
function mouseout(el)
{
	el.style.background = '#fff';
	el.style.color = '#000';
}

function isDate(DateToCheck)
{
	if (DateToCheck == "")
		return true;

	var m_strDate = FormatDate(DateToCheck);
	if (m_strDate == "")
		return false;

	var m_arrDate = m_strDate.split("/");
	var m_DAY = m_arrDate[0];
	var m_MONTH = m_arrDate[1];
	var m_YEAR = m_arrDate[2];
	if (m_YEAR.length > 4)
		return false;
		
	m_strDate = m_MONTH + "/" + m_DAY + "/" + m_YEAR;
	var testDate = new Date(m_strDate);
	if (testDate.getMonth()+1 == m_MONTH)
		return true;
	else
		return false;
}

function FormatDate(DateToFormat,FormatAs)
{
	if (DateToFormat == "")
		return "";

	if (!FormatAs)
		FormatAs = "dd/mm/yyyy";

	var strReturnDate;
	FormatAs = FormatAs.toLowerCase();
	DateToFormat = DateToFormat.toLowerCase();
	var arrDate
	var arrMonths = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	var strMONTH;
	var Separator;

	while (DateToFormat.indexOf("st") > -1)
		DateToFormat = DateToFormat.replace("st","");

	while (DateToFormat.indexOf("nd") > -1)
		DateToFormat = DateToFormat.replace("nd","");

	while (DateToFormat.indexOf("rd") > -1)
		DateToFormat = DateToFormat.replace("rd","");

	while (DateToFormat.indexOf("th") > -1)
		DateToFormat = DateToFormat.replace("th","");

	if (DateToFormat.indexOf(".") > -1)
		Separator = ".";

	if (DateToFormat.indexOf("-") > -1)
		Separator = "-";

	if (DateToFormat.indexOf("/") > -1)
		Separator = "/";

	if (DateToFormat.indexOf(" ") > -1)
		Separator = " ";

	arrDate = DateToFormat.split(Separator);
	DateToFormat = "";
	for (var iSD = 0;iSD < arrDate.length;iSD++)
	{
		if (arrDate[iSD] != "")
			DateToFormat += arrDate[iSD] + Separator;
	}
	
	DateToFormat = DateToFormat.substring(0,DateToFormat.length-1);
	arrDate = DateToFormat.split(Separator);

	if (arrDate.length < 3)
		return "";

	var DAY 	= arrDate[0];
	var MONTH = arrDate[1];
	var YEAR 	= arrDate[2];

	if (parseFloat(arrDate[1]) > 12)
	{
		DAY 	= arrDate[1];
		MONTH = arrDate[0];
	}

	if ((parseFloat(DAY)) && (DAY.toString().length == 4))
	{
		YEAR 	= arrDate[0];
		DAY 	= arrDate[2];
		MONTH = arrDate[1];
	}

	for (var iSD = 0;iSD < arrMonths.length;iSD++)
	{
		var ShortMonth = arrMonths[iSD].substring(0,3).toLowerCase();
		var MonthPosition = DateToFormat.indexOf(ShortMonth);
		if (MonthPosition > -1)
		{
			MONTH = iSD + 1;
			if (MonthPosition == 0)
			{
				DAY 	= arrDate[1];
				YEAR 	= arrDate[2];
			}
			break;
		}
	}

	var strTemp = YEAR.toString();
	if (strTemp.length == 2)
	{
		if (parseFloat(YEAR) > 40)
			YEAR = "19" + YEAR;
		else
			YEAR = "20" + YEAR;
	}


	if ((parseInt(MONTH) < 10) && (MONTH.toString().length < 2))
		MONTH = "0" + MONTH;
	
	if ((parseInt(DAY) < 10) && (DAY.toString().length < 2))
		DAY = "0" + DAY;
	
	switch (FormatAs)
	{
		case "dd/mm/yyyy":
			return DAY + "/" + MONTH + "/" + YEAR;
		case "mm/dd/yyyy":
			return MONTH + "/" + DAY + "/" + YEAR;
		case "dd/mmm/yyyy":
			return DAY + " " + arrMonths[MONTH -1].substring(0,3) + " " + YEAR;
		case "mmm/dd/yyyy":
			return arrMonths[MONTH -1].substring(0,3) + " " + DAY + " " + YEAR;
		case "dd/mmmm/yyyy":
			return DAY + " " + arrMonths[MONTH -1] + " " + YEAR;	
		case "mmmm/dd/yyyy":
			return arrMonths[MONTH -1] + " " + DAY + " " + YEAR;
	}

	return DAY + "/" + strMONTH + "/" + YEAR;

}
