
/*
$(document).ready(function(){
  $("#account_show").click(function(){
  $("#account_data_block").show();
   $("#account_show").css({"color":"#fe0000","text-decoration":"underline"});
  });
});*/

function accountShow()
{
document.getElementById("account_messager").style.display="none";
var account_data_block = document.getElementById("account_data_block");
var account_show = document.getElementById("account_show");
if(account_data_block.style.display == "block")
{
$(document).ready(function(){
 
  $("#pass_show").show(500);
  $("#help_show").show(500);
  
});
account_data_block.style.display = "none";
account_show.style.color = "#484848";
account_show.style.hover.color = "#fa0000";

}
else{

account_data_block.style.display = "block";
account_show.style.color = "#fe0000";
account_show.style.textDecoration = "underline";
$(document).ready(function(){
 
  $("#pass_show").hide(500);
  $("#help_show").hide(500);
  
});
}
}


function passShow()
{
document.getElementById("account_messager").style.display="none";
var account_pass_block = document.getElementById("account_pass_block");
var pass_show = document.getElementById("pass_show");
if(account_pass_block.style.display == "block")
{
$(document).ready(function(){
 
  $("#account_show").show(500);
  $("#help_show").show(500);
  
});
account_pass_block.style.display = "none";
pass_show.style.color = "#484848";
pass_show.style.hover.color = "#fa0000";

}
else{

account_pass_block.style.display = "block";
pass_show.style.color = "#fe0000";
pass_show.style.textDecoration = "underline";
$(document).ready(function(){
 
  $("#account_show").hide(500);
  $("#help_show").hide(500);
  
});
}
}


function account_act(item)
{
var e = document.getElementById(item);
//e.className="account_selected";
e.style.background="url(/images/account_pic4.gif) repeat-x";
e.style.cursor="pointer";
}

function account_free(item)
{
var e = document.getElementById(item);
e.style.background="url(/images/account_pic1.gif) repeat-x";
}


function account_arrow_act(item,img_item)
{//alert("fhfgh");
var e = document.getElementById(item);
var img = document.getElementById(img_item);
if(img_item == "arrow_up"){img.src="/images/arrow_up_2.png";}
if(img_item == "arrow_down"){img.src="/images/arrow_down_2.png";}
//e.className="account_selected";
e.style.background="url(/images/account_pic4.gif) repeat-x";
e.style.cursor="pointer";
}

function account_arrow_free(item,img_item)
{
var e = document.getElementById(item);
var img = document.getElementById(img_item);
if(img_item == "arrow_up"){img.src="/images/arrow_up.png";}
if(img_item == "arrow_down"){img.src="/images/arrow_down.png";}
e.style.background="url(/images/account_pic1.gif) repeat-x";
}


