function getDealersByState(state){
	$.get("/actions.php?action=getDealersByState&state="+state, function(data){
		$("#dealersWrap").html(data);
	});
}

function getDealers(){
	$.get("/actions.php?action=getDealers", function(data){
		$("#dealers").html(data);
	});
}

function getDealerById(id){
	$.get("/actions.php?action=getDealerById&id="+id, function(data){
		$("#dealer").html(data);
	});
}

function getStatesByCountry(country){
	var html = "<option value=\"0\"selected>Select State...</option>";
	var noState = false;
	
	if(country == 840){
		getDealerStates();
		getDealersByState(26);
	} else {
		$.get("/actions.php?action=getStatesByCountry&countryId="+country, function(data){
	
			$(data).find("state").each(function(){
				if($(this).attr('name') == "N/A" || $(this).attr('name') == "n/a"){
					html = "";
					noState = $(this).attr('code');
				}
				html += "<option value=\""+$(this).attr('code')+"\">"+ $(this).attr('name')+"</option>";	
			});
		
			$("#state").html(html);
		
			if(noState){
				getDealersByState(noState);
			}
		});
	}
}

function getCountries(){
	$.get("/actions.php?action=getCountries" ,function(data){
		var html = "";
		$(data).find("country").each(function(){
			var s = "";
			if($(this).attr('code') == 840){
				s = "selected";
			}
			
			if($(this).attr('name') != "N/A" && $(this).attr('name') != "n/a"){
				html += "<option "+s+" value=\""+$(this).attr('code')+"\">"+$(this).attr('name')+"</option>";
			}
		});
		
		$("#country").html(html);
		
	});
}

function getProstaffStates(){
	$.get("/actions.php?action=getProstaffStates", function(data){
		var html = "<option value=\"0\"selected>Select State...</option>";
		$(data).find("state").each(function(){
			var s = "";
			if($(this).attr('code') == 26){
				s = "selected";
			}
			html += "<option "+s+" value=\""+$(this).attr('code')+"\">"+ $(this).attr('name')+"</option>";
		});
		$("#state").html(html);
	});
}

function getDealerStates(){
	$.get("/actions.php?action=getDealerStates", function(data){
		var html = "<option value=\"0\">Select State...</option>";
		$(data).find("state").each(function(){
			if($(this).attr('name') != "N/A" && $(this).attr('name') != "n/a"){
				var s = "";
				if($(this).attr('code') == 26){
					s = "selected";
				}
				html += "<option " + s +" value=\""+$(this).attr('code')+"\">"+ $(this).attr('name')+"</option>";
			}
		});
		$("#state").html(html);
	});
}


function getStates(){
	$.get("/actions.php?action=getStates", function(data){
		var html = "<option value=\"0\">Select State...</option>";
		$(data).find("state").each(function(){
			if($(this).attr('name') != "N/A" && $(this).attr('name') != "n/a"){
				var s = "";
				if($(this).attr('code') == 26){
					s = "selected";
				}
				html += "<option "+s+" value=\""+$(this).attr('code')+"\">"+ $(this).attr('name')+"</option>";
			}
		});
		$("#state").html(html);
	});
}

function getProStaff(id){
	$.get("/actions.php?action=getProStaff", function(data){
		$(id).html();
	});
}

function getProStaffById(id){
	$.get("/actions.php?action=getProStaffById&id="+id, function(data){
		$("#dealer").html(data);
	});
}

function getProStaffByCountry(state){
	$.get("/actions.php?action=getProStaff&state="+state,function(data){
		$("#proWrapper").html(data)
	});	
}

