	// Modified from Captain's AJAX HTML Form POST/Submit with AJAX Tutorial Example
	// http://www.captain.at/howto-ajax-form-post-request.php
   var http_request = false;
   function makePOSTRequest(url, parameters,debug) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...even IE7 now!
 		 http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
	  if (debug == 'debug') {
		http_request.onreadystatechange = alertContents;
	  }
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            alert (result);
			return true;
         } else {
            alert('There was a problem with the request.');
			return false;
         }
      }
   }
   
	function makePost(obj,destinationURL,debug) {
		// Array to hold bulletin array
		var allBulletins = new Array();
		var billing_country = "";
		var birthdate = "";
		
		// Replace NULL values with empty strings
		if(document.getElementById("billing_country")) {
			billing_country = document.getElementById("billing_country").value;
		} else {
			billing_country = "United States";
	    }
		if(document.getElementById("chkBeautyBulletin").checked) {
			allBulletins.push(document.getElementById("chkBeautyBulletin").value);
		}
		if(document.getElementById("chkBonusBeautyBulletin").checked) {
			allBulletins.push(document.getElementById("chkBonusBeautyBulletin").value);
		}
		if(document.getElementById("chkSpecialBulletins").checked) {
			allBulletins.push(document.getElementById("chkSpecialBulletins").value);
		}
		if(document.getElementById("chkBeautypediaBulletin").checked) {
			allBulletins.push(document.getElementById("chkBeautypediaBulletin").value);
		}
		if(document.getElementById("birthdate")) {
			birthdate = document.getElementById("birthdate").value;
		} else {
			birthdate = "";
		}
				
		/* Set up the input string per EmailLabs' specifications.
			Demographic info:
			1 = First Name
			2 = Last Name
			7 = Zip/Postal Code
			8 = Country
			33690 = Birthday
			33692 = Bulletins
		*/
		var input =	'<?xml version=\'1.0\' encoding=\'iso-8859-1\'?>' +
					'<DATASET>' +
					'<SITE_ID>666758</SITE_ID>' +
					'<MLID>5426</MLID>' +
					// Testing		'<MLID>5805</MLID>' +
					'<DATA type="email">' + encodeURI(document.getElementById('email').value) + '</DATA>' +
					'<DATA type="demographic" id="1">' + encodeURI(document.getElementById('first_name').value) + '</DATA>' +
					'<DATA type="demographic" id="2">' + encodeURI(document.getElementById('last_name').value) + '</DATA>' +
					'<DATA type="demographic" id="7">' + encodeURI(document.getElementById('sZipField2').value) + '</DATA>' +
					'<DATA type="demographic" id="8">' + encodeURI(billing_country) +'</DATA>' +
					'<DATA type="demographic" id="33690">' + encodeURI(birthdate) + '</DATA>' +
					'<DATA type="demographic" id="33692">' + encodeURI(allBulletins.join("||")) + '</DATA>' +
					'</DATASET>';
					var poststr = "type=record" +
					"&activity=add" +
					"&input=" + input +
					"&submit=yes";
      makePOSTRequest(destinationURL, poststr,debug);
   }
