////////////If country is US, than select opt ins /////////
function updateOptIns(country) {
	if(country == "USA") {
		$(function() {
			$('#ehsdm').attr('checked', true);
			$('#elsevier').attr('checked', true);
			$('#3rdparty').attr('checked', true);
		});
	}
}

/////////// Remove the required fields, when a new occupation is selected /////////
function updateOccupationReqFields(job) {
	if(job == "ST" || job == "FI") {
		$(function() {
			$('#school').attr('title', 'School');
			$('#schoolSpan').html('*');
		});
	} else {
		$(function() {
			$('#school').attr('title', '');
			$('#schoolSpan').html('');
		});	
	}
}

///////////////////////////////////////Validate Form//////////////////////////////////////////////////
function validateForm(aform) {
	var el = aform.elements;
	var errorMsg = '';
	var isEmail_re = /^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/;
	
	for(var i = 0 ; i < el.length ; ++i) {
		var googleToolbar = el[i].title;
		
		if(googleToolbar.substr(0,11) == "Your Google") {continue;}
		
		if(el[i].name == 'email') {
			if((String(el[i].value).search (isEmail_re) != -1) == false) {
				errorMsg += 'Invalid Email' + '\n';
			}
		} else if (el[i].type == 'select-one') {
			if(el[i].selectedIndex < 1 && el[i].title.length > 0) {
				errorMsg += el[i].title + '\n';
			}
		} else if (el[i].title.length > 0) {
			if(el[i].value.length == 0) {
				errorMsg += el[i].title + '\n';
			}
		}
	}
	
	if(errorMsg.length > 0) {
		errorMsg = 'Please complete all required fields below:\n'+errorMsg;
		alert(errorMsg);
		return false;
	} else {
		return true;
	}
	
	return false;
}