// JavaScript Document
    //insert_after
    //klammer_auf  //string to be put before the currency select box - HTML allowed
    //klammer_zu   //a string to be put after the calculated value - HTML allowed
    //originalpreis_id //the id of the span containing the original price
    //ajaxloader_src="/ajax-loader(2).gif"; //the path to the temporary image appearing in the place of the select box while the the xml is downloaded and processed
    //select_font_size="9px"; //font size for the entries in the select box   
    //select_font_family="trebuchet ms"; //font face for the entries in the select box
    //select_font_weight="bold";  //font weight for the entries in the select box
    //select_font_color="#000000"; //font colour of the entries in the select box
    //default_currency="GBP"; // pre-selected currency - has to be one from the following array
    var my_currs=new Array("DKK","EEK","GBP","LTL","LVL","SEK","CHF","NOK","TRY","AUD","BRL","CAD","MXN","NZD","ZAR");
    // possible values according to the present xml contents from the EZB
    // var mycurrs=new Array("USD","JPY","BGN","CZK","DKK","EEK","GBP","HUF","LTL","LVL","PLN","RON","SEK","CHF","NOK","HRK","RUB","TRY","AUD","BRL","CAD","CNY","HKD","IDR","INR","KRW","MXN","MYR","NZD","PHP","SGD","THB","ZAR");
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    klammerauf = (typeof(klammer_auf) != "undefined") ? klammer_auf :  " ( "; //default text before the select box
    klammerzu = (typeof(klammer_zu) != "undefined") ? klammer_zu :  " ) ";  //default text after the calculated value;	
    originalpreisid = (typeof(originalpreis_id) != "undefined") ? originalpreis_id : "orig_price"; //default id of the span containing the original price
    insertafter = (typeof(insert_after) != "undefined") ? insert_after : originalpreisid;
    ajaxloadersrc = (typeof(ajaxloader_src) != "undefined") ? ajaxloader_src :  "/ajax-loader(2).gif"; //default ajax-loader image path
    selfontsize = (typeof(select_font_size) != "undefined") ? select_font_size :  ""; //default font size of the options in the selected box
    selfontfamily = (typeof(select_font_family) != "undefined") ? select_font_family : ""; //default font family for the entries in the select box
    selfontweight=(typeof(select_font_weight) != "undefined") ? select_font_weight : ""; //default font weight of the entries in the select box   
    selfontcolor=(typeof(select_font_color) != "undefined") ? select_font_color : "";  //default font color of the entries in the select box
    defaultcurrency=(typeof(default_currency) != "undefined") ? default_currency : "GBP";  //default currency selected in the select box  
    var mycurrs = (typeof(my_currs) != "undefined") ? my_currs : new Array("USD","JPY","BGN","CZK","DKK","EEK","GBP","HUF","LTL","LVL","PLN","RON","SEK","CHF","NOK","HRK","RUB","TRY","AUD","BRL","CAD","CNY","HKD","IDR","INR","KRW","MXN","MYR","NZD","PHP","SGD","THB","ZAR");
    ///////////////////////////////////
    ajaximgid="ajaximg";     
    newpriceid="new_price";  
    document.write("<img id='" + ajaximgid + "' src='" + ajaxloadersrc + "'>");    
    var httpRequestObject;       
    var kurs=new Object();   
    selectloaded=false;      
    function isInMyCurrs(str) //prüft ob str im Array mycurrs enthalten ist.
    { answer=false;          
      for (var g=0; g<mycurrs.length; g++)
      { if (mycurrs[g]==str) 
        { answer=true;       
          break;             
        }                    
      }                      
      return answer;         
    }                        
   function initajax()  //Initialisiert und tartet den Request     
   {  try                    
      { httpRequestObject = (navigator.appName == "Microsoft Internet Explorer") ? new ActiveXObject ("Microsoft.XMLHTTP") : new XMLHttpRequest ();
        httpRequestObject.open ('GET', '/getecbxml.php'); 
        httpRequestObject.onreadystatechange = handleReadyStateChange;
        httpRequestObject.send (null);
      }                      
      catch (err) { deleteAjaxImg(); }
             
   } 
   function handleReadyStateChange () // Request Objekt Handler
    { if (httpRequestObject) 
      { if (httpRequestObject.readyState == 4 && httpRequestObject.status == 200) xml_update_kurs (httpRequestObject.responseXML);
        if (httpRequestObject.readyState == 4 && httpRequestObject.status != 200) { deleteAjaxImg();}
      } 
      else deleteAjaxImg();                
    }
   function deleteAjaxImg() //funktion zum Entfernen vom ajax-loader-Image
   {  if (document.getElementById(ajaximgid))
      { var pic = document.getElementById(ajaximgid);
        pic.parentNode.removeChild(pic);
      }
   } 
    function xml_update_kurs(responseXML) //liest die Werte aus der responseXML in das globale Objekt kurs:
    { var x=false;
      kurs = new Object();
      var currencies = new Array();
      currencies = responseXML.getElementsByTagName ('Cube'); 
      for(var t=0; t<currencies.length; t++)
      { if (currencies[t].getAttribute('currency')!=null && currencies[t].getAttribute('rate')!=null && isInMyCurrs(currencies[t].getAttribute('currency')))
        {  kurs[currencies[t].getAttribute('currency')]=currencies[t].getAttribute('rate');
           x=true;
        }              
      }
      if (x==true) loadselect();
    } 
    function loadselect()   //erstellt dynamische Objekte einschl. Select-Box und ausgabe spans direkt nach dem span mit dem Originalpreis
    { if (selectloaded==false)
      { deleteAjaxImg(); // ajax-loader-Image abstellen.      
        var orig_price=document.getElementById(originalpreisid);
		var ins_after=document.getElementById(insertafter);
        if (orig_price && ins_after)
        {   var origpr=orig_price.firstChild.data*1;
            if (!isNaN(origpr)) //der zu konvertierende Preis kann ermittelt werden - erzeuge die dynamischen Objekte 
            { var nbsp=document.createElement("span");
              nbsp.innerHTML=klammerauf;
              var nbsp1=document.createElement("span");
              nbsp1.innerHTML=klammerzu;
              var newcontainer=document.createElement("span");
              newcontainer.setAttribute("id","newcontainer");
              var spannewprice=document.createElement("span");
              spannewprice.setAttribute("id",newpriceid);
              var sel=document.createElement("select");
              if (selfontsize) sel.style.fontSize=selfontsize;
              if (selfontfamily) sel.style.fontFamily=selfontfamily;
              if (selfontweight) sel.style.fontWeight=selfontweight;
              if (selfontcolor) sel.style.color=selfontcolor;
              for(var curr in kurs)
              { var opt=document.createElement("option");
                opt.innerHTML=curr;
                opt.setAttribute("value",curr);
                if (curr==defaultcurrency) opt.setAttribute("selected","selected");
                sel.appendChild(opt);
              }
              sel.onchange=function(){umrechnen(this.options[this.selectedIndex].value);}
              newcontainer.appendChild(nbsp);         
              newcontainer.appendChild(sel);         
              newcontainer.appendChild(spannewprice);
              newcontainer.appendChild(nbsp1);
              ins_after.parentNode.insertBefore(newcontainer,orig_price.nextSibling);         
              umrechnen(defaultcurrency);
              selectloaded=true;  
            }
            //sonst keine dyn. Objekte      
        }
        //else alert("Can't create the new elements: the span with id='" + originalpreisid + "' is missing.");        
      }
    }
   function umrechnen(newcurr) //sucht im glob. Objekt kurs nach der eingenschaft newcurr und schreibt deren Wert in den span 'newpricespan'
    { var origpricespan;
      var newcurrencyspan;
      var newpricespan;
      origpricespan=document.getElementById(originalpreisid);      
      newpricespan=document.getElementById(newpriceid);
      if (origpricespan && newpricespan)
      { var origpr=origpricespan.firstChild.data*1;
        var np=Math.round(origpr*kurs[newcurr]*100)/100 + "";
        if (np.indexOf('.')<0) np=np+".00";
        else if (np.length-np.indexOf('.')==2) np=np+"0";
		if (newpricespan.firstChild) newpricespan.removeChild(newpricespan.firstChild);
		var npr = document.createTextNode(np);
		newpricespan.appendChild(npr);
        //newpricespan.innerHTML=0;//np;
      } 
      //else alert("Can't calculate the price: the spans with id='" + originalpreisid + "' or  id='" + newpriceid + "' are missing.");         
    }     
   window.setTimeout('initajax()', 700); 
