function getXmlHttp(){
  var xmlhttp;
  try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
      xmlhttp = false;
    }
  }
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    xmlhttp = new XMLHttpRequest();
  }
  return xmlhttp;
}

function get_forms_elements() { 
        var forms = document.forms;
        var elements = [];
        for (var i = 0; i < forms.length; i++ ) {
                elements[i] = get_elements_from_form(forms[i]);
        }
        return elements;
} 

function addbox (id, ses, count, sale) {
   var xmlhttp = getXmlHttp();
   var current_date = new Date();
   var div = document.getElementById('box');
   var flag = '';

//   var inputs = document.all.tags("select");
//    for (var i=0; i<inputs.length; i++)
//    {
//    flag = flag+'@'+inputs[i].value;
//    }
   xmlhttp.open('GET', 'http://'+location.host+'/add_box.php?id='+id+'&ses='+ses+'&count='+count+'&sale='+sale+'&flag='+flag, true);
   xmlhttp.onreadystatechange = function() {
   if (xmlhttp.readyState == 4)
   {
    if(xmlhttp.status == 200)
    {
   div.innerHTML = xmlhttp.responseText;
   var pokupka = document.getElementById('pokupka'+id);
   if(pokupka!=undefined)
   {
   pokupka.innerHTML = "<center><font color=\"#008000\">Товар в корзине<font></center>";
   }

    }
   }
 }
xmlhttp.send(null);
}
function showLink(url)
{
var msgWindow;
msgWindow=window.open('http://hattabych.com.ua/foto_big.php?id='+url,"","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=10,height=10");
if (msgWindow != null && msgWindow.opener == null) msgWindow.opener=window;
msgWindow.focus();
}

function addfoto () {
  var count = document.getElementById('countfoto').value;
  document.getElementById('countfoto').value = eval(count+'+1');

  var newDiv = document.createElement('div');
  newDiv.innerHTML = '<input name=\"userfile'+eval(count+'+1')+'\" type=\"file\" style=\"width=100%\">';
  add_foto.appendChild(newDiv);
}

function showbig (id, file) {
  document.getElementById('tablefoto'+document.getElementById('fotoid').value).bgColor= 'FFFFFF';
  document.getElementById('fotobig').src= 'images/tovar/l'+file+'';
  document.getElementById('fotopix').value= file;
  document.getElementById('fotoid').value= id;
  document.getElementById('tablefoto'+id).bgColor= 'C81124';
}

function addbigpix (id) {

var oknoWidth=800; var oknoHeight=640;
if (self.innerWidth)
    oknoWidth = self.innerWidth;
else if (document.documentElement && document.documentElement.clientWidth)
    oknoWidth = document.documentElement.clientWidth;
else if (document.body)
    oknoWidth = document.body.clientWidth;

    if (self.innerHeight)
    oknoHeight = self.innerHeight;
else if (document.documentElement && document.documentElement.clientHeight)
    oknoHeight = document.documentElement.clientHeight;
else if (document.body)
    oknoHeight = document.body.clientHeight;

    newImg = new Image(); 
    newImg.src = id; 

var box_block = document.getElementById('box_block');
var scrollt = document.body.scrollTop;
var scrolll = document.body.scrollLeft;


     box_block.style.top = eval(scrollt+'+(('+oknoHeight+'/2)-30)')+'px';
     box_block.style.left = eval(scrolll+'+(('+oknoWidth+'/2)-30)')+'px';

   document.getElementById('box_page').style.zIndex = '10';
   document.getElementById('box_page').style.display = '';
   document.getElementById('box_block').style.zIndex = '20';
   document.getElementById('box_block').style.display = '';
   document.getElementById('box_page').style.top = scrollt;
   document.getElementById('box_page').style.left = scrolll;


newImg.onload=function(){

  
    box_block.style.top = eval(scrollt+'+(('+oknoHeight+'/2)-('+newImg.height+'/2))-15')+'px';
    box_block.style.left = eval(scrolll+'+(('+oknoWidth+'/2)-('+newImg.width+'/2)-15)')+'px';
    document.getElementById('addbigfoto').src = id;
  
}
if(newImg.complete)
{
    box_block.style.top = eval(scrollt+'+(('+oknoHeight+'/2)-('+newImg.height+'/2))-15')+'px';
    box_block.style.left = eval(scrolll+'+(('+oknoWidth+'/2)-('+newImg.width+'/2)-15)')+'px';
    document.getElementById('addbigfoto').src = id;
}
}
function hidebox () {
   document.getElementById('addbigfoto').src = 'images/1x1.gif';
   document.getElementById('box_block').style.zIndex = '-10';
   document.getElementById('box_block').style.display = 'none';
   document.getElementById('box_page').style.zIndex = '-10';
   document.getElementById('box_page').style.display = 'none';
}

