var ym_msg = ['Store №'];
Preload();

function Preload()
	{
	newimg = new Array();
	for(var i=0;i<5;i++)
		{
		newimg[i] = new Image();
		}
	newimg[0].src = '/images/e11.png';
	newimg[1].src = '/images/e22.png';
	newimg[2].src = '/images/e33.png';
	newimg[3].src = '/images/e44.png';
	newimg[4].src = '/images/e55.png';
	}



function CheckForm(id)
	{
    var uForm  = document.getElementById(id);
	if(uForm){
    for (var i=0; i < uForm.length; i++)
				{
				var labelTxt  =  GetLabelByEl(uForm,GetAttr(uForm[i],'id'));
				if(GetAttr(uForm[i],'validate') =='text' && CheckEmptyField(uForm[i]) == 0)
					{
					alert("Field "+labelTxt+" must be not empty!");
					uForm[i].focus();
					return;
					}
				 else if((GetAttr(uForm[i],'validate') =='latin' || uForm[i].getAttribute('validate') =='pass') && CheckLatin(uForm[i]) == 0)
				 	{
					uForm[i].focus();
				     return 0;
					}
				else if(GetAttr(uForm[i],'validate') =='num' && CheckNumField(uForm[i],1) == 0)
				 	{
					alert("Field "+labelTxt+" must be numeric!");
					uForm[i].focus();
				     return 0;
					}
				else if(GetAttr(uForm[i],'validate') =='float' && CheckNumField(uForm[i]) == 0)
				 	{
					alert("Field "+labelTxt+" must be number");
					uForm[i].focus();
				     return 0;
					}
				else if(GetAttr(uForm[i],'validate') =='email' && CheckEmail(uForm[i]) == 0)
				 	{
					alert("Field "+labelTxt+" is not filled correctly");
					uForm[i].focus();
				    return 0;
					}
				}
    //проверка товара
    var check_prod = 0;
    for(i=1;i<5;i++)
    	{
    	var prod = ById('prod_list_'+i);
    	var cnt  = ById('product_'+i);
        if(prod && cnt && CheckEmptyField(prod) &&  CheckNumField(cnt,1)){
        	check_prod = 1;
        	break;
        	}
    	}
     if(check_prod)
     	{
     	//проверка доставки
        var delivery  = ById('delivery_type');
        if(delivery){
            if(delivery.checked)
            	{
            	  var dest = ById('delivery_store');
            	  if(!dest || dest.value < 1){
	            	  alert('Select a warehouse for EX!');
	            	  return;
            	  }
            	}
            else{
                var dest = ById('dev_adress');
                if(!dest || CheckEmptyField(dest) == 0){
                	alert('Enter delivery address!');
	            	return;
                	}
            	}
          }
     	 var phone = ById('u_phone');
	     var email = ById('u_email');
	     if(phone && email){
	             var labelTxtph  =  GetLabelByEl(uForm,GetAttr(phone,'id'));
	             var labelTxtem  =  GetLabelByEl(uForm,GetAttr(email,'id'));
	             if(CheckEmail(email) == 0 && CheckEmptyField(phone) == 0){
	             	 alert("One of the fields: "+labelTxtph+" или "+labelTxtem+" must be not empty!");
	             	return 0;
	             	}
	      }
     	  uForm.submit();
     	}
     else alert('Select products to order and specify the quantity!');
	}
  }

