$(document).ready(function() {


		
		/*$('body').on("blur", "#msview tbody textarea.det", function(e){
			
	var tempRow =$(this).closest('tr');
      var ratio_val = $.trim($(this).val());
            var res_srt = ratio_val.split(",");
			var total = 0;
			
			for (var i = 0; i < $.trim(Number(res_srt)); i++) {
			total+=res_srt[i];
			console.log(total);
			}
			tempRow.find("#msview tbody textarea.det1").val(total);
    });*/
	
	$('body').on("blur", "#msview tbody textarea.det", function(e){
		var row= $(this).closest('tr');
			if(row.find('.mstype').val()=='SSC'){
	
      var ratio_val = $.trim($(this).val());
            var res_srt = ratio_val.split(",");
			var total = 0;
			
			  $.each(res_srt, function( index, value ) {
			  total = Number(total)+Number(value);
			  row.find(".det1").val( total );
			  });
			}
			
    });
	
	/*$('body').on("blur", "#msview tbody textarea",function(){
	
	var row= $(this).closest('tr');
	
	var qtyval =row.find('.qty').val(); 
	var rateval =row.find('.psrate').val(); 
	var amountval = 0; 
	
	amountval = qtyval*rateval;
	row.find(".pamount").val( amountval );
	});*/
	$('body').on('click','#fltselect',function(){
	if($(this).val()=='clt'){ // Product name
		$('#empinfoval').hide();
		$('#rowval').hide();
		$('#prodgencode').show();
		$('#ledval').hide();
		}
		else if($(this).val()=='empinfo'){
			$('#empinfoval').show();
			$('#rowval').hide();
			$('#prodgencode').hide();
			$('#ledval').hide();
			}
			else if($(this).val()=='Row'){
			$('#empinfoval').hide();
			$('#rowval').show();
			$('#prodgencode').hide();
			$('#ledval').hide();
			}
			else if($(this).val()=='led'){
			$('#empinfoval').hide();
			$('#rowval').hide();
			$('#prodgencode').hide();
			$('#ledval').show();
			}
	
	});

	var totlinks;
	var row_u;
	var curr_u;
	var undo_u;
	$('#mastertype input.button').click(function(){
		$('#mastertype input:button').css({'font-size':'100%'});
		$(this).css({'font-size':'138%'});
	$('#message').hide();
	
ms_type=this.id;
var ms_value =   $('#mstvalue').val();
var ms_cmptype =   $('#cmptype').val();
var search_compid =   $('#search_compid').val();
var prodgencode = $('#prodgencode').val();
var fltselect = $('#fltselect').val();
var empinfoval = $('#empinfoval').val();
var rowval = $('#rowval').val();
var ledval = $('#ledval').val();

if(ms_type!='search')
{
	fltselect ='';
	}
  $('#transperent').show();
$.post("getmaster.php",{ms_type:ms_type,compid:$('#mstvalue').val(),ms_value:ms_value,ms_cmptype:ms_cmptype,search_com:search_compid,prodgencode:prodgencode,fltselect:fltselect,empinfoval:empinfoval,rowval:rowval,ledval:ledval},function(result){
	var str=result.split('###');
	$('#masres').html(str[0]);
	//jSuccess(str[1]);
	//$('#message_disp').html(str[0]);
	if($.trim(str[1])!=''&&Number(str[1])!=0&&Number(str[1])>100)
	{
		totlinks=Math.ceil(parseFloat(str[1]/300))
		var links="<div class='div_links' style='float:right;margin-top: 10px;'>Page:";
		for(var i=0;i<totlinks;i++)
		{
			links=links+"<span class='links'><a style='color:#000' onclick='pagig(this.id)' href='#' id="+(i*300)+">"+(i+1)+"</a></span>";
			}
			links=links+""
			
			$('#masres').append(links);
		}
	
	links=links+"</div>";
if(ms_type=='ratemst')
{
	
	$('#masres').append("<div style='background:#fff;height:50px;width:600px;-webkit-border-radius: 5px;-moz-border-radius: 5px;left: 250px;display:none;position: absolute;' id='div_copyrate'><table width='100%' height='100%' cellspacing='0' cellpadding='5' sytle='-webkit-border-radius: 5px;-moz-border-radius: 5px;' ><tr><td align='center' style='border-color:transparent'> City: <input type='radio' name='rate_type' id='rate_type_city' checked='checked' value='rate_type_city'/></td>         <td style='border-color:transparent' align='center'>Comp ID:          <input type='radio' name='rate_type'  value='rate_type_compid' id='rate_type_compid'/></td>         <td style='border-color:transparent' align='center'>CompID(from): <input name='rate_citycompidfrom' class='rate_city' type='text'  id='rate_citycompidfrom' size='15'  /></td>         <td style='border-color:transparent' align='center'>&nbsp;</td> </tr> <tr>           <td style='border-color:transparent' align='center'>From             <input name='rate_cityfrom' type='text' class='rate_city'  id='rate_cityfrom' size='15'  />             <input name='rate_compidfrom' type='text' class='rate_compid'  id='rate_compidfrom' size='15' style='display:none'  />            </td>           <td style='border-color:transparent' align='center'>To:             <input name='rate_cityto' class='rate_city' type='text'  id='rate_cityto' size='15'  /> <input name='rate_compidto' type='text' class='rate_compid'  id='rate_compidto' size='15' style='display:none'  /></td>           <td style='border-color:transparent' align='center'>CompID(to):<input name='rate_citycompidto' class='rate_city' type='text'  id='rate_citycompidto' size='15'  /></td>        <td style='border-color:transparent' align='center'><input type='button' class='button' id='rate_submit' value='Submit' /></td></tr></table></div><div><input name='copyrate' type='button' class='bill' id='copyrate' style=' width:auto; position:absolute' value='Copy Rate' /></div>");
	copy_rate();
	}
$(".procat").autocomplete(
      "cat_by_fill.php?",
      {
  			delay:10,
  			minChars:1,
			mustMatch:1,
  			matchSubset:1,
  			matchContains:1,
  			cacheLength:10,
  			autoFill:false
  		}
    );
	
	
	
	
$("#msview").createScrollableTable({
	            width: '100%',
	            height: '450'
	        });
			
			var options = {
				clearFiltersControls: [$('input:button')],
				enableCookies :false ,
				 filteredRows: function(filterStates) {
            //console.log(filterStates);
			$('#msview .new_entry').show();// to show the last row
        }            
			};
				$('#msview').tableFilter(options);	
				$('#msview thead tr:eq(0)').hide();
				$('#msview thead tr:eq(1) td:eq(0)').hide();
			//	$('#msview thead tr:eq(1) td:eq(1) input:text').hide();
				$('#msview thead tr:eq(1) td:last input:text').hide();
				inline_edit();
				getmaster_rel(ms_type);
						if(ms_type=='cmpmst'||ms_type=='ratemst'||ms_type=='led'||ms_type=='usr'||ms_type=='empinfo')
						// $("#msview tbody tr:last td:eq(0) textarea").focus().trigger('click');
						 $("#msview tbody tr:last td:eq(0) textarea").focus();
                      else if(ms_type=='clt')
						// $("#msview tbody tr:last td:eq(0) textarea").focus().trigger('click');
						 $("#msview tbody tr td:eq(0) textarea").focus();
						else
					 //$("#msview tbody tr:last td:eq(2) textarea").focus().trigger('click');
					 $("#msview tbody tr:last td:eq(2) textarea").focus();
	  $('#transperent').hide();		
			
});//post ends

});


$.post("masterval_fill.php",{},function(result){
				 			if(result == null)
							{
								$('#mstvalue:last').html("")
								return;
							}
							var html = "<option selected value=''>--select--</option>";
							$.each(result.list, function(key,value) {
							
								html += "<option  value='"+value.mstype+"'>"+value.code+"</option>";
								
							});
							console.log(html);
							$('#mstvalue:last').html("").append(html);

 },'json');//post ends





});


