// ***** Set Cookies *****
function Set_Cookie(name, value, expires, path, domain, secure) {

	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	
	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires ) {
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
	
}

// ***** Get Cookies *****
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = "";
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return "";
	}
}



// ***** Set Dropdown Cookies *****
function JumpTo_Service() {
	
	var ServiceValue = document.getElementById("dropdown1")[document.getElementById("dropdown1").selectedIndex].value;
	Set_Cookie("currState_Service", ServiceValue, "365", "/", "", "");
	
	if (Get_Cookie("currState_Service") != "" && Get_Cookie("currState_Zip") != "") {
		
		var JumpTo_ZipURL;
		switch (Get_Cookie("currState_Zip")) {
			
			case "67003": { JumpTo_ZipURL = "CONTACT"; break }
			case "67009": { JumpTo_ZipURL = "CONTACT"; break }
			case "67021": { JumpTo_ZipURL = "ILEC"; break }
			case "67029": { JumpTo_ZipURL = "CONTACT"; break }
			case "67054": { JumpTo_ZipURL = "CONTACT"; break }
			case "67058": { JumpTo_ZipURL = "CONTACT"; break }
			case "67061": { JumpTo_ZipURL = "ILEC"; break }
			case "67066": { JumpTo_ZipURL = "ILEC"; break }
			case "67068": { JumpTo_ZipURL = "CONTACT"; break }
			case "67070": { JumpTo_ZipURL = "ILEC"; break }
			case "67071": { JumpTo_ZipURL = "ILEC"; break }
			case "67104": { JumpTo_ZipURL = "CLEC"; break }
			case "67124": { JumpTo_ZipURL = "CLEC"; break }
			case "67138": { JumpTo_ZipURL = "ILEC"; break }
			case "67143": { JumpTo_ZipURL = "ILEC"; break }
			case "67578": { JumpTo_ZipURL = "CONTACT"; break }
			case "67583": { JumpTo_ZipURL = "ILEC"; break }
			case "73719": { JumpTo_ZipURL = "ILEC"; break }
			case "73722": { JumpTo_ZipURL = "ILEC"; break }
			default: { break }
			
		}
		
		if (JumpTo_ZipURL == "CONTACT") {
			document.location = "contact_service.html";
		} else {
			document.location = "services_" + Get_Cookie("currState_Service") + "_" + JumpTo_ZipURL + ".htm";
		}
		
	}
	
	if (Get_Cookie("currState_Zip") == "") {
		
		document.getElementById("dropdown2").focus();
		
	}
	
}
function JumpTo_Zip() {
	
	var ZipValue = document.getElementById("dropdown2")[document.getElementById("dropdown2").selectedIndex].value;
	Set_Cookie("currState_Zip", ZipValue, "365", "/", "", "");
	
	if (Get_Cookie("currState_Service") != "" && Get_Cookie("currState_Zip") != "") {
		
		var JumpTo_ZipURL;
		switch (Get_Cookie("currState_Zip")) {
			
			case "67003": { JumpTo_ZipURL = "CONTACT"; break }
			case "67009": { JumpTo_ZipURL = "CONTACT"; break }
			case "67021": { JumpTo_ZipURL = "ILEC"; break }
			case "67029": { JumpTo_ZipURL = "CONTACT"; break }
			case "67054": { JumpTo_ZipURL = "CONTACT"; break }
			case "67058": { JumpTo_ZipURL = "CONTACT"; break }
			case "67061": { JumpTo_ZipURL = "ILEC"; break }
			case "67066": { JumpTo_ZipURL = "ILEC"; break }
			case "67068": { JumpTo_ZipURL = "CONTACT"; break }
			case "67070": { JumpTo_ZipURL = "ILEC"; break }
			case "67071": { JumpTo_ZipURL = "ILEC"; break }
			case "67104": { JumpTo_ZipURL = "CLEC"; break }
			case "67124": { JumpTo_ZipURL = "CLEC"; break }
			case "67138": { JumpTo_ZipURL = "ILEC"; break }
			case "67143": { JumpTo_ZipURL = "ILEC"; break }
			case "67578": { JumpTo_ZipURL = "CONTACT"; break }
			case "67583": { JumpTo_ZipURL = "ILEC"; break }
			case "73719": { JumpTo_ZipURL = "ILEC"; break }
			case "73722": { JumpTo_ZipURL = "ILEC"; break }
			default: { break }
			
		}
		
		if (JumpTo_ZipURL == "CONTACT") {
			document.location = "contact_service.html";
		} else {
			document.location = "services_" + Get_Cookie("currState_Service") + "_" + JumpTo_ZipURL + ".htm";
		}
		
	}
	
	if (Get_Cookie("currState_Service") == "") {
		
		document.getElementById("dropdown1").focus();
		
	}
	
}

// ***** Default States *****
function setDefaults() {
	
	var currState_Zip = Get_Cookie("currState_Zip");
	
	switch (currState_Zip) {
		
		case "67003": { document.getElementById("dropdown2").selectedIndex = 1; break }
		case "67009": { document.getElementById("dropdown2").selectedIndex = 2; break }
		case "67021": { document.getElementById("dropdown2").selectedIndex = 3; break }
		case "67029": { document.getElementById("dropdown2").selectedIndex = 4; break }
		case "67054": { document.getElementById("dropdown2").selectedIndex = 5; break }
		case "67058": { document.getElementById("dropdown2").selectedIndex = 6; break }
		case "67061": { document.getElementById("dropdown2").selectedIndex = 7; break }
		case "67066": { document.getElementById("dropdown2").selectedIndex = 8; break }
		case "67068": { document.getElementById("dropdown2").selectedIndex = 9; break }
		case "67070": { document.getElementById("dropdown2").selectedIndex = 10; break }
		case "67071": { document.getElementById("dropdown2").selectedIndex = 11; break }
		case "67104": { document.getElementById("dropdown2").selectedIndex = 12; break }
		case "67124": { document.getElementById("dropdown2").selectedIndex = 13; break }
		case "67138": { document.getElementById("dropdown2").selectedIndex = 14; break }
		case "67143": { document.getElementById("dropdown2").selectedIndex = 15; break }
		case "67578": { document.getElementById("dropdown2").selectedIndex = 16; break }
		case "67583": { document.getElementById("dropdown2").selectedIndex = 17; break }
		case "73719": { document.getElementById("dropdown2").selectedIndex = 18; break }
		case "73722": { document.getElementById("dropdown2").selectedIndex = 19; break }
		default: { break }
		
	}
	
}
