function isCyrAlpha(ch) {
	var alphabet = "ÀÁÂÃÄÅ¨ÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäå¸æçèéêëìíîïðñòóôõö÷øùúûüýþÿ";
	for(var i=0; i<alphabet.length; i++)
	{
		letter = alphabet.substring(i, i + 1);
		if (ch == letter) return true;
	}
	return false;
}

function eCheckMaskEmail(Elem) {
	s = Elem.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 eCheckMaskUrl(Elem) {
	var res = true;
	var s = Elem.value;
	if (s.indexOf(".") == -1) return false;
	for (var i = 0; i < s.length; i++) {
		ch = s.substring(i, i + 1);
		res = res && ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z")
		|| (ch == ".") || (ch == "_") || (ch == "/") || (ch == ":")
		|| (ch == "-") || (ch >= "0" && ch <= "9"));
	}
	return res;
}

function eCheckMaskAlpha(Elem){
	s = Elem.value;
	for (var i = 0; i < s.length; i++) {
		ch = s.substring(i, i + 1)
		if (!((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z") || isCyrAlpha(ch)))
		 return false;
	}
	return true;
}

function eCheckMaskAlphaNum(Elem){
	s = Elem.value;
	for (var i = 0; i < s.length; i++) {
		ch = s.substring(i, i + 1)
		if (!((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z") || isCyrAlpha(ch) || (ch >= "0" && ch <= "9")))
		 return false;
	}
	return true;
}

function eCheckMaskPhone(Elem){
	s = Elem.value;
	for (var i = 0; i < s.length; i++) {
		ch = s.substring(i, i + 1);
		if (!((ch >= "0" && ch <= "9") || ch=='(' || ch==')' || ch=='-' || ch==' ')) 
			return false;
	}
	return true;
}

function eCheckMaskText(Elem){
	s = Elem.value;
	for (var i = 0; i < s.length; i++) {
		ch = s.substring(i, i + 1);
		if (!((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z") || isCyrAlpha(ch)
		|| (ch >= "0" && ch <= "9") || (ch == ",") || (ch == ".")
		|| (ch == "_") || (ch == "-") || (ch == "(")  || (ch == ")")
		|| (ch == "!") || (ch == "?") || (ch == "#") || (ch == "$")
		|| (ch == " ") || (ch == "\n")))
		return false;
	}
	return true;
}

function eCheckMinMax(Value, MinVal, MaxVal) {
	if (Value < MinVal) return -1;
	if (Value > MaxVal) return 1;
	return 0;
}

/*****************************************/
	/*****************************************/
/*****************************************/

function CheckBounds(theForm, theElem, MinVal, MaxVal)  {	
	elem = dfind(theForm + "_" + theElem);	
	val = elem.value;
	if (val == "" && isRequired(theElem) == false) return true;
	res  = eCheckMinMax(val, MinVal, MaxVal);
	//alert(theElem+":val="+val+", min="+MinVal+", max="+MaxVal+", res="+res);
	if (res > 0) {
		alert("Maximum value exceeded (max. "+MaxVal+")");
		elem.focus();
		return false;
	} else
	if (res < 0) {
		alert("Mininum value required (min. "+MaxVal+")");
		elem.focus();
		return false;
	} else
	return true;
}

function CheckLength(theForm, theElem, MinVal, MaxVal) {
	elem = dfind(theForm + "_" + theElem);	
	val = elem.value;
	if (val == "" && isRequired(theElem) == false) return true;
	res  = eCheckMinMax(val.length, MinVal, MaxVal);
	//alert(theElem+":val="+val.length+", min="+MinVal+", max="+MaxVal+", res="+res);
	if (res > 0) {
		alert("Max string length exceeded (max. "+MaxVal+" chars.)");
		elem.focus();
		return false;
	} else
	if (res < 0) {		
		alert("Min string length is required (min."+MinVal+" chars.)");
		elem.focus();
		return false;
	} else
	return true;
}

function CheckRequiredFields(theForm) {		
	for(i=1; i<CheckRequiredFields.arguments.length; i++) {		
		elem_name = theForm + "_" + CheckRequiredFields.arguments[i];
		elem = dfind(elem_name);
		if(elem.value=="") {
			alert("This field value is required");
			elem.focus();
			return false;
		}
	}
	return true;
}

function CheckAlpha(theForm){
	for(var i=1; i<CheckAlpha.arguments.length; i++) {		
		elem_name = theForm + "_" + CheckAlpha.arguments[i];
		elem = dfind(elem_name);
		if (elem.value == "" && isRequired(CheckAlpha.arguments[i]) == false) return true;
		if (!eCheckMaskAlpha(elem)) {
			alert("Illegal field value");
			elem.focus();
			return false;
		}
	}
	return true;
}

function CheckAlphaNum(theForm) { 
	for(var i=1; i<CheckAlphaNum.arguments.length; i++) {
		elem_name = theForm + "_" + CheckAlphaNum.arguments[i];
		elem = dfind(elem_name);
		if (elem.value == "" && isRequired(CheckAlphaNum.arguments[i]) == false) return true;
		if (!eCheckMaskAlphaNum(elem)) {
			alert("Illegal field value");
			elem.focus();
			return false;
		}
	}
	return true;
}

function CheckText(theForm){
	for(var i=1; i<CheckText.arguments.length; i++) {		
		elem_name = theForm + "_" + CheckText.arguments[i];
		elem = dfind(elem_name);
		if (elem.value == "" && isRequired(CheckText.arguments[i]) == false) return true;
		if (!eCheckMaskText(elem)) {
			alert("Illegal field value");
			elem.focus();
			return false;
		}
	}
	return true;
}

function CheckPhone(theForm) {
	for(var i=1; i<CheckPhone.arguments.length; i++) {		
		elem_name = theForm + "_" + CheckPhone.arguments[i];
		elem = dfind(elem_name);
		if (elem.value == "" && isRequired(CheckPhone.arguments[i]) == false) return true;
		if (!eCheckMaskPhone(elem)) {
			alert("Illegal field value");
			elem.focus();
			return false;
		}
	}
	return true;
}

function CheckEmail(theForm){
	for(var i=1; i<CheckEmail.arguments.length; i++) {		
		elem_name = theForm + "_" + CheckEmail.arguments[i];
		elem = dfind(elem_name);
		if (elem.value == "" && isRequired(CheckEmail.arguments[i]) == false) return true;
		if (!eCheckMaskEmail(elem)) {
			alert("Illegal field value");
			elem.focus();
			return false;
		}
	}
	return true;
}

function CheckUrl(theForm){
	for(var i=1; i<CheckUrl.arguments.length; i++) {		
		elem_name = theForm + "_" + CheckUrl.arguments[i];
		elem = dfind(elem_name);
		if (elem.value == "" && isRequired(CheckUrl.arguments[i]) == false) return true;
		if (!eCheckMaskUrl(elem)) {
			alert("Illegal field value");
			elem.focus();
			return false;
		}
	}
	return true;
}

function test(ch)
{
	//return CheckRequiredFields('employer_register', 'username', 'password');
	return isCyrAlpha(ch);
}


/*****************************************************************************/
// application specific



