function placeFocus() 
{
	if (document.forms.length > 0) 
	{
		var field = document.forms[0];
		for (i = 0; i < field.length; i++) 
		{
			if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s")) 
			{
				document.forms[0].elements[i].focus();
				break;
		    }
	    }
    }
}

function isDate(dateStr) {

var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
var matchArray = dateStr.match(datePat); // is the format ok?

if (matchArray == null) {
alert("Please enter date in mm/dd/yyyy format.");
return false;
}

month = matchArray[1]; // p@rse date into variables
day = matchArray[3];
year = matchArray[5];

if (month < 1 || month > 12) { // check month range
alert("Month must be between 1 and 12.");
return false;
}

if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
return false;
}

if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn`t have 31 days!")
return false;
}

if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day > 29 || (day==29 && !isleap)) {
alert("February " + year + " doesn`t have " + day + " days!");
return false;
}
}
return true; // date is valid
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		secondary_02_over = newImage("img/secondary_02-over.gif");
		secondary_03_over = newImage("img/secondary_03-over.gif");
		secondary_04_over = newImage("img/secondary_04-over.gif");
		secondary_05_over = newImage("img/secondary_05-over.gif");
		secondary_06_over = newImage("img/secondary_06-over.gif");
		secondary_07_over = newImage("img/secondary_07-over.gif");
		secondary_08_over = newImage("img/secondary_08-over.gif");
		secondary_09_over = newImage("img/secondary_09-over.gif");
		preloadFlag = true;
	}
}

// -->

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function f_editpassword_validate()
{
		if (document.f_editpassword.pwd.value=="")
		{
			alert("Please enter a value in the password field.");
			document.f_editpassword.pwd.focus();
			return false;
		}
		if (document.f_editpassword.cpwd.value=="")
		{
			alert("Please enter a value in the confirm password field.");
			document.f_editpassword.cpwd.focus();
			return false;
		}
		if (document.f_editpassword.pwd.value!=document.f_editpassword.cpwd.value)
		{
			alert("The password and confirm password fields donot match please re-enter them.")
			document.f_editpassword.pwd.value="";
			document.f_editpassword.cpwd.value="";
			document.f_editpassword.pwd.focus();
			return false;
		}
		return true;
}

function f_addeditlogin_validate()
{
		if (document.f_addeditlogin.uname.value=="")
		{
			alert("Please enter a username.");
			document.f_addeditlogin.uname.focus();
			return false;
		}
		if (document.f_addeditlogin.pwd.value=="")
		{
			alert("Please enter a password.");
			document.f_addeditlogin.pwd.focus();
			return false;
		}
		if (document.f_addeditlogin.fname.value=="")
		{
			alert("Please enter a firstname.");
			document.f_addeditlogin.fname.focus();
			return false;
		}
		if (document.f_addeditlogin.lname.value=="")
		{
			alert("Please enter a lastname.");
			document.f_addeditlogin.lname.focus();
			return false;
		}
		if (document.f_addeditlogin.email.value=="")
		{
			alert("Please enter a email address.");
			document.f_addeditlogin.email.focus();
			return false;
		}
		if (document.f_addeditlogin.role.value=="")
		{
			alert("Please select a role for the user.");
			document.f_addeditlogin.role.focus();
			return false;
		}
		return true;
}

function f_addeditaudience_validate()
{
		if (document.f_addeditaudience.aname.value=="")
		{
			alert("Please enter a audience name.");
			document.f_addeditaudience.aname.focus();
			return false;
		}
		return true;
}

function f_addeditparticipation_validate()
{
		if (document.f_addeditparticipation.pname.value=="")
		{
			alert("Please enter a participation level.");
			document.f_addeditparticipation.pname.focus();
			return false;
		}
		return true;
}

function f_addedittimezone_validate()
{
		if (document.f_addedittimezone.tname.value=="")
		{
			alert("Please enter a Time Zone.");
			document.f_addedittimezone.tname.focus();
			return false;
		}
		return true;
}

function f_addeditgradelevel_validate()
{
		if (document.f_addeditgradelevel.gname.value=="")
		{
			alert("Please enter a Grade Level.");
			document.f_addeditgradelevel.gname.focus();
			return false;
		}
		return true;
}

function f_addeditsubject_validate()
{
		if (document.f_addeditsubject.sname.value=="")
		{
			alert("Please enter a Curriculum Subject.");
			document.f_addeditsubject.sname.focus();
			return false;
		}
		return true;
}

