// CREATING THE REQUEST

function createRequestObject()
{
	try
	{
		xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(e)
	{
		alert('Sorry, but your browser doesn\'t support XMLHttpRequest.');
	}
	return xmlhttp;
}

var http = createRequestObject();
var sess = createRequestObject();

// IMAGE REFRESHING

function refreshimg()
{
	var url = 'image_req.php';
	dorefresh(url, displayimg);
}

function dorefresh(url, callback)
{
	sess.open('POST', 'newsession.php', true);
	sess.send(null);
	http.open('POST', url, true);
	http.onreadystatechange = displayimg;
	http.send(null);
}

function displayimg()
{
	if(http.readyState == 4)
	{
		var showimage = http.responseText;
		document.getElementById('captchaimage').innerHTML = showimage;
	}
}

// SUBMISSION

function check()
{
	var submission = document.f.captcha.value;

    var querystring = "";

				querystring += "&company=" + document.f.company.value;
				querystring += "&email=" + document.f.email.value;
				querystring += "&username=" + document.f.username.value;

    submission+=querystring;
	var url = 'process.php?captcha='+submission+''+querystring;
	//var url = 'process.php?captcha='+submission;
	docheck(url, displaycheck);
}

function docheck(url, callback)
{
	http.open('GET', url, true);
	http.onreadystatechange = displaycheck;
	http.send(null);
}

function displaycheck()
{
	if(http.readyState == 4)
	{
		var showcheck = http.responseText;
		//alert(showcheck);

		a = showcheck.split(" ");
		//names validation         
		//email validation 
		
		if(a[1]==0){
			document.f.company.style.border = '1px solid #c24949';
			document.f.company.style.background = '#ffbcbc';
	
		} else {
			document.f.company.style.border = '1px solid #49c24f';
			document.f.company.style.background = '#bcffbf';
				
		}
		
		if(a[2]==0){
			document.f.email.style.border = '1px solid #c24949';
			document.f.email.style.background = '#ffbcbc';

	
		} else if(a[2]==2){
			document.f.email.style.border = '1px solid #c24949';
			document.f.email.style.background = '#ffbcbc';


		} else {
			document.f.email.style.border = '1px solid #49c24f';
			document.f.email.style.background = '#bcffbf';
				
		}
		
		//pw validation 

		
		
		if(a[3]==0){
			document.f.username.style.border = '1px solid #c24949';
			document.f.username.style.background = '#ffbcbc';

	
		} else {
			document.f.username.style.border = '1px solid #49c24f';
			document.f.username.style.background = '#bcffbf';
				
		}
		
		//
		
		if(a[0]==1){
		  //document.location.href="reg_step2.php";	
		  document.getElementById('main').innerHTML = "Thank you for your inquiry. We will contact you shortly.";
		}
		
	}
}



