var http='';
function contactFormCheck(ajax,action,next,formid){
	var querystr='';
	var theForm = document.getElementById(formid);
	var emailFilter=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	if (document.getElementById('fname') && document.getElementById('fname').value==''){
			alert('Please enter your first name');
			document.getElementById('fname').focus();
			//document.getElementById("reqFName").style.color="red";
			return false;
	}
	if (document.getElementById('lname') && document.getElementById('lname').value==''){
			alert('Please enter your last name');
			document.getElementById('lname').focus();
			return false;
	}
	if (document.getElementById('company') && document.getElementById('company').value==''){
			alert('Please enter the name of your company');
			document.getElementById('company').focus();
			return false;
	}
	if (document.getElementById('address') && document.getElementById('address').value==''){
			alert('Please enter your address');
			document.getElementById('address').focus();
			return false;
	}
	if (document.getElementById('zip') && document.getElementById('zip').value==''){
			alert('Please enter your zip');
			document.getElementById('zip').focus();
			return false;
	}
	if (document.getElementById('city') && document.getElementById('city').value==''){
			alert('Please enter your city');
			document.getElementById('city').focus();
			return false;
	}
	if (document.getElementById('state') && document.getElementById('state').value==''){
			alert('Please enter your state');
			document.getElementById('state').focus();
			return false;
	}
	if (document.getElementById('phone') && document.getElementById('phone').value==''){
			alert('Please enter your phone');
			document.getElementById('phone').focus();
			return false;
	}
	if (document.getElementById('email') && !(emailFilter.test(document.getElementById('email').value))){
			alert('Please enter your email address correctly');
			document.getElementById('email').focus();
			return false;
	}
	if(ajax){
		for (i=0;i<theForm.elements.length;i++){
			if( (theForm.elements[i].name!="product1") && (theForm.elements[i].name!="product2") && (theForm.elements[i].name!="product3") && (theForm.elements[i].name!="product4") && (theForm.elements[i].name!="product5") ){
				querystr=querystr+theForm.elements[i].name+'='+ theForm.elements[i].value+'&';
			}
			
			if(theForm.elements[i].name=="product1" && theForm.elements[i].checked){
				querystr=querystr+theForm.elements[i].name+'='+ theForm.elements[i].value+'&';
			}
			if(theForm.elements[i].name=="product2" && theForm.elements[i].checked){
				querystr=querystr+theForm.elements[i].name+'='+ theForm.elements[i].value+'&';
			}
			if(theForm.elements[i].name=="product3" && theForm.elements[i].checked){
				querystr=querystr+theForm.elements[i].name+'='+ theForm.elements[i].value+'&';
			}
			if(theForm.elements[i].name=="product4" && theForm.elements[i].checked){
				querystr=querystr+theForm.elements[i].name+'='+ theForm.elements[i].value+'&';
			}
			if(theForm.elements[i].name=="product5" && theForm.elements[i].checked){
				querystr=querystr+theForm.elements[i].name+'='+ theForm.elements[i].value+'&';
			}
			
			//theForm.elements[i].value='';
			
		}
		querystr=querystr+'submit=1';
		
		document.getElementById('processing').innerHTML="<div align='left'>Loading...</div>";
		ajaxForm(action,querystr,next);
		return false;
	}
	return true;
}

/*function getHTTPObject(){
	var xhr=false;
	if(window.XMLHttpRequest){
		xhr=new XMLHttpRequest();
	}
	else if(window.ActiveXObject){
		try{
			xhr=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e){
			try{
				xhr=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){}
		}
	}
	return xhr;
}

function ajaxForm(action,request_vars,next){
	//window.onload=init;
	http='';
	http=getHTTPObject();
	next_function = next;
	http.open('get',  action + '.php?' + request_vars);
	http.onreadystatechange = ajres;
	http.send(null);
}
function ajres() 
{
    if(http.readyState==4)
    {    	
		eval(next_function + "(http.responseText)"); 
	}
}
function formResult(result,param){
	alert(result);
	document.getElementById('processing').innerHTML='<h4>'+result+'</h4>';
}*/