var selectedProduct='none';
var stagentCode;

function submitQuote() {
	dcsMultiTrack('DCS.dsuri',document.getElementById(selectedProduct).action,'WT.ti','Microsite','WT.stagt',stagentCode, 'WT.cg_n','AgentMicrositeInsProductsPortlet','WT.cg_s','Forms','WT.ac',selectedProduct);
	document.getElementById(selectedProduct).submit();
}

function checkSurveyInd(productLine) {
	if (isValidZip(productLine))
	{
		selectedProduct=productLine;
		if(!surveyInd) {
			showDialog('AMD66');
			return false;
		} else {
			submitQuote();
			return false;
		}
	}
	else
	{
		return false;
	}
}

function resetZipErrMsg() {
	document.getElementById("rateQuoteZipErrorMsg").style.display = "none";
}

function isValidZip(formName)
{
	var zipVal = document.getElementById(formName).postalCode.value;
	stagentCode = document.getElementById(formName).st.value + document.getElementById(formName).ofc.value;
	
	var RegExpUS = /(^\d{5}$)/;
	var RegExpCA = /^([abceghjklmnprstvxyABCEGHJKLMNPRSTVXY][0-9][abceghjklmnprstvwxyzABCEGHJKLMNPRSTVWXYZ])\s*([0-9][abceghjklmnprstvwxyzABCEGHJKLMNPRSTVWXYZ][0-9])$/;

	var matchUS, matchCA;
	zipVal = zipVal.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
	
	document.getElementById(formName).postalCode.value = zipVal;
	
	matchUS = RegExpUS.test(zipVal);
	matchCA = RegExpCA.test(zipVal);
	
	if(matchUS || matchCA)
	{
		if (matchCA)
		{
			zipVal = zipVal.toUpperCase();
			zipVal = zipVal.replace(/\s+/g,'');
			document.getElementById(formName).postalCode.value = zipVal;
		}	
		return true;
	}
	else
	{
		document.getElementById("rateQuoteZipErrorMsg").style.display = "block";
		document.getElementById("rateQuoteZipErrorMsg").innerHTML = "Please enter a valid Zip/Postal Code";
		document.getElementById("rateQuoteZipErrorMsg").style.position = "absolute";
		
		var coords = dojo.coords(document.getElementById(formName).postalCode, true);
		
		document.getElementById("rateQuoteZipErrorMsg").style.top = coords['y'] + "px";
		document.getElementById("rateQuoteZipErrorMsg").style.left = coords['x'] + "px";
		return false;
	}
}

