function doclick(){
     $(".do_checkbox input").click(function(){
       var doId =$(this).val();
       var Id = $(this).val();
       //alert(doId);
       if( $(this).is(':checked') ) {
        $('div.container').block({ message: 'Loading...' }); 
        $.ajax({
        url: 'user_profile_setup_agent.php',
        type: "GET",
        data: "do_id="+doId,
        dataType: "json",
        success:function(data) {
         // alert(JSON.stringify(data));
          $(".agent_cont").append(data["content"]);
          $('div.container').unblock(); 
          //doclick();
          //alert("Form submitted successfully.\nReturned json: " + data["content"]);
        },
        failure:function(data) {
          alert("Something Wrong Went");
          $('div.container').unblock(); 
        }

      }); 
       
  }
  else {
    //alert("this is not checked");
    var id = ".do"+doId;
    $(id).remove();
  }
    });
}



  $(document).ready(function(){
    doclick();
    dosubmakeclick();

    $(".branch_checkbox input").click(function(){
      var branchId =$(this).val();
      if( $(this).is(':checked') ) {
        $('div.container').block({ message: 'Loading...' }); 
      $.ajax({
        url: 'user_profile_setup_do.php',
        type: "GET",
        data: "branch_id="+$(this).val(),
        dataType: "json",
        success:function(data) {
          //alert(JSON.stringify(data));
          $(".do_cont").append(data["content"]);
          $(".client_cont").append(data["contentclient"]);
          doclick();
	   dosubmakeclick();
          $('div.container').unblock(); 
          //alert("Form submitted successfully.\nReturned json: " + data["content"]);
        },
        failure:function(data) {
          alert("Something Wrong Went");
          $('div.container').unblock(); 
        }
      }); 

     }
     else {
          $(".br"+branchId+" input:checked").each(function() {
          $(".do"+$(this).attr('value')).remove();
        });
          var id = ".br"+branchId;
        $(id).remove();
     }

    });

    $(".make_checkbox input").click(function(){
	
      var makeId =$(this).val();
      if( $(this).is(':checked') ) {
        $('div.container').block({ message: 'Loading...' }); 
      $.ajax({
        url: 'product_make_submake.php',
        type: "GET",
        data: "make_id="+$(this).val(),
        dataType: "json",
        success:function(data) {
          //alert(JSON.stringify(data));
          $(".submake_cont").append(data["content"]);
          doclick();
	   dosubmakeclick();
          $('div.container').unblock(); 
          //alert("Form submitted successfully.\nReturned json: " + data["content"]);
        },
        failure:function(data) {
          alert("Something Wrong Went");
          $('div.container').unblock(); 
        }
      }); 

     }
     else {
          $(".br"+makeId+" input:checked").each(function() {
          $(".submake"+$(this).attr('value')).remove();
        });
          var id = ".br"+makeId;
        $(id).remove();
     }

    });

 });

function dosubmakeclick(){
	$(".submake_checkbox input").click(function(){
	  var submakeId =$(this).val();
	  var submakeName = this.id;
	  if( $(this).is(':checked') ) {
		var $data = '';
		$data = '<div id="t'+submakeId+'">';
		$data += '<input type="checkbox" value="'+submakeId+'" name="tracker[]" class="inp" id="'+submakeId+'" />';
              $data += '<label for="'+submakeId+'">'+submakeName+'</label>';
              $data += '</div>';

		$(".submaketracker_cont").append($data);
	   }
	   else {
		$("#t"+submakeId).remove();		
     	   }

	}); 

}


$(document).ready(function(){
   
    var totalChars      = 4000 - $('#counttextarea').text().length ; //Total characters allowed in textarea
    var countTextBox    = $('#counttextarea') // Textarea input box
    var charsCountEl    = $('#countchars'); // Remaining chars count will be displayed here
    
    charsCountEl.text(totalChars); //initial value of countchars element
    countTextBox.keyup(function() { //user releases a key on the keyboard
        var thisChars = this.value.replace(/{.*}/g, '').length; //get chars count in textarea
        if(thisChars > totalChars) //if we have more chars than it should be
        {
            var CharsToDel = (thisChars-totalChars); // total extra chars to delete
            this.value = this.value.substring(0,this.value.length-CharsToDel); //remove excess chars from textarea
        }else{
            charsCountEl.text( totalChars - thisChars ); //count remaining chars
        }
    });
});