function opr_wh()
{
var oknoWidth=800; var oknoHeight=640;
if (self.innerWidth)
    oknoWidth = self.innerWidth;
else if (document.documentElement && document.documentElement.clientWidth)
    oknoWidth = document.documentElement.clientWidth;
else if (document.body)
    oknoWidth = document.body.clientWidth;

    if (self.innerHeight)
    oknoHeight = self.innerHeight;
else if (document.documentElement && document.documentElement.clientHeight)
    oknoHeight = document.documentElement.clientHeight;
else if (document.body)
    oknoHeight = document.body.clientHeight;

var box_block = document.getElementById('box_block');
var scrollt = document.body.scrollTop;
var scrolll = document.body.scrollLeft;
if(box_block!=undefined)
{

     box_block.style.top = eval(scrollt+'+(('+oknoHeight+'/2)-('+document.getElementById('addbigfoto').height+'/2)-15)')+'px';
     box_block.style.left = eval(scrolll+'+(('+oknoWidth+'/2)-('+document.getElementById('addbigfoto').width+'/2)-15)')+'px';
     document.getElementById('box_page').style.top = scrollt+'px';
    document.getElementById('box_page').style.left = scrolll+'px';
}
}

function div_hide(id) {
  
  if(document.getElementById(''+id+'').style.display == 'none')
  {
    document.getElementById(''+id+'').style.display = '';
  }
  else
  {
    document.getElementById(''+id+'').style.display = 'none';
  }
}

function edit_email(id) {

  var email = document.getElementById('email_'+id).value;  
  if(document.getElementById('status_edit_'+id).value == '0')
  {
    document.getElementById('status_edit_'+id).value = '1';
    document.getElementById('edit_'+id+'').innerHTML = '<input id="new_email_'+id+'" type="text" value="'+email+'" style="width:70%"><input onclick="savee_email('+id+')" type="button" value="Сохранить">';
  }
  else
  {
    document.getElementById('status_edit_'+id).value = '0';
    document.getElementById('edit_'+id+'').innerHTML = email;
  }  

}


function savee_email (id) {
  
   var new_email = document.getElementById('new_email_'+id).value;  
//  alert(id+' - '+new_email);

   var xmlhttp = getXmlHttp();
   var current_date = new Date();
//   alert('http://'+location.host+'/add_email.php?id='+id+'&email='+new_email+'&date='+current_date);

   xmlhttp.open('GET', 'http://'+location.host+'/ajax/add_email.php?id='+id+'&email='+new_email, true);
   xmlhttp.onreadystatechange = function()
   {
    if (xmlhttp.readyState == 4)
    {
     if(xmlhttp.status == 200)
     {
//      alert(xmlhttp.responseText);
      if(xmlhttp.responseText == 'Ok')
      {
       document.getElementById('edit_'+id+'').innerHTML = new_email;
       document.getElementById('status_edit_'+id).value = '0';
       document.getElementById('email_'+id).value = new_email;
      }
     }
    }
   }
   xmlhttp.send(null);
}

function news_textt (id) {
  
   var xmlhttp = getXmlHttp();
   var current_date = new Date();

   xmlhttp.open('GET', 'http://'+location.host+'/ajax/news_text.php?id='+id, true);
   xmlhttp.onreadystatechange = function()
   {
    if (xmlhttp.readyState == 4)
    {
     if(xmlhttp.status == 200)
     {
//      alert(xmlhttp.responseText);
       document.getElementById('news_text').value = xmlhttp.responseText;
     }
    }
   }
   xmlhttp.send(null);
}


