function quoteboxSubmit(f){
	ni_var1 = f.ni_var1.value;

	if(f.zipcode.value == ''){
		alert('Please enter your zipcode.');
		f.zipcode.focus();
		return false;
	} else if(!validZIP(f.zipcode.value)){
		alert('Please enter valid 5-digits zipcode.');
		f.zipcode.focus();
		return false;
	} else if(!existingZIP(f.zipcode.value)){
		alert('This zipcode does not exist.');
		f.zipcode.focus();
		return false;
	}

	var hostPrefix = (window.location.host == 'autoinsurancenet') ? 'http://autoinsurancenet/' : window.location.protocol + '//' + window.location.host + '/';
	var url, popup;
	var selected = f.srcid.value;

	switch(f.autoToggle.value){
		case 'FormsInsuranceAgents':
			FormsInsuranceAgents(f.zipcode.value, ni_var1);
			break;

		case 'AutoFrame':
			AutoFrame(f.zipcode.value, false, ni_var1 + '_x');
			break;

		case 'AutoFrameMOSS':
			AutoFrameMOSS(f.zipcode.value, ni_var1 + '-f');
			break;

		case 'BW':
			state = f.stateName.value;
			if(f.zipcode.value.length > 0){
				$.ajax({
					type: "POST",
					url: "/getStateByZip.php",
					data: "zipcode=" + f.zipcode.value,
					async:false,
					success: function(msg){
						state = msg;
					}
				});
			}
			var tgUrl = hostPrefix + 'Instant-' + state + '-Insurance-Quotes.php';
			$.ajax({
				type: "GET",
				url: '/savestat.php',
				data: "tgUrl=" + escape(tgUrl) + '&Nivar=' + ni_var1 + '&state=' + state,
				success: function(msg){
					document.location = tgUrl;
					return false;
				}
			});
			break;

		case 'auto_quote':
			var tgUrl = 'https://' + window.location.host + '/auto_quote.php';
			$.ajax({
				type: "GET",
				url: '/savestat.php',
				data: "tgUrl=" + escape(tgUrl),
				success: function(msg){
					document.location = tgUrl;
					return false;
				}
			});
			break;

		case 'trouve':
			var tgUrl = window.location.protocol + '//' + window.location.host + '/auto/quotes?curl=autoinsurancenet.net&from=' + window.location.host + '&sid=TE-A-BGL-1&zipCode=' + f.zipcode.value + '&psv=1&c2=' + ni_var1;
			$.ajax({
				type: "GET",
				url: '/savestat.php',
				data: "tgUrl=" + escape(tgUrl),
				success: function(msg){
					document.location = tgUrl;
					return false;
				}
			});
			break;

		case 'surehits':

		default:
			document.location = hostPrefix + 'autoinsurancequote.php?zip=' + f.zipcode.value + '&ni_var1=' + ni_var1;
			break;
	}

	return false;
}



