function ajax() {
	var ro;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		ro = new XMLHttpRequest();
	}
	return ro;
}

function setPrice() {
	numbooths = document.form.numbooths.value;
	switch (document.form.type.selectedIndex) {
		case 1:
			boothprice = 200;
		break;
		case 2:
			boothprice = 100;
		break;
	}
	if(document.form.corner.checked == true) {
		corner = 100;	
	} else {
		corner = 0;	
	}
	
	var price = (numbooths * boothprice) + corner;
	
	document.getElementById("price").innerHTML = '$' + price;
	document.form.amount.value = price;
}

function checkForm() {
	if(document.form.company.value == '') {
		alert("Company Name is missing");
		document.form.company.focus();
	} else if(document.form.contact.value == '') {
		alert("Contact Name is missing");
		document.form.contact.focus();
	} else if(document.form.address1.value == '') {
		alert("Address is missing");
		document.form.address1.focus();
	} else if(document.form.city.value == '') {
		alert("City is missing");
		document.form.city.focus();
	} else if(document.form.state.value == '') {
		alert("State is missing");
		document.form.state.focus();
	} else if(document.form.zip.value == '') {
		alert("Zip Code is missing");
		document.form.zip.focus();
	} else if(document.form.phone.value == '') {
		alert("Phone Number is missing");
		document.form.phone.focus();
	} else if(document.form.email.value == '') {
		alert("Email Address is missing");
		document.form.email.focus();
	} else if(document.form.brands.value == '') {
		alert("List your brands");
		document.form.brands.focus();
	} else if(document.form.type.selectedIndex == 0) {
		alert("Select your booth type");	
	} else {
		submitForm();	
	}
}

function submitForm() {
	var	company = document.form.company.value;
	var contact = document.form.contact.value;
	var address1 = document.form.address1.value;
	var address2 = document.form.address2.value;
	var city = document.form.city.value;
	var state = document.form.state.value;
	var zip = document.form.zip.value;
	var phone = document.form.phone.value;
	var email = document.form.email.value;
	var website = document.form.website.value;
	var type = document.form.type.value;
	var numbooths = document.form.numbooths.value;
	if(document.form.corner.checked == true) {
		var corner = 1;	
	} else {
		var corner = 0;	
	}
	var pref1 = document.form.pref1.value;
	var pref2 = document.form.pref2.value;
	var brands = document.form.brands.value;
	var fourwords = document.form.fourwords.value;
	var transid = document.form.transaction_id.value;
	
	var ajx = new ajax;
	var params = 'action=submit&company=' + company + '&contact=' + contact + '&address1=' + address1 + '&address2=' + address2 + '&city=' + city + '&state=' + state + '&zip=' + zip + '&phone=' + phone + '&email=' + email + '&website=' + website + '&type=' + type + '&numbooths=' + numbooths + '&corner=' + corner + '&pref1=' + pref1 + '&pref2=' + pref2 + '&brands=' + brands + '&fourwords=' + fourwords + '&transid=' + transid;
	ajx.open('POST', 'script/ajax.php',true);
	ajx.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ajx.setRequestHeader("Content-length", params.length);
	ajx.setRequestHeader("Connection", "close");
    ajx.onreadystatechange = function() {
		if(ajx.readyState == 4){
			//alert(ajx.responseText);
			if(ajx.responseText == 'success') {
				document.form.submit();
			} else {
				alert("There was an error with your transaction, please contact customer support at 801.204.6840");	
			}
		}
	}
    ajx.send(params);	
}