function f_addeditstate_validate()
{
		if (document.f_addeditstate.sabb.value=="")
		{
			alert("Please enter a State ID.");
			document.f_addeditstate.sabb.focus();
			return false;
		}
		if (document.f_addeditstate.sname.value=="")
		{
			alert("Please enter a State of America.");
			document.f_addeditstate.sname.focus();
			return false;
		}		
		return true;
}

function f_addeditcredit_validate()
{
		if (document.f_addeditcredit.cname.value=="")
		{
			alert("Please enter a Credit Type.");
			document.f_addeditcredit.cname.focus();
			return false;
		}
		return true;
}

function f_addeditrole_validate()
{
		if (document.f_addeditrole.rname.value=="")
		{
			alert("Please enter a Role.");
			document.f_addeditrole.rname.focus();
			return false;
		}
		if (document.f_addeditrole.navids.value=="")
		{
			alert("Please Select a Navigation.");
			document.f_addeditrole.navids.focus();
			return false;
		}
		return true;
}
function f_addeditnav_validate()
{
		document.f_addeditnav.content.value=oDiv.innerHTML;
		document.f_addeditnav.attachedfile.value=document.f_addeditnav.uploadfile.value;
		if (document.f_addeditnav.nname.value=="")
		{
			alert("Please enter a Navigation Name.");
			document.f_addeditnav.nname.focus();
			return false;
		}		
		return true;
}
function f_addeditproposition_validate()
{
		if (document.f_addeditproposition.pname.value=="")
		{
			alert("Please enter a Proposition.");
			document.f_addeditproposition.pname.focus();
			return false;
		}
		return true;
}

function f_addeditscientificallybasedreserch_validate()
{
		if (document.f_addeditscientificallybasedreserch.sname.value=="")
		{
			alert("Please enter a Scientifically Based Reserch.");
			document.f_addeditscientificallybasedreserch.sname.focus();
			return false;
		}
		return true;
}

