// Show and hide submenu

function ShowHide(id, display) {
alert(display);
    obj = document.getElementsByTagName("div");
    obj[id].style.display = display;
}

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);
}


function lstSelectAll(controlid)
{
    var control = getObj(controlid);    
    if(control)
    {    
        for(i=0; i< control.options.length; i++)
        {
            control.options[(control.options.length-1)-i].selected = true;
        }
    }
    
}

function lstDeselectAll(controlid)
{
    var control = getObj(controlid);
    if(control)
    {    
        for(i=0; i< control.options.length; i++)
        {
            control.options[i].selected = false;
        }
    }
}

function getObj(name)
{
  if (document.getElementById)
  {
  	return document.getElementById(name);	
  }
  else if (document.all)
  {
	return document.all[name];
  }
  else if (document.layers)
  {
    return document.layers[name];
  }
}

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 updateJobRoleDDL(jobroleddlid, sectorid)
{    
    var jobroleddl = document.getElementById(jobroleddlid);
    var idzerooptiontext = null;
    var selectedids = '|';
        
    if (jobroleddl.options.length > 0 && parseInt(jobroleddl.options[0].value) === 0) {
        idzerooptiontext = jobroleddl.options[0].text;
    }
      
    for (var i=0; i<jobroleddl.options.length; i++) {        
        if (jobroleddl.options[i].selected)
        {
          selectedids +=  jobroleddl.options[i].value + '|'
        }
    }
    
    jobroleddl.options.length = 0;
    
    for (var i=0; i<jobroleoptionspersector['ss:' + sectorid].length; i++) {
        var o = jobroleoptionspersector['ss:' + sectorid][i];
        var newopt = document.createElement("option");
        newopt.value = o[0];
        newopt.innerText = o[1];
        newopt.text = o[1];
        jobroleddl.appendChild(newopt);
    }

    setTimeout(function () { setJobRoleDDLSelection(jobroleddlid,selectedids) }, 5); // setTimeout req'd for IE6

    return;    
}

function setJobRoleDDLSelection(jobroleddlid,values)
{    
    var jobroleddl = document.getElementById(jobroleddlid);
    
    for (var i=0; i<jobroleddl.options.length; i++) {        
        if (values.indexOf('|' + jobroleddl.options[i].value + '|') > -1)
        {        
            jobroleddl.options[i].selected = true;
        }
    }
     
}


function updateLocationDDL(locationddlid, regionid)
{
    var locationddl = document.getElementById(locationddlid);
    var idzerooptiontext = null;
    var selectedids = '|';
    
    if (locationddl.options.length > 0 && parseInt(locationddl.options[0].value) === 0) {
        idzerooptiontext = locationddl.options[0].text;
    }
    
    for (var i=0; i<locationddl.options.length; i++) {        
        if (locationddl.options[i].selected)
        {
          selectedids +=  locationddl.options[i].value + '|'
        }
    }
    
    locationddl.options.length = 0;
        
    for (var i=0; i<locationoptionsperregion['ss:' + regionid].length; i++) {
        var o = locationoptionsperregion['ss:' + regionid][i];
        var newopt = document.createElement("option");
        newopt.value = o[0];
        newopt.innerText = o[1];
        newopt.text = o[1];
        locationddl.appendChild(newopt);
    }

    setTimeout(function () { setLocationDDLSelection(locationddlid,selectedids) }, 5); // setTimeout req'd for IE6

    return;    
}

function setLocationDDLSelection(locationddlid,values)
{    
    var locationddl = document.getElementById(locationddlid);
    
    for (var i=0; i<locationddl.options.length; i++) {        
        if (values.indexOf('|' + locationddl.options[i].value + '|') > -1)
        {        
            locationddl.options[i].selected = true;
        }
    }
}

