function save_partial_commission_releases_schedule(){
	//alert('saving...'); 
	var mods 					=	$('#main_page').val();
	var types 					=	$('#main_type').val(); 
	var action 					=	$('#main_action').val();
	var mainid					=	$('#main_id').val(); 

	var partial_commission		=	$('#partial_commission_releases_schedule_form').serialize(); 
  
	var dataString				=	partial_commission+"&action="+encodeURIComponent(action)+"&mainid="+encodeURIComponent(mainid)+"&types="+encodeURIComponent(types);  
 
	$.post('./ajax/partial_commission_releases_schedule.php', dataString, function(msg){
		var obj	= $.parseJSON(msg);
			if(obj.output==true){
				bootbox.alert("Successfully Saved ..."); 
				window.setTimeout(function() { window.location.href = 'index.php?pg='+mods+'&type='+types; }, 1000);
			}else{
				bootbox.alert("Failed in saving.");
			}
	}); 
  
}

function checkCompleteRequirements(reservationId){
  
	var dataString				=	"reservation_id="+encodeURIComponent(reservationId); 
	$.post('./ajax/check_complete_requirements.php', dataString, function(msg){
		 
								var obj	= $.parseJSON(msg);
								if(obj.output==true){
									//REQUIREMENTS ALL COMPLETE
									$('#complete_requirement').val('yes');
								}else{
									//REQUIREMENTS INCOMPLETE
									$('#complete_requirement').val('no');
								}
						}); 
}

function checkCompleteEquity(reservationId){
  
	var dataString				=	"reservation_id="+encodeURIComponent(reservationId); 
	$.post('./ajax/check_complete_equity.php', dataString, function(msg){
								var obj	= $.parseJSON(msg);
								if(obj.output==true){
									//EQUITY ALL COMPLETE
									$('#complete_equity').val('yes');
								}else{
									//EQUITY INCOMPLETE
									$('#complete_equity').val('no');
								}
						}); 
}

load_partial_commission_releases_schedule();
 

