$(document).ready(function(){ 
	var mods 			=	$('#main_page').val();
	var types 			=	$('#main_type').val(); 
	var action 			=	$('#main_action').val(); 
  	   
});



//SAVING RESERVATION
function save_reservation(){ 
				var mods 					=	$('#main_page').val();
				var types 					=	$('#main_type').val(); 
				var action 					=	$('#main_action').val();
				var mainid					=	$('#main_id').val();
				var rtransfer				=	$('#rtransfer').val(); 
				var myform = $('#reservation_form');
				myform.find('select:disabled').removeAttr('disabled');
				myform.find(':input:disabled').removeAttr('disabled');
				var reservation_details		=	$('#reservation_form').serialize();
				
				var p = $('#current_phase').val();
				var b = $('#current_block').val();
				var l = $('#current_lot').val();
				var pd = $('#pricelist_date').val();
				var rd = $('#reservation_date').val();
				var et = $('#employee_type').val();
				var cm = $('#current_model').val();
				var cp = $('#current_project').val();
				var cb = $('#current_broker').val();
				var ca = $('#current_agent').val();
				
				if(p=='' || b=='' || l=='' || pd=='' || rd=='' || et=='-' || et=='' || cm=='' || cp=='' || cb=='' || ca==''){
					bootbox.alert("Required Fields"); 
				}else{
						var dataString				=	reservation_details+"&action="+encodeURIComponent(action)+"&mainid="+encodeURIComponent(mainid)+"&rtransfer="+encodeURIComponent(rtransfer);  
						$.post('./ajax/reservation.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.");
								}
						});
				}
				
				
}
  
  
  //LOADING RESERVATION DETAILS
function load_conversion(){
				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); 
						$.post('./ajax/load_conversion.php', dataString, function(msg){ 
								var obj	= $.parseJSON(msg);
								var project				=	obj.data[0].project;
								var model				=	obj.data[0].model;
								var reservationDate		=	obj.data[0].reservation_date;  
								
								var phase				=	obj.data[0].phase;
								var block				=	obj.data[0].block;
								var lot					=	obj.data[0].lot;

   
							 $('#reservedate').val(reservationDate);   
								var r = $('#reservation_date').val();   
	  							
								var spa					=	obj.data[0].spa;
								var spa_contactno		=	obj.data[0].spa_contactno;
								var tcp					=	obj.data[0].tcp;
								var loanable_amount		=	obj.data[0].loanable_amount;
	  							
								$('#reservation_spa').val(spa);								
								$('#reservation_spa_contactno').val(spa_contactno);								
 							 
								if(action=="view"){
									$('input').attr("disabled", true);
									$('textarea').attr("disabled", true);
									$('select').attr("disabled", true);
									$('#current_project').select2('disable');
									$('#current_model').select2('disable'); 
									$('.glyphicon-trash').hide();
									$('.glyphicon-plus').hide();  
									$('.refresh').hide();  
								}
  								$('#transfer_spa_contactno').val(spa_contactno);  
						});
}
  
//DELETE CONVERSION
function delete_conversion(id){
		var transaction		=	"conversion";
		var mods 			=	$('#main_page').val();
		var types 			=	$('#main_type').val(); 
		var dataString		=	"mainid="+encodeURIComponent(id)+"&transaction="+encodeURIComponent(transaction);
						$.post('./ajax/delete_conversion.php', dataString, function(msg){
								var obj	= $.parseJSON(msg);
								if(obj.output==true){
									bootbox.alert("Successfully Deleted ..."); 
									window.setTimeout(function() { window.location.href = 'index.php?pg='+mods+'&type='+types; }, 1000);
								}else{
									bootbox.alert("Failed in Deleting ..."); 
									window.setTimeout(function() { window.location.href = 'index.php?pg='+mods+'&type='+types; }, 1000);
								}	
						});
}
 

function updateConversion(conversionValue,conversionType,reserveId){
 	var mods 			=	$('#main_page').val();
	var types 			=	$('#main_type').val(); 
	var dataString		=	"mainid="+encodeURIComponent(reserveId)+"&conversion_type="+encodeURIComponent(conversionType)+"&conversion_value="+encodeURIComponent(conversionValue);
						 
						$.post('./ajax/save_conversion.php', dataString, function(msg){
								var obj	= $.parseJSON(msg);
								 
								if(obj.output==true){
									bootbox.alert("Successfully Updated ..."); 
									//window.setTimeout(function() { window.location.href = 'index.php?pg='+mods+'&type='+types; }, 1000);
								}else{
									bootbox.alert("Failed in Deleting ..."); 
									//window.setTimeout(function() { window.location.href = 'index.php?pg='+mods+'&type='+types; }, 1000);
								}	
						});
} 

 


 var date = $('.datepicker2').datepicker({ dateFormat: 'mm/dd/yy' }).val();
