function LoadSubControl(ddlControl,ddlSubControl,hidSubControl,text,table) 
{    
    ddlControl.disabled="disabled"; 
    ClearItems(ddlSubControl,text);
    if(ddlControl.selectedIndex > 0)
    {   
        BindData(ddlSubControl,table,ddlControl.value); 
    }
    ddlControl.disabled=false; 
    
    hidSubControl.value = "-1";
}

function SetHiddenValue(ddlControl,hidControl)//Set value for hidden field by control
{
    hidControl.value = ddlControl.value;    
}

function LoadDefaultControl(ddlSubType,ddlCity)
{
   if(ddlSubType!= null && ddlSubType.length < 2)
   {
       ClearItems(ddlSubType,"All Sub types"); 
   }
    
   if(ddlCity!= null && ddlCity.length < 2)
   {
       ClearItems(ddlCity,"All Cities");           
   }
}

function AddNewListItem(text, value,objTarget)
{  
  if (!isExist(objTarget, text, value))
  {	    
    //Add new option 
    tLength = objTarget.options.length;
    objTarget.options[tLength] = new Option(text,value);       
    AddListItem(objTarget, text, value);
  }
}

function RemoveOldListItem(objTarget) 
{
    if(objTarget.selectedIndex > -1)
    { 
        RemoveListItem(objTarget,objTarget.value);
        objTarget.remove(objTarget.selectedIndex);
    }
    return false;
}

//added by HoangDT 01-02-2012                           
function LoadDdlCity(ddlControl,ddlSubControl,hidSubControl,text,table,AustraliaGeneralID)
{
    ddlControl.disabled="disabled"; 
    ClearItems(ddlSubControl,text);
    if(ddlControl.selectedIndex > 0)
    {   
        //BindData(ddlSubControl,table,ddlControl.value); 
        var xmlHttpObj = CreateXmlHttpRequestObject();
        if (xmlHttpObj)
        {
            // Obtain a reference to the <SELECT> drop list control.
            var ddl = ddlSubControl;
            ddl.disabled=true;
            // We want this request synchronous
            xmlHttpObj.open("GET", rootURL + "AJAXServer.ashx?ajaxAct=" + table + "&id=" + ddlControl.value, true);

            xmlHttpObj.onreadystatechange = function()
            {
                if (xmlHttpObj.readyState == READYSTATE_COMPLETE)
                {   
                    // If the request was ok (ie. equal to a Http Status code of 200)            
                    if (xmlHttpObj.status == HTTPSTATUS_OK)
                    {   
                        var xmlDoc = xmlHttpObj.responseXML;
                        var nodeLocation = xmlDoc.getElementsByTagName('root');
                        for(i = 0; i < nodeLocation.length; i ++)
                         {
                            htmlCode = document.createElement('option');
                            ddl.options.add(htmlCode);
                            if (window.ActiveXObject)
                            {
                                htmlCode.text = nodeLocation[i].childNodes[1].childNodes[0].nodeValue;
                                htmlCode.value = nodeLocation[i].childNodes[0].childNodes[0].nodeValue;
                            }
                            else
                            {   
                                htmlCode.text = nodeLocation[i].childNodes[2].childNodes[0].nodeValue;
                                htmlCode.value = nodeLocation[i].childNodes[1].childNodes[0].nodeValue;
                            }                                
                         }
                         ddl.disabled = false;
                         
                         //added by HoangDT 01-02-2012
                         //if state is 'Australia General' then choose the city named '-' and set value for hidden field
                        if(ddlControl.value == AustraliaGeneralID)
                        {
                            if(ddlSubControl.options[0].value == '-1')
                            {
                                ddlSubControl.remove(0);
                            }
                            for(var i = 0; i < ddlSubControl.options.length; i++)
                            {            
                                if(ddlSubControl.options[i].text == '-')
                                {
                                    ddlSubControl.selectedIndex = i;
                                    ddlSubControl.options[i].selected = true;
                                    hidSubControl.value = ddlSubControl.options[i].value;
                                }
                            }
                        }
                    }
                }
            }                   
        }
        // Execute the request            
        xmlHttpObj.send("SomeDataToSend"); 
    }
    else
    {
        hidSubControl.value = "-1";
    }
    ddlControl.disabled=false; 
}
