function GetXmlHttpObject() {
    var xmlHttp = null;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    } catch (e) {
// Internet Explorer
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

function keyset(key, e) {

    if (e.keyCode == 13) {
        document.getElementById(key).focus();
    }
}

function got_focus(key) {
    document.getElementById(key).style.backgroundColor = "#000066";
}

function lost_focus(key) {
    document.getElementById(key).style.backgroundColor = "#000000";
}



function lastmonthcal()
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	} 		
	 document.getElementById('lastlockmonth').innerHTML ="";
			
	var url="bank_rec_data.php";	
	
	url=url+"?Command="+"lastmonthcal";
	url=url+"&txtBankCode="+document.getElementById('Com_CAS').value;
	url=url+"&dtpDate="+document.getElementById('dtpDate').value;
	 
	
	xmlHttp.onreadystatechange=lastmonthcal_results;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}

function lastmonthcal_results()
{
	var XMLAddress1; 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") 	{ 	
		XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("txt_bankbal");	
		document.getElementById('txt_bankbal').value = XMLAddress1[0].childNodes[0].nodeValue;			
		
		XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("dtfrom");	
		document.getElementById('dtfrom').value = XMLAddress1[0].childNodes[0].nodeValue;	
		
		XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("txt_bF");	
		document.getElementById('txt_bankbal2').value = XMLAddress1[0].childNodes[0].nodeValue;	
		
		XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("state_bal");	
		document.getElementById('txtBankClosBal').value = XMLAddress1[0].childNodes[0].nodeValue;	
		 
	    	XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("lastlockmonth");	
    		document.getElementById('lastlockmonth').innerHTML = XMLAddress1[0].childNodes[0].nodeValue;
	}
}


function display()
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	} 		
	
	 document.getElementById('lastlockmonth').innerHTML ="";
	 
	var url="bank_rec_data.php";	
	
	url=url+"?Command="+"display";
	url=url+"&txtBankCode="+document.getElementById('Com_CAS').value;
	url=url+"&dtpDate="+document.getElementById('dtpDate').value;
	url=url+"&txt_bankbal="+document.getElementById('txt_bankbal').value;
	url=url+"&txtBankClosBal="+document.getElementById('txtBankClosBal').value;
	url=url+"&txt_bankbal2="+document.getElementById('txt_bankbal2').value;
	 
	
	xmlHttp.onreadystatechange=display_results;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}

function display_results() {
	var XMLAddress1;
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 	
        var res = xmlHttp.responseText;
        if (res != ""){ 
    		XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("debtable");	 
    		document.getElementById('flexDeb').innerHTML = XMLAddress1[0].childNodes[0].nodeValue;			
    		
    		XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("cretable");	
    		document.getElementById('flexCre').innerHTML = XMLAddress1[0].childNodes[0].nodeValue;		
    		
    		XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("txtbankpay");	
    		document.getElementById('txtbankpay').value = XMLAddress1[0].childNodes[0].nodeValue;		
    		
    		XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("txtbankdepo");	
    		document.getElementById('txtbankdepo').value = XMLAddress1[0].childNodes[0].nodeValue;	
    		
    		XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("txtbankpay");	
    		document.getElementById('txtbankpay2').value = XMLAddress1[0].childNodes[0].nodeValue;		
    		
    		XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("txtbankdepo");	
    		document.getElementById('txtbankdepo2').value = XMLAddress1[0].childNodes[0].nodeValue;	
    		
    		XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("txtFinalBal");	
    		document.getElementById('txtFinalBal').value = XMLAddress1[0].childNodes[0].nodeValue;		
    		
    		
    		
    		XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("txtclosebal");	
    		document.getElementById('txtclosebal').value = XMLAddress1[0].childNodes[0].nodeValue;	
    		
    		XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("txtclosebal2");	
    		document.getElementById('txtclosebal2').value = XMLAddress1[0].childNodes[0].nodeValue;	
    		
    		
    		
    		XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("txttot");	
    		document.getElementById('txttot').value = XMLAddress1[0].childNodes[0].nodeValue;	
    		
    		
    		XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("lastlockmonth");	
    		document.getElementById('lastlockmonth').innerHTML = XMLAddress1[0].childNodes[0].nodeValue;
		
	    	alert("Ready");
		 
                        
        }else{
            alert("Please Login Again!");    
		}
    }
}


