
// Email Validation
function isEmail(str) {
if (str == "")
return true;
else
var supported = 0;
if (window.RegExp) {
var tempStr = "a";
var tempReg = new RegExp(tempStr);
if (tempReg.test(tempStr)) supported = 1;
}
if (!supported) 
return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");
return (!r1.test(str) && r2.test(str));
}
function isblank(s)
{
for (var i = 0; i < s.length; i++) {
var c = s.charAt(i);
if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
}
return true;
}
function MailValidate() {
var empty_fields = "";
var errors = "";
if (!isEmail(document.subscribe.email.value)){
errors += "- You did not provide a valid e-mail address for yourself" + "\n\n";
}
if ((document.subscribe.email.value == null) || (document.subscribe.email.value == "") || isblank(document.subscribe.email.value)){
empty_fields += "\n        " + "Your Email Address";
}
if (!empty_fields && !errors) {
return true;
}
msg =  "******************************************************************\n";
msg += " The Form was not submitted because of the following error.\n";
msg += " Please correct the error and re-submit.\n";
msg +=  "******************************************************************\n\n";
if (empty_fields) {
msg += "- The following mandatory field is empty: \n"
+ empty_fields + "\n\n";
}
if (errors) {
msg += errors + "\n\n";
}
alert(msg);
document.subscribe.email.focus();
document.subscribe.email.select();
return false;
}

function verify(f)
{
        var msg;
        
        
        var empty_fields = "";
        var errors = "";

        for (var i = 0; i < f.length; i++) {
        var e = f.elements[i];
if (e.name == "email") {
			if (!isEmail(e.value))
				errors += "- You did not provide a valid e-mail address " + "\n\n";
				if ((e.value == null) || (e.value == "") || isblank(e.value))
				empty_fields += "\n        " + "Email Address";
		}
		if (e.name == "fullname") {
			
				if ((e.value == null) || (e.value == "") || isblank(e.value))
				empty_fields += "\n        " + "Name";
		}
		if (e.type == "textarea") {
			
				if ((e.value == null) || (e.value == "") || isblank(e.value) || (e.value == "Please type in your message here"))
				empty_fields += "\n        " + "Message";
		}
	if (e.name == "Old_email") {
			if (!isEmail(e.value))
				errors += "- The old address you provided is not a valid e-mail address " + "\n\n";

				if ((e.value == null) || (e.value == "") || isblank(e.value))
				empty_fields += "\n        " + "Old Email Address";

		}
		if (e.name == "New_email") {
			if (!isEmail(e.value))
				errors += "- The new address you provided is not a valid e-mail address " + "\n\n";

				if ((e.value == null) || (e.value == "") || isblank(e.value))
				empty_fields += "\n        " + "New Email Address";

}
if (e.name == "artitle") {
			

				if ((e.value == null) || (e.value == "") || isblank(e.value))
				empty_fields += "\n        " + "Article Title";

}
if (e.name == "date1x") {
			

				if ((e.value == null) || (e.value == "") || isblank(e.value))
				empty_fields += "\n        " + "Article Date";

}
if (e.name == "arfile") {
	if (!isblank(e.value)){
	var t = e.value.toLowerCase();
	var tsuf = t.indexOf('.xml');
	if(tsuf == -1)
		errors += "- The article must be in xml format prior to uploading " + "\n\n";
		}
				if ((e.value == null) || (e.value == "") || isblank(e.value))
				empty_fields += "\n        " + "Upload Article";

}
if (e.name == "pdffile") {
	if (!isblank(e.value)){
	var t = e.value.toLowerCase();
	var tsuf = t.indexOf('.pdf');
	if(tsuf == -1)
		errors += "- The article must be in pdf format prior to uploading " + "\n\n";
		}
				if ((e.value == null) || (e.value == "") || isblank(e.value))
				empty_fields += "\n        " + "Upload PDF";

	}
	}
		if (!empty_fields && !errors) {
		return true;
	}

	msg =  "*************************************************************************\n";
	msg += " Your request was not submitted because of the following error.\n";
	msg += " Please correct the error and re-submit.\n";
	msg +=  "*************************************************************************\n\n";

	if (empty_fields) {
		msg += "- The following mandatory field(s) are empty: \n"
					+ empty_fields + "\n\n";
	}
	if (errors) {
		 msg += errors + "\n\n";
	}
	alert(msg);
	return false;
}


// Remove Spaces
function ignoreSpaces(string) {
var temp = "";
string = '' + string;
splitstring = string.split(" ");
for(i = 0; i < splitstring.length; i++)
temp += splitstring[i];
return temp;
}
