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 = 'includes/' + 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, fullname, companyname, telephone,email, work,no_of_pages,budget,type,target_market,current_website,desired_website,finding,question) { //the page is described in the xhtml
	var myurl = 'includes/' + page + '.php';

	var submitted = submitted; 
	var fullname=fullname;
	var companyname=companyname;
	var telephone=telephone;
	var email=email;
	var work=work;
	var no_of_pages=no_of_pages;
	var budget=budget;
	var type=type;
	var target_market=target_market;
	var current_website=current_website;
	var desired_website=desired_website;
	var finding=finding;
	var question=question;	

	
	var query = "submitted="+submitted +"&fullname="+fullname+"&companyname="+companyname+"&telephone="+telephone+"&email="+email+"&work="+work+"&no_of_pages="+no_of_pages+"&budget="+budget+"&type="+type+"&target_market="+target_market+"&current_website="+current_website+"&desired_website="+desired_website+"&finding="+finding+"&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 getRecommend(page, submitted, name,fname,femail) { //the page is described in the xhtml
	var myurl = 'includes/' + page + '.php';
	
	var submitted = submitted; 
	var name=name;
	var fname=fname
	var femail=femail;
	
	var query = "submitted="+submitted +"&name="+name+"&fname="+fname+"&femail="+femail; 
	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_container').innerHTML = detailsValue; //writes to div
		}
	}else{ //the process hasnt finished so display animation to indicate it is working
	randomCall = new Array('W3C standards','accessibile web sites','cool original designs','personal service','realstic pricing','search engine friendly');
		document.getElementById('ajax_container').innerHTML = '<div class="ajax1" title="Division Web Design pricing"><p>' + randomCall[Math.floor(Math.random()*randomCall.length)] +  '</p><img src="ajax-loader.gif" alt="loading" /><br /><br /><br /><br /><br /><br /><br /><br /></div><div class="ajax2" title="contact us, discuss requirements, get quote."><img src="ajax-loader.gif" alt="loading"/></div><div style="clear:both";></div>';
	}//else ajax has failed
}


