// JavaScript Document
$(document).ready(function(){ $("#rm").attr("disabled", false);
						   $("#h5").click(function(){
												   var cityid = document.getElementById("city_id").value;
												   var action = document.getElementById("action").value;
												   getvaluefrondb(this.value,cityid,action);
											       $("#rm").attr("disabled", false); 
												   });
						   
						    $("#h1").click(function(){
												   var cityid = document.getElementById("city_id").value;
												   var action = document.getElementById("action").value;
												   getvaluefrondb(this.value,cityid,action);
											    
												   $("#rm").attr("disabled", true); 
														 
												   });
							
							$("#h2").click(function(){
												   var cityid = document.getElementById("city_id").value;
												   var action = document.getElementById("action").value;
												   getvaluefrondb(this.value,cityid,action);
											       $("#rm").attr("disabled", false);
												   });
							
							$("#h3").click(function(){
												   var cityid = document.getElementById("city_id").value;
												   var action = document.getElementById("action").value;
												   getvaluefrondb(this.value,cityid,action);
											       $("#rm").attr("disabled", false);
												   });
							
							$("#h4").click(function(){
												   var cityid = document.getElementById("city_id").value;
												   var action = document.getElementById("action").value;
												   getvaluefrondb(this.value,cityid,action);
											       $("#rm").attr("disabled", false);
												   });
							
							
							
							//checking forromate plan
							$("#rm").click(function(){
													 if ($('#rm:checked').val() !== undefined)
													 {
												   var cityid = document.getElementById("city_id").value;
												   var action = document.getElementById("action").value;
                                                          if ( $("#h2").is(':checked') )
														  {
															  roommateplan($("#h2").val(),cityid,11 )
														  }
														  else if ( $("#h3").is(':checked') )
														  {
															  roommateplan($("#h3").val(),cityid,11 )
														  }
														  else if ( $("#h4").is(':checked') )
														  {
															  roommateplan($("#h4").val(),cityid,11 )
														  }
														  else if ( $("#h5").is(':checked') )
														  {
															  roommateplan($("#h5").val(),cityid,11 )
														  }
														
												    }
													 else
													    {
														  var cityid = document.getElementById("city_id").value;
												          var action = document.getElementById("action").value;
                                                          if ( $("#h2").is(':checked') )
														  {
															  roommateplan($("#h2").val(),cityid,12 )
														  }
														  else if ( $("#h3").is(':checked') )
														  {
															  roommateplan($("#h3").val(),cityid,12 )
														  }
														  else if ( $("#h4").is(':checked') )
														  {
															  roommateplan($("#h4").val(),cityid,12 )
														  }
														  else if ( $("#h5").is(':checked') )
														  {
															  roommateplan($("#h5").val(),cityid,12 )
														  }
															
														}
													});
							
							
							
							$("#u1").click(function(){
												   var cityid = document.getElementById("city_id").value;
												   var action = document.getElementById("action").value;
												   
                                                   //alert(cityid);
												    if ($('#u1:checked').val() !== undefined)
													 {
                                                          handlerformultiple(this.value,cityid,action);
													 }
													 else
													 minusamt(this.value,cityid,action);
												   });
							
							$("#u2").click(function(){
												   var cityid = document.getElementById("city_id").value;
												   var action = document.getElementById("action").value;
												   
                                                   //alert(cityid);
												   if ($('#u2:checked').val() !== undefined)
													 {
                                                          handlerformultiple(this.value,cityid,action);
													 }
													 else
													 minusamt(this.value,cityid,action);
												   });
							
							$("#u3").click(function(){
												   var cityid = document.getElementById("city_id").value;
												   var action = document.getElementById("action").value;
												   
                                                   //alert(cityid);
												    if ($('#u3:checked').val() !== undefined)
													 {
                                                          handlerformultiple(this.value,cityid,action);
													 }
													 else
													 minusamt(this.value,cityid,action);
												   });
							
							$("#u4").click(function(){
												   var cityid = document.getElementById("city_id").value;
												   var action = document.getElementById("action").value;
												   
                                                   //alert(cityid);
												  if ($('#u4:checked').val() !== undefined)
													 {
                                                          handlerformultiple(this.value,cityid,action);
													 }
													 else
													 minusamt(this.value,cityid,action);
												   });
							
							$("#u5").click(function(){
												   var cityid = document.getElementById("city_id").value;
												   var action = document.getElementById("action").value;
												   
                                                   //alert(cityid);
												   if ($('#u5:checked').val() !== undefined)
													 {
                                                          handlerformultiple(this.value,cityid,action);
													 }
													 else
													 minusamt(this.value,cityid,action);
												   });
							
							$("#u6").click(function(){
												   var cityid = document.getElementById("city_id").value;
												   var action = document.getElementById("action").value;
												   
													 if ($('#u6:checked').val() !== undefined)
													 {
                                                          handlerformultiple(this.value,cityid,action);
													 }
													 else
													 minusamt(this.value,cityid,action);
												   });
							
							 $("#f1").click(function(){
													 
												   var cityid = document.getElementById("city_id").value;
												   var action = document.getElementById("action").value;
												   
												    getvaluefrondb(this.value,cityid,action);
												   });
							
							
							 $("#f2").click(function(){
												   var cityid = document.getElementById("city_id").value;
												   var action = document.getElementById("action").value;
												   getvaluefrondb(this.value,cityid,action);
												   });
							 
							 
							  $("#f3").click(function(){
												   var cityid = document.getElementById("city_id").value;
												   var action = document.getElementById("action").value;
												   getvaluefrondb(this.value,cityid,action);
												   });
							  
							  
							   $("#f4").click(function(){
												   var cityid = document.getElementById("city_id").value;
												   var action = document.getElementById("action").value;
												   getvaluefrondb(this.value,cityid,action);
												   });
							   
							   
							    $("#f5").click(function(){
												   var cityid = document.getElementById("city_id").value;
												   var action = document.getElementById("action").value;
												   getvaluefrondb(this.value,cityid,action);
												   });
								
								
								$("#t1").click(function(){
														 var cityid = document.getElementById("city_id").value;
												         var action = document.getElementById("action").value;
												         getvaluefrondb(this.value,cityid,action);
														   
														   });
								
									$("#t2").click(function(){
														 var cityid = document.getElementById("city_id").value;
												         var action = document.getElementById("action").value;
												     getvaluefrondb(this.value,cityid,action);
														   
														   });
									
								   $("#t3").click(function(){
														 var cityid = document.getElementById("city_id").value;
												         var action = document.getElementById("action").value;
												     getvaluefrondb(this.value,cityid,action);
														   
														   });
								   
								   	$("#t4").click(function(){
														 var cityid = document.getElementById("city_id").value;
												         var action = document.getElementById("action").value;
												    getvaluefrondb(this.value,cityid,action);
														   
														   });
									
										$("#t5").click(function(){
														 var cityid = document.getElementById("city_id").value;
												         var action = document.getElementById("action").value;
												    getvaluefrondb(this.value,cityid,action);
														   
														   });
										
											$("#t6").click(function(){
														 var cityid = document.getElementById("city_id").value;
												         var action = document.getElementById("action").value;
												    getvaluefrondb(this.value,cityid,action);
														   
														   });
											
											$("#c1").click(function(){
														 var cityid = document.getElementById("city_id").value;
												         var action = document.getElementById("action").value;
												     if ($('#c1:checked').val() !== undefined)
													 {
                                                          handlerformultiple(this.value,cityid,action);
													 }
													 else
													 minusamt(this.value,cityid,action);
														   
														   });
											$("#c2").click(function(){
														 var cityid = document.getElementById("city_id").value;
												         var action = document.getElementById("action").value;
												     if ($('#c2:checked').val() !== undefined)
													 {
                                                          handlerformultiple(this.value,cityid,action);
													 }
													 else
													 minusamt(this.value,cityid,action);
														   
														   });
											
											$("#c3").click(function(){
														 var cityid = document.getElementById("city_id").value;
												         var action = document.getElementById("action").value;
												     if ($('#c3:checked').val() !== undefined)
													 {
                                                          handlerformultiple(this.value,cityid,action);
													 }
													 else
													 minusamt(this.value,cityid,action);
														   
														   });
											
											$("#c4").click(function(){
														 var cityid = document.getElementById("city_id").value;
												         var action = document.getElementById("action").value;
												     if ($('#c4:checked').val() !== undefined)
													 {
                                                          handlerformultiple(this.value,cityid,action);
													 }
													 else
													 minusamt(this.value,cityid,action);
														   
														   });
											
											$("#c5").click(function(){
														 var cityid = document.getElementById("city_id").value;
												         var action = document.getElementById("action").value;
												     if ($('#c5:checked').val() !== undefined)
													 {
                                                          handlerformultiple(this.value,cityid,action);
													 }
													 else
													 minusamt(this.value,cityid,action);
														   
														   });
											
											$("#c6").click(function(){
														 var cityid = document.getElementById("city_id").value;
												         var action = document.getElementById("action").value;
												     if ($('#c6:checked').val() !== undefined)
													 {
                                                          handlerformultiple(this.value,cityid,action);
													 }
													 else
													 minusamt(this.value,cityid,action);
														   
														   });
											
											$("#hc1").click(function(){
														 var cityid = document.getElementById("city_id").value;
												         var action = document.getElementById("action").value;
												     getvaluefrondb(this.value,cityid,action);
														   });
											
												$("#hc2").click(function(){
														 var cityid = document.getElementById("city_id").value;
												         var action = document.getElementById("action").value;
												     getvaluefrondb(this.value,cityid,action);
														   });
												
													$("#hc3").click(function(){
														 var cityid = document.getElementById("city_id").value;
												         var action = document.getElementById("action").value;
												    getvaluefrondb(this.value,cityid,action);
														   });
													
													$("#hc4").click(function(){
														 var cityid = document.getElementById("city_id").value;
												         var action = document.getElementById("action").value;
												    getvaluefrondb(this.value,cityid,action);
														   });
													
													$("#pc1").click(function(){
														 var cityid = document.getElementById("city_id").value;
												         var action = document.getElementById("action").value;
												     if ($('#pc1:checked').val() !== undefined)
													 {
                                                          handlerformultiple(this.value,cityid,action);
													 }
													 else
													 minusamt(this.value,cityid,action);
														   });
													
													$("#pc2").click(function(){
														 var cityid = document.getElementById("city_id").value;
												         var action = document.getElementById("action").value;
												     if ($('#pc2:checked').val() !== undefined)
													 {
                                                          handlerformultiple(this.value,cityid,action);
													 }
													 else
													 minusamt(this.value,cityid,action);
														   });
													
													$("#pc3").click(function(){
														 var cityid = document.getElementById("city_id").value;
												         var action = document.getElementById("action").value;
												     if ($('#pc3:checked').val() !== undefined)
													 {
                                                          handlerformultiple(this.value,cityid,action);
													 }
													 else
													 minusamt(this.value,cityid,action);
														   });
													
													$("#pc4").click(function(){
														 var cityid = document.getElementById("city_id").value;
												         var action = document.getElementById("action").value;
												     if ($('#pc4:checked').val() !== undefined)
													 {
                                                          handlerformultiple(this.value,cityid,action);
													 }
													 else
													 minusamt(this.value,cityid,action);
														   });
													
													
													$("#pc5").click(function(){
														 var cityid = document.getElementById("city_id").value;
												         var action = document.getElementById("action").value;
												     if ($('#pc5:checked').val() !== undefined)
													 {
                                                          handlerformultiple(this.value,cityid,action);
													 }
													 else
													 minusamt(this.value,cityid,action);
														   });
													
													$("#e1").click(function(){
														 var cityid = document.getElementById("city_id").value;
												         var action = document.getElementById("action").value;
												     if ($('#e1:checked').val() !== undefined)
													 {
                                                          handlerformultiple(this.value,cityid,action);
													 }
													 else
													 minusamt(this.value,cityid,action);
														   });
													
													$("#e2").click(function(){
														 var cityid = document.getElementById("city_id").value;
												         var action = document.getElementById("action").value;
												     if ($('#e2:checked').val() !== undefined)
													 {
                                                          handlerformultiple(this.value,cityid,action);
													 }
													 else
													 minusamt(this.value,cityid,action);
														   });
													
													$("#e3").click(function(){
														 var cityid = document.getElementById("city_id").value;
												         var action = document.getElementById("action").value;
												     if ($('#e3:checked').val() !== undefined)
													 {
                                                          handlerformultiple(this.value,cityid,action);
													 }
													 else
													 minusamt(this.value,cityid,action);
														   });
													
													$("#e4").click(function(){
														 var cityid = document.getElementById("city_id").value;
												         var action = document.getElementById("action").value;
												     if ($('#e4:checked').val() !== undefined)
													 {
                                                          handlerformultiple(this.value,cityid,action);
													 }
													 else
													 minusamt(this.value,cityid,action);
														   });
													
													$("#e5").click(function(){
														 var cityid = document.getElementById("city_id").value;
												         var action = document.getElementById("action").value;
												     if ($('#e5:checked').val() !== undefined)
													 {
                                                          handlerformultiple(this.value,cityid,action);
													 }
													 else
													 minusamt(this.value,cityid,action);
														   });
													
													$("#m1").click(function(){
														 var cityid = document.getElementById("city_id").value;
												         var action = document.getElementById("action").value;
												     if ($('#m1:checked').val() !== undefined)
													 {
                                                          handlerformultiple(this.value,cityid,action);
													 }
													 else
													 minusamt(this.value,cityid,action);
														   });
													
													$("#m2").click(function(){
														 var cityid = document.getElementById("city_id").value;
												         var action = document.getElementById("action").value;
												     if ($('#m2:checked').val() !== undefined)
													 {
                                                          handlerformultiple(this.value,cityid,action);
													 }
													 else
													 minusamt(this.value,cityid,action);
														   });
													
													$("#m3").click(function(){
														 var cityid = document.getElementById("city_id").value;
												         var action = document.getElementById("action").value;
												     if ($('#m3:checked').val() !== undefined)
													 {
                                                          handlerformultiple(this.value,cityid,action);
													 }
													 else
													 minusamt(this.value,cityid,action);
														   });
													
													$("#m4").click(function(){
														 var cityid = document.getElementById("city_id").value;
												         var action = document.getElementById("action").value;
												     if ($('#m4:checked').val() !== undefined)
													 {
                                                          handlerformultiple(this.value,cityid,action);
													 }
													 else
													 minusamt(this.value,cityid,action);
														   });
													
													$("#m5").click(function(){
														 var cityid = document.getElementById("city_id").value;
												         var action = document.getElementById("action").value;
												     if ($('#m5:checked').val() !== undefined)
													 {
                                                          handlerformultiple(this.value,cityid,action);
													 }
													 else
													 minusamt(this.value,cityid,action);
														   });
													
													
												   $("#s1").click(function(){
												   var cityid = document.getElementById("city_id").value;
												   var action = document.getElementById("action").value;
												   getvaluefromdbsave(this.value,cityid,action);
												   });
												   
												   $("#s2").click(function(){
												   var cityid = document.getElementById("city_id").value;
												   var action = document.getElementById("action").value;
												   getvaluefromdbsave(this.value,cityid,action);
												   });
												   
												   $("#s3").click(function(){
												   var cityid = document.getElementById("city_id").value;
												   var action = document.getElementById("action").value;
												   getvaluefromdbsave(this.value,cityid,action);
												   });
												   
												   $("#s4").click(function(){
												   var cityid = document.getElementById("city_id").value;
												   var action = document.getElementById("action").value;
												   getvaluefromdbsave(this.value,cityid,action);
												   });
												   
												   $("#D1").click(function(){
																	
												   var last_clicked=$("#current_clicked").val();					
												   var current_clicked=this.value;
												   $("#current_clicked").val(current_clicked);						   
												   var dc=getCheckedValue(document.forms['load_debt'].elements['dc']);
												   var old_key = document.getElementById("old_key").value;
												   var current_key=this.value;
												   var o_div=current_key.split("D");
												   var opacity_div=o_div[1];
												   
												       if(old_key!=current_key)
													   {
														   if(dc)
														   {
																getdebt(current_key,dc);
														   }
														   if(last_clicked==current_clicked)
														   {
															   $('#'+current_key+'').attr('checked', false);
															   $("label[for='D"+opacity_div+"']").attr("class","");
															   $("#old_key").val('');
															   $("#div"+opacity_div+"").css('opacity','1');
															   $(".cover"+opacity_div+"", ".boxgrid.slidedown").stop().animate({top:'0px'},{queue:false,duration:300});
															   $("#current_clicked").val('');
														   }
													   }
													   else
													   {
														   deductloanamount(current_key,30,dc);  
									 					   $('#'+current_key+'').attr('checked', false);
														   $("label[for='D"+opacity_div+"']").attr("class","");
														   $("#old_key").val('');
														   $("#div"+opacity_div+"").css('opacity','1');
														   $(".cover"+opacity_div+"", ".boxgrid.slidedown").stop().animate({top:'0px'},{queue:false,duration:300});
														   $("#current_clicked").val('');
													   }
													   
												   });
							
												   $("#D2").click(function(){
																		   
												   var last_clicked=$("#current_clicked").val();					
												   var current_clicked=this.value;
												   $("#current_clicked").val(current_clicked);						   
												   var dc=getCheckedValue(document.forms['load_debt'].elements['dc']);
												   var old_key = document.getElementById("old_key").value;
												   var current_key=this.value;
												   var o_div=current_key.split("D");
												   var opacity_div=o_div[1];
												   
												       if(old_key!=current_key)
													   {
														   if(dc)
														   {
																getdebt(current_key,dc);
														   }
														   if(last_clicked==current_clicked)
														   {
																$('#'+current_key+'').attr('checked', false);
																$("label[for='D"+opacity_div+"']").attr("class","");
																$("#old_key").val('');
																$("#div"+opacity_div+"").css('opacity','1');
																$(".cover"+opacity_div+"",".boxgrid.slidedown").stop().animate({top:'0px'},{queue:false,duration:300});
																$("#current_clicked").val('');
														   }
													   }
													   else
													   {
														   deductloanamount(current_key,30,dc);  
									 					   $('#'+current_key+'').attr('checked', false);
														   $("label[for='D"+opacity_div+"']").attr("class","");
														   $("#old_key").val('');
														   $("#div"+opacity_div+"").css('opacity','1');
														   $(".cover"+opacity_div+"", ".boxgrid.slidedown").stop().animate({top:'0px'},{queue:false,duration:300});
														   $("#current_clicked").val('');
													   }
													   
												   });
							
												   $("#D3").click(function(){
																		   
												   var last_clicked=$("#current_clicked").val();					
												   var current_clicked=this.value;
												   $("#current_clicked").val(current_clicked);	 					   
												   var dc=getCheckedValue(document.forms['load_debt'].elements['dc']);
												   var old_key = document.getElementById("old_key").value;
												   var current_key=this.value;
												   var o_div=current_key.split("D");
												   var opacity_div=o_div[1];
												   
												       if(old_key!=current_key)
													   {
														   if(dc)
														   {
																getdebt(current_key,dc);
														   }
														   if(last_clicked==current_clicked)
														   {
																$('#'+current_key+'').attr('checked', false);
																$("label[for='D"+opacity_div+"']").attr("class","");
																$("#old_key").val('');
																$("#div"+opacity_div+"").css('opacity','1');
																$(".cover"+opacity_div+"",".boxgrid.slidedown").stop().animate({top:'0px'},{queue:false,duration:300});
																$("#current_clicked").val('');
														   }
													   }
													   else
													   {
														   deductloanamount(current_key,30,dc);  
									 					   $('#'+current_key+'').attr('checked', false);
														   $("label[for='D"+opacity_div+"']").attr("class","");
														   $("#old_key").val('');
														   $("#div"+opacity_div+"").css('opacity','1');
														   $("#current_clicked").val('');
														   $(".cover"+opacity_div+"", ".boxgrid.slidedown").stop().animate({top:'0px'},{queue:false,duration:300});
													   }
												   });
							
												   $("#D4").click(function(){
																		   
												   var last_clicked=$("#current_clicked").val();					
												   var current_clicked=this.value;
												   $("#current_clicked").val(current_clicked);							   
												   var dc=getCheckedValue(document.forms['load_debt'].elements['dc']);
												   var old_key = document.getElementById("old_key").value;
												   var current_key=this.value;
												   var o_div=current_key.split("D");
												   var opacity_div=o_div[1];
												   
												       if(old_key!=current_key)
													   {
														   if(dc)
														   {
																getdebt(current_key,dc);
														   }
														   if(last_clicked==current_clicked)
														   {
																$('#'+current_key+'').attr('checked', false);
																$("label[for='D"+opacity_div+"']").attr("class","");
																$("#old_key").val('');
																$("#div"+opacity_div+"").css('opacity','1');
																$(".cover"+opacity_div+"",".boxgrid.slidedown").stop().animate({top:'0px'},{queue:false,duration:300});
																$("#current_clicked").val('');
														   }
													   }
													   else
													   {
														   deductloanamount(current_key,30,dc);  
									 					   $('#'+current_key+'').attr('checked', false);
														   $("label[for='D"+opacity_div+"']").attr("class","");
														   $("#old_key").val('');
														   $("#div"+opacity_div+"").css('opacity','1');
														   $(".cover"+opacity_div+"", ".boxgrid.slidedown").stop().animate({top:'0px'},{queue:false,duration:300});
														   $("#current_clicked").val('');
													   }
												   });
												   
   												   $("#D5").click(function(){
																		   
												   var last_clicked=$("#current_clicked").val();					
												   var current_clicked=this.value;
												   $("#current_clicked").val(current_clicked);								   
												   var dc=getCheckedValue(document.forms['load_debt'].elements['dc']);
												   var old_key = document.getElementById("old_key").value;
												   var current_key=this.value;
												   var o_div=current_key.split("D");
												   var opacity_div=o_div[1];
												   
												       if(old_key!=current_key)
													   {
														   if(dc)
														   {
																getdebt(current_key,dc);
														   }
														   if(last_clicked==current_clicked)
														   {
																$('#'+current_key+'').attr('checked', false);
																$("label[for='D"+opacity_div+"']").attr("class","");
																$("#old_key").val('');
																$("#div"+opacity_div+"").css('opacity','1');
																$(".cover"+opacity_div+"",".boxgrid.slidedown").stop().animate({top:'0px'},{queue:false,duration:300});
																$("#current_clicked").val('');
														   }
													   }
													   else
													   {
														   deductloanamount(current_key,30,dc);  
									 					   $('#'+current_key+'').attr('checked', false);
														   $("label[for='D"+opacity_div+"']").attr("class","");
														   $("#old_key").val('');
														   $("#div"+opacity_div+"").css('opacity','1');
														   $(".cover"+opacity_div+"", ".boxgrid.slidedown").stop().animate({top:'0px'},{queue:false,duration:300});
														   $("#current_clicked").val('');
													   }
												   });
												   
												   $("#DC1").click(function(){
						 							var deg=getCheckedValue(document.forms['load_debt'].elements['debt']);
													var old_key = document.getElementById("old_key1").value;
												    var current_key=this.value;
												    var o_div=current_key.split("DC");
												    var opacity_div=o_div[1];
												   
												       if(current_key!=old_key)
													   {
														   if(deg)
														   {
																getdebt(deg,current_key);
														   }
													   }
													   else
													   {
														 deductloanamount(deg,30,current_key);
														 $("#"+current_key+"").attr('checked', false);
					   									 $(".institution-text").css('display','none');
														 $("#old_key").val('');
														 $("#old_key1").val('');
													   }	
													
													});
												   
												   $("#DC2").click(function(){
						 
													var deg=getCheckedValue(document.forms['load_debt'].elements['debt']);
													var old_key = document.getElementById("old_key1").value;
												    var current_key=this.value;
												    var o_div=current_key.split("DC");
												    var opacity_div=o_div[1];
												   
												       if(current_key!=old_key)
													   {
														   if(deg)
														   {
																getdebt(deg,current_key);
														   }
													   }
													   else
													   {
														 deductloanamount(deg,30,current_key);
														 $("#"+current_key+"").attr('checked', false);
					   									 $(".institution-text").css('display','none');
														 $("#old_key").val('');
														 $("#old_key1").val('');
													   }	
													
													});
												   
												   $("#DC3").click(function(){
						 
													var deg=getCheckedValue(document.forms['load_debt'].elements['debt']);
													var old_key = document.getElementById("old_key1").value;
												    var current_key=this.value;
												    var o_div=current_key.split("DC");
												    var opacity_div=o_div[1];
												   
												       if(current_key!=old_key)
													   {
														   if(deg)
														   {
																getdebt(deg,current_key);
														   }
													   }
													   else
													   {
														 deductloanamount(deg,30,current_key);
														 $("#"+current_key+"").attr('checked', false);
					   									 $(".institution-text").css('display','none');
														 $("#old_key").val('');
														 $("#old_key1").val('');
													   }	
													
													});

												   
							
						   });

