/** 
 Chack the EventHandler. 
 If some hanler exists than overwrite it with myown
*/
function UpdateEventHandler(strEvent, sFunName){
  /*make varible with temporary handler content*/
  eval("var tHandler="+strEvent+";");
  /*
   * check if the function is allready exists, than try to rewrite it
   * if handler is non emty then add some actions
   */
  if(typeof(tHandler)=='function'){
    tHandler=tHandler.toString();
    var sArgName="";

    /*check for the argument name in the parent handler*/
    var iFirstRound=tHandler.indexOf("(");
    if(iFirstRound>-1){
      var iLastRound=tHandler.indexOf(")", iFirstRound);
      sArgName=tHandler.substring(iFirstRound+1, iLastRound);
    }
    /*Find last brace - the end of the handler body*/
    var iLastBrace=tHandler.lastIndexOf("}");
    /*
     * check the presence of our own handler already in the handler
     * bacause of the possible recurtion `\n` use as markers
     */
    if(tHandler.indexOf(sFunName+"("+sArgName+");\n")==-1 && tHandler.indexOf("function "+sFunName+"("+sArgName+")")==-1){
      /*
       * insert our function into the body of the handler
       * `\n` just in case if there is no semicolon at the last 
       */
      tHandler=tHandler.substring(iLastBrace, 0)+"\n"+sFunName+"("+sArgName+");\n}";
      //alert("1:\n"+strEvent+"="+tHandler+";");
      eval(strEvent+"="+tHandler+";");
    }
  }else if(typeof(tHandler)=='string' && tHandler.length>0){
    /*
     * Create null call function
     */
    eval(strEvent+"=function(event){"+tHandler+"\n"+sFunName+"(event);\n}");
    //alert("2:\n"+strEvent+"=function(event){"+tHandler+"\n"+sFunName+"(event);\n}");
  }else{
    //alert("3:\n"+strEvent+"="+sFunName+";");
    eval(strEvent+"="+sFunName+";");
  }

}
/*==============================*/

/*Resize images*/
function SynImg(){
  /*Get all cells to check for my class SynFeedOut*/
  if(typeof(document.getElementsByTagName)=='undefined'){
    return; //catch old browsers such as IE 4.01 and older
  }
  var aTObj=document.getElementsByTagName('TD');
  for(var p=0; p<aTObj.length; p++){
    if(aTObj[p].className=="SynFeedOut"){
      var aImgObj=aTObj[p].getElementsByTagName('IMG');
      /** hide all images to calculate real width of the HTML Syndication Feed*/
      for(var k=0; k<aImgObj.length; k++){
        aImgObj[k].SynWidth=aImgObj[k].offsetWidth;     /*save the offset Netscape 6.2 brokes the offsetWidth after display='none'*/
        aImgObj[k].SynDisplay=aImgObj[k].style.display; /*save the display of teh object */
        aImgObj[k].style.display='none';                /*hide the IMG object*/
      }
      
      /*Calculate the real size of the feed parent TABLE tag*/
      var tMax=aTObj[p].parentNode.parentNode.parentNode.offsetWidth;

      /*process images of teh feed*/
      for(var k=0; k<aImgObj.length; k++){
        /*Resize the image if necessary*/  

        if(aImgObj[k].SynWidth>tMax && aImgObj[k].SynDisplay!='none'){
          aImgObj[k].width=tMax;
        }
        /*show the object as it was*/
        aImgObj[k].style.display=aImgObj[k].SynDisplay;
      }
      /*if more than one feeed on the page process them only once*/
      aTObj[p].className+="i";
    }
  }
}

