// Cross Site AJAX BEGIN

/* *********************************************************************** */
/* (c) 2006 Bridge Interactive Group LLC. All Rights Reserved              */
/*                                                                         */
/* Author:  Marc G. Smith <msmith_at_bigllc_dot.com>                       */      
/* Version: 1.0                                                            */      
/* *********************************************************************** */
    
var com = com ? com : {}
    com.bigllc  = com.bigllc ? com.bigllc : {};   
    com.bigllc.fm_xjrButton  = com.bigllc.fm_xjrButton ? com.bigllc.fm_xjrButton : {};

/* *********************************************************************** */

com.bigllc.fm_xjrButton.CrossSiteJsonRequest = function()
{
    if(com.bigllc.fm_xjrButton.CrossSiteJsonRequest.prototype.instance) {
      return com.bigllc.fm_xjrButton.CrossSiteJsonRequest.prototype.instance;
    }
    
        var heads     = document.getElementsByTagName('head');
      this.head     = heads[0];
      this.busy     = false;
      this.queue    = new Array();
      this.timerId  = null; 
    this.timeOut    = 100;
    
      var self = this;
      this.queueDispatcher = function() {
        if(!self.busy) {
          var url = self.queue[0];
          self.queue.splice(0, 1);
          self.get(url);
        }
        
        if(self.queue.length == 0) {
          clearInterval(self.timerId);
          self.timerId = null;
        }
      }
      
      com.bigllc.fm_xjrButton.CrossSiteJsonRequest.prototype.instance = this;
}

/* *********************************************************************** */

com.bigllc.fm_xjrButton.CrossSiteJsonRequest.prototype = {
  instance : null,
  
  setErrorHandler: function(handler) {
    this.errorHandler = handler;
  },

  setResponseHandler: function(handler) {
    this.responseHandler = handler;
  },
  
  get: function(url, timerId) {
    if(this.busy) {
      this.queue[this.queue.length] = url;
      
      if(!this.timerId) {
        this.timerId = setInterval(this.queueDispatcher, this.timeOut); 
      }
      
      return;
    }
    
    this.busy = true;
    
    url += (url.indexOf("?") < 0) ?  "?" : "&";
    url += "xjrid=" + new Date().getTime();
    
    if(this.scriptTag) { this.head.removeChild(this.scriptTag); }
        this.scriptTag=document.createElement('script');
        this.scriptTag.setAttribute('type','text/javascript');
        this.scriptTag.setAttribute('src', url);
        this.head.appendChild(this.scriptTag);
  },
  
  notify: function() {
          try { fm_xjrExecuteButton(this.responseHandler); }
          catch(e){ (this.errorHandler) ? this.errorHandler(e) : alert(e.message); }
          this.busy = false;
          //this.head.removeChild(this.scriptTag);
          //this.scriptTag = null;
  } 
}

/* *********************************************************************** */

com.bigllc.fm_xjrButton.RequestDispatcher = new com.bigllc.fm_xjrButton.CrossSiteJsonRequest();

/* *********************************************************************** */

// Cross Site AJAX END



var fm_xjrButton = com.bigllc.fm_xjrButton.RequestDispatcher;
fm_xjrButton.setResponseHandler(fm_XJRResponseButton);
fm_fetchButtonText();



function fm_XJRResponseButton(data,punkte)
{
	if (punkte==0)
		punkte='';
    document.getElementById('fmButton').innerHTML = punkte + '<img src="http://www.wertpunkte.de/images/kleiner_wertpunkt.gif" alt="www.wertpunkte.de">&nbsp;<a href="javascript:fm_openwindow();">' + data + '</a>';   
    
}
    
function fm_fetchButtonText()
{
	fm_xjrButton.get("http://www.wertpunkte.de/fehlermelden/fmbutton.php?url=" + encodeURIComponent(window.location.href));
} 

function fm_openwindow()
{
	var l = (screen.availWidth - 550) / 2;
    var t = (screen.availHeight - 650) / 2;
	var fm_window = window.open('http://www.wertpunkte.de/fehlermelden/index.php?task=add&url='+ encodeURIComponent(window.location.href),"fm_window","width=550, height=650,menubar=no, scrollbars=no,status=no, toolbar=no,left=" + l + ",top="+t);
}
