function submitthisform($FormId,$ListOfFields,$Type,$ErrorBackground)
{

		$ArrayOfFields=$ListOfFields.split(",");

		$Error=0;
		if(!$ErrorBackground) $ErrorBackground="#fff";
		for($i=0;$i>-1;$i++)
		{
			if(!$ArrayOfFields[$i]) break;
			$Doesnt=$ArrayOfFields[$i].split("!");

			if($Doesnt[1])
			{
				$Id=$FormId+$ArrayOfFields[$i].replace("!"+$Doesnt[1],"");
				$Item=document.getElementById($Id).value;
				if($Item=="" | $Item==$Doesnt[1]) {$Error=1; document.getElementById($Id).style.backgroundColor=$ErrorBackground; }
			}
			else
			{
				$Item=document.getElementById($FormId+$ArrayOfFields[$i]).value;
				if($Item=="") {$Error=1;document.getElementById($FormId+$ArrayOfFields[$i]).style.backgroundColor=$ErrorBackground; }
			}
		}

		//------------ ИСКЛЮЧИТЕЛЬНЫЕ ПРОВЕРКИ



		if($Type && $Error==0)
		{
			$Type=$Type.split(":");
			if($Type[0]=="ajax")
			{
				$FormElements=document.getElementById($FormId);
				$ps="";
				for($i=0;$i<$FormElements.length;$i++)
				{
					$ps=$ps+$FormElements.elements[$i].id+"="+$FormElements.elements[$i].value+"&";
				}
				$ps=$ps+"ajax=1";

				post_data =$ps;
				loadHTML('POST','index.php', post_data, $Type[1]);

			}
		}
		else if($Error==0)
		{

			document.getElementById($FormId).submit();
		}

}

function submitthisform_msg($FormId,$ListOfFields,$Type,$ErrorBackground)
{
		$ArrayOfFields=$ListOfFields.split(",");
		$Error=0;
		$Message_Empty="Это поле обязательно для заполнения";
		$Message_EmptyPhoto="Выберите фотографию";
		if(!$ErrorBackground) $ErrorBackground="#fff1f1";
		for($i=0;$i>-1;$i++)
		{

			if(!$ArrayOfFields[$i]) break;
			$Doesnt=$ArrayOfFields[$i].split("!");

			if($Doesnt[1])
			{
				$Id=$FormId+$ArrayOfFields[$i].replace("!"+$Doesnt[1],"");
				$Item=document.getElementById($Id).value;
				if($Item=="" | $Item==$Doesnt[1]) {$Error=1; document.getElementById($Id).style.border=$ErrorBackground; }
			}
			else
			{
				$Item=document.getElementById($FormId+$ArrayOfFields[$i]).value;
				if($FormId+$ArrayOfFields[$i]=="photochangeformphoto") $Message_Empty=$Message_EmptyPhoto;
				if($Item=="")
				{
					$Error=1;
					document.getElementById($FormId+$ArrayOfFields[$i]).style.backgroundColor=$ErrorBackground;
					document.getElementById($FormId+$ArrayOfFields[$i]+"errormessage").innerHTML=$Message_Empty;
					document.getElementById($FormId+$ArrayOfFields[$i]+"errormessage").className="error";
				}
				else
				{
					if(document.getElementById($FormId+$ArrayOfFields[$i]+"errormessage"))document.getElementById($FormId+$ArrayOfFields[$i]+"errormessage").innerHTML="";;
				}
			}
		}

		//  -------------------- ИСКЛЮЧЕНИЯ
		if($FormId)
		{
			if(document.getElementById($FormId+"pass"))
			{
				if(document.getElementById($FormId+"pass").value!=document.getElementById($FormId+"pass2").value)
				{
					$Error=1;
					document.getElementById($FormId+"pass2").style.backgroundColor=$ErrorBackground;
					document.getElementById($FormId+"pass2"+"errormessage").innerHTML="Пароли не совпадают";
					document.getElementById($FormId+"pass2"+"errormessage").className="error";
				}
			}
			if(document.getElementById($FormId+"email"))
			{
				$Email=document.getElementById($FormId+"email").value;
				$EmailSplit=$Email.split(".");

				if(!$Email.match("@") || !$EmailSplit[1])
				{
					$Error=1;
					document.getElementById($FormId+"email").style.backgroundColor=$ErrorBackground;
					document.getElementById($FormId+"email"+"errormessage").innerHTML="Неправильный формат электронной почты";
					document.getElementById($FormId+"email"+"errormessage").className="error";
				}
			}
		}
		if($Type && $Error==0)
		{
			$Type=$Type.split(":");
			if($Type[0]=="ajax")
			{

				$FormElements=document.getElementById($FormId);
				$ps="";
				for($i=0;$i<$FormElements.length;$i++)
				{
					if($FormElements.elements[$i].id!="email_show" & $FormElements.elements[$i].id!="phone_show" &$FormElements.elements[$i].id!="sname_show")
					{
						$ps=$ps+$FormElements.elements[$i].id+"="+$FormElements.elements[$i].value+"&";
					}
					if($FormElements.elements[$i].id=="phone_show")
					{
						$Checked=$FormElements.elements[$i].checked;
						if($Checked)	$ps=$ps+$FormElements.elements[$i].id+"="+$FormElements.elements[$i].value+"&";
						else	$ps=$ps+$FormElements.elements[$i].id+"=0&";
					}
					if($FormElements.elements[$i].id=="email_show")
					{
						$Checked=$FormElements.elements[$i].checked;
						if($Checked)	$ps=$ps+$FormElements.elements[$i].id+"="+$FormElements.elements[$i].value+"&";
						else	$ps=$ps+$FormElements.elements[$i].id+"=0&";
					}
					if($FormElements.elements[$i].id=="sname_show")
					{
						$Checked=$FormElements.elements[$i].checked;
						if($Checked)	$ps=$ps+$FormElements.elements[$i].id+"="+$FormElements.elements[$i].value+"&";
						else	$ps=$ps+$FormElements.elements[$i].id+"=0&";
					}
				}
				$ps=$ps+"ajax=1";

				post_data=$ps;
				loadHTML('POST','index.php', post_data, $Type[1]);
				if($FormId=="passwordchangeform") clearthisform('passwordchangeform');

			}
		}
		else if($Error==0)
		{

			document.getElementById($FormId).submit();
		}

}

function clearthisform($FormId,$ClearOnly)
{
	$FormElements=document.getElementById($FormId);
	for($i=0;$i<$FormElements.length;$i++)
	{
		if($FormElements.elements[$i].type!="button") $FormElements.elements[$i].value="";
		//if($FormElements.elements[$i].type!="button") $FormElements.elements[$i].style.backgroundColor="#fff";
	}
}


function form_errors($Id,$Message)
{
	$ErrorBackground="#fff1f1";
	if(document.getElementById($Id)) document.getElementById($Id).style.backgroundColor=$ErrorBackground;
	if(document.getElementById($Id+"errormessage")) document.getElementById($Id+"errormessage").innerHTML=$Message;
	if(document.getElementById($Id+"errormessage")) document.getElementById($Id+"errormessage").className="error";
}



function cleantypo($Content)
{
	for($i=0;$i>-1;$i++)
	{
		if($Content.match("&nbsp;") || $Content.match("<nobr>") || $Content.match("</nobr>"))
		{
			$Content=$Content.replace("&nbsp;"," ");
			$Content=$Content.replace("<nobr>","");
			$Content=$Content.replace("</nobr>","");
		}
		else break;
	}
	return $Content;
}


