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();



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 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 +"&fullname="+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 useHTTPResponse(){
	if(http.readyState == 4){ //ajax is working
		if(http.status == 200){ //operation is complete
			var detailsValue = http.responseText;
			document.getElementById('ajax_window').innerHTML = detailsValue; //writes to div
		}
	}else{ //the process hasnt finished so display animation to indicate it is working
		slogan=new Array("We work around your time","Bristol&acute;s premier painting &amp; decorating service","Bristol&acute;s specialist painting &amp; decorating service","Professional service in a frinedly manner","Quality and value combined","Paitning you a better future");
		
		document.getElementById('ajax_window').innerHTML = '</div><div style="height:800px;position:relative;left:100px;"><br /><br /><img src="ajax-loader.gif" alt="loading"/><p><br />' + slogan[Math.floor(Math.random()*6)] +'</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;
}