function checkdb(refno, id, type)
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	} 		
			
	var url="bank_rec_data.php";	
	
	url=url+"?Command="+"checkdb";
	url=url+"&refno="+refno;
	url=url+"&id="+id;
	url=url+"&type="+type;
	url=url+"&chk="+document.getElementById(refno).checked;
	
	url=url+"&txtBankCode="+document.getElementById("Com_CAS").value;
	url=url+"&dtpDate="+document.getElementById("dtpDate").value;
	
	url=url+"&txt_bankbal="+document.getElementById("txt_bankbal").value;
	url=url+"&txtBankClosBal="+document.getElementById("txtBankClosBal").value;
	 
	xmlHttp.onreadystatechange=checkdb_results;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}


function checkdb_results()
{
	var XMLAddress1; 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") 	{ 	
			 
        $msg = "to be updated";
        document.getElementById('txtbankpay').value = $msg;
        document.getElementById('txtbankpay2').value = $msg;
        document.getElementById('txtbankdepo').value = $msg;
        document.getElementById('txtbankdepo2').value = $msg;
        document.getElementById('txtFinalBal').value = $msg;		
        document.getElementById('txtclosebal').value = $msg;
        document.getElementById('txtclosebal2').value = $msg;
        document.getElementById('txttot').value = $msg;
    }
}


function update_customer() {   
	
			
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	} 	
			
	var msg=confirm("Do you want to Upadte this  ! ");
	if (msg==true){
			
		var url="bank_rec_data.php";			
		url=url+"?Command="+"update_customer";
		url=url+"&txtBankCode="+document.getElementById('Com_CAS').value;
		url=url+"&dtpDate="+document.getElementById('dtpDate').value;
		url=url+"&dtfrom="+document.getElementById('dtfrom').value;
		url=url+"&txt_bankbal="+document.getElementById('txt_bankbal').value;
		url=url+"&txtclosebal="+document.getElementById('txtclosebal').value;
		url=url+"&txtBankClosBal="+document.getElementById('txtBankClosBal').value;
	

	
		xmlHttp.onreadystatechange=update_customer_result;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
			
	}
		
}

function update_customer_result()
{
	var XMLAddress1;
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		alert(xmlHttp.responseText); 
	}
}

function save_customer() {   
	
 	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	} 	
	var msg=confirm("Do you want to Save this  ! ");
	if (msg==true){
    	var url="bank_rec_data.php";			
    	url=url+"?Command="+"save_customer";
    	url=url+"&dtpDate="+document.getElementById('dtpDate').value;
    	url=url+"&txtBankCode="+document.getElementById('Com_CAS').value;
		url=url+"&dtpDate="+document.getElementById('dtpDate').value;
		url=url+"&dtfrom="+document.getElementById('dtfrom').value;
    	 
    	xmlHttp.onreadystatechange=save_customer_result;
    	xmlHttp.open("GET",url,true);
    	xmlHttp.send(null);
			
	}
		
}

function save_customer_result() {
	var XMLAddress1;
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		alert(xmlHttp.responseText);
		if(xmlHttp.responseText !="Already Locked Month"){
		    var isDisplay = confirm("Do you want to see the changes now?");
            if(isDisplay){
                display(); 
        	}  
		}
         
    }
}


function print_recon() {
	
	var url="rep_bank_recon.php";			
	url=url+"?txtBankCode="+document.getElementById('Com_CAS').value;
	url=url+"&dtpDate="+document.getElementById('dtpDate').value;
	url=url+"&dtfrom="+document.getElementById('dtfrom').value;
	url=url+"&txtBankClosBal="+document.getElementById('txtBankClosBal').value;
	url=url+"&txtbankpay="+document.getElementById('txtbankpay').value;
	url=url+"&txtbankdepo="+document.getElementById('txtbankdepo').value;
	url=url+"&txtclosebal="+document.getElementById('txtclosebal').value;
	url=url+"&txt_bankbal="+document.getElementById('txt_bankbal').value;
	url=url+"&txt_bankbal2="+document.getElementById('txt_bankbal2').value;
	url=url+"&txtclosebal2="+document.getElementById('txtclosebal2').value;
	
	window.open(url);
  	
}