function f_addeditoppurtunity_validate()
{
		if (document.f_addeditoppurtunity.audience.value=="")
		{
			alert("Please select the audience.");
			document.f_addeditoppurtunity.audience.focus();
			return false;
		}
		if (document.f_addeditoppurtunity.participation.value=="")
		{
			alert("Please select the participation.");
			document.f_addeditoppurtunity.participation.focus();
			return false;
		}
		if (document.f_addeditoppurtunity.participation.value=="2")
		{
			if (document.f_addeditoppurtunity.epart.value=="")
			{
				alert("Please enter a value in the eligible participants field.");
				document.f_addeditoppurtunity.epart.focus();
				return false;
			}			
		}
		else
		{
			if (document.f_addeditoppurtunity.epart.value!="")
			{
				alert("Since the event is open to anyone there should be no value entered in eligible participants field");
				document.f_addeditoppurtunity.epart.value="";
				document.f_addeditoppurtunity.epart.focus();
				return false;
			}			
		}
		if (document.f_addeditoppurtunity.title.value=="")
		{
			alert("Please enter a value for the title.");
			document.f_addeditoppurtunity.title.focus();
			return false;
		}
		
		if (!(isDate(document.f_addeditoppurtunity.msdate.value+"/"+document.f_addeditoppurtunity.dsdate.value+"/"+document.f_addeditoppurtunity.ysdate.value)))
		{
			alert("Please enter a valid start date.");
			document.f_addeditoppurtunity.msdate.focus();
			return false;
		}
		if (!(isDate(document.f_addeditoppurtunity.medate.value+"/"+document.f_addeditoppurtunity.dedate.value+"/"+document.f_addeditoppurtunity.yedate.value)))
		{
			alert("Please enter a valid end date.");
			document.f_addeditoppurtunity.medate.focus();
			return false;
		}
		if (document.f_addeditoppurtunity.shour.value=="")
		{
			alert("Please select the hour of the start time.");
			document.f_addeditoppurtunity.shour.focus();
			return false;
		}
		if (document.f_addeditoppurtunity.smin.value=="")
		{
			alert("Please select the minute of the start time.");
			document.f_addeditoppurtunity.smin.focus();
			return false;
		}
		if (document.f_addeditoppurtunity.smeridian.value=="")
		{
			alert("Please select the meridian of the start time.");
			document.f_addeditoppurtunity.smeridian.focus();
			return false;
		}
		if (document.f_addeditoppurtunity.ehour.value=="")
		{
			alert("Please select the hour of the end time.");
			document.f_addeditoppurtunity.ehour.focus();
			return false;
		}
		if (document.f_addeditoppurtunity.emin.value=="")
		{
			alert("Please select the minute of the end time.");
			document.f_addeditoppurtunity.emin.focus();
			return false;
		}
		if (document.f_addeditoppurtunity.emeridian.value=="")
		{
			alert("Please select the meridian of the end time.");
			document.f_addeditoppurtunity.emeridian.focus();
			return false;
		}
		if (document.f_addeditoppurtunity.tzone.value=="")
		{
			alert("Please select the Time Zone of the event.");
			document.f_addeditoppurtunity.tzone.focus();
			return false;
		}
		if (document.f_addeditoppurtunity.overview.value=="")
		{
			alert("Please enter the overview of the event.");
			document.f_addeditoppurtunity.overview.focus();
			return false;
		}
		if (document.f_addeditoppurtunity.location.value=="")
		{
			alert("Please enter the location of the event.");
			document.f_addeditoppurtunity.location.focus();
			return false;
		}
		if (document.f_addeditoppurtunity.address.value=="")
		{
			alert("Please enter the physical address of the event.");
			document.f_addeditoppurtunity.address.focus();
			return false;
		}
		if (document.f_addeditoppurtunity.city.value=="")
		{
			alert("Please enter the city of the event.");
			document.f_addeditoppurtunity.city.focus();
			return false;
		}
		if (document.f_addeditoppurtunity.state.value=="")
		{
			alert("Please select the state of the event.");
			document.f_addeditoppurtunity.state.focus();
			return false;
		}
		if (document.f_addeditoppurtunity.provider.value=="")
		{
			alert("Please enter the provider / agency of the event.");
			document.f_addeditoppurtunity.provider.focus();
			return false;
		}
		if (document.f_addeditoppurtunity.cname.value=="")
		{
			alert("Please enter the Contact person's name.");
			document.f_addeditoppurtunity.cname.focus();
			return false;
		}
		if (document.f_addeditoppurtunity.ctype.value=="")
		{
			if (document.f_addeditoppurtunity.noc.value!="0")
			{
				alert("When no credit type is selected the value for No. of Credits should be 0 (Zero).");
				document.f_addeditoppurtunity.noc.value="0";
				document.f_addeditoppurtunity.noc.focus();
				return false;
			}			
		}
		else
		{
			//if (document.f_addeditoppurtunity.noc.value=="0")
			//{
			//	alert("When a credit type is selected the value for No. of Credits cannot be 0 (Zero).");
			//	document.f_addeditoppurtunity.overview.focus();
			//	return false;
			//}
			if (document.f_addeditoppurtunity.noc.value!="")
			{
				for (i=0;i<document.f_addeditoppurtunity.noc.value.length ;i++ )
				{	
					if (isNaN(document.f_addeditoppurtunity.noc.value.substr(i,1)))
					{
						alert("Number of Credits must be a numeric value without special characters.");
						document.f_addeditoppurtunity.noc.focus();
						return false;
					}
				}
			}
			else
			{
				alert("Please enter a value for Number of Credits.");
				document.f_addeditoppurtunity.noc.focus();
				return false;				
			}
			
		}
		if (document.f_addeditoppurtunity.phone1.value!="" || document.f_addeditoppurtunity.phone2.value!="" || document.f_addeditoppurtunity.phone3.value!="")
		{
			if (document.f_addeditoppurtunity.phone1.value!="" && document.f_addeditoppurtunity.phone2.value!="" && document.f_addeditoppurtunity.phone3.value!="")
			{
				for (i=0;i<document.f_addeditoppurtunity.phone1.value.length ;i++ )
				{	
					if (isNaN(document.f_addeditoppurtunity.phone1.value.substr(i,1)))
					{
						alert("Phone number must be a numeric value without special characters.");
						document.f_addeditoppurtunity.phone1.focus();
						return false;
					}
				}
				for (i=0;i<document.f_addeditoppurtunity.phone2.value.length ;i++ )
				{	
					if (isNaN(document.f_addeditoppurtunity.phone2.value.substr(i,1)))
					{
						alert("Phone number must be a numeric value without special characters.");
						document.f_addeditoppurtunity.phone2.focus();
						return false;
					}
				}
				for (i=0;i<document.f_addeditoppurtunity.phone3.value.length ;i++ )
				{	
					if (isNaN(document.f_addeditoppurtunity.phone3.value.substr(i,1)))
					{
						alert("Phone number must be a numeric value without special characters.");
						document.f_addeditoppurtunity.phone3.focus();
						return false;
					}
				}
			}
			else
			{
				alert("Please enter a valid phone number.");
				document.f_addeditoppurtunity.phone1.focus();
				return false;
			}			
		}

		if (document.f_addeditoppurtunity.stipend.value!="")
		{
			for (i=0;i<document.f_addeditoppurtunity.stipend.value.length ;i++ )
			{	
				if (isNaN(document.f_addeditoppurtunity.stipend.value.substr(i,1)))
				{
					alert("Stipend must be a numeric value without special characters.");
					document.f_addeditoppurtunity.stipend.focus();
					return false;
				}
			}
		}

		if (document.f_addeditoppurtunity.cost.value!="")
		{
			for (i=0;i<document.f_addeditoppurtunity.cost.value.length ;i++ )
			{	
				if (isNaN(document.f_addeditoppurtunity.cost.value.substr(i,1)))
				{
					alert("Cost must be a numeric value without special characters.");
					document.f_addeditoppurtunity.cost.focus();
					return false;
				}
			}
		}

		if (document.f_addeditoppurtunity.min.value!="")
		{
			for (i=0;i<document.f_addeditoppurtunity.min.value.length ;i++ )
			{	
				if (isNaN(document.f_addeditoppurtunity.min.value.substr(i,1)))
				{
					alert("Minimum Attendees must be a numeric value without special characters.");
					document.f_addeditoppurtunity.min.focus();
					return false;
				}
			}
		}

		if (document.f_addeditoppurtunity.max.value!="")
		{
			for (i=0;i<document.f_addeditoppurtunity.max.value.length ;i++ )
			{	
				if (isNaN(document.f_addeditoppurtunity.max.value.substr(i,1)))
				{
					alert("Maximum Attendees must be a numeric value without special characters.");
					document.f_addeditoppurtunity.max.focus();
					return false;
				}
			}
		}
		return true;
}

