
//fuggosegek: 
if (typeof BROWSERDETECT == "undefined") {  
}
//tobbszoros include:
if (typeof BUGREPORT != "undefined") {
}
BUGREPORT=true;

/** Ez az osztaly vegzi a hibajelentes osszeallitasat
  */
function BugReport() {
} // BugReport


/** Inicializalo fuggveny
  *
  * @static
  * @param object config parameterek objektuma
  */
BugReport.init = function(config) {
  if (null == this.canvas) {

    this.button='';
    this.reportUrl='';
    
    this.setDefaults();
    this.readConfig(config);

    if (this.reportUrl == "") {
      throw new Error("bugreport: url undefined");
    }

    this.downloadJs();
    var bugreport=this;
    setTimeout(function(event) {bugreport.initAfterJs();},100);

  }
} // BugReport.init

/** Elvegzi az inicializalas azon reszet, amit a JS osztalyok betoltese utan szukseges
  *
  * @static
  */
BugReport.initAfterJs=function() {
  if ("undefined" == typeof XmlHttp) {
    var bugreport=this;
    setTimeout(function(event) {bugreport.initAfterJs();},100);
  } if (false == XmlHttp.isSupported()) {
    alert(BugReport.I18N.text.xmlHttpError);
  } else {
    document.documentElement.style.width='100%';
    document.documentElement.style.height='100%';
    document.body.style.width='100%';
    document.body.style.height='100%';

    this.canvas=document.createElement("div");
    this.canvas.setAttribute("id","bugreport_canvas");
    this.canvas.style.width='100%';
    this.canvas.style.height='100%';
    this.canvas.style.zIndex='9000';
    this.canvas.style.position='absolute';
    this.canvas.style.top="0px";
    this.canvas.style.left="0px";
    this.canvas.style.background="url(transparent.gif) repeat"; //ez minek is kell?

    document.body.appendChild(this.canvas);

    this.toolbar=document.createElement("div");
    this.toolbar.setAttribute("id","bugreport_toolbar");
    this.toolbar.style.backgroundColor="#e0e0e0";
    this.toolbar.style.border='1px solid #000';
    this.toolbar.style.zIndex='9001';
    this.toolbar.style.position='absolute';
    this.toolbar.style.right='0px';

    this.buildToolbar();

    document.body.appendChild(this.toolbar);


    this.registerEventListeners();

    this.resizeCanvas();
    this.moveToolbar();
  }
} // BugReport.initAfterJs

/** Ez a fuggveny beallitja a default ertekeket, amiket at lehet definialni
  *
  * @static
  */
BugReport.setDefaults=function() {
  this.pixelSize=5;
  this.pixelColor='#000';
  this.lang='hu_HU';
  this.textareaRows=5;
  this.textareaCols=30;
  this.scripts="";
  this.images="";
} // BugReport.setDefaults

/** E fuggveny vegigmegy a config objektumon es ervenyes ertekek eseten atirja a megfelelo parametert
  *
  * @static
  * @param object config parameterek objektuma
  */