function pagig(curr_id){
	$('.links a').css('color','#000');
	$('#'+curr_id).css('color','red');
	var links=$('.div_links').clone();
	  $('#transperent').show();	
	$.post("getmaster.php",{ms_type:'ratemstpage',getpage:curr_id,compid:$('#search_compid').val()},function(result){

$('#masres').html(result);
$('#masres').append(links);	
//if(ms_type=='ratemst')
//{
	
	$('#masres').append("<div style='background:#fff;height:50px;width:600px;-webkit-border-radius: 5px;-moz-border-radius: 5px;left: 250px;display:none;position: absolute;' id='div_copyrate'><table width='100%' height='100%' cellspacing='0' cellpadding='5' sytle='-webkit-border-radius: 5px;-moz-border-radius: 5px;' ><tr><td align='center' style='border-color:transparent'> City: <input type='radio' name='rate_type' id='rate_type_city' checked='checked' value='rate_type_city'/></td>         <td style='border-color:transparent' align='center'>Comp ID:          <input type='radio' name='rate_type'  value='rate_type_compid' id='rate_type_compid'/></td>         <td style='border-color:transparent' align='center'>CompID(from): <input name='rate_citycompidfrom' class='rate_city' type='text'  id='rate_citycompidfrom' size='15'  /></td>         <td style='border-color:transparent' align='center'>&nbsp;</td> </tr> <tr>           <td style='border-color:transparent' align='center'>From             <input name='rate_cityfrom' type='text' class='rate_city'  id='rate_cityfrom' size='15'  />             <input name='rate_compidfrom' type='text' class='rate_compid'  id='rate_compidfrom' size='15' style='display:none'  />            </td>           <td style='border-color:transparent' align='center'>To:             <input name='rate_cityto' class='rate_city' type='text'  id='rate_cityto' size='15'  /> <input name='rate_compidto' type='text' class='rate_compid'  id='rate_compidto' size='15' style='display:none'  /></td>           <td style='border-color:transparent' align='center'>CompID(to):<input name='rate_citycompidto' class='rate_city' type='text'  id='rate_citycompidto' size='15'  /></td>        <td style='border-color:transparent' align='center'><input type='button' class='button' id='rate_submit' value='Submit' /></td></tr></table></div><div><input name='copyrate' type='button' class='bill' id='copyrate' style=' width:auto; position:absolute' value='Copy Rate' /></div>");
	copy_rate();
	//}
$("#msview").createScrollableTable({
	            width: '1040',
	            height: '450'
	        });
			
			var options = {
				clearFiltersControls: [$('input:button')],
				enableCookies :false ,
				 filteredRows: function(filterStates) {
            //console.log(filterStates);
			$('#msview .new_entry').show();
        }            
			};
				$('#msview').tableFilter(options);	
				$('#msview thead tr:eq(0)').hide();
				$('#msview thead tr:eq(1) td:eq(0)').hide();
			//	$('#msview thead tr:eq(1) td:eq(1) input:text').hide();
				$('#msview thead tr:eq(1) td:last input:text').hide();
				inline_edit();
				getmaster_rel(ms_type);
						if(ms_type=='cmpmst'||ms_type=='ratemst'||ms_type=='led'||ms_type=='usr')
						// $("#msview tbody tr:last td:eq(0) textarea").focus().trigger('click');
						 $("#msview tbody tr:last td:eq(0) textarea").focus();


						else
					// $("#msview tbody tr:last td:eq(2) textarea").focus().trigger('click');
					 	 $("#msview tbody tr:last td:eq(2) textarea").focus();
			 jNotify("Please Save the changes made OR press ESC to UNDO");
	  $('#transperent').hide();		
			
});//post ends
	}

