function getAddresses_old(state)
{
	jQuery('#wait').css('display', 'block'); 
	jQuery.post("wheretobuy.php", {state: state, ajax: true}, function(data){
		jQuery("#content").html(data);
		jQuery('#wait').css('display', 'none'); 
	});
}


function getAddresses(state)
{
	jQuery('#wait').css('display', 'block'); 
	jQuery.post("wheretobuy.php", {state: state, ajax: true}, function(data){
		jQuery("#content").html(data);
		jQuery('#wait').css('display', 'none'); 
	});
}

function getAddresses_round(){
	if(Where.passport == 'is'){
	    if(jQuery("#miles_input").val() !== '' ){
		    jQuery('#wait').css('display', 'block');
		    jQuery.post("wheretobuy.php", {zip: jQuery("#zip_input").val() , radius: "75" , ajax: true}, function(data){
			    jQuery("#content").html(data);
			    jQuery('#wait').css('display', 'none'); 
		});
	}
	}
}

/*function getAddresses_round_new(){
	if(Where.passport == 'is'){
	    if(jQuery("#miles_input").val() !== '' ){
		    jQuery('#wait').css('display', 'block');
		    jQuery.post("wheretobuy_new.php", {zip: jQuery("#zip_input").val() , radius: "75" , ajax: true}, function(data){
			    jQuery("#content").html(data);
			    jQuery('#wait').css('display', 'none'); 
		});
	}
	}
}*/

function changeAction(action)
{
	jQuery('#states_div').css('display', 'block') 
	jQuery('#action_value').val(action);
	
	jQuery('#wait').css('display', 'block') 
	jQuery.post("manage.php", {ajax: 'getStates', action: jQuery('#action_value').val()}, function(data){
		jQuery("#states_div").html(data);
		
		jQuery("#cities_div").html("");
	  jQuery("#names_div").html("");
	  jQuery("#representatives_div").html("");
	  
		jQuery('#wait').css('display', 'none') 
	})
}

function getCities(state_id, selected)
{
	jQuery('#wait').css('display', 'block') 
	jQuery.post("manage.php", {state_id: state_id, ajax: 'getCities', action: jQuery('#action_value').val()}, function(data){
		jQuery("#cities_div").html(data);
		jQuery("#names_div").html("");
	  jQuery("#representatives_div").html("");
		jQuery('#wait').css('display', 'none') 
	})
}

function getNames(city_id, selected)
{
	if (jQuery('#action_value').val() == 'create')
	{
		getRepresentative(); 
	}
	else
	{
		var user_type = jQuery('#user_type').val();
		jQuery('#wait').css('display', 'block') ;
		jQuery.post("manage.php", {city_id: city_id, user_type: user_type, ajax: 'getNames', action: jQuery('#action_value').val()}, function(data){
			jQuery("#names_div").html(data);
			jQuery("#representatives_div").html("");
			jQuery('#wait').css('display', 'none') 
		})
	}
}

function getRepresentative(id)
{
	jQuery('#wait').css('display', 'block') 
	jQuery.post("manage.php", {id: id, ajax: 'getRepresentative', action: jQuery('#action_value').val()}, function(data){
		jQuery("#representatives_div").html(data);
		
		if (document.getElementById('user_type_retailer').checked == true)
	  	jQuery('#fabricator_div').css('display', 'none') 
	  	
		jQuery('#wait').css('display', 'none') 
		
	})
	
	
}

function changeValue(obj, value_)
{
	jQuery('#'+obj).val(value_);
}

