function addEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener) { 
	elm.addEventListener(evType, fn, useCapture); 
	return true; 
	}
	else if (elm.attachEvent) { 
	var r = elm.attachEvent('on' + evType, fn); 
	EventCache.add(elm, evType, fn);
	return r; 
	}
	else {
	elm['on' + evType] = fn;
	}
}
function getEventSrc(e) {
	if (!e) e = window.event;

	if (e.originalTarget)
	return e.originalTarget;
	else if (e.srcElement)
	return e.srcElement;
}
function addLoadEvent(func) {
var oldonload = window.onload;
	if (typeof window.onload != 'function') {
	window.onload = func;
	} else {
	window.onload = 
		function() {
		oldonload();
		func();
		}
	}
}
var EventCache = function(){
	var listEvents = [];
	return {
		listEvents : listEvents,
	
		add : function(node, sEventName, fHandler, bCapture){
			listEvents.push(arguments);
		},
	
		flush : function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item = listEvents[i];
				
				if(item[0].removeEventListener){
					item[0].removeEventListener(item[1], item[2], item[3]);
				};
				
				/* From this point on we need the event names to be prefixed with 'on" */
				if(item[1].substring(0, 2) != "on"){
					item[1] = "on" + item[1];
				};
				
				if(item[0].detachEvent){
					item[0].detachEvent(item[1], item[2]);
				};
				
				item[0][item[1]] = null;
			};
		}
	};
}();

addEvent(window,'unload',EventCache.flush, false);

function validateFields() {
var frm1 = document.getElementById("newsletterSignup");
var name = document.getElementById("strname");
var email = document.getElementById("stremail");
var company = document.getElementById("strcompany");
var whiteSpace = /^[\s]+$/;
var emailFormat = /^[\w\.\-]+@[\w\.\-]+\.[\w\.\-]+$/;

	if ( name.value == "" || whiteSpace.test(name.value) ) {
		hideAllErrors();		
		document.getElementById("strname").style.border = "1px solid #CC3333";		
		document.getElementById("strname").style.background = "#F2CCCC";		
		document.getElementById("strname").style.color = "#641A1A";
		document.getElementById("name").select();
		document.getElementById("name").focus();
	} else if ( email.value == "" || whiteSpace.test(email.value) ) {
		hideAllErrors();		
		document.getElementById("stremail").style.border = "1px solid #CC3333";		
		document.getElementById("stremail").style.background = "#F2CCCC";		
		document.getElementById("stremail").style.color = "#641A1A";
		document.getElementById("email").select();
		document.getElementById("email").focus();
	} else if ( (email.value !="") && (!email.value.match(emailFormat)) ) {
		hideAllErrors();		
		document.getElementById("stremail").style.border = "1px solid #CC3333";		
		document.getElementById("stremail").style.background = "#F2CCCC";		
		document.getElementById("stremail").style.color = "#641A1A";
		document.getElementById("email").select();
		document.getElementById("email").focus();
	} else if ( company.value == "" || whiteSpace.test(company.value) ) {
		hideAllErrors();		
		document.getElementById("strcompany").style.border = "1px solid #CC3333";		
		document.getElementById("strcompany").style.background = "#F2CCCC";		
		document.getElementById("strcompany").style.color = "#641A1A";
		document.getElementById("company").select();
		document.getElementById("company").focus();
	} else {
		hideAllErrors();
		sendemail();
	}
}
function hideAllErrors() {
	document.getElementById("strname").style.border = "1px solid #80744D";		
	document.getElementById("strname").style.background = "#FFFFFF";		
	document.getElementById("strname").style.color = "#80744D";
	document.getElementById("stremail").style.border = "1px solid #80744D";		
	document.getElementById("stremail").style.background = "#FFFFFF";		
	document.getElementById("stremail").style.color = "#80744D";
	document.getElementById("strcompany").style.border = "1px solid #80744D";		
	document.getElementById("strcompany").style.background = "#FFFFFF";		
	document.getElementById("strcompany").style.color = "#80744D";
}
function sendemail () {
	var name = document.getElementById("strname");
	var email = document.getElementById("stremail");
	var company = document.getElementById("strcompany");		
	
	var url = "newsletter-process.asp?strname=" + name.value + "&stremail=" + email.value + "&strcompany=" + company.value;
	
	window.location = url;
}

function ajaxContact() {
var frm1 = document.getElementById('newsletterSignup');
addEvent(frm1, 'submit', validateFields, false);
frm1.onsubmit = function() { return false; }
}
addEvent(window, 'load',ajaxContact, false);

function toggle(targetId) {
	target = document.getElementById(targetId);
	if (target.style.display == 'block'){
		target.style.display='none';
	} else {
		target.style.display='block';
	}
}	