function vybor(){


var table=document.getElementById("account_number_table");
	 var x=table.getElementsByTagName("tr");
 /* var ebt=document.getElementById("v1");
  if(ebt){alert('ebt');}*/

for(var i=1;i<x.length;i++){
var h = x[i].id; var ft=h.slice(-(h.length-1));//alert(h.length);
var v = document.getElementById("v"+ft);//alert(ft);
var h = document.getElementById("h"+ft);
var n = document.getElementById("n"+ft);
var t = document.getElementById("t"+ft);
var s = document.getElementById("s"+ft);
var f = document.getElementById("f"+ft);
var m = document.getElementById("m"+ft);
var p = document.getElementById("p"+ft);

if(v.checked)
{h.style.backgroundColor="#8cbe7a";
n.readOnly =false;
t.readOnly =false;
s.readOnly =false;
f.readOnly =false;
m.disabled=false;
//p.readOnly =false;

}
else{h.style.backgroundColor="#cbcbcb";
n.readOnly = true;
t.readOnly = true;
s.readOnly = true;
f.readOnly = true;
p.readOnly = true;
m.disabled=true;
}



}
}


 
  
   function newNumber()
   {
  if(!document.getElementById("h1")){
   var numbers = document.getElementById("selmn");
   var account_number_error  = document.getElementById("account_number_error");
    //account_number_error.style.display="none";
   for (var j=0; j<numbers.options.length; j++) if (numbers.options[j].selected) {
      var table=document.getElementById("account_number_table");
	  
    var trs=table.getElementsByTagName("tr");
     //alert(trs.length);
	  var d=trs.length;
	 i=1;
	 var v ="v"+i; var n="n"+i; var t="t"+i;var s="s"+i;var f="f"+i;var p="p"+i;var h="h"+i;var m="m"+i;
	
	 var input_vybor=document.createElement("input");
	 input_vybor.setAttribute("type","checkbox");
	 input_vybor.setAttribute("id",v);
	input_vybor.setAttribute("onclick","vybor();");
     input_vybor.setAttribute("checked",true);	 
	 
	 var input_appdata=document.createElement("input");
	 input_appdata.setAttribute("type","text");
	 input_appdata.setAttribute("valign","center");
	 input_appdata.style.width="110px";
	 input_appdata.setAttribute("id",n);
	 input_appdata.setAttribute("readonly",true);
	 
	 var input_timeout=document.createElement("input");
	 input_timeout.setAttribute("type","text");
	 input_timeout.style.width="25px";
	 input_timeout.setAttribute("id",t);
	 input_timeout.setAttribute("readonly",true);
	  input_timeout.setAttribute("value","60");
	 
	 var input_start=document.createElement("input");
	 input_start.setAttribute("type","text");
	 input_start.style.width="55px";
	 input_start.setAttribute("id",s);
	 input_start.setAttribute("readonly",true);
	 input_start.setAttribute("value","00:00:00");
	 
	 var input_finish=document.createElement("input");
	 input_finish.setAttribute("type","text");
	 input_finish.style.width="55px";
	 input_finish.setAttribute("id",f);
	 input_finish.setAttribute("readonly",true);
	 input_finish.setAttribute("value","24:00:00");
	   
	 var input_music=document.createElement("select");
	 input_music.style.width="120px";
	 input_music.setAttribute("id",m);
	 input_music.setAttribute("disabled",true);
	 var music_option=document.createElement("option");
      music_option.text='blank';
    try
  {
  input_music.add(music_option,null); // standards compliant
  }
   catch(ex)
  {
  input_music.add(music_option); // IE only
  }
	 
	 
	 var input_priority=document.createElement("input");
	 input_priority.setAttribute("type","text");
	 input_priority.style.width="25px";
	 input_priority.setAttribute("value",trs.length);
	 input_priority.setAttribute("readonly",true);
	 input_priority.setAttribute("id",p);
	 input_priority.style.display="inline";
	 /*input_priority.style.marginRight="4px";*/
	 
	
	 
	 var header = document.createElement("tr");header.setAttribute("id",h);
	 var st_1 = document.createElement("td");st_1.setAttribute("align","center");st_1.style.borderRight = "solid #aaaaaa 1px";st_1.style.borderBottom = "solid #aaaaaa 1px";st_1.style.height = "38px";st_1.style.verticalAlign = "middle";
	 var st_2 = document.createElement("td");st_2.setAttribute("align","center");st_2.style.borderRight = "solid #aaaaaa 1px";st_2.style.borderBottom= "solid #aaaaaa 1px";st_2.style.height = "38px";st_2.style.verticalAlign = "middle";
	 var st_3 = document.createElement("td");st_3.setAttribute("align","center");st_3.style.borderRight = "solid #aaaaaa 1px";st_3.style.borderBottom = "solid #aaaaaa 1px";st_3.style.height = "38px";st_3.style.verticalAlign = "middle";
	 var st_4 = document.createElement("td");st_4.setAttribute("align","center");st_4.style.borderRight = "solid #aaaaaa 1px";st_4.style.borderBottom = "solid #aaaaaa 1px";st_4.style.height = "38px";st_4.style.verticalAlign = "middle";
	 var st_5 = document.createElement("td");st_5.setAttribute("align","center");st_5.style.borderRight = "solid #aaaaaa 1px";st_5.style.borderBottom = "solid #aaaaaa 1px";st_5.style.height = "38px";st_5.style.verticalAlign = "middle";
	 var st_6 = document.createElement("td");st_6.setAttribute("align","center");st_6.style.borderRight = "solid #aaaaaa 1px";st_6.style.borderBottom = "solid #aaaaaa 1px";st_6.style.height = "38px";st_6.style.verticalAlign = "middle";
	 var st_7 = document.createElement("td");st_7.setAttribute("align","center");st_7.style.borderBottom = "solid #aaaaaa 1px";st_7.style.height = "38px";//st_6.style.verticalAlign = "middle";
	 
	
	  st_1.appendChild(input_vybor);
	 st_2.appendChild(input_appdata);
	 st_3.appendChild(input_timeout);
	 st_4.appendChild(input_start);
	 st_5.appendChild(input_finish);
	 st_6.appendChild(input_music);
	 st_7.appendChild(input_priority);
	 
	
	 header.appendChild(st_1);
	 header.appendChild(st_2);
	 header.appendChild(st_3);
	 header.appendChild(st_4);
	 header.appendChild(st_5);
	 header.appendChild(st_6);
     header.appendChild(st_7); 	 
	 table.appendChild(header);
	 
	  
	  vybor();
       }}
   }

  /* function blockNumber()
   {
   var numbers = document.getElementById("selmn");
   var account_number_error  = document.getElementById("account_number_error");
    //account_number_error.style.display="none";
   for (var i=0; i<numbers.options.length; i++) if (numbers.options[i].selected) {
      account_number_error.style.display="block";
	  account_number_error.style.color="#235d22";
	  account_number_error.innerHTML="блокирование номера... ";
      account_number_error.style.borderTop="solid #bbbbbb 1px";
       }
   }*/
   
  
   
  

   function changePass()
   {
    var account_pass_block = document.getElementById("account_pass_block");
	account_pass_block.style.display="block";
    }
   
   function cancelPass()
   {
   document.getElementById("account_messager").style.display="none";
   var account_pass_block = document.getElementById("account_pass_block");
   var pass_show = document.getElementById("pass_show");
	$(document).ready(function(){
 
  $("#account_show").show(500);
  $("#help_show").show(500);
  
});
account_pass_block.style.display = "none";
pass_show.style.color = "#484848";
pass_show.style.hover.color = "#fa0000";
	
	document.getElementById("account_pass_current").value="";
	document.getElementById("account_pass_new").value="";
	document.getElementById("account_pass_repeat").value="";
   }
 
 
    function cancelData()
   {
   document.getElementById("account_messager").style.display="none";
   var account_data_block = document.getElementById("account_data_block");
   var account_show = document.getElementById("account_show");
	$(document).ready(function(){
 
  $("#pass_show").show(500);
  $("#help_show").show(500);
  
});
account_data_block.style.display = "none";
account_show.style.color = "#484848";
account_show.style.hover.color = "#fa0000";
	
	/*document.getElementById("account_pass_current").value="";
	document.getElementById("account_pass_new").value="";
	document.getElementById("account_pass_repeat").value="";*/
   }
 
 
 
  function cancelNumber()
  {
     var ebt=document.getElementById("v1");
     if(!ebt){
  
   var table=document.getElementById("account_number_table");
	 var browser=navigator.appName;
	 if (browser=="Microsoft Internet Explorer")
	 { while(table.childNodes.length>1){table.removeChild(table.lastChild);}}
	 else{
     while(table.childNodes.length>2){table.removeChild(table.lastChild);}}
   var account_number_error  = document.getElementById("account_number_error");
   account_number_error.style.display="block";
   var numbers = document.getElementById("selmn");
   var account_top_line = document.getElementById("account_top_line");
   var account_top_line_number = document.getElementById("account_top_line_number");
 
   for (var i=0; i<numbers.options.length; i++) if (numbers.options[i].selected) {numbers.options[i].selected=false; account_top_line.innerHTML="пока не выбран ни один номер ";
   account_top_line.style.fontWeight="normal"; account_top_line.style.color="#aa3128";
   account_top_line_number.innerHTML = "";}
   }
   else getNumber();
  }
 

   var xmlhttp;
   
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}
  
  
  function getNumber()
{ 
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Your browser does not support XMLHTTP!");
  return;
  }  
 var numbers = document.getElementById("selmn");
 var account_top_line = document.getElementById("account_top_line");
 var account_top_line_number = document.getElementById("account_top_line_number");
 var account_number_error  = document.getElementById("account_number_error");
  /*var table=document.getElementById("account_number_table");
  var browser=navigator.appName;
	 if (browser=="Microsoft Internet Explorer")
	 { while(table.childNodes.length>1){table.removeChild(table.lastChild);}}
	 else{
     while(table.childNodes.length>2){table.removeChild(table.lastChild);}}*/
 account_number_error.style.display="none";
 account_top_line.style.fontWeight="bold";account_top_line.style.color="#505050";
 account_top_line_number.style.color="#aa3128";
 for (var i=0; i<numbers.options.length; i++) if (numbers.options[i].selected) {account_top_line.innerHTML="Сейчас Вы работаете с номером: ";
 account_top_line_number.innerHTML = numbers.options[i].innerHTML;var number_id=numbers.options[i].value;
 var number_status = "get_number"; //alert(number_id);
  var url = "account_data.php";
     xmlhttp.open("POST", url, true);
     xmlhttp.onreadystatechange = updateGet_number;
	 xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
     xmlhttp.send("number_id=" + number_id +  "&status=" + number_status);   }
	
 }
  
  
  function updateGet_number()
  {
  
  if (xmlhttp.readyState == 4) {
     var numberData = xmlhttp.responseText;
     
   String(numberData);
    var numbers =numberData.split("REWQ");
  // alert(numbers[0]);
     var table=document.getElementById("account_number_table");
	 var browser=navigator.appName;
	 if (browser=="Microsoft Internet Explorer")
	 { while(table.childNodes.length>1){table.removeChild(table.lastChild);}}
	 else{
     while(table.childNodes.length>2){table.removeChild(table.lastChild);}}
	
	 
     
     for(var i=0;i<(numbers.length-1);i+=6){ 
	 var v ="v"+numbers[i]; var n="n"+numbers[i]; var t="t"+numbers[i];var s="s"+numbers[i];var f="f"+numbers[i];var p="p"+numbers[i];var h="h"+numbers[i];var m="m"+numbers[i];
	// alert(numbers[i]);
	
	 var input_vybor=document.createElement("input");
	 input_vybor.setAttribute("type","checkbox");
	 input_vybor.setAttribute("id",v);
	 input_vybor.setAttribute("onclick","vybor();"); 
	 
	 
	 var input_appdata=document.createElement("input");
	 input_appdata.setAttribute("type","text");
	 input_appdata.setAttribute("valign","center");
	 input_appdata.style.width="110px";
	 input_appdata.setAttribute("id",n);
	 input_appdata.setAttribute("readonly",true);
	 input_appdata.setAttribute("value",numbers[i+1]);
	 
	 var input_timeout=document.createElement("input");
	 input_timeout.setAttribute("type","text");
	 input_timeout.style.width="25px";
	 input_timeout.setAttribute("id",t);
	 input_timeout.setAttribute("readonly",true);
	 input_timeout.setAttribute("value",numbers[i+2]);
	 
	 var input_start=document.createElement("input");
	 input_start.setAttribute("type","text");
	 input_start.style.width="55px";
	 input_start.setAttribute("id",s);
	 input_start.setAttribute("readonly",true);
	 input_start.setAttribute("value",numbers[i+3]);
	 
	 var input_finish=document.createElement("input");
	 input_finish.setAttribute("type","text");
	 input_finish.style.width="55px";
	 input_finish.setAttribute("id",f);
	 input_finish.setAttribute("readonly",true);
	 input_finish.setAttribute("value",numbers[i+4]);
	 
	 
	 var input_music=document.createElement("select");
	 input_music.style.width="120px";
	 input_music.setAttribute("id",m);
	 input_music.setAttribute("disabled",true);
	 var music_option=document.createElement("option");
      music_option.text='blank';
    try
  {
  input_music.add(music_option,null); // standards compliant
  }
   catch(ex)
  {
  input_music.add(music_option); // IE only
  }
  
	// alert(m);
	 
	 var input_priority=document.createElement("input");
	 input_priority.setAttribute("type","text");
	 input_priority.style.width="25px";
	 input_priority.setAttribute("value",i);
	 input_priority.setAttribute("readonly",true);
	 input_priority.setAttribute("id",p);
	 input_priority.setAttribute("value",numbers[i+5]);
	 
	 var header = document.createElement("tr");
	 header.setAttribute("id",h);
	  
	 var st_1 = document.createElement("td");
	 st_1.setAttribute("align","center");
	 st_1.style.borderRight = "solid #aaaaaa 1px"; 
	 st_1.style.borderBottom = "solid #aaaaaa 1px";
	 st_1.style.height = "38px";
	 st_1.style.verticalAlign = "middle";
	  
	 var st_2 = document.createElement("td");
	 st_2.setAttribute("align","center");
	 st_2.style.borderRight = "solid #aaaaaa 1px";
	 st_2.style.borderBottom = "solid #aaaaaa 1px";
	 st_2.style.height = "38px";
	 st_2.style.verticalAlign = "middle";
	 
	 var st_3 = document.createElement("td");
	 st_3.setAttribute("align","center");
	 st_3.style.borderRight = "solid #aaaaaa 1px";
	 st_3.style.borderBottom = "solid #aaaaaa 1px";
	 st_3.style.height = "38px";
	 st_3.style.verticalAlign = "middle";
	 
	 var st_4 = document.createElement("td");
	 st_4.setAttribute("align","center");
	 st_4.style.borderRight = "solid #aaaaaa 1px";
	 st_4.style.borderBottom = "solid #aaaaaa 1px";
	 st_4.style.height = "38px";
	 st_4.style.verticalAlign = "middle";
	 
	 var st_5 = document.createElement("td");
	 st_5.setAttribute("align","center");
	 st_5.style.borderRight = "solid #aaaaaa 1px";
	 st_5.style.borderBottom = "solid #aaaaaa 1px";
	 st_5.style.height = "38px";
	 st_5.style.verticalAlign = "middle";
	 
	  var st_6 = document.createElement("td");
	 st_6.setAttribute("align","center");
	 st_6.style.borderRight = "solid #aaaaaa 1px";
	 st_6.style.borderBottom = "solid #aaaaaa 1px";
	 st_6.style.height = "38px";
	 st_6.style.verticalAlign = "middle";
	 
	 var st_7 = document.createElement("td");
	 st_7.setAttribute("align","center");
	 st_7.style.borderBottom = "solid #aaaaaa 1px";
	 st_7.style.height = "38px";
	 st_7.style.verticalAlign = "middle";
	 
	
	 st_1.appendChild(input_vybor);
	 st_2.appendChild(input_appdata);
	 st_3.appendChild(input_timeout);
	 st_4.appendChild(input_start);
	 st_5.appendChild(input_finish);
	 st_6.appendChild(input_music);
	 st_7.appendChild(input_priority);
	 
	 header.appendChild(st_1);
	 header.appendChild(st_2);
	 header.appendChild(st_3);
	 header.appendChild(st_4);
	 header.appendChild(st_5);
	 header.appendChild(st_6); 
	 header.appendChild(st_7);
	 
	 table.appendChild(header);
	 }
  
  }
  
  }
  
  

  
  
   function saveNumber()
   {  
   xmlhttp=GetXmlHttpObject();
  if (xmlhttp==null)
  {
  alert ("Your browser does not support XMLHTTP!");
  return;
  } 
  
   var numbers = document.getElementById("selmn");
   //var account_number_error  = document.getElementById("account_number_error");
    //account_number_error.style.display="none";
   for (var i=0; i<numbers.options.length; i++) if (numbers.options[i].selected) {
      var number_id=numbers.options[i].value;
       
	 var table=document.getElementById("account_number_table");
	 var x=table.getElementsByTagName("tr");
	 var sep="REWQ";
	 var common_string="";
	 var equiv_id="";
	 var appdata="";
	 var timeout="";
	 var start="";
	 var finish="";
	 var priority="";
	 var h="";
	 var f="";
	 var v=""; //alert(x.length);
	for(var j=1;j<(x.length);j++)
	{ h = x[j].id; f=h.slice(-(h.length-1)); v=document.getElementById("v"+f);
	if(v.checked){
	  equiv_id=f;
	  appdata = document.getElementById("n"+f).value;
	  timeout = document.getElementById("t"+f).value;
	  start = document.getElementById("s"+f).value;
	  finish = document.getElementById("f"+f).value;
	  priority = document.getElementById("p"+f).value;
	 common_string += equiv_id + sep + appdata + sep + timeout + sep + start + sep + finish + sep + priority + sep;
	   } else continue;
         }
          // alert(common_string);
	 var number_status = "save_number"; 
     var url = "account_data.php";
     xmlhttp.open("POST", url, true);
     xmlhttp.onreadystatechange = updateSave_number;
	 xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
     xmlhttp.send("number_id=" + number_id +  "&common_string=" + common_string + "&status=" + number_status); 

     }
	   
	   
   }
  
  function updateSave_number()
  {
  if (xmlhttp.readyState == 4) {
     var numberData = xmlhttp.responseText;
  if(numberData=="good"){getNumber();}
  else{getNumber();
  alert(numberData);}
  }
  }
  
  
   function removeNumber()
   {
     var ebt=document.getElementById("v1");
  if(!ebt){ 
   xmlhttp=GetXmlHttpObject();
  if (xmlhttp==null)
  {
  alert ("Your browser does not support XMLHTTP!");
  return;
  } 
  
   var numbers = document.getElementById("selmn");
   for (var i=0; i<numbers.options.length; i++) if (numbers.options[i].selected) {
      var number_id=numbers.options[i].value;
       
	 var table=document.getElementById("account_number_table");
	 var x=table.getElementsByTagName("tr");
	 var sep="REWQ";
	 var common_string="";
	 var equiv_id="";
	 
	 var priority="";
	 var h="";
	 var f="";
	 var v=""; //alert(x.length);
	for(var j=1;j<(x.length);j++)
	{ h = x[j].id; f=h.slice(-(h.length-1)); v=document.getElementById("v"+f);
	if(v.checked){
	  equiv_id=f;
	  priority = document.getElementById("p"+f).value;
	 common_string += equiv_id + sep + priority + sep;
	   } else continue;
         }
           if(common_string){
	 var number_status = "delete_number"; 
     var url = "account_data.php";
     xmlhttp.open("POST", url, true);
     xmlhttp.onreadystatechange = updateRemove_number;
	 xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
     xmlhttp.send("number_id=" + number_id +  "&common_string=" + common_string + "&status=" + number_status); 
     }
     }
	   }
   }
  
  
  function updateRemove_number()
  {
  if (xmlhttp.readyState == 4) {
     var numberData = xmlhttp.responseText;
  if(numberData=="good"){getNumber();}
  else{getNumber();
  alert(numberData);}
  }
  }
  
  
  
  
  
  
  
  function upNumber()
   {
     var ebt=document.getElementById("v1");
  if(!ebt){ 
   xmlhttp=GetXmlHttpObject();
  if (xmlhttp==null)
  {
  alert ("Your browser does not support XMLHTTP!");
  return;
  } 
  
   var numbers = document.getElementById("selmn");
   for (var i=0; i<numbers.options.length; i++) if (numbers.options[i].selected) {
      var number_id=numbers.options[i].value;
       
	 var table=document.getElementById("account_number_table");
	 var x=table.getElementsByTagName("tr");
	 var sep="REWQ";
	 var common_string="";
	 var equiv_id="";
	 var priority="";
	 var h="";
	 var f="";
	 var v=""; //alert(x.length);
	for(var j=1;j<(x.length);j++)
	{ h = x[j].id; f=h.slice(-(h.length-1)); v=document.getElementById("v"+f);
	if(v.checked){
	  equiv_id=f;
	  priority = document.getElementById("p"+f).value;
	 common_string += equiv_id + sep + priority + sep;
	  break; } else continue;
         }
           if(common_string){
	 var number_status = "up_number"; 
     var url = "account_data.php";
     xmlhttp.open("POST", url, true);
     xmlhttp.onreadystatechange = updateUp_number;
	 xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
     xmlhttp.send("number_id=" + number_id +  "&common_string=" + common_string + "&status=" + number_status); 
            }
     }
	   }
   }
  
  
  function updateUp_number()
  {
  if (xmlhttp.readyState == 4) {
     var numberData = xmlhttp.responseText;
  if(numberData=="good"){getNumber();}
  else{getNumber();
  alert(numberData);}
  }
  }
  
  
  
  function downNumber()
   {
     var ebt=document.getElementById("v1");
  if(!ebt){ 
   xmlhttp=GetXmlHttpObject();
  if (xmlhttp==null)
  {
  alert ("Your browser does not support XMLHTTP!");
  return;
  } 
  
   var numbers = document.getElementById("selmn");
   for (var i=0; i<numbers.options.length; i++) if (numbers.options[i].selected) {
      var number_id=numbers.options[i].value;
       
	 var table=document.getElementById("account_number_table");
	 var x=table.getElementsByTagName("tr");
	 var sep="REWQ";
	 var common_string="";
	 var equiv_id="";
	 var priority="";
	 var h="";
	 var f="";
	 var v=""; 
	for(var j=1;j<(x.length);j++)
	{ h = x[j].id; f=h.slice(-(h.length-1)); v=document.getElementById("v"+f);
	if(v.checked){
	  equiv_id=f;
	  priority = document.getElementById("p"+f).value;
	 common_string += equiv_id + sep + priority + sep;
	  break; } else continue;
         }
           if(common_string){
	 var number_status = "down_number"; 
     var url = "account_data.php";
     xmlhttp.open("POST", url, true);
     xmlhttp.onreadystatechange = updateDown_number;
	 xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
     xmlhttp.send("number_id=" + number_id +  "&common_string=" + common_string + "&status=" + number_status); 
            }
     }
	   }
   }
  
  
  function updateDown_number()
  {
  if (xmlhttp.readyState == 4) {
     var numberData = xmlhttp.responseText;
  if(numberData=="good"){getNumber();}
  else{getNumber();
  alert(numberData);}
  }
  }
  
  
  
  
  
  