function f_search_validate()
{
	if (document.f_search.msdate.value!="" || document.f_search.dsdate.value!="" || document.f_search.ysdate.value!="")
	{
		if (document.f_search.msdate.value!="" && document.f_search.dsdate.value!="" && document.f_search.ysdate.value!="")
		{
			if (!(isDate(document.f_search.msdate.value+"/"+document.f_search.dsdate.value+"/"+document.f_search.ysdate.value)))
			{
				alert("Please enter a valid start date.");
				document.f_search.msdate.focus();
				return false;
			}
		}
		else
		{
			alert("Please enter a valid start date.");
			document.f_search.msdate.focus();
			return false;
		}
	}
	
	return true;
}

function f_proddisp_validate()
{
	// check for null value of quantity
	if (document.f_proddisp.qty.value=="")
	{
		alert("Please enter a value for the quantity of the product");
		document.f_proddisp.qty.focus();
		return false;
	}
	// check for non numeric value of quantity
	if (isNaN(document.f_proddisp.qty.value))
	{
		alert("Please enter a numeric value for the quantity of the product");
		document.f_proddisp.qty.focus();
		return false;
	}
	// check for maxqty =0 . If maxqty > 0 then check for qty > maxqty	
	if (document.f_proddisp.mqty.value!=0)
	{
		if (parseInt(document.f_proddisp.qty.value) > parseInt(document.f_proddisp.mqty.value))
		{
			alert("This product has a limit on purchase. Purchase cannot exceed "+document.f_proddisp.mqty.value+". Please change the value in the quantity field.");
			document.f_proddisp.qty.focus();
			return false;
		}
	}
	return true;
}

function f_shoppingcart_validate(formno)
{
	for (i=1;i<=formno;i++ )
	{
		if (eval('document.f_shoppingcart.qty'+i+'.value')=="")
		{
			alert("Please enter a value for the quantity of the product");
			eval('document.f_shoppingcart.qty'+i+'.focus()');
			return false;
		}
		if (isNaN(eval('document.f_shoppingcart.qty'+i+'.value')))
		{
			alert("Please enter a numeric value for the quantity of the product");
			eval('document.f_shoppingcart.qty'+i+'.focus()');
			return false;
		}
		if (eval('document.f_shoppingcart.mqty'+i+'.value')!=0)
		{
			if (parseInt(eval('document.f_shoppingcart.qty'+i+'.value')) > parseInt(eval('document.f_shoppingcart.mqty'+i+'.value')))
			{
				alert("This product has a limit on purchase. Purchase cannot exceed "+eval('document.f_shoppingcart.mqty'+i+'.value')+". Please change the value in the quantity field.");
				eval('document.f_shoppingcart.qty'+i+'.focus()');
				return false;
			}
		}
	}	
	return true;
}

