var xmlHttp;
function fetchSubCompanies(coId)
{
    showPopUp("dialog"); 
    document.getElementById("subCompanies").innerHTML='<img src="images/ajax.gif"> <small>در حال جستجو</small>';
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url=BaseUrl+"sub_companies.php?coId="+coId;
    xmlHttp.onreadystatechange=function(){
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
        {
            if(xmlHttp.responseText)
                document.getElementById("subCompanies").innerHTML=xmlHttp.responseText;
            else
                document.getElementById("subCompanies").innerHTML="موردی یافت نشد!";
        } 
    };
    xmlHttp.open("GET",encodeURI(url),true);
    xmlHttp.send(null);
    return 0;
}
function showPopUp(el) {
    var cvr = document.getElementById("cover")
    var dlg = document.getElementById(el)
   cvr.style.display = "block"
    dlg.style.display = "block"
    if (document.body.style.overflow = "hidden") {
        cvr.style.width = "100%"
        cvr.style.height = "100%"
    }
}
function closePopUp(el) {
    var cvr = document.getElementById("cover")
    var dlg = document.getElementById(el)
    cvr.style.display = "none"
    dlg.style.display = "none"
    document.body.style.overflowY = "scroll"
}

function serach_company(source_city)
{ 
    document.getElementById("search_company_list").innerHTML='<img src="images/ajax.gif"> <small>در حال جستجو</small>';
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request");
        return;
    }
    var url=BaseUrl+"company.php?source_city="+source_city;
    xmlHttp.onreadystatechange=search_company_list;
    xmlHttp.open("GET",encodeURI(url),true);
    xmlHttp.send(null);
    return 0;
}

function search_company_list()
{ 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
        if(xmlHttp.responseText)
            document.getElementById("search_company_list").innerHTML=xmlHttp.responseText;
        else
            document.getElementById("search_company_list").innerHTML="موردی یافت نشد!";
    } 
}

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;
}
