// WAHM.COM


/*** Newsletter Form JavaScript v1.1 */

/*** DO NOT EDIT THE CODE BELOW THIS LINE */
var AJAXRequestHandleObj = {
	url: undefined,
	method: "GET",
	theXmlHttpObject: undefined,
	createRequestObject: function(){
		var _XmlHttpObject;
		if (window.XMLHttpRequest) { 
			_XmlHttpObject = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			try{
				_XmlHttpObject = new ActiveXObject("MSXML2.XMLHTTP.3.0");
        	        }catch(e){
				try{
					_XmlHttpObject = new ActiveXObject("Msxml2.XMLHTTP");
				}catch(e2){
					try{
						_XmlHttpObject = new ActiveXObject("Microsoft.XMLHTTP");
					}catch(e3){
						alert("Your browser does not support AJAX!")
						return false;
					}
				}
            		}
		}
		return _XmlHttpObject;
	},
	setURL: function(url){
		this.url = url;
		return this;
	},
	sendRequest: function(xmlHttpObj, params, outputDiv, customSuccessHTML){
		if (xmlHttpObj != null) {
			xmlHttpObj.open(this.method, this.url + "?" + params, true);
			xmlHttpObj.onreadystatechange = function(){
				if (xmlHttpObj.readyState == 4) {
					if (xmlHttpObj.status == 200) {
						if(typeof outputDiv != 'undefined' && document.getElementById(outputDiv)){
							var arrayRsp = xmlHttpObj.responseText.split('|'),
								failure = ( arrayRsp[0] == "error" ),
								outMsg = (failure ? arrayRsp[1] : '');
							document.getElementById(outputDiv).innerHTML=outMsg;
							if(!failure && (typeof customSuccessHTML != 'undefined')){
 								// alert( document.getElementById(outputDiv).parentNode ); // [object HTMLDivElement]
								// alert( document.getElementById(outputDiv).parentNode.getAttribute('class') ); // opportunities
								// alert( document.getElementById(outputDiv).parentNode.innerHTML ); // current HTML
								// document.getElementById(outputDiv).parentNode.innerHTML = '<span class="n_grey_title">Thank You</span><br />A confirmation email has been sent';
								document.getElementById(outputDiv).parentNode.innerHTML = customSuccessHTML;								
							}
						}else
							alert(xmlHttpObj.responseText);
					}
				}	
			};
			xmlHttpObj.send();
		}
		else {
			window.alert("AJAX (XMLHTTP) not supported.");
		}		
	}
};

var NewsletterSubscriberObj = {
	theURL: "",
	theFrmName: "",
	theField: "",
	theMsg: "",
	theOutput: "",
	theCustmHtml: "",
	setFrmName: function(frm){
		this.theFrmName = frm;
		return this;
	},
	setField: function(field){
		this.theField = field;
		return this;
	},
	setMsg: function(msg){
		this.theMsg = msg;
		return this;
	},
	setOutput: function(divID){
		this.theOutput = divID;
		return this;
	},
	setCustomSuccessHTML: function(html){
		this.theCustmHtml = html;
		return this;
	},
	setURL: function(url){
		this.theURL = window.location.href.match(/^http[s]?:[/]{2}[a-z0-9.:-]+/i)+url;
		return this;
	},
	checkEmailAddress: function(){
		eval( 'var theFrm = document.' + this.theFrmName + ';' );
		eval( 'var hasDot = theFrm.' + this.theField + '.value.indexOf(\'.\');' );
		eval( 'var hasAt = theFrm.' + this.theField + '.value.indexOf(\'@\');' );
		if (hasDot == -1 || hasAt == -1){
			alert(this.theMsg);
			eval( 'theFrm.' + this.theField + '.focus();' );
			eval( 'theFrm.' + this.theField + '.select();' );
			return false;
		}
		return true;
	},
	doRequest: function(ajaxObj){
			eval( 'var theEmail = document.' + this.theFrmName + '.' + this.theField + '.value;' );
			ajaxObj.setURL(this.theURL)
					.sendRequest(
						 ajaxObj.createRequestObject() 
						,"" + this.theField + "=" + theEmail + "&timestamp=" + new Date().toString() + "&action=subscribe&ajax=true"
						,this.theOutput
						,this.theCustmHtml
					);
	}
};

/*** DO NOT EDIT THE CODE ABOVE THIS LINE */


/*** CONFIGURE YOUR OWN VALUES BELOW */
function newsletter_signup(){

	NewsletterSubscriberObj.setFrmName("newsletter_form")
			       .setField("newsletter_email")
			       .setMsg("Please enter a valid email address.")
				   .setOutput("nMessage")
				   .setCustomSuccessHTML('<span class="n_grey_title">Thank You</span><br />A confirmation email has been sent')
			       .setURL("/subscribe.php");

	if( NewsletterSubscriberObj.checkEmailAddress() ){
		NewsletterSubscriberObj.doRequest(AJAXRequestHandleObj);
	}
}

/*** Eof Newsletter Form JavaScript v1.1 */



