//socioabs.js - validate form input for socioabs form

String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function verify_recaptcha(strng) {
	var error = "";
	var strng = strng.trim();
	var error ="";
	if (strng == "") {
		error = "Security Code is required\n";
	}
	return error;
}

function verify_conference(radioObj) {
	var error = "";
	var radioLength = radioObj.length;
	var radioValue = "";
	
	for (var i=0; i<radioLength; i++) {
		if (radioObj[i].checked) {
			var radioValue = radioObj[i].value;
		}
	}
	if (radioValue == "") {
		error = "Please select a Conference\n";
	}
	return error;
}

function verify_author(strng) {
	var strng = strng.trim();
	var error ="";
	if (strng == "") {
		error = "Author field is required\n";
	}
	var myregex = /\;/
	var matchpos = strng.search(myregex)
	if ( matchpos == -1 ) {
	} else {
		error = "Please enter one author name, others as Additional Authors\n";
	}
	return error;
}

function verify_title(strng) {
	var strng = strng.trim();
	var error ="";
	if (strng == "") {
		error = "Title field is required\n";
		}
	return error;
}

function verify_abstract(strng) {
	var strng = strng.trim();
	var error ="";
	if (strng == "") {
		error = "Abstract is required\n";
	}
	return error;
}

function verify_email(strng) {
	var strng = strng.trim();
	var error = "";
	var emailFilter=/^.+@.+\..{2,3}$/;
	var illegalChars = /[\(\)\<\>\, \:\\\"\[\]]/;

	if (strng == "") {
		error = "Email address is required\n";
	}
	
	var myregex = /\;/
	var matchpos = strng.search(myregex)
	if ( matchpos == -1 ) {
		var emailFilter=/^.+@.+\..{2,3}$/;
		if (!(emailFilter.test(strng) )) {
			error = "Please enter a valid email\n";
		} else {
			if (strng.match(illegalChars)) {
			error = "Email contains illegal characters\n";
			}
		}
	} else {
		var emails = new Array()
		var emails = strng.split(";")
		for (var j=0; j<emails.length; j++) {
				//alert(emails[j])
			if (!(emailFilter.test(emails[j]))) {
				error = "Please enter valid email(s)\n";
			} else {
				if (emails[j].match(illegalChars)) {
				error = "Email contains illegal characters\n";
				}
			}
		}
	}
			return error;
}

var RecaptchaOptions = {
	theme: 'custom',
	lang: 'en',
	custom_theme_widget: 'recaptcha_widget'
};