//function area

function getdebt(key,dc)
{
	var div=key.split("D");
    var text_div=div[1];
	$.ajax({
		   type: "POST",
		   url : "businesslayer.php?action=28&expensekey="+key+"&dc="+dc,
		   data: key,
		   success: function(msg){
			   var msgarr = msg.split('@');
			       if(msgarr[0]=="success")
				   {
					   var expense=parseFloat(msgarr[1]);
					   var runbal=parseFloat(msgarr[2]);
					   $("#expense").val(addCommas(expense.toFixed(2)));
					   $("#runbal").val(addCommas(runbal.toFixed(2)));
					   $("#old_key").val(key);
					   $("#old_key1").val(dc);
					   change_content(expense,text_div);
				   }
			   }
		   });	
}

function deductloanamount(key,action,dc)
{
	$.ajax({
		   type: "POST",
		   url : "businesslayer.php?action="+action+"&key="+key+"&dc="+dc,
		   data: key,
		   success: function(msg){
			   var msgarr = msg.split('@');
			       if(msgarr[0]=="success")
				   {
					   var expense=parseFloat(msgarr[1]);
					   var runbal=parseFloat(msgarr[2]);
					   $("#expense").val(addCommas(expense.toFixed(2)));
					   $("#runbal").val(addCommas(runbal.toFixed(2)));
				   }
			   }
		   });	
	
}



