// Ladebild vorladen
load_img = new Image();
load_img.src = '/img/aload.gif';

function request(urlPath, pst) {
  http_request = false;
  position = pst;

  // Mozilla, Safari,...
  if (window.XMLHttpRequest) {
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType) {
      http_request.overrideMimeType('text/xml');
    }
  } 
  
  // IE
  else if (window.ActiveXObject) { 
    try {
      http_request = new ActiveXObject("Msxml2.XMLHTTP");
    } 
    catch (e) {
      try {
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {}
    }
  }

  if (!http_request) {
    alert('Kann keine XMLHTTP-Instanz erzeugen');
    return false;
  }
  http_request.onreadystatechange = show;
  http_request.open('GET', urlPath, true);
  http_request.send(null);
}


function show() {
  // Contentbox speichern
  switch(position) {
    case "bottom":
      var contentBox = document.getElementById("cont_bott");
      break;
    case "contactBottom":  
      var contentBox = document.getElementById("show_top");
      break;
    default:
      var showTop = true;
      var contentBox = document.getElementById("cont_top");
      break;
  }       
  // Styleeigenschaften ueberschreiben
  if(http_request.readyState == 1) {    
    contentBox.removeAttribute("style", 0);    
    contentBox.style.overflow = "hidden";
    if(position == "contactBottom") {      
      contentBox.removeAttribute("style", 0);      
      contentBox.style.borderBottom = "1px #999999 solid";
      contentBox.style.padding = "15px";
      contentBox.style.marginBottom = "10px";      
    }
  }
  
  if (http_request.readyState == 4) {
    if (http_request.status == 200) {      
      // geladenen Contetn einfuegen
      if(position == "close") {                        
        contentBox.removeChild(contentBox.firstChild);
        contentBox.removeAttribute("style");        
        contentBox.style.backgroundImage = "url(/media/image/14.jpg)";
        contentBox.style.backgroundRepeat = "no-repeat";
        contentBox.style.overflow = "hidden";
      }
      else {        
        //alert(http_request.responseXML.firstChild);
        //contentBox.replaceChild(http_request.responseXML.firstChild, contentBox.firstChild);
        contentBox.innerHTML = http_request.responseText;
      }
    }
    else {
      alert("HTTP-Code: "+http_request.status);
    }      
  }
  else {    
    switch(position) {
      case "":
        contentBox.innerHTML = '<img src="img/aload.gif" alt="loading..." style="margin-left:375px; margin-top:150px;" />';
        break;
      case "bottom":
        contentBox.innerHTML = '<img src="img/aload.gif" alt="loading..." style="margin-left:375px;" />';
        break;
      case "contactBottom":
        if(document.getElementById("contactload"))
          document.getElementById("contactload").innerHTML = '<img src="img/aload.gif" style="margin-left:5px; alt="loading..." />';
        break;        
      default:
        if(showTop == true)
          contentBox.innerHTML = '<img src="img/aload.gif" alt="loading..." style="margin-left:375px; margin-top:150px;" />';
    }
  }  
}


function sendContact() {
  var sendURL = '';

  // URL Parameter ermitteln
  var fm = document.forms.contactform.elements;  
  sendURL += "/beschreibung/" + fm.beschreibung.value.replace("/", "|");
  sendURL += "/nachname/" + fm.nachname.value.replace("/", "|");
  sendURL += "/unternehmen/" + fm.unternehmen.value.replace("/", "|");
  sendURL += "/telefonnummer/" + fm.telefonnummer.value.replace("/", "|");
  sendURL += "/email/" + fm.email.value.replace("/", "|");  
  sendURL += "/contactformsubmit/1";
  
  if(fm.website.checked)
    sendURL += "/website/1"
  if(fm.payment.checked)
    sendURL += "/payment/1"
  if(fm.datenbank.checked)
    sendURL += "/datenbank/1"
  if(fm.smsemail.checked)
    sendURL += "/smsemail/1"
  if(fm.verbaende.checked)
    sendURL += "/verbaende/1"
  if(fm.cms.checked)
    sendURL += "/cms/1"
  if(fm.dvis.checked)   
    sendURL += "/dvis/1"
  if(fm.sonstige.checked)   
    sendURL += "/sonstige/1"  
  request("/internetagentur-berlin.php/cat/45"+sendURL, "contactBottom");    
}


function sendRecommend() {
  var sendURL = '';

  // URL Parameter ermitteln
  var fm = document.forms.recommendform.elements;  
  sendURL += "/rid/" + fm.rid.value;
  sendURL += "/f_sname/" + fm.f_sname.value.replace("/", "|");
  sendURL += "/f_rname/" + fm.f_rname.value.replace("/", "|");
  sendURL += "/f_remail/" + fm.f_remail.value.replace("/", "|");
  sendURL += "/f_semail/" + fm.f_semail.value.replace("/", "|");
  sendURL += "/recommend_submit/1";
  
  request("/internetagentur-berlin.php/cat/48"+sendURL, "contactBottom");    
}


function clearstring(str) {
  str = str.replace('&nbsp;', " ");
  str = str.replace('&amp;',  "&");
  str = str.replace('&Uuml;', "U");
  str = str.replace('&uuml;', "u");
  str = str.replace('&Auml;', "A");
  str = str.replace('&auml;', "a");
  str = str.replace('&Ouml;', "O");
  str = str.replace('&ouml;', "o");   
  return str;
  }