
$(document).ready(function() {
	$('a.login-window').click(function() {
		
	
		var loginBox = $(this).attr('href');

		$(loginBox).fadeIn(300);
		
		
		var popMargTop = ($(loginBox).height() + 24) / 2; 
		var popMargLeft = ($(loginBox).width() + 24) / 2; 
		
		$(loginBox).css({ 
			'margin-top' : -popMargTop,
			'margin-left' : -popMargLeft
		});
	
		$('body').append('<div id="mask"></div>');
		$('#mask').fadeIn(300);
		
		return false;
	});
	

	$('a.close, #mask').live('click', function() { 
	  $('#mask , .login-popup').fadeOut(300 , function() {
		$('#mask').remove();  
	}); 
	return false;
	});
});


 $(document).ready(function(){
  $("#svbttn").click(function(){

$("#msgbox").html('<small>Loading...</small>');
      

   
  	 var values1 = $("#jforms").serialize();
 	// $(".typeselecter").attr("disabled", true);
 	 // $("#td1").html('');

  	  $.ajax({
   	   url: "upd_lub.php",
    	  type: "POST",
   	  data:   values1,
     	  success: function(msg){

 

           	 if(parseInt(msg)!=0)    

          	  {

                $('#msgbox').html(msg);
              
		}
           

      	},
      error:function(){
          alert("failure");
          $("#msgbox").html('there is error while submit');
      }   
   	 }); 

	 }); 
	 }); 



        $(function() {
          if ($.browser.msie && $.browser.version.substr(0,1)<7)
          {
			$('li').has('ul').mouseover(function(){
				$(this).children('ul').show();
				}).mouseout(function(){
				$(this).children('ul').hide();
				})
          }
        });        


    $(document).ready(function() {
        var cont_left = $("#container").position().left;
        $("a img").hover(function() {
            // hover in
            //$(this).parent().parent().css("z-index", 1);
            $(this).animate({
               height: "110",
               width: "110",
              
            }, "fast");
        }, function() {
            // hover out
         //   $(this).parent().parent().css("z-index", 0);
            $(this).animate({
                height: "80",
                width: "80",
                
            }, "fast");
        });
        
        $(".img").each(function(index) {
            var left = (index * 160) + cont_left;
            $(this).css("left", left + "px");
        });
    });







            

//function below is to add total amount


function qutychecking(r){
    

    var i        =r.parentNode.parentNode.rowIndex;
    var tbl      =document.getElementById('myTable');
    var id1      =tbl.rows[i].cells[0].innerHTML;
   
    var unit     =document.getElementById('unit'+id1).value;
      
    var qty      =document.getElementById('qty'+id1).value;
    var unitprice=document.getElementById('unitprice'+id1).value;
    var dis      =document.getElementById('dis'+id1).value;
      
    if(isNaN(qty)){
     
      alert('enter digit');
      document.getElementById('qty'+id1).value=0;
      document.getElementById('qty'+id1).focus();
      document.getElementById('qty'+id1).select();
    } 
     if(isNaN(dis)){
     
      alert('enter digit');
      document.getElementById('dis'+id1).value=0;
      document.getElementById('dis'+id1).focus();
      document.getElementById('dis'+id1).select();
    }    
   
    var cn=1;
    var i;
    for(i=1; i<count1; i++){ 
        if(unit==unity[i])
           cn=cnvr[i];
        
    }
    document.getElementById('conv'+id1).value=cn;
    var tot   = parseFloat((cn*qty*unitprice))- parseFloat(dis);
    document.getElementById('tot'+id1).value=tot;    
    var p=0;
    var tt= document.getElementsByName('tot[]'), sum1 = 0, p;
   
    for(p = tt.length; p--;)
       if(tt[p].value)
          sum1 += parseFloat(tt[p].value, 10);
			
    document.getElementById('sum_total').value=sum1.toFixed(2);
    
         
}




