function Refresh()

{
var text = "/portal.nsf/(prnextall)?OpenAgent";
document.qbody.action = text;
document.qbody.method="POST";
document.qbody.submit();
}

function Defaults()

{var dtf; var monf; var datestr; dateName = new Date();
 dtf = dateName.getDate(); if (dtf<10) {datestr="0"+dtf+".";} else {datestr=dtf+".";}
 monf = dateName.getMonth()+1; if (monf<10) {datestr=datestr+"0"+monf;} else {datestr=datestr+monf;}
 if (dateName.getYear()>1000 | dateName.getYear()<100) {datestr=datestr+"."+dateName.getYear();} else {datestr=datestr+"."+(1900+dateName.getYear());}
document.qbody.dat0.value=datestr;

dtf = dateName.getHours(); if (dtf<10) {datestr="0"+dtf+":";} else {datestr=dtf+":";}
monf = dateName.getMinutes(); if (monf<10) {datestr=datestr+"0"+monf;} else {datestr=datestr+monf;}
document.qbody.tim0.value=datestr;

}


function RSym (let0)
{
if (let0=='а')
   return '\u0430';
if (let0=='б')
   return '\u0431';
if (let0=='в')
   return '\u0432';
if (let0=='г')
   return '\u0433';
if (let0=='д')
   return '\u0434';
if (let0=='е')
   return '\u0435';
if (let0=='ж')
   return '\u0436';
if (let0=='з')
   return '\u0437';
if (let0=='и')
   return '\u0438';
if (let0=='й')
   return '\u0439';
if (let0=='к')
   return '\u043a';
if (let0=='л')
   return '\u043b';
if (let0=='м')
   return '\u043c';
if (let0=='н')
   return '\u043d';
if (let0=='о')
   return '\u043e';
if (let0=='п')
   return '\u043f';
if (let0=='р')
   return '\u0440';
if (let0=='с')
   return '\u0441';
if (let0=='т')
   return '\u0442';
if (let0=='у')
   return '\u0443';
if (let0=='ф')
   return '\u0444';
if (let0=='х')
   return '\u0445';
if (let0=='ц')
   return '\u0446';
if (let0=='ч')
   return '\u0447';
if (let0=='ш')
   return '\u0448';
if (let0=='щ')
   return '\u0449';
if (let0=='ъ')
   return '\u044a';
if (let0=='ы')
   return '\u044b';
if (let0=='ь')
   return '\u044c';
if (let0=='э')
   return '\u044d';
if (let0=='ю')
   return '\u044e';
if (let0=='я')
   return '\u044f';
if (let0=='А')
   return '\u0410';
if (let0=='Б')
   return '\u0411';
if (let0=='В')
   return '\u0412';
if (let0=='Г')
   return '\u0413';
if (let0=='Д')
   return '\u0414';
if (let0=='Е')
   return '\u0415';
if (let0=='Ж')
   return '\u0416';
if (let0=='З')
   return '\u0417';
if (let0=='И')
   return '\u0418';
if (let0=='Й')
   return '\u0419';
if (let0=='К')
   return '\u041a';
if (let0=='Л')
   return '\u041b';
if (let0=='М')
   return '\u041c';
if (let0=='Н')
   return '\u041d';
if (let0=='О')
   return '\u041e';
if (let0=='П')
   return '\u041f';
if (let0=='Р')
   return '\u0420';
if (let0=='С')
   return '\u0421';
if (let0=='Т')
   return '\u0422';
if (let0=='У')
   return '\u0423';
if (let0=='Ф')
   return '\u0424';
if (let0=='Х')
   return '\u0425';
if (let0=='Ц')
   return '\u0426';
if (let0=='Ч')
   return '\u0427';
if (let0=='Ш')
   return '\u0428';
if (let0=='Щ')
   return '\u0429';
if (let0=='Ъ')
   return '\u042a';
if (let0=='Ы')
   return '\u042b';
if (let0=='Ь')
   return '\u042c';
if (let0=='Э')
   return '\u042d';
if (let0=='Ю')
   return '\u042e';
if (let0=='Я')
   return '\u042f';
return let0;
}


