<!-- Begin
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if(init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function CheckReportForm(){
    if (document.report.phone.value.length==0 || document.report.month.value.length==0) return false;
    if (!clearPeriod(document.report.fromD.value,document.report.toD.value)) return false;

    var v1,v2;

    if (document.report.fromD.value.length>0 || document.report.toD.value.length>0){
    if (document.report.fromD.value.length==0) document.report.fromD.value ="01";
    if (document.report.fromD.value>document.report.toD.value) document.report.toD.value=document.report.fromD.value;
    if (document.report.fromD.value.length==1) document.report.fromD.value='0'+document.report.fromD.value;
    if (document.report.toD.value.length==1) document.report.toD.value='0'+document.report.toD.value;
    var ddcc = document.report.month.value;
    document.report.ddcc.value = ddcc.substr(0,7);
}
  if(document.report.cntRows.value < 10 || document.report.cntRows.value > 200){
     alert("Броят редове на страница може да бъде от 10 до 200 !!!");
     document.report.cntRows.focus();
     return false;
  }

    document.report.page.value = 1;
    document.report.rownum.value =  0;
    document.report.pg.value =  0;
    document.report.end.value =  document.report.cntRows.value;
    document.report.submit();
}

function convertDateBill(par){
var mes = new Array('','Януари','Февруари','Март','Април','Май','Юни','Юли','Август','Септември','Октомври','Ноември','Декември');
var ind = parseInt(par.substr(5,2),10);
    if (ind>0 && ind<13){
//        alert(mes[ind]+", "+par.substr(0,4));
        return (mes[ind]+", "+par.substr(0,4));
        }
    else {
//        document.bill.temp.value="bill_noinf.html";
//        document.bill.submit();
        }
      }

function ReplDst(par){
    document.report.phone.value = par;
    document.report.submit();

    }


function convertDate(par){
var mes = new Array('','Януари','Февруари','Март','Април','Май','Юни','Юли','Август','Септември','Октомври','Ноември','Декември');

var ind = parseInt(par.substr(5,2),10);
 //   if (par.substr(0,4)>2006)  return (mes[12]+", 2006");
    if (ind>0 && ind<13) return (mes[ind]+", "+par.substr(0,4));
    else return("");
    }

function convertDate800(par){
var mes = new Array('','Януари','Февруари','Март','Април','Май','Юни','Юли','Август','Септември','Октомври','Ноември','Декември');

var ind = parseInt(par.substr(5,2),10);
    if (ind>0 && ind<13) return (mes[ind]+", "+par.substr(0,4));
    else return("");
    }


function convertDateP(par){
var mes = new Array('','Януари','Февруари','Март','Април','Май','Юни','Юли','Август','Септември','Октомври','Ноември','Декември');

var ind = parseInt(par.substr(0,2),10)-1;
var yy = parseInt(par.substr(3,4),10);
       if (ind==0) {ind=12; yy = yy-1;}
    return (mes[ind]+", "+yy);
    }

function convertDateEmi(par,par1){
    if (par1=="0"){
    var dt = convertDateP(par);
    return dt;
        }
var mes = new Array('','Януари','Февруари','Март','Април','Май','Юни','Юли','Август','Септември','Октомври','Ноември','Декември');

var ind = parseInt(par.substr(4,2),10);
var yy = parseInt(par.substr(0,4),10);
    return (mes[ind]+", "+yy);
    }


function clearSP(parin){
var paro = "";
for (i=0;i<parin.length;i++){
    a=parin.substr(i,1);
if (a > " ") paro = paro+a;
    }
    return(paro);
    }

function receiveSelectDate(par){
    for (i=0; i<document.report.phone.length; i++){
     if (document.report.phone[i].value==par) {
         document.report.phone.selectedIndex=i;
            }
         }
     return(convertDate(document.report.month.value));

    }

function receiveSelectPhone(){
     return(document.report.phone.value);
    }

function beginReport(){    //alert("beginReport");
    if (document.report.conditions.value!="") return(true);
var cnd = "";
    if (document.report.phone.type!="hidden") document.report.phone.selectedIndex=0;
    return(document.report.phone.value);
    }

function calcRow(){
  if (document.report.rownum.value=="") document.report.rownum.value="0";
  var c = parseInt(document.report.rownum.value,10);
      c = c + 1;
      document.report.rownum.value = c;
      return(c);
    }

function posPage(par){
    var step   = parseInt(document.report.cntRows.value,10);
//    step = step * par;
    document.report.pg.value = step * par;
//    document.report.end.value = step * par + step;
    document.report.rownum.value =  step * par;
    par = par + 1;
    document.report.page.value = par;
    document.report.submit();
    }

function secTOTime(par){
    var h,m,s;
    var sec   = parseInt(par,10);
    if (sec>=3600) {
        h = parseInt(sec/3600,10);
        sec = sec - (h * 3600);
        }
        else h = "0";
    if (sec>=60) {
        m = parseInt(sec / 60,10);
        sec = sec - (m * 60);
    }
    else m = "0"
    var hh,mm,ss;
    if (h<10)   hh = "0"+h; else hh = h;
    if (m<10)   mm = "0"+m; else mm = m;
    if (sec<10) ss = "0"+sec; else ss = sec;
   if (hh>0) return(hh+":"+mm+":"+ss);
   else return(mm+":"+ss);
}

function sortVPN(par){
        if (par=="stat"){
        document.report.temp.value="reference_vpngraph.html";
        document.report.period.value = convertDate(document.report.month.value);
        document.report.submit();
        return false;
        }

//    var sa = new Array('date_call','pc','pi','ph','date_call','dr','am','kc');
    var sa = new Array('date_call','phone_call','phone_inet','phone','date_call','duration','amount','kind_call');
    if (document.report.sort.value == sa[par]) document.report.sort.value = document.report.sort.value + ' DESC';
    else document.report.sort.value = sa[par];
    document.report.sort1.value = sa[par];
    document.report.page.value = 1;
    document.report.rownum.value =  0;
    document.report.end.value = document.report.cntRows.value;
    document.report.pg.value =  0;
    CheckReportForm();
    }

function sortHOME(par){
//    var sa = new Array('date_call','pc','date_call','dr','im','kc');
    var sa = new Array('date_call','phone_call','date_call','duration','impuls','kind_call');
    if (document.report.sort.value == sa[par]) document.report.sort.value = document.report.sort.value + ' DESC';
    else document.report.sort.value = sa[par];
    document.report.sort1.value = sa[par];
    document.report.page.value = 1;
    document.report.rownum.value =  0;
    document.report.end.value = document.report.cntRows.value;
    document.report.pg.value =  0;
    CheckReportForm();
    }
function sort78(par){
    var sa = new Array('date_call','phone_call','date_call','duration','amount','kind_call');
//    var sa = new Array('date_call','pc','date_call','dr','am','kc');
    if (document.report.sort.value == sa[par]) document.report.sort.value = document.report.sort.value + ' DESC';
    else document.report.sort.value = sa[par];
    document.report.sort1.value = sa[par];
    document.report.page.value = 1;
    document.report.rownum.value =  0;
    document.report.end.value = document.report.cntRows.value;
    document.report.pg.value =  0;
    document.report.submit();
    }

function clN(str){
var page = document.report.page.value;
   document.report.page.value = str;
   str = document.report.page.value;
   document.report.page.value = page;
  var suma = 0;
   var l = 0;
   l=str.length;
   if (l==0) return(suma);
   for (k=0; k<l; k++){
   c=str.charAt(k);
   if (c=="." || c==",") {
   suma = str.substr(0,k+3);
   return(suma);
          }
        }
return(str);
}

function NewCondition(){
   document.report.conditions.value="";
   document.report.conditions1.value="";
   document.report.temp.value="reference_details.html";
    document.report.submit();
    }
    
function CheckReportFormS(s){   //alert("CheckReportFormS");
    var cond = "";
    if (s=="f") cond = cond+" phone='"+document.report.phone.value+"'";
    if (s=="m") cond = cond+" phone='"+document.report.phone.value+"' and to_char(r.nominal_bill_date,'yyyy-mm')='"+document.report.month.value+"'";
    document.report.conditions.value=cond;
    document.report.temp.value="reference_detailsselect.html";
  document.report.submit();
    }

function PrintData(par){
                         document.p.period.value = convertDate(document.report.month.value);
    if (par=='x'){       document.p.temp.value = 'downloadreport'+document.report.ku.value+'.tmpl';
                         document.p.download.value = 'report.xls';
    }
    if (par=='t'){       document.p.temp.value = 'downloadreport0'+document.report.ku.value+'.tmpl';
                         document.p.download.value = 'report.txt';
    }
    if (par=='a'){       document.p.temp.value = 'downloadreporta'+document.report.ku.value+'.tmpl';
                         document.p.download.value = 'report.txt';
    }
    if (par!='t' && par!='x' && par!='a') document.p.temp.value = 'main.html';
//    alert("print_data"+document.p.phone.value+document.p.month.value);
    document.p.submit();
}

function PrintData800(par){
                         document.p.period.value = convertDate800(document.report.month.value);
    if (par=='x'){       document.p.temp.value = 'downloadreport'+document.report.ku.value+'.tmpl';
                         document.p.download.value = 'report.xls';
    }
    if (par=='t'){       document.p.temp.value = 'downloadreport0'+document.report.ku.value+'.tmpl';
                         document.p.download.value = 'report.txt';
    }
    if (par=='a'){       document.p.temp.value = 'downloadreporta'+document.report.ku.value+'.tmpl';
                         document.p.download.value = 'report.txt';
    }
    if (par!='t' && par!='x' && par!='a') document.p.temp.value = 'main.html';
//    alert("print_data"+document.p.phone.value+document.p.month.value);
    document.p.submit();
}


function PrintGraph(){
  document.report.temp.value = 'reference_graph.html';
  document.report.submit();
}

function DownFile(par,par1){
    document.pp.temp.value = "downloadreport"+par+".tmpl"
    document.pp.download.value = "report"+par1;
    document.pp.period.value = convertDate(document.pp.month.value);
//    alert(document.pp.period.value+'='+document.pp.month.value);
  document.pp.submit();
}


function CheckReportBill(){
  document.f.submit();
    }

function countROW(){
   var inn = parseInt(document.report.rownum.value,10);
   inn = inn + 1;
   document.report.rownum.value = inn;
   return(inn);
    }

function convPeriod(m){
  var day = m.substr(5,2)+"."+m.substr(0,4);
  return(day);
    }

function findLastDay(m){
  var mes = new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
  var day = m.substr(5,2);
  var y = parseInt(day,10);
  if (y>0 && y<13) return(mes[y]);
  else return("");
    }

function convPeriodNext(m){
  var mes = new Array('','01','02','03','04','05','06','07','08','09','10','11','12');
  var day = m.substr(5,2);
  var yy  = m.substr(0,4);
  day = parseInt(day,10) + 1;
  if (day==13) {
  day = 1;
  yy = parseInt(yy,10) + 1;
        }

  if (day>0 && day<13) yy =  mes[day]+"."+yy;
  else yy="";
  return(yy);
 }


function convPeriodPay(m){
  var mes = new Array('','01','02','03','04','05','06','07','08','09','10','11','12');
  var mm = m.substr(5,2);
  var yy  = m.substr(0,4);
  mm = parseInt(mm,10) + 1;
  if (mm==13) {
  mm = 1;
  yy = parseInt(yy,10) + 1;
        }
  if(mm>0 && mm<13) ; else mm = 0;
  if (mm==2) mm = "28."+mes[mm]+"."+ yy;
  else mm = "29."+mes[mm]+"."+ yy;
  return(mm);
 }

function clearPeriod(m,n){

  var mes1 = new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
  var mes = document.report.month.value;

  var mm = parseInt(mes.substr(5,2),10);

  var yy = mes.substr(0,4);
  if (mm==2 && yy%4==0) mes1[2] = 29;
  if (n > mes1[mm])  document.report.toD.value=mes1[mm];

    if (m.length>0 || n.length>0){
    if(!parseInt(m,10) || !parseInt(n,10)){
          alert("Въведете верен интервал!");
     return false;
      }
    if (parseInt(m,10)<1 || parseInt(m,10)>31){
          alert("Въведете верен интервал!");
     return false;
        }
    if (parseInt(n,10)<1 || parseInt(n,10)>31){
          alert("Въведете верен интервал!");
     return false;
        }
    if (parseInt(m,10) > parseInt(n,10)){
          alert("Въведете верен интервал!");
     return false;
        }
     }
  return true;
}

function PgInit(){
 document.report.code.focus();
 history.go(+1);
 return true;
}

function convertNOMBill(par){
var mes = new Array('','Януари','Февруари','Март','Април','Май','Юни','Юли','Август','Септември','Октомври','Ноември','Декември');
var ind = parseInt(par.substr(5,2),10);
var gg  = parseInt(par.substr(0,4),10);
    if (ind>1 && ind<13) return (mes[ind-1]+", "+ par.substr(0,4));
    if (ind==1) {
        gg = gg - 1;
        return (mes[12]+","+gg);
        }
    else return("");
    }
    
function additionalINF(){
    document.report.temp.value = "additional_inf"+document.report.ku.value+".html";
    document.report.submit();
    }

function ClearForm(){
    document.report.code.value = "";
    document.report.phone.value = "";
    document.report.pak.value = "";
    }

function downloadPDF(pdffl){
    document.f.download.value = pdffl;
    document.f.submit();
    }

function downloadPDFE(pdffl,fl)
{
    MM_showHideLayers('Layer5','','show');
    document.ff.download.value = pdffl;
    if(fl=='255') document.ff.temp.value="download_pdfen5.tmpl";
    if(fl=='131') document.ff.temp.value="download_pdfen.tmpl";
    if(fl=='249') document.ff.temp.value="download_pdfnew.tmpl";
//    document.ff.submit();
}

function STAT(par1,stt){
    if (!stt) return false;
     var par3 = stt.substr(0,1);
     var par4 = stt.substr(1,10);
     var par2 = stt.substr(12,stt.length-11);

//    alert(stt+" serv "+par1+" phone= "+matchArray[1]+" phoneinet= "+matchArray[2]+" type= "+par3+" date= "+par4);
    document.report.temp.value = "reference_details"+par3+".html";
    document.report.month.value = par4;
    document.report.ku.value = par3;
    document.report.rownum.value = 0;
//    if (par3==2) ReplDst(par2);
    document.report.phone.value = par2;
    document.report.dest.value = par2;
//    alert(document.report.temp.value+" -- "+document.report.month.value+" -- "+document.report.phone.value);
    if (par1==2) {
    document.p.temp.value = "downloadreport"+par3+".tmpl";
    document.p.month.value = par4;
    document.p.phone.value = par2;
    document.p.dest.value = par2;
    PrintData800('x');
    return false;
     }
    if (par1==3) {
    document.p.temp.value = "downloadreport"+par3+".tmpl";
    document.p.month.value = par4;
    document.p.phone.value = par2;
    document.p.dest.value = par2;
    PrintData('t');
        return false;
        }
//     alert(document.p.temp.value+" -- "+document.p.month.value+" -- "+document.p.phone.value);
    document.report.submit();
    }
    
    function writeLy(name,mx,sum){
//    alert(ar);
document.write('<DIV id=Layer style="Z-INDEX: 3; left: 541; VISIBILITY: hidden; OVERFLOW: hidden; WIDTH: 360px; POSITION: absolute; TOP: 154px; HEIGHT: 180px" bgcolor=#FFFFFF>');
document.write('<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0><TBODY><TR><TD bgColor=#ffccaa>');
document.write('<TABLE cellSpacing=1 cellPadding=3 width="100%" border=0>');
document.write('<TBODY><TR bgColor=#fff4e1><TD>За <B>');
document.write(name+"</B>&nbsp;</TD></TR>");
document.write("<TR bgColor=#f8f8e8><TD>&nbsp;<B>Брой разговори&nbsp;</B></TD><TD><B>Сума</B></TD></TR>");
document.write("<TR bgColor=#f8f8e8><TD>");
//mx = myArrSum[ar];
sx = parseFloat(mx/sum*100);
sx = parseInt(sx,10);
document.write(sx+"%</B>&nbsp; от общия брой&nbsp;("+sum+")</TD></TR>");
if (is==0) mx=0; else mx = parseInt(mx/is*100,10);
document.write("<TR bgColor=#f8f8e8><TD>&nbsp;<B>");
if (mx<101) document.write(mx+"%&nbsp; от междуселищните");
document.write("</B></TD></TR></TBODY></TABLE></TR></TBODY></TABLE></DIV>");
}

//  End -->
