function isZipcode(value)
{
	var exp_zipcode = /^[0-9]{5}$/;
	return exp_zipcode.test(value); 
}

function showPopup(currentForm) {
	prodid = currentForm.prodid.value;
	
	var siteURL ="";
	siteURL = url_prefix + "quotes_popup.php";
	siteURL = siteURL + "?prodid=" + prodid;
	
	if (typeof currentForm.zip != 'undefined') {
		zip = currentForm.zip.value;
		siteURL = siteURL + "&zip=" + zip;
	} else {
		state = currentForm.st.value;
		siteURL = siteURL + "&st=" + state;
	}
	siteURL = siteURL + "&source=top_window";
	window.open(siteURL,null,"fullscreen=yes, toolbars=yes, scrollbars=yes, menubar=yes, location=yes");
}

function validateForm(currentForm) {
	var elementsInputs;
	elementsInputs = currentForm.getElementsByTagName("input"); 
	for (var intCounter = 0; intCounter < elementsInputs.length; intCounter++) { 
		if (elementsInputs[intCounter].name == "zip") { 
			if (!(isZipcode(elementsInputs[intCounter].value))) {
				alert("To proceed please enter a valid ZIP Code.");
				elementsInputs[intCounter].focus();
				return false;
			}
		}
	}
	return true;
}

function validateQuotesForm(currentForm) {
	var elementsInputs;
	elementsInputs = currentForm.getElementsByTagName("input"); 
	for (var intCounter = 0; intCounter < elementsInputs.length; intCounter++) { 
		if (elementsInputs[intCounter].name == "zip") { 
			if (!(isZipcode(elementsInputs[intCounter].value))) {
				alert("To proceed please enter a valid ZIP Code.");
				elementsInputs[intCounter].focus();
				return false;
			}
		}
	}
	
	showPopup(currentForm);
	return true;
}

function validateFormLanding(currentForm) {
	var elementsInputs;
	elementsInputs = currentForm.getElementsByTagName("input"); 
	for (var intCounter = 0; intCounter < elementsInputs.length; intCounter++) { 
		if (elementsInputs[intCounter].name == "zip") { 
			if (!(isZipcode(elementsInputs[intCounter].value))) {
				alert("To proceed please enter a valid ZIP Code.");
				elementsInputs[intCounter].focus();
				return false;
			}
		}
	}
	currentForm.submit();
}

function validateQuotesFormLanding(currentForm) {
	var elementsInputs;
	elementsInputs = currentForm.getElementsByTagName("input"); 
	for (var intCounter = 0; intCounter < elementsInputs.length; intCounter++) { 
		if (elementsInputs[intCounter].name == "zip") { 
			if (!(isZipcode(elementsInputs[intCounter].value))) {
				alert("To proceed please enter a valid ZIP Code.");
				elementsInputs[intCounter].focus();
				return false;
			}
		}
	}
	
	showPopup(currentForm);
	currentForm.submit();
}

function formStValidate(f) {
	if (f.st.value == 0) {
		alert('Please select your state and then click on get quotes');	
		return false;
	}
	return true;
}

function quotesFormStValidate(f) {
	if (f.st.value == 0) {
		alert('Please select your state and then click on get quotes');	
		return false;
	}
	
	showPopup(f);
	return true;
}

function formStValidateLanding(f) {
	if (f.st.value == 0) {
		alert('Please select your state and then click on get quotes');	
		return false;
	}
	f.submit();
}

function quotesFormStValidateLanding(f) {
	if (f.st.value == 0) {
		alert('Please select your state and then click on get quotes');	
		return false;
	}
	
	showPopup(f);
	f.submit();
}

function doIQ() {
	setFocusFrmIQ();
	addResultsText();
	getTodayDate();
}

function addResultsText() {
	if (document.getElementById('bwapsheader') != null)
		document.getElementById('bwapsheader').innerHTML = '<div id="quotesTitle">Recommended Quote Providers for' + document.getElementById('bwapsheader').innerHTML + '</div><div id="todaydate"></div>';
}

function setFocusFrmIQ()
{
	var form = document.getElementById('frmTop');
	if (form)
		form.zip.focus()
}

function getTodayDate() {
	var months=new Array(13);
	months[1]="01";
	months[2]="02";
	months[3]="03";
	months[4]="04";
	months[5]="05";
	months[6]="06";
	months[7]="07";
	months[8]="08";
	months[9]="09";
	months[10]="10";
	months[11]="11";
	months[12]="12";
	var time=new Date();
	var lmonth=months[time.getMonth() + 1];
	var date=time.getDate();
	var year=time.getYear();
	if (year < 2000)
	year = year + 1900;
	document.getElementById('todaydate').innerHTML = 'Updated as of ' + lmonth + '/' + date + '/' + year;
}
