function validEmail(email) {

	invalidChars = " /:,;"

	if (email == "") {
		return false
	}
	for (i=0; i<invalidChars.length; i++) {
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1) {
			return false
		}
	}
	atPos = email.indexOf("@",1)
	if (atPos == -1) {
		return false
	}
	if (email.indexOf("@",atPos+1) > -1) {
		return false
	}
	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1) {
		return false
	}
	if (periodPos+3 > email.length)	{
		return false
	}
	return true
}

function submitIt(subsForm) {
	if (!validEmail($('email').value))
		{
			$('otherErrors').update("Invalid email address");
			$('email').focus()
			$('email').select()
			return false
		}

	//LOOP THROUGH CHECKBOXES AND MAKE SURE AT LEAST ONE IS CHECKED
	var errCount = 0;
	chk = $$('input.interestChk');
	chk.each(function(item){
		if($(item).checked == false)
		{
			errCount++;
		}
	});

	var pref = "";
	var reqfields = new Array('FirstName','LastName','Company','StreetAddress','City','State','ZipPostalCode','Country');

		for(i=0; i < reqfields.length;i++)
			{
				tempfield = "document.subsForm."+pref+reqfields[i]+".value";
				tempid = "document.subsForm."+pref+reqfields[i]+".id";
				tempval = eval(tempfield);
				tempid = eval(tempid);

				if(tempval=="" || tempval=="--Please Select--")
					{
						$('otherErrors').update("Please provide a "+tempid);
						return false;
					}
		}

	//TEST FOR MISSING INTEREST CHECKBOX AFTER REQUIRED IS MET
	var additionalMsg = errCount == chk.length ? '\nPlease choose at least one area of interest' : '';
	$('otherErrors').update(additionalMsg);
	if(additionalMsg != '')
	{
		return false;
	}

	var success = TestCheckBoxes();
	if(success)
	{
			dcsMultiTrack('DCS.dcsuri','/' + par['ca'] + '.html','WT.ti','Thermo Scientific - Welcome to Scientific Instruments Topic Membership Enrollment','WT.si_n',par['ca'],'WT.si_x','2')
			window.setTimeout(function() {document.subsForm.submit()}, 1000);
	}

}

function TestCheckBoxes()
{

	//ADJUST VALUE OF HIDDEN FIELDS
	if($('genOpt').checked == true)
	{
		$('OriginalGeneralOptIn').value = 'Y';
		$('CatchAllList').value = '';
	} else {
		$('OriginalGeneralOptIn').value = 'N';
	}

		var newsLetters = $$('input.newsletterChk');
		var nlUnchecked = 0;
		newsLetters.each(function(item){
			if($(item).checked == false)
			{
				nlUnchecked++;
			}
		});


	//$('CatchAllList').value =  nlUnchecked == newsLetters.length && $('genOpt').checked==false ? 'SIDN14113217' : '';
	if($('genOpt').checked == false)
	{
		alert('You have not authorized us to send your information on the Scientific Instruments Topic via email.  Please check the box at the top left of the page.');
		return false;
	} else {
		return true;
	}
}

function init()
{

	if(location.search)
	{
		par = location.search.toQueryParams();
		$('email').value = typeof(par['em']) != 'undefined' ? par['em'] : '';
		$('First Name').value = typeof(par['fName']) != 'undefined' ? par['fName'] : '';
		$('Last Name').value =  typeof(par['lName']) != 'undefined' ? par['lName'] : '';
	}


}

Event.observe(window, 'load', function() {init();Event.observe('genOpt','click',TestCheckBoxes)});