//<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
// JavaScript Document
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function field_correct(id,wrongVal,msg)
{ //alert(id);
	if(document.getElementById(id).value == wrongVal) { //alert(id);
		alert(msg);
		document.getElementById(id).focus();
		return false;
	}
	return true;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function dubfield_correct(id,wrongVal,id2,wrongVal2,msg)
{ //alert(id);
	if (!document.getElementById(id2)) return field_correct(id,wrongVal,msg);
	if(document.getElementById(id).value==wrongVal && document.getElementById(id2).value==wrongVal2) {
		alert(msg);
		document.getElementById(id).focus();
		return false;
	}
	return true;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function code_correct(id1,id2,msg)
{
	var str=document.getElementById(id2).value;
	var tmp=""; var j=0; var codeChar="a";
	for (i=0; i<str.length; i++) 
		if (str.charAt(i)!="0") { //alert(str.charCodeAt(i));
			tmp+=str.charCodeAt(i)-codeChar.charCodeAt(0); 
		}
//	alert(document.getElementById(id1).value); alert(tmp);
	if(document.getElementById(id1).value != tmp) {
		alert(msg);
		document.getElementById(id1).focus();
		return false;
	}
	return true;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function pass_correct(id1,id2,msg)
{
//	alert(document.getElementById(id1).value); alert(tmp);
	if(document.getElementById(id1).value != document.getElementById(id2).value) {
		alert(msg);
		document.getElementById(id1).focus();
		return false;
	}
	return true;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function check_email(id)
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(!filter.test(document.getElementById(id).value))
	{
		alert('Некорректный адрес электронной почты');
		document.getElementById(id).focus();
		return false;
	}
	return true;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function check_form(nameList, wrongList, msgList)
{
	nameArr=nameList.split("^,^"); 
	wrongArr=wrongList.split("^,^")
	msgArr=msgList.split("^,^")
	n=msgArr.length; //alert(n);
	
	if(!code_correct('keystr','key','Значение кода введено неверно!')) return false;
//	if(!pass_correct('prsnPass','prsnPass1','Пароль не совпадает с дублирующим полем!')) return false;
	for(i=0; i<n; i++) { //alert(nameArr[i]);
		if (wrongArr[i]!="•••Выбрать•••") {
			if(!field_correct(nameArr[i],wrongArr[i],msgArr[i])) return false;
		}
		else {
			if(!dubfield_correct(nameArr[i],wrongArr[i],nameArr[i]+"1","",msgArr[i])) return false;
		}
	}
	//alert(forName);
	return true;
}
