function getClientWidth()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}


function showHide(id){
  elem = document.getElementById(id);	
  if(elem.style.display=='block'){
	  elem.style.display='none';
  }else{
	  elem.style.display='block';
  }
}

function CheckboxFunc(chk,inpid,bgpos1,bgpos2){
  elem = chk;
  input = document.getElementById(inpid);
  if(elem.style.backgroundPosition==bgpos1){
	  elem.style.backgroundPosition=bgpos2;
	  input.value=1;
  }else{
	  elem.style.backgroundPosition=bgpos1;
	  input.value=0;
  }
}

var NoGoodBrowser = navigator.userAgent.indexOf('MSIE 6.0')>-1;

function switchOver(a,num) {
  var cback = a.style.backgroundImage;
    a.style.backgroundImage = cback.replace("image_prev","image_norm");
    if (NoGoodBrowser==true)
            a.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='files/14/shop/categories_"+num+"_image_norm.png',sizingMethod='crop')";
}

function switchOut(a,num) {
  var cback = a.style.backgroundImage;
    a.style.backgroundImage = cback.replace("image_norm","image_prev");
    if (NoGoodBrowser==true)
      a.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='files/14/shop/categories_"+num+"_image_prev.png',sizingMethod='crop')";
      
}

function ImageOver(elem,num){
  if (num == 1){
    elem.src=elem.src.replace('.gif','_over.gif');
  }else{
    elem.src=elem.src.replace('_over.gif','.gif')
  }
}

function update_basket_count(c)
  {
  var ajax = new Ajax.Updater(
    {success: 'basket_count'},
    '/lib/ajax/modules/shop/shop.basket.php',
    {method: 'post',
    parameters: {option: 'update', count: c}} 
    );
  }
  
function show_full_image(e,img_src,width,height)
  {
  if (img_src != "")
    {
    var event = (window.event)?window.event:e;
    MouseX = event.clientX + document.body.scrollLeft;
    MouseY = event.clientY + document.body.scrollTop;
    
    obj = document.getElementById("window");
    obj.style.display = "block";
    
    if (height >= 400)
      {
      if (navigator.appName == "Netscape")
	{
	var objtop = eval(window.pageYOffset + getClientHeight()/2 - 250);
	var objleft = eval(getClientWidth()/2 - 200);
	obj.style.top = objtop + "px";
	obj.style.left = objleft + "px";
	}
      else
	{
	var objtop = eval(document.documentElement.scrollTop + screen.availHeight/2 - 320);
	var objleft = eval(getClientWidth()/2 - 200);
	obj.style.pixelTop = objtop;
	obj.style.pixelLeft = objleft;
	obj.style.pixelWidth = 40 + parseInt(width);
	//obj.style.width = 435;
	}
      }
    else
      {
      if (navigator.appName == "Netscape")
	{
	var objtop = eval(window.pageYOffset + getClientHeight()/2 - 200);
	var objleft = eval(getClientWidth()/2 - 250);
	obj.style.top = objtop + "px";
	obj.style.left = objleft + "px";
	}
      else
	{
	var objtop = eval(document.documentElement.scrollTop + screen.availHeight/2 - 220);
	var objleft = eval(getClientWidth()/2 - 250);
	obj.style.pixelTop = objtop;
	obj.style.pixelLeft = objleft;
	obj.style.pixelWidth = 480;
	//obj.style.width = 435;
	}
      }
    
    document.getElementById("winContent").innerHTML= "<img src="+img_src+">";
    }
  }

function add_to_basket(id)
  {
  var c = (document.getElementById('count_items')) ? document.getElementById('count_items').value : '';
  if (c > 0)
    {
    var ajax = new Ajax.Updater(
      {success: 'basket_add_res'},
      '/lib/ajax/modules/shop/shop.basket.php',
      {method: 'post',
      parameters: {option:'add', id: id, count:c}} 
      );
    len = mas.length;
    mas[len] = id;
    document.getElementById("winContent").innerHTML = "<span style='color: #648c89'>Изделие успешно добавлено в <a href='/basket' style=\'color: #648c89;\'>корзину</a></span>";
    if (navigator.appName == "Netscape") 
      {
      document.getElementById("window").style.top = document.getElementById("window").style.top + 180;
      }
    else
      {
      document.getElementById("window").style.pixelTop = document.getElementById("window").style.pixelTop + 180;
      }
    }
    
  er = setTimeout("update_basket_count("+c+")",500);
  }

function reportError()
  {
  alert('Error');
  }

function hide_bar()
  {
  document.getElementById("window").style.display="none";
  }

function all_check()
  {
  for (i=0;i<mas.length;i++)
    {
    elem = document.getElementById(mas[i]+'_a');
    input = document.getElementById(mas[i]+'_check');
    if(document.getElementById('all_item_a').style.backgroundPosition=='0px 0px')
      {
      elem.style.backgroundPosition='0px 0px';
      input.value=0;
      }
    else
      {
      elem.style.backgroundPosition='left bottom';
      input.value=1;
      }
    }
  }

function recounting()
  {
  var all_cost = 0;
  var nums = new Array('0','1','2','3','4','5','6','7','8','9');
  for (i=0;i<mas.length;i++)
    {
    count = document.getElementById(mas[i]+'_count').value;
    
    if (count == "")
      {
      count = 1;
      }
    else
    {
      var  new_count = count;
      for (j=0;j<count.length;j++)
        {
        if (nums.indexOf(count.charAt(j)) == -1)
          {
          new_count = new_count.replace(count.charAt(j),"");
          }
        }
      count = new_count;
      while (count.charAt(0) == 0)
        {
        ch = "";  
        for (j=1;j<count.length;j++) ch += count.charAt(j);
        count = ch;
        }
      
      if (count == "")
        {
        count = 1;
        }
    }  
    count = parseInt(count);
    
    document.getElementById(mas[i]+'_count').value = count;
    price = document.getElementById(mas[i]+'_price').innerHTML;
    var ajax = new Ajax.Updater(
          'basket_add_res',
          'lib/ajax/modules/shop/shop.basket.php',
          {method: 'post',
          parameters: {option:'add', id: mas[i], count:count}} 
          );
    document.getElementById(mas[i]+'_cost').innerHTML = count*price;
    all_cost += count*price;
    }
  document.getElementById('all_cost').innerHTML = all_cost;
  }

