// JavaScript Document
// 
var showErrors = true;
var cache = new Array();
function displayError($message){
    if(showErrors){
        showErrors = false;
        alert("Возникла ошибка: \n" + $message);
    }
}
function process(content,content2){
    if(xmlHttp){
        params = "";
        content = encodeURIComponent(document.getElementById(content).value);
        content2 = encodeURIComponent(document.getElementById(content2).value);
        params = "?c=" + content + "&c2=" + content2;
        if(params){
             cache.push(params);
        }
        try{
              if((xmlHttp.readyState == 4 || xmlHttp.readyState == 0) && cache.length > 0){
                    var cacheEntry = cache.shift();
                    xmlHttp.open("GET", "http://pkmspb.ru/wp-content/themes/PKM/search_in_db.php" + cacheEntry, true);
                    xmlHttp.setRequestHeader("Content-Type",
                                             "application/x-www-form-urlencoded");
                    xmlHttp.onreadystatechange = handleRequestStateChange;
                    xmlHttp.send(null);
              } else {
                    setTimeout("process();", 1000);
              }
        } catch(e){
              displayError(e.toString());
        }
    }
}
function process_cors(content){
    if(xmlHttp){
        params = "";
        content = encodeURIComponent(content);
        params = "?c=" + content;
        if(params){
             cache.push(params);
        }
        try{
              if((xmlHttp.readyState == 4 || xmlHttp.readyState == 0) && cache.length > 0){
                    var cacheEntry = cache.shift();
                    xmlHttp.open("GET", "http://pkmspb.ru/wp-content/themes/PKM/corsina.php" + cacheEntry, true);
                    xmlHttp.setRequestHeader("Content-Type",
                                             "application/x-www-form-urlencoded");
                    xmlHttp.onreadystatechange = handleRequestCorsina;
                    xmlHttp.send(null);
              } else {
                    setTimeout("process();", 1000);
              }
        } catch(e){
              displayError(e.toString());
        }
    }
}

function handleKey(e){
      e = (!e)?windoe.event:e;
      code = (e.charCode) ? e.charCode : ((e.keyCode) ? e.keyCode : ((e.which) ? e.which : 0));
      if(e.type == "keydown"){
            if(code == 13){
                  process("search");
            }
      }
}
