                     currentLineIsBlank = false;
                 }
             } // end if (client.available())
+            else{
+             client.stop(); 
+            }
         } // end while (client.connected())
         delay(1);      // give the web browser time to receive the data
         client.stop(); // close the connection
     } // end if (client)
 }
 
+void respondToRequest(EthernetClient client, String & request){
+    //String request = String(req);
+    Serial.print("request: ");
+    Serial.println(request);
+    Serial.println("</request>");
+    
+    
+    String findLED = String("blinkLED");
+    String findAJAXJSON = "myajax";
+    String findAJAXHTML = "ajaxtest";  
+  
+    int loc = request.indexOf(findLED);
+    if( loc > -1){
+      Serial.print("turning on or off b/c of ");
+      Serial.print(findLED);
+      Serial.print(" found at ");
+      Serial.print(loc);
+      client.println("HTTP/1.1 200 OK");
+      client.println("Content-Type: text/html");
+      client.println("Connection: close");
+      //client.println("Refresh: 1");
+      client.println();
+      client.println("<!DOCTYPE html>");
+      client.println("<html>");
+      client.println("<head>");
+      client.println("<title>Arduino LED Control</title>");
+      client.println("</head>");
+      client.println("<body>");
+      client.println("<h1>LED</h1>");
+     /* if(request.indexOf("on=1") > -1){
+         LED_status = 1;
+          client.println("<h2>ON</h2>");
+      }
+      if(request.indexOf("on=0") > -1){
+         LED_status = 0;
+         client.println("<h2>OFF</h2>");
+      }*/
+      LED_status = -( LED_status-1);
+    }
+    else if(request.indexOf(findAJAXJSON) > -1){
+      client.println("<data>hi</data>");
+      client.println("<status>good</status>");
+    }
+    else if(request.indexOf(findAJAXHTML)>-1){
+      char myString[] = "<!DOCTYPE html>"
+                  "<html> "
+                  "<head> "
+                  "*<script src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js\"></script>"
+                  "<script>"
+                  "$(document).ready(function(){"
+                  "    $(\"button\").click(function(){"
+                  "        $.get(\"192.168.1.10/?myajax=1\", function(data, status){"
+                  "            alert(\"Data: \" + data + \"\nStatus: \" + status);"
+                  "        });"
+                  "    });"
+                  "});"
+                  "</script>"
+                  "</head>"
+                  "<body>"
+                  ""
+                  "<button>Send an HTTP GET request to a page and get the result back</button>"
+                  ""
+                  "</body>"
+                  "</html>";
+        client.println(myString);
+    }
+    else{
+           char myString[] = ""
+                  "HTTP/1.1 200 OK\n"
+                  "Content-Type: text/html\n"
+                  "Connection: close\n"
+                  "\n"
+                   "<!DOCTYPE html>\n"
+                  "<html> \n"
+                  "<body>\n"
+                  "\n"
+                  "<h1> default result! </h1>\n"
+                  "\n"
+                  "</body>\n"
+                  "</html>\n";
+           client.print(myString);
+           Serial.print(myString);
+    }
+   
+}
+/*
 void processButton(EthernetClient cl){
       
     BTN_status = digitalRead(buttonPin);

        while (client.connected()) {
            if (client.available()) {   // client data available to read
                char c = client.read(); // read 1 byte (character) from client
                HTTP_req += c;  // save the HTTP request 1 char at a time
                // last line of client request is blank and ends with \n
                // respond to client only after last line received
                if (c == '\n' && currentLineIsBlank) {
                    // send a standard http response header
                    client.println("HTTP/1.1 200 OK");
                    client.println("Content-Type: text/html");
                    client.println("Connection: close");
                    client.println();
                    // send web page
                    client.println("<!DOCTYPE html>");
                    client.println("<html>");
                    client.println("<head>");
                    client.println("<title>Arduino LED Control</title>");
                    client.println("</head>");
                    client.println("<body>");
                    client.println("<h1>LED</h1>");
                    client.println("<p>Click to switch LED on and off.</p>");
                    client.println("<form method=\"get\">");
                    ProcessCheckbox(client);
                    client.println("</form>");
                    
                    processButton(client);
                    
       
                    client.println("</body>");
                    client.println("</html>");
                    Serial.print(HTTP_req);
                    HTTP_req = "";    // finished with request, empty string
                    break;
                }
                // every line of text received from the client ends with \r\n

      cl.println("<h3> button not pressed </h3>");
    } 
    
}
void printSite(EthernetClient client){
  client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();
// send web page
client.println("<!DOCTYPE html>");
client.println("<html>");
client.println("<head>");
client.println("<title>Arduino LED Control</title>");
client.println("</head>");
client.println("<body>");
client.println("<h1>LED</h1>");
client.println("<p>Click to switch LED on and off.</p>");
client.println("<form method=\"get\">");
ProcessCheckbox(client);
client.println("</form>");

processButton(client);

 
client.println("</body>");
client.println("</html>");
Serial.print(HTTP_req);
HTTP_req = "";    // finished with request, empty string
}

void analyzeGETparams(EthernetClient cl){

  
}


