NS4 = (document.layers) ? true : false;
delta = 1;
var jobArray = new Array();
var titleArray = new Array();
var job;
var ind;

coreTitles = new Array(
"Account Manager/Sales Rep;21",
"Analyst;22",
"Associate/Individual Contributor/Specialist;23",
"Assistant/Support Staff/CSR;24",
"Buyer;25",
"Chairman/CEO/COO;26",
"CFO;27",
"CIO/CTO;28",
"Counsel/Legal;29",
"Database Administrator;30",
"Systems Administrator;31",
"Network Administrator;32",
"Systems Architect;33",
"Programmer/Developer;34",
"Designer;35",
"Director/Sr Mgr;36",
"Engineer (non-IT);37",
"HR;38",
"Inspector;39",
"Producer;40",
"Project Mgr;41",
"Recruiter;42",
"Regional/General Mgr;43",
"Researcher/Scientist;44",
"Mgr/Supervisor;45",
"VP/Sr VP/Exec VP;46",
"Other;47"
);

function loadDefaults(i, j, s)
{
  if (i!='') {
      document.frmClientRegistration['.ind'].options[getValueIndex(document.forms['frmClientRegistration']['.ind'], i)].selected=true;
      setInd(document.forms['frmClientRegistration']['.ind']);
      document.forms['frmClientRegistration']['.job'].options[getValueIndex(document.forms['frmClientRegistration']['.job'], j)].selected=true;
      setJob(document.forms['frmClientRegistration']['.job']);
      document.forms['frmClientRegistration']['.spe'].options[getValueIndex(document.forms['frmClientRegistration']['.spe'], s)].selected=true;
  }
}
function loadDefaultJobs(i,j,s){
   if( i != '' ){
      document.forms['frmClientRegistration']['.job'].options[getValueIndex(document.forms['frmClientRegistration']['.job'], j)].selected=true;
      fillTitle(i);
      setJob(document.forms['frmClientRegistration']['.job']);
      document.forms['frmClientRegistration']['.spe'].options[getValueIndex(document.forms['frmClientRegistration']['.spe'], s)].selected=true;
   }
}
function loadDefaultSpecs(i,j,s){
   if( i != '' && j != '' ){
      document.forms['frmClientRegistration']['.spe'].options[getValueIndex(document.forms['frmClientRegistration']['.spe'], s)].selected=true;
      fillJob(j);
   }
}
function removeElement(arr, element)
{
	for(i=0; i<arr.length; i++){
		if(arr[i].search(';'+element)!=-1){
			arr1 = arr.slice(0, i);
			arr2 = arr.slice(i+1);
			arr = arr1.concat(arr2);
			return arr;
		}
	}
}
function getTitle(industry){
	titleArr = new Array(); 	
	titleArr=titleArr.concat(coreTitles);
	if(industry =='36'){
		titleArr=removeElement(titleArr, '25'); 
		titleArr=removeElement(titleArr, '39'); 
		titleArr=removeElement(titleArr, '44'); 
		var i0Arr = new Array(
"Art Director;48",
"Artist;49",
"Copywriter;50",
"Media Planner;51",
"Photographer;52",
"Creative Director;53");
		titleArr=i0Arr.concat(titleArr);
		return titleArr;
	}
	if(industry == '18'){
		titleArr=removeElement(titleArr, '40');	
		return titleArr;
	}
	if(industry == '19'){
		titleArr=removeElement(titleArr, '40');	
		titleArr=removeElement(titleArr, '35');	
		titleArr=removeElement(titleArr, '45');	
		var i2Arr = new Array(
"Laborer;54",
"Farmer;55",
"Rancher;56",
"Vintner;57");
		titleArr=i2Arr.concat(titleArr);
		return titleArr;
	
	}
	if(industry == '20') {
		titleArr=removeElement(titleArr, '40');	
		return titleArr;
	}
	if(industry == '21'){
		var i4Arr = new Array(
"Technical Support;58",
"Technical Writer;59");
		titleArr=i4Arr.concat(titleArr);
		return titleArr;
	}
	if(industry == '22'){
		titleArr=removeElement(titleArr, '45');	
		var i5Arr = new Array(
"Carpenter;60",
"Developer;61",
"Electrician;62",
"General Contractor;63",
"Laborer;54",
"Plumber;64");
		titleArr=i5Arr.concat(titleArr);
		return titleArr;
	}
	if(industry == '23'){
		titleArr=removeElement(titleArr, '44'); 
		var i6Arr = new Array(

"Artist;49",
"Copywriter;50",
"Media Planner;51",
"Photographer;52");
		titleArr=i6Arr.concat(titleArr);
		return titleArr;
	}
	if(industry == '24'){
		titleArr=removeElement(titleArr, '21');
                titleArr=removeElement(titleArr, '22'); 
		var i7Arr = new Array(
"Administration;65",
"Chancellor/Provost/Dean;66",
"Librarian;67",
"Professor;68",
"Student - College;69",
"Student - Graduate;70",
"Student - K-12;71",
"Teacher - High School;72",
"Teacher - K-8;73");
		titleArr=i7Arr.concat(titleArr);
		return titleArr;
	}
	if(industry == '25'){
		titleArr=removeElement(titleArr, '35');	
		titleArr=removeElement(titleArr, '40');	
		var i8Arr = new Array(
"Maintenance Worker;74",
"Miner;75",
"Driller;76");

		titleArr=i8Arr.concat(titleArr);
		return titleArr;
	}
	if(industry == '26'){
		titleArr=removeElement(titleArr, '39'); 
		titleArr=removeElement(titleArr, '40');	
		titleArr=removeElement(titleArr, '41');	
		titleArr=removeElement(titleArr, '44'); 
		var i9Arr = new Array(
"Accountant;77",
"Actuary;78",
"Banker;79",
"Broker/Dealer;80",
"Financial Planner;81",
"Insurance Agent - Commercial;82",
"Insurance Agent - Personal;83",
"Real Estate Developer;84",
"Realtor - Commercial;85",
"Realtor - Residential;86",
"Trader;87",
"Underwriter;88",
"Venture Capitalist;89");
		titleArr=i9Arr.concat(titleArr);
		return titleArr;
	}
	if(industry == '27'){
		titleArr=removeElement(titleArr, '21');
		titleArr=removeElement(titleArr, '27');
		titleArr=removeElement(titleArr, '28');
		titleArr=removeElement(titleArr, '35');	
		titleArr=removeElement(titleArr, '39'); 
		titleArr=removeElement(titleArr, '40');	
		titleArr=removeElement(titleArr, '43');	
		titleArr=removeElement(titleArr, '46');	
		var i10Arr = new Array(
"Assessor/Recorder;90",
"Enlisted Person;91",
"Firefighter;92",
"Judge;93",
"Legislator;94",
"Mayor;95",
"Officer;96",
"Police Officer/Sheriff;97");
		titleArr=i10Arr.concat(titleArr);
		return titleArr;
	}
	if(industry == '28'){
		titleArr=removeElement(titleArr, '35');	
		titleArr=removeElement(titleArr, '39'); 
		titleArr=removeElement(titleArr, '40');	
		titleArr=removeElement(titleArr, '44'); 
		var i11Arr = new Array(
"Chef;98",
"Event Planner;99",
"Food/Beverage Server;100",
"Guest Services;101",
"Security Officer;102",
"Trainer;103");
		titleArr=i11Arr.concat(titleArr);
		return titleArr;
	}
	if(industry == '29'){
		titleArr=removeElement(titleArr, '39'); 
		titleArr=removeElement(titleArr, '44'); 
		var i12Arr = new Array(
"Actor;104",
"Athlete;105",
"Model;106",
"Musician;107",
"Performer;108",
"Photographer;52",
"Singer;109",
"Writer;110");
		titleArr=i12Arr.concat(titleArr);
		return titleArr;
	}
	if(industry == '30'){
		titleArr=removeElement(titleArr, '36');	
		titleArr=removeElement(titleArr, '35');	
		titleArr=removeElement(titleArr, '39'); 
		titleArr=removeElement(titleArr, '40');	
		var i13Arr = new Array(
"Acupuncturist;111",
"Chiropractor;112",
"Dentist/Orthodontist;113",
"Dietitian/Nutritionist;114",
"Doctor - Asthma/Allergy;115",
"Doctor - Cardiology;116",
"Doctor - Dermatology;117",
"Doctor - Gastroenterology;118",
"Doctor - Internal/Primary Care;119",
"Doctor - OB/GYN;120",
"Doctor - Oncology;121",
"Doctor - Ophthalmology;122",
"Doctor - Orthopedics;123",
"Doctor - Other;124",
"Doctor - Otolaryngology;125",
"Doctor - Pediatrics;126",
"Doctor - Psychiatry;127",
"Doctor - Radiology;128",
"Doctor - Surgery;129",
"Nurse;130",
"Pharmacist;131",
"Physical Therapist;132",
"Physicians' Assistant;133",
"Psychologist;134",
"Veterinarian;135");
		titleArr=i13Arr.concat(titleArr);
		return titleArr;
	}
	if(industry == '31'){
		titleArr=removeElement(titleArr, '40');	
		var i14Arr = new Array(
"Artist;49",
"Copywriter;50",
"Pharmacist;131",
"Doctor;136");
		titleArr=i14Arr.concat(titleArr);
		return titleArr;
	}
	if(industry == '33'){
		titleArr=removeElement(titleArr, '29'); 
		titleArr=removeElement(titleArr, '39'); 
		titleArr=removeElement(titleArr, '41');	
		var i15Arr = new Array(
"Accountant;77",
"Actuary;78",
"Architect;137",
"Attorney - Antitrust;138",
"Attorney - Corporate;139",
"Attorney - Criminal Law;140",
"Attorney - Cyberlaw;141",
"Attorney - Employment/Labor;142",
"Attorney - Environment;143",
"Attorney - Intellectual Property;144",
"Attorney - International;145",
"Attorney - Taxation;146",
"Consultant - Management;147",
"Consultant - Marketing;148",
"Consultant - Systems/IT;149",
"Event Planner;99",
"Interior Designer;150",
"Paralegal;151",
"Partner/Owner;152",
"Religious;153",
"Technical Support;58",
"Technical Writer;59");
		titleArr=i15Arr.concat(titleArr);
		return titleArr;
	}
	if(industry == '32'){
		var i16Arr = new Array(
"Artist;49",
"Copywriter;50",
"Photographer;52",
"Merchandiser;154",
"Security Officer;102",
"Small Business Owner/Operator;155");
		titleArr=i16Arr.concat(titleArr);
		return titleArr;
	}
	if(industry == '34'){
		titleArr=removeElement(titleArr, '40');	
		var i17Arr = new Array(
"Maintenance Worker;74",
"Installer;156");
		titleArr=i17Arr.concat(titleArr);
		return titleArr;
	}
	if(industry == '35'){
		titleArr=removeElement(titleArr, '39'); 
		titleArr=removeElement(titleArr, '44'); 
		var i18Arr = new Array(
"Driver;157",
"Flight Attendant;158",
"Maintenance Worker;74",
"Pilot;159",
"Railroad Engineer;160",
"Security Officer;102",
"Ship Captain;161",
"Tour Guide;162",
"Travel Agent;163");
		titleArr=i18Arr.concat(titleArr);
		return titleArr;
	}
	return titleArr;
}	

