/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
var AjaxReturncontent="";
var http = createRequestObject();
// if response type is XML output will get in the formate of XML.
var HTTPResponceXML;
// if responce type is TEXt you get the result in th normale formate.
var HTTPResponceTEXT;
var AjaxURLStatus=false;
var test=""
var DisplayID="";
function createRequestObject() {
    // find the correct xmlHTTP, works with IE, FF and Opera
    var xmlhttp;
    try {
        xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e) {
        try {
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(e) {
            xmlhttp=null;
        }
    }
    if(!xmlhttp&&typeof XMLHttpRequest!="undefined") {
        xmlhttp=new XMLHttpRequest();
    }
    return  xmlhttp;
}

//function sendRequest(ResType,url,ReadRetunValues,OutPutDiv) {
function sendRequestXML(ResType,url,OutPutDiv) {
	
    DisplayID=OutPutDiv;
    try{
    //   document.getElementById(DisplayID).innerHTML="<img src='../images/loading.gif' alt='loading...'/>";
    }catch(e){
        
    }
    // document.getElementById(DisplayID).innerHTML='loading...';
    //alert("");
    ResType=ResType.toLowerCase();
   
    HTTPResponceXML="";
    HTTPResponceTEXT="";

    //To acceess fress page on every request
    var rnd = Math.random();
    

    url+="&count="+rnd;
    // url="creditinformationByMemberIndustryId.php?MID=TFP3689514&IID=MI_1&EditOptions=false&count=0.6817256404555232";
    //alert(url)
        
    try{
        http.open("GET", url, true);
        http.setRequestHeader('content-type',  "text/xml");
        
        if(ResType=="text")
        {
            http.onreadystatechange = handleResponseTEXT;
            try{
                msg (DisplayID, "error",AjaxReturncontent);
            }catch(e){}
        }
        if(ResType=="xml")
        {
            http.onreadystatechange = handleResponseXML;
        }
        http.send(null);
    }
    catch(e){
         
        
    //alert('Request send failed.'+e);
    }
     
    return HTTPResponceTEXT;
 
 
}
//---------------------------------****************************************-----------------------------

function handleResponseTEXT() {

    try{

        if (http.readyState==4 || http.readyState=="complete")
        {


            AjaxURLStatus=true;

            //************** ******************** YOUr Data will come here..........
            // alert(http.responseText );
            HTTPResponceTEXT=http.responseText ;
            //Write all the final process in this method(outside)
            //ReadRetunValues(HTTPResponceTEXT)
            try{
                if(DisplayID!="")
                {
                    //alert(HTTPResponceTEXT);
                    document.getElementById(DisplayID).innerHTML=HTTPResponceTEXT;
                    //  alert( document.getElementById(DisplayID).innerHTML)
                    AjaxReturncontent=document.getElementById(DisplayID).innerHTML;
                    //alert("");
                    document.getElementById("dispayCatcount_search").innerHTML="";
                }
            }catch(e)
            {
                 
            }
			 
        // FinalProcess(HTTPResponceTEXT);
        //************** ******************** YOUr Data END here..........








        }
        else
        {
            AjaxURLStatus=false;
        }
    }
    catch(e){
    //alert(e)
    // caught an error
    //alert('Response failed.');
    }
//alert(HTTPResponceTEXT);
//  return HTTPResponceTEXT;
  
}
//---------------------------------****************************************-----------------------------

function handleResponseXML() {
    
    try{
        
        if((http.readyState == 4)&&(http.status == 200))
        {

            if(http.responseXML != null)
            // success!
            {





                //************** ******************** YOUr Data will come here..........
                HTTPResponceXML=http.responseXML;
                FinalProcess(HTTPResponceXML);
            //var result = http.responseXML.getElementsByTagName('FRUIT')[0].firstChild.nodeValue;
            //  alert(result);
            //************** ******************** YOUr Data end here..........





            }
            else{
                alert("Responce is in Invalid XML Formate or  Responce XML is NULL");
            }


      
        }
    }
    catch(e){
    //  alert(e)
    // caught an error
    //alert('Response failed.');
    }
     
}

