// Show and hide Sectors

function ShowHide(id, display) {
    obj = document.getElementsByTagName("div");
    obj[id].style.display = display;
}


function rotateBannerSlot(container, bannercount, interval)
{                
    if ( bannercount > 0 ) 
    {
        for (var CurrentBanner = 0; CurrentBanner <= bannercount-1; CurrentBanner++)
        {
            if( document.getElementById( container + '_bn' + CurrentBanner).style.display != 'none' )
            {
                break;
            }
        }
        var RandomNumber=Math.floor(Math.random() * (bannercount-1));
        if(RandomNumber >= CurrentBanner)
        {
            RandomNumber++;
        }
        document.getElementById( container + '_bn' + CurrentBanner).style.display = 'none';
        document.getElementById( container + '_bn' + RandomNumber).style.display = '';
        window.setTimeout("rotateBannerSlot('"+container+"',"+bannercount+","+interval+")",interval);
    }
}



function updateDDLs(subsecddlid, countryid)
{
    var subsecddl = document.getElementById(subsecddlid);
    var idzerooptiontext = null;
    var selectedid = null;
    
    if (subsecddl.options.length > 0 && parseInt(subsecddl.options[0].value) === 0) {
        idzerooptiontext = subsecddl.options[0].text;
    }
        
    if (subsecddl.selectedIndex >= 0) {
        selectedid = parseInt(subsecddl.options[subsecddl.selectedIndex].value, 10);
    }
        
    subsecddl.options.length = 0;
    
    
    if (idzerooptiontext !== null) {
        var newopt = document.createElement("option");
        newopt.value = 0;
        newopt.innerText = idzerooptiontext;
        newopt.text = idzerooptiontext;
        subsecddl.appendChild(newopt);
        if (selectedid === 0) {
            setTimeout(function () { subsecddl.selectedIndex = 0}, 5); // setTimeout req'd for IE6
        }
    }    
    
    for (var i=0; i < locationspercountry['cty:' + countryid].length; i++) {
        var o = locationspercountry['cty:' + countryid][i];
        var newopt = document.createElement("option");
        newopt.value = o[0];
        newopt.innerText = o[1];
        newopt.text = o[1];
        subsecddl.appendChild(newopt);
        if (selectedid === o[0]) {
            var selectedidx = subsecddl.options.length-1;
            setTimeout(function () { subsecddl.selectedIndex = selectedidx}, 5); // setTimeout req'd for IE6
        }
    }
    
    
    
//    var titleddl = document.getElementById(titleddlid);
//    var idzerooptiontext2 = null;
//    var selectedid2 = null;
//    
//    if (titleddl.options.length > 0 && parseInt(titleddl.options[0].value) === 0) {
//        idzerooptiontext2 = titleddl.options[0].text;
//    }
//    
//    if (titleddl.selectedIndex >= 0) {
//        selectedid2 = parseInt(titleddl.options[titleddl.selectedIndex].value, 10);
//    }
//    
//    
//    titleddl.options.length = 0;
//    
//    if (idzerooptiontext2 !== null) {
//        var newopt = document.createElement("option");
//        newopt.value = 0;
//        newopt.innerText = idzerooptiontext2;
//        newopt.text = idzerooptiontext2;
//        titleddl.appendChild(newopt);
//        if (selectedid2 === 0) {
//            setTimeout(function () { titleddl.selectedIndex = 0}, 5); // setTimeout req'd for IE6
//        }
//    }
//    
//    for (var i=0; i < titleoptionspersector['sec:' + countryid].length; i++) {
//        var o = titleoptionspersector['sec:' + countryid][i];
//        var newopt = document.createElement("option");
//        newopt.value = o[0];
//        newopt.innerText = o[1];
//        newopt.text = o[1];
//        titleddl.appendChild(newopt);
//        if (selectedid2 === o[0]) {
//            var selectedidx2 = titleddl.options.length-1;
//            setTimeout(function () { titleddl.selectedIndex = selectedidx2}, 5); // setTimeout req'd for IE6
//        }
//    }

    return;    
}




function doWhenElementAvailable(elementid, func, delay)
{
    delay = delay || 0;

	var timerid = setInterval(function () {
		var node = document.getElementById(elementid);

		if (node) {
			clearInterval(timerid);
			setTimeout(func, delay);
		}
	}, 100);
}