function print_un_rp() {
	
	var url="report_un_rp.php";			
	url=url+"?txtBankCode="+document.getElementById('Com_CAS').value;
	url=url+"&dtpDate="+document.getElementById('dtpDate').value;
	url=url+"&dtfrom="+document.getElementById('dtfrom').value;
	url=url+"&txtBankClosBal="+document.getElementById('txtBankClosBal').value;
	url=url+"&txtbankpay="+document.getElementById('txtbankpay').value;
	url=url+"&txtbankdepo="+document.getElementById('txtbankdepo').value;
	url=url+"&txtclosebal="+document.getElementById('txtclosebal').value;
	url=url+"&txt_bankbal="+document.getElementById('txt_bankbal').value;
	url=url+"&txt_bankbal2="+document.getElementById('txt_bankbal2').value;
	url=url+"&txtclosebal2="+document.getElementById('txtclosebal2').value;
	
	window.open(url);
  	
}














// function getrecdt() {

//     xmlHttp = GetXmlHttpObject();
//     if (xmlHttp == null)
//     {
//         alert("Browser does not support HTTP Request");
//         return;
//     }

//     var url = "bank_rec_data.php";
//     url = url + "?Command=" + "getrecdt";
//     url = url + "&bank=" + document.getElementById('bank').value;
//     url = url + "&dtto=" + document.getElementById('dtto').value;



//     xmlHttp.onreadystatechange = showitemresult;
//     xmlHttp.open("GET", url, true);
//     xmlHttp.send(null);

// }


// function showitemresult()
// {
//     var XMLAddress1;

//     if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
//     {


//         XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("dbgrid");
//         document.getElementById('itemdetails').innerHTML = XMLAddress1[0].childNodes[0].nodeValue;

//         XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("count");
//         document.getElementById('count').value = XMLAddress1[0].childNodes[0].nodeValue;


//         XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("crgrid");
//         document.getElementById('itemdetails1').innerHTML = XMLAddress1[0].childNodes[0].nodeValue;

//         XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("count1");
//         document.getElementById('count1').value = XMLAddress1[0].childNodes[0].nodeValue;


//         XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("bank_bal");
//         document.getElementById('bank_bal').value = XMLAddress1[0].childNodes[0].nodeValue;


//         XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("last_dt");
//         document.getElementById('lastdt').value = XMLAddress1[0].childNodes[0].nodeValue;



//     }
// }


// function new_inv() {
    
     
//     document.getElementById('msg_box').innerHTML = "";
//     document.getElementById('itemdetails').innerHTML = "";
//     document.getElementById('itemdetails1').innerHTML = "";
//     document.getElementById('bank_bal').value =""; 
//      document.getElementById('bank').value =""; 
    
// }

// function print_inv(cdata) {

//     var url = "bank_rec_print.php";
//     url = url + "?bank=" + document.getElementById('bank').value;
    
//     url = url + "&dtto=" + document.getElementById('dtto').value;
    
//     url = url + "&bank_bal=" + escape(document.getElementById('bank_bal').value);
//     url = url + "&action=" + cdata;


//     window.open(url, '_blank');


// }

// function save_inv() {

//     xmlHttp = GetXmlHttpObject();
//     if (xmlHttp == null) {
//         alert("Browser does not support HTTP Request");
//         return;
//     }
//     document.getElementById('msg_box').innerHTML = "";
//     if (document.getElementById('bank').value == "") {
//         document.getElementById('msg_box').innerHTML = "<div class='alert alert-warning' role='alert'><span class='center-block'>Bank Not Selected</span></div>";
//         return false;
//     }

//     var url = "bank_rec_data.php";
//     var params = "Command=" + "save_item";

//     params = params + "&dtto=" + document.getElementById('dtto').value;
//     params = params + "&bank=" + escape(document.getElementById('bank').value);
//     params = params + "&bank_bal=" + escape(document.getElementById('bank_bal').value);

//     params = params + "&count=" + escape(document.getElementById('count').value);
//     params = params + "&count1=" + escape(document.getElementById('count1').value);


//     var count = document.getElementById('count').value;
//     var i = 1;
//     while (count > i) {
//         var id_deb = "id_deb" + i;
//         var dt_deb = "dt_deb" + i;
//         params = params + '&' + id_deb + '=' + document.getElementById(id_deb).value;
//         if (document.getElementById(dt_deb).checked == true) {
//             params = params + '&' + dt_deb + '=1';
//         } else {
//             params = params + '&' + dt_deb + '=0';
//         }

//         i = i + 1;
//     }

//     var count1 = document.getElementById('count1').value;
//     var t = 1;
//     while (count1 > t) {
//         var id_cre = "id_cre" + t;
//         var dt_cre = "dt_cre" + t;
//         params = params + '&' + id_cre + '=' + document.getElementById(id_cre).value;
//         if (document.getElementById(dt_cre).checked == true) {
//             params = params + '&' + dt_cre + '=1';
//         } else {
//             params = params + '&' + dt_cre + '=0';
//         }

