var DomComp = (document.getElementById) // this will pick up the Dom 1 Compliant browsers such as IE 5 and Netscape 6.
var NS4 = (document.layers)?true:false;
var IE4 = (document.all && !document.getElementById)?true:false;

function _struct(child,childcaption,parent){
this.child = child;
this.childcaption = childcaption;
this.parent	= parent;
}

function _addobject(child,childcaption,parent){
var obj = new _struct();
obj.child = child;
obj.childcaption = childcaption;
obj.parent = parent;
return(obj);
}

function insertEntry(child,childcaption,parent){
	if(child.length > 0 ){		
		for(var i=0;i<this.length;i++)
			if(this.items[i].child == child)
				return;			
		this.items[this.length++] = _addobject(child,childcaption,parent);		
	}
}
function OptionCollection(){
this.length=0;
this.items = new Object();
this.Add=insertEntry
}

function clearSelect(oSelect){
var iCount=0;
if(!oSelect) return;
iCount = oSelect.options.length;
for(var i=0;i<iCount;i++){
	if(IE4) oSelect.options.remove(0);
	else if(NS4) oSelect.options[0]=null;
	else if(DomComp) oSelect.remove(0);
}
}

function addOptions(oSelect,olist,parent){
	var elOption;
	var idxSelect=0;	
	//check arguments.
	if((!olist) || (!oSelect)) return;		
	if(parent.length <=	0) 	return;
	//now looop through all the list items only entering relevant options.
	clearSelect(oSelect);	
	//add a blank list
	elBlankOption = new Option();
	elBlankOption.text = "";
	if(NS4) oSelect.options[0] = elBlankOption
	else if(IE4) oSelect.options.add(elBlankOption,0)
	elBlankOption.value = "";
	
	for(var i=0;i<olist.length;i++){		
		//only the child entries of the parent				
		if(olist.items[i].parent == parent){	
			elOption = new Option();
			//now IE and NS4 and NS6 have a different way to handle object creation.
			if(NS4){						
				elOption.value = olist.items[i].child
				elOption.text = olist.items[i].childcaption
				oSelect.options[idxSelect] = elOption				
			}else if(IE4){				
				elOption.value = olist.items[i].child
				elOption.text = olist.items[i].childcaption
				oSelect.options.add(elOption,idxSelect)					
			}else if(DomComp){
				elOption.value = olist.items[i].child
                elOption.text = olist.items[i].childcaption
                oSelect.options[oSelect.options.length]= elOption;  
			}					
			idxSelect++;
			//delete(elOption);
		}			
	}	
}

function UpdateSelect(szSelect,szForm,szParent,olist){
	if(IE4){addOptions(szSelect,olist,szParent);}
	else if(NS4) {addOptions(szSelect,olist,szParent);}
	else if(DomComp){addOptions(szSelect,olist,szParent);}
}

function UpdateBrands(objSelect) {
	var brandId = objSelect.options[objSelect.selectedIndex].value;
	var brandValue;
	var pos = 0;
	pos = brandId.indexOf("_",0);
	brandValue = brandId.substring(pos + 1,brandId.length);
	document.form_hotel.brand_search.value = brandValue;
}


function ReloadDropDown(frm,iLocation) {
	frm.cmbCountry.onchange();

	if (iLocation != ""){
		for(i=0;i<frm.cmbLocation.options.length;i++) {
			if(frm.cmbLocation.options[i].value == iLocation)  {
				frm.cmbLocation.selectedIndex=i;
			}
		}
	}
}

function selectOption(oSelect,value)
{
    var selected = false;
    for (i=0;i<oSelect.options.length;i++)
    {
        if (oSelect.options[i].value==value)
        {
            oSelect.options[i].selected= true;
            selected = true;    
        }
        else
            oSelect.options[i].selected = false;
    }
    if (!selected)
        oSelect.options[0].selected = true;
}//selectOption