var countiesWithHMOPPO = ['Alamance','Alexander','Alleghany','Ashe','Avery','Bertie','Brunswick','Cabarrus','Caldwell','Carteret','Caswell','Catawba','Chatham','Cumberland',
						'Davidson','Davie','Durham','Edgecombe','Forsyth','Gates','Gaston','Greene','Guilford','Halifax','Hertford','Hoke','Iredell','Johnston','Lee','Martin',
						'Mecklenburg','Nash','New Hanover','Northampton','Onslow','Orange','Perquimans','Person','Pitt','Randolph','Richmond','Rockingham','Rowan','Stanly','Stokes',
						'Surry','Wake','Watauga','Wayne','Wilkes','Yadkin'];

var countiesWith2010HMOPPO = ['Alamance','Alexander','Alleghany','Ashe','Avery','Beaufort','Bertie','Bladen','Brunswick','Cabarrus','Caldwell','Carteret','Caswell','Catawba','Chatham',
						'Chowan','Columbus','Cumberland','Davidson','Davie','Duplin','Durham','Edgecombe','Forsyth','Franklin','Gaston','Gates','Granville','Greene','Guilford','Halifax',
						'Harnett','Haywood','Henderson','Hertford','Hoke','Hyde','Iredell','Johnston','Lee','Lincoln','Martin','Mecklenburg','Nash','New Hanover','Northampton','Onslow','Orange',
						'Pender','Perquimans','Person','Pitt','Polk','Randolph','Richmond','Robeson','Rockingham','Rowan','Sampson','Stanly','Stokes','Surry','Tyrrell','Wake','Warren',
						'Washington','Watauga','Wayne','Wilkes','Yadkin'];

//Use this function when specifying year to enroll
/*function getAvailablePlan(countyName, option) 
{
	if(option == 0)
	{
		var filename = "medicare-supplement/nohmoppo.htm";
	}
	else if(option == 1)
	{
		var filename = "medicare-supplement2/nohmoppo.htm";
	}
	
	
	if(option == 0)
	{
		$.each(countiesWithHMOPPO,(function(i, n)
			{
				if(n == countyName && option == 0)
				{
					filename = "medicare-supplement/hmoppo.htm";
				}
				else if(n == countyName && option == 1)
				{
					filename = "medicare-supplement2/hmoppo.htm";
				}
			}));
	}
	else if(option == 1)
	{
		$.each(countiesWith2010HMOPPO,(function(i, n)
			{
				if(n == countyName && option == 0)
				{
					filename = "medicare-supplement/hmoppo.htm";
				}
				else if(n == countyName && option == 1)
				{
					filename = "medicare-supplement2/hmoppo.htm";
				}
			}));
	}
	
	location.href= 'http://' + location.host + "/assets/shopper/public/" + filename;
}*/

function getAvailablePlan(countyName) 
{
	var filename = "medicare-supplement2/nohmoppo.htm";
	
	$.each(countiesWith2010HMOPPO,(function(i, n)
			{
				if(n == countyName)
				{
					filename = "medicare-supplement2/hmoppo.htm";
				}
			}));
	
	location.href= 'http://' + location.host + "/assets/shopper/public/" + filename;
}

function populateCountiesMS(zipField, selectControl) {
		fillCountyWithName(zipField.value, selectControl);
	
		if(selectControl.options.length > 1) {
			selectControl.focus();
			
		}
	}


function populateCounties(zipField,selectControl)
	{
		fillCountyWithName(zipField.value,selectControl);$('#selectwrapper').css('display','');$('#countyhtml').html('');
		if(selectControl.options.length>1)
			{
				$('.countyform').removeClass('hide');/*$('#apply_error_box').show();$('#label-zip').removeClass('labelerror');*/
				$('.pixelArrow').removeClass('hide');
			}
		/*if($('#apply_error_box').html().indexOf("Select the county where you reside.")==-1)
			{
				$('#apply_error_box').append("<p>Select the county where you reside.</p>")}$(selectControl).addClass("required");selectControl.focus()
			}
		*/
			if(selectControl.options.length==1&&selectControl.value!='')
				{
					$('.countyform').removeClass('hide');/*$('#label-zip').removeClass('labelerror');*/$('#selectwrapper').css('display','none');$('#countyhtml').html(selectControl.value);$(selectControl).removeClass("required");
					$('.pixelArrow').removeClass('hide');
				}
	}

function selectByValue(selControl,selValue)
{for(var i=0;i<selControl.options.length;i++){if(selControl.options[i].value==selValue){selControl.options[i].selected=true}}}

function validateRadio(form) {
		option1 = -1;
		for (i=0; i < form.enrollYear.length; i++) {
				if (form.enrollYear[i].checked) {
				option1 = i;
			}
		}
		if (option1 == -1) {
				alert("Please select the year you want your coverage to start.");
				return false;
			}
		else {
				getAvailablePlan(document.getElementById('countyOfResidence').value, option1);
				return false;
			}
	} 


function checkCountySelection(selectControl)
	{
		if(selectControl.options.length > 1 && selectControl.value != '') { //More than one county
			//validateRadio(document.GetMedSuppPlan);
			getAvailablePlan(document.getElementById('countyOfResidence').value);
			return false;	
		}
		
		else if(selectControl.options.length > 1) { //More than one county
			selectControl.focus();
			alert("Select a county.");
			return false;	
		}
		
		else if(selectControl.options.length == 0) { //No county
			alert("Enter ZIP code.");
			return false;	
		}
		
		else if(selectControl.options.length == 1 && (selectControl.value == '' || selectControl.value == '-Enter ZIP code-')) { //No county
			alert("Enter ZIP code.");
			return false;	
		}

		else if(selectControl.options.length == 1) { //One County 
			//validateRadio(document.GetMedSuppPlan);
			getAvailablePlan(document.getElementById('countyOfResidence').value);
			return false;
		}
		
	}