function load_partial_commission_releases_schedule(){

				var mods 			=	$('#main_page').val();
				var types 			=	$('#main_type').val(); 
				var action 			=	$('#main_action').val();
				var mainid			=	$('#main_id').val();
				var dataString		=	"action="+encodeURIComponent(action)+"&mainid="+encodeURIComponent(mainid); 

				$('.warning_incomplete_req').hide();    //hide incomplete req symbol
				$('.warning_incomplete_equity').hide(); //hide incomplete equity symbol


				checkCompleteRequirements(mainid);
				checkCompleteEquity(mainid);
  
				if(action=='edit' || action=='view' || action=='create'){
						

						$.post('./ajax/load_partial_commission_releases_schedule.php', dataString, function(msg){ 
								var obj	= $.parseJSON(msg); 
								 
								var reservation_date	=	obj.data[0].reservation_date;
								var model				=	obj.data[0].model;
						 		var block				=	obj.data[0].block;
								var lot					=	obj.data[0].lot; 
						 		var full_name			=	obj.data[0].full_name; 

								var broker				=	obj.data[0].broker; 
								var agent				=	obj.data[0].agent;
								var realty				=	obj.data[0].realty; 
								var reservation_id		=	obj.data[0].id; 

								var broker_account		=	obj.data[0].broker_account; 
								var agent_account		=	obj.data[0].agent_account;

								$('.agent_name').val(agent);
								$('.broker_name').val(broker);


								$('.agent_account').val(agent_account);
								$('.broker_account').val(broker_account);
 
 								var first_release_checkbox 			= obj.data[0].first_release_checkbox;  
								var first_release_broker_amount 	= obj.data[0].first_release_broker_amount; 
								var first_release_agent_amount  	= obj.data[0].first_release_agent_amount;  
								var first_release_date 				= obj.data[0].first_release_date;   
 
								var second_release_checkbox  		= obj.data[0].second_release_checkbox; 
								var second_release_broker_amount  	= obj.data[0].second_release_broker_amount; 
								var second_release_agent_amount 	= obj.data[0].second_release_agent_amount; 
								var second_release_date				= obj.data[0].second_release_date; 
								 
								var third_release_checkbox  		= obj.data[0].third_release_checkbox; 
								var third_release_broker_amount  	= obj.data[0].third_release_broker_amount; 
								var third_release_agent_amount 		= obj.data[0].third_release_agent_amount; 
								var third_release_date				= obj.data[0].third_release_date; 
  
								var fourth_release_checkbox  		= obj.data[0].fourth_release_checkbox; 
								var fourth_release_broker_amount  	= obj.data[0].fourth_release_broker_amount; 
								var fourth_release_agent_amount 	= obj.data[0].fourth_release_agent_amount; 
								var fourth_release_date				= obj.data[0].fourth_release_date; 
 
								var fifth_release_checkbox  		= obj.data[0].fifth_release_checkbox; 
								var fifth_release_broker_amount  	= obj.data[0].fifth_release_broker_amount; 
								var fifth_release_agent_amount 		= obj.data[0].fifth_release_agent_amount; 
								var fifth_release_date				= obj.data[0].fifth_release_date; 
 
								var six_release_checkbox  			= obj.data[0].six_release_checkbox; 
								var six_release_broker_amount 	 	= obj.data[0].six_release_broker_amount; 
								var six_release_agent_amount 		= obj.data[0].six_release_agent_amount; 
								var six_release_date				= obj.data[0].six_release_date; 
 
								var seven_release_checkbox  		= obj.data[0].seven_release_checkbox; 
								var seven_release_broker_amount 	= obj.data[0].seven_release_broker_amount; 
								var seven_release_agent_amount 		= obj.data[0].seven_release_agent_amount; 
								var seven_release_date				= obj.data[0].seven_release_date; 
 
								var eight_release_checkbox  		= obj.data[0].eight_release_checkbox; 
								var eight_release_broker_amount 	= obj.data[0].eight_release_broker_amount; 
								var eight_release_agent_amount 		= obj.data[0].eight_release_agent_amount; 
								var eight_release_date				= obj.data[0].eight_release_date; 
 
								var nine_release_checkbox  			= obj.data[0].nine_release_checkbox; 
								var nine_release_broker_amount 		= obj.data[0].nine_release_broker_amount; 
								var nine_release_agent_amount 		= obj.data[0].nine_release_agent_amount; 
								var nine_release_date				= obj.data[0].nine_release_date; 
 
								var ten_release_checkbox  			= obj.data[0].ten_release_checkbox; 
								var ten_release_broker_amount 		= obj.data[0].ten_release_broker_amount; 
								var ten_release_agent_amount 		= obj.data[0].ten_release_agent_amount; 
								var ten_release_date				= obj.data[0].ten_release_date; 

								var eleven_release_checkbox  		= obj.data[0].eleven_release_checkbox; 
								var eleven_release_broker_amount 	= obj.data[0].eleven_release_broker_amount; 
								var eleven_release_agent_amount 	= obj.data[0].eleven_release_agent_amount; 
								var eleven_release_date				= obj.data[0].eleven_release_date; 

								var twelve_release_checkbox  		= obj.data[0].twelve_release_checkbox; 
								var twelve_release_broker_amount 	= obj.data[0].twelve_release_broker_amount; 
								var twelve_release_agent_amount 	= obj.data[0].twelve_release_agent_amount; 
								var twelve_release_date				= obj.data[0].twelve_release_date; 
 
								if(first_release_broker_amount=='NaN' || first_release_broker_amount=='0.00' || first_release_broker_amount=='' || first_release_broker_amount==null){
									first_release_broker_amount = '2000.00';
								}

								if(first_release_agent_amount=='NaN' || first_release_agent_amount=='0.00' || first_release_agent_amount=='' || first_release_agent_amount==null){
									first_release_agent_amount = '3000.00';
								}
 
								if(second_release_broker_amount=='NaN' || second_release_broker_amount=='0.00' || second_release_broker_amount=='' || second_release_broker_amount==null){
									second_release_broker_amount = '2000.00';
								}

								if(second_release_agent_amount=='NaN' || second_release_agent_amount=='0.00' || second_release_agent_amount=='' || second_release_agent_amount==null){
									second_release_agent_amount = '3000.00';
								}

								if(third_release_broker_amount=='NaN' || third_release_broker_amount=='0.00' || third_release_broker_amount=='' || third_release_broker_amount==null){
									third_release_broker_amount = '2000.00';
								}

								if(third_release_agent_amount=='NaN' || third_release_agent_amount=='0.00' || third_release_agent_amount=='' || third_release_agent_amount==null){
									third_release_agent_amount = '3000.00';
								}
								
								if(fourth_release_broker_amount=='NaN' || fourth_release_broker_amount=='0.00' || fourth_release_broker_amount=='' || fourth_release_broker_amount==null){
									fourth_release_broker_amount = '2000.00';
								}

								if(fourth_release_agent_amount=='NaN' || fourth_release_agent_amount=='0.00' || fourth_release_agent_amount=='' || fourth_release_agent_amount==null){
									fourth_release_agent_amount = '3000.00';
								}

								if(fifth_release_broker_amount=='NaN' || fifth_release_broker_amount=='0.00' || fifth_release_broker_amount=='' || fifth_release_broker_amount==null){
									fifth_release_broker_amount = '2000.00';
								}

								if(fifth_release_agent_amount=='NaN' || fifth_release_agent_amount=='0.00' || fifth_release_agent_amount=='' || fifth_release_agent_amount==null){
									fifth_release_agent_amount = '3000.00';
								}
								
								if(six_release_broker_amount=='NaN' || six_release_broker_amount=='0.00' || six_release_broker_amount=='' || six_release_broker_amount==null){
									six_release_broker_amount = '2000.00';
								}

								if(six_release_agent_amount=='NaN' || six_release_agent_amount=='0.00' || six_release_agent_amount=='' || six_release_agent_amount==null){
									six_release_agent_amount = '3000.00';
								}

								if(seven_release_broker_amount=='NaN' || seven_release_broker_amount=='0.00' || seven_release_broker_amount=='' || seven_release_broker_amount==null){
									seven_release_broker_amount = '2000.00';
								}

								if(seven_release_agent_amount=='NaN' || seven_release_agent_amount=='0.00' || seven_release_agent_amount=='' || seven_release_agent_amount==null){
									seven_release_agent_amount = '3000.00';
								}
								
								if(eight_release_broker_amount=='NaN' || eight_release_broker_amount=='0.00' || eight_release_broker_amount=='' || eight_release_broker_amount==null){
									eight_release_broker_amount = '2000.00';
								}

								if(eight_release_agent_amount=='NaN' || eight_release_agent_amount=='0.00' || eight_release_agent_amount=='' || eight_release_agent_amount==null){
									eight_release_agent_amount = '3000.00';
								}
								
								if(nine_release_broker_amount=='NaN' || nine_release_broker_amount=='0.00' || nine_release_broker_amount=='' || nine_release_broker_amount==null){
									nine_release_broker_amount = '2000.00';
								}

								if(nine_release_agent_amount=='NaN' || nine_release_agent_amount=='0.00' || nine_release_agent_amount=='' || nine_release_agent_amount==null){
									nine_release_agent_amount = '3000.00';
								}
								
								if(ten_release_broker_amount=='NaN' || ten_release_broker_amount=='0.00' || ten_release_broker_amount=='' || ten_release_broker_amount==null){
									ten_release_broker_amount = '2000.00';
								}

								if(ten_release_agent_amount=='NaN' || ten_release_agent_amount=='0.00' || ten_release_agent_amount=='' || ten_release_agent_amount==null){
									ten_release_agent_amount = '3000.00';
								}


								if(eleven_release_broker_amount=='NaN' || eleven_release_broker_amount=='0.00' || eleven_release_broker_amount=='' || eleven_release_broker_amount==null){
									eleven_release_broker_amount = '2000.00';
								}

								if(eleven_release_agent_amount=='NaN' || eleven_release_agent_amount=='0.00' || eleven_release_agent_amount=='' || eleven_release_agent_amount==null){
									eleven_release_agent_amount = '3000.00';
								}

								if(twelve_release_broker_amount=='NaN' || twelve_release_broker_amount=='0.00' || twelve_release_broker_amount=='' || twelve_release_broker_amount==null){
									twelve_release_broker_amount = '2000.00';
								}

								if(twelve_release_agent_amount=='NaN' || twelve_release_agent_amount=='0.00' || twelve_release_agent_amount=='' || twelve_release_agent_amount==null){
									twelve_release_agent_amount = '3000.00';
								}
								
 
								if(first_release_date=='01/01/1970'){
									first_release_date = '';
								}

								if(second_release_date=='01/01/1970'){
									second_release_date = '';
								}

								if(third_release_date=='01/01/1970'){
									third_release_date = '';
								}

								if(fourth_release_date=='01/01/1970'){
									fourth_release_date = '';
								}

								if(fifth_release_date=='01/01/1970'){
									fifth_release_date = '';
								}

								if(six_release_date=='01/01/1970'){
									six_release_date = '';
								}

								if(seven_release_date=='01/01/1970'){
									seven_release_date = '';
								}

								if(eight_release_date=='01/01/1970'){
									eight_release_date = '';
								}

								if(nine_release_date=='01/01/1970'){
									nine_release_date = '';
								}

								if(ten_release_date=='01/01/1970'){
									ten_release_date = '';
								}

								if(eleven_release_date=='01/01/1970'){
									eleven_release_date = '';
								}

								if(twelve_release_date=='01/01/1970'){
									twelve_release_date = '';
								}

								if(reservation_date=='01/01/1970'){
									reservation_date = '';
								}


								//CHECKBOXES
								if(first_release_checkbox=='on'){
									$('#first_release_checkbox').attr('checked',true);
								}
								  
								if(second_release_checkbox=='on'){
									$('#second_release_checkbox').attr('checked',true);
								}
								 
								if(third_release_checkbox=='on'){
									$('#third_release_checkbox').attr('checked',true);
								}

								if(fourth_release_checkbox=='on'){
									$('#fourth_release_checkbox').attr('checked',true);
								}

								if(fifth_release_checkbox=='on'){
									$('#fifth_release_checkbox').attr('checked',true);
								}

								if(six_release_checkbox=='on'){
									$('#six_release_checkbox').attr('checked',true);
								}

								if(seven_release_checkbox=='on'){
									$('#seven_release_checkbox').attr('checked',true);
								}

								if(eight_release_checkbox=='on'){
									$('#eight_release_checkbox').attr('checked',true);
								}

								if(nine_release_checkbox=='on'){
									$('#nine_release_checkbox').attr('checked',true);
								}

								if(ten_release_checkbox=='on'){
									$('#ten_release_checkbox').attr('checked',true);
								}

								if(eleven_release_checkbox=='on'){
									$('#eleven_release_checkbox').attr('checked',true);
								}
  
								if(twelve_release_checkbox=='on'){
									$('#twelve_release_checkbox').attr('checked',true);
								}

								first_release_broker_amount = Comma(parseFloat(first_release_broker_amount).toFixed(2));
								$('#first_broker_amount').val(first_release_broker_amount);
								first_release_agent_amount = Comma(parseFloat(first_release_agent_amount).toFixed(2));
								$('#first_agent_amount').val(first_release_agent_amount);
								
								second_release_broker_amount = Comma(parseFloat(second_release_broker_amount).toFixed(2));
								$('#second_broker_amount').val(second_release_broker_amount);
								second_release_agent_amount = Comma(parseFloat(second_release_agent_amount).toFixed(2));
								$('#second_agent_amount').val(second_release_agent_amount);
								
								third_release_broker_amount = Comma(parseFloat(third_release_broker_amount).toFixed(2));
								$('#third_broker_amount').val(third_release_broker_amount);
								third_release_agent_amount = Comma(parseFloat(third_release_agent_amount).toFixed(2));
								$('#third_agent_amount').val(third_release_agent_amount);
								
								fourth_release_broker_amount = Comma(parseFloat(fourth_release_broker_amount).toFixed(2));
								$('#fourth_broker_amount').val(fourth_release_broker_amount);
								fourth_release_agent_amount = Comma(parseFloat(fourth_release_agent_amount).toFixed(2));
								$('#fourth_agent_amount').val(fourth_release_agent_amount);
								
								fifth_release_broker_amount = Comma(parseFloat(fifth_release_broker_amount).toFixed(2));
								$('#fifth_broker_amount').val(fifth_release_broker_amount);
								fifth_release_agent_amount = Comma(parseFloat(fifth_release_agent_amount).toFixed(2));
								$('#fifth_agent_amount').val(fifth_release_agent_amount);

								six_release_broker_amount = Comma(parseFloat(six_release_broker_amount).toFixed(2));
								$('#six_broker_amount').val(six_release_broker_amount);
								six_release_agent_amount = Comma(parseFloat(six_release_agent_amount).toFixed(2));
								$('#six_agent_amount').val(six_release_agent_amount);

								seven_release_broker_amount = Comma(parseFloat(seven_release_broker_amount).toFixed(2));
								$('#seven_broker_amount').val(seven_release_broker_amount);
								seven_release_agent_amount = Comma(parseFloat(seven_release_agent_amount).toFixed(2));
								$('#seven_agent_amount').val(seven_release_agent_amount);
								
								eight_release_broker_amount = Comma(parseFloat(eight_release_broker_amount).toFixed(2));
								$('#eight_broker_amount').val(eight_release_broker_amount);
								eight_release_agent_amount = Comma(parseFloat(eight_release_agent_amount).toFixed(2));
								$('#eight_agent_amount').val(eight_release_agent_amount);
								
								nine_release_broker_amount = Comma(parseFloat(nine_release_broker_amount).toFixed(2));
								$('#nine_broker_amount').val(nine_release_broker_amount);
								nine_release_agent_amount = Comma(parseFloat(nine_release_agent_amount).toFixed(2));
								$('#nine_agent_amount').val(nine_release_agent_amount);
								
								ten_release_broker_amount = Comma(parseFloat(ten_release_broker_amount).toFixed(2));
								$('#ten_broker_amount').val(ten_release_broker_amount);
								ten_release_agent_amount = Comma(parseFloat(ten_release_agent_amount).toFixed(2));
								$('#ten_agent_amount').val(ten_release_agent_amount);

								eleven_release_broker_amount = Comma(parseFloat(eleven_release_broker_amount).toFixed(2));
								$('#eleven_broker_amount').val(eleven_release_broker_amount);
								eleven_release_agent_amount = Comma(parseFloat(eleven_release_agent_amount).toFixed(2));
								$('#eleven_agent_amount').val(eleven_release_agent_amount);

								twelve_release_broker_amount = Comma(parseFloat(twelve_release_broker_amount).toFixed(2));
								$('#twelve_broker_amount').val(twelve_release_broker_amount);
								twelve_release_agent_amount = Comma(parseFloat(twelve_release_agent_amount).toFixed(2));
								$('#twelve_agent_amount').val(twelve_release_agent_amount);
								
 

								//RELEASE DATES
								$('#first_release_date').val(first_release_date);
								$('#second_release_date').val(second_release_date);
								$('#third_release_date').val(third_release_date);
								$('#fourth_release_date').val(fourth_release_date);
								$('#fifth_release_date').val(fifth_release_date);
								$('#six_release_date').val(six_release_date);
								$('#seven_release_date').val(seven_release_date);
								$('#eight_release_date').val(eight_release_date);
								$('#nine_release_date').val(nine_release_date);
								$('#ten_release_date').val(ten_release_date);
								$('#eleven_release_date').val(eleven_release_date);
								$('#twelve_release_date').val(twelve_release_date);
								

								$('#partial_buyer').val(full_name);

								
								$('#partial_block').val(block);
								$('#partial_broker').val(broker);
								$('#partial_agent').val(agent);
								$('#partial_realty').val(realty);
								$('#partial_lot').val(lot);
								$('#reservation_id').val(reservation_id);
								$('#partial_reservation_date').val(reservation_date);
								 
												
								
								var iscomplete_req = $('#complete_requirement').val();
								
								$('.warning_incomplete_req').hide();    //hide incomplete req symbol
								$('.warning_incomplete_equity').hide(); //hide incomplete equity symbol

								if(iscomplete_req=='no'){
									/*
									$('.release_checkbox').attr('checked',false); 
									$('.release_checkbox').attr('disabled',true); 
									$('.datepicker').attr('disabled',true); 
									$('.datepicker').css('cursor','not-allowed');
									*/

									//if requirement not complete 4th tickedbox till 12th will be disabled
									$('.warning_incomplete_req').show();    //show incomplete req symbol
 
									$('#fourth_release_checkbox').attr('checked',false); 
									$('#fourth_release_checkbox').attr('disabled',true); 
									$('#fourth_release_date').attr('disabled',true); 
									$('#fourth_release_date').css('cursor','not-allowed');

									$('#fifth_release_checkbox').attr('checked',false); 
									$('#fifth_release_checkbox').attr('disabled',true); 
									$('#fifth_release_date').attr('disabled',true); 
									$('#fifth_release_date').css('cursor','not-allowed');

									$('#six_release_checkbox').attr('checked',false); 
									$('#six_release_checkbox').attr('disabled',true); 
									$('#six_release_date').attr('disabled',true); 
									$('#six_release_date').css('cursor','not-allowed');

									$('#seven_release_checkbox').attr('checked',false); 
									$('#seven_release_checkbox').attr('disabled',true); 
									$('#seven_release_date').attr('disabled',true); 
									$('#seven_release_date').css('cursor','not-allowed');

									$('#eight_release_checkbox').attr('checked',false); 
									$('#eight_release_checkbox').attr('disabled',true); 
									$('#eight_release_date').attr('disabled',true); 
									$('#eight_release_date').css('cursor','not-allowed');
 
									$('#nine_release_checkbox').attr('checked',false); 
									$('#nine_release_checkbox').attr('disabled',true); 
									$('#nine_release_date').attr('disabled',true); 
									$('#nine_release_date').css('cursor','not-allowed');
 
									$('#ten_release_checkbox').attr('checked',false); 
									$('#ten_release_checkbox').attr('disabled',true); 
									$('#ten_release_date').attr('disabled',true); 
									$('#ten_release_date').css('cursor','not-allowed');
 
									$('#eleven_release_checkbox').attr('checked',false); 
									$('#eleven_release_checkbox').attr('disabled',true); 
									$('#eleven_release_date').attr('disabled',true); 
									$('#eleven_release_date').css('cursor','not-allowed');
 
									$('#twelve_release_checkbox').attr('checked',false); 
									$('#twelve_release_checkbox').attr('disabled',true); 
									$('#twelve_release_date').attr('disabled',true); 
									$('#twelve_release_date').css('cursor','not-allowed');

									
								}

								var iscomplete_equity = $('#complete_equity').val();
								 
								if(iscomplete_equity=='no'){
									$('.release_checkbox').attr('checked',false); 
									$('.release_checkbox').attr('disabled',true); 
									$('.datepicker').attr('disabled',true); 
									$('.datepicker').css('cursor','not-allowed'); 

									$('.warning_incomplete_equity').show(); //show incomplete equity symbol
								}

								if(iscomplete_req=='yes' && iscomplete_equity=='yes'){ 
									$('.release_checkbox').attr('disabled',false); 
									$('.datepicker').attr('disabled',false); 
									$('.datepicker').css('cursor','cursor'); 	
									$('.datepicker').css('background-color','#ffffff'); 	

									$('.warning_incomplete_req').hide();    //hide incomplete req symbol
									$('.warning_incomplete_equity').hide(); //hide incomplete equity symbol
								}

								//alert(iscomplete_equity+' is equity complete');
								//alert(iscomplete_req+' is req complete');
						});
			}
}
   
									