// JavaScript Document

/* Open XML connection */
function createXMLHttpRequest() {
	try{return new XMLHttpRequest();}
	catch(e){
		try { return new ActiveXObject('Msxml2.XMLHTTP'); }
		catch(e){
			try { return new ActiveXObject('Microsoft.XMLHTTP'); }
			catch(e){}
		}	
	}
	
	return null;
}

/* Use XML to contact the email page */
function SendEmail() {
	var xmlHttp = createXMLHttpRequest();
	xmlHttp.open('GET', '/contact/sendmail.asp?Name=' + document.getElementById('Name').value + '&Email=' + document.getElementById('Email').value + '&Message=' + document.getElementById('Message').value.replace(/\n/g, '<br />').replace(/\?/g,'*qu*').replace(/\&/g,'*am*').replace(/\=/g,'*eq*').replace(/\+/g,'*pl*'), false);
	xmlHttp.send(null);
	
	var myFunction = function(){
		var divFx = new Fx.Style('loadBar', 'opacity', {
			duration: 400, 
			transition: Fx.Transitions.quartInOut
		});
		
		divFx.start(0,1); // fade it in
	}
	
	document.getElementById('spaceHolder').style.display = 'none';
	
	myFunction(); // Fade the "Sending" text in and out
	
	if (xmlHttp.status == 200) {
		var myFunction2 = function(){
			var divFx = new Fx.Style('loadBar', 'opacity', {
				duration: 50, 
				transition: Fx.Transitions.quartInOut
			});
			
			var divFx2 = new Fx.Style('emailSuccess', 'opacity', {
				duration: 500, 
				transition: Fx.Transitions.quartInOut
			});
			
			divFx.start.pass([1,0], divFx).delay(0);
			
			document.getElementById('loadBar').style.display = 'none';
			document.getElementById('emailSuccess').style.display = '';
			
			divFx2.start(0,1); // fade it in
			divFx2.start.pass([1,0], divFx2).delay(5000); // and back out
		}
		
		myFunction2(); // Fade the "Success" text in and out
	} else {
		var myFunction2 = function(){
			var divFx = new Fx.Style('loadBar', 'opacity', {
				duration: 50, 
				transition: Fx.Transitions.quartInOut
			});
			
			var divFx2 = new Fx.Style('emailFailed', 'opacity', {
				duration: 500, 
				transition: Fx.Transitions.quartInOut
			});
			
			divFx.start.pass([1,0], divFx).delay(0);
			
			document.getElementById('loadBar').style.display = 'none';
			document.getElementById('emailFailed').style.display = '';
			
			divFx2.start(0,1); // fade it in
			divFx2.start.pass([1,0], divFx2).delay(5000); // and back out
		}
		
		myFunction2(); // Fade the "Failure" text in and out
	}
	
	return xmlHttp.responseText;
}