var activeItem = null;
var killed = false;
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i>a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function change_date(day,month,year,mode) {
  document.location = "?mode="+mode+"&d="+year+"-"+month+"-"+day;
}


var activeItem = null;
var killed = false;
function kill() {
        if (activeItem != null && killed) {
                clearTimeout();
                document.getElementById(activeItem).style.visibility='hidden';
                killed = false;
        }
}
function menuOpen(t, i)
{
        clearTimeout();
        killed = false;
        if (activeItem != null) {
                document.getElementById(activeItem).style.visibility='hidden';
        };
        activeItem = t.id+'div';
        if (document.all) {
                obj = document.getElementById(t.id).parentElement.parentElement;
                all_L = 0;
                all_T = 0;
                while (obj = obj.parentElement) {
                        all_L += obj.offsetLeft;
                        all_T += obj.offsetTop;
        };
        posX = all_L + document.getElementById(t.id).width + 2;
        if (i == 0) {
                posY = all_T;
        } else {
                posY = all_T + document.getElementById(t.id).height - document.getElementById(activeItem).clientHeight;
        };
        document.getElementById(activeItem).style.left=posX;
        document.getElementById(activeItem).style.top=posY;
        document.getElementById(activeItem).style.visibility='visible';
} else {
        posX = document.getElementById(t.id).x + 2 + document.getElementById(t.id).naturalWidth;
        if (i == 0) {
                posY = document.getElementById(t.id).y ;
        } else {
                posY = document.getElementById(t.id).y +document.getElementById(t.id).naturalHeight- document.getElementById(activeItem).clientHeight;
        };
        document.getElementById(activeItem).style.left=posX;
        document.getElementById(activeItem).style.top=posY;
        document.getElementById(activeItem).style.visibility='visible';
}
};
function menuClose(t)
{

        if (activeItem != null) {
                clearTimeout();
                killed = true;
                setTimeout("kill()",3000);
        };
};

function spanShow(t) {
        clearTimeout();
        killed = false;
}
function change_tr_color(id) {
        color=document.getElementById(id).style.backgroundColor;
        if(color){
              color=document.getElementById(id).style.backgroundColor = ''
        }
        else color=document.getElementById(id).style.backgroundColor='#d8d8d8';
}
function change_back_tr_color(id) {
        color=document.getElementById(id).style.backgroundColor;
        if(color){
              color=document.getElementById(id).style.backgroundColor = ''
        }
        else color=document.getElementById(id).style.backgroundColor='#d8d8d8';
}

var req;

function loadXMLDoc(url) {
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        //req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
           // req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}

function Assign_session_data(id)
{
    host = 'http://www.direct-line.ru/';
    //host = 'http://sergey.unlab.ru/__zakaz/';
    //host = 'http://85.142.31.2/direct-line.ru/www/';
    if('both' == window.event.srcElement.id){
         url  = host + 'basket.php?both=1';
         loadXMLDoc(url);
    }
    else if('new' == window.event.srcElement.id){
         url  = host + 'basket.php?new=1';
        loadXMLDoc(url);
    }
    else if('politic' == window.event.srcElement.id){
         url  = host + 'basket.php?politic=1';
         loadXMLDoc(url);
    }
    else if('delovoy' == window.event.srcElement.id){
         url  = host + 'basket.php?delovoy=1';
         loadXMLDoc(url);
    }
    else{
          id=window.event.srcElement.id;
          if(document.getElementById(id).checked){
             action='add';}
          else action='out';
          id=id.substring(2,id.length);
          url  = host + 'basket.php?id=' + id + '&action=' + action;
          loadXMLDoc(url);
    }
}

function Count(){

  id=window.event.srcElement.id;
  span=document.getElementById("count");
  num=span.innerHTML;
  num=num-0;
  span1=document.getElementById("count1");
  num1=span1.innerHTML;
  num1=num1-0;
  if(document.getElementById(id).checked){
       span.innerHTML=num+1;
       if(num == 0){
       document.getElementById("send_link").innerHTML = '<a href="sendblank.php" class="order">оформить подписку</a>';
       }
       span1.innerHTML=num1+1;
       if(num1 == 0){
       document.getElementById("send_link1").innerHTML = '<a href="sendblank.php" class="order">оформить подписку</a>';
       }
  }
  else{
       span.innerHTML=num-1;
       if(num ==1){
       document.getElementById("send_link").innerHTML = '<font color="#D3D3D3">оформить подписку</font>';
       }
       span1.innerHTML=num1-1;
       if(num1 ==1){
       document.getElementById("send_link1").innerHTML = '<font color="#D3D3D3">оформить подписку</font>';
       }
  }
  return true;
}
function PrintDate() {
months = new Array("Января","Февраля","Марта","Апреля","Мая","Июня","Июля","Августа","Сентября","Октября","Ноября","Декабря");
span=document.getElementById('date');
today = new Date();
month=months[today.getMonth()];
span.innerHTML = today.getDate() + " " + month + ",";
//Timebox.theDate.value = today.getMonth()+1 + "/" + today.getDate() + "/" + today.getYear();
}
function RefreshTimebox() {
today = new Date();
hours = today.getHours();
min = today.getMinutes();
sec = today.getSeconds();
document.getElementById('time').value = ((hours > 9)?hours:"0" + hours) + ":" + ((min > 9)?min:"0" + min) + ':'+ ((sec > 9)?sec:"0" + sec);
//Timebox.theDate.value = today.getMonth()+1 + "/" + today.getDate() + "/" + today.getYear();
setTimeout("RefreshTimebox()", 500);
}