function validateIns(f){
	srcid = '';
	if(f.srcid.value != ''){
		srcid = f.srcid.value;
	}

	if(srcid == 'get-quotes-results' || srcid == 'landingpage8002'){
		if(f.zipcode.value == ''){
			alert('Please select a state.');
			f.zipcode.focus();
			return false;
		}
	} else {
		/*if(f.zipcode.value == ''){
			alert('Please enter your zipcode.');
			f.zipcode.focus();
			return false;
		} else if((f.zipcode.value != '') && !validZIP(f.zipcode.value)){
			alert('Please enter valid 5-digits zipcode.');
			f.zipcode.focus();
			return false;
		} else if(!existingZIP(f.zipcode.value)){
			alert('This zipcode does not exist.');
			f.zipcode.focus();
			return false;
		}*/
	}

	var hostPrefix = (window.location.host == 'autoinsurancenet') ? 'http://autoinsurancenet/' : window.location.protocol + '//' + window.location.host + '/';

	var currently;

	if(typeof(f.currently) != 'undefined'){
		if(f.currently[0].checked){
			currently = 1;
		} else if(f.currently[1].checked){
			currently = 0;
		} else {
			currently = -1;
		}
	} else {
		currently = 1;
	}

	ni_var1 = f.ni_var1.value;

	if(srcid == 'get-auto-insurance-quotes')
	{
		var toggle = '';
		if(currently == 0){
			toggle = f.tgNo.value;
		} else {
			toggle = f.tgYes.value;
		}

		switch(toggle){
			case 'bw':
				state = f.stateName.value;
				if(f.zipcode.value.length > 0){
					$.ajax({
						type: "POST",
						url: "/getStateByZip.php",
						data: "zipcode=" + f.zipcode.value,
						async:false,
						success: function(msg){
							state = msg;
						}
					});
				}
				var tgUrl = hostPrefix + 'Instant-' + state + '-Insurance-Quotes.php';
				$.ajax({
					type: "GET",
					url: '/savestat.php',
					data: "tgUrl=" + escape(tgUrl) + '&Nivar=' + ni_var1 + '&state=' + state,
					success: function(msg){
						document.location = tgUrl;
						return false;
					}
				});
				break;

			case 'surehits':
				document.location = hostPrefix + 'autoinsurancequote.php?zip=' + f.zipcode.value + '&ni_var1=' + ni_var1;
				break;

			case 'moss':
				AutoFrameMOSS(f.zipcode.value, ni_var1 + '-f');
				break;

			case 'moss_bw': {
				AutoFrameMOSS(f.zipcode.value, ni_var1 + '-f', true);
				state = f.stateName.value;
				if(f.zipcode.value.length > 0){
					$.ajax({
						type: "POST",
						url: "/getStateByZip.php",
						data: "zipcode=" + f.zipcode.value,
						async:false,
						success: function(msg){
							state = msg;
						}
					});
				}
				var tgUrl = hostPrefix + 'Instant-' + state + '-Insurance-Quotes.php';
				$.ajax({
					type: "GET",
					url: '/savestat.php',
					data: "tgUrl=" + escape(tgUrl) + '&Nivar=' + ni_var1 + '&state=' + state,
					success: function(msg){
						document.location = tgUrl;
						return false;
					}
				});
				break;
			}

			case 'auto_quote': {
				var tgUrl = 'https://' + window.location.host + '/auto_quote.php';
				$.ajax({
					type: "GET",
					url: '/savestat.php',
					data: "tgUrl=" + escape(tgUrl),
					success: function(msg){
						document.location = tgUrl;
						return false;
					}
				});
				break;
			}

			case 'trouve':
				var tgUrl = window.location.protocol + '//' + window.location.host + '/auto/quotes?curl=autoinsurancenet.net&from=' + window.location.host + '&sid=TE-A-BGL-1&zipCode=' + f.zipcode.value + '&psv=1&c2=' + ni_var1;
				$.ajax({
					type: "GET",
					url: '/savestat.php',
					data: "tgUrl=" + escape(tgUrl),
					success: function(msg){
						document.location = tgUrl;
						return false;
					}
				});
				break;
		}
		return false;
	}
	else
	{
		var hostPrefix = (window.location.host == 'autoinsurancenet') ? 'http://autoinsurancenet/' : window.location.protocol + '//' + window.location.host + '/';

		xmlUrl = '/toggle.php?toggle=auto';
		xmlHttp.open('GET', xmlUrl, true);

		xmlHttp.onreadystatechange = function(){
			if(xmlHttp.readyState == 4){
				if(xmlHttp.status == 200){
					if(xmlHttp.responseText == 'FormsInsuranceAgents'){
						FormsInsuranceAgents(f.zipcode.value, ni_var1);
					} else if(xmlHttp.responseText == 'AutoFrame'){
						AutoFrame(f.zipcode.value, currently, ni_var1 + '_x');
					} else if(xmlHttp.responseText == 'AutoFrameMOSS'){
						AutoFrameMOSS(f.zipcode.value, ni_var1 + '-f');
					} else if(xmlHttp.responseText == 'BW'){
						state = f.stateName.value;
						if(f.zipcode.value.length > 0){
							$.ajax({
								type: "POST",
								url: "/getStateByZip.php",
								data: "zipcode=" + f.zipcode.value,
								async:false,
								success: function(msg){
									state = msg;
								}
							});
						}
						var tgUrl = hostPrefix + 'Instant-' + state + '-Insurance-Quotes.php';
						$.ajax({
							type: "GET",
							url: '/savestat.php',
							data: "tgUrl=" + escape(tgUrl) + '&Nivar=' + ni_var1 + '&state=' + state,
							success: function(msg){
								document.location = tgUrl;
								return false;
							}
						});
						return false;



					} else if(xmlHttp.responseText == 'BW2'){
						state = f.stateName.value;
						if(f.zipcode.value.length > 0){
							$.ajax({
								type: "POST",
								url: "/getStateByZip.php",
								data: "zipcode=" + f.zipcode.value,
								async:false,
								success: function(msg){
									state = msg;
								}
							});
						}
						var tgUrl = hostPrefix + 'Instant-' + state + '-Insurance-Quotes2.php';
						$.ajax({
							type: "GET",
							url: '/savestat.php',
							data: "tgUrl=" + escape(tgUrl) + '&Nivar=' + ni_var1 + '&state=' + state,
							success: function(msg){
								document.location = tgUrl;
								return false;
							}
						});
						return false;
					}



					else if(xmlHttp.responseText == 'surehits')
					{
						document.location = hostPrefix + 'autoinsurancequote.php?zip=' + f.zipcode.value + '&ni_var1=' + ni_var1;
					}
					else if(xmlHttp.responseText == 'auto_quote')
					{
						var tgUrl = 'https://' + window.location.host + '/auto_quote.php';
						$.ajax({
							type: "GET",
							url: '/savestat.php',
							data: "tgUrl=" + escape(tgUrl),
							success: function(msg){
								document.location = tgUrl;
								return false;
							}
						});
						return false;
					}
					else if(xmlHttp.responseText == 'trouve')
					{
						var tgUrl = window.location.protocol + '//' + window.location.host + '/auto/quotes?curl=autoinsurancenet.net&from=' + window.location.host + '&sid=TE-A-BGL-1&zipCode=' + f.zipcode.value + '&psv=1&c2=' + ni_var1;
						$.ajax({
							type: "GET",
							url: '/savestat.php',
							data: "tgUrl=" + escape(tgUrl),
							success: function(msg){
								document.location = tgUrl;
								return false;
							}
						});
						return false;
					}
				}
			}
		}
		xmlHttp.send(null);

		return false;
	}
}


