/*##############################################################################
Contest form check
##############################################################################*/

//functie care verifica formularul de trimitere
function checkChestionar() {	
	var checkEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var err = false;
	var str = '';
	
	if($('#nume').val().length<1) {
		err=true;
		text = LANG == 'ro' ? 'Nu ati introdus numele' : 'Please enter the name';
		str+='<li>'+text+'!</li>';
	}
	if(!checkEmail.test($('#email').val())) {
		err=true;
		text = LANG == 'ro' ? 'Adresa de email este incorecta' : 'Wrong email address';
		str+='<li>'+text+'!</li>';
	}
	if($('#telefon').val().length<1) {
		err=true;
		text = LANG == 'ro' ? 'Nu ati introdus numarul de telefon' : 'Please enter the phone number';
		str+='<li>'+text+'!</li>';
	}
	if($('#adresa').val().length<1) {
		err=true;
		text = LANG == 'ro' ? 'Nu ati introdus adresa' : 'Please enter the address';
		str+='<li>'+text+'!</li>';
	}
	if(!$('#i11').attr('checked')&&!$('#i12').attr('checked')&&!$('#i13').attr('checked')&&!$('#i14').attr('checked')) {
		err=true;
		text = LANG == 'ro' ? 'Nu ati raspuns la prima intrebare' : 'Please answer the first question';
		str+='<li>'+text+'!</li>';
	}
	if(!$('#i21').attr('checked')&&!$('#i22').attr('checked')&&!$('#i23').attr('checked')&&!$('#i24').attr('checked')) {
		err=true;
		text = LANG == 'ro' ? 'Nu ati raspuns la a doua intrebare' : 'Please answer the second question';
		str+='<li>'+text+'!</li>';
	}
	if(!$('#i31').attr('checked')&&!$('#i32').attr('checked')&&!$('#i33').attr('checked')&&!$('#i34').attr('checked')) {
		err=true;
		text = LANG == 'ro' ? 'Nu ati raspuns la a treia intrebare' : 'Please answer the third question';
		str+='<li>'+text+'!</li>';
	}
	if(!$('#i41').attr('checked')&&!$('#i42').attr('checked')&&!$('#i43').attr('checked')&&!$('#i44').attr('checked')) {
		err=true;
		text = LANG == 'ro' ? 'Nu ati raspuns la a patra intrebare' : 'Please answer the fourth question';
		str+='<li>'+text+'!</li>';
	}
	if(!$('#i51').attr('checked')&&!$('#i52').attr('checked')&&!$('#i53').attr('checked')&&!$('#i54').attr('checked')) {
		err=true;
		text = LANG == 'ro' ? 'Nu ati raspuns la a cincea intrebare' : 'Please answer the fifth question';
		str+='<li>'+text+'!</li>';
	}
	if(!$('#i61').attr('checked')&&!$('#i62').attr('checked')&&!$('#i63').attr('checked')&&!$('#i64').attr('checked')) {
		err=true;
		text = LANG == 'ro' ? 'Nu ati raspuns la a şasea intrebare' : 'Please answer the sixth question';
		str+='<li>'+text+'!</li>';
	}
	if(!$('#i71').attr('checked')&&!$('#i72').attr('checked')&&!$('#i73').attr('checked')&&!$('#i74').attr('checked')) {
		err=true;
		text = LANG == 'ro' ? 'Nu ati raspuns la a şaptea intrebare' : 'Please answer the seventh question';
		str+='<li>'+text+'!</li>';
	}
	if($('#i81').val()==0||$('#i82').val()==0||$('#i83').val()==0||$('#i84').val()==0||$('#i85').val()==0) {
		err=true; 
		text = LANG == 'ro' ? 'Nu ati ales raspunsurile la a opta intrebare' : 'Please select the eight question`s answers';
		str+='<li>'+text+'!</li>';
	}

	if (!err) {
		$('#contestDataForm').submit();
	} else {
		$('#wrongData').html(str);
		$('#wrongData').parent().parent().show();
		$('#wrongData').slideDown('fast');
		$('html, body').animate({scrollTop: 400}, "fast");
	}
}

$('document').ready(function() {
	// listen to form submission
	$('#submitContestData').click(function() {
		checkChestionar();
	});
});