function saveData(){
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Your browser does not support XMLHTTP!");
  return;
  }  
var name = document.getElementById("account_data_name").value;
var lname = document.getElementById("account_data_lname").value;
var mname = document.getElementById("account_data_mname").value;
var company = document.getElementById("account_data_company").value;
var tel = document.getElementById("account_data_tel").value;
var fax = document.getElementById("account_data_fax").value; //alert("fhfh");
var face="";
var person = document.getElementById("account_data_person");
if(person.checked){face=person.value;}
var firm = document.getElementById("account_data_firm");
if(firm.checked){face=firm.value;}
 var account_status = "account_save_data";
     var url = "account_data.php";
     xmlhttp.open("POST", url, true);
     xmlhttp.onreadystatechange = updateAccount_data;
	 xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
     xmlhttp.send("name=" + name + "&lname=" + lname + "&mname=" + mname + "&company=" + company + "&face=" + face + "&tel=" + tel + "&fax=" + fax + "&status=" + account_status);   
	// xmlhttp.send('param='+encodeURIComponent('привет мир'));
 }
 
function updateAccount_data()
{
if (xmlhttp.readyState == 4) {
   
     var accountData = xmlhttp.responseText;
 //alert(accountData);
 String(accountData);
 var numbers =accountData.split("REWQ");
 
 document.getElementById("account_data_name").value=numbers[0];
 document.getElementById("account_data_lname").value=numbers[1];
 document.getElementById("account_data_mname").value=numbers[2];
 document.getElementById("account_data_company").value=numbers[3];
 if(numbers[4]=="person"){document.getElementById("account_data_person").checked=true;}
 if(numbers[4]=="firm"){document.getElementById("account_data_firm").checked=true;}
  document.getElementById("account_data_tel").value=numbers[5];
 document.getElementById("account_data_fax").value=numbers[6];
 document.getElementById("account_messager").style.display="block";
 document.getElementById("account_messager").innerHTML="инмормация об аккаунте успешно изменена)";
 $(document).ready(function(){
 
  $("#pass_show").show(1000);
  $("#help_show").show(1000);
  $("#account_data_block").hide(1000);
});
var account_show = document.getElementById("account_show");
account_show.style.color = "#484848";
account_show.style.hover.color = "#fa0000";
}
} 

