var stateName = new Array();
var stateChapter = new Array();
var i=0;

stateName[i] = "Alabama";
stateChapter[i++] = new Array("Alabama/Northwest Florida", "alabama");
stateName[i] = "Alaska";
stateChapter[i++] = new Array("Northwest", "northwest");
stateName[i] = "Arizona";
stateChapter[i++] = new Array("Southwest", "southwest");
stateName[i] = "Arkansas";
stateChapter[i++] = new Array("Mid-America", "midamerica", "Louisiana/Mississippi", "louisiana", "Oklahoma", "oklahoma", "Tennessee", "tennessee");
stateName[i] = "California";
stateChapter[i++] = new Array("Northern California", "northerncalifornia", "Greater Los Angeles/Orange County", "losangeles", "Greater San Diego & Desert Area", "sandiego");

stateName[i] = "Colorado";
stateChapter[i++] = new Array("Rocky Mountain", "rockymountain");
stateName[i] = "Connecticut";
stateChapter[i++] = new Array("Connecticut", "centralct", "Fairfield/Westchester", "westfield");
stateName[i] = "Delaware";
stateChapter[i++] = new Array("Maryland/Southern Delaware", "md-southde", "Philadelphia/Delaware Valley", "philadelphia");
stateName[i] = "District of Columbia";
stateChapter[i++] = new Array("Greater Washington D.C./Virginia", "washingtondc");
stateName[i] = "Florida";
stateChapter[i++] = new Array("Alabama/Northwest Florida", "alabama", "Northern Florida", "northernflorida", "Florida", "florida");
stateName[i] = "Georgia";
stateChapter[i++] = new Array("Georgia", "georgia");
stateName[i] = "Hawaii";
stateChapter[i++] = new Array("Greater Los Angeles/Orange County", "losangeles");
stateName[i] = "Idaho";
stateChapter[i++] = new Array("Northwest", "northwest");

stateName[i] = "Illinois";
stateChapter[i++] = new Array("Illinois Carol Fisher", "illinois");
stateName[i] = "Indiana";
stateChapter[i++] = new Array("Indiana", "indiana");
stateName[i] = "Iowa";
stateChapter[i++] = new Array("Iowa", "iowa");
stateName[i] = "Kansas";
stateChapter[i++] = new Array("Mid-America", "midamerica");
stateName[i] = "Kentucky";
stateChapter[i++] = new Array("Kentucky", "kentucky");
stateName[i] = "Louisiana";
stateChapter[i++] = new Array("Louisiana/Mississippi", "louisiana");
stateName[i] = "Maine";
stateChapter[i++] = new Array("New England", "ne");
stateName[i] = "Maryland";
stateChapter[i++] = new Array("Maryland/Southern Delaware", "md-southde");

stateName[i] = "Massachusetts";
stateChapter[i++] = new Array("New England", "ne");
stateName[i] = "Michigan";
stateChapter[i++] = new Array("Michigan", "michigan");
stateName[i] = "Minnesota";
stateChapter[i++] = new Array("Minnesota/Dakotas", "minnesota");
stateName[i] = "Mississippi";
stateChapter[i++] = new Array("Louisiana/Mississippi", "louisiana");
stateName[i] = "Missouri";
stateChapter[i++] = new Array("Mid-America", "midamerica");
stateName[i] = "Montana";
stateChapter[i++] = new Array("Northwest", "northwest");
stateName[i] = "Nebraska";
stateChapter[i++] = new Array("Nebraska", "nebraska");
stateName[i] = "Nevada";
stateChapter[i++] = new Array("Southwest", "southwest");

stateName[i] = "New Hampshire";
stateChapter[i++] = new Array("New England", "ne");
stateName[i] = "New Jersey";
stateChapter[i++] = new Array("New Jersey", "newjersey");
stateName[i] = "New Mexico";
stateChapter[i++] = new Array("Southwest", "southwest");
stateName[i] = "New York";
stateChapter[i++] = new Array("Central New York Affiliate", "centralny", "Fairfield/Westchester", "westfield", "Greater New York", "newyork", "Long Island", "longisland", "Rochester", "rochester", "Western New York", "westernny", "Upstate/Northeastern New York", "upstateny");
stateName[i] = "North Carolina";
stateChapter[i++] = new Array("Carolinas", "carolinas");
stateName[i] = "North Dakota";
stateChapter[i++] = new Array("Minnesota/Dakotas", "minnesota");