function copy_rate(){
	//copy rate
  $("#copyrate").click(function(){
	  
    $("#div_copyrate").animate({
      width:'toggle'
    },"slow");
	//$("#div_copyrate").slideToggle();
	$(".rate_city:first").focus();
  });
  
    $("#rate_type_compid").click(function(){
		$(".rate_compid").show();
		$(".rate_compid:first").focus();
		$(".rate_city").hide();
	});
	
	$("#rate_type_city").click(function(){
		$(".rate_compid").hide();
		$(".rate_city").show();
		$(".rate_city:first").focus();
	});
	
	$("#rate_submit").click(function(){
		 $('#transperent').show();	
		 //jSuccess($('#div_copyrate input:text,#div_copyrate input:radio').serialize());
		$.post("copy_ratemaster.php",$('#div_copyrate input:text,#div_copyrate input:radio').serialize(),function(result){
			jSuccess(result);
			 $('#transperent').hide();	
		});
	});
	
	$("#rate_cityfrom,#rate_cityto").autocomplete(
      "city.php?",
      {
  			delay:10,
  			minChars:1,
			mustMatch:1,
  			matchSubset:1,
  			matchContains:1,
  			cacheLength:10,
  			autoFill:false
  		}
    );


    


	
	$("#rate_citycompidto,#rate_citycompidfrom,#rate_compidto,#rate_compidfrom").autocomplete(
      "billedto.php?",
      {
  			delay:10,
  			minChars:1,
			mustMatch:1,
  			matchSubset:1,
  			matchContains:1,
  			cacheLength:10,
  			autoFill:false
  		}
    );
	}



function inline_edit()
{
	
	var tableid='#msview ';
	$(tableid+'tbody textarea,'+tableid+' tbody .pwd').click(function(event){
		if($('#inline_edit').val()==0){
			
			
		$(tableid+' tbody tr input:button').hide();
		
		var row= $(this).closest('tr');
		row_u= $(this).closest('tr');	
		curr_u=$(this);
  		undo_u=  $(row_u).clone(true);
		
		row.find('input:button').show();
			
		}
		else	
		$('#message').html("Please Save the changes made OR press ESC to UNDO").show();
	});
	
		$(tableid+' tbody textarea,'+tableid+' tbody .pwd').keyup(function(event){
			if((event.keyCode==67 && event.ctrlKey)||event.ctrlKey||event.keyCode==9)
		 	return;
			if(event.keyCode==222){
			//event.preventdefault();
			  $(this).val($(this).val().substring(0,($(this).val().length-1))+"`");
			  }
			  if($('#inline_edit').val()==0){
			var row= $(this).closest('tr');
			$(tableid+' tbody tr  textarea').attr('readonly','readonly');
			row.find('textarea').removeAttr('readonly');
			row.find('textarea').css('background-color','#E0B99F');
			row.find('input:button').show();
			$('#inline_edit').val('1');
			  }
		});
	}



