// JavaScript Document


function validateFormOnSubmit(theForm) {
var reason = "";
  reason += validateEmpty(theForm.name, "Name");
  reason += validatePhone(theForm.telephone);
  reason += validateEmail(theForm.email);
  reason += validateEmpty(theForm.comments, "Comments");
  
  if (reason != "") {
    alert("Some fields need your attention:\n" + reason);
    return false;
  }
  return true;
}
function validateEmpty(fld, name) {
    var error = "";
 
    if (fld.value.length == 0) {
        error = "- The "+name+" field cannot be empty\n"
    } else {}
    return error;  
}

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}
function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        error = "- The email field cannot be empty\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        error = "- Enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        error = "- Enter a valid email address.\n";
    } else {}
    return error;
}
function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "- The telephone field cannot be empty\n";
    } else if (isNaN(parseInt(stripped))) {
        error = "- Enter a valid telephone number.\n";
    }else {}
    return error;
}

/////////////////////////////////////////////////////////////////////////////////

function validateFormOnSubmit2(theForm) {
var reason = "";
  reason += validateEmpty2(theForm.name, "Όνομα");
  reason += validateEmpty2(theForm.lastname, "Επώνυμο");
  reason += validateEmpty2(theForm.address, "Διεύθυνση");
  reason += validatePhone2(theForm.phone, "Τηλέφωνο");
  reason += validatePhone2(theForm.tk, "Τ.Κ.");
  reason += validateEmail2(theForm.email);
  
  if (reason != "") {
    alert("Μερικά πεδία χρειάζονται διόρθωση:\n" + reason);
    return false;
  }
  return true;
}
function validateEmpty2(fld, name) {
    var error = "";
 
    if (fld.value.length == 0) {
        error = "- Το πεδίο "+name+" είναι υποχρεωτικό\n"
    } else {}
    return error;  
}

function trim2(s)
{
  return s.replace(/^\s+|\s+$/, '');
}
function validateEmail2(fld) {
    var error="";
    var tfld = trim2(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        error = "- Το πεδίο email είναι υποχρεωτικό\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        error = "- Εισάγετε ένα έγκυρο email.\n";
    } else if (fld.value.match(illegalChars)) {
        error = "- Εισάγετε ένα έγκυρο email.\n";
    } else {}
    return error;
}
function validatePhone2(fld, name) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "- Το πεδίο "+name+" είναι υποχρεωτικό\n";
    } else if (isNaN(parseInt(stripped))) {
        error = "- Εισάγετε ένα έγκυρο "+name+".\n";
    }else {}
    return error;
}

/////////////////////////////////////////////////////////////////



function validateFormOnSubmit3(theForm) {
var reason = "";
  reason += isChecked(theForm.terms);
  reason += validateEmpty3(theForm.card_holder, "Δικαιούχος Κάρτας");
  reason += validatePhone3(theForm.card_number, "Αριθμός Κάρτας");
  reason += validatePhone3(theForm.ccv, "CCV");
  
  if (reason != "") {
    alert("Μερικά πεδία χρειάζονται διόρθωση:\n" + reason);
    return false;
  }
  return true;
}
function validateEmpty3(fld, name) {
    var error = "";
 
    if (fld.value.length == 0) {
        error = "- Το πεδίο "+name+" είναι υποχρεωτικό\n"
    } else {}
    return error;  
}


function validatePhone3(fld, name) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "- Το πεδίο "+name+" είναι υποχρεωτικό\n";
    } else if (isNaN(parseInt(stripped))) {
        error = "- Εισάγετε ένα έγκυρο "+name+".\n";
    }else {}
    return error;
}

function isChecked(fld) {
	var error = "";
	if (fld.checked == false) {
        error = "- Πρέπει να αποδεχτείτε τους όρους χρήσης\n"
    } else {}
    return error;
}
/////////////////////////////////////////////////////

function acceptTerms() {
	var check = document.getElementById('check');
	var button = document.getElementById('button2');
	
	if(check.checked == true) {
		button.disabled = false;	
	}
	else {
		button.disabled = true;
	}
}
///////////////////////////////////////////////////////////////











