function ajaxFunction(filename,show,funcname) {
	var xmlHttp, sendURL;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) window[funcname](xmlHttp.responseText);
	}
	sendURL = filename+".php?val="+show;
	xmlHttp.open("GET",sendURL,true);
	xmlHttp.send(null);
}

function fillOptions(responseText) {
	var elSel = document.qtfrm.Car_Model;
	var newOpts = responseText.split(";");
	for (x=0;x<newOpts.length;x++) {
		var newOption = new Option(newOpts[x],newOpts[x]);
		elSel.options[x] = newOption;
	}
}

function PhoneValidate(currentField,nextField,maxLen) {
    if (currentField.value.length == maxLen) document.qtfrm[nextField].focus();
}

function autolayer(x) {
	if (document.all) var div = document.all.autolayer;
	else var div = document.getElementById("autolayer");
	if (x) {
		if (!document.qtfrm.Car_Model.value) ajaxFunction('cars',document.qtfrm.Car_Make.value,'fillOptions');
		div.style.display = 'inline';
	}
	else div.style.display = 'none';
}

function chkSubmit(x) {
	if (x==1) {
		if (document.qtfrm.zip.value.length != 5 || !document.qtfrm.state.value || !document.qtfrm.res.value) alert("Please fill all related fields");
		else ajaxFunction('zipcheck',document.qtfrm.zip.value,'checkzip');
		return false;
	}
	if (x==2) {
		var missingContent = false, zipStr = "",a="";
		for (t=0; t<document.qtfrm.elements.length ;t++ ) {
			if ((t<5 || t>9) && t!=23 && t!=13 && t<29) {
				if (t<25 || (t>=25 && document.qtfrm.Auto_Move.checked)) {
					if (!document.qtfrm.First_Name.value || !document.qtfrm.Last_Name.value || !document.qtfrm.Hphone1.value || !document.qtfrm.Hphone2.value || !document.qtfrm.Hphone3.value || !document.qtfrm.Email.value || !document.qtfrm.Contact_Preference.value || !document.qtfrm.Contact_Time.value || !document.qtfrm.From_City.value || !document.qtfrm.To_City.value || !document.qtfrm.From_State.value || !document.qtfrm.To_State.value || !document.qtfrm.From_Zip.value || !document.qtfrm.MoveMonth.value || !document.qtfrm.MoveDay.value || !document.qtfrm.MoveYear.value || !document.qtfrm.Move_Size.value || (!document.qtfrm.Car_Make.value && document.qtfrm.Auto_Move.checked) || (!document.qtfrm.Car_Model.value && document.qtfrm.Auto_Move.checked) || (!document.qtfrm.Car_Year.value && document.qtfrm.Auto_Move.checked)) missingContent = true;
				}
			}
		}
		if (missingContent) {
			alert("Please fill all fields marked in red");
			return false;
		}
		else {
			if (document.qtfrm.areacode.value.indexOf(document.qtfrm.Hphone1.value) == -1) {
				alert("Please fill out a valid area code");
				return false;
			}
		}
	}
	if (x==3) {
		document.fnlfrm.divval.value = document.getElementById("frmdata").innerHTML;
		document.fnlfrm.submit();
	}
	if (x==4) {
		if (document.cntftm.fullname.value == "" || document.cntftm.email.value == "" || document.cntftm.mes.value == "") {
			alert("Please complete all the form");
			return false;
		}
	}
}

function checkzip(val) {
	if (!val) alert("Please provide a valid ZIP code");
	else document.qtfrm.submit();
}

function showhelp(dn) {
	var div = document.getElementById(dn);
	showwindow(div);
	if (dn=='biz') {
		div.innerHTML = "What does your business do? (moving, agent etc.)";
		div.style.width = "320";
		div.style.height = "20";
	}
	if (dn=='auto') {
		div.innerHTML = "Are you interested in moving your car in a truck?";
		div.style.width = "310";
		div.style.height = "20";
	}
}

function emailsResponse(responseText) {
	if (responseText == "ok") {
		document.getElementById('processing').innerHTML = "";
		document.getElementById('response').style.display = "inline";
		document.optfrm.sbmt.style.display = "inline";
	}
	else document.getElementById('processing').innerHTML = responseText;
}