//         t = t + 1;
//     }


//     xmlHttp.open("POST", url, true);

//     xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//     xmlHttp.setRequestHeader("Content-length", params.length);
//     xmlHttp.setRequestHeader("Connection", "close");

//     xmlHttp.onreadystatechange = salessaveresult;

//     xmlHttp.send(params);

// }

// function salessaveresult() {
//     var XMLAddress1;
//     if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {

//         if (xmlHttp.responseText == "Saved") {
//             document.getElementById('msg_box').innerHTML = "<div class='alert alert-success' role='alert'><span class='center-block'>Saved</span></div>";
//             print_inv('save');
//             document.getElementById('filup').style.visibility = "visible";
//         } else {
//             document.getElementById('msg_box').innerHTML = "<div class='alert alert-warning' role='alert'><span class='center-block'>" + xmlHttp.responseText + "</span></div>";
//         }
//     }
// }


// function display() {

//     xmlHttp = GetXmlHttpObject();
//     if (xmlHttp == null)
//     {
//         alert("Browser does not support HTTP Request");
//         return;
//     }

//     var url = "bank_rec_data.php";
//     url = url + "?Command=" + "display"; 

//     url=url+"&txtBankCode="+document.getElementById('bank').value;
// 	url=url+"&dtpDate="+document.getElementById('dtto').value;
// 	url=url+"&txt_bankbal="+document.getElementById('txt_bankbal').value;
// 	url=url+"&txtBankClosBal="+document.getElementById('bank_bal').value;
// 	url=url+"&txt_bankbal2="+document.getElementById('txt_bankbal2').value;

//     xmlHttp.onreadystatechange = showitemresult;
//     xmlHttp.open("GET", url, true);
//     xmlHttp.send(null);

// }


// function showitemresult()
// {
//     var XMLAddress1;

//     if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
//     {
//             //  XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("dbgrid");
//             // document.getElementById('itemdetails').innerHTML = XMLAddress1[0].childNodes[0].nodeValue;
    
//             // XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("count");
//             // document.getElementById('count').value = XMLAddress1[0].childNodes[0].nodeValue;
    
    
//             // XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("crgrid");
//             // document.getElementById('itemdetails1').innerHTML = XMLAddress1[0].childNodes[0].nodeValue;
    
//             // XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("count1");
//             // document.getElementById('count1').value = XMLAddress1[0].childNodes[0].nodeValue;
    
    
//             // XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("bank_bal");
//             // document.getElementById('bank_bal').value = XMLAddress1[0].childNodes[0].nodeValue;
    
    
//             // XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("last_dt");
//             // document.getElementById('lastdt').value = XMLAddress1[0].childNodes[0].nodeValue;
        
        
        

//         	XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("debtable");	 
// 			document.getElementById('itemdetails').innerHTML = XMLAddress1[0].childNodes[0].nodeValue;			
			
// 			XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("cretable");	
// 			document.getElementById('itemdetails1').innerHTML = XMLAddress1[0].childNodes[0].nodeValue;		
			
// 			XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("txtbankpay");	
// 			document.getElementById('txtbankpay').value = XMLAddress1[0].childNodes[0].nodeValue;		
			
// 			XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("txtbankdepo");	
// 			document.getElementById('txtbankdepo').value = XMLAddress1[0].childNodes[0].nodeValue;	
			
// 			XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("txtbankpay");	
// 			document.getElementById('txtbankpay2').value = XMLAddress1[0].childNodes[0].nodeValue;		
			
// 			XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("txtbankdepo");	
// 			document.getElementById('txtbankdepo2').value = XMLAddress1[0].childNodes[0].nodeValue;	
			
// 			XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("txtFinalBal");	
// 			document.getElementById('txtFinalBal').value = XMLAddress1[0].childNodes[0].nodeValue;		
			
			
			
// 			XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("txtclosebal");	
// 			document.getElementById('txtclosebal').value = XMLAddress1[0].childNodes[0].nodeValue;	
			
// 			XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("txtclosebal2");	
// 			document.getElementById('txtclosebal2').value = XMLAddress1[0].childNodes[0].nodeValue;	
			
			
			
// 			XMLAddress1 = xmlHttp.responseXML.getElementsByTagName("txttot");	
// 			document.getElementById('txttot').value = XMLAddress1[0].childNodes[0].nodeValue;	
			
// 			alert("Ready");



//     }
// }