corporateFunction = new  Array(
"Advertising/Marketing/PR;1",
"Accounting/Finance;2",
"Engineering - IT;3",
"Engineering (non-IT);4",
"Operations or Manufacturing;5",
"Procurement;6",
"Research/Product Development;7",
"Sales;8");
itFunction = new Array(
"Computer: CRM;9",
"Computer: Database;10",
"Computer: Multimedia/Gaming;11",
"Computer: Networking;12",
"Computer: Security;13",
"Computer: Storage;14");
nonItEng = new Array(
"Aerospace;15",
"Chemical;16",
"Civil;17",
"Electrical;18",
"Environmental;19",
"Human Factors;20",
"Industrial/Manufacturing;21",
"Mechanical;22",
"Nuclear;23",
"Quality;24",
"Semiconductor;25",
"Traffic;26");
noFunction = new Array("[No Selection Necessary];");

function getJobFunction(title){
	if(title == '23'
		|| title == '36'
		|| title == '41'
		|| title == '43'
		|| title == '45'
		|| title == '46'){
		return corporateFunction ;
	}
	if( title == '30'
		|| title == '31'
		|| title == '32'
		|| title == '33'
		|| title == '149'
		|| title == '34'){
		return itFunction;
	}
	if( title == '37'){
		return nonItEng;
	}
	return noFunction;
}

