String.prototype.trim = function() { //metoda trim
   return this.replace(/(^\s*)|(\s*$)/g, "")
}

function checkEmail(email) { //kontrola e-mail
    re = /^[^.]+(\.[^.]+)*@([^.]+[.])+[A-Za-z]{2,}$/;
    return email.search(re) == 0;
}

function checkForm() { //kontrola formulare - pridat fotku
   var msg = '';
   if (window.document.getElementById('jmeno').value.trim().length < 1) msg += '- jméno\n';
   if (!checkEmail(window.document.getElementById('email').value)) msg += '- e-mail\n';
   if (window.document.getElementById('nazev').value.trim().length < 1) msg += '- název snímku\n';
   if (window.document.getElementById('datum').value.trim().length < 1) msg += '- datum snímku\n';
   if (window.document.getElementById('misto').value.trim().length < 1) msg += '- místo snímku\n';
   if (window.document.getElementById('typ').value.trim().length < 1) msg += '- typ hodinek\n';
   
   var ext = window.document.getElementById('fotka').value
   ext = ext.substring(ext.lastIndexOf('.'), ext.length);
   ext = ext.toLowerCase();
   if ((ext != ".jpg") && (ext != ".jpeg")) msg += '- fotka ve správném formátu\n';
   
   if (msg.length != 0) {
	   alert('Nebyly vyplněny tyto položky:\n' + msg);
	   return false;
   } else {
	   return true;
   }
}

function checkFormHlas() { //kontrola formulare - hlasovani
   var msg = '';
   if ((parseInt(window.document.getElementById('id').value) < 1) || (isNaN(parseInt(window.document.getElementById('id').value)))) msg += '- ID fotografie\n';
   if (!checkEmail(window.document.getElementById('email2').value)) msg += '- e-mail\n'; 
   if (msg.length != 0) {
	   alert('Nebyly vyplněny tyto položky:\n' + msg);
	   return false;
   } else {
	   return true;
   }
}