function f_createlogin_validate()
{
	if (document.f_createlogin.fname.value=="")
	{
		alert("First name field is required");
		document.f_createlogin.fname.focus();
		return false;
	}
	if (document.f_createlogin.lname.value=="")
	{
		alert("Last name field is required");
		document.f_createlogin.lname.focus();
		return false;
	}
	if (document.f_createlogin.address.value=="")
	{
		alert("Address field is required");
		document.f_createlogin.address.focus();
		return false;
	}
	if (document.f_createlogin.city.value=="")
	{
		alert("City field is required");
		document.f_createlogin.city.focus();
		return false;
	}
	if (document.f_createlogin.state.value=="")
	{
		alert("State field is required");
		document.f_createlogin.state.focus();
		return false;
	}
	if (document.f_createlogin.zipcode.value=="")
	{
		alert("Zipcode field is required");
		document.f_createlogin.zipcode.focus();
		return false;
	}
	if (isNaN(document.f_createlogin.zipcode.value))
	{
		alert("Please enter a numeric value for the zipcode");
		document.f_createlogin.zipcode.focus();
		return false;
	}
	if (document.f_createlogin.hphone.value=="")
	{
		alert("Home Phone field is required");
		document.f_createlogin.hphone.focus();
		return false;
	}
	if (isNaN(document.f_createlogin.hphone.value))
	{
		alert("Please enter a numeric value for the Home Phone");
		document.f_createlogin.hphone.focus();
		return false;
	}
	if (document.f_createlogin.ophone.value!="")
	{
		if (isNaN(document.f_createlogin.ophone.value))
		{
			alert("Please enter a numeric value for the Office Phone");
			document.f_createlogin.ophone.focus();
			return false;
		}
	}
	
	/*if (document.f_createlogin.ctype.value=="")
	{
		alert("Credit Card Type field is required");
		document.f_createlogin.ctype.focus();
		return false;
	}
	if (document.f_createlogin.cno.value=="")
	{
		alert("Credit Card Number field is required");
		document.f_createlogin.cno.focus();
		return false;
	}*/
	if (document.f_createlogin.cno.value!="")
	{
		if (isNaN(document.f_createlogin.cno.value))
		{
			alert("Please enter a numeric value for the Credit Card Number");
			document.f_createlogin.cno.focus();
			return false;
		}
	}
	/*if (document.f_createlogin.cmonth.value=="" || document.f_createlogin.cyear.value=="")
	{
		alert("Expiration Date field is required");
		document.f_createlogin.cmonth.focus();
		return false;
	}*/
	if (document.f_createlogin.cmonth.value!="" || document.f_createlogin.cyear.value!="")
	{
		if (isNaN(document.f_createlogin.cmonth.value))
		{
			alert("Please enter a numeric value for the expiration dates month");
			document.f_createlogin.cmonth.focus();
			return false;
		}
		if (document.f_createlogin.cmonth.value.length<2)
		{
			alert("The expiry month of the credit card should be in the format mm");
			document.f_createlogin.cmonth.focus();
			return false;
		}
		if (isNaN(document.f_createlogin.cyear.value))
		{
			alert("Please enter a numeric value for the expiration dates year");
			document.f_createlogin.cyear.focus();
			return false;
		}

		if (document.f_createlogin.cyear.value.length<4)
		{
			alert("The expiry year of the credit card should be in the format yyyy");
			document.f_createlogin.cyear.focus();
			return false;
		}
	}
	if (document.f_createlogin.uname.value=="")
	{
		alert("Email field is required");
		document.f_createlogin.uname.focus();
		return false;
	}
	if (document.f_createlogin.pwd.value=="")
	{
		alert("Password field is required");
		document.f_createlogin.pwd.focus();
		return false;
	}
	return true;
}

function f_login_validate()
{
	if (document.f_login.uname.value=="")
	{
		alert("The username field is required");
		document.f_login.uname.focus();
		return false;
	}
	if (document.f_login.pwd.value=="")
	{
		alert("The password field is required");
		document.f_login.pwd.focus();
		return false;
	}
	return true;
}

function f_addeditnews_validate()
{
	document.f_addeditnews.content.value=oDiv.innerHTML;
	if (document.f_addeditnews.content.value=="")
	{
		alert("The Content for the Quick Tips cannot be null.");
		return false;
	}
	return true;
}

function f_uploadimages_validate()
{
	document.f_uploadimages.uploadfile.value=document.f_uploadimages.imagefile.value;
	return true;
}