
function show_load() {
//alert("i am showing load");
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
 //var lft = 0, top = 0;
 var lft = (myWidth/2)-75;
 var top = (myHeight/2)-50 ;
 //alert(lft + " 000 " + top );
 var str = "<table border=0 cellpadding=4 cellspacing=1 width=100% height=100% align=center style=BORDER-RIGHT:#888888 2px solid; BORDER-TOP:#888888 2px solid; BORDER-LEFT:#888888 2px solid; CURSOR:default; BORDER-BOTTOM:#888888 2px solid; BACKGROUND-COLOR:#ffffff bgcolor=#cccccc><tr><td align=center class=text11><IMG src=/bfree/images/spinner.gif>&nbsp;&nbsp;<b>Loading ...</b></td></tr></table>";
 
 document.getElementById('load_splash').style.left=lft;
 document.getElementById('load_splash').style.top=top;
 document.getElementById('load_splash').style.width="150px";
 document.getElementById('load_splash').style.height="100px";
 document.getElementById('load_splash').innerHTML= str;
 document.getElementById('load_splash').style.visibility="visible";
 
}

function hide_load(){
document.getElementById('load_splash').style.visibility="hidden";
}

function GetXmlHttpObject(handler)
{ 
	var objXMLHttp=null
		if (window.XMLHttpRequest)
		{
			objXMLHttp=new XMLHttpRequest()
		}
		else if (window.ActiveXObject)
		{
			objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
		}
	return objXMLHttp
}

var xmlHttp;
var _xt;
var _div_id;

function show_data(param,xt,_div)
{
//alert("from this field " + param);
var obj = document.getElementById(param);
var str = obj.value;
if (!isInt(str)){ 
	if (str.indexOf("&")!=-1){ 
		while(str.indexOf("&")!=-1){
			str = str.replace("&","and"); 
		}
	}
}
_div_id = _div;
_xt = xt;


	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	
		show_load_xt(xt);
		//var url="http://www.b-free.com.au/bfree/xjax/xjax.aspx"
		//var url="http://test.b-free.com.au/bfree/xjax/xjax.aspx";
		var url=location.protocol + "//" + location.hostname +"/bfree/xjax/xjax.aspx";
		//alert(url);
		url=url+"?xt="+xt;
		url=url+"&var="+str;
		url=url+"&sid="+sid;
		//url=url+"&uid="+uid
		url=url+"&xid="+Math.random();
		//alert(url);
		xmlHttp.onreadystatechange=stateChanged
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
		
} 

function isInt(x) { 
   var y=parseInt(x); 
   if (isNaN(y)){ return false; }else{ return true; }
   //return x==y && x.toString()==y.toString(); 
 } 



function send_data(param,xt,_div)
{
var str =param;

if (!isInt(str)){ 
	if (str.indexOf("&")!=-1){ 
		while(str.indexOf("&")!=-1){
			str = str.replace("&","and"); 
		}
	}
}

_xt = xt;
_div_id = _div;
//
//alert(_xt);

	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	
		show_load_xt(xt);
	
		//var url="http://www.b-free.com.au/bfree/xjax/xjax.aspx"
		//var url="http://test.b-free.com.au/bfree/xjax/xjax.aspx";
		var url=location.protocol + "//" + location.hostname +"/bfree/xjax/xjax.aspx";
		//alert(url);
		url=url+"?xt="+xt
		url=url+"&var="+str
		url=url+"&sid="+sid
		//url=url+"&uid="+uid
		url=url+"&xid="+Math.random()
		xmlHttp.onreadystatechange=stateChanged
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
		
} 



