var request;
var dest;
var func;

function processStateChange(){
    if (request.readyState == 4){
        contentDiv = document.getElementById(dest);
        if (request.status == 200){
            response = request.responseText;
            contentDiv.innerHTML = response;
	    if(func!='') eval(func+"();");
        } else {
            contentDiv.innerHTML = "Error: Status "+request.status;
        }
    }
}

function loadHTML(URL, destination, function_to_exec){
    dest = destination;
    func = function_to_exec;

    if (window.XMLHttpRequest){
        request = new XMLHttpRequest();
        request.onreadystatechange = processStateChange;
        request.open("POST", URL, true);
        request.send(null);
    } else if (window.ActiveXObject) {
        request = new ActiveXObject("Microsoft.XMLHTTP");
        if (request) {
            request.onreadystatechange = processStateChange;
            request.open("POST", URL, true);
            request.send();
        }
    }
}

var cart_vis = true;
var t=0;

function ChangeCartVis()
{
  cart_vis = !cart_vis;

  cart_im = document.getElementById("cart_img");

  if(cart_vis)
    cart_im.style.visibility = 'visible';
  else
    cart_im.style.visibility = 'hidden';
  if(t<7)
    setTimeout(function(){ChangeCartVis()},500);
  if(t>=7)
  { 
    if(cart_im.style.visibility == 'hidden') cart_im.style.visibility = 'visible'; 
    t=0; return;
  }
  t++;
}

function SplashCart()
{
 if(t>6)
 {
   setTimeout(function(){SplashCart()},500);
 }
 else
 {
   cart_vis = true;
   t=0;
   setTimeout(function(){ChangeCartVis()},500);
 }
}

function CheckHallo()
{
 if(!document.getElementById("hallo")) alert('Неверный пароль');
 else
 {
   if(location.href.search('tool_f.php')!=-1 || location.href.search('tool_s.php')!=-1 || location.href.search('korzina.php')!=-1)
   {
     location.reload();
   }
 }
}

function OnExit()
{
   if(location.href.search('tool_f.php')!=-1 || location.href.search('tool_s.php')!=-1 || location.href.search('korzina.php')!=-1)
   {
     location.reload();
   }
}

function onEnter(el,event)
{
  ecode = (event.keyCode ? event.keyCode : event.which ? event.which : null);
  if(ecode==13)
    if(el.value!="") {loadHTML("top.php?pass="+el.value, "topforms", "CheckHallo");}
}

function onEnterSearch(el,event)
{
  ecode = (event.keyCode ? event.keyCode : event.which ? event.which : null);
  if(ecode==13)
    if(el.value!="") { find=el.value; if(find.length>=3) location.href="search.php?find="+find; else alert("Введите минимум три символа");}
}

function onSubmitSearchForm()
{
  el = document.getElementById("sf_find");
  if(el.value!="") { find=el.value; if(find.length>=3) document.getElementById("sf").submit(); else alert("Введите минимум три символа");}
}