function RUtf(textfrom)  
{
if (textfrom.length>0) 
   {var result; var i;
    var n = textfrom.length;
    result="";
    while (n>0) {             
          result=result+RSym(textfrom.substring(0,1));
          textfrom=textfrom.substring(1,n);
          n=n-1;
          }
    return result; 
    }
else
   return "";
}


function RHSym (let0)
{
if (let0=='\u0430')
   return '^01';
if (let0=='\u0431')
   return '^02';
if (let0=='\u0432')
   return '^03';
if (let0=='\u0433')
   return '^04';
if (let0=='\u0434')
   return '^05';
if (let0=='\u0435')
   return '^06';
if (let0=='\u0436')
   return '^07';
if (let0=='\u0437')
   return '^08';
if (let0=='\u0438')
   return '^09';
if (let0=='\u0439')
   return '^10';
if (let0=='\u043a')
   return '^11';
if (let0=='\u043b')
   return '^12';
if (let0=='\u043c')
   return '^13';
if (let0=='\u043d')
   return '^14';
if (let0=='\u043e')
   return '^15';
if (let0=='\u043f')
   return '^16';
if (let0=='\u0440')
   return '^17';
if (let0=='\u0441')
   return '^18';
if (let0=='\u0442')
   return '^19';
if (let0=='\u0443')
   return '^20';
if (let0=='\u0444')
   return '^21';
if (let0=='\u0445')
   return '^22';
if (let0=='\u0446')
   return '^23';
if (let0=='\u0447')
   return '^24';
if (let0=='\u0448')
   return '^25';
if (let0=='\u0449')
   return '^26';
if (let0=='\u044a')
   return '^27';
if (let0=='\u044b')
   return '^28';
if (let0=='\u044c')
   return '^29';
if (let0=='\u044d')
   return '^30';
if (let0=='\u044e')
   return '^31';
if (let0=='\u044f')
   return '^32';
if (let0=='\u0410')
   return '^33';
if (let0=='\u0411')
   return '^34';
if (let0=='\u0412')
   return '^35';
if (let0=='\u0413')
   return '^36';
if (let0=='\u0414')
   return '^37';
if (let0=='\u0415')
   return '^38';
if (let0=='\u0416')
   return '^39';
if (let0=='\u0417')
   return '^40';
if (let0=='\u0418')
   return '^41';
if (let0=='\u0419')
   return '^42';
if (let0=='\u041a')
   return '^43';
if (let0=='\u041b')
   return '^44';
if (let0=='\u041c')
   return '^45';
if (let0=='\u041d')
   return '^46';
if (let0=='\u041e')
   return '^47';
if (let0=='\u041f')
   return '^48';
if (let0=='\u0420')
   return '^49';
if (let0=='\u0421')
   return '^50';
if (let0=='\u0422')
   return '^51';
if (let0=='\u0423')
   return '^52';
if (let0=='\u0424')
   return '^53';
if (let0=='\u0425')
   return '^54';
if (let0=='\u0426')
   return '^55';
if (let0=='\u0427')
   return '^56';
if (let0=='\u0428')
   return '^57';
if (let0=='\u0429')
   return '^58';
if (let0=='\u042a')
   return '^59';
if (let0=='\u042b')
   return '^60';
if (let0=='\u042c')
   return '^61';
if (let0=='\u042d')
   return '^62';
if (let0=='\u042e')
   return '^63';
if (let0=='\u042f')
   return '^64';
return let0;
}


function RHex(textfrom)  
{
if (textfrom.length>0) 
   {var result; var i;
    var n = textfrom.length;
    result="";
    while (n>0) {             
          result=result+RHSym(textfrom.substring(0,1));
          textfrom=textfrom.substring(1,n);
          n=n-1;
          }
    return result; 
    }
else
   return "";
}


function QSend()