function moss_and_bw(zipcode, ni_var1){
	AutoFrameMOSS(zipcode, ni_var1 + '-f', true);

	var hostPrefix = (window.location.host == 'autoinsurancenet') ? 'http://autoinsurancenet/' : window.location.protocol + '//' + window.location.host + '/';
	state = f.stateName.value;

	if(zipcode.length > 0){
		$.ajax({
			type: "POST",
			url: "/getStateByZip.php",
			data: "zipcode=" + zipcode,
			async:false,
			success: function(msg){
				state = msg;
			}
		});
	}

	var tgUrl = hostPrefix + 'Instant-' + state + '-Insurance-Quotes.php';

	$.ajax({
		type: "GET",
		url: '/savestat.php',
		data: "tgUrl=" + escape(tgUrl) + '&Nivar=' + ni_var1 + '&state=' + state,
		success: function(msg){
			document.location = tgUrl;
			return false;
		}
	});
}

function validateGetAutoInsurance(f){
	if(f.zipcode.value == ''){
		alert('Please enter your zipcode.');
		f.zipcode.focus();
		return false;
	} else if(!validZIP(f.zipcode.value)){
		alert('Please enter valid 5-digits zipcode.');
		f.zipcode.focus();
		return false;
	} else if(!existingZIP(f.zipcode.value)){
		alert('This zipcode does not exist.');
		f.zipcode.focus();
		return false;
	}

	var zipcode = f.zipcode.value;
	var ni_var1 = f.ni_var1.value;
	var toggle = f.toggle.value;

	var hostPrefix = (window.location.host == 'autoinsurancenet') ? 'http://autoinsurancenet/' : window.location.protocol + '//' + window.location.host + '/';
	switch(toggle){
		case 'bw':
			document.location = hostPrefix + 'getautoinsurancequote.php?zip=' + zipcode + '&ni_var1=' + ni_var1;
			break;
		case 'surehits':
			document.location = hostPrefix + 'autoinsurancequote.php?zip=' + zipcode + '&ni_var1=' + ni_var1;
			break;
		case 'auto_quote':
			document.location = 'https://' + window.location.host + '/auto_quote.php';
			break;
		case 'trouve':
			document.location = window.location.protocol + '//' + window.location.host + '/auto/quotes?curl=autoinsurancenet.net&from=' + window.location.host + '&sid=TE-A-BGL-1&zipCode=' + f.zipcode.value + '&psv=1&c2=' + ni_var1;
			break;
		case 'moss':
			AutoFrameMOSS(f.zipcode.value, ni_var1 + '-f');
			break;
		case 'moss_bw':
			AutoFrameMOSS(f.zipcode.value, ni_var1 + '-f', true);
			document.location = hostPrefix + 'getautoinsurancequote.php?zip=' + zipcode + '&ni_var1=' + ni_var1;
			break;
		case 'moss_sh':
			AutoFrameMOSS(f.zipcode.value, ni_var1 + '-f', true);
			document.location = hostPrefix + 'autoinsurancequote.php?zip=' + zipcode + '&ni_var1=' + ni_var1;
			break;
	}
	return false;
}

function autotestSubmit(f){
	var ni_var1 = f.ni_var1.value;
	if(f.zipcode.value == ''){
		alert('Please enter your zipcode.');
		f.zipcode.focus();
		return false;
	} else if(!validZIP(f.zipcode.value)){
		alert('Please enter valid 5-digits zipcode.');
		f.zipcode.focus();
		return false;
	} else if(!existingZIP(f.zipcode.value)){
		alert('This zipcode does not exist.');
		f.zipcode.focus();
		return false;
	}
	document.location = window.location.protocol + '//' + window.location.host + '/auto/quotes?curl=autoinsurancenet.net&from=' + window.location.host + '&sid=TE-A-BGL-1&zipCode=' + f.zipcode.value + '&psv=1&c2=' + ni_var1;
	return false;
}
