﻿// 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 updateSalaryBandDDL(salarybandddlid, primaryid, salarybandcontainerid)
{
    var salarybandddl = document.getElementById(salarybandddlid);
    var idzerooptiontext = null;
    var selectedids = '|';
    
    if (salarybandddl.options.length > 0 && parseInt(salarybandddl.options[0].value) === 0) {
        idzerooptiontext = salarybandddl.options[0].text;
    }
    
    for (var i=0; i<salarybandddl.options.length; i++) {        
        if (salarybandddl.options[i].selected)
        {
          selectedids +=  salarybandddl.options[i].value + '|'
        }
    }
    
    salarybandddl.options.length = 0;
    if(salarybandsperjobtype['sb:' + primaryid])
    {
        for (var i=0; i<salarybandsperjobtype['sb:' + primaryid].length; i++) {
            var o = salarybandsperjobtype['sb:' + primaryid][i];
            var newopt = document.createElement("option");
            newopt.value = o[0];
            newopt.innerText = o[1];
            newopt.text = o[1];
            salarybandddl.appendChild(newopt);
        }    
        if( document.getElementById(salarybandcontainerid) )
        {
            document.getElementById(salarybandcontainerid).style.display = '';
        }
    } else {
        if( document.getElementById(salarybandcontainerid) )
        {
            document.getElementById(salarybandcontainerid).style.display = 'none';
        }
    }
    
    
    setTimeout(function () { setSalaryBandDDLSelection(salarybandddlid,selectedids) }, 5); // setTimeout req'd for IE6

    return;    
}

function setSalaryBandDDLSelection(salarybandddlid,values)
{    
    var salarybandddl = document.getElementById(salarybandddlid);
    
    for (var i=0; i<salarybandddl.options.length; i++) {        
        if (values.indexOf('|' + salarybandddl.options[i].value + '|') > -1)
        {        
            salarybandddl.options[i].selected = true;
        }
    }
     
}

function setSalaryRateVisibility(salarybandddlid,ratebandddlid,rate)
{  
    var salarybandddl =  document.getElementById(salarybandddlid);
    var ratebandddl =  document.getElementById(ratebandddlid);    
    salarybandddl.style.display = '';
    ratebandddl.style.display = '';    
    if (rate == 1) {
        salarybandddl.style.display = 'none';
    }
    if (rate == 0) {
        ratebandddl.style.display = 'none';
    }
}

function setSalaryRateVisibilityByJobTypeID(salarybandddlid,ratebandddlid,jobtypeid)
{    
    setSalaryRateVisibility(salarybandddlid,ratebandddlid,eval('jobtype' + jobtypeid + 'rate'));
}



function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
	{
	    // The index() method calculates the index from a
	    // given index who is out of the actual item range.
	    var idx = carousel.index(i, mycarousel_itemList.length);
	    carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
 
	    // Pause autoscrolling if the user moves with the cursor over the clip.
	    carousel.clip.hover(function() {
	        carousel.stopAuto();
	    }, function() {
	        carousel.startAuto();
	    });
	};
 
	function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
	{
	    carousel.remove(i);
	};
 
 
	function mycarousel_getItemHTML(item)
	{
	    return '<a href="' + item.link  +'"><img src="' + item.url + '" width="156" height="81" alt="' + item.title + '" /></a>';
	};	

function updateJobRoleList(subsectorddlid, sectorid)
{
    var subsectorddl = document.getElementById(subsectorddlid);
    var idzerooptiontext = null;
    var selectedids = '|';
    
    if (subsectorddl.options.length > 0 && parseInt(subsectorddl.options[0].value) === 0) {
        idzerooptiontext = subsectorddl.options[0].text;
    }
    
    for (var i=0; i<subsectorddl.options.length; i++) {        
        if (subsectorddl.options[i].selected)
        {
          selectedids +=  subsectorddl.options[i].value + '|'
        }
    }
    
    subsectorddl.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];
        subsectorddl.appendChild(newopt);
    }

    setTimeout(function () { setJobRoleListSelection(subsectorddlid,selectedids) }, 5); // setTimeout req'd for IE6

    return;    
}

function setJobRoleListSelection(subsectorddlid,values)
{    
    var subsectorddl = document.getElementById(subsectorddlid);
    
    for (var i=0; i<subsectorddl.options.length; i++) {        
        if (values.indexOf('|' + subsectorddl.options[i].value + '|') > -1)
        {        
            subsectorddl.options[i].selected = true;
        }
    }
     
}

/* TEAM CAROUSEL */
function myteamcarousel_itemVisibleInCallback(carousel, item, i, state, evt)
{
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    var idx = carousel.index(i, myteamcarousel_itemList.length);
    carousel.add(i, myteamcarousel_getItemHTML(myteamcarousel_itemList[idx - 1]));

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

function myteamcarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{
    carousel.remove(i);
};


function myteamcarousel_getItemHTML(item)
{
    return '<a href="' + item.link + '"><img src="' + item.url + '" width="180" height="168" alt="' + item.title + '" /></a>';
};

