﻿ var isMozilla = (document.all) ? 0 : 1;
 
 function CityDataBind(cboreceiver, returnVal, selectedText, selectedValue) 
    {      
        cboreceiver.length = 0;
        CreateOptionElement(cboreceiver, selectedText, selectedValue, true);
        if (isMozilla) 
        {
            var parser = new DOMParser();
            xmlDOC = parser.parseFromString(returnVal, "text/xml");
        }
        else if (!isMozilla) 
        {
            xmlDOC = new ActiveXObject("Microsoft.XMLDOM");
            xmlDOC.async = "false";
            xmlDOC.loadXML(returnVal.toString());
        }
        xmlObj = xmlDOC.documentElement;
        if(xmlObj != null)
        {
            var citylen = xmlObj.childNodes.length;
            for (var i = 0; i < citylen; i++) 
            {
                var textfield = null;
                var valuefield = null;
                if (isMozilla) 
                {
                    if (citylen == 0) { textfield = ""; valuefield = ""; }
                    else 
                    { 
                        textfield = xmlObj.childNodes[i].childNodes[0].firstChild.textContent; 
                        valuefield = xmlObj.childNodes[i].childNodes[1].firstChild.textContent; 
                    }
                }
                else if (!isMozilla) 
                {
                    textfield = xmlObj.childNodes[i].childNodes[0].firstChild.text;
                    valuefield = xmlObj.childNodes[i].childNodes[1].firstChild.text;
                }
                
                CreateOptionElement(cboreceiver, textfield.toString(), valuefield.toString(), false);
            }
        }
     }
       
     function CreateOptionElement(p_dropdownlist, p_textfield, p_valuefield, p_isClear)
     {
        if(p_isClear == true)
        {
            p_dropdownlist.options.length = 0;
        }
        
        var opt = document.createElement('option');
        p_dropdownlist.options.add(opt);
        opt.text = p_textfield.toString();
        opt.value = p_valuefield.toString();
     }  
     
     function DropDownSelectedText(p_dropdown, p_selectedId)
     {
        p_dropdown.value = p_selectedId;
     }
     
    function $(id)
    {
        return document.getElementById(id);
    }