stateName[i] = "Ohio";
stateChapter[i++] = new Array("Central Ohio", "centralohio", "Southwest Ohio", "swohio", "Northeast Ohio", "neohio");
stateName[i] = "Oklahoma";
stateChapter[i++] = new Array("Oklahoma", "oklahoma");
stateName[i] = "Oregon";
stateChapter[i++] = new Array("Northwest", "northwest");
stateName[i] = "Pennsylvania";
stateChapter[i++] = new Array("Philadelphia/Delaware Valley", "philadelphia", "Western Pennsylvania/West Virginia", "wpawv");
stateName[i] = "Puerto Rico";
stateChapter[i++] = new Array("Puerto Rico Affiliate", "puertorico");

stateName[i] = "Rhode Island";
stateChapter[i++] = new Array("New England", "ne");
stateName[i] = "South Carolina";
stateChapter[i++] = new Array("Carolinas", "carolinas");
stateName[i] = "South Dakota";
stateChapter[i++] = new Array("Minnesota/Dakotas", "minnesota");
stateName[i] = "Tennessee";
stateChapter[i++] = new Array("Tennessee", "tennessee");
stateName[i] = "Texas";
stateChapter[i++] = new Array("Houston Gulf Coast/South Texas", "houston", "North Texas", "ntexas");
stateName[i] = "Utah";
stateChapter[i++] = new Array("Rocky Mountain", "rockymountain");
stateName[i] = "Vermont";
stateChapter[i++] = new Array("New England", "ne");

stateName[i] = "Virginia";
stateChapter[i++] = new Array("Greater Washington D.C./Virginia", "washingtondc");
stateName[i] = "Washington";
stateChapter[i++] = new Array("Northwest", "northwest");
stateName[i] = "West Virginia";
stateChapter[i++] = new Array("Western Pennsylvania/West Virginia", "wpawv");
stateName[i] = "Wisconsin";
stateChapter[i++] = new Array("Wisconsin", "wisconsin");
stateName[i] = "Wyoming";
stateChapter[i++] = new Array("Rocky Mountain", "rockymountain");

function stateSelect(s) { 
        var f = s.form;
	var c = f.search_chapter;	
       
        
	if (s.selectedIndex ==  0) {
	     //check if the state is available in cookie
             var stateIndex = readCookie('state');        
	     if (stateIndex != null) {
	         s.selectedIndex = stateIndex;
	     } else {
	        return;
	     }
	}	
	c.disabled = true;
	var cArr = stateChapter[s.options[s.selectedIndex].value];
	c.options.length=0;
	
	if (cArr && cArr.length) {
		c.options[0] = new Option();
		c.options[0].text = "Pick Your Chapter";
		c.options[0].value = "";
		var i=1;
		var j=0;
		for (i=1;i<=cArr.length/2;i++) {
			c.options[i] = new Option();
			c.options[i].text = cArr[j++];
			c.options[i].value = cArr[j++];
		}
		c.disabled = false;
		if (c.length ==2) {
			c.selectedIndex = 1;
		}
	} else {
		c.options[0] = new Option();
		c.options[0].text = "No Chapter in This Area";
		c.options[0].value = "";		
	}
	//create a cookie to store the state selected
	createCookie('state', s.selectedIndex);	
}

function chapterSelect(c) {
    alert("chapter:"+c.selectedIndex);
    if (c.selectedIndex == 0) {
        return;    
    }
    createCookie('chapter', c.selectedIndex);
}

function goToChapter(f) {
	var c = f.search_chapter;
	var u = c.options[c.selectedIndex].value;
	if (u == "") {
		alert("You must select a chapter to go to.");
	} else {
		location.href="/chapters/" + u;
	}
}

function createCookie(name,value,days) {
        if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	} else var expires = "";
        
        document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
        var nameEQ = name+"=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}



