function redirect() {
	//initialize variables		
	var sid = "";
	var zip = "";
	var ins = "";
	var msg = "";
	
	//fetch variable values from form
	var zip = document.getElementById('form1').z.value;
	var sid = document.getElementById('form1').sid.value;
	for (var i=0; i < document.getElementById('form1').ins.length; i++) { 
		if (document.getElementById('form1').ins[i].checked) {
				var ins = document.getElementById('form1').ins[i].value;
		}
	}
	
	//fetch XML validation by pinging state.php
	//set alert message if 'Invalid' is returned
	if (window.XMLHttpRequest) {
		xhttp=new XMLHttpRequest()
	} else {
		xhttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	xhttp.open("GET","/state.php?zipcode=" + zip,false);
	xhttp.send("");
	xmlDoc=xhttp.responseXML;
	results = xmlDoc.getElementsByTagName("state")[0].childNodes[0].nodeValue;
	if (results == 'Invalid') {
		var msg = "Please enter a valid zipcode. \n";
	}
	if (ins == "") {
		var msg = msg + "Please tell us your insured status. \n"
	}
	
	//pass or fail the form		
	if (msg != "") { //if msg is set then validation has failed. Pop msg and retun false.
		alert(msg);			
		return false;				
	} else { //if msg is blank then validation has passed. Open LRS window and return true.
		document.getElementById('form1').action = 'redirect.php';
		return true;
	}
}

function redirect_pop() {
	//initialize variables		
	var sid = "";
	var zip = "";
	var ins = "";
	var msg = "";
	
	//fetch variable values from form
	var zip = document.getElementById('form1').z.value;
	var sid = document.getElementById('form1').sid.value;
	for (var i=0; i < document.getElementById('form1').ins.length; i++) { 
		if (document.getElementById('form1').ins[i].checked) {
				var ins = document.getElementById('form1').ins[i].value;
		}
	}
	
	//fetch XML validation by pinging state.php
	//set alert message if 'Invalid' is returned
	if (window.XMLHttpRequest) {
		xhttp=new XMLHttpRequest()
	} else {
		xhttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	xhttp.open("GET","/state.php?zipcode=" + zip,false);
	xhttp.send("");
	xmlDoc=xhttp.responseXML;
	results = xmlDoc.getElementsByTagName("state")[0].childNodes[0].nodeValue;
	if (results == 'Invalid') {
		var msg = "Please enter a valid zipcode. \n";
	}
	if (ins == "") {
		var msg = msg + "Please tell us your insured status. \n"
	}
	
	//pass or fail the form		
	if (msg != "") { //if msg is set then validation has failed. Pop msg and retun false.
		alert(msg);			
		return false;				
	} else { //if msg is blank then validation has passed. Open LRS window and return true.
		if (ins == 'Y') {	
			window.open("/redirect.php?PromoID="+ sid + "&ZipCode=" + zip + "&insradio=" + ins);
			document.getElementById('form1').action = '/surehits.php';
		} else {
			document.getElementById('form1').action = '/redirect.php';
		}
		return true;
	}
}

function openwin(url,name){
	window.open (url, name, config='height=500,width=550, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, directories=no, status=no');
}
