function createRequestObject() { var ro; var browser = navigator.appName; if(browser == "Microsoft Internet Explorer"){ ro = new ActiveXObject("Microsoft.XMLHTTP"); }else{ ro = new XMLHttpRequest(); } return ro; } var http = createRequestObject(); function sndReq(action, value) { url = 'change_prefs.php?'+action+'='+value; http.open('get', url); // http.onreadystatechange = handleResponse; http.send(null); } function sndReqFetch(url) { url = 'fetch.php?url=' + url; http.open('get', url); http.onreadystatechange = handleFetchResponse; http.send(null); } function sndReqMeta(url) { url = 'create_meta_page.php?url=' + url; http.open('get', url); http.onreadystatechange = handleMetaResponse; http.send(null); } function sndReqCheck(url) { url = 'check_url.php?url=' + url; http.open('get', url); http.onreadystatechange = handleCheckResponse; http.send(null); } function sndReqInsertSite(where) { url = 'insert_site.php?where=' + where; // alert(url); http.open('get', url); http.onreadystatechange = handleInsertResponse; http.send(null); } function handleInsertResponse() { if(http.readyState == 4) { var response = http.responseText; var update = new Array(); update = response.split('|'); // alert(response); if(update[0] == 'true') { location.href = 'index.html?p=' + update[1]; } else { location.href = 'index.html?p=error'; } } } function handleCheckResponse() { if(http.readyState == 4) { var response = http.responseText; var update = new Array(); // We have a result in parts seperated with a pipe (|) // Split the results into parts update = response.split('|'); document.getElementById('check_res').innerHTML = update[1]; document.getElementById('check_info').innerHTML = update[2]; if(update[0] == 'ok') { hide('start_check'); hide('check_bad'); hide('checking'); show('check_ok'); } else { hide('start_check'); hide('checking'); hide('check_ok'); show('check_bad'); } } } function handleMetaResponse() { if(http.readyState == 4) { var response = http.responseText; // Our response id the id of the meta analysis file location.href="index.html?p=met&id=" + response; } } function handleFetchResponse() { if(http.readyState == 4) { var response = http.responseText; var update = new Array(); // We have a result in parts seperated with a pipe (|) // Split the results into parts update = response.split('|'); // Set the status message div with the HTTP header result (Required?) // document.getElementById('fetch_msg').innerHTML = 'Result: ' + update[0]; // If there is an error part 1 should be set to 'error' so check for this if(update[1] == 'error') { alert("Sorry, we were unable to fetch your site details - Please fill the form by hand."); } else { // Check that there is content before the pipe if(response.indexOf('|' != -1)) { //alert('Start to fill the form'); // Okay so set the elements with the returned data // If there is no data this will just fill a blank // So there is no need for additional error checks document.getElementById('site_url').value = update[1]; document.getElementById('site_name').value = update[2]; document.getElementById('site_desc').value = update[3]; document.getElementById('countBody').innerHTML = update[3].length; // Put out coutry ID into a variable var country_id = update[4]; // Check that our country ID is a number (NaN = Not A Number) if(!isNaN(country_id) || country_id.length > 1) { // Now annoying work around becasue javascript insists on inserting by position and not value var country_select = document.getElementById('site_country'); // Look at all the countries... for (var x = 1; x 0) { // The keywords are seperated by a pluid (+) so additionally split these keys = update[5].split('+'); // Count the number of keywords var no_of_keys = keys.length; //alert('No of Keys: ' + no_of_keys); // We only want a maximum of 20 so reset the count if we have more if(no_of_keys > 20) { no_of_keys = 20; } //alert('No of Keys after mod: ' + no_of_keys); // Assuming that we have more that zero (this should have been caught earlier) if(no_of_keys > 0) { //alert('Setting Keys'); // Fill in each of the keyword tabs for(var x = 1; x <= no_of_keys; x++) { // Set the element ID as index index = 'site_key_' + x; // And now fill the correct element with the kayword document.getElementById(index).value = keys[x-1]; //alert('Index:' + index + ' Set To: ' + keys[x-1]); } } } /*else { var no_of_keys = 0; } //alert('Blanking Remaining Keys'); // Set the rest to blank - just in case we are writting over previous data for (var x = no_of_keys+1; x < 21; x++) { // Set the element ID as index index = 'site_key_' + x; // And now fill the correct element with a blank document.getElementById(index).value = ''; //alert('Index:' + index + ' Set To: [blank]'); }*/ //alert('Rearrange Display'); //alert('Done!'); // document.getElementById('fetch_status').value = 'complete'; } else { alert('Sorry there was an error - please fill the form by hand.'); } } hide('wait'); show('add_form'); } }