var setTimeOut=false;

checkedFields=new Array('input1_1','input1_2','input1_3','input1_5');//defines array of fields to be checked
compulsaryFields=new Array('input1_1','input1_2','input1_3','input1_5');//defines array of compulsory fields
arr_alerts=new Array('נעשה שימוש בסימנים אסורים. אנא נסו שוב, ללא שימוש בסימני פיסוק.','כתובת אי-מייל שגוייה.','אנא מלא/י את כל השדות.');
/*var invalidChars =  "/:,;~!#$%^&*)(][}{+=><?\\";*/
var invalidChars =  ";~!#$^&][}{><";


function submitForm(obj){
	
	var ErrorFlag=false;
	var emptyfield=false;
	var badcharFound=false;
	var badMail=false;
	var str='';
	for(i=0;i<checkedFields.length;i++){
		for (i2=0; i2<invalidChars.length; i2++) {	// does it contain any invalid characters?
			badChar = invalidChars.charAt(i2);
			if (badcharFound==false && eval('obj.'+checkedFields[i]+'.value').indexOf(badChar,0) > -1) {
				badcharFound=true;
				ErrorFlag=true;
				str+="<br>"+arr_alerts[0];
			}
		}
		if(eval('obj.'+checkedFields[i]+'.value')==""){
			ErrorFlag=true;
			
			if(emptyfield==false){
				str+="<br>"+arr_alerts[2];
			}
			emptyfield=true;
		}	
		if(checkedFields[i]=="input1_2"){ //email
			email=eval('obj.'+checkedFields[i]+'.value');
			if (email == "") {						// cannot be empty
				badMail=true;
			}
			atPos = email.indexOf("@",1)			// there must be one "@" symbol
			if (atPos == -1) {
				badMail=true;
			}
			if (email.indexOf("@",atPos+1) != -1) {	// and only one "@" symbol
				badMail=true;
			}
			periodPos = email.indexOf(".",atPos)
			if (periodPos == -1) {					// and at least one "." after the "@"
				badMail=true;
			}
			if (periodPos+3 > email.length)	{		// must be at least 2 characters after the "."
				badMail=true;
			}
			if(badMail==true){
				ErrorFlag=true;
				str+="<br><br>"+arr_alerts[1];
			}
		}
		
	}
	if(ErrorFlag==true){
		
		document.getElementById('LayerAlert').innerHTML = str;
		document.getElementById('LayerAlert').style.display="block";
		setTimeout("makeVanish('LayerAlert')",3000);
		return(false);
	}else{
			
		document.getElementById('LayerAlert').innerHTML = "שולח טופס";
		document.getElementById('LayerAlert').style.display="block";
		setTimeout("makeVanish('LayerAlert')",1500);
		document.form1.submit();
		return(true);
	}
}
function makeVanish(obj){
	document.getElementById(obj).style.display="none";
}
function makeSuccess(obj){
	document.getElementById('alert').style.display="block";
	setTimeout("makeVanish('alert')",5000);
}