function GetSelectedText(box){
  var boxText = '';
  for(var i=0; i<box.options.length; i++){
    if(box.options[i].selected && box.options[i].value != ''){
      boxText = box.options[i].value;
    }
  }
  return boxText;
}

function getValueIndex(box, value){
  for(var i=0; i<box.options.length; i++){
    if(box.options[i].value == value)
       return i;
  }
  return 0;
}

function compare(s1, s2){
	var t1 = s1.toLowerCase();
	var t2 = s2.toLowerCase();
	if(t1 < t2){
		return -1;
	}
	if(t1 > t2){
		return 1;
	}
	return 0;
}
function fillTitle(industry){
  document.forms['frmClientRegistration']['.job'].length=1;
  var cnt = 1;
  var isSelected = false;
  var arr = getTitle(industry);
  arr.sort(compare);
  //document.forms['frmClientRegistration']['.job'].length=arr.length+1;

  for(var n=0; n<arr.length; n++){
        newOpt=new Option;
	i = arr[n].search(';');
        newOpt.value=arr[n].slice(i+1);
        newOpt.text=arr[n].slice(0,i);
	if (!isSelected){
	  //newOpt.selected = true;
	  isSelected = true;
	}
	document.forms['frmClientRegistration']['.job'].options[cnt]=newOpt;
	cnt=cnt+1;
  }
/*  if(NS4){
    window.resizeBy(delta, delta);
    delta = -1*delta;
  } */
}

