var faderPic=0;
function imageFader(){  
    var pic=$('img'+faderPic);
    if (faderPic==3) {
      faderPic=-1;
    }  
    var picPlus=$('img'+(faderPic+1));
    pic.tween('opacity', [1, 0]);
    picPlus.tween('opacity', [0, 1]);  
    faderPic++;  
   }
window.addEvent('domready', function() {
  if (document.location.href=='http://www2.comteam.at/content_home_6226.html'){
    window.setInterval("imageFader()",8000);
  }
  
   if ($('anfrage')){
        submit=new Element('input', {'class': 'submit','type': 'button', 'value': 'Anfrage absenden'}).inject($('anfrage'));        
        submit.addEvent('click', function(){        
          submit.setProperty('disabled','true');
          submit.set('value', 'Daten werden gesendet ...');
          jsonRequest=new Request.JSON({'async':false,encoding:'utf-8',noCache:true,url: '/json/mailer.php',onSuccess: function(responseJSON, responseText){
            submit.removeProperty('disabled');
            if (responseJSON.error){
              $each(responseJSON.error,function(obj,ind){          
                $(obj).addClass('error');          
              });
            }
            if (responseJSON.success){
              $each(responseJSON.success,function(obj,ind){
                $(obj).removeClass('error');
              });
            }
            submit.set('value', 'Anfrage absenden');
            if (responseJSON.error){
              //alert(responseJSON.error);
            } else {              
              submit.setProperty('disabled','true');
              submit.set('value','Anfrage absenden');              
              thanx=new Element('div', {'html': 'Vielen Dank f&uuml;r Ihre Anfrage'}).inject($('containerContent'));
              $('anfrage').destroy();              
            }
          }}).send({method: 'post',data: $('anfrage').toJSON()}); 
        });
   }
});
function domainCheck(){
  domainForm = new Element('form', {'id':'domainForm'}).inject($('containerContent'));
  domainContainer = new Element('div', {'class':'domainContainer', 'html':'Ihre Wunschdomain'}).inject(domainForm);  
  domainInput=new Element('input', {'name':'domainInput','id': 'domainInput', 'class': 'domainInput','type': 'text', 'value': 'www.beispiel.com'}).inject(domainContainer);
  domainSubmit=new Element('input', {'class': 'domainSubmit','type': 'button', 'value': 'überprüfen'}).inject(domainContainer);
  domainResults=new Element('div', {'id':'domainResults','class': 'domainResults'}).inject(domainForm);
  
  domainSubmit.addEvent('click', function(){        
    domainResults.empty();
    domainSubmit.setProperty('disabled','true');
    domainSubmit.set('value', 'Domain wird geprüft ...');
    jsonRequest=new Request.JSON({'async':false,encoding:'utf-8',noCache:true,url: '/domaincheck/json/check.php',onSuccess: function(responseJSON, responseText){      
      domainSubmit.removeProperty('disabled');      
        if (responseJSON.error){
          domainResults.set('html',responseJSON.error);
        }
        if (responseJSON.success){
          $each(responseJSON.success,function(obj,ind){
            new Element("div", {'class':'domainSuccess','html':obj}).inject($('domainResults'));
          });
        }
        if (responseJSON.failed){
          $each(responseJSON.failed,function(obj,ind){
            new Element("div", {'class':'domainError','html':obj}).inject($('domainResults'));
          });
        }       
        domainSubmit.set('value', 'überprüfen');        
    }}).send({method: 'post',data: $('domainForm').toJSON()});
  });
}
Element.implement({
    toJSON: function(){
        var json = {};
        this.getElements('input, select, textarea', true).each(function(el){
            if (!el.name || el.disabled || el.type == 'submit' || el.type == 'reset' || el.type == 'file') return;
            var value = (el.tagName.toLowerCase() == 'select') ? Element.getSelected(el).map(function(opt){
                return opt.value;
            }) : ((el.type == 'radio' || el.type == 'checkbox') && !el.checked) ? null : el.value;
            $splat(value).each(function(val){
                if (typeof val != 'undefined') {
                    json[el.name] = val;
                }
            });
        });
        return json;
    }
});