function getmaster_rel(type)
{
$('input:text:not(.nocaps),textarea:not(.nocaps)').autoCap();

//for focusing on next field by pressing enter		
var n=0;  
$select=null;
    
$('input:text,textarea,select,input:button,.pwd').keydown(function(e)
    {
		$select=$('input:text,textarea,select,input:button,.pwd');
		  n = $select.length;
	
	if (e.which == 13) 
   { 
	//Enter key
     e.preventDefault(); //to skip default behavior of the enter key
     var nextIndex = $select.index(this)+1;
     if(nextIndex < n)
       $select[nextIndex].focus();
     else
     {
       $select[nextIndex-1].blur();
     }
  
		
     e.preventDefault(); //to skip default behavior of the enter key
     var nextIndex = $select.index(this)+1;
     if(nextIndex < n)
       $select[nextIndex].focus();
     else
     {
       $select[nextIndex-1].blur();
     }
 }
});

$('input:button').keydown(function(e){
	if(e.which==13)
	$(this).trigger('click');
	});


$('body').keydown(function(e){
	if(e.keyCode==27)
	{
		
	 $('#inline_edit').val('0');
	 curr_id=$('#msview').attr('class');
	 row_u.replaceWith(undo_u);
	 undo_u.find('textarea').css('background-color','transparent');
	 undo_u.find('input:button').hide();

			$('#msview tbody textarea').removeAttr('readonly');
				$('#msview').tableFilterRefresh();	
				$('#msview thead tr:eq(0)').hide();
				$('#msview thead tr:eq(1) td:eq(0)').hide();
				$('#msview thead tr:eq(1) td:last input:text').hide();

	$('#message').hide();
	
	 
	 
	}
	
	
	
	
});



$('#msview tbody  #master_edit').click(function(){
	$('#inline_edit').val('0');
		$('#message').hide();
		 $("#msview tbody tr textarea").css("background-color","");
			$('#msview tbody textarea').removeAttr('readonly');
var row= $(this).parents('tr');	

row.find('input:button').hide();
  $('#transperent').show();
 $.post("master_crud.php?mode=update",row.find('textarea').serialize(),function(html){
	// var str=html.split('###');
	 
	  jSuccess(html);
	  $('#transperent').hide();
  });
});

$('#msview tbody  #master_new').click(function(){
	$('#inline_edit').val('0');
	$('#message').hide();
	
			 $("#msview tbody tr textarea").css("background-color","");
	$('#msview tbody textarea').removeAttr('readonly');
	
	var row= $(this).parents('tr');	
	row.find('input:button').hide();
	  $('#transperent').show();
	 $.post("master_crud.php?mode=insert",row.find('textarea').serialize(),function(html){
	
	
	$('#mst').trigger('click');
	

	 jSuccess(html);
		
	   $('#transperent').hide();
	 
  });
	
});	

$('#msview tbody  #prod_new').click(function(){
	$('#inline_edit').val('0');
	$('#message').hide();
	
			 $("#msview tbody tr textarea").css("background-color","");
	$('#msview tbody textarea').removeAttr('readonly');
	
	var row= $(this).parents('tr');	
	row.find('input:button').hide();
	  $('#transperent').show();
	 $.post("master_product_crud.php?mode=insert",row.find('textarea').serialize(),function(html){
	$temp=$('#msview').attr('class');
	$('#clt').trigger('click');
	jSuccess(html);
		
	   $('#transperent').hide();
	 
  });
	
});

$('#msview tbody  .prod_edit').click(function(){
	$('#inline_edit').val('0');
		$('#message').hide();
		 $("#msview tbody tr textarea").css("background-color","");
			$('#msview tbody textarea').removeAttr('readonly');
var row= $(this).parents('tr');	

row.find('input:button').hide();
  $('#transperent').show();
 $.post("master_product_crud.php?mode=update",row.find('textarea').serialize(),function(html){
	// var str=html.split('###');	   
	  jSuccess(html);  
	  $('#transperent').hide();
  });
});



$('#msview tbody  #rawmat_new').click(function(){
	$('#inline_edit').val('0');
	$('#message').hide();
	
	$("#msview tbody tr textarea").css("background-color","");
	$('#msview tbody textarea').removeAttr('readonly');
	
	var row= $(this).parents('tr');	
	row.find('input:button').hide();
	$('#transperent').show();
	 $.post("master_crud.php?mode=rowinsert",row.find('textarea').serialize(),function(html){
	//jSuccess(html);
	$temp=$('#msview').attr('class');
	$('#Row').trigger('click');
	 jSuccess(html);
	 $('#transperent').hide();
	 
  });
	
});

$('#msview tbody  #rawmat_edit').click(function(){
	$('#inline_edit').val('0');
		$('#message').hide();
		 $("#msview tbody tr textarea").css("background-color","");
			$('#msview tbody textarea').removeAttr('readonly');
var row= $(this).parents('tr');	

row.find('input:button').hide();
  $('#transperent').show();
 $.post("master_crud.php?mode=rowupdate",row.find('textarea').serialize(),function(html){
	// var str=html.split('###');
	   
	 jSuccess(html);
	  
	  $('#transperent').hide();
  });
});



$('#msview tbody  .delete_master').click(function(){
	$('#inline_edit').val('0');
		$('#message').hide();
var row= $(this).parents('tr');	
row.find('input:button').hide();

 
  var r=confirm("Press OK to Delete");
if (r==false)
  {
	
 return;
  }
   $('#transperent').show();
 $.post("master_crud.php?mode=rowdelete",row.find('.entryid').serialize(),function(html){
	// var str=html.split('###');
	 	row.remove();
	  jSuccess(html);

	  $('#transperent').hide();
  });
	
	
});



$('#msview tbody  #ser_master_new').click(function(){
	$('#inline_edit').val('0');
	$('#message').hide();
	
			 $("#msview tbody tr textarea").css("background-color","");
	$('#msview tbody textarea').removeAttr('readonly');
	
	var row= $(this).parents('tr');	
	row.find('input:button').hide();
	  $('#transperent').show();
	 $.post("master_service_crud.php?mode=insert",row.find('textarea').serialize(),function(html){
	//jSuccess(html);
	$temp=$('#msview').attr('class');
	$('#'+$temp).trigger('click');
	 jSuccess(html);
		
	   $('#transperent').hide();
	 
  });
	
});

$('#msview tbody  .service_edit').click(function(){
	$('#inline_edit').val('0');
		$('#message').hide();
		 $("#msview tbody tr textarea").css("background-color","");
			$('#msview tbody textarea').removeAttr('readonly');
var row= $(this).parents('tr');	

row.find('input:button').hide();
  $('#transperent').show();
 $.post("master_service_crud.php?mode=update",row.find('textarea').serialize(),function(html){
	// var str=html.split('###');
	   
	  jSuccess(html);
	  
	  $('#transperent').hide();
  });
});


$('#msview tbody  .delete_serv_mas').click(function(){
	$('#inline_edit').val('0');
		$('#message').hide();
var row= $(this).parents('tr');	
row.find('input:button').hide();

 
  var r=confirm("Press OK to Delete");
if (r==false)
  {
	
 return;
  }
   $('#transperent').show();
 $.post("master_service_crud.php?mode=delete",row.find('.entryid').serialize(),function(html){
	// var str=html.split('###');
	 	row.remove();
	  $('#message').html(html).fadeIn(2000);

	  $('#transperent').hide();
  });
	
	
});


$('#msview tbody  .delete_master').click(function(){
	$('#inline_edit').val('0');
		$('#message').hide();
var row= $(this).parents('tr');	
row.find('input:button').hide();

 
  var r=confirm("Press OK to Delete");
if (r==false)
  {
	
 return;
  }
   $('#transperent').show();
 $.post("master_crud.php?mode=delete",row.find('.entryid').serialize(),function(html){
	// var str=html.split('###');
	 	row.remove();
	  $('#message').html(html).fadeIn(2000);

	  $('#transperent').hide();
  });
	
	
});

$('#msview tbody  .delete_product').click(function(){
	$('#inline_edit').val('0');
		$('#message').hide();
var row= $(this).parents('tr');	
row.find('input:button').hide();

 
  var r=confirm("Press OK to Delete");
if (r==false)
  {
	
 return;
  }
   $('#transperent').show();
 $.post("master_crud.php?mode=delete_product",row.find('.id').serialize(),function(html){
	// var str=html.split('###');
	 	row.remove();
	  jSuccess(html);

	  $('#transperent').hide();
  });
	
	
});




$('#msview tbody  #cmp_master_edit').click(function(){
	$('#inline_edit').val('0');
		$('#message').hide();
		 $("#msview tbody tr textarea").css("background-color","");
			$('#msview tbody textarea').removeAttr('readonly');
var row= $(this).parents('tr');	
row.find('input:button').hide();

  $('#transperent').show();
 $.post("master_cmp_crud.php?mode=update",row.find('textarea').serialize(),function(html){
	// var str=html.split('###');
	 
	  jSuccess(html);
	 
	
	  $('#transperent').hide();
  });
	
});	



$('#msview tbody  #cmp_master_new').click(function(){
	$('#inline_edit').val('0');
	$('#message').hide();
	
			 $("#msview tbody tr textarea,#msview tbody tr .pwd").css("background-color","");
	$('#msview tbody textarea').removeAttr('readonly');
	
	var row= $(this).parents('tr');	
	row.find('input:button').hide();
	  $('#transperent').show();
	 $.post("master_cmp_crud.php?mode=insert",row.find('textarea,.pwd').serialize(),function(html){
	//jSuccess(html);
	$temp=$('#msview').attr('class');
	$('#'+$temp).trigger('click');
	 jSuccess(html);

	   $('#transperent').hide();
	 
  });
		
});


$('#msview tbody  .delete_master_cmp').click(function(){
	$('#inline_edit').val('0');
		$('#message').hide();
var row= $(this).parents('tr');	

 row.find('input:button').hide();
  var r=confirm("Press OK to Delete");
if (r==false)
  {
	
 return;
  }
  $('#transperent').show();
 $.post("master_cmp_crud.php?mode=delete",row.find('textarea').serialize(),function(html){
	// var str=html.split('###');
	 	row.remove();
	  jSuccess(html);

	  $('#transperent').hide();
  });
	});

$('#msview tbody  #rate_master_edit').click(function(){
	$('#inline_edit').val('0');
		$('#message').hide();
		 $("#msview tbody tr textarea").css("background-color","");
			$('#msview tbody textarea').removeAttr('readonly');
var row= $(this).parents('tr');	
row.find('input:button').hide();

  $('#transperent').show();
 $.post("master_rate_crud.php?mode=update",row.find('textarea').serialize(),function(html){
	// var str=html.split('###');
	 
	  jSuccess(html);
	  $('#transperent').hide();
  });
	
	});	



$('#msview tbody  #rate_master_new').click(function(){
	$('#inline_edit').val('0');
	$('#message').hide();
	
			 $("#msview tbody tr textarea,#msview tbody tr .pwd").css("background-color","");
	$('#msview tbody textarea').removeAttr('readonly');
	
	var row= $(this).parents('tr');	
	row.find('input:button').hide();
	  $('#transperent').show();
	 $.post("master_rate_crud.php?mode=insert",row.find('textarea,.pwd').serialize(),function(html){
	//jSuccess(html);
	$temp=$('#msview').attr('class');
	$('#'+$temp).trigger('click');
	 jSuccess(html);

	   $('#transperent').hide();
	 
  });
		
});


$('#msview tbody  .delete_master_rate').click(function(){
	$('#inline_edit').val('0');
		$('#message').hide();
var row= $(this).parents('tr');	

 row.find('input:button').hide();
  var r=confirm("Press OK to Delete");
if (r==false)
  {
	
 return;
  }
  $('#transperent').show();
 $.post("master_rate_crud.php?mode=delete",row.find('textarea').serialize(),function(html){
	// var str=html.split('###');
	 	row.remove();
	  jSuccess(html);

	  $('#transperent').hide();
  });
	});	
	
	
	
	$('#msview tbody  #empinfo_master_edit').click(function(){
		$('#inline_edit').val('0');
		$('#message').hide();
		 $("#msview tbody tr textarea").css("background-color","");
			$('#msview tbody textarea').removeAttr('readonly');
var row= $(this).parents('tr');	

row.find('input:button').hide();
  $('#transperent').show();
 $.post("master_empinfo_crud.php?mode=update",row.find('textarea,.pwd').serialize(),function(html){
	// var str=html.split('###');
	 
	 jSuccess(html);
	  $('#transperent').hide();
  });
	
});	



$('#msview tbody  #empinfo_master_new').click(function(){
	$('#inline_edit').val('0');
	$('#message').hide();
	
			 $("#msview tbody tr textarea,#msview tbody tr .pwd").css("background-color","");
	$('#msview tbody textarea').removeAttr('readonly');
	
	var row= $(this).parents('tr');	
	row.find('input:button').hide();
	  $('#transperent').show();
	 $.post("master_empinfo_crud.php?mode=insert",row.find('textarea,.pwd').serialize(),function(html){
	//jSuccess(html);
	$temp=$('#msview').attr('class');
	$('#'+$temp).trigger('click');
	 jSuccess(html);

	   $('#transperent').hide();
	 
  });
		
});


$('#msview tbody  .delete_master_empinfo').click(function(){
	$('#inline_edit').val('0');
		$('#message').hide();
var row= $(this).parents('tr');	

 row.find('input:button').hide();
  var r=confirm("Press OK to Delete");
if (r==false)
  {
	
 return;
  }
  $('#transperent').show();
 $.post("master_empinfo_crud.php?mode=delete",row.find('textarea').serialize(),function(html){
	// var str=html.split('###');
	 	row.remove();
	  jSuccess(html);

	  $('#transperent').hide();
  });
	});	
	
	
	
$('#msview tbody  #led_master_edit').click(function(){
	$('#inline_edit').val('0');
		$('#message').hide();
		 $("#msview tbody tr textarea").css("background-color","");
			$('#msview tbody textarea').removeAttr('readonly');
var row= $(this).parents('tr');	

row.find('input:button').hide();
  $('#transperent').show();
 $.post("master_led_crud.php?mode=update",row.find('textarea').serialize(),function(html){
	// var str=html.split('###');
	 
	  jSuccess(html);
	  $('#transperent').hide();
  });
	
	});	



$('#msview tbody  #led_master_new').click(function(){
	$('#inline_edit').val('0');
	$('#message').hide();
	
			 $("#msview tbody tr textarea,#msview tbody tr .pwd").css("background-color","");
	$('#msview tbody textarea').removeAttr('readonly');
	
	var row= $(this).parents('tr');	
	row.find('input:button').hide();
	  $('#transperent').show();
	 $.post("master_led_crud.php?mode=insert",row.find('textarea').serialize(),function(html){
	//jSuccess(html);
	$temp=$('#msview').attr('class');
	$('#'+$temp).trigger('click');
	 jSuccess(html);

	   $('#transperent').hide();
	 
  });
  	
});		


$('.stock, .vat, .rate').blur(function(){
	var row=$(this).closest('tr');
	var stock=row.find('.stock').val();
	var vat=row.find('.vat').val();
	var rate=row.find('.rate').val();
	if(!isNaN(row.find('.stock').val())&& !isNaN(row.find('.rate').val()))
	{
		row.find(".ptotal").val(Math.round(Number(stock)*Number(rate)));
		//row.find(".ISCLOSED").val("1");
		
		}
		else
		return;
});

$('.stock, .vat, .drate').blur(function(){
	var row=$(this).closest('tr');
	var stock=row.find('.stock').val();
	var vat=row.find('.vat').val();
	var rate=row.find('.drate').val();
	if(!isNaN(row.find('.stock').val())&& !isNaN(row.find('.drate').val()))
	{
		row.find(".stotal").val(Math.round(Number(stock)*Number(rate)));
		//row.find(".ISCLOSED").val("1");
		
		}
		else
		return;
});


$('#msview tbody  .delete_master_led').click(function(){
	$('#inline_edit').val('0');
		$('#message').hide();
var row= $(this).parents('tr');	

 row.find('input:button').hide();
  var r=confirm("Press OK to Delete");
if (r==false)
  {
	
 return;
  }
  $('#transperent').show();
 $.post("master_led_crud.php?mode=delete",row.find('textarea').serialize(),function(html){
	// var str=html.split('###');
	 	row.remove();
	  jSuccess(html);

	  $('#transperent').hide();
  });
	});	
  
 $('#msview tbody  #usr_master_edit').click(function(){
	 $('#inline_edit').val('0');
	 
		$('#message').hide();
		 $("#msview tbody tr textarea,#msview tbody tr .pwd").css("background-color","");
			$('#msview tbody textarea,#msview tbody tr .pwd').removeAttr('readonly');
var row= $(this).parents('tr');	

row.find('input:button').hide();
  $('#transperent').show();
 $.post("master_user_crud.php?mode=update",row.find('textarea,.pwd').serialize(),function(html){
	// var str=html.split('###');
	 
	  jSuccess(html);
	 	  $('#transperent').hide();
  });
	});

$('#msview tbody  #usr_master_new').click(function(){
	$('#inline_edit').val('0');
	$('#message').hide();
	
	$("#msview tbody tr textarea,#msview tbody tr .pwd").css("background-color","");
	$('#msview tbody textarea').removeAttr('readonly');
	
	var row= $(this).parents('tr');	
	row.find('input:button').hide();
	  $('#transperent').show();
	 $.post("master_user_crud.php?mode=insert",row.find('textarea,.pwd').serialize(),function(html){
	jSuccess(html);
	$temp=$('#msview').attr('class');
	$('#'+$temp).trigger('click');
	 jSuccess(html);

	   $('#transperent').hide();
	 
  });
		
}); 

if($('#mstvalue').val()=='SSC'||$('#mstvalue').val()=='CAT'){
$(function ()
{
    $(document).on("keydown", "#msview tbody textarea.det", function(e)
    {
		var row= $(this).closest('tr');
			if(row.find('.mstype').val()=='SSC'){
		
        if ((e.keyCode == 32))
        {    
			var ratio = $(this).val()+",";
            $(this).val(ratio);
			
		
        }
		
		
			}
			
			
			else if(row.find('.mstype').val()=='CAT'){
			  
			  $(this).autocomplete(
      "../ssetcode_fill.php?",
      {
  			delay:300,
  			minChars:1,
  			matchSubset:1,
  			matchContains:1,
			cacheLength:10,
			showResult:function(rownew,data) {
    		return rownew+"|"+data[0]+"|"+data[1];
 			 },
			 onItemSelect:function(rownew){
				 var temprow= $(this).closest('tr');
				if(rownew.data[0]!='undefined')
				row.find('.det').val($.trim(rownew.data[0]));
				if(rownew.data[1]!='undefined')
				row.find('.det1').val($.trim(rownew.data[1]));
				if(rownew.data[3]!='undefined')
				row.find('.det2').val($.trim(rownew.data[3]));
				if(rownew.data[4]!='undefined')
				row.find('.det3').val($.trim(rownew.data[4]));
				
					
			 },
  			autoFill:false
  		});
			  
			  
	 }// end if(row.find('.mstype').val()=='CAT'){
    });
});

$(function ()
{
    $(document).on("keydown", "#msview tbody textarea.desc", function(e)
    {
		var row= $(this).closest('tr');
		  if(row.find('.mstype').val()=='SSC'){
			if ((e.keyCode == 32))
			{    
			  var ratio = $(this).val()+",";
			  $(this).val(ratio);
	   
			}
		  }
		  
		
    });
});
}
 



$('#msview tbody  .delete_master_usr').click(function(){
	$('#inline_edit').val('0');
		$('#message').hide();
var row= $(this).parents('tr');	
row.find('input:button').hide();
 
  var r=confirm("Press OK to Delete");
if (r==false)
  {
	
 return;
  }
  $('#transperent').show();
 $.post("master_user_crud.php?mode=delete",row.find('textarea').serialize(),function(html){
	// var str=html.split('###');
	 	row.remove();
	  jSuccess(html);

	  $('#transperent').hide();
  });
	});	
	
if(type=="ratemst")
{
	$(".compid").autocomplete(
      "billedto.php",
      {
  			delay:10,
  			minChars:1,
  			matchSubset:1,
			mustMatch:1,
  			matchContains:1,
			onItemSelect: function findValue_bt(li) {
  	if( li == null ) return jSuccess("No match!");

  	// if coming from an AJAX call, let's use the CityId as the value
  	if( !!li.data ) var sValue = li.data[0];

  	// otherwise, let's just display the value in the text box
  	else var sValue = li.selectValue;
	
	var row= $("*:focus").parents('tr');
	 row.find('.city').val(sValue);

  	//jSuccess("The value you selected was: " + sValue);
  },
  			cacheLength:10,
  			autoFill:false
  		}
    );
	
	
	$(".vehtype").autocomplete(
      "vehicle.php?",
      {
  			delay:10,
  			minChars:1,
  			matchSubset:1,
  			matchContains:1,
  			cacheLength:10,
			mustMatch:1,
  			autoFill:false
  		}
    );
	
	$(".city").autocomplete(
      "city.php?",
      {
  			delay:10,
  			minChars:1,
  			matchSubset:1,
  			matchContains:1,
  			cacheLength:10,
			mustMatch:1,
  			autoFill:false
  		}
    );
	
	
	$(".package").autocomplete(
      "package.php?mode=asn",
      {
  			delay:10,
  			minChars:1,
  			matchSubset:1,
  			matchContains:1,
  			cacheLength:10,
			mustMatch:1,
  			autoFill:false
  		}
    );
	
	}
	if(type=="cmpmst")
		{
		$(".type").autocomplete(
		 "comtype.php?",
	  {
  			delay:10,
  			minChars:1,
  			matchSubset:1,
  			matchContains:1,
  			cacheLength:10,
			mustMatch:1,
  			autoFill:false
  		}
    );
		}
		
		if(type=="empinfo")
		{
			$(".Designation").autocomplete(
      
	  "design.php?",
	  {
  			delay:10,
  			minChars:1,
  			matchSubset:1,
  			matchContains:1,
  			cacheLength:10,
			mustMatch:1,
		
  			autoFill:false
  		}
    );	
		}
		
		if(type=="vno")
		{
			$(".det3").autocomplete(
      
	  "billedto.php?mode=vendor",
	  {
  			delay:10,
  			minChars:1,
  			matchSubset:1,
  			matchContains:1,
  			cacheLength:10,
			mustMatch:1,
		
  			autoFill:false
  		}
    );	
		}

	
}

var winPop;

function positionedPopup(url,width,height){
	
	 if(winPop&&!winPop.closed&&winPop.document.location.href!=url){  //checks to see if window is open  
    winPop.close();  
  } 
 winPop =window.open (url,"mywindow","menubar=1,resizable=1,width="+width+",height="+height+",left=250,top=80");
  if(winPop&&winPop.document.location.href==url)
winPop.focus();

}