function fillJob(title){
  document.forms['frmClientRegistration']['.spe'].length=0;
  var cnt =0;
  var isSelected = false;
  var arr = getJobFunction(title);
  if(arr.length != 1){
	var tmp = new Array("[Select a Specialization];-1");
	arr = tmp.concat(arr);
  }
  for(var n=0; n<arr.length; n++){
        newOpt=new Option;
	i = arr[n].search(';');
        newOpt.value=arr[n].slice(i+1);
        newOpt.text=arr[n].slice(0,i);
        if (!isSelected){
	  newOpt.selected = true;
	  isSelected = true;
	}
	document.forms['frmClientRegistration']['.spe'].options[cnt]=newOpt;
	cnt=cnt+1;
   }
   if(!(NS4)){
    if(arr.length != 1){
	document.forms['frmClientRegistration']['.spe'].style.visibility = 'visible';

    }else{
	document.forms['frmClientRegistration']['.spe'].style.visibility = 'hidden';
    }
   } // not Netscapoe 4
/*  if(NS4){
    window.resizeBy(delta, delta);
    delta = -1*delta;
  } */
}

function setInd(box) {
  ind = GetSelectedText(box);
  if(ind != ''){
    fillTitle(ind);
  }
  //alert(ind);
}

function setJob(box) {
  title = GetSelectedText(box);
  //alert(job);
  if(ind != ''){
    doIt();
  }
}

function doIt(){
  if(ind != '' && title != ''){
    fillJob(title);
  } else {
    //alert("You must select your Industry and Title");
  }
}
 
 