{ 
Defaults();

var text = "/portal.nsf/(priemnaya)?OpenAgent"; var text0 = "";

text0 = document.qbody.name1.value;

text0=RHex(text0);
if (QEmpty(text0)==1)
   { alert(RUtf("Напишите Вашу фамилию! ")); document.qbody.name1.focus();
     return false;
   }   

text = text + "&name1="+text0;

text0 = document.qbody.name2.value;
text0 = RHex(text0);

if (QEmpty(text0)==1)
   { alert(RUtf("Напишите Ваше имя! ")); document.qbody.name2.focus();
     return false;
   }  

text = text + "&name2="+text0;

text0 = document.qbody.name3.value;
text0 = RHex(text0);

if (QEmpty(text0)==1)
   { alert(RUtf("Напишите Ваше отчество! ")); document.qbody.name3.focus();
     return false;
   }  

text = text + "&name3="+text0;

text0 = document.qbody.email.value;
text0 = RHex(text0);

text = text + "&email="+text0;

text0 = document.qbody.address.value;
text0 = RHex(text0);

if (QEmpty(text0)==1)
   { alert(RUtf("Напишите Ваш почтовый адрес! ")); document.qbody.address.focus();
     return false;
   }
text = text + "&address=" + text0;

text0 = document.qbody.phone.value;
text0 = RHex(text0);

text = text + "&phone="+text0;

text0 = document.qbody.where.value;
text0 = RHex(text0);
if (QEmpty(text0)==1)
   { alert(RUtf("Напишите адресата - кому направить Ваш вопрос! "));      document.qbody.where.focus();
     return false;
   }
text = text + "&where=" + text0;

text0 = document.qbody.ident.value;
text0 = RHex(text0);

if (QEmpty(text0)==1)
   { alert(RUtf("Введите цифры, которые Вы видите на картинке! "));      document.qbody.ident.focus();
     return false;
   }
text = text + "&ident=" + text0;

// text = text + "&file="+document.qbody.fname.value;

text = text + "&date="+document.qbody.dat0.value;
text = text + "&time="+document.qbody.tim0.value;

var text1=document.qbody.question.value;
text1 = RHex(text1);

var lng=text1.length;
if (lng>700)
   { alert(RUtf("Ваш запрос слишком длинный и будет сокращен, отредактируйте его при необходимости")); document.qbody.question.focus();
     document.qbody.question.value=text1.substring(0,699);
     return false;
   }
else
   {
   if (QEmpty(text1)==1)
      { alert(RUtf("Введите текст Вашего запроса! ")); document.qbody.question.focus();
        return false;
      }
   }   
      
text1=QReplace(text1);
text = text + "&question="+text1;

document.qbody.action = text;
document.qbody.method="POST";
document.qbody.submit();
}


function QReplace(QText) {
var start = 0; var end = QText.length, QText1 = "";
    while (start<end) {     
               if (QText.substring(start,start+1)<=" ")
                   { QText1 = QText1 + "^99"; }
               else  
                  { QText1 = QText1+ QText.substring(start,start+1); }
                  ++start;                                                               
                  }
return QText1;
}

function QEmpty(QText) {
var start = 0; var end = QText.length; var let="";
    while (start<end) { let = QText.substring(start,start+1);
               if (let>="a" && let<="z")
                  return 0;
               if (let>="A" && let<="Z")
                  return 0;
               if (let>=RSym("А") && let<=RSym("Я"))
                  return 0;
               if (let>=RSym("а") && let<=RSym("я"))
                  return 0;
               if (let>="0" && let<="9")
                  return 0;
               start=start+1;
                  }
return 1;
}


function QStrtran(QText,Qfrom,Qto)  {                   
                                    if (QText.length>0) { 
                                        var start = QText.indexOf(Qfrom);
                                        var end = QText.length;
                                        while (start!=-1) {              
                                              if (start>0) {
                                                        if (start<end) 
                                                           {QText = QText.substring(0,start)+Qto+QText.substring(start+1,end);}
                                                        else                                                                                              
                                                           {QText = QText.substring(0,end)+Qto;}
                                                        }
                                              else
                                                 {QText = Qto+QText.substring(1,end);}
                                        start = QText.indexOf(Qfrom);
                                        end = QText.length;                                                                   
                                                         }
                                                 }
                                    return QText;
                                    }