function getvaluefrondb(key,cityid,action)
{
	$.ajax({
		   type: "POST",
		   url : "businesslayer.php?expensekey="+key+"&cityid="+cityid+"&action="+action,
		   data: key,
		   success: function(msg){
			   var msgarr = msg.split('@');
			       if(msgarr[0]=="success")
				   {
					   var expense=parseFloat(msgarr[1]);
					   var runbal=parseFloat(msgarr[2]);
					   $("#expense").val(addCommas(expense.toFixed(2)));
					   $("#runbal").val(addCommas(runbal.toFixed(2)));
				   }
			   }
		   });
}

function handlerformultiple(key,cityid,action)
{
	$.ajax({
		   type: "POST",
		   url : "businesslayer.php?expensekey="+key+"&cityid="+cityid+"&action="+action,
		   data: key,
		   success: function(msg){
			   var msgarr = msg.split('-');
			       if(msgarr[0]=="success")
				   {
						   var pexpamt = parseFloat(filter_value($("#expense").val()));
						   
						   var newexpamt = pexpamt + parseFloat(msgarr[1]);
						   $("#expense").val(addCommas(newexpamt.toFixed(2)));
						   
						   var prunbal = parseFloat(filter_value($("#runbal").val()));
						   
						   var newrunbal = prunbal + parseFloat(msgarr[1]);
						   $("#runbal").val(addCommas(newrunbal.toFixed(2)));   
				   }
			   }
		   });
}