BugReport.readConfig = function(config) {
  if (config.pixelColor != null && (config.pixelColor.match(/#([0-9a-f]{3}|[0-9a-f]{6})/i))){
    this.pixelColor=config.pixelColor;
  }
  if (typeof config.pixelSize == 'number' && config.pixelSize > 0) {
    this.pixelSize=config.pixelSize;
  }

  if (config.lang != null && ("hu_HU" == config.lang || "en_US" == config.lang)) {
    this.lang=config.lang;
  }
  if (typeof config.textareaRows == 'number' && config.textareaRows > 0) {
    this.textareaRows=config.textareaRows;
  }
  if (typeof config.textareaCols == 'number' && config.textareaCols > 0) {
    this.textareaCols=config.textareaCols;
  }
  if (typeof config.reportUrl == 'string') {
    this.reportUrl=config.reportUrl;
  }
  if (typeof config.scripts == 'string') {
    this.scripts=config.scripts;
  }
  if (typeof config.images == 'string') {
    this.images=config.images;
  }
} // BugReport.readConfig

/** Betolti azokat a JS osztalyokat, amikre szuksege van
  *
  * @static
  */
BugReport.downloadJs = function() {
  //detect kell, ez megvan 
  //useful kell, ez is, kulonben ide kellene a downloadScript

  if (typeof XMLHTTP == "undefined") {
    //xmlhttp kell
    downloadScript(this.scripts+"xmlhttp.js");
  }
  if (typeof XMLRPC == "undefined") {
    //xmlrpc kell
    downloadScript(this.scripts+"xmlrpc.js");
  }
  if (typeof DRAGDROP == "undefined") {
    //dragdrop kell
    //dragdrop-hu_HU kell
    downloadScript(this.scripts+"dragdrop.js");
    downloadScript(this.scripts+"dragdrop-"+this.lang+".js");
  }

  if (typeof PROGRESSBAR == "undefined") {
    //progressbar kell
    //progressbar-hu_HU kell
    downloadScript(this.scripts+"progressbar.js");
    downloadScript(this.scripts+"progressbar-"+this.lang+".js");
  }
} // BugReport.donwloadJs

/** Letrehozza az eszkoztar elemeit
  *
  * @static
  */
BugReport.buildToolbar = function() {
 this.newNoteButton=document.createElement("img");   
 this.newNoteButton.setAttribute("src",this.images+"bugreport_newnote.gif");
 this.newNoteButton.setAttribute("title",BugReport.I18N.text.newNoteTitle);
 this.newNoteButton.style.border="outset";
 addEvent(this.newNoteButton,"click",function(event) { BugReport.newNote(); });
// addEvent(this.newNoteButton,"mouseover",function(event) { BugReport.hoverButton(event,true); });
// addEvent(this.newNoteButton,"mouseout",function(event) { BugReport.hoverButton(event,false); });
 this.toolbar.appendChild(this.newNoteButton);

 this.colorButton=document.createElement("img");   
 this.colorButton.setAttribute("src",this.images+"bugreport_color.gif");
 this.colorButton.setAttribute("title",BugReport.I18N.text.colorTitle);
 this.colorButton.style.border="outset";
 this.colorButton.style.backgroundColor=this.pixelColor;
 addEvent(this.colorButton,"click",function(event) { BugReport.toggleColor(event); });
 this.toolbar.appendChild(this.colorButton);


 this.eraseButton=document.createElement("img");   
 this.eraseButton.setAttribute("src",this.images+"bugreport_erase.gif");
 this.eraseButton.setAttribute("title",BugReport.I18N.text.eraseTitle);
 this.eraseButton.style.border="outset";
 var eraseButton=this.eraseButton;
 addEvent(this.eraseButton,"click",function(event) { BugReport.toggleButton(event,eraseButton); });
 this.toolbar.appendChild(this.eraseButton);
 
 this.clearButton=document.createElement("img");   
 this.clearButton.setAttribute("src",this.images+"bugreport_clear.gif");
 this.clearButton.setAttribute("title",BugReport.I18N.text.clearTitle);
 this.clearButton.style.border="outset";
 addEvent(this.clearButton,"click",function(event) {
     BugReport.clear();
     });
 this.toolbar.appendChild(this.clearButton);


 this.sendButton=document.createElement("img");   
 this.sendButton.setAttribute("src",this.images+"bugreport_send.gif");
 this.sendButton.setAttribute("title",BugReport.I18N.text.sendTitle);
 this.sendButton.style.border="outset";
 addEvent(this.sendButton,"click",function(event)  {  BugReport.sendBug();      });
 this.toolbar.appendChild(this.sendButton);

 this.stopButton=document.createElement("img");   
 this.stopButton.setAttribute("src",this.images+"bugreport_stop.gif");
 this.stopButton.setAttribute("title",BugReport.I18N.text.stopTitle);
 this.stopButton.style.border="outset";
 addEvent(this.stopButton,"click",function(event)  {  BugReport.abortSendBug();      });
 this.toolbar.appendChild(this.stopButton);
 this.stopButton.style.display='none';
 
 this.busyButton=document.createElement("img");   
 this.busyButton.setAttribute("src",this.images+"bugreport_busy.gif");
 this.busyButton.setAttribute("title",BugReport.I18N.text.busyTitle);
 this.toolbar.appendChild(this.busyButton);
 this.busyButton.style.display='none';
// this.busyButton.style.verticalAlign='middle';
 

 
 this.infoButton=document.createElement("img");   
 this.infoButton.setAttribute("src",this.images+"bugreport_info.gif");
 this.infoButton.setAttribute("title",BugReport.I18N.text.infoTitle);
 this.infoButton.style.border="outset";
 addEvent(this.infoButton,"click",function(event) {
     alert(BugReport.I18N.text.info);
     });
 this.toolbar.appendChild(this.infoButton);

 this.closeButton=document.createElement("img");   
 this.closeButton.setAttribute("src",this.images+"bugreport_close.gif");
 this.closeButton.setAttribute("title",BugReport.I18N.text.closeTitle);
 this.closeButton.style.border="outset";
 addEvent(this.closeButton,"click",function(event) {
     BugReport.close();
     });
 this.toolbar.appendChild(this.closeButton);

 /*
 this.statusDiv=document.createElement("div");
 this.toolbar.appendChild(this.statusDiv);
 */
 this.colorChooser=document.createElement("div");
 var table=document.createElement("table");
 var tbody=document.createElement("tbody");
 table.setAttribute("border","1");      table.border=1;
 table.setAttribute("cellspacing","0"); table.cellPadding=0;
 table.setAttribute("cellpadding","0"); table.cellSpacing=0;
 table.style.cursor="pointer";
 table.appendChild(tbody);

 var tr=document.createElement("tr");
 tbody.appendChild(tr);
 for (var i=0; i < 256; i+=23.185) { 
   var td=document.createElement("td");
   var color="#"+dec2Hex(i)+dec2Hex(i)+dec2Hex(i);
   td.setAttribute("width",9);
   td.setAttribute("height",9); 
   td.style.backgroundColor=color;
   td.setAttribute("title",color);
   this.addColorEvent(td);
   tr.appendChild(td);
 }

 var colors=["#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF","#00FFFF"];
 for (var i=0; i < colors.length; ++i) { 
   var td=document.createElement("td");
   var color=colors[i];
   td.setAttribute("width",9);
   td.setAttribute("height",9); 
   td.style.backgroundColor=color;
   td.setAttribute("title",color);
   this.addColorEvent(td);
   tr.appendChild(td);
 }

 
 var db=0;
 for(var i=0; i < 256; i+=51) {
   for (var j=0; j < 256; j+=51) {
     for (var k=0; k < 256; k+=51) {
       if (db % 18 == 0) {
         var tr=document.createElement("tr");
         tbody.appendChild(tr);
       }
       var td=document.createElement("td");
       var color="#"+dec2Hex(i)+dec2Hex(j)+dec2Hex(k);
       td.setAttribute("width",9);
       td.setAttribute("height",9);
       td.style.backgroundColor=color;
       td.setAttribute("title",color);
       this.addColorEvent(td);
       tr.appendChild(td);
       ++db;
     }
   }   
 }

 
 this.colorChooser.appendChild(table);
 this.colorChooser.style.display="none";
 this.toolbar.appendChild(this.colorChooser);
} // BugReport.buildToolbar

/** Elkuldi a hibajelentest (osszeallitja a parametereket, xhtml forrasokat, elinditja az XML-RPC hivast)
  *
  * @static
  */
BugReport.sendBug=function() {
  //valamit ki kene rakni, hogy wait vagy valami
  //meg talan progressbart is

  var bugName=prompt(BugReport.I18N.text.bugName,"");

  if (typeof bugName == "string" && "" == trim(bugName)) {
    alert(BugReport.I18N.text.bugNameError);
  } else if (null != bugName) {
    //osszerakni a forrasokat, status es progressbar

    this.newNoteButton.style.display='none';
    this.clearButton.style.display='none';
    this.closeButton.style.display='none';
    this.eraseButton.style.display='none';
    this.sendButton.style.display='none';
    this.infoButton.style.display='none';
    this.colorButton.style.display='none';
    this.stopButton.style.display='inline';


    
    this.progress=new ProgressBar();
    this.progress.init({
        parent:       this.toolbar,
        max:          document.getElementsByTagName("*").length-this.toolbar.getElementsByTagName("*").length,
        width:        250,
        height:       50
        });

    this.progressAct=0;

    
    this.iframes=[];
    this.iframeNames=[];
    this.iframeXhtmls=[];
    this.contextData={};

    this.progress.start();
//    this.progress.update(30);
//    return;
    var xhtml=this.getXhtml(document.documentElement,true);
    if (this.iframes.length > 0) {
      for(var i=0; i<this.iframes.length; ++i) {
        var iframe=this.iframes[i];
        var iframeDoc=null;
        if (iframe.contentDocument) {
          iframeDoc=iframe.contentDocument.documentElement;
        } else if (iframe.contentWindow.document.documentElement) {   
          iframeDoc=iframe.contentWindow.document.documentElement;
        }
        if (iframeDoc) {
          this.progress.addMax(iframeDoc.getElementsByTagName("*").length);
          this.iframeXhtmls[this.iframeXhtmls.length]=this.getXhtml(iframeDoc,true,true);
        }
      }
    }
    //alert(this.progressAct+" "+document.getElementsByTagName("*").length+" "+this.toolbar.getElementsByTagName("*").length);
    this.progress.stop();
    this.progress=null;


  //  alert(window.navigator.appCodeName+"\n"+window.navigator.appName+"\n"+window.navigator.appVersion+"\n"+window.navigator.platform+"\n"+window.navigator.userAgent);  //eleg a useragent
  //  alert(window.location+" "+document.URL); //mindegy
  //  alert(document.referrer);
  //  alert(window.outerWidth+" "+window.outerHeight); //IE eseten mas kell document.documentElement.offsetWidth es height
    var width=0;
    var height=0;
    if (window.outerWidth && window.outerHeight) {
      width=window.outerWidth;
      height=window.outerHeight;
    } else if (document.documentElement.offsetWidth && document.documentElement.offsetHeight) {
      width=document.documentElement.offsetWidth;
      height=document.documentElement.offsetHeight;
    }
    var identifier="";
    var metas=document.getElementsByTagName("meta");
    for(var i=0; i < metas.length; ++i) {
      if ("Identifier" == metas[i].getAttribute("name")) {
        identifier=metas[i].getAttribute("content");
      }
    }
    var bugDescr="";
    var textareas=this.canvas.getElementsByTagName("textarea");
    for(var i=0; i < textareas.length; ++i) {
      bugDescr+=textareas[i].value+"\n\n";
    }

    
   
    var d=new Date();
    this.contextData["date"]=d.getFullYear()+"."+digit2(d.getMonth()+1)+"."+digit2(d.getDate())+". "+digit2(d.getHours())+":"
      +digit2(d.getMinutes())+":"+digit2(d.getSeconds());
    this.contextData["url"]=window.location.href;
    this.contextData["referer"]=document.referrer;
    this.contextData["userAgent"]=window.navigator.userAgent;
    this.contextData["browserWidth"]=width;
    this.contextData["browserHeight"]=height;



    
    //kuldeni a cuccot, status
   
    var config={
                functionName: "reportBug",
                //reportBug
                functionParams: [bugName,bugDescr,identifier,xhtml,this.iframeNames,this.iframeXhtmls,this.contextData],
                url: location.protocol+"//"+location.host+this.reportUrl,
                //core/xmlrpc
                asyncFlag: true,
                onError: function (e,xmlhttp) {
//                  alert("onError: "+e.message);
                  BugReport.sendError(e,xmlhttp);
                },
                callback: function (response) {
                  BugReport.sendSuccess(response);
                }              
    };

    
    this.callId=XmlRpc.call(config);       

    if (null == this.callId) {
      //nem sikerult a hivas
      alert(BugReport.I18N.text.xmlHttpError);
      this.showButtons();
    } else {
      this.busyButton.style.display='inline';
    }
  }
  
} // BugReport.sendBug

/** Az eszkoztar gombjait jeleniti meg
  * 
  * @static
  */
BugReport.showButtons=function() {
  this.newNoteButton.style.display='inline';
  this.clearButton.style.display='inline';
  this.closeButton.style.display='inline';
  this.eraseButton.style.display='inline';
  this.sendButton.style.display='inline';
  this.infoButton.style.display='inline';
  this.colorButton.style.display='inline';
  this.stopButton.style.display='none';
  this.busyButton.style.display='none';
} // BugReport.showButtons

/** A sikeres kuldes callback fuggvenye (aszinkron XML-RPC call)
  *
  * @static
  * @param int response az XML-RPC hivas eredmeny
  */
BugReport.sendSuccess=function(response) {  
  this.showButtons();

  if (0 == response) {
    alert(BugReport.I18N.text.sendSuccess);
  } else if (1 == response) {
    alert(BugReport.I18N.text.sendError1);
  }
} // BugReport.sendSuccess

/** Jelzi, hogy hiba lepett fel a hibajelentes kuldesekor 
  *
  * @static
  * @param object error a hiba objektum
  * @param object xmlhttp az xmlhttp objektum
  */
BugReport.sendError=function(error,xmlhttp) {  
  this.showButtons();

  var str=BugReport.I18N.text.sendError+error.message;
  if (null != xmlhttp) {
    str+="\nresponseText: "+xmlhttp.req.responseText;
  }
 
  alert(str);
}

/** A hibajelentes kuldeset allitja le (abort XML-RPC call)
  *
  * @static
  */
BugReport.abortSendBug=function() {  
  this.showButtons();

  XmlRpc.abort(this.callId);
//  alert(BugReport.I18N.text.abortSuccess);
} // BugReport.abortSendBug

/** Egy uj megjegyzes objektumot hoz letre
  *
  * @static
  */
BugReport.newNote = function() {
  var scrollPos=getScrollPos();
  var config = {
           parentNode: this.canvas,
           name:      "note",
           resizable: 1,                  //atmeretezheto: 0 nem, 1 igen (def: 1)
           header:    1,                  //fejlec: 0 nem, 1 igen (def: 1)           
           dragGlobal: 0,
           headerPos: 'N',                //fejlec pozicioja: N,W,S,E (def: N)
           headerText: BugReport.I18N.text.note,                //fejlec szovege (def: "header"), ha ures, akkor &nbsp; lesz benne
           headerButtons: ["size","min","normal","close"],              //fejlecben allapotgombok, ha van header: 0 nem, 1 igen (def: 1)
           headerButtonsPos: 'E',              //fejlecben a gombok balra, fent (N,W) vagy jobbra, lent (S,E) legyenek (def: E)
           borderSize: 2,                 //mennyi pixel vastag legyen a keret, ha 0, akkor nincs, nem lesz atmeretezheto!!!! (def: 2)
           state:      'normal',          //kezdeti allapot: 'normal', 'max', 'min' (def: 'normal')
           pos:        scrollPos, //kezdeti pozicio (def: 0,0)
           //width: 300,                    //kezdeti szelesseg (def: tartalomtol fugg) (border nincs benne)
           //height: 200,                   //kezdeti magassag (def: tartalomtol fugg)
           minWidth:  120,                //min allapotban a szelesseg (def: 100) csak fenti vagy lenti header eseten szamit!!!!!
           minHeight: 40,                 //min allapotban a magassag  (def: 100) csak bal vagy jobb header eseten szamit!!!!!
           images:  this.images,
           onresizeend: function (drag,e) {
             var contentSize=getSize(drag.contentDiv); //contentDiv csak scrollozo div, realContent az igazi tartalom, de most nem scrollozunk, vagyis realContent is valtozik
             setSizeMargin(drag.realContentDiv.firstChild,contentSize);
           }

  };
  var drag=new DragDrop();
  drag.initAtOnce(config,"<textarea rows='"+this.textareaRows+"' cols='"+this.textareaCols+"'></textarea>"); 
} // BugReport.newNote

/** Beallitja az esemenykezeloket
  *
  * @static
  */
BugReport.registerEventListeners = function() {
  this.resizeCanvasFunc=function(event) {
    BugReport.resizeCanvas();
  }
  this.moveToolbarFunc=function(event) {
    BugReport.moveToolbar();
  }
  
  addEvent(window,"resize",BugReport.resizeCanvasFunc);
  addEvent(window,"scroll",BugReport.moveToolbarFunc);
  
  addEvent(this.canvas,"mousemove",function(event) {
      BugReport.mousemove(event);
  });
  addEvent(this.canvas,"mousedown",function(event) {
      BugReport.mousedown(event);
  });
  addEvent(this.canvas,"mouseup",function(event) {
      BugReport.mouseup(event);
  });
} // BugReport.registerEventListeners

/** Beallitja szinvalaszto tablazat egy cella elemre az esemenykezeloket
  *
  * @static
  * @param object td a cella 
  */
BugReport.addColorEvent=function(td) {
  var bugreport=this;
  addEvent(td,"click",function(event) {
      BugReport.setColor(event,td.style.backgroundColor);
      });
  addEvent(td,"mouseover",function(event) {
      bugreport.colorButton.style.backgroundColor=td.style.backgroundColor;
      });
  addEvent(td,"mouseout",function(event) {
      bugreport.colorButton.style.backgroundColor=bugreport.pixelColor;
      });
} // BugReport.addColorEvent

/** Az szinvalaszton tortent kattintas esemenykezeloje
  *
  * @static
  * @param object event az esemeny objektuma
  * @param string color a szin #aabbcc formaban
  */
BugReport.setColor=function(event,color) {
  this.pixelColor=color;
  this.colorButton.style.backgroundColor=this.pixelColor;
  this.colorChooser.style.display='none';
} // BugReport.setColor


/** A szinvalaszto megjeleniteset vezerli
  *
  * @static
  * @param object event az esemeny objektuma
  */
BugReport.toggleColor=function(event) {
  if ('none' == this.colorChooser.style.display) {
    this.colorChooser.style.display='block';
  } else {
    this.colorChooser.style.display='none';
  } 
} // BugReport.toggleColor


/** Az eszkoztaron levo gombok allapotat allitja
  *
  * @static
  * @param object event az esemeny objektuma
  * @param obejct button a gomb node
  */
BugReport.toggleButton=function(event,button) {
  if (button.checked) {
    button.checked=false,
    button.style.border="outset";
  } else {
    button.checked=true;
    button.style.border="inset";
  } 
} // BugReport.toggleButton

/** Az eger gombjanak lenyomasanak esemenykezeloje
  *
  * @static
  * @param object event az esemeny objektuma
  */
BugReport.mousedown=function(event) {
  if ('left' == getEventButton(event)) {
    this.button='left';
    stopProp(event);
    if (ieDOM || operaDOM) {
      preventDef(event); //ez firefoxban kinyirja a focust
    }

  }
} // BugReport.mousedown

/** Az eger gombjanak felengedesenek esemenykezeloje
  *
  * @static
  * @param object event az esemeny objektuma
  */
BugReport.mouseup=function(event) { 
  if ('left' == getEventButton(event)) {
    this.button='';
    stopProp(event);
    preventDef(event);

    if (this.eraseButton.checked && this.eraserDiv) {
      //torles
      var eraseDim=getDim(this.eraserDiv);
      var canvasDivs=this.canvas.getElementsByTagName("div");
      for (var i=0; i<canvasDivs.length; ++i) {
        if ("bugreport_pixel" == canvasDivs[i].getAttribute("class")) {
          var pixel=canvasDivs[i];
          var pixelDim=getDim(pixel);

          var intersect=dimIntersectsDim(eraseDim,pixelDim);
          //inkabb pixelDim meretevel kellene osszevetni
          if (null != intersect[1]) {
            //van metszes, kell torolni            
            pixel.parentNode.removeChild(pixel); 
            --i;  //index maradjon meg
          }
        }
      }
      this.eraserDiv.parentNode.removeChild(this.eraserDiv);
      this.eraserDiv=null;
    }
  }
} // BugReport.mouseup

/** Az egermozgasi esemenykezelo, rajzolas, radirozas
  *
  * @static
  * @param object event az esemeny objektuma
  */
BugReport.mousemove=function(event) {
  if ('left' == this.button) {
    if (this.eraseButton.checked) {
      if (null == this.eraserDiv) {
        this.eraserDiv=document.createElement("div");
        this.eraserDiv.style.position="absolute";        
        this.eraserDiv.style.border="1px dotted #000";
        this.canvas.appendChild(this.eraserDiv);
        this.eraserBeginPos=getEventAbsolutePos(event);
      } else {
        var pos1=getEventAbsolutePos(event);
        var pos2={top: 0,left: 0};
        if (pos1.top < this.eraserBeginPos.top) {
          pos2.top=this.eraserBeginPos.top;
        } else {
          pos2.top=pos1.top;
          pos1.top=this.eraserBeginPos.top;
        }
        if (pos1.left < this.eraserBeginPos.left) {
          pos2.left=this.eraserBeginPos.left;
        } else {
          pos2.left=pos1.left;
          pos1.left=this.eraserBeginPos.left;
        }
        setDim(this.eraserDiv,{top: pos1.top,left: pos1.left,bottom: pos2.top,right: pos2.left});
      }

    } else {
      //rajzolas
      var p=document.createElement("div");
      p.style.width=this.pixelSize+'px'; 
      p.style.height=this.pixelSize+'px'; 
      p.style.position='absolute'; 
      p.style.fontSize='1px'; 
      p.style.backgroundColor=this.pixelColor;
///      
///      p.style.clip='rect(0,'+this.pixelSize+'px,'+this.pixelSize+'px,0)';
///       
      p.setAttribute("class","bugreport_pixel");
      
      this.canvas.appendChild(p);
      
      setPosMargin(p,getEventAbsolutePos(event),false,false);
    }


    stopProp(event);
    preventDef(event);

  }
} // BugReport.mousemove

/** A rajzolasi teruletet es a megjegyzeseket torli
  *
  * @static
  */
BugReport.clear=function() {
//  while(this.canvas.hasChildNodes()) {this.canvas.removeChild(this.canvas.firstChild)}
  this.canvas.innerHTML='';
} // BugReport.clear

/** Bezarja a bugreport toolbart, eltunteti a rajzolasi teruletet
  *
  * @static
  */
BugReport.close=function() {
  this.canvas.parentNode.removeChild(this.canvas);
  this.toolbar.parentNode.removeChild(this.toolbar);
  this.canvas=null;
  this.toolbar=null;
  removeEvent(window,"resize",BugReport.resizeCanvasFunc);
  removeEvent(window,"scroll",BugReport.moveToolbarFunc);
} // BugReport.close

/** A canvast (rajzolhato teruletet) meretezi at a body teljes meretere (onresizera hivodik meg)
  *
  * @static
  */
BugReport.resizeCanvas=function() {
  setSizeMargin(this.canvas,getBodySize());
} // BugReport.resizeCanvas

/** Az eszkoztarat mozgatja mindig az ablak tetejere (onscrollra hivodik meg)
  *
  * @static
  */
BugReport.moveToolbar=function() {
  var scrollPos=getScrollPos();
  this.toolbar.style.top=scrollPos.top+"px";
} // BugReport.moveToolbar

/** Egy iframe elemet hozzaad az ifram listahoz, es general neki egy egyedi nevet
  *
  * @static
  * @param object node az iframe html node
  * @return string az iframe generalt neve
  */
BugReport.addIframe=function(node) {
  var name="iframe"+this.iframes.length+".html";
  this.iframes[this.iframes.length]=node;
  this.iframeNames[this.iframeNames.length]=name;
  return name;
} // BugReport.addIframe

/** Ez a rekurziv fuggveny bejarja a DOM strukturat es osszeallitja az xhtml forrasat 
  *
  * @static
  * @param object node az elem, amit fel kell dolgozni
  * @param boolean outputNode az aktualis elemet be kell-e rakni az xhtml forrasba
  * @param boolean iframe az aktualis dokumentum iframe-ben van-e
  * @return string az xhtml forrasszoveg
  */
BugReport.getXhtml=function(node, outputNode,iframe) {

  function encode(str) {
    // we don't need regexp for that, but.. so be it for now.
    if (ieDOM && "string" != typeof str) {
      str=str.toString();
    }
    str=str.replace(/&/ig, "&amp;");    
    str=str.replace(/</ig, "&lt;");
    str=str.replace(/>/ig, "&gt;");
    str=str.replace(/\"/ig, "&quot;");   //&#32;
    str=str.replace(/\u00a0/ig, "&nbsp;");
    return str;
  }; //function encode()


  function noClosingTag(tag) {
    //IE:      219 node/s
    //mozilla: 480 node/s     
    /**/
    single=" area base br col frame hr img input link meta param "; //ezek egyedul allnak, a tobbinek kell lezaro!
    return (single.indexOf(" "+tag.toLowerCase()+" ") != -1);
    /**/
    /*
       //IE:      205 node/s
       //mozilla: 462 node/s
    var ret=false;
    var single=new Array("area","base","br","col","frame","hr","img","input","link","meta","param"); //ezek egyedul allnak, a tobbinek kell lezaro!
    for(var j=0;ret == false && j<single.length; j++) {
      if (single[j] == tag) {
        ret=true;
      }
    }
    return ret;
    */
  }
  
  
  var html = "";
  switch (node.nodeType) {
    case 1: // Node.ELEMENT_NODE
    case 11: // Node.DOCUMENT_FRAGMENT_NODE            
		var closed;
		var i=0;
                var tagName=node.tagName.toLowerCase();
                var namespace=false;
                var skippedNode=false;

                ++this.progressAct;
                if (this.progressAct % 20 == 0) {
                  this.progress.update(this.progressAct);
                }
                
                if ("script" == tagName || "div" == tagName && "bugreport_toolbar" == node.getAttribute("id")) {
                  skippedNode=true;
                }

                if (outputNode && false == skippedNode) {
                  if (!iframe && node == document.documentElement && document.doctype) {
                    html+='<!DOCTYPE '+document.doctype.name+' PUBLIC "'+document.doctype.publicId+'" "'+document.doctype.systemId+'">';
                    // alert(document.doctype.name+")("+document.doctype.publicId+")("+document.doctype.systemId);
                  }
                  closed=noClosingTag(tagName);
                  
                  if (/:/.test(tagName) || (ieDOM && node.scopeName.toLowerCase() != 'html')) {
                    //marpedig ami namespace-s, az nem fog bekerulni
                    namespace=true;
                  }

                  if (false == namespace) {
                    html+="<"+tagName;
                    var attrs=node.attributes;
                    for (i=0; i < attrs.length; ++i) {
                      var a=attrs.item(i);
                      if (!a.specified) {
                        continue;
                      }
                      var name=a.nodeName.toLowerCase();
                      if (nsDOM && name.substr(0,4) == "_moz") {
                        // Mozilla reports some special tags
                        // here; we don't need them.
                        continue;
                      }
                      if (name.substr(0,2) == "on") {
                        //kihagyni js esemenykezeloket
                        continue;
                      }
                      var value="";

                      if ('style' == name) {
                        //idezojelek lecserelese
                        if (operaDOM) {
                          for(var j in node.style) {
                            if (typeof node.style[j] == "string" && node.style[j]) {
                               value+=fromCamelCase(j)+": "+node.style[j].replace(/\"/ig,"'")+"; ";
                            }
                          }
                        } else {
                          value=node.style.cssText.toLowerCase().replace(/\"/ig,"'");
                        }
                        if (nsDOM) {
                          //-moz kiszedese
                          value=value.replace(/-moz.+?;/ig,"");
                        }
                      } else if ('value' == name) {
                        value=node.value;

                      } else {
                        value=a.nodeValue;  //defaultban marad                        
                        if (tagName == "img" && name == "src" || tagName == "link" && name == "href") {
                          //kep vagy stilus
                          var loc=location;
                          //ha relativ, akkor ki kell potolni, abszolutra
                          var avalue=a.value.toLowerCase();
                          if (avalue.indexOf("http://") == -1
                              && avalue.indexOf("https://") == -1
                              && avalue.indexOf("ftp://") == -1
                              && avalue.indexOf("mailto:") == -1
                              && trim(avalue).charAt(0) != "#"
                              ) {
                              //ez bizony relativ
                            value="http://"+loc.host+(a.value.charAt(0)=="/"?"":"/")+a.value; // "/" ha kell
                          }
                        } //href,src
                      }

                      if (nsDOM && (value.substr(0, 4) == "_moz" || value.substr(0, 4) == "-moz")) {
                        // Mozilla reports some special tags
                        // here; we don't need them.
                        continue;
                      }
                      html+=" "+name+'="'+encode(value)+'"';
                    }
                    if (ieDOM && tagName == 'input') {
                      //valamiert IE nem rakja be az input value-t
                      html+=' value="'+encode(node.getAttribute("value"))+'" ';
                    }
                    if (tagName == 'iframe' && !node.getAttribute("src")) {
                      //htmlarea iframe, relativ src-t neki!
                      var iframeName=this.addIframe(node);
                      html+=' src="'+iframeName+'"';
                    }

                    html+=closed ? " />" : ">";

                  } //namespace
                } //outputnode
                if (false == skippedNode) {
                  if ("head" == tagName && true == iframe) {
                    //charset beszurasa: <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
//                    html+='<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>';
                    if (document.characterSet) {
                      html+='<meta http-equiv="Content-Type" content="text/html; charset='+document.characterSet+'"/>';
                    } else if (document.charset) {
                      html+='<meta http-equiv="Content-Type" content="text/html; charset='+document.charset.toUpperCase()+'"/>';
                    }
                  }

                 
                  if ("textarea" == tagName) {
                    html+=encode(node.value);
                  } else {
                    for (i=0; i<node.childNodes.length; ++i) {
                      html+=this.getXhtml(node.childNodes[i], true,iframe);
                    }
                  }
                }                
                if (false == namespace && outputNode && !closed && false == skippedNode) {
                  /*
                  if (!iframe && node == document.documentElement) {                    
                    var width=0;
                    var height=0;
                    if (window.outerWidth && window.outerHeight) {
                      width=window.outerWidth;
                      height=window.outerHeight;
                    } else if (document.documentElement.offsetWidth && document.documentElement.offsetHeight) {
                      width=document.documentElement.offsetWidth;
                      height=document.documentElement.offsetHeight;
                    }
                    html+="<script type='text/javascript'>window.resizeTo(100,100);</script>";
                    html+="<script type='text/javascript'>window.resizeTo("+width+","+height+");</script>";
                  }
                  */
                  html+="</"+tagName+">";
                }
                break;
    case 3: // Node.TEXT_NODE
                  html=encode(node.data);   //root.nodeValue
            
//                  alert(root.data);
                  break;
    case 8: // Node.COMMENT_NODE
//		html = "<!--" + root.data + "-->";
		break;		// skip comments, for now.
  }
  return html;
} // BugReport.getXhtml

