function upload_pics(tc_id, pic_num, real_pic_id, pic_comment)
{
    var but=document.getElementById("upload_button_"+tc_id);
    if(real_pic_id)
    {
        add_pic_cell(tc_id, real_pic_id, pic_comment);
    }
    uploaded_cnt[tc_id]++;
    if(pic_num>1) document.forms["upload_form_"+tc_id+"_"+(pic_num-1)].reset();
    else
    {
        var num=0;
        for(i=1;i<=pics_cnt_in_class;i++)
            if(document.forms["upload_form_"+tc_id+"_"+i].pic_file.value!='') num++;
        if(num==0)
        {
            alert("Выберите картинки");
            return;
        }
        need_upload_cnt[tc_id]=num;
        uploaded_cnt[tc_id]=0;
    }
    while(pic_num<=pics_cnt_in_class && document.forms["upload_form_"+tc_id+"_"+pic_num].pic_file.value=='') pic_num++;
    if(pic_num-1==pics_cnt_in_class)
    {
        but.disabled=false;
        but.value="Загрузить фото";
        return;
    }
    else
    {
        but.disabled=true;
        but.value="Загружено "+uploaded_cnt[tc_id]+" из "+need_upload_cnt[tc_id];
        document.forms["upload_form_"+tc_id+"_"+pic_num].submit();
    }
}



 function IsEMail(str) {       
    if ((str.indexOf ("@", 0) != -1) && (str.indexOf (".", 0) != -1))
    {
      i = str.length - str.lastIndexOf (".") - 1 ;
      if ( (str.indexOf ("@", 0) == 0) || (str.indexOf (".", 0) == 0) )
        return 0;
      if ( str.indexOf("@", 0) != str.lastIndexOf("@", str.length) )
        return 0;
      if (i && (i <= 3))
        return 1 ;
    }
    return 0 ;
  }

/*  Form add story  */      
function FSubmitStory(form) {      
   
  var Fields = form.login;
  var str = new String(Fields.value);    
  if ((str == "") || (str == "undefined")) {
     window.alert('Вы не ввели имя.');
     Fields.focus(); return 1;
  }
 
  var Fields = form.email;
  var str = new String(Fields.value);  
  if (str != "") 
    if (!IsEMail(str)) {
      window.alert('Укажите правильный E-Mail адрес.');
      Fields.focus();
      return 1;
    }  
  if ((str == "") || (str == "undefined"))  {
    window.alert('Пустое поле email.\n\n');
    Fields.focus();
    return 1;
 }

 var Fields = form.message;
  var str = new String(Fields.value);
  if ((str == "") || (str == "undefined")) {
    window.alert('Пустое поле комментария.\n\n');
    Fields.focus();
    return 1;
  } 
 var Fields = form.secretcode;
  var str = new String(Fields.value);
  if ((str == "") || (str == "undefined")) {
    window.alert('Пустое поле - код.\n\n');
    Fields.focus();
    return 1;
  } 
  return 100;                    
}

function checkLen(Text,MaxSymbol,View){
    if(Text.value.length > MaxSymbol){
        Text.value = Text.value.substring(0, MaxSymbol);
        return;
    }
    if(View != "" && View != null) document.getElementById(View).innerHTML = MaxSymbol-Text.value.length;
}

