function eCheckEMail(sn){
		s= sn.value;
		if (s.indexOf("@") == -1) return false;
		if (s.indexOf(".") == -1) return false;
		at=false;
		dot=false;
		for (var i = 0; i < s.length; i++) {
				ch = s.substring(i, i + 1)
				if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z")
								|| (ch == "@") || (ch == ".") || (ch == "_")
								|| (ch == "-") || (ch >= "0" && ch <= "9")) {
								if (ch == "@"){
									if (at) return false;
									else at=true;
								}
								if ((ch==".") && at)
									 dot=true;
				}
				else return false;
		}
	 return dot;
}

function CheckEMail(theForm){
//	 for(var i=1; i<CheckEMail.arguments.length; i++) {
				 if (!eCheckEMail(theForm.EMAIL)){
						alert("Невалиден email!");
						theForm.EMAIL.focus();
						return false;
				}
//	 }
	 return true;
}


function eCheckAlpha(sn){
		s= sn.value;
		for (var i = 0; i < s.length; i++) {
				ch = s.substring(i, i + 1)
				if (!((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z")))
						 return false;
				}
	 return true;
}

function CheckPass(theForm){
	s1= theForm.PASSWORD.value;
	s2= theForm.PASSWORD2.value;
	if (s1==s2) return true;
	alert("Паролите не съвпадат. Въведете ги отново!");
	return false;
}


function CheckAlpha(theForm){
	 for(var i=1; i<CheckAlpha.arguments.length; i++)
				 if (!eCheckAlpha(theForm.elements[CheckAlpha.arguments[i]])){
						alert("Невалидни данни!");
						theForm.elements[CheckAlpha.arguments[i]].focus();
						return false;
				}
	 return true;
}

function CheckRequiredFields(theForm)
{
	 for(i=1; i<CheckRequiredFields.arguments.length; i++) {
//				alert(i+"-- "+theForm.elements[CheckRequiredFields.arguments[i]].value);
				if(theForm.elements[CheckRequiredFields.arguments[i]].value==""){
						alert("Непопълнено поле!");
						theForm.elements[CheckRequiredFields.arguments[i]].focus();
						return false;
				}
	 }
	 return true;
}

function CheckForm(theForm){
		 if(CheckRequiredFields(theForm, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11))
		 //if(CheckAlpha(theForm,  0, 1, 2))
		 if(CheckEMail(theForm))
		 if(CheckPass(theForm))
					return true;
	return false;
}