var out = "";
out += '<table border=0 cellpadding=0 cellspacing=0 width=485 bgcolor="#ECECEC">';
out += '<form name="search_chapters_form" method="post" action="" onSubmit="goToChapter(this);return false;"';
out += '	<tr>';
out += '		<td colspan=3 bgcolor="#F9A51E" background="/images/custom_table_top_bg.gif" align="left"><IMG align="left" src="/images/custom_table_tl.gif " border=0 width=25 height=22><IMG src="/images/spacer.gif " border=0 width=1 height=7><BR><img src="http://ccfa.i33.com/images/od/CHAPTER%20SEARCH%20/F9A51E/9/b/000000/MetaBoldRoman/gif" border="0"></td>';
out += '		<td colspan=2 bgcolor="#F9A51E" background="/images/custom_table_top_bg.gif" align="right"><IMG src="/images/custom_table_tr.gif " border=0 width=11 height=22></td>';
out += '	</tr>';
out += '	<tr>';
out += '		<td bgcolor="#DDDDDD"><IMG src="/images/spacer.gif " border=0 width=1 height=1></td>';
out += '		<td colspan=3><IMG src="/images/spacer.gif" border=0 width=1 height=10></td>';
out += '		<td bgcolor="#DDDDDD"><IMG src="/images/spacer.gif " border=0 width=1 height=1></td>';
out += '	</tr>';
out += '	<tr>';
out += '		<td bgcolor="#DDDDDD"><IMG src="/images/spacer.gif " border=0 width=1 height=1></td>';
out += '		<td><IMG src="/images/spacer.gif " border=0 width=1 height=1></td>';
out += '		<td valign="top"><table border=0 cellpadding=0 cellspacing=0>';
out += '			<tr>';
out += '				<td colspan=6><IMG src="/images/spacer.gif " border=0 width=1 height=5></td>';
out += '			</tr>';
out += '			<tr>';
out += '				<td><IMG src="/images/spacer.gif " border=0 width=25 height=1></td>';
out += '				<td><select name="search_state" id="search_state" style="width:140px;" onChange="stateSelect(this);">';
out += '					<option value="">Pick Your State</option>';
for (var i=0; i<stateName.length; i++) {
	out += '<option value="' + i + '">' + stateName[i] + '</option>';
}
out += '				</select></td>';
out += '				<td><IMG src="/images/spacer.gif " border=0 width=25 height=1></td>';
out += '				<td><select name="search_chapter" id="search_chapter" style="width:180px;" disabled>';
out += '					<option value="">Pick Your Chapter</option>';
out += '				</select></td>';
out += '				<td><IMG src="/images/spacer.gif " border=0 width=25 height=1></td>';
out += '				<td><input type="image" src="/images/button_go.gif " border=0 width=30 height=17></td>';
out += '			</tr>';
out += '			<tr>';
out += '				<td colspan=6><IMG src="/images/spacer.gif " border=0 width=1 height=5></td>';
out += '			</tr>';
out += '		</table></td>';
out += '		<td><IMG src="/images/spacer.gif " border=0 width=10 height=1></td>';
out += '		<td bgcolor="#DDDDDD"><IMG src="/images/spacer.gif " border=0 width=1 height=1></td>';
out += '	</tr>';
out += '	<tr>';
out += '		<td rowspan=2 colspan=2><IMG src="/images/custom_table_bl_grey.gif " border=0 width=13 height=12></td>';
out += '		<td><IMG src="/images/spacer.gif " border=0 width=1 height=11></td>';
out += '		<td rowspan=2 colspan=2><IMG src="/images/custom_table_br_grey.gif " border=0 width=11 height=12></td>';
out += '	</tr>';
out += '	<tr>';
out += '		<td bgcolor="#DDDDDD"><IMG src="/images/spacer.gif " border=0 width=1 height=1></td>';
out += '	</tr>';
out += '	<tr>';
out += '		<td bgcolor="#FFFFFF"><IMG src="/images/spacer.gif " border=0 width=1 height=1></td>';
out += '		<td bgcolor="#FFFFFF"><IMG src="/images/spacer.gif " border=0 width=12 height=1></td>';
out += '		<td bgcolor="#FFFFFF"><IMG src="/images/spacer.gif " border=0 width=461 height=1></td>';
out += '		<td bgcolor="#FFFFFF"><IMG src="/images/spacer.gif " border=0 width=10 height=1></td>';
out += '		<td bgcolor="#FFFFFF"><IMG src="/images/spacer.gif " border=0 width=1 height=1></td>';
out += '	</tr>';
out += '</form>';
out += '</table>';

document.write(out);
stateSelect(document.search_chapters_form.search_state);