function stateChanged() 
{ 
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
	//alert(_xt);
	//alert(xmlHttp.responseText);
	//alert(_div_id);
	hide_load();
			
			if (_xt==1){
				document.getElementById(_div_id).innerHTML =xmlHttp.responseText;
			}else{
				document.getElementById(_div_id).innerHTML =xmlHttp.responseText;
			}
			
			/*if ((_xt==4) || (_xt==6)){
				document.getElementById(_div_id).style.display = "";
				document.getElementById(_div_id).innerHTML = xmlHttp.responseText;
				var check_len = document.getElementById(_div_id).innerHTML;
				if (check_len.length<3000){ document.getElementById(_div_id).style.height="auto"; }else{ document.getElementById(_div_id).style.height="150px"; }
			}else if((_xt==7) || (_xt==8)){
				document.getElementById(_div_id).innerHTML =xmlHttp.responseText;
				send_data('null',10,total_amt_div)		
			}else if(_xt==10){
				document.getElementById(_div_id).innerHTML =xmlHttp.responseText;
				send_data('null',11,top_total_txt);
			}else if (_xt==11){
				document.getElementById(_div_id).value =xmlHttp.responseText;
				send_data(document.getElementById(invoice_id_txt).value,12,r_details2_div);
			}else if (_xt==13){
				var res = xmlHttp.responseText;
				//alert(res);
				if (res.indexOf("|") > 0){
					var _res = res.split("|")
					//alert(_res[0]);
					alert(_res[1]);
					document.getElementById(_div_id).value =_res[0];
					send_data(document.getElementById(invoice_id_txt).value,12,r_details2_div);
				}else{
					document.getElementById(_div_id).value =xmlHttp.responseText;
					send_data(document.getElementById(invoice_id_txt).value,12,r_details2_div);
				}
			}else if (_xt==14){
			
				document.getElementById(_div_id).style.display="";
				document.getElementById(_div_id).innerHTML =xmlHttp.responseText;
				document.getElementById(view_trans_link_id).style.display="none";
				document.getElementById(hide_trans_link_id).style.display="";
				var check_len = xmlHttp.responseText;
				if (check_len.length< 1050){ document.getElementById(_div_id).style.height="auto"; }else{ document.getElementById(_div_id).style.height="100px"; }
				
			}else if ((_xt==15) || (_xt==19)){

				document.getElementById(_div_id).innerHTML =xmlHttp.responseText;
				//send_data('null',18,available_amount_id);
				
			}else if (_xt==23){
				//alert(xmlHttp.responseText);
				document.getElementById(_div_id).innerHTML =xmlHttp.responseText;
				//send_data('null',26,available_amount_id);
				
			}else if(_xt==17){
				
				document.getElementById(_div_id).innerHTML =xmlHttp.responseText;
				document.getElementById(_div_id).style.display="";
				var check_len = xmlHttp.responseText;
				//alert(check_len);
				dropdown_status=_div_id;
				if (check_len.length<1800){ document.getElementById(_div_id).style.height="auto"; }else{ document.getElementById(_div_id).style.height="100px"; }
				
				refresh_business();
				
			}else if (_xt==18){

				document.getElementById(_div_id).innerHTML =xmlHttp.responseText;
				send_data('null',20,business_name_id);
				
			}else if ((_xt==22) || (_xt==33)){
			
				document.getElementById(_div_id).value =xmlHttp.responseText;
					
			}else if (_xt==21){
			
				// after getting invoice_deails for credit credit note , getting details for credit note
				document.getElementById(_div_id).innerHTML =xmlHttp.responseText;
				send_data('null',27,cn_details_client_id)
				
			}else if(_xt==30){
			
				document.getElementById(_div_id).style.display="";
				var check_len = xmlHttp.responseText;
				//alert("checklen" + check_len.length);
				if (check_len.length< 1500){ document.getElementById(_div_id).style.height="auto"; }else{ document.getElementById(_div_id).style.height="150px"; }
				document.getElementById(_div_id).innerHTML =xmlHttp.responseText;
				
			}else if(_xt==32){
			
				//on readjust transactiosn page once the item is selected 
				document.getElementById(_div_id).innerHTML =xmlHttp.responseText;
				show_data(item_selected_id,33,item_selected_id);
				
			}else if(_xt==34){
				
				//on business_change in add/edit cheque return gst|pup  to gst_val hidden variable
				document.getElementById(_div_id).value =xmlHttp.responseText;
				document.getElementById(amount_id).disabled = false;
				document.getElementById(pup_id).disabled = false;
				if (country_id == "1") {document.getElementById(gst_id).disabled = false;}
				//alert("this is done")
				update_gst();
				document.getElementById(amount_id).focus();
				document.getElementById(amount_id).focus();
								
			}else if(_xt==40){
				// getting business_dropdown_submited
				document.getElementById(_div_id).innerHTML =xmlHttp.responseText;
				//getting updated category name
				//send_data(trans_id,41,'c_'+trans_id);
				// get complete transaction updated 
				send_data('null',44,result_table);
			}else if(_xt==41){
				//got updated category name , remove trans_id 
				document.getElementById(_div_id).innerHTML =xmlHttp.responseText;
				trans_id ="";	
			}else if(_xt==42){
				document.getElementById(_div_id).innerHTML =xmlHttp.responseText;
				send_data('null',44,result_table);
			}else if(_xt==43){
				alert(xmlHttp.responseText);
				send_data('null',44,result_table);
			}else if((_xt==44)){
				// getting result for transaction list 
				document.getElementById(_div_id).innerHTML =xmlHttp.responseText;
				// fixing pager on its place
				//alert("from xjax" + cur_place);
				document.all['trans_pager'].scrollLeft=cur_place;
				// cleaning tooltip layer
				hidetip2();
				// trying to refresh and enter the details of searhc options
				//alert(dsearch_by);
				document.getElementById("search_by").value=dsearch_by;
				getsearchready(document.getElementById("search_by"));
				//document.getElementById("search_by").value=dsearch_by;
			}else if((_xt==36)){
				// getting result for transaction list 
				document.getElementById(_div_id).innerHTML =xmlHttp.responseText;
				// fixing pager on its place
				//alert("from xjax" + cur_place);
				document.all['trans_pager'].scrollLeft=cur_place;
				// cleaning tooltip layer
				hidetip2();
				// trying to refresh and enter the details of searhc options
				
			}else if((_xt==47) || (_xt==48)){
				// delete from ajax grid
				var ressss =xmlHttp.responseText;
				var ressss1 = ressss.split("|");
				document.getElementById(_div_id).innerHTML = ressss1[0];
				if(_xt==47) { if(ressss1[1]=="True"){ alert("Record has been deleted Sucessfully"); }else{ alert("Cannot Delete, May be connected to some other Data"); } }
				if (_xt==48){ if(ressss1[1]=="True"){ alert("All Records has been deleted Sucessfully"); }else{ alert("Cannot Delete All Records, May be some records are connected to some other Data"); } }
				//alert(ressss1[1]);
				hidetip2();
			}else if ((_xt==54) || (_xt==53)){
				document.getElementById(_div_id).innerHTML =xmlHttp.responseText;
				send_data("0",52,enter_budget_id);
			}else if ((_xt==56) || (_xt==60)){
				// 56 GETTING TRANSACTIONS UNDER CATEGORY FOR BUDGET REPORT 
				// 60 GETTING TRANSACTIONS UNDER CATEGORY FOR Job REPORT 
				//alert(xmlHttp.responseText);
				//alert(_div_id);
				document.getElementById(_div_id).innerHTML =xmlHttp.responseText;
				document.getElementById(_div_id).style.display ="";
			}else{
				document.getElementById(_div_id).innerHTML =xmlHttp.responseText;
			}*/
	} 
} 

function show_load_xt(xt){
	if (xt!="1"){ 
		show_load();
	}
}



	