function compat_url() { var script_root = '/php-bin/form.mail/'; //var doc_url = doc_url.replace(location.protocol + "//" + location.host + "\/", "\/"); return script_root; } //alert( compat_url() ); // Debugging function form_data_array(form_name) { for (var i = 0; i < form_name.length; i++) { var scan_keys = ''; var scan_values = ''; if ( form_name[i].name ) { if ( form_name[i].type == 'checkbox' && form_name[i].checked == false ) { form_name[i].value = ''; } else if ( form_name[i].type == 'radio' && form_name[i].checked == false ) { form_name[i].value = ''; } if ( !ajax_string ) { var scan_keys = form_name[i].name.replace("\&", "ESCAPE_AMPERSAND"); var scan_values = form_name[i].value.replace("\&", "ESCAPE_AMPERSAND"); var ajax_string = scan_keys + "=" + scan_values + "&"; } else { var scan_keys = form_name[i].name.replace("\&", "ESCAPE_AMPERSAND"); var scan_values = form_name[i].value.replace("\&", "ESCAPE_AMPERSAND"); var ajax_string = ajax_string + scan_keys + "=" + scan_values + "&"; } } else if ( form_name[i].id ) { if ( form_name[i].type == 'checkbox' && form_name[i].checked == false ) { form_name[i].value = ''; } else if ( form_name[i].type == 'radio' && form_name[i].checked == false ) { form_name[i].value = ''; } if ( !ajax_string ) { var scan_keys = form_name[i].id.replace("\&", "ESCAPE_AMPERSAND"); var scan_values = form_name[i].value.replace("\&", "ESCAPE_AMPERSAND"); var ajax_string = scan_keys + "=" + scan_values + "&"; } else { var scan_keys = form_name[i].id.replace("\&", "ESCAPE_AMPERSAND"); var scan_values = form_name[i].value.replace("\&", "ESCAPE_AMPERSAND"); var ajax_string = ajax_string + scan_keys + "=" + scan_values + "&"; } } //var ajax_string = ajax_string.replace(" ", " "); //var ajax_string = ajax_string.replace(" ", "_"); } var ajax_string = ajax_string.substring(0, ajax_string.length-1) return ajax_string; } ////////////////////////////////////////////////////////////////////////////////////////// function send_data() { var post_data = form_data_array(document.form_data_mail); makeRequest(post_data); } //////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// function makeRequest(post_data) { var http_request = false; // If *POST* occurs in Netscape (disables script in MSIE if not run inside an IF statement!) if (http_request.overrideMimeType) { http_request.overrideMimeType('text/xml'); } // Create a xmlhttp request... // Mozilla, Safari, etc if (window.XMLHttpRequest) { http_request = new XMLHttpRequest(); } // MSIE else if (window.ActiveXObject) { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } else { alert('Your browser settings don\'t seem to support AJAX,\n or you need to upgrade your browser :('); return false; } // Javascript function to call as the xmlhttp request is processed and sent back http_request.onreadystatechange = function() { alertContents(http_request); }; // Were're ready to make the xmlhttp request now... // POST http_request.open('POST', compat_url() + 'form.mailer.php', true); http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); http_request.setRequestHeader("Content-length", post_data.length); http_request.setRequestHeader("Connection", "close"); http_request.send(post_data); // alert(post_data); // Debugging } ////////////////////////////////////////////////////////////////////////////////////// function alertContents(http_request) { /* Display "Loading...", and see if the request has been responded to, and that it wasn't a 404/500 etc... */ if ( http_request.readyState == 4 && http_request.status == 200 ) { var thanks = /DETECT_THANKS/; document.getElementById("form_status").innerHTML = http_request.responseText; if ( http_request.responseText.search(thanks) != -1 ) { document.getElementById("form_status").innerHTML = ''; document.getElementById("form_div_data").innerHTML = 'Vielen Dank, wir haben Ihre Mail erhalten und werden Ihre Anfrage schnellstmöglich bearbeiten.'; } else if ( http_request.responseText.search(thanks) == -1 ) { } // alert(http_request.responseText); // Debugging } else if ( http_request.readyState == 4 ) { // 3xx CODES - FAILURE if ( http_request.status == 301 ) { var http_error_status = 'Moved permanently'; } else if ( http_request.status == 302 ) { var http_error_status = 'Moved temporarily'; } else if ( http_request.status == 307 ) { var http_error_status = 'Moved temporarily'; } // 4xx CODES - FAILURE if ( http_request.status == 400 ) { var http_error_status = 'Did not understand request, try again'; } else if ( http_request.status == 401 ) { var http_error_status = 'Authorization required , needs password'; } else if ( http_request.status == 402 ) { var http_error_status = 'Payment required, need s payment data'; } else if ( http_request.status == 403 ) { var http_error_status = 'Request refused'; } else if ( http_request.status == 404 ) { var http_error_status = 'File not found'; } else if ( http_request.status == 406 ) { var http_error_status = 'Content type not acceptable to request'; } else if ( http_request.status == 407 ) { var http_error_status = 'Browser must authenticate itself'; } else if ( http_request.status == 408 ) { var http_error_status = 'Timed out, send request again'; } else if ( http_request.status == 409 ) { var http_error_status = 'Update conflict'; } else if ( http_request.status == 410 ) { var http_error_status = 'File not found, resource permanently gone'; } else if ( http_request.status == 411 ) { var http_error_status = 'Content length missing in request'; } else if ( http_request.status == 412 ) { var http_error_status = 'Conditions on request failed'; } else if ( http_request.status == 413 ) { var http_error_status = 'Request too long to process'; } else if ( http_request.status == 414 ) { var http_error_status = 'Resource address too long to process'; } else if ( http_request.status == 415 ) { var http_error_status = 'Unsupported media type, bad format'; } // 5xx CODES - SERVER ERRORS else if ( http_request.status == 500 ) { var http_error_status = 'Internal server error'; } else if ( http_request.status == 501 ) { var http_error_status = 'Server cannot fill request'; } else if ( http_request.status == 502 ) { var http_error_status = 'Server cannot process gateway request'; } else if ( http_request.status == 503 ) { var http_error_status = 'Server overloaded or service over limits'; } else if ( http_request.status == 504 ) { var http_error_status = 'Gateway or proxy server timed out'; } else if ( http_request.status == 505 ) { var http_error_status = 'HTTP version not supported in server'; } else if ( !http_error_status ) { var http_error_status = ''; } document.getElementById("form_status").innerHTML = "Error Code: " + http_request.status + " ... " + http_error_status + ""; } else { document.getElementById("form_status").innerHTML = "Loading..."; } } ///////////////////////////////////////////////////////////////////////////////////////