function optinClick(theForm){
	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 Therawear\'s email noticiations.');}
		}
	}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 Therawear\'s email noticiations.');}
	}

}//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 = "/email_subscribe.php?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 = /newsletter.html/i;
                        if(newstest.test(thePage)){
				alert('Thank you for signing up for special offers and promotions from Therawear.  You will receive an email confirmation shortly.');
				document.getElementById('fname').value = "";
				document.getElementById('lname').value = "";
				document.getElementById('email').value = "";
                        }
		}else{
                        //this indicates an error so we wanna show it to the customer
                        alert(response); 
		}
        }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
