/**
* GooInt
von Chris Leipold
*/

function prepareSearch() {
  if ($('regions')) {
    var countries = $('countries').getElementsByTagName('OPTION');
    for (var i=0, il=countries.length; i<il; i++) {
      var country = countries[i];
      country.style.backgroundImage = 'url(http://www.roadsoap.com/fileadmin/templates/img_common/flags/' + country.getAttribute('VALUE').toLowerCase() + '.png)';
    }
  	setRegion($('regions').options[$('regions').selectedIndex].text);
    $('regions').onchange = function() {
    	setRegion(this.options[this.selectedIndex].text);
    }
    
    var leo = document.createElement('img');
    leo.setAttribute('src', 'http://www.roadsoap.com/fileadmin/templates/img_common/leo.gif');
    leo.setAttribute('alt', 'LEO');
    leo.setAttribute('title', 'Online-Dictionary: Suchwort mit LEO übersetzen');
    leo.style.cursor = 'pointer';
    leo.style.position = 'relative';
    leo.style.top = '3px';
    leo.style.marginRight = '5px';
    leo.onclick = function() {window.open("http://pda.leo.org/?search="+$('q').value);};
    /*leo.observe('click', function(event){
      window.open("http://pda.leo.org/?search="+$('q').value);
    });
*/
     $('googleint').insertBefore(leo, $('googleint').firstChild);
     
     var cxe = document.createElement('img');
     cxe.setAttribute('src', 'http://www.roadsoap.com/fileadmin/templates/img_common/xe.gif');
     cxe.setAttribute('alt', 'XE');
     cxe.setAttribute('title', 'Währungsumrechner: Suchsumme in Fremdwährung umrechnen');
     cxe.style.cursor = 'pointer';
     cxe.style.position = 'relative';
     cxe.style.top = '3px';
     cxe.style.marginRight = '10px';
     cxe.onclick = function() {window.open("http://www.xe.com/ucc/convert.cgi?From=EUR&To=USD&Amount="+$('q').value);};
     /*
     cxe.observe('click', function(event){
       window.open("http://www.xe.com/ucc/convert.cgi?From=EUR&To=USD&Amount="+$('q').value);
     });
     */
     $('googleint').insertBefore(cxe, $('googleint').firstChild);
  }
}


function setRegion(sRegion) {
	var oOptgroups = $('countries').getElementsByTagName("OPTGROUP");
  for (var i=0; i<oOptgroups.length; i++) {
  	if (oOptgroups[i].getAttribute("LABEL") != sRegion) oOptgroups[i].style.display = 'none';
  	else {
  		oOptgroups[i].getElementsByTagName("OPTION")[0].selected = true;
  		oOptgroups[i].style.display = '';
  	}
  }
}

function createRegionDrop() {
  oCountries = $('regions').cloneNode(true);
  $('regions').setAttribute("id", "countries");
  var oOptgroups = $('countries').getElementsByTagName("OPTGROUP");
  for (var i=0; i<oOptgroups.length; i++) {
    oLi = document.createElement("OPTION");
    oLi.appendChild(document.createTextNode(oOptgroups[i].getAttribute("label")));
    $('countries').appendChild(oLi);
  }
  for (var i=0; i<$('countries').childNodes.length; i++) {
    if ($('countries').childNodes[i].nodeName=="OPTGROUP") {
      $('countries').removeChild($('countries').childNodes[i]);
      i--;
    }
  }
  $('countries').onchange = function() {
    createCountriesDrop(this.options[this.selectedIndex].text, oCountries);
  }
}

function createCountriesDrop(sRegion, oDrop) {
	var oOptgroups = oDrop.getElementsByTagName("OPTGROUP");
  for (var i=0; i<oOptgroups.length; i++) {
    if (oOptgroups[i].getAttribute("LABEL") == sRegion) {
    	var oOptions = oOptgroups[i].getElementsByTagName("OPTION");
    	for (var j=0; j<oOptions.length; j++) {
    		oDrop.appendChild(oOptions[j]);
    		j--;
    	}
    }
  }
  for (var k=0; k<oDrop.childNodes.length; k++) {
    if (oDrop.childNodes[k].nodeName=="OPTGROUP") {
      oDrop.removeChild(oDrop.childNodes[k]);
      k--;
    }
  }
  $('countries').parentNode.insertBefore(oDrop,$('countries').nextSibling);
}


sfHover = function() {
	var sfEls = document.getElementById("mainnavi").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
		  var oElt = this;
		  aktiv = window.setTimeout(function() {oElt.className=oElt.className.replace(new RegExp(" sfhover\\b"), "");}, 100);
		}
	}
}

prepareSearch();

//if (window.attachEvent) window.attachEvent("onload", );



