// Crystal Ball Data
// COPYRIGHT 2007
// Paul Kukk
// global flag
var isIE = false;

// global request and XML document objects
var req;
var url = "http://www.ehealth-center.com/ajax/formmail.php?"; // The server-side script

// Main generic function
function sendCommentMail(form) {
 	var url_string = "fullname="+form.name.value;
	url_string = url_string+"&company="+form.company.value+"&address="+form.address.value;
	url_string = url_string+"&city="+form.city.value+"&state="+form.state.value+"&zip="+form.zip.value;
	url_string = url_string+"&email="+form.email.value;
	url_string = url_string+"&phone="+form.phone.value+"&fax="+form.fax.value;
	url_string = url_string+"&mail="+form.mail.value+"&comments="+form.comments.value;
	//alert(url+url_string);
  // branch for native XMLHttpRequest object
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
    req.onreadystatechange = processReqChange;
    req.open("GET", url + url_string, true);
    req.send(null);
  // branch for IE/Windows ActiveX version
  } else if (window.ActiveXObject) {
    isIE = true;
    req = new ActiveXObject("Microsoft.XMLHTTP");
    if (req) {
      req.onreadystatechange = processReqChange;
      req.open("GET", url + url_string, true);
      req.send();
    }
  }
}

// handle onreadystatechange event of req object
function processReqChange() {
  // only if req shows "loaded"
	var result = "";
	//alert(req.responseText);
  if (req.readyState == 4) {
  	// only if "OK"
    if (req.status == 200) {
		//alert(req.status);
      	results = req.responseText.split("|");
		//alert(results[1]);
		if (results[0] == "mail") {
			//document.getElementById('timeDelta').innerHTML = results[1];
			document.getElementById("message").innerHTML = results[1];
		}
    } else {
       alert("There was a problem retrieving the XML data:\n" +
       req.statusText);
    }
  }
}

function replaceAll( str, from, to ) {
    var idx = str.indexOf( from );


    while ( idx > -1 ) {
        str = str.replace( from, to ); 
        idx = str.indexOf( from );
    }

    return str;
}
