// JScript File

var strPath = '/content/upload/AssetMgmt/inDirectorySearchXML/';
var tag = 'Designation';
var AjaxServerPageName = strPath + 'Desig-Realtors.xml' ;
var ctrlConst='inCtx11cboDirElem';

function AjaxCaller(ctrl, tag, pdir) {

	var obj = document.getElementById(ctrl);
	removeAllOptions(obj);

	if (pdir =='Affiliates') {AjaxServerPageName = strPath + 'Desig-Affiliates.xml' ;}
	if (pdir =='Realtors') {AjaxServerPageName = strPath + 'Desig-Realtors.xml';}
	if (pdir =='AffiliatesOffice') {AjaxServerPageName = strPath + 'Office-Affiliates.xml';}
	if (pdir =='RealtorsOffice') {AjaxServerPageName = strPath + 'Office-Realtors.xml';}

	var requestUrl = AjaxServerPageName;

	var ajax = new AjaxDelegate(requestUrl, CreateList, ctrl, tag);
	ajax.Fetch();
}


function CreateList(url, response, ctrl, tag) {
	var data = new Array();
	data =	response;

	var obj = document.getElementById(ctrl);
	//removeAllOptions(obj);
	loadXMLToDropdown(data, obj, tag);
}


function removeAllOptions(from) { 
	//remove all options
	var max = from.options.length
	
	for (var i=0; i<max; i++) {
		from.options[0] = null; 
	}
	from.selectedIndex = -1; 
} 

function loadXMLToDropdown(xml, dd, field) 
{
        var xmldoc, parser;
        var Elem;
        var destination="", addtext, addvalue;

        try{		// Internet Explorer
		xmldoc = new ActiveXObject("Microsoft.XMLDOM") 
		xmldoc.async = false 
		xmldoc.loadXML(xml)         

		Elem = xmldoc.getElementsByTagName(field) ; 
		Provlength = Elem.length; 
		for(i=0; i < Provlength; i++) 
		{ 
		    destination = Elem.item(i).text; 		    
		    addtext = destination; 
		    
		    //if (destination == "All") {destination=""}
		    //addvalue = destination; 
		    
		    addvalue = Elem.item(i).attributes.getNamedItem("value").nodeValue;
		    dd.options[i] = new Option(addtext,addvalue);                  
		}            
            
        }catch(e){	//Firefox, Mozilla, Opera, etc.                
            	parser = new DOMParser();
            	xmldoc = parser.parseFromString(xml,"text/xml");

		Elem = xmldoc.getElementsByTagName(field) ; 
        	Provlength = Elem.length;                        
        
		for(i=0; i < Provlength; i++) 
		{ 
		    destination = Elem[i].childNodes[0].nodeValue; 
		    addtext = destination; 
		    
		    //if (destination == "All") {destination=""}
		    //addvalue = destination; 

		    addvalue = Elem.item(i).attributes.getNamedItem("value").nodeValue;
		    dd.options[i] = new Option(addtext, addvalue);                  
		}
        	
        }

                              
} 


function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

// example of using trim, ltrim, and rtrim
//var myString = " hello my name is ";
//alert("*"+trim(myString)+"*");
//alert("*"+ltrim(myString)+"*");
//alert("*"+rtrim(myString)+"*");
