function optinClick(theForm){
        document.getElementById('submit_msg').innerHTML = '<span style="font-family:verdana;font-size:12px;color:red;">Processing - Please Wait.</span>';
	var pick = "";
	if(theForm.opt){
		if(theForm.opt[0].checked){
			pick = theForm.opt[0].value;
		}else {pick = theForm.opt[1].value;}
		if(pick == "in"){
			if((theForm.fname.value != "") && (theForm.lname.value != "") && (theForm.email.value != "")){
				emailCheck(theForm);
			}else{
			        alert('You must enter your First Name, Last Name, and Email to sign up for Missouri Table & Chair\'s email noticiations.');
                                document.getElementById('submit_msg').innerHTML = '<input type="image" id="special_offers_submit" onclick="javascript:optinClick(this.form);" src="/ic-info/images/foundation/index/sign-up-btn.jpg">';			        
                        }
		}
	}else{
		if((theForm.fname.value != "") && (theForm.lname.value != "") && (theForm.email.value != "")){
			emailCheck(theForm);
		}else{
		        alert('You must enter your First Name, Last Name, and Email to sign up for Missouri Table & Chair\'s email noticiations.');
                        document.getElementById('submit_msg').innerHTML = '<input type="image" id="special_offers_submit" onclick="javascript:optinClick(this.form);" src="/ic-info/images/foundation/index/sign-up-btn.jpg">';                }
	}

}//end optinClick

function createRequestObject() {
        var req;
        if(window.XMLHttpRequest){
          req = new XMLHttpRequest();
        } else if(window.ActiveXObject) {
          req = new ActiveXObject("Microsoft.XMLHTTP");
        } else {
          alert('Your browser does not support AJAX.');
        }

        return req;
}//end createRequestObject

function emailCheck(theForm) {
httpGet=createRequestObject();
if (httpGet==null) {
        alert ("Your browser does not support AJAX!");
        return;
}
var thefile = "/store-address.php?ajax=true&email="+theForm.email.value+"&fname="+theForm.fname.value+"&lname="+theForm.lname.value;
httpGet.open("GET",thefile,true);
httpGet.onreadystatechange=handleResults;
httpGet.send(null);
}//end emailCheck

function handleResults(){
if(httpGet.readyState == 4){
   if(httpGet.status == 200){
        var response = httpGet.responseText;
        if(response){
		if(response == 1){
			var thePage = document.URL;
			var newstest = /index.html/i;
			alert('Thank you for signing up for special offers and promotions from Missouri Table & Chair.  You will receive an email confirmation shortly.');
			document.getElementById('fname').value = "";
			document.getElementById('lname').value = "";
			document.getElementById('email').value = "";
                        document.getElementById('submit_msg').innerHTML = '<input type="image" id="special_offers_submit" onclick="javascript:optinClick(this.form);" src="/ic-info/images/foundation/index/sign-up-btn.jpg">';
		}else{
                        //this indicates an error so we wanna show it to the customer
                        alert(response); 
                        document.getElementById('submit_msg').innerHTML = '<input type="image" id="special_offers_submit" onclick="javascript:optinClick(this.form);" src="/ic-info/images/foundation/index/sign-up-btn.jpg">';
		}
        }else{alert('There was no response while requesting your addition to the mailing list.  Please try again.');}
   }else{alert('There was a problem requesting your addition to the mailing list.  Please try again.');}
}
}//end handleResults

