function selectAllText(id) {
	document.getElementById(id).focus();
	document.getElementById(id).select();
}

function cwsubmitzipcode(module,siteid,basicinfo){
	var address = jQuery('#cwebcontent_address' + module).val();
	var city = jQuery('#cwebcontent_city' + module).val();
	var state = jQuery('#cwebcontent_state' + module).val();
	var zipcode = jQuery('#cwebcontent_zipcode' + module).val()+'';
	var zipregex = /^\d{5}([\-]\d{4})?$/;
	var zipcodelength = 0;
	var zip5 = '';
	var plus4 = '';
	
	//Obtain Zipcode Information
	zipcode = zipcode.replace(/\s+/g,'');
	zipcodelength = zipcode.length;
	
	jQuery('#cwLegSearchFormSubmit').hide();
	jQuery('#cwLegSearchFormLoading').show();
	jQuery('#cwebcontent_zipcodevalidation' + module).html('');
	jQuery('#legsearchresultcontent').html('');
	
	if (jQuery('#cwebcontent_fulladdress' + module + ':visible').length) {
		if (!address.length){
			jQuery('#cwebcontent_zipcodevalidation' + module).html('Enter an Address');
			jQuery('#cwLegSearchFormLoading').hide();
			jQuery('#cwLegSearchFormSubmit').show();	
		}
		else if (!zipcodelength > 0){
			jQuery('#cwebcontent_zipcodevalidation' + module).html('Enter a Zip Code');
			jQuery('#cwLegSearchFormLoading').hide();
			jQuery('#cwLegSearchFormSubmit').show();	
		}
		else {
			if (!zipregex.test(zipcode)) {
				//Check the Zip Code for validity
				jQuery('#cwebcontent_zipcodevalidation' + module).html('Enter a Valid Zip Code');
				jQuery('#cwLegSearchFormLoading').hide();
				jQuery('#cwLegSearchFormSubmit').show();
			}
			else {
				if(basicinfo){
					jQuery('#cwLegSearchFormLoading').show();
					jQuery('#cwLegSearchFormSubmit').hide();
					jQuery.getJSON(
						cw_rootPath + '/index.cfm?siteid=' + siteid + '/action/Legislators.ZipSearchResult/addressform/true/js/true/basicinfo/true?'+jQuery('#cw_zipcodesearch form').serialize(),
						function(response){
							jQuery('#legsearchresultcontent').html(response.CONTENT);
							jQuery('#cwebcontent_zipcodezipcodesearch').val(jQuery('#cwZiplookupupdate').html());
							cwhidfulladdressform(module);

							jQuery('#cwLegSearchFormLoading').hide();
							jQuery('#cwLegSearchFormSubmit').show();
						} 
					);
				}
				else{
					jQuery('.cwebcontent_legsearch' + module).attr({'action': cw_rootPath + '/index.cfm/siteid/' + siteid + '/action/Legislators.ZipSearchResult/addressform/true'});
					jQuery('.cwebcontent_legsearch' + module).removeAttr('onSubmit');
					jQuery('.cwebcontent_legsearch' + module).submit();
				}
			}	
		}
	}
	else {
		//Check Zip Code Length
		if (!zipcodelength > 0) {
			jQuery('#cwebcontent_zipcodevalidation' + module).html('Enter a Zip Code');
			jQuery('#cwLegSearchFormLoading').hide();
			jQuery('#cwLegSearchFormSubmit').show();
		}
		else {
			if (!zipregex.test(zipcode)) {
				//Check the Zip Code for validity
				jQuery('#cwebcontent_zipcodevalidation' + module).html('Enter a Valid Zip Code');
				jQuery('#cwLegSearchFormLoading').hide();
				jQuery('#cwLegSearchFormSubmit').show();
			}
			else {
				//The Code is Valid, Submit ZipCode Value
				jQuery.post(cw_rootPath + "/index.cfm?siteid=" + siteid + "&action=Legislators.SubmitZipCode&js=true&requesttype=update", {
					'zipcode': zipcode,
					'module': module
				}, function(response){
					if (response.CONTENT.MATCHED) {
						if (response.CONTENT.MULTIPLEDISTRICTS) {
							cwshowfulladdressform(response.CONTENT.MODULE);
							jQuery('#cwLegSearchFormLoading').hide();
							jQuery('#cwLegSearchFormSubmit').show();
							
						}
						else {

							if(basicinfo){
								jQuery.getJSON(
									cw_rootPath + '/index.cfm?siteid=' + siteid + '&action=Legislators.ZipSearchResult&requesttype=update&js=true&basicinfo=true&zipcode='+zipcode,
									function(response){
										jQuery('#legsearchresultcontent').html(response.CONTENT);
										jQuery('#cwLegSearchFormLoading').hide();
										jQuery('#cwLegSearchFormSubmit').show();
									}								
								);
							}
							else
								window.location = cw_rootPath + '/index.cfm/siteid/' + siteid + '/action/Legislators.ZipSearchResult/zipcode/' + jQuery.trim(response.CONTENT.ZIPCODE);
						}
					}
					else {
						var instructions = 'Your zip code could not be found.  Please enter your address to find the correct zip code.';
						jQuery('#cwebcontent_multimatchalert' + response.CONTENT.MODULE).html(instructions);
						cwshowfulladdressform(response.CONTENT.MODULE);
						jQuery('#cwLegSearchFormLoading').hide();
						jQuery('#cwLegSearchFormSubmit').show();
					}}, 'json');
			}
		}	
	}
	enableSubmit();
}

function cwshowfulladdressform(module){
	jQuery('#cwebcontent_address' + module).val('');
	jQuery('#cwebcontent_city' + module).val('');
	
	jQuery('#cwebcontent_fulladdress' + module).show();
}
function cwhidfulladdressform(module){
	jQuery('#cwebcontent_address' + module).val('');
	jQuery('#cwebcontent_city' + module).val('');
	
	jQuery('#cwebcontent_fulladdress' + module).hide();
}

