function getXMLHTTPRequest(){
var req = false;
try{
req = new XMLHttpRequest(); //firefox and other browsers NOTE the case sensitivity
} catch(e){
	try{
	req = new ActiveXObject("Msxml2.XMLHTTP");	//ie 7
	} catch(e){
		try{
	req = new AtiveXObject("Microsoft.XMLHTTP"); //ie other
	} catch(E){
		req = false; //if it fails
		alert("You must enable javascript in your internet options to view this page properly.")
	}
}
}

return req; //returns the result
}

var http = getXMLHTTPRequest();
var http1 = getXMLHTTPRequest();


function getDetails(page) { //the page is described in the xhtml
	var myurl = page + '.php';
	var myRand = parseInt(Math.random()*999999999999999) //to prevent browser caching
	var modurl = myurl +"?rand="+ myRand; //creates a unique url to fool browser cache
	http.open('GET', modurl, true); 
	http.onreadystatechange= useHTTPResponse; //this is how to call an undefined function 
	http.send(null);
}


function getDetails2(page,id) { //the page is described in the xhtml
	var myurl = page + '.php';
	var id= id;
	var myRand = parseInt(Math.random()*999999999999999) //to prevent browser caching
	var modurl = myurl +"?rand="+ myRand+"&id="+id; //creates a unique url to fool browser cache
	http1.open('GET', modurl, true); 
	http1.onreadystatechange= useHTTPResponse2; //this is how to call an undefined function 
	http1.send(null);
}

function getContact(page, submitted, name,telephone,email,question) { //the page is described in the xhtml
	var myurl = page + '.php';
	var submitted = submitted; 
	var name=name;
	var telephone=telephone;
	var email=email;
	var question=question;
	
	var query = "submitted="+submitted +"&name="+name+"&telephone="+telephone+"&email="+email+"&question="+question; 
	http.open('POST', myurl, 1); //needs to be set to one or 0 for POST
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); //needed for POST ajax
	http.onreadystatechange= useHTTPResponse; //this is how to call an undefined function 
	http.send(query);
}

function getRegister(page, submitted_registration, register_firstname,register_lastname,aka,register_email,register_password1,register_password2,contact_me) { //the page is described in the xhtml
	var myurl = page + '.php';
	var s= submitted_registration; 
	var fn=register_firstname;
	var ln=register_lastname;
	var aka=aka;
	var e=register_email;
	var p1=register_password1;
	var p2=register_password2;
	var c=contact_me;
	
	if(c==''){//have checked and c works!!!
		c='0';
	}
	
	
	var query = "s="+s+"&fn="+fn+"&ln="+ln+"&aka="+aka+"&e="+e+"&p1="+p1+"&p2="+p2+"&c="+c; 
	http.open('POST', myurl,1); 
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); //needed for POST ajax
	http.onreadystatechange= useHTTPResponse; //this is how to call an undefined function 
	http.send(query);
}

function getProfile(page, sp, pfn,pln,paka,pe,pp1,pp2,pc) { //the page is described in the xhtml
	var myurl = page + '.php';
	var pc=pc;	
	
	if(pc==''){//have checked and pc works!!!
		pc='0';
	}
	
	var query = "sp="+sp+"&pfn="+pfn+"&pln="+pln+"&paka="+paka+"&pe="+pe+"&pp1="+pp1+"&pp2="+pp2+"&pc="+pc; 
	http.open('POST', myurl,1); 
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); //needed for POST ajax
	http.onreadystatechange= useHTTPResponse; //this is how to call an undefined function 
	http.send(query);
}

function getProfile1(page, sp, pfn,pln,paka,pe,pp1,pp2,pc) { //the page is described in the xhtml
	var myurl = page + '.php';
	var pc=pc;	
	
	if(pc==''){//have checked and pc works!!!
		pc='0';
	}
	
	var query = "submitted_profile_change="+sp+"&pfn="+pfn+"&pln="+pln+"&paka="+paka+"&pe="+pe+"&pp1="+pp1+"&pp2="+pp2+"&pc="+pc; 
	http.open('POST', myurl,1); 
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); //needed for POST ajax
	http.onreadystatechange= useHTTPResponse; //this is how to call an undefined function 
	http.send(query);
}

function getBlog(page, comment, submitted,stamp) { //the page is described in the xhtml
	var myurl = page + '.php';
	var c=''+comment+''; 
	var s=submitted;
	var stamp=stamp
		
	var query = "c="+c+"&s="+s+"&stamp="+stamp; 
	http1.open('POST', myurl, 1); //needs to be set to one or 0 for POST
	http1.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); //needed for POST ajax
	http1.onreadystatechange= useHTTPResponse2; //this is how to call an undefined function 
	http1.send(query);
	
}

function getForgotten(page, email, submitted) { //the page is described in the xhtml
	var myurl = page + '.php';
	var e= email; 
	var s=submitted;
	
	var query = "fpe="+e+"&fpsub="+s; 
	http.open('POST', myurl, 1); // nededs to be set for 1 or 0 for POST
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); //needed for POST ajax
	http.onreadystatechange= useHTTPResponse; //this is how to call an undefined function 
	http.send(query);
}

function useHTTPResponse(){
	if(http.readyState == 4){ //ajax is working
		if(http.status == 200){ //operation is complete
			var detailsValue = http.responseText;
			document.getElementById('dynamic_window_01').innerHTML = detailsValue; //writes to div
		}
	}else{ //the process hasnt finished so display animation to indicate it is working
		document.getElementById('dynamic_window_01').innerHTML = '<div style="height:300px;position:relative;left:40px;"><br /><br /><br /><br /><br /><img src="images/ajax-loader-bar.gif" alt="data loading"><br /><p><span style="position:relative;left:45px;">...loading data...</span></p></div>';
	}//else ajax has failed
}
function useHTTPResponse2(){
	if(http1.readyState == 4){ //ajax is working
		if(http1.status == 200){ //operation is complete
			var detailsValue = http1.responseText;
			document.getElementById('blog_holder').innerHTML = detailsValue; //writes to div
		}
	}else{ //the process hasnt finished so display animation to indicate it is working
		document.getElementById('blog_holder').innerHTML = '<div style="height:300px;position:relative;left:40px;"><br /><br /><br /><br /><br /><img src="images/ajax-loader-bar.gif" alt="data loading"><br /><p><span style="position:relative;left:30px;">...editing web log...</span></p></div>';
	}//else ajax has failed
}
function hoverPreloader(){ 
  var args = hoverPreloader.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }

}

function get_check_value(iSource) //field to get values from
{
var c_value = "";
var fieldobj = document.getElementsByName(iSource);
for (var i=0; i < fieldobj.length; i++)
{
if (fieldobj[i].checked)
{
c_value = c_value + fieldobj[i].value + "\n";
}
}
return c_value;
}