function savePass()
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Your browser does not support XMLHTTP!");
  return;
  } 
var pass_current = document.getElementById("account_pass_current").value;
var pass_new = document.getElementById("account_pass_new").value;
var pass_repeat = document.getElementById("account_pass_repeat").value;
var account_status = "account_change_pass";
     var url = "account_data.php";
     xmlhttp.open("POST", url, true);
     xmlhttp.onreadystatechange = updatePass;
	 xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
     xmlhttp.send("pass_current=" + pass_current + "&pass_new=" + pass_new + "&pass_repeat=" + pass_repeat + "&status=" + account_status );   
	
}

function updatePass()
{
if (xmlhttp.readyState == 4) {
var accountPass = xmlhttp.responseText;
var account_pass_block = document.getElementById("account_pass_block");
var account_pass_messager = document.getElementById("account_pass_messager");
if(accountPass=="good")
  {
  document.getElementById("account_messager").style.display="block";
  document.getElementById("account_messager").innerHTML="операция по замене пароля прошла успешно)";
  $(document).ready(function(){
 
  $("#account_show").show(1000);
  $("#help_show").show(1000);
  $("#account_pass_block").hide(1000);
});
   }
  else{
  document.getElementById("account_messager").style.display="block";
  document.getElementById("account_messager").style.fontWeight="bold";
  document.getElementById("account_messager").style.color="#fa0000";
  document.getElementById("account_messager").innerHTML=accountPass;
  //account_pass_messager.innerHTML=accountPass;
  } 
}
}



