var errorMsg1 = "Παρακαλώ συμπληρώστε όλα τα πεδία";

function check_and_submit(){

	//Check if the user has given all the mandatory personal data
	if(!(notEmpty(document.forms[0].libname) && notEmpty(document.forms[0].libunits) && notEmpty(document.forms[0].totalborrownum) && notEmpty(document.forms[0].email) && notEmpty(document.forms[0].libregistrationnumber) && notEmpty(document.forms[0].numberofcopies) && notEmpty(document.forms[0].numberofmembers) && notEmpty(document.forms[0].servingnumber) && notEmpty(document.forms[0].borrownum) ))
	{
		alert(errorMsg1);
		return;
	}   
        else
	{

		if( emailValidator(document.forms[0].email, "Η μορφή του e-mail δεν είναι έγκυρη") == false)
		{
			return;			
		}
	}


document.forms[0].libunits.value = (document.forms[0].libunits.value).replace(".","");
document.forms[0].libregistrationnumber.value=(document.forms[0].libregistrationnumber.value).replace(".","");
document.forms[0].numberofcopies.value=(document.forms[0].numberofcopies.value).replace(".","");
document.forms[0].numberofmembers.value=(document.forms[0].numberofmembers.value).replace(".","");

document.forms[0].servingnumber.value=(document.forms[0].servingnumber.value).replace(".","");
document.forms[0].borrownum.value=(document.forms[0].borrownum.value).replace(".","");
document.forms[0].totalborrownum.value=(document.forms[0].totalborrownum.value).replace(".","");


	document.forms[0].submit();

}

function check_and_submit_ekt_abekt(){

	//Check if the user has given all the mandatory personal data
	if(!(notEmpty(document.forms[0].library) && notEmptyRadio(document.forms[0].past1_promo_autolib) && notEmptyRadio(document.forms[0].past2_rules) && notEmptyRadio(document.forms[0].past3_rec_data) && notEmptyRadio(document.forms[0].past4_pc_familiar) && notEmptyRadio(document.forms[0].past5_tech_support) && notEmptyRadio(document.forms[0].past6_tools) && notEmptyRadio(document.forms[0]. nonce1_abekt) && notEmpty(document.forms[0].nonce2_failures) && notEmptyRadio(document.forms[0].nonce3_helpdesk) && notEmpty(document.forms[0].nonce4_helpdesk_failures) && notEmptyRadio(document.forms[0].nonce5_elearning) && notEmpty(document.forms[0].nonce6_elearning_failures) && notEmpty(document.forms[0].nonce7_quality) ))
	{
		alert(errorMsg1);
		return;
	}   


	document.forms[0].submit();

}

/* Check if the input is empty or not. If yes return false. If no return true */
function notEmpty(elem){
	if(elem.value.length == 0){
		return false;
	}
	return true;
}

/* Check if the input is empty or not. If yes return false. If no return true */
function notEmptyRadio(elem){
	for (var i=0; i < elem.length; i++)
   	{
   		if (elem[i].checked)
      		{
      			var rad_val = elem[i].value;
			return true;	
      		}
   	}

	if(rad_val == undefined){
		return false;
	}
}

/*************************************************/

/* Check if at least one radio button is selected*/
function radioGroupValidation( group, msg ){

	// require at least one radio button be selected
	var radioSelected = false;
	for (i = 0;  i < group.length;  i++)
	{
		if (group[i].checked)
		radioSelected = true;
	}
	if (!radioSelected)
	{
		alert(msg);

		return (false);
	}

}


/*************************************************/

/* Check if the user's email address is valid */
function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		return false;
	}

}

function checkLibrary_submit(){
	if(document.forms[0].library.value != "-1"){
		document.forms[0].submit();
	}
        else{
            alert("Πρέπει να επιλέξετε τη βιβλιοθήκη σας!");
	    return;
        }
}