function minusamt(key,cityid,action)
{
	$.ajax({
		   type: "POST",
		   url : "businesslayer.php?expensekey="+key+"&cityid="+cityid+"&action="+action,
		   data: key,
		   success: function(msg){
			   var msgarr = msg.split('-');
			       if(msgarr[0]=="success")
				   {
						   var pexpamt = parseFloat(filter_value($("#expense").val()));
						   var newexpamt = (pexpamt - parseFloat(msgarr[1]) >= 0 ? pexpamt - parseFloat(msgarr[1]) : pexpamt);
						  $("#expense").val(addCommas(newexpamt.toFixed(2)));  
						   var prunbal = parseFloat(filter_value($("#runbal").val()));
						   var newrunbal = prunbal - parseFloat(msgarr[1]);
						  $("#runbal").val(addCommas(newrunbal.toFixed(2)));
					  
				   }
			   }
		   });
}
function getvaluefromdbsave(key,cityid,action)
{
	$.ajax({
		   type: "POST",
		   url : "businesslayer.php?expensekey="+key+"&cityid="+cityid+"&action="+action,
		   data: key,
		   success: function(msg){
			   var msgarr = msg.split('@');
			       if(msgarr[0]=="success")
				   {
					   var expense=parseFloat(msgarr[1]);
					   var runbal=parseFloat(msgarr[2]);
					   $("#expense").val(addCommas(parseFloat(expense.toFixed(2))));
					   $("#runbal").val(addCommas(parseFloat(runbal.toFixed(2))));
				   }
			   }
		   });
}

function roommateplan(key,cityid,action)
{
	$.ajax({
		   type: "POST",
		   url : "businesslayer.php?expensekey="+key+"&cityid="+cityid+"&action="+action,
		   data: key,
		   success: function(msg){
			   var msgarr = msg.split('-');
			       if(msgarr[0]=="success")
				   {
                       var expense=parseFloat(msgarr[1]);
					   var runbal=parseFloat(msgarr[2]);
					   $("#expense").val(addCommas(parseFloat(expense.toFixed(2))));
					   $("#runbal").val(addCommas(parseFloat(runbal.toFixed(2))));
				   }
			   }
		   });
}

function trim(s)
{
	var l=0; var r=s.length -1;
	while(l < s.length && s[l] == ' ')
	{	l++; }
	while(r > l && s[r] == ' ')
	{	r-=1;	}
	return s.substring(l, r+1);
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function filter_value(value) {
    var filter=parseInt(value.toString().replace(/[^0-9.]+/g,''));
	return filter;
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
