﻿// JavaScript Document
// 
var showErrors = true;
var cache = new Array();
function displayError($message){
    if(showErrors){
        showErrors = false;
        alert("Возникла ошибка: \n" + $message);
    }
}
function process(element){
    if(xmlHttp){        
        params = "";
        var title = encodeURIComponent(element.getAttribute("title"));
        params = "?title=" + title;
        var newDiv = document.createElement("div");
        if(newDiv && newDiv != ""){
              newDiv.setAttribute("id", "plan");
              document.body.appendChild(newDiv);
              var div = (document.getElementById)?document.getElementById("plan"):document.all.plan;
              var pos = getOffset(element);
              div.style.left = (pos.left - 312) + "px";
              div.style.top = (pos.top) + "px"; 
        } else {
              return false;
        }
        
        if(params){
             cache.push(params);
        }
        //try{
              if((xmlHttp.readyState == 4 || xmlHttp.readyState == 0) && cache.length > 0){
                    var cacheEntry = cache.shift();
                    xmlHttp.open("GET", "http://www.ozerki-fitness.ru/wp-content/themes/fitnes/parseXML.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());
        //}
    }
}
