var html_progressbar = "<div style='float:left;z-index:10;'><img src='images/preloader2.gif'></div><div style='font:Arial, Helvetica, sans-serif; color:#3B73B9;'>&nbsp;&nbsp;Loading...</div>";
var html_progressbar_region = "<div style='font:Arial, Helvetica, sans-serif; color:#3B73B9;width:150px;font-size:11px;height: 30px;'>&nbsp;&nbsp;Loading...</div>";

function selectAjaxSubregion()
{
    contentPasteAt ="subregion";
    var subcat_id = document.frm.subcategory_id.value;
    var region_id = document.frm.region_id.value;
    //var url = "distributor_search_includeAjax.php?subcat_id=" + subcat_id + "&region_id=" + region_id;  
    var url = "get_subregion_ajax.php?subcat_id=" + subcat_id + "&region_id=" + region_id;  
    //alert(url);
    loadXMLDocDistributorSearch(url);
}
function selectAjaxSubregion_new()
{
    contentPasteAt ="subregion";
    document.getElementById("subregion").innerHTML = html_progressbar_region;	
    var subcat_id = document.frm.subcategory_id.value;
    var region_id = document.frm.region_id.value;
	//alert("region_id=="+region_id);
    var url = "distributor_search_includeAjax.php?subcat_id=" + subcat_id + "&region_id=" + region_id;  
    //var url = "get_subregion_ajax.php?subcat_id=" + subcat_id + "&region_id=" + region_id;  
    //alert(url);
    loadXMLDocDistributorSearch(url);
}

function showDistributorResult()
{
	document.getElementById("cont_id0").style.display = "none";
	document.getElementById("cont_id1").style.display = "none";
	document.getElementById("cont_id2").style.display = "none";
    contentPasteAt ="div_distributor_result";
    document.getElementById("div_distributor_result").innerHTML = html_progressbar;
    var region_id = document.frm.region_id.value;
    var sub_regions = document.getElementById("sub_regions").value;
	var subcategory_id = document.getElementById("subcategory_id").value;
    var url = "distributor_search_includeAjax.php?search=Search&region_id=" + region_id + "&sub_regions=" + sub_regions + "&subcategory_id="+subcategory_id;
   // alert(url);
    loadXMLDocDistributorSearchResult(url);
    //document.getElementById("div_footer_space").style.display="none";
    
}
/////////////////COMMON start/////////////////////////////////

function loadXMLDocDistributorSearch(url)
{
    // branch for native XMLHttpRequest object
    //alert(1);
    if (window.XMLHttpRequest)
    {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqDistributorSearch;
        req.open("GET", url, true);
        req.send(null);
        // branch for IE/Windows ActiveX version
    }
    else if (window.ActiveXObject)
    {
        req = new ActiveXObject("Microsoft.XMLHTTP"); 
        if (req)
        {
            req.onreadystatechange = processReqDistributorSearch;
            req.open("GET", url, true);
            req.send();
        }
    }
}

function processReqDistributorSearch()
{
    // only if req shows "complete"
    if (req.readyState == 4)
    {
        
        // only if "OK"
        if (req.status == 200)
        {
            response = req.responseXML.documentElement;
            var urlpath='';
            //alert(response.getElementsByTagName('testingnode')[0].childNodes[x].data); inside for loop

            for(var x = 0; response.getElementsByTagName('urlpath')[0].childNodes[x]; x++ )
                 urlpath = urlpath.concat(response.getElementsByTagName('urlpath')[0].childNodes[x].data);          
            document.getElementById(contentPasteAt).innerHTML = urlpath;
            // working
            var myCfe = new cfe.base(true);
            myCfe.init({spacer: "gfx/spacer.gif", toolTipsStyle: "normal"});
        }
        else
        {
            alert("There was a problem retrieving the XML data:\n" + req.statusText);
        }
    }
}


function loadXMLDocDistributorSearchResult(url)
{
    // branch for native XMLHttpRequest object
    //alert(1);
	
    if (window.XMLHttpRequest)
    {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqDistributorSearchResult;
        req.open("GET", url, true);
        req.send(null);
        // branch for IE/Windows ActiveX version
    }
    else if (window.ActiveXObject)
    {
        req = new ActiveXObject("Microsoft.XMLHTTP"); 
        if (req)
        {
            req.onreadystatechange = processReqDistributorSearchResult;
            req.open("GET", url, true);
            req.send();
        }
    }
}

function processReqDistributorSearchResult()
{
    // only if req shows "complete"
    if (req.readyState == 4)
    {
        
        // only if "OK"
        if (req.status == 200)
        {
            response = req.responseXML.documentElement;
            var urlpath='';var urlpath1='';var urlpath2='';
            //alert(response.getElementsByTagName('testingnode')[0].childNodes[x].data); inside for loop
			
			if (response) {
				for (var x = 0; response.getElementsByTagName('urlpath')[0].childNodes[x]; x++) 
					urlpath = urlpath.concat(response.getElementsByTagName('urlpath')[0].childNodes[x].data);
				
				document.getElementById(contentPasteAt).innerHTML = urlpath;
				document.getElementById("div_footer_space").style.display = "none";
			}
        }
        else
        {
            alert("There was a problem retrieving the XML data:\n" + req.statusText);
        }
    }
}


/****************************** End added by Nilaja **************************************************/