//--------------------------------------------------------------------------------------------------------------

   var request = null;
  
  function createRequest() {
     try {
       request = new XMLHttpRequest();
     } catch (trymicrosoft) {
       try {
         request = new ActiveXObject("Msxml2.XMLHTTP");
       } catch (othermicrosoft) {
         try {
           request = new ActiveXObject("Microsoft.XMLHTTP");
         } catch (failed) {
           request = null;
         }
       }
     }

     if (request == null)
       alert("Error creating request object!");
   }

   
  
 function getUserNumbers(){
 
  createRequest();
	 var valmn =" ";
	 for (var i=0; i<document.phones.selmn.options.length; i++) if (document.phones.selmn.options[i].selected) valmn=document.phones.selmn.options[i].value;
     var valln =" ";
	 for (var i=0; i<document.phones.selln.options.length; i++) if (document.phones.selln.options[i].selected) valln=document.phones.selln.options[i].value;
	 //var num = document.getElementById("ln").value; alert(val);
	 var url = "timeout.php";
     request.open("POST", url, true);
     request.onreadystatechange = updateTimeout;
	 request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
     request.send("valmn=" + valmn + "&valln=" + valln);
 
 }
 
 function updateTimeout() {
    if (request.readyState == 4) {
      var newTotal = request.responseText;
    
	 var numbers =newTotal;
	
		  document.phones.ln.value="";
		  document.phones.timeout.value=newTotal;
     
    }
  }
  
  
  function statistic() 
   {    
   
   createRequest();
    var year_1 =" ";
	 for (var i=0; i<document.statistics.stat_year_1.options.length; i++) if (document.statistics.stat_year_1.options[i].selected){ year_1=document.statistics.stat_year_1.options[i].value;}
     var month_1 =" ";
	 for (var i=0; i<document.statistics.stat_month_1.options.length; i++) if (document.statistics.stat_month_1.options[i].selected){ month_1=document.statistics.stat_month_1.options[i].value;}
	 var day_1 =" ";
	 for (var i=0; i<document.statistics.stat_day_1.options.length; i++) if (document.statistics.stat_day_1.options[i].selected) {day_1=document.statistics.stat_day_1.options[i].value;}
     var time_1 = document.getElementById("stat_time_1").value;   
     var year_2 =" ";
	 for (var i=0; i<document.statistics.stat_year_2.options.length; i++) if (document.statistics.stat_year_2.options[i].selected){ year_2=document.statistics.stat_year_2.options[i].value;}
    var month_2 =" ";
	 for (var i=0; i<document.statistics.stat_month_2.options.length; i++) if (document.statistics.stat_month_2.options[i].selected){ month_2=document.statistics.stat_month_2.options[i].value;}
	 var day_2 =" ";
	 for (var i=0; i<document.statistics.stat_day_2.options.length; i++) if (document.statistics.stat_day_2.options[i].selected) {day_2=document.statistics.stat_day_2.options[i].value;}
     var time_2 = document.getElementById("stat_time_2").value;    	
  
	 var url = "statistics.php";
     request.open("POST", url, true);
     request.onreadystatechange = updateStatistics;
	 request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
     request.send("year_1=" + year_1 + "&month_1=" + month_1 + "&day_1=" + day_1 + "&time_1=" + time_1 + "&year_2=" + year_2 + "&month_2=" + month_2 + "&day_2=" + day_2 + "&time_2=" + time_2);   
	 }
  
  
  function updateStatistics()
  {
   
   if (request.readyState == 4) {
     var my_st = document.getElementById("my_st");
     var newTotal = request.responseText;
     var table=document.getElementById("my_st_table");
     var ch=table.getElementsByTagName("tr");
	 var tota_bilsec=document.getElementById("total_bilsec");
	 var tota_cost=document.getElementById("total_cost");
	 var total_values=document.getElementById("total_values");
	 var stat_error=document.getElementById("stat_error");
	
	  tota_bilsec.value="";
	 tota_cost.value="";
     var numrows = ch.length;
	 var evenodd=0;
	 var total_bilsec = 0;
	 var total_cost = 0 ;
	 while(table.childNodes.length>2){table.removeChild(table.lastChild);}
	 String(newTotal);
	 var numbers =newTotal.split("REWQ");
	 if(numbers.length<=1){
	   stat_error.innerHTML="за выбранный период времени звонки не производились"; //alert("qwe");
	   total_values.className="di_none";
	   my_st.className="di_none";
	   }
	 else{
	     stat_error.innerHTML="";  
         my_st.className="di_block";
	     total_values.className="di_block";
	      }
	// for(var j=numrows;j>0;j--){table.removeChild(table.LastChild);}
	 for(var i=0;i<(numbers.length-1);i+=7){ evenodd++;
	 var header = document.createElement("tr");if((evenodd%2)==0){header.style.backgroundColor="#ededed";}else{header.style.backgroundColor="#fdfdfd";}
	 var st_date = document.createElement("td");st_date.setAttribute("align","center");st_date.style.borderRight = "solid #bbbbbb 1px";st_date.style.borderBottom = "solid #bbbbbb 1px";st_date.style.height = "25px";
	 var st_source = document.createElement("td");st_source.setAttribute("align","center");st_source.style.borderRight = "solid #bbbbbb 1px";st_source.style.borderBottom = "solid #bbbbbb 1px";
	 var st_destination = document.createElement("td");st_destination.setAttribute("align","center");st_destination.style.borderRight = "solid #bbbbbb 1px";st_destination.style.borderBottom = "solid #bbbbbb 1px";
	 var st_lastdata = document.createElement("td");st_lastdata.setAttribute("align","center");st_lastdata.style.borderRight = "solid #bbbbbb 1px";st_lastdata.style.borderBottom = "solid #bbbbbb 1px";
     var st_bilsec = document.createElement("td");st_bilsec.setAttribute("align","center");st_bilsec.style.borderRight = "solid #bbbbbb 1px";st_bilsec.style.borderBottom = "solid #bbbbbb 1px";
	 var st_disposition = document.createElement("td");st_disposition.setAttribute("align","center");st_disposition.style.borderRight = "solid #bbbbbb 1px";st_disposition.style.borderBottom = "solid #bbbbbb 1px";
    //var st_cost2 = document.createElement("td");st_cost2.setAttribute("align","center");st_cost2.style.border = "solid #bbbbbb 1px";	
	var st_cost = document.createElement("td");st_cost.setAttribute("align","center");/*st_cost.style.borderRight = "solid #bbbbbb 1px";*/st_cost.style.borderBottom = "solid #bbbbbb 1px";
	 st_date.appendChild(document.createTextNode(numbers[i]));
	 st_source.appendChild(document.createTextNode(numbers[i+1]));
	 st_destination.appendChild(document.createTextNode(numbers[i+2]));
	 var num_1=numbers[i+3].match(/\/\d+/);
	 if(num_1!=null){
	          var num_2 = num_1[0].match(/\d+/);
	st_lastdata.appendChild(document.createTextNode(num_2));}
	 else{  st_lastdata.appendChild(document.createTextNode(numbers[i+3])); }
	 st_bilsec.appendChild(document.createTextNode(numbers[i+4]));
	 total_bilsec+= parseFloat(numbers[i+4]);
	 st_disposition.appendChild(document.createTextNode(numbers[i+5]));
	 //st_cost2.appendChild(document.createTextNode(numbers[i+6]));
	 st_cost.appendChild(document.createTextNode(numbers[i+6]));
	 total_cost += parseFloat(numbers[i+6]);
	 header.appendChild(st_date);
	 header.appendChild(st_source);
	 header.appendChild(st_destination);
	 header.appendChild(st_lastdata);
	 header.appendChild(st_bilsec);
	 header.appendChild(st_disposition);
	 //header.appendChild(st_cost2);
	 header.appendChild(st_cost);
	 table.appendChild(header);}
	  total_bilsec=total_bilsec/60;
	  tota_bilsec.value=total_bilsec.toFixed();
	  tota_cost.value=total_cost.toFixed(2);
	 
     
    }
   
  }
  
  
  function statisticshide()
  {
  var stat_error=document.getElementById("stat_error");
  var my_st = document.getElementById("my_st");
  var total_values=document.getElementById("total_values");
  stat_error.innerHTML=""; 
  total_values.className="di_none";
  my_st.className="di_none";
  }
  
//--------------------------------------------------------------------------------------------------------------


function getInstuction()
{
var title=document.getElementById("title_numbers_instruction");
var body=document.getElementById("numbers_instruction");
if(title.innerHTML=="инструкция")
{
title.innerHTML ="скрыть";
body.style.display="block";
}
else
{
title.innerHTML ="инструкция";
body.style.display="none";
}
}













 
 

