function _Register() {
	
	this.onLoad = function() {
                 
	}
	
	this.buildManus = function(Industries, groupIndustry, array) {
		Register.groupIndustryID = groupIndustry;
		Register.industryFramesIDCounters[groupIndustry] = 0;
		Industries.forEach(Register.buildManu);
	}
	
	this.buildManu = function(element, index, array) {
		if (Register.industryFramesIDCounter > 0 && index == 1) return;
		var profile_industry = $('profile_industry_'+Register.groupIndustryID+'_'+Register.industryFramesIDCounters[Register.groupIndustryID]);
		if (!profile_industry) {
			alert(Register.groupIndustryID);
			alert(Register.industryFramesIDCounters[Register.groupIndustryID]);
		}
		profile_industry[profile_industry.length] = new Option(element, index, false)		
	}
	
	this.addNewIndustryMenu = function(groupIndustryID) {
		this.groupIndustryID = groupIndustryID;
		if (this.industryFramesIDCounters[groupIndustryID] >= 4) return
		this.industryFramesIDCounters[groupIndustryID]++;
		var newSelect = document.createElement('select');
		newSelect.name = 'profile_industry['+groupIndustryID+']['+this.industryFramesIDCounters[groupIndustryID]+']';
		newSelect.id = 'profile_industry_'+groupIndustryID+'_'+this.industryFramesIDCounters[groupIndustryID];
		$('IndustrySelects_'+groupIndustryID).appendChild(newSelect);
		GroupIndustries[groupIndustryID].forEach(this.buildManu);
		$('RemoveButton_'+groupIndustryID).style.display = '';
	}
	
	this.removeIndustryMenu = function(groupIndustryID) {
		var selectId = 'profile_industry_'+groupIndustryID+'_'+this.industryFramesIDCounters[groupIndustryID];
		var oldChild = $('IndustrySelects_'+groupIndustryID).removeChild($(selectId));
		this.industryFramesIDCounters[groupIndustryID]--;
		if (this.industryFramesIDCounters[groupIndustryID] == 0) $('RemoveButton_'+groupIndustryID).style.display = 'none';
	}
	
	this.groupIndustryChangeOld = function(groupIndustry) {
		$('talent_pool_'+groupIndustry).checked = 'checked';		
		for (var i=2; i<=10; i++) 
		{
			if (!$('GroupIndustryForm_'+i)) continue;
			$('TalentPoolLabel_'+i).className = $('TalentPoolLabel_'+i).className.replace('current','');
            //BlindUp all the menus TAKES TOO LONG! 
            /*var lists = $('RegistrationForm').getElementsByClassName("catlist");
            for (var j in lists)
            {
                if (!lists[j].id) continue;
                Effect.BlindUp(lists[j], {duration:0.1});
            }*/
		}
		
		if (document.forms['RegistrationForm'].GroupIndustryForm_2.style.display == 'block')
			document.forms['RegistrationForm'].GroupIndustryForm_2.style.display = 'none';
		if (document.forms['RegistrationForm'].GroupIndustryForm_3.style.display == 'block')
			document.forms['RegistrationForm'].GroupIndustryForm_3.style.display = 'none';
		if (document.forms['RegistrationForm'].GroupIndustryForm_4.style.display == 'block')
			document.forms['RegistrationForm'].GroupIndustryForm_4.style.display = 'none';
		if (document.forms['RegistrationForm'].GroupIndustryForm_5.style.display == 'block')
			document.forms['RegistrationForm'].GroupIndustryForm_5.style.display = 'none';
		if (document.forms['RegistrationForm'].GroupIndustryForm_6.style.display == 'block')
			document.forms['RegistrationForm'].GroupIndustryForm_6.style.display = 'none';
		if (document.forms['RegistrationForm'].GroupIndustryForm_10.style.display == 'block')
			document.forms['RegistrationForm'].GroupIndustryForm_10.style.display = 'none';
			
		switch (groupIndustry)
		{			
			case 2:
				document.forms['RegistrationForm'].GroupIndustryForm_2.style.display = 'block';
				break;
			case 3:
				document.forms['RegistrationForm'].GroupIndustryForm_3.style.display = 'block';
				break;
			case 4:
				document.forms['RegistrationForm'].GroupIndustryForm_4.style.display = 'block';
				break;
			case 5:
				document.forms['RegistrationForm'].GroupIndustryForm_5.style.display = 'block';
				break;
			case 6:
				document.forms['RegistrationForm'].GroupIndustryForm_6.style.display = 'block';
				break;
			case 10:
				document.forms['RegistrationForm'].GroupIndustryForm_10.style.display = 'block';
				break;
			
		}

		$('TalentPoolLabel_'+groupIndustry).className += ' current';
		this.unMarkAllIndustries('any');
	}
	
	this.groupIndustryChange = function(groupIndustry)
    {
        updateGeneralNoticeMessageJQ("Loading data...");
        changeOptions(groupIndustry, 'registration_profile_sub_group_id', 'RegistrationForm');
        closeGeneralNoticeJQ();
        for (var i=2; i<=10; i++)
		{
			if (!$('TalentPoolLabel_'+i)) continue;
			$('TalentPoolLabel_'+i).className = $('TalentPoolLabel_'+i).className.replace('current','');
		}
		$('TalentPoolLabel_'+groupIndustry).className += ' current';
	}

	this.showHide = function(fieldsetID)
    {
    	if (!$(fieldsetID)) return false;
        if ($(fieldsetID).style.display == 'none') Effect.BlindDown(fieldsetID, {duration:0.5});
    	else Effect.BlindUp(fieldsetID, {duration:0.5});
    }
    this.openList = function(x,tp)
    {
      b=$('list' + x + tp);
      this.showHide(b);  
    }
	
	this.unMarkAllIndustries = function(tp)
	{
       $('industrySelected_tp2').value = 0;
       $('industrySelected_tp3').value = 0;
       $('industrySelected_tp4').value = 0;
       $('industrySelected_tp5').value = 0;
       $('industrySelected_tp6').value = 0;
       $('industrySelected_tp10').value = 0;
       if (tp != '_tp2')
       {
           var checkboxes = $('RegistrationForm').getElementsByClassName('checkbox_tp2');
           for (var i in checkboxes)
           {
                checkboxes[i].checked = false;
           }
       }
       if (tp != '_tp3')
       {
           var checkboxes = $('RegistrationForm').getElementsByClassName('checkbox_tp3');
           for (var i in checkboxes)
           {
                checkboxes[i].checked = false;
           }
       }
       if (tp != '_tp4')
       {
           var checkboxes = $('RegistrationForm').getElementsByClassName('checkbox_tp4');
           for (var i in checkboxes)
           {
                checkboxes[i].checked = false;
           }
       }
       if (tp != '_tp5')
       {
           var checkboxes = $('RegistrationForm').getElementsByClassName('checkbox_tp5');
           for (var i in checkboxes)
           {
                checkboxes[i].checked = false;
           }
       }
       if (tp != '_tp6')
       {
           var checkboxes = $('RegistrationForm').getElementsByClassName('checkbox_tp6');
           for (var i in checkboxes)
           {
                checkboxes[i].checked = false;
           }
       }
       if (tp != '_tp10')
      {
	  var checkboxes = $('RegistrationForm').getElementsByClassName('checkbox_tp10');
	  for (var i in checkboxes)
	  {
	       checkboxes[i].checked = false;
	  }
       }
    }

    this.updateIndustrySelected = function(tp)
    {
       this.unMarkAllIndustries(tp);
       var n = 0;
       var checkboxes = $('RegistrationForm').getElementsByClassName('checkbox'+tp);
       for (var i in checkboxes)
       {
         if (checkboxes[i].checked)
         {
           n++;
         }
       }
       $('industrySelected'+tp).value = n;
    }
    
	this.selectAll = function(catId,tp)
    {
      var last = '';

      var catsArray = eval('category_'+catId+'_general');
      for (var i in catsArray)
      {
        var indId = catsArray[i];

        if ($('industry_'+indId+tp))
        {
            $('industry_'+indId+tp).checked = true;
            last = indId;
        }
      }
      $('industry_'+last+tp).checked = false;
      this.updateIndustrySelected(tp);
    }

    this.unselectAll = function(catId,tp)
    {
      var catsArray = eval('category_'+catId+'_general');
      for (var i in catsArray)
      {
        var indId = catsArray[i];
        if ($('industry_'+indId+tp))
        {
            $('industry_'+indId+tp).checked = false;

        }
      }
      this.updateIndustrySelected(tp);
    }

    this.selectOthers = function(catId,indId,tp)
    {
      if ($('suggested_'+catId+tp).value != '')
        $('industry_'+indId+tp).checked = true;
      else $('industry_'+indId+tp).checked = false;
      this.updateIndustrySelected(tp);
    }

    //'_professionals'

    this.selectAllProfessionals = function(catId,tp)
    {
      var last = '';

      var catsArray = eval('category_'+catId+'_professionals');
      for (var i in catsArray)
      {
        var indId = catsArray[i];

        if ($('industry_'+indId+tp))
        {
            $('industry_'+indId+tp).checked = true;
            last = indId;
        }
      }
      $('industry_'+last+tp).checked = false;
      this.updateIndustrySelected(tp);
    }

    this.unselectAllProfessionals = function(catId,tp)
    {
      var catsArray = eval('category_'+catId+'_professionals');
      for (var i in catsArray)
      {
        var indId = catsArray[i];
        if ($('industry_'+indId+tp))
        {
            $('industry_'+indId+tp).checked = false;

        }
      }
      this.updateIndustrySelected(tp);
    }
}

var Register = new _Register();
