$(document).ready(function(){
  
  $().keyup(function(event) {
   
    if( event.keyCode == 13){
      $('#perform-checks').click();
    }
    
  });
    
   $('#checks-ok').hide();
  
  $('#perform-checks').click( function(){
	  
	  $('#checks-ok').hide();
	  
	  $('#check-loader').css({ 'marginTop' : '59px', 'backgroundColor' : '#fff', 'height' : $("table.normal").height() + 'px' }).show();
	  $('#perform-checks').fadeOut(500);		
	  //$('#check-loader').fadeTo(2000, 0.0); 
  	  
	  //$('#check-loader').fadeTo(5000, 0.7);
         // $('form').fadeTo(2000, 0.4);
	 //$('form').hide();
    
    serial =  $('form :input').serialize();
        
    $.post("http://mailing.servxs.net/customers/ajax/checkInput.php", serial,
        function(data){
          
  	  $('#check-loader').hide();
	  //$('form').fadeTo(2000, 1.0);
         //$('form').show();
	  
          if(data.ok == "J")
          {
              tot = 0;
              good = 0;
            
             $.each( data.respons, function(a,b){
             dingetje = "#" + a + "check";
              
              tot++;
              if( b == true ){
                $(dingetje).css("border", "2px solid green");
                //$(dingetje).attr("READONLY", true);
                good++;
              }
              if( b == false ){
                $(dingetje).css("border", "2px solid red").focus();
				
              }
              if( b == "o"){
                $(dingetje).css("border", "2px solid yellow").focus();   
              }
             });
             
               if( good == tot){
               $('#check-agree').fadeIn(500);
               }else{
			$('#perform-checks').fadeIn(500);		
	       }
            
          }
        }, "json");
    
    
    
    });
    
  
  $('#aol-ja').click( function(){
    $('#wsdlcheck').hide();
    $('.wsdl-info').html("Niet van toepassing");
    $('#wsdlcheck').val("");
    $('#wsdlcheck').attr("readonly", true);
    $('#wsdlcheck').css("color", "grey");
    $('#usercheck').focus();
  });
  
  $('#aol-nee').click( function(){
    $('#wsdlcheck').show();
    $('.wsdl-info').html("");
    $('#wsdlcheck').val("");
    $('#wsdlcheck').attr("readonly", false);
    $('#wsdlcheck').css("color", "black");
    $('#wsdlcheck').focus();
  });

  
});


function profitCall( ivar, evar )
{
  
  if( ivar == -1 )
  {
	if( confirm("Uw profit omgevings is nog niet (juist) geconfigureerd, wilt u dit direct doen?") )
       {
            window.location.href = "http://mailing.servxs.net/customers/?mod=X3A%3D";
       }
	return;
  }
  
  $("#d-address").attr("value", "");
  
  $('#profit-image-'+evar).find("img").attr("src", "images/loader3.gif");
  $('#profit-image-'+evar).attr("disabled", true);
 
  // Do the profitcall
  bla = $("#lijst-option-"+evar).attr("selected", true);
  
  $.post("http://mailing.servxs.net/customers/ajax/profitCall.php", {} ,function(data){
	
	$("#d-address").attr("value", data.data);
	
	$('#profit-image-'+evar).find("img").attr("src", "images/profiticon-check.png");
	$('#profit-image-'+evar).attr("disabled", false);
	
  }, "json");


}




