//////

function Validator() { 

	var Name = document.getElementById('Name').value;
	var Type0 = document.FormReg.Type[0];
	var Department = document.getElementById('Department').value;
	var Hospital = document.getElementById('Hospital').value;
	var Country = document.getElementById('Country').value;
	var Email = document.getElementById('Email').value;

	// Check necessary inputs 
	var helperMsg = "";
	if(Name == 0) helperMsg = helperMsg + "Name\n";
	if((Type0.checked) && (Department == 0)) helperMsg = helperMsg + "Department\n";
	if((Type0.checked) && (Hospital == 0)) helperMsg = helperMsg + "Hospital/Institution\n";
	if(Country == 0) helperMsg = helperMsg + "Country\n";
	if(Email == 0) helperMsg = helperMsg + "Email\n";

	if (helperMsg.length) {
		helperMsg = "Please insert:\n\n" + helperMsg;
		alert (helperMsg);
		return false;
	};

	// Checking OK
	document.getElementById("FormReg").submit();

};

function ValidateEmail() { 

	var Email = document.getElementById('Email').value;

	// Checking OK
	if (Email.indexOf("@") > 0) {
		document.getElementById("Form").submit();
		return true;
	};

	// Checking Wrong
	helperMsg = "Please insert a valid email address";
	alert (helperMsg);
	return false;
};

function countwords(x) {

	var text = x.value;
	var r = 0;
	var cadena = text.replace(/\s/g,' ');
	cadena = cadena.split(' ');
	for (z=0; z<cadena.length; z++) 
		if (cadena[z].length > 0) r++;
	return r;
};

function ValidateContent() { 

	var Title = document.getElementById('Title').value;

	// Check necessary inputs 
	var helperMsg = "";
	if(Title == 0) helperMsg = helperMsg + "Title\n";

	if (helperMsg.length) {
		helperMsg = "Please insert:\n\n" + helperMsg;
		alert (helperMsg);
		return false;
	};

	// Count words 
	var words = 0;
	words = words + countwords(document.getElementById('Purpose'));
	words = words + countwords(document.getElementById('Materials'));
	words = words + countwords(document.getElementById('Results'));
	words = words + countwords(document.getElementById('Conclusions'));

	if ((words<200) || (words>400)) {
		helperMsg = "The abstract should have between 200 and 400 words. And now it has: " + words;
		alert (helperMsg);
		return false;
	};

	// Checking OK
	document.getElementById("Form").submit();

};

function ValidateAbstract4() { 

	var Corresponding = document.getElementById('Corresponding').value;

	var extensok = new Array(".gif", ".jpg", ".png");
	var Figure = new Array(3);
	Figure[1]= document.getElementById('Figure1').value;
	Figure[2] = document.getElementById('Figure2').value;
 
	// Checking the figures
	var okFig = false;
 	var helperMsg = "";
    	for (var n = 1; n <= 2; n++) {
		var dotFig = Figure[n].lastIndexOf(".");
		if( dotFig != -1 ) {
			okFig = false;
			var extension = Figure[n].substr(dotFig,Figure[n].length);
			extension = extension.toLowerCase();  
	      		for (var i = 0; i < extensok.length; i++) {
	         		if (extensok[i] == extension) {
	         			okFig = true;
	         			break;
	         		};
			};
			if (okFig == false) helperMsg = helperMsg + "The extension of Fig." + n + " is incorrect\n\n";		
		};
	};

	// Check necessary inputs 
	if(Corresponding == 0) helperMsg = helperMsg + "Please insert:\tCorresponding author\n";

	if (helperMsg.length) {
		alert (helperMsg);
		return false;
	};

	// Checking OK
	document.getElementById("Form").submit();

};



