function check_and_submit(theForm)
{
 var why = "";

 why += checkStringGR(theForm.firstname.value,"Όνομα");
 why += checkStringGR(theForm.lastname.value,"Επώνυμο");
 why += checkStringGR(theForm.company.value,"Φορέας");
 why += checkStringGR(theForm.dept.value,"Τμήμα");
 why += checkStringGR(theForm.position.value,"Ιδιότητα/Θέση");
 

 why += checkStringGR(theForm.streetno.value,"Οδός/Αριθμός");
/* why += checkZipCodeGR(theForm.zip.value,"ΤΚ");*/
 why += checkStringGR(theForm.city.value,"Πόλη");

 why += checkEmailGR(theForm.email.value);
 why += checkPhoneGR(theForm.phone.value,"Τηλέφωνο");
 why += checkFaxGR(theForm.fax.value, "Fax");
 

 if (why != "") {
 alert(why);
 return false;
 }
 theForm.submit();
}

/*---------------------------------------------------------------------*/

function checkZipCodeGR(strng, field)
{

    var error = "";
    if (strng == "")
    {
         error = "Το πεδίο '"+field+"' είναι υποχρεωτικό.\n";
    }
    else{

	// Check for correct zip code
         reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
         if (!reZip.test(strng)) {
             error = "Η μορφή του '"+field+"' δεν είναι έγκυρη.\n";
         }	
    }
    return error
}
/*---------------------------------------------------------------------*/

function checkStringGR (strng, field)
{
 var error = "";
 if (strng == "")
 {
 error = "Το πεδίο '"+field+"' είναι υποχρεωτικό.\n";
 }

 if (strng.length < 1)
 {
 error = "Το πεδίο '"+field+"' είναι υποχρεωτικό.\n";
 }

 /*var illegalChars = /\W/;
 // allow only letters, numbers, and underscores
 if (illegalChars.test(strng))
 {
 error = "Το πεδίο "+field+" περιέχει μη επιτρεπτούς χαρακτήρες.\n";
 }*/

 return error
}

/*---------------------------------------------------------------------*/

function checkEmailGR(strng)
{
 var error = "";
 var emailFilter=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
 if (!(emailFilter.test(strng)))
 {
 error = "Η μορφή του E-mail δεν είναι έγκυρη.\n";
 }
 var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
 if (strng.match(illegalChars))
 {
 error = "Το E-mail περιέχει μη επιτρεπτούς χαρακτήρες.\n";
 }
 if (strng == "")
 {
 error = "Το πεδίο E-mail είναι υποχρεωτικό.\n";
 }
 return error
}

/*---------------------------------------------------------------------*/

function checkPhoneGR(strng,field)
{
 var error = "";
 var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
 //strip out acceptable non-numeric characters
 if (isNaN(parseInt(stripped)))
 {
 error = "Το πεδίο "+field+" περιέχει μη επιτρεπτούς χαρακτήρες.\n";
 }
 if (stripped.length<10)
 {
 error = "Το πεδίο '"+field+"'  πρέπει να αποτελείται απο τουλάχιστον 10 ψηφία.\n";
 }
 return error
}


function checkFaxGR(strng,field)
{
 var error = "";
 var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
 //strip out acceptable non-numeric characters
 if (isNaN(parseInt(stripped)) && stripped.length>0)
 {
 error = "Το πεδίο "+field+" περιέχει μη επιτρεπτούς χαρακτήρες.\n";
 }
 return error
}


function checkDropdown(choice,field) {
 var error = "";
 if ((choice == 0 && field == "organization type") || (choice == -1 && field == "research interest")) {
 error = "You didn't choose an option from the " + field + " list.\n";
 }
return error;
}

function check_position()
{
 s = document.getElementById('member_position_id')
 if (s.options[s.options.length-1].selected)
 document.getElementById('member_position_other').disabled = false
 else
 document.getElementById('member_position_other').disabled = true

}

function check_country()
{
 s = document.getElementById('member_country_id')
 if (s.options[s.options.length-1].selected)
 document.getElementById('member_country_other').disabled = false
 else
 document.getElementById('member_country_other').disabled = true

}

function check_domain()
{
 s = document.getElementById('member_domain_id')
 if (s.options[s.options.length-1].selected)
 document.getElementById('member_domain_other').disabled = false
 else
 document.getElementById('member_domain_other').disabled = true

}
