function redirect(formname, domain) {
	//initialize variables
	var docform = document.getElementById(formname);
	var msg = "";
	
	//fetch variable values from form
	var zip = docform.zipCode.value;
	var sid = docform.sid.value;
	var curl = docform.curl.value;
	var from = docform.from.value;
	var psv = docform.psv.value;
	
	//validate zip code using checkZip() function
	//set alert message if returned false
	if (!checkZip(zip)) {
		msg = "Please enter a valid zipcode. \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.
		var url = "/auto/quotes?zipCode="+ zip + "&sid=" + sid + "&curl=" + curl + "&from=" + from + "&psv=" + psv;
		if (docform.c1) {
			url = url + "&c1=" + docform.c1.value;
		}
		if (docform.c2) {
			url = url + "&c2=" + docform.c2.value;
		}
		if (docform.c3) {
			url = url + "&c3=" + docform.c3.value;
		}
		if (domain) {
			var url = "https://" + domain + url;
		}
		window.open(url);
		docform.action = "/listings";
		return true;
	}	
		
}

function checkZip(strString) {
	var strValidChars = "0123456789";
	var strChar;
	var blnResult = true;

	if (strString.length < 5) return false;
	for (i = 0; i < strString.length && blnResult == true; i++) {
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1) {
			blnResult = false;
		}
	}
	return blnResult;
}