function delrow(r)
{


var i=r.parentNode.parentNode.rowIndex;




 document.getElementById('myTable').deleteRow(i);

  var rowCount = document.getElementById('myTable').rows.length;
   var tbl = document.getElementById('myTable');
   
  var q;
  var id1;
  var part; 
  var sum2=0;
   var sum3=0;





 if(rowCount<=1)
 {
  document.getElementById('insrowbttn').type='button';
 }





var k=0;
   var ups = document.getElementsByName('tot[]'), sum = 0, k;
    for(k = ups.length; k--;)
        if(ups[k].value)
            sum += parseFloat(ups[k].value, 10);
			document.getElementById('sum_total').value=sum.toFixed(2);





cnt--;
     
 }




/***********************************************
* Disable "Enter" key in Form script
* This notice must stay intact for use
***********************************************/
    

function handleEnter (field, event) {
               
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();
			field.form.elements[i].select();
			return false;
		} 


                if (keyCode == 38){
                    var row=field.parentNode.parentNode.rowIndex;
			 var col  =field.parentNode.cellIndex ;
			 
                     document.getElementById('myTable').rows[row-1].cells[col].getElementsByTagName("input")[0].focus();
			
			 
              }

                  if (keyCode == 40){
                    var row=field.parentNode.parentNode.rowIndex;
			 var col  =field.parentNode.cellIndex ;
			 
                     document.getElementById('myTable').rows[row+1].cells[col].getElementsByTagName("input")[0].focus();
			
			 
              }
                     if (keyCode == 37){


                    /* var row=field.parentNode.parentNode.rowIndex;
			 var col  =field.parentNode.cellIndex ;
			 
                     document.getElementById('myTable').rows[row].cells[col-1].getElementsByTagName("input")[0].focus();*/

                   var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i - 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
			
			 
              }
               
                   	 if (keyCode == 46){
			  var i=field.parentNode.parentNode.rowIndex;
			  
                       var r=confirm("Do you want to delete the row?");
			  if (r==true)
 				 {
 					//document.getElementById('myTable').deleteRow(i);
					delrow(field);
                                  document.getElementById('myTable').rows[i].cells[1].getElementsByTagName("input")[0].focus();
                                  
					//var nxt =document.getElementById('myTable').rows[i].cells[0].innerHTML;
					//alert(nxt);
  				 }
			  
        }
                   
		else
		return true;
	}      





    
        $('#default_notes_textarea, #to_address, #from_address').jqEasyCounter({
            'maxChars': 1000,
            'maxCharsWarning': 980,
            'msgFontSize': '10px',
            'msgFontColor': 'silver',
            'msgFontFamily': 'Arial',
            'msgTextAlign': 'right',
            'msgWarningColor': 'red',
            'msgAppendMethod': 'insertAfter',
            'allocateSpace': true
        });
        
        reCalculate(document.getElementById('sum_discount'),'dataTable','0.00');

        function loadReceiptLayer(obj){
            var to_id = $('#to_name').val();

            if (obj.checked){
                $('#receipts_layer').show(100, function(){
                    if (!$(this).attr('rloaded')){
                        $(this).attr('rloaded','true');
                        $('#receipts_layer').html('<img src="images/loadingsmall.gif">');

                        $.ajax({

                            url: "showExpenses.php?action=displayReceiptList&customer_id="+to_id+"&list=",
                            type: 'GET',
                            cache: false,
                            async: true,
                            dataType : 'json',
                            success:function(response){
                                if (response && response.success)
                                    $('#receipts_layer').html(response.html);
                                else
                                    $('#receipts_layer').html('Fail to load. Try Again');
                            },
                            error:function(){
                                $('#receipts_layer').html('There was an error. Try Again');
                            }
                        });




                    }
                }) ;
            }
            else{
                $('#receipts_layer').hide();
            }
        }

        $(function(){
            /*
            $('#to_name').change(function(){
                $('#receipts_layer').attr('rloaded','');
                document.getElementById('receipts_include').checked = false;
                $('#receipts_layer').hide();

            });
            */



        });
        $('#receipts_include').click(function(){


            var obj = $('#receipts_layer');
            if (document.getElementById('receipts_include').checked){


                if (obj.attr('rloaded') == 'true'){
                    obj.show();
                }
                else{
                    loadReceiptLayer(document.getElementById('receipts_include'));
                }
            }else{
                obj.hide();
            }



        })




    
