// JavaScript Document
function displayEmail(name, text){
	document.write('<a href="mailto:' + name + '@thebrandconsultancy.com">');
	document.write(text);
	document.write('</a>');
}


function GetXmlHttpObject(){
	var xmlHttp=null;
	try{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e){
	// Internet Explorer
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function validateContactForm(){
	var emailAddress = document.getElementById("email").value;
	var title = document.getElementById("title").value;
	var company = document.getElementById("company").value;
	var name = document.getElementById("name").value;

	var msg = "";
	
	if(name==""){
		msg += "You must provide your name\n";
	}	
	if(emailAddress==""){
		msg += "You must provide a valid email address\n";
	}	
	if(title==""){
		msg += "You must provide your title\n";
	}	
	if(company==""){
		msg += "You must provide your company\n";
	}	
	
	if(msg==""){
		return(true);
	}else{
		alert(msg);	
		return(false);
	}
}

function submitContactForm(){
	if( validateContactForm() ){
		var email = document.getElementById("email").value;
		var title = document.getElementById("title").value;
		var company = document.getElementById("company").value;
		var comments = document.getElementById("comments").value;
		var phone = document.getElementById("phone").value;
		var marketing = document.getElementById("marketing").value;
		var name = document.getElementById("name").value;
		if(	document.getElementById("signup").checked ){
			var add = "Yes";	
		}else{
			var add = "No";
		}

		
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null){
		  alert ("Your browser does not support AJAX!");
		  return;
		} 
		var url="ajax_contact.php";
		var params="email=" + email;
		params=params+"&title="+title; 
		params=params+"&company="+company; 
		params=params+"&name="+name; 
		params=params+"&add="+add; 
		params=params+"&comments="+comments; 
		params=params+"&phone="+phone; 
		params=params+"&marketing="+marketing; 
		params=params+"&ip="+client_ip; 
		params=params+"&sid="+Math.random(); //used to force no cache of URL
	
		url = url + "?" + params;
		//alert(url);
		xmlHttp.onreadystatechange=email_signup_done;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(params);
   }
	return(false);
}

function email_signup_done(){
	if (xmlHttp.readyState==4){ 
		submit_success();
		//alert(xmlHttp.responseText);
		return(false);
	}
}


function submit_success(){
//	alert('fade');
	$("#form").fadeOut( ("slow"), function(){$("#thanks").fadeIn("slow") } );
}
						
function show_thanks(){
	$("#form").fadeOut( ("slow"), function(){$("#thanks").fadeIn("slow") } );

}
						