// #### AJAX STUFF ####		used by contact forms
var xmlHttp_contact;
var qucount;
var totalqu = 1;

function createXMLHttpRequest_contact() {
    if (window.ActiveXObject) {
        xmlHttp_contact = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    else if (window.XMLHttpRequest) {
        xmlHttp_contact = new XMLHttpRequest();
    }
	//*/
    /*if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest(); // code for all new browsers (inc IE7)
    }
    else if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); // code for IE5 and IE6
    }*/
}

function startRequest_contact(cat_id,qucountparam,cPath,thisobj) {
	if (thisobj){ // if a button clicked, sort out tint/plain for buttons for this qu div only (qucount). This is false on very first auto call (as no button clicked!)
		main = document.getElementById(qucountparam);
		for (x in main.childNodes){
			//alert(main.childNodes[x].nodeName);
			if (main.childNodes[x].type == 'button') main.childNodes[x].childNodes[0].className = 'green_button_tint';
		}
		thisobj.childNodes[0].className = 'green_button';
	}
	qucount = qucountparam;
    //if (!xmlHttp) createXMLHttpRequest(); // ok in FF but stops in IE
	createXMLHttpRequest_contact();
    xmlHttp_contact.onreadystatechange = handleStateChange_contact;
	//#2
    xmlHttp_contact.open("POST", "/contact_us_data.php", true);
	//#3
	xmlHttp_contact.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');	// needed if POSTing data
    //xmlHttp.send("email_address=" + document.forms[0].email_address.value );
	xmlHttp_contact.send("cat_id=" + cat_id + "&qucount=" + qucount + "&cPath=" + cPath);
	//xmlHttp.send(null);
}
    
function handleStateChange_contact() {
    if(xmlHttp_contact.readyState == 4) {
        if(xmlHttp_contact.status == 200) {
			// sort of display of qu/ans
			if (totalqu > qucount){ // if gone back to previous qu/ans, delete accordingly
				main = document.getElementById("results");
				for (i=qucount+1; i<=totalqu; i++){ // remove from current qu +1 and on
					elem = document.getElementById(i);
					main.removeChild(elem);
				}
				totalqu = qucount+1; // reset total num of qu
			} else { // else just increment total
				totalqu++;
			}
			// display requested qu/ans
            document.getElementById("results").innerHTML += xmlHttp_contact.responseText;	// "results" div populated by response
			//if (document.getElementById("results").height > 445) document.getElementById("content_bg").height = document.getElementById("results").height;
			//alert(document.getElementById("results").style.height);
			//delete xmlHttp;
        }
    }
}
// EOF AJAX STUFF
function showHide(elem){ // called by info button in ajax divs - eg product finder or contact forms
	elem = document.getElementById(elem);
	if (elem.style.display == 'block'){
		elem.style.display = 'none';
	} else {
		elem.style.display = 'block';
	}
}