/// check the user name already exist
function check_user_name(siteurl)
{ 
	set_data1('');
	var user_name = document.getElementById('username').value;
	
	$.ajax({
			  type: "POST",
			  url: siteurl+"/ajax_php/chk_user.php",
			  data: "username="+user_name,
			  beforeSend:function()
			  {
				  $("#loading_img").show();
			  }, 
			  success: function(data){
				    //alert(data);
					setTimeout('set_data1(\''+data+'\')',1500)
				  }
			  /*complete:function()
			  {
				 $("#loading_img").hide();
			  }*/
			});
	$("#error").html("");
}
function set_data1(data)
{
   $("#td_user_name").html(data);
   $("#loading_img").hide();
}

/// end  check the user name already exist
/// populate states of USA
function populate_sates(siteurl,register)
{ 
	var country = document.getElementById('country').value;
	$.ajax({
			  type: "POST",
			  url: siteurl+"/ajax_php/populate_states.php",
			  data: "country_name="+country+"&register="+register,
			  success: function(data){
					$("#ajax_states_div").html(data);
				  }
			});
}

/// end populate states of USA

//  populate counties
function pop_multiple_counties(siteurl,register)
{ 
	var province_options = document.getElementById('province_id[]').options;
	var province_ids = '';
	for(i=0;i<province_options.length;i++){
		if(province_options[i].selected)
		{
			province_ids += ", " + province_options[i].value;
			if(province_options[i].value == 1)
			{
				province_ids = ",1";
				break;
			}
		}
	}
	province_ids = province_ids.substr(1);
	$.ajax({
			  type: "POST",
			  url: siteurl+"/ajax_php/pop_multiple_counties.php",
			  data: "province_id="+province_ids+"&register="+register,
			  beforeSend:function()
			  {
				$("#loading_img_1").show();
				if(document.getElementById('county_id[]'))
				{ 
				   document.getElementById('county_id[]').disabled = "disabled";
				}
				else
				{
				  document.getElementById('county_id').disabled = "disabled";
				}
			  }, 
			  success: function(data){
					$("#ajax_county_div").html(data);
				  },
			  complete:function()
			  {
				 $("#loading_img_1").hide();
			  }	  
			});
}

/// populate region
function pop_multiple_regions(siteurl,register)
{ 
	var county_options = document.getElementById('county_id[]').options;
	var county_ids = '';
	for(i=0;i<county_options.length;i++){
		if(county_options[i].selected)
			county_ids += ", " + county_options[i].value;
	}
	county_ids = county_ids.substr(1);
	$.ajax({
			  type: "POST",
			  url: siteurl+"/ajax_php/pop_multiple_regions.php",
			  data: "county_id="+county_ids+"&register="+register,
			  beforeSend:function()
			  {
				$("#loading_img_2").show();
				if(document.getElementById('regions[]'))
				{ 
				   document.getElementById('regions[]').disabled = "disabled";
				}
				else
				{
				  document.getElementById('regions').disabled = "disabled";
				}
			  }, 
			  success: function(data){
					$("#ajax_region_div").html(data);
				  },
			  complete:function()
			  {
				 $("#loading_img_2").hide();
			  }	  
			});
}

/// end populate region

/// populate region
function populate_regions(siteurl,register)
{ 
	var county = document.getElementById('county_id').value;
	$.ajax({
			  type: "POST",
			  url: siteurl+"/ajax_php/populate_regions.php",
			  data: "county_id="+county+"&register="+register,
			  beforeSend:function()
			  {
				$("#loading_img_1").show();
				if(document.getElementById('regions[]'))
				{ 
				   document.getElementById('regions[]').disabled = "disabled";
				}
				else
				{
				  document.getElementById('regions').disabled = "disabled";
				}
			  }, 
			  success: function(data){
					$("#ajax_region_div").html(data);
				  },
			  complete:function()
			  {
				 $("#loading_img_1").hide();
			  }	  
			});
}

/// end populate region

function getBuilderDescription(siteurl)
{
	var builder_id = document.getElementById('builder_id').value;
	$.ajax({
			  type: "POST",
			  url: siteurl+"/ajax_php/chk_user.php",
			  data: "builder_id="+builder_id,
			  success: function(data){
				    $("#description_experience").html(data);
				  }
			});
	}

