   function text (str) { return /[0-9_;:'!~?=+<|>]/g.test(str); }

   function numeric (str) { return /^[0-9-\+\(\)\s]+z/.test(str + "z"); }
  
   function phone (str) { return /^\(\d{3}\)\d{3}-\d{2}-\d{2}$/.test(str); }
   
   function data (str) { return /^\d{1,2}([-. /])\d{1,2}\1\d{2,4}$/.test(str); }
   
   function mail (str) { return /^[-._a-z0-9]+@(?:[a-z0-9][-a-z0-9]+\.)+[a-z]{2,6}$/.test(str); }
   
   function checkForm () 
      {
      var title;
      var elem;
	  var elom;
      var elim;
      var elam;
      var elon;
      var elin;
      var elan;
      var elot;
      var elit;
      var elat;
      var elop;
      var elip;
      var elap;
      var elor;
      var elir;
      var elar;
      var dutyField = "Не заполнено поле ";
      var wrongField = "Неверное значение поля ";
      var check = true;

      function checkError (field, str) 
         {
         document.getElementById("alert").innerHTML = str;
         document.forms.form2.field.focus();
         check = false;
         }

      document.getElementById("alert").innerHTML = "";

      if (check)
         {
         elem = document.form2.marka.value;
         if (elem == 0) checkError('marka', 'Выберите марку автомобиля');
         }
  
      if (check)
         {
         title = '"модель"';
         elem = document.form2.model.value;
         if (elem.length == 0) checkError('model', 'Укажите модель автомобиля: просто впишите название модели');
         }
		 
      if (check)
         {
         elem = document.form2.owner.value;
         if (elem == 0) checkError('owner', 'Укажите владельца автомобиля');
         }
		 
      if (check)
         {
         elem = document.form2.region.value;
         if (elem == 0) checkError('region', 'Укажите регион постановки автомобиля на учет');
         }  
		 
      if (check)
         {
         elem = document.form2.credit.value;
         if (elem == 0) checkError('credit', 'Укажите куплен автомобиль в кредит или нет');
         }  
		 
      if (check)
         {
         elem = document.form2.year.value;
         if (elem == 0) checkError('year', 'Укажите год выпуска автомобиля');
         }
		 
      if (check)
         {
         title = '"пробег"';
         elem = document.form2.distance.value;
         if (elem.length == 0) checkError('distance', 'Укажите пробег, если автомобиль новый, поставьте "0"');
         else if (!numeric(elem)) checkError('distance', wrongField + title);
         }
		 
      if (check)
         {
         title = '"Страховая стоимость"';
         elem = document.form2.insvalue.value;
         if (elem.length == 0) checkError('insvalue', 'Укажите стоимость автомобиля, за которую планируете его страховать');
         else if (elem.length < 6) checkError('insvalue', 'Указана недостаточная стоимость автомобиля');
		 else if (elem.length > 8) checkError('insvalue', 'Указана некорректная стоимость автомобиля');
         else if (!numeric(elem)) checkError('insvalue', wrongField + title);
         }
		 
      if (check)
         {
         title = '"Объем двигателя"';
         elem = document.form2.volume.value;
         if (elem.length == 0) checkError('volume', 'Укажите объем двигателя автомобиля в л.');
         else if (elem.length > 3) checkError('insvalue', 'Некорректно указан объем двигателя');
          }	
		 
      if (check)
         {
         title = '"Мощность двигателя"';
         elem = document.form2.power.value;
         if (elem.length == 0) checkError('power', 'Укажите мощность двигателя автомобиля в л.с.');
		 else if (elem.length > 3) checkError('insvalue', 'Некорректно указана мощность двигателя');
         else if (!numeric(elem)) checkError('power', wrongField + title);
         }	
		 
      if (check)
         {
         elem = document.form2.side.value;
         if (elem == 0) checkError('side', 'Укажите расположение руля');
         }
  		 
      if (check)
         {
         elem = document.form2.drivers.value;
         if (elem == 0) checkError('drivers', 'Укажите количество допущенных водителей');
         }  

      if (check)
         {
         elem = document.form2.drivers.value;
		 elom = document.form2.age1.value;
         elim = document.form2.expirience1.value;
         elam = document.form2.sex1.value;		 
         if (elem == 1 && elom == 0) checkError('age1', 'Укажите возраст Водителя 1');
	else if (elem == 1 && elim == 0) checkError('expirience1', 'Укажите стаж Водителя 1');
	else if (elem == 1 && elam == 0) checkError('sex1', 'Укажите пол Водителя 1');	
         }  	
      if (check)
         {
         elem = document.form2.drivers.value;
		 elom = document.form2.age1.value;
         elim = document.form2.expirience1.value;
         elam = document.form2.sex1.value;		 
         elon = document.form2.age2.value;
         elin = document.form2.expirience2.value;
         elan = document.form2.sex2.value;		
         if (elem == 2 && elom == 0) checkError('age1', 'Укажите возраст Водителя 1');
	else if (elem == 2 && elim == 0) checkError('expirience1', 'Укажите стаж Водителя 1');
	else if (elem == 2 && elam == 0) checkError('sex1', 'Укажите пол Водителя 1');	
	else if (elem == 2 && elon == 0) checkError('age2', 'Укажите возраст Водителя 2');
	else if (elem == 2 && elin == 0) checkError('expirience2', 'Укажите стаж Водителя 2');
	else if (elem == 2 && elan == 0) checkError('sex2', 'Укажите пол Водителя 2');	
         }  
      if (check)
         {
         elem = document.form2.drivers.value;
		 elom = document.form2.age1.value;
         elim = document.form2.expirience1.value;
         elam = document.form2.sex1.value;		 
         elon = document.form2.age2.value;
         elin = document.form2.expirience2.value;
         elan = document.form2.sex2.value;	
         elot = document.form2.age3.value;
         elit = document.form2.expirience3.value;
         elat = document.form2.sex3.value;			 
         if (elem == 3 && elom == 0) checkError('age1', 'Укажите возраст Водителя 1');
	else if (elem == 3 && elim == 0) checkError('expirience1', 'Укажите стаж Водителя 1');
	else if (elem == 3 && elam == 0) checkError('sex1', 'Укажите пол Водителя 1');	
	else if (elem == 3 && elon == 0) checkError('age2', 'Укажите возраст Водителя 2');
	else if (elem == 3 && elin == 0) checkError('expirience2', 'Укажите стаж Водителя 2');
	else if (elem == 3 && elan == 0) checkError('sex2', 'Укажите пол Водителя 2');	
	else if (elem == 3 && elot == 0) checkError('age3', 'Укажите возраст Водителя 3');
	else if (elem == 3 && elit == 0) checkError('expirience3', 'Укажите стаж Водителя 3');
	else if (elem == 3 && elat == 0) checkError('sex3', 'Укажите пол Водителя 3');	
         }  
      if (check)
         {
         elem = document.form2.drivers.value;
		 elom = document.form2.age1.value;
         elim = document.form2.expirience1.value;
         elam = document.form2.sex1.value;		 
         elon = document.form2.age2.value;
         elin = document.form2.expirience2.value;
         elan = document.form2.sex2.value;	
         elot = document.form2.age3.value;
         elit = document.form2.expirience3.value;
         elat = document.form2.sex3.value;	
         elop = document.form2.age4.value;
         elip = document.form2.expirience4.value;
         elap = document.form2.sex4.value;			 
         if (elem == 4 && elom == 0) checkError('age1', 'Укажите возраст Водителя 1');
	else if (elem == 4 && elim == 0) checkError('expirience1', 'Укажите стаж Водителя 1');
	else if (elem == 4 && elam == 0) checkError('sex1', 'Укажите пол Водителя 1');	
	else if (elem == 4 && elon == 0) checkError('age2', 'Укажите возраст Водителя 2');
	else if (elem == 4 && elin == 0) checkError('expirience2', 'Укажите стаж Водителя 2');
	else if (elem == 4 && elan == 0) checkError('sex2', 'Укажите пол Водителя 2');	
	else if (elem == 4 && elot == 0) checkError('age3', 'Укажите возраст Водителя 3');
	else if (elem == 4 && elit == 0) checkError('expirience3', 'Укажите стаж Водителя 3');
	else if (elem == 4 && elat == 0) checkError('sex3', 'Укажите пол Водителя 3');	
	else if (elem == 4 && elop == 0) checkError('age4', 'Укажите возраст Водителя 4');
	else if (elem == 4 && elip == 0) checkError('expirience4', 'Укажите стаж Водителя 4');
	else if (elem == 4 && elap == 0) checkError('sex4', 'Укажите пол Водителя 4');	
         }
      if (check)
         {
         elem = document.form2.drivers.value;
		 elom = document.form2.age1.value;
         elim = document.form2.expirience1.value;
         elam = document.form2.sex1.value;		 
         elon = document.form2.age2.value;
         elin = document.form2.expirience2.value;
         elan = document.form2.sex2.value;	
         elot = document.form2.age3.value;
         elit = document.form2.expirience3.value;
         elat = document.form2.sex3.value;	
         elop = document.form2.age4.value;
         elip = document.form2.expirience4.value;
         elap = document.form2.sex4.value;	
         elor = document.form2.age5.value;
         elir = document.form2.expirience5.value;
         elar = document.form2.sex5.value;			 
         if (elem == 5 && elom == 0) checkError('age1', 'Укажите возраст Водителя 1');
	else if (elem == 5 && elim == 0) checkError('expirience1', 'Укажите стаж Водителя 1');
	else if (elem == 5 && elam == 0) checkError('sex1', 'Укажите пол Водителя 1');	
	else if (elem == 5 && elon == 0) checkError('age2', 'Укажите возраст Водителя 2');
	else if (elem == 5 && elin == 0) checkError('expirience2', 'Укажите стаж Водителя 2');
	else if (elem == 5 && elan == 0) checkError('sex2', 'Укажите пол Водителя 2');	
	else if (elem == 5 && elot == 0) checkError('age3', 'Укажите возраст Водителя 3');
	else if (elem == 5 && elit == 0) checkError('expirience3', 'Укажите стаж Водителя 3');
	else if (elem == 5 && elat == 0) checkError('sex3', 'Укажите пол Водителя 3');	
	else if (elem == 5 && elop == 0) checkError('age4', 'Укажите возраст Водителя 4');
	else if (elem == 5 && elip == 0) checkError('expirience4', 'Укажите стаж Водителя 4');
	else if (elem == 5 && elap == 0) checkError('sex4', 'Укажите пол Водителя 4');	
	else if (elem == 5 && elor == 0) checkError('age5', 'Укажите возраст Водителя 5');
	else if (elem == 5 && elir == 0) checkError('expirience5', 'Укажите стаж Водителя 5');
	else if (elem == 5 && elar == 0) checkError('sex5', 'Укажите пол Водителя 5');	
         } 		 
        if (check)
         {
         title = '"Дата страхования"';
         elem = document.form2.insdata.value;
         if (elem.length == 0) checkError('insdata', dutyField + title);
         else if (!data(elem)) checkError('insdata', 'укажите дату, когда планируете страховать ТС в формате 01/01/2011');
         }		 		 

      if (check)
         {
         elem = document.form2.insperiod.value;
         if (elem == 0) checkError('insperiod', 'Укажите срок, на который планируете страховать автомобиль');
         }  
		 
      if (check)
         {
         elem = document.form2.inshistory.value;
         if (elem == 0) checkError('inshistory', 'Для получения скидки за безубыточность укажите были или нет страховые случаи');
         } 	
		 
      if (check)
         {
         title = '"Ваше имя"';
         elem = document.form2.name.value;
         if (elem.length == 0) checkError('name', dutyField + title);
         else if (text(elem)) checkError('name', wrongField + title);
         }
		      
        if (check)
         {
         title = '"Ваш контактный телефон"';
         elem = document.form2.tel.value;
         if (elem.length == 0) checkError('tel', dutyField + title);
         else if (!phone(elem)) checkError('tel', 'укажите контактный телефон в формате (ххх)ххх-хх-хх');
         }		 
  			 
 
        
      if (check)  { document.form2.submit(); }

      return check;
      }