function save()
{
	var action             = jQuery('#action').val();
	var id                 = jQuery('#id').val();
	
	jQuery('#wait').css('display', 'block') 
	
	if (action != 'remove')
	{
		var inputs_ = jQuery('#content_ input:text, #content_ input:password, #content_ input:radio, #content_ textarea, #content_ select');
		var values = {};
    inputs_.each(function(i, el) {
        values[el.name] = jQuery(el).val();
    });
    
    var checkboxes = jQuery('#content_ input:checkbox');
    checkboxes.each(function(i, el) {
    	  if (jQuery(el).attr('checked') == true)
    	    values[el.name] = 1;
    });
    
    var hiddens_ = jQuery('#content_ input:hidden')
    {
	    hiddens_.each(function(i, el) {
	        values[el.name] = jQuery(el).val();
	    });
    }
    
    
    
    values['id']     = id;
    values['action'] = action;
    values['ajax']   = 'save';
		
		/*var name               = jQuery('#name').val();
		var address            = jQuery('#address').val();
		var zip                = jQuery('#zip').val();
		var phone1             = jQuery('#phone1').val();
		var phone2             = jQuery('#phone2').val();
		var phone3             = jQuery('#phone3').val();
		var website            = jQuery('#website').val();
		var firstname          = jQuery('#firstname').val();
		var lastname           = jQuery('#lastname').val();
		var email              = jQuery('#email').val();
		var user_type          = jQuery('#user_type').val();
		var listed_on_the_site = jQuery('#listed_on_the_site').val();
		var state_id           = jQuery('#state_id').val();
		var city_id            = jQuery('#city_id').val();
		var new_city_id        = jQuery('#new_city_id').val();
		
		var showroom                  = document.getElementById('showroom').checked == true ? 1 : 0;
		var showroom_displayed        = document.getElementById('showroom_displayed').checked == true ? 1 : 0;
		var showroom_colors           = jQuery('#showroom_colors').val();
		var showroom_corian_displayed = document.getElementById('showroom_corian_displayed').checked == true ? 1 : 0;
		var showroom_corian_colors    = jQuery('#showroom_corian_colors').val();
		var showroom_himacs_displayed = document.getElementById('showroom_himacs_displayed').checked == true ? 1 : 0;
		var showroom_himacs_colors    = jQuery('#showroom_himacs_colors').val();
		
		var wallboard                 = document.getElementById('wallboard').checked == true ? 1 : 0;
		var notificate                = document.getElementById('notificate').checked == true ? 1 : 0;*/
		
		


    /*$j.post("https://countertopsbysupplymycounter.com/costco_admin/payment/pay_page", values, function(data){
        alert(data);
    });*/
	/*{
			  id: id, 
			  ajax: 'save', 
			  action: action, 
			  name: name,
			  address: address, 
			  zip: zip,
			  phone1: phone1, 
			  phone2: phone2, 
			  phone3: phone3, 
			  website: website,
			  firstname: firstname,
			  lastname: lastname,
			  email: email,
			  user_type: user_type,
			  listed_on_the_site: listed_on_the_site,
			  state_id: state_id,
			  city_id: city_id,
			  new_city_id: new_city_id,
			  
			  showroom: showroom,
	 	    showroom_displayed: showroom_displayed,
		    showroom_colors: showroom_colors,
		    showroom_corian_displayed: showroom_corian_displayed,
		    showroom_corian_colors: showroom_corian_colors,
		    showroom_himacs_displayed: showroom_himacs_displayed,
		    showroom_himacs_colors: showroom_himacs_colors,
		    wallboard: wallboard,
		    notificate: notificate 
			  
			  
			}*/
		jQuery.post("manage.php", values, function(data){
			jQuery("#representatives_div").html(data);
			jQuery('#wait').css('display', 'none') 
		})
	}
	else
	{
		jQuery.post("manage.php", {
			  id: id, 
			  ajax: 'save', 
			  action: action
			}, function(data){
			jQuery("#representatives_div").html(data);
			jQuery('#wait').css('display', 'none') 
		})
	}
}

function addNewCity(state_id)
{
	jQuery.post("manage.php", {
		  ajax: 'new_city_form', 
		  state_id: state_id
		}, function (data) {
	jQuery("#cities_div").html(data);
	jQuery("#representatives_div").html("")
		});
}

function saveCity()
{ 
	var name               = jQuery('#city').val();
	var state_id           = jQuery('#state_id').val();
	
	jQuery('#wait').css('display', 'block') 
	jQuery.post("manage.php", {
		  ajax: 'saveCity', 
		  name: name,
		  state_id: state_id
		}, function(data){
		jQuery("#cities_div").html(data);
		jQuery('#wait').css('display', 'none') 
	})
}

function checkPhone(value, count, nextObject)
{
	if (value.length >= count) document.getElementById(nextObject).focus();
}

function getNewCities(state_id, city_id)
{
	jQuery('#wait').css('display', 'block') 
	jQuery.post("manage.php", {state_id: state_id, selected: city_id, ajax: 'getCitiesNew', action: jQuery('#action_value').val()}, function(data){
		jQuery("#new_cities_div").html(data);
	})
}

function showBlock(checked, block)
{
	jQuery('#'+block).css('display', checked == true ? 'block' : 'none') 
}