function openHelpWindow(strUrl){
	popWin = window.open(strUrl,'helpWin','height=300,width=400,scrollbars=yes');
	popWin.focus();
}




//##############################################################################################
//############################### Event handleres  start #######################################

	function Grade_onchange(){
		var objGradeSelect = document.forms[0].fmGrade;
		var objStepSelect = document.forms[0].fmStep;
		var intSelectedIndex = objGradeSelect.selectedIndex;
		
		strGrade = objGradeSelect.options[intSelectedIndex].value;
		//alert(strGrade)
		
		//reset intStep
		intStep = 0;
		
		var regEx = /G\d{1}/
		if(regEx.test(strGrade)){
			blnIsGSstaff = true;
		}
		else{
			blnIsGSstaff = false;
		}	
		
		// activate Step
		if(intSelectedIndex > 0){
			document.forms[0].fmStep.disabled = false;
		}
		else{
			document.forms[0].fmStep.disabled = true;
		}
		
		// if  Step select has options delete all
		if(objStepSelect.options.length > 1){
			for(var i = objStepSelect.options.length; i>=1;i--){
				objStepSelect.options[i]= null;
			}
		}
		
		// get index in Grades array
		for(var i=0;i<Grades.length;i++){
			if(Grades[i].Name.indexOf('G')!=-1 && Grades[i].Name.length == 2){
				if(Grades[i].Name == strGrade){
					intGradesIndex = i;
					break;
				}
			}
			else{
				if(Grades[i].Name == strGrade && Grades[i].DependantRate == blnIsDepandent){
					intGradesIndex = i;
					break;
				}
			}
		}
		
		// get levels for selected grade
		var objTmp = Grades[intGradesIndex];
		var itm, intStepCount;
		intStepCount = 1;
		for(var itm in objTmp){
			if(itm.indexOf('L')!= -1){
				if(objTmp[itm]>0){
					objStepSelect.options[objStepSelect.options.length] = new Option(itm.substring(1),intStepCount)
					//alert(intStepCount)
					intStepCount++;
				}
			}
		}
		
		// display divIsSmRr
		

		if(strGrade.indexOf('D1') != -1 || strGrade.indexOf('D2') != -1 || strGrade.indexOf('P4') != -1 || strGrade.indexOf('P5') != -1){
			// Added by Henrik Juul
			if(agency  == 'unicef'){
				//alert("unicef");
				document.getElementById('divIsSmRr').style.display = 'none';
			}
			else{
				//alert("not unicef");
				document.getElementById('divIsSmRr').style.display = 'block';
			}
		}
		else{
			document.getElementById('divIsSmRr').style.display = 'none';
		}
		
		
		
		
		if(blnIsGSstaff){
			displayLanguageSelects(true);
			document.forms['frmForm'].fmJpoPension.options[0].selected = true;
			document.getElementById('divJpoPension').style.display = 'none';
			document.getElementById('spanGroupLifeInsurance').innerHTML = strGroupLifeInsurance;
		}
		else{
			displayLanguageSelects(false);
		}
		
				
		// display SecondDependant div
		displaySecondDependant();
		// display LanguageAllowance 
		displayLanguageAllowance();
		//display Row RepresentationAllowance
		displayRowRepresentationAllowance();
		// display displayAssignmentGrant
		displayAssignmentGrant();
		//display MobilityHardship
		displayMobilityHardship();
		//display DivDsa()
		displayDivDsa();
		
		// if Grade is G-staff preselect Ds New York Id = 4560
		setDStoNewYork();
		
		
		//set ContractOptions
		setContractOptions();

		
		
		// recalculated value
		reCalc();
	}

	function DutyStaion_onchange(){
		if(document.forms['frmForm'].fmDutyStation.selectedIndex > 0){
			strDutyStation = document.forms['frmForm'].fmDutyStation.options[document.forms['frmForm'].fmDutyStation.selectedIndex].value;
			// we have a default option so we deduct 1 to be in sunc with arrays
			intDutyStationSelectedIndex = document.forms['frmForm'].fmDutyStation.selectedIndex - 1;
			strDutyStationCountryCode = DutyStations[intDutyStationSelectedIndex].CountryCode;
		
			//reset msa rate
			fltMsaRate = 0;		
			getApaToDutystation();
			// get DSA or MSA
			//fmSolaFirst fmSolaSecond
			getSolaRates();
			if(document.forms[0].fmSolaFirst.options.length > 0){
			
			for(var i=0;i<document.forms[0].fmSolaFirst.options.length;i++){
				if(document.forms[0].fmSolaFirst.options[i].text  == strDutyStation){
					document.forms[0].fmSolaFirst.options[i].selected=true;
					break;
				}
			}
			
			
			//	document.forms[0].fmSolaFirst.options[0].selected = true;
				SolaFirst_onchange();
			}
			//display DivDsa
			displayDivDsa();
			setClassification();
			// set text of divMobilityHeader
			setDivMobilityHeaderText();
			// get options for insurance select
			setfmInsuranceOption();
			// recalculated value
			// get PostAjustment
			if(!blnHasAPA){
				fltPostAdjustment = DutyStations[intDutyStationSelectedIndex].PostAdjustMultiplier;
			}
			else{
				//alert(objApaDs.PostAdjustMultiplier)
				fltPostAdjustment = objApaDs.PostAdjustMultiplier
			}
			setPostAdjustment();
			reCalc();
		}
		else{
			strDutyStation = '';
			intDutyStationSelectedIndex = 0;
			strDutyStationCountryCode = '';
			strAPA = '';
			blnHasAPA = false;
			fltPostAdjustment = 0
			fltPostAdjustmentCalculated = 0
			fltMobilityHardshipAllowanceCalculated = 0
			fltSpecialLivingAllowanceFirst = 0
			fltSpecialLivingAllowanceSecond = 0
			fltMsaRate = 0
			strClassification = '';
			
			getApaToDutystation();
			
			objApaDs = new DutyStation();
			setDivMobilityHeaderText();
			setClassification();
			setPostAdjustment();
			getMobilityHardshipAllowance()
			
			reCalc();
		}
	}
	
	function Step_onchange(){
		intStep = document.forms['frmForm'].fmStep.options[document.forms['frmForm'].fmStep.selectedIndex].value;
		//fltNetBaseSalary = intStep;
		// recalculated value
		reCalc();
	}
	
	function IsSmRr_onchange(){
		intSmRr = document.forms['frmForm'].fmIsSmRr.options[document.forms['frmForm'].fmIsSmRr.selectedIndex].value;
		if(intSmRr > 0){
			blnIsSmRr = true;
		}
		else{
			blnIsSmRr = false;
		}
		//display Row RepresentationAllowance
		displayRowRepresentationAllowance();
		// recalculated value
		reCalc();
	}
	
	
		function ContractType_onchange(){
		strContractType = document.forms['frmForm'].fmContractType.options[document.forms['frmForm'].fmContractType.selectedIndex].value;
	
		if(strContractType == 'JPO'){
			document.getElementById('divJpoPension').style.display = 'block';
			document.getElementById('spanGroupLifeInsurance').innerHTML = strGroupLifeInsuranceJpo;
		}
		else{
			document.getElementById('divJpoPension').style.display = 'none';
			document.getElementById('spanGroupLifeInsurance').innerHTML = strGroupLifeInsurance;
		}
		// recalculated value
		reCalc();
	}
	
	function JpoPension_onchange(){
		var intTmp = document.forms['frmForm'].fmJpoPension.options[document.forms['frmForm'].fmJpoPension.selectedIndex].value;
		if(intTmp == 1){
			blnJpoPension = true;
		}
		else{
			blnJpoPension = false;
		}
		// recalculated value
		reCalc();
	}
	
	function MaritalStatus_onchange(){
		intMaritalStatus = document.forms['frmForm'].fmMaritalStatus.options[document.forms['frmForm'].fmMaritalStatus.selectedIndex].value;
		// recalculated value
		reCalc();
	} 
	
	function DependentSpouse_onchange(){
		intDependentSpouse = document.forms['frmForm'].fmDependentSpouse.options[document.forms['frmForm'].fmDependentSpouse.selectedIndex].value;
		
		if(intDependentSpouse != 2){
			document.forms['frmForm'].fmSecondaryDependant.options[0].selected = true;
		}
		
		// is there a dependent
		setIsDepandent();
		// display SecondDependant div
		displaySecondDependant();
		// recalculated value
		reCalc();
	}
	
	function DependentChild_onchange(){
		intDependentChild = document.forms['frmForm'].fmDependentChild.options[document.forms['frmForm'].fmDependentChild.selectedIndex].value;
		// is there a dependent
		setIsDepandent();
		// recalculated value
		reCalc();
	}
	
	function SecondaryDependant_onchange(){
		intSecondaryDependant = document.forms['frmForm'].fmSecondaryDependant.options[document.forms['frmForm'].fmSecondaryDependant.selectedIndex].value;
		// recalculated value
		reCalc();
	}
	
	function Classification_onchange(){
		strClassification = document.forms['frmForm'].fmClassification.options[document.forms['frmForm'].fmClassification.selectedIndex].value;
		// recalculated value
		reCalc();
	}
	
	function NoOfAssignments_onchange(){
		intNoOfAssignments = document.forms['frmForm'].fmNoOfAssignments.options[document.forms['frmForm'].fmNoOfAssignments.selectedIndex].value;
		// recalculated value
		reCalc();
	}
	
	function Insurance_onchange(){
		//intInsurance is only set here if dutystation is US, othervise value is set in "setfmInsuranceOption()"
		intInsurance = document.forms['frmForm'].fmInsurance.options[document.forms['frmForm'].fmInsurance.selectedIndex].value;
		// recalculated value
		reCalc();
	}
	
	function LanguageAllowance_onchange(){
		var intTmp = document.forms['frmForm'].fmLanguageAllowance.options[document.forms['frmForm'].fmLanguageAllowance.selectedIndex].value;
		if(intTmp == 1){
			blnLanguageAllowance = true;
		}
		else{
			blnLanguageAllowance = false;
		}
		// recalculated value
		reCalc();
	}
	
	function NumberOfLanguage_onchange(){
		intNumberOfLanguage = document.forms['frmForm'].fmNumberOfLanguage.options[document.forms['frmForm'].fmNumberOfLanguage.selectedIndex].value;
		// recalculated value
		reCalc();
	}
	function PostAdjustment_onchange(){
		fltPostAdjustment = document.forms['frmForm'].fmPostAdjustment.value;
		fltPostAdjustment = fltPostAdjustment.replace(/\,/gi,'.')
		document.getElementById('spanPostAdjustment').innerHTML = fltPostAdjustment;
		// recalculated value
		reCalc();
	}
	function SpecialLivingAllowanceFirst_onchange(){
		document.getElementById('spanFirst30Days').innerHTML = '$ ' + document.forms[0].fmSpecialLivingAllowanceFirst.value;
		fltSpecialLivingAllowanceFirst = 30 * document.forms[0].fmSpecialLivingAllowanceFirst.value;
		// recalculated value
		reCalc();
	}
	function SpecialLivingAllowanceSecond_onchange(){
		// recalculated value
		reCalc();
	}
	function SolaFirst_onchange(){
		var strSelectText
		strSelectText = document.forms[0].fmSolaFirst.options[document.forms[0].fmSolaFirst.selectedIndex].text
			for(var i = 0;i<DsaRates.length;i++){
				if((DsaRates[i].CountryName + ', ' + DsaRates[i].Name) == strSelectText && parseInt(DsaRates[i].Type) == 1){
					document.forms[0].fmSpecialLivingAllowanceFirst.value = DsaRates[i].USDAmount;
				}
				if((DsaRates[i].CountryName + ', ' + DsaRates[i].Name) == strSelectText && parseInt(DsaRates[i].Type) == 2){
					document.forms[0].fmSpecialLivingAllowanceSecond.value = DsaRates[i].USDAmount;
				}
			}
		reCalc();
	}
	
	function fmAPA_onChange(){
		strAPA = document.forms[0].fmAPA.options[document.forms[0].fmAPA.selectedIndex].text;
		fltMsaRate = document.forms[0].fmAPA.options[document.forms[0].fmAPA.selectedIndex].value;
		for(i=0;i<DutyStations.length;i++){
			if((DutyStations[i].Country + ', ' + DutyStations[i].City).indexOf(strAPA) != -1){
				objApaDs = DutyStations[i];
			}
		}
		setClassification();
		fltPostAdjustment = objApaDs.PostAdjustMultiplier;
		setPostAdjustment();
		reCalc();
	}

//############################### Event handleres  end  ########################################
//##############################################################################################

//##############################################################################################
//############################### Calculations  start  #########################################
	function getDentalInsurance(){
	var fltTmp = 0;
		if(intInsurance > 0 && strDutyStationCountryCode.indexOf('USA')!=-1){
			if(intNumberOfDependents == 0){
					fltTmp = (fltNetBaseSalary - 0 + fltPostAdjustmentCalculated) / 100 * InsuranceEnums[6].SmOnly;
					if(fltTmp > (InsuranceEnums[6].SmOnlyMax/100*InsuranceMaxDeduction)){
						fltDentalInsuranceValue = (InsuranceEnums[6].SmOnlyMax/100*InsuranceMaxDeduction)
					}
					else{
						fltDentalInsuranceValue = fltTmp
					}
				}
				else if(intNumberOfDependents == 1){
					fltTmp = (fltNetBaseSalary - 0 + fltPostAdjustmentCalculated) / 100 * InsuranceEnums[6].SmOneDependent;
					if(fltTmp > (InsuranceEnums[6].SmOneDependentMax/100*InsuranceMaxDeduction)){
						fltDentalInsuranceValue = (InsuranceEnums[6].SmOneDependentMax/100*InsuranceMaxDeduction)
					}
					else{
						fltDentalInsuranceValue = fltTmp
					}
				}
				else if(intNumberOfDependents >= 2){
					fltTmp = (fltNetBaseSalary - 0 + fltPostAdjustmentCalculated) / 100 * InsuranceEnums[6].SmTwoDependent;
					if(fltTmp > (InsuranceEnums[6].SmTwoDependentMax/100*InsuranceMaxDeduction)){
						fltDentalInsuranceValue = (InsuranceEnums[6].SmTwoDependentMax/100*InsuranceMaxDeduction)
					}
					else{
						fltDentalInsuranceValue = fltTmp
					}
				}
				else{
					fltDentalInsuranceValue = 0;
				}
			}
		else{
			fltDentalInsuranceValue = 0;
		}
		if(!document.forms[0].optDentalInsurance.checked){
			fltDentalInsuranceValue = 0;
		}
		document.forms[0].fmDentalInsuranceValue.value = get2DigetRounded(fltDentalInsuranceValue);
	}
	

	function resetHardship(){
		document.forms[0].fmNoOfAssignments.options[0].selected = true;
		intNoOfAssignments = 0;
		document.forms[0].fmClassification.options[0].selected = true;
		strClassification = '';
	}

function getNetBaseSalary(){
	if(intStep>0){
		for(var i = 0;i<Grades.length;i++){
			if(Grades[i].Name == strGrade && Grades[i].DependantRate == blnIsDepandent){
				fltNetBaseSalary = eval('Grades[i].L' + intStep)
				break;
			}
		}
	}
	else{
		fltNetBaseSalary = 0;
	}
	document.forms['frmForm'].fmNetBaseSalary.value = get2DigetRounded(fltNetBaseSalary);
}

function getTotalEarnings(){
	var tmpTotalEarnings = 0;
	tmpTotalEarnings = fltNetBaseSalary - 0;
	tmpTotalEarnings += fltPostAdjustmentCalculated;
	tmpTotalEarnings += fltDependencyAllowance;
	tmpTotalEarnings += fltLanguageAllowanceCalculated;
	tmpTotalEarnings += fltRepresentationAllowanceCalculated;
	tmpTotalEarnings += fltMobilityHardshipAllowanceCalculated;

	fltTotalEarnings = tmpTotalEarnings;
	document.forms['frmForm'].fmTotalEarnings.value = get2DigetRounded(tmpTotalEarnings);
}
function getTotalDeductions(){
	fltTotalDeductions = fltPensionFundValue - 0;
	fltTotalDeductions += fltMedicalAndDentalInsuranceValue;
	fltTotalDeductions += fltGroupLifeInsuranceValue;
	fltTotalDeductions  += fltDentalInsuranceValue;
	
	document.forms['frmForm'].fmTotalDeductions.value = get2DigetRounded(fltTotalDeductions);
}

//intMaritalStatus
//intDependentSpouse
//intDependentChild

function getDependencyAllowance(){
	var tmpReturn = 0;
	var regEx = /G\d{1}/
	if(regEx.test(strGrade)){
	
		if(intDependentSpouse == 1){
			tmpReturn = DependencyAllowances[3].Value;
		}
		if(intDependentChild > 0 && (intMaritalStatus == 2 || intMaritalStatus == 4 || intMaritalStatus == 5)){
			tmpReturn += ((parseInt(intDependentChild) - 1) * DependencyAllowances[1].Value) + DependencyAllowances[2].Value;
		}
		if(intDependentChild > 0 && (intMaritalStatus == 1 || intMaritalStatus == 3)){
			tmpReturn += intDependentChild * DependencyAllowances[1].Value;
		}
	}
	else{
		if(intDependentSpouse == 1){
			tmpReturn = intDependentChild * DependencyAllowances[0].Value;
		}
		if(intDependentSpouse == 2){
			tmpReturn =  (parseInt(intDependentChild) - 1)  * DependencyAllowances[0].Value;
		}

	}
	if(tmpReturn<0){
		tmpReturn = 0;
	}
	fltDependencyAllowance = tmpReturn;

	document.forms['frmForm'].fmDependencyAllowanceCalculated.value = get2DigetRounded(fltDependencyAllowance);
}

function getSecondaryDependant(){
	var regEx = /G\d{1}/
	if(intSecondaryDependant == 1){
		if(regEx.test(strGrade)){
			fltDependencyAllowance += DependencyAllowances[4].Value;
		}
		else{
			fltDependencyAllowance += DependencyAllowances[5].Value;
		}
	}
	/*else{
		if(fltDependencyAllowance > 0){
			if(regEx.test(strGrade)){
				fltDependencyAllowance -= DependencyAllowances[4].Value;
			}
			else{
				fltDependencyAllowance -= DependencyAllowances[5].Value;
			}
		}
	}*/
	
	document.forms['frmForm'].fmDependencyAllowanceCalculated.value = get2DigetRounded(fltDependencyAllowance);
}

function getLanguageAllowance(){
	//fltLanguageAllowanceCalculated
	var regEx = /G\d{1}/
	if(regEx.test(strGrade)){
		if(blnLanguageAllowance){
			if(intNumberOfLanguage == 1){
				fltLanguageAllowanceCalculated = LanguageAllowanceses[0].Value;
			}
			else if(intNumberOfLanguage == 2){
				fltLanguageAllowanceCalculated = LanguageAllowanceses[0].Value + LanguageAllowanceses[1].Value;
			}
			else{
				fltLanguageAllowanceCalculated = 0;
			}
		}
		else{
			fltLanguageAllowanceCalculated = 0;
		}	
	}
	document.forms['frmForm'].fmLanguageAllowanceCalculated.value = get2DigetRounded(fltLanguageAllowanceCalculated);
}

function getRepresentationAllowance(){
	if(blnIsSmRr && strDutyStation != ''){
		for(var i=0;i<RepresentationAllowances.length;i++){
			if(strDutyStation.indexOf(RepresentationAllowances[i].DutyStation) != -1){
				fltRepresentationAllowanceCalculated = RepresentationAllowances[i].Allowance * 1000;
				document.getElementById('spanRepresentationAllowance').innerHTML = strRepresentationAllowanceTrue;
				break;
			}
			else{
				fltRepresentationAllowanceCalculated = 0;
				document.getElementById('spanRepresentationAllowance').innerHTML = strRepresentationAllowanceError;
			}
		}
	}
	else{
		var regEx = /ASG|USG/
		if(regEx.test(strGrade) && !blnIsSmRr){
			document.getElementById('spanRepresentationAllowance').innerHTML = strRepresentationAllowanceUSGASG;
		}
		if(!regEx.test(strGrade) && !blnIsSmRr){
			document.getElementById('spanRepresentationAllowance').innerHTML = strRepresentationAllowanceTrue;
		}
		
		fltRepresentationAllowanceCalculated = 0;
	}
	document.forms['frmForm'].fmRepresentationAllowanceCalculated.value = get2DigetRounded(fltRepresentationAllowanceCalculated);
}

function getPensionFund(){
	var intTmp = 0;
	if(strGrade != '' && intStep > 0){
		for(var i=0;i<PensionableRemunerations.length;i++){
			if(PensionableRemunerations[i].Name.toString().indexOf(strGrade)!=-1){
				intTmp = eval('PensionableRemunerations[i].L' + intStep);
				fltPensionFundValue = (intTmp/100)*SmContributionRate;
				break;
			}
			else{
				fltPensionFundValue = 0;
			}
		}	
	}
	else{
		fltPensionFundValue = 0;
	}
	if(!blnJpoPension && strContractType.indexOf('JPO')!= -1){
		fltPensionFundValue = 0;
	}
	document.forms['frmForm'].fmPensionFundValue.value = get2DigetRounded(fltPensionFundValue);
}

function getMedicalAndDentalInsurance(){
	var fltTmp = 0;
	if(intInsurance > 0){
		if(intNumberOfDependents == 0){
			fltTmp = (fltNetBaseSalary - 0 + fltPostAdjustmentCalculated) / 100 * InsuranceEnums[intInsurance].SmOnly;
			if(fltTmp > (InsuranceEnums[intInsurance].SmOnlyMax/100*InsuranceMaxDeduction)){
				fltMedicalAndDentalInsuranceValue = (InsuranceEnums[intInsurance].SmOnlyMax/100*InsuranceMaxDeduction)
			}
			else{
				fltMedicalAndDentalInsuranceValue = fltTmp
			}
		}
		else if(intNumberOfDependents == 1){
			fltTmp = (fltNetBaseSalary - 0 + fltPostAdjustmentCalculated) / 100 * InsuranceEnums[intInsurance].SmOneDependent;
			if(fltTmp > (InsuranceEnums[intInsurance].SmOneDependentMax/100*InsuranceMaxDeduction)){
				fltMedicalAndDentalInsuranceValue = (InsuranceEnums[intInsurance].SmOneDependentMax/100*InsuranceMaxDeduction)
			}
			else{
				fltMedicalAndDentalInsuranceValue = fltTmp
			}
		
		}
		else if(intNumberOfDependents >= 2){
			fltTmp = (fltNetBaseSalary - 0 + fltPostAdjustmentCalculated) / 100 * InsuranceEnums[intInsurance].SmTwoDependent;
			if(fltTmp > (InsuranceEnums[intInsurance].SmTwoDependentMax/100*InsuranceMaxDeduction)){
				fltMedicalAndDentalInsuranceValue = (InsuranceEnums[intInsurance].SmTwoDependentMax/100*InsuranceMaxDeduction)
			}
			else{
				fltMedicalAndDentalInsuranceValue = fltTmp
			}
		
		}
		else{
			fltMedicalAndDentalInsuranceValue = 0;
		}
	}
	else{
		fltMedicalAndDentalInsuranceValue = 0;
	}
	document.forms['frmForm'].fmMedicalAndDentalInsuranceValue.value = get2DigetRounded(fltMedicalAndDentalInsuranceValue);
}

function getGroupLifeInsuranceValue(){
	var fltTmp = 0;
	//fltGroupLifeInsuranceValue
	if(strGrade != '' && intStep > 0){
		for(var i=0;i<PensionableRemunerations.length;i++){
			if(PensionableRemunerations[i].Name.toString().indexOf(strGrade)!=-1){
				fltTmp = eval('PensionableRemunerations[i].L' + intStep);
				fltGroupLifeInsuranceValue = (fltTmp/100)*GliRate*12;
				if(fltGroupLifeInsuranceValue > GliRateMax){
					fltGroupLifeInsuranceValue = GliRateMax;
				}
				break;
			}
			else{
				fltGroupLifeInsuranceValue = 0;
			}
		}	
	}
	else{
		fltGroupLifeInsuranceValue = 0;
	}
	// if jpo fltGroupLifeInsuranceValue = 0
	if(strContractType.indexOf('JPO') != -1){
		fltGroupLifeInsuranceValue = 0;
	}
	if(!document.forms['frmForm'].optGroupLife.checked){
		fltGroupLifeInsuranceValue = 0;
	}
	document.forms['frmForm'].fmGroupLifeInsuranceValue.value = get2DigetRounded(fltGroupLifeInsuranceValue);
}

function getNumberOfDependents(){
	var intTmp = new Number(0)
	/*
	<option value="1">Common-law</option>
	<option value="2">Divorced</option>
	<option value="3">Married</option>
	<option value="4">Single</option>
	<option value="5">Widowed</option>
	*/
	//Single-2 Divorced-4 Widowed-4
	if((intDependentSpouse-0) == 1){
		if(intMaritalStatus != 0 && intMaritalStatus != 2 && intMaritalStatus != 4 && intMaritalStatus != 5){
			intTmp += 1;
		}
	}
	if(intDependentChild > 0){
		intTmp += intDependentChild - 0;
	}
	intNumberOfDependents = intTmp
}

function getSalyryAfterDeduction(){
	//fltAnnualSalaryAfterDeductions
	//fltMonthlySalaryAfterDeductions
	//var fltTotalEarnings
	//fltTotalDeductions
	fltAnnualSalaryAfterDeductions = fltTotalEarnings - fltTotalDeductions;
	fltMonthlySalaryAfterDeductions = fltAnnualSalaryAfterDeductions/12;
	document.forms['frmForm'].fmAnnualSalaryAfterDeductions.value = get2DigetRounded(fltAnnualSalaryAfterDeductions);
	document.forms['frmForm'].fmMonthlySalaryAfterDeductions.value = get2DigetRounded(fltMonthlySalaryAfterDeductions);
}
function calcSola(){
		if(fltMsaRate == 0){
			document.getElementById('spanAfter30Days').innerHTML = '$ ' + document.forms[0].fmSpecialLivingAllowanceSecond.value;
			fltSpecialLivingAllowanceSecond = 30 * 12 * document.forms[0].fmSpecialLivingAllowanceSecond.value;
		}
		else{
			document.getElementById('spanAfter30Days').innerHTML = '$ ' + fltMsaRate;
			fltSpecialLivingAllowanceSecond = 30 * 12 * fltMsaRate;
		}
}
function getPostAdjustment(){
	if(fltNetBaseSalary > 0){
		fltPostAdjustmentCalculated = (fltNetBaseSalary/100)*fltPostAdjustment;
		document.forms['frmForm'].fmPostAdjustmentCalculated.value = get2DigetRounded(fltPostAdjustmentCalculated);
	}
	else{
		fltPostAdjustmentCalculated = 0;
		document.forms['frmForm'].fmPostAdjustmentCalculated.value = get2DigetRounded(0);
	}
}
function setPostAdjustment(){
	document.forms['frmForm'].fmPostAdjustment.value = fltPostAdjustment;
	document.getElementById('spanPostAdjustment').innerHTML = fltPostAdjustment;
	if(blnIsGSstaff){
		document.getElementById('fieldsetfPostAdjustment').style.display= 'none';
		document.getElementById('rowPostAdjustment').style.display= 'none';
		fltPostAdjustment = 0;
		document.forms['frmForm'].fmPostAdjustment.value = fltPostAdjustment;
		document.getElementById('spanPostAdjustment').innerHTML = fltPostAdjustment;
		document.getElementById('divDutyStationNotis').style.display= 'block';
		document.getElementById('divDutyStationNotis').innerHTML = strDutyStationNotis;
	}
	else{
		document.getElementById('fieldsetfPostAdjustment').style.display= 'block';
		document.getElementById('rowPostAdjustment').style.display= 'block';
		document.getElementById('divDutyStationNotis').style.display= 'none';
		document.getElementById('divDutyStationNotis').innerHTML = '';
	}
}
function setClassification(){
	for(var i = 0;i<document.forms['frmForm'].fmClassification.options.length;i++){
		if(blnHasAPA){
			if(document.forms['frmForm'].fmClassification.options[i].value == getApaHardship()){
				document.forms['frmForm'].fmClassification.options[i].selected = true;
				strClassification = getApaHardship()
			}
		}
		else{
			if(document.forms['frmForm'].fmClassification.options[i].value == DutyStations[intDutyStationSelectedIndex].Hardship){
				document.forms['frmForm'].fmClassification.options[i].selected = true;
				strClassification = DutyStations[intDutyStationSelectedIndex].Hardship
			}
		}
	}
	if(strDutyStation==''){
		document.forms['frmForm'].fmClassification.options[0].selected = true;
	}
}
function getApaHardship(){
	var strHardShip = ''
	if(blnHasAPA){
		objApaDs = new DutyStation(); 
		for(var i=0;i<DutyStations.length;i++){
			if((DutyStations[i].Country + ', ' + DutyStations[i].City).indexOf(strAPA) != -1){
				strHardShip = DutyStations[i].Hardship;
				objApaDs = DutyStations[i]; 
				break;
			}
		}
	}
	else{
		strHardShip = DutyStations[intDutyStationSelectedIndex].Hardship;
	}	
	return strHardShip;
}

function getMobilityHardshipAllowance(){

	// get ohter grades than G
	var regEx = /G\d{1}/
	if(!regEx.test(strGrade) && strGrade != ''){
		// is there selected a classification and a number of assignments
		if(strClassification != '' && intNoOfAssignments > 0){
			// loop rates
			for(var i=0;i<MobilityHardshipAllowances.length;i++){
				if(MobilityHardshipAllowances[i].Category.toString().indexOf(strClassification) != -1 && MobilityHardshipAllowances[i].Levels.toString().indexOf(strGrade) != -1 && !MobilityHardshipAllowances[i].Removal){
					if(blnIsDepandent){	
						fltMobilityHardshipAllowanceCalculated = eval('MobilityHardshipAllowances[i].D' + intNoOfAssignments)
					}
					else{
						fltMobilityHardshipAllowanceCalculated = eval('MobilityHardshipAllowances[i].S' + intNoOfAssignments);
					}
					break;
				}
				else{
					fltMobilityHardshipAllowanceCalculated = 0;
				}
			}
		}
		else{
			fltMobilityHardshipAllowanceCalculated = 0;
		}
	}
	else{
		fltMobilityHardshipAllowanceCalculated = 0;
	}
	document.forms['frmForm'].fmMobilityHardshipAllowanceCalculated.value = get2DigetRounded(fltMobilityHardshipAllowanceCalculated)
}
function getMsaRate(){
	for(var i = 0;i<SolaRates.length;i++){
		if(SolaRates[i].DutyStation == strDutyStation && strAPA == SolaRates[i].APA){
			if(SolaRates[i].LivingAllowance == 'MSA'){
				fltMsaRate = SolaRates[i].Rate;
				break;
			}
			else{
				fltMsaRate = 0;
			}
		}
	}
	document.forms[0].fmSpecialLivingAllowanceSecond.value = fltMsaRate;
}
function getSpecialLivingAllowance(){
	if(strAPA != ''){
		document.getElementById('divSpecialLivingAllowance').style.display = 'block'
		getMsaRate()
		document.forms['frmForm'].fmSpecialLivingAllowanceFirstCalc.value = get2DigetRounded(fltSpecialLivingAllowanceFirst);
		document.forms['frmForm'].fmSpecialLivingAllowanceSecondCalc.value = get2DigetRounded(fltSpecialLivingAllowanceSecond);
	}
	else{
		document.getElementById('divSpecialLivingAllowance').style.display = 'none'
		//document.getElementById('divSpecialLivingAllowance').style.display = 'block'
		document.forms['frmForm'].fmSpecialLivingAllowanceFirstCalc.value = get2DigetRounded(fltSpecialLivingAllowanceFirst);
		document.forms['frmForm'].fmSpecialLivingAllowanceSecondCalc.value = get2DigetRounded(fltSpecialLivingAllowanceSecond);
	}
}

function getSolaRates(){
		if(document.forms[0].fmSolaFirst.options.length > 1){
			for(var i = document.forms[0].fmSolaFirst.options.length; i>=0;i--){
				document.forms[0].fmSolaFirst.options[i]= null;
			}
		}
		var objLatestDsaRates = new DsaRate();
//strDutyStation

		for(var i = 0;i<DsaRates.length;i++){
			if(DsaRates[i].Country == strDutyStationCountryCode){
			//if((DsaRates[i].CountryName + ', ' + DsaRates[i].Name)  == strDutyStation){
				if(parseInt(DsaRates[i].Type) == 1){
					objSelect = document.forms[0].fmSolaFirst;
					objSelect.options[objSelect.options.length] = new Option(DsaRates[i].CountryName + ', ' + DsaRates[i].Name,DsaRates[i].USDAmount);
					objLatestDsaRates = DsaRates[i];
				}						
			}
		}
		if(document.forms[0].fmSolaFirst.options.length >= 1){
			for(var i=0;i<document.forms[0].fmSolaFirst.options.length;i++){
				if(document.forms[0].fmSolaFirst.options[i].text  == strDutyStation){
					document.forms[0].fmSolaFirst.options[i].selected=true;
					break;
				}
			}
		}
		
		if(document.forms[0].fmSolaFirst.options.length == 1){
			document.forms[0].fmSpecialLivingAllowanceFirst.value = objLatestDsaRates.USDAmount;
			for(var i = 0;i<DsaRates.length;i++){
				if(DsaRates[i].CountryName == objLatestDsaRates.CountryName && parseInt(DsaRates[i].Type) == 2){
					document.forms[0].fmSpecialLivingAllowanceSecond.value = DsaRates[i].USDAmount;
					break;
				}
			}
		}		
		document.getElementById('divSpecialLivingAllowance').style.display = 'block';
}

function getAssignmentGrant1Calc(){
	document.forms[0].fmAssignmentGrant1Calc.value = get2DigetRounded((fltNetBaseSalary + fltPostAdjustmentCalculated)/12);
}
function getAssignmentGrant2Calc(){
	document.forms[0].fmAssignmentGrant2Calc.value = get2DigetRounded(document.forms[0].fmSpecialLivingAllowanceFirst.value * 30);
}

function getAssignmentGrant3Calc(){
	document.forms[0].fmAssignmentGrant3Calc.value = get2DigetRounded((document.forms[0].fmAssignmentGrant2Calc.value * intNumberOfDependents)/ 2);
}

// december 2004
function getAssignmentGrant4Calc(){
	// 3 is the default value
	var intGroup = 3;
	if(strContractType == 'JPO'){
		intGroup = 1;
	}
	if(intSmRr == 2){
		intGroup = 2;
	}
	//alert(intMaritalStatus)
	for(var i=0;i<RelocationGrants.length;i++){
		if(RelocationGrants[i].GroupId == intGroup){
			if(blnIsDepandent){
				fltRelocationGrant = RelocationGrants[i].DepandentRate;
			}
			else{
				if(intMaritalStatus == 3){
					fltRelocationGrant = RelocationGrants[i].DepandentRate;
				}
				else{
					fltRelocationGrant = RelocationGrants[i].SingleRate;
				}
			}
		}
		
	}
	document.forms[0].fmAssignmentGrant4Calc.value = get2DigetRounded(fltRelocationGrant);
}
// /december 2004

function getApaToDutystation(){
	// reset strAPA
	strAPA = '';
	//reset blnHasAPA
	blnHasAPA = false;
	// if fmAPA select has options delete all
	if(document.forms['frmForm'].fmAPA.options.length > 0){
		for(var i = document.forms['frmForm'].fmAPA.options.length; i>=0;i--){
			document.forms['frmForm'].fmAPA.options[i]= null;
		}
	}
	if(strDutyStation != ''){
		for(var i = 0; i< SolaRates.length;i++){
			if(strDutyStation == SolaRates[i].DutyStation){
				document.forms['frmForm'].fmAPA.options[document.forms['frmForm'].fmAPA.options.length] = new Option(SolaRates[i].APA, SolaRates[i].Rate)
			}
		}
	}
	if(document.forms['frmForm'].fmAPA.options.length > 0){
		strAPA = document.forms['frmForm'].fmAPA.options[0].text;
		fltMsaRate = document.forms['frmForm'].fmAPA.options[0].value;
		blnHasAPA = true;
	}
	if(document.forms['frmForm'].fmAPA.options.length > 0){
		document.getElementById('divAPA').style.display = 'block';
		document.getElementById('divDsa').style.display = 'block';
	}
	else{
		document.getElementById('divAPA').style.display = 'none';
		document.getElementById('divDsa').style.display = 'none';
		//document.getElementById('divDsa').style.display = 'block';
	}
}

//##############################################################################################
//############################### helpers  start  ##############################################
//"New York","United States of America"

function setDStoNewYork(){
	
	if(blnIsGSstaff){
		for(var i=0;i<document.forms[0].fmDutyStation.options.length;i++){
			if(document.forms[0].fmDutyStation.options[i].value == 'United States of America, New York'){
				document.forms[0].fmDutyStation.options[i].selected = true;
				document.forms[0].fmDutyStation.disabled  = true;
				DutyStaion_onchange()
			}
		}
	}
	else{
		document.forms[0].fmDutyStation.disabled  = false;
		if(intDutyStationSelectedIndex != 0){
			document.forms[0].fmDutyStation.options[intDutyStationSelectedIndex+1].selected = true;
		}
		else{
			document.forms[0].fmDutyStation.options[intDutyStationSelectedIndex].selected = true;
		}
		DutyStaion_onchange();
	}

}

function displaySecondDependant(){
	if(blnIsGSstaff || intDependentSpouse==2){
		document.getElementById('divSecondaryDependant').style.display = 'block';
	}
	else{
		document.getElementById('divSecondaryDependant').style.display = 'none';
		intSecondaryDependant = 0;
		
	}
}
function displayLanguageAllowance(){
	var regEx = /G\d{1}/
	if(regEx.test(strGrade) && strGrade != ''){
		document.getElementById('trRowLanguageAllowance').style.display = 'block';
	}
	else{
		document.getElementById('trRowLanguageAllowance').style.display = 'none';
	}
}

function displayRowRepresentationAllowance(){
	var regEx = /ASG|USG/
	if(regEx.test(strGrade) || blnIsSmRr){
		document.getElementById('trRowRepresentationAllowance').style.display = 'block';
	}
	else{
		document.getElementById('trRowRepresentationAllowance').style.display = 'none';
	}
}
function displayLanguageAllowance(){
	var regEx = /G\d{1}/
	if(regEx.test(strGrade) && strGrade != ''){
		document.getElementById('trRowLanguageAllowance').style.display = 'block';
	}
	else{
		document.getElementById('trRowLanguageAllowance').style.display = 'none';
	}
}

function displayLanguageSelects(blnDisplay){
	if(blnDisplay){
		document.getElementById('divLanguageAllowance').style.display = 'block';
		document.getElementById('divNumberOfLanguage').style.display = 'block';
	}
	else{
		document.getElementById('divLanguageAllowance').style.display = 'none';
		document.getElementById('divNumberOfLanguage').style.display = 'none';
		// reset all values
		blnLanguageAllowance = false;
		intNumberOfLanguage = 0;
		document.forms['frmForm'].fmLanguageAllowance.selectedIndex = 0;
		document.forms['frmForm'].fmNumberOfLanguage.selectedIndex = 0;
	}
}

function displayDivDsa(){

	if(blnIsGSstaff){
		document.getElementById('divDsa').style.display = 'none';
		//document.getElementById('divDsa').style.display = 'block';
	}
	else{
		if(intDutyStationSelectedIndex > 0){
			document.getElementById('divDsa').style.display = 'block';
		}
	}
}

function displayAssignmentGrant(){
	if(strGrade.indexOf('G')!= 0){
		document.getElementById('divAssignmentGrant').style.display = 'block';
	}
	else{
		document.getElementById('divAssignmentGrant').style.display = 'none';
	}
}

function displayMobilityHardship(){

	if(blnIsGSstaff){
		document.getElementById('fieldsetMobilityHardship').style.display = 'none';
		document.getElementById('trRowMobilityHardshipAllowance').style.display = 'none';
	}
	else{
		document.getElementById('fieldsetMobilityHardship').style.display = 'block';
		document.getElementById('trRowMobilityHardshipAllowance').style.display = 'block';
	}
}

function setDivMobilityHeaderText(){
	if(strAPA != ''){
		//document.getElementById('divMobilityHeader').className = 'groupHeaderAttention';
		document.getElementById('divMobilityHeader').innerHTML = strMobilityHeaderTextApa;
		document.getElementById('divDsa').style.display = 'block'; 
	}
	else{
		//document.getElementById('divMobilityHeader').className = 'groupHeader';
		document.getElementById('divMobilityHeader').innerHTML = strMobilityHeaderText;
		document.getElementById('divDsa').style.display = 'none';
		//document.getElementById('divDsa').style.display = 'block';
	}
}

function setContractOptions(){
	var objSelect = document.forms[0].fmContractType
	if(blnIsGSstaff){
		for(i=0;i<objSelect.options.length;i++){
			if(objSelect.options[i].value=='GS'){
				objSelect.options[i].selected = true;
				objSelect.disabled = true;
				
			}
		}
	}
	else{
		objSelect.options[0].selected = true;
		objSelect.disabled = false;
	}
	// set global variable: strContractType
	strContractType = objSelect.options[objSelect.selectedIndex].value
}

function setfmInsuranceOption(){
	var objSelect = document.forms[0].fmInsurance;
	
	// reset dental insurance
	//fltDentalInsuranceValue = 0;
	document.getElementById('trRowDentalInsuranceValue').style.display = 'none';
	
	// if  Insurance select has options delete all
		if(objSelect.options.length >= 1){
			for(var i = objSelect.options.length; i>=0;i--){
				objSelect.options[i]= null;
			}
		}
	//alert(strDutyStationCountryCode)
	if(strDutyStationCountryCode != ''){
		switch(strDutyStationCountryCode){
			case 'DEN':
				//objSelect.options[objSelect.options.length] = new Option(InsuranceEnums[2].Name,InsuranceEnums[2].Value,true)
				intInsurance = 2;
				document.getElementById('fieldsetInsurence').style.display = 'none';
			break;
			case 'GER':
				//objSelect.options[objSelect.options.length] = new Option(InsuranceEnums[2].Name,InsuranceEnums[2].Value,true)
				intInsurance = 2;
				document.getElementById('fieldsetInsurence').style.display = 'none';
			break;
			case 'SWE':
				//objSelect.options[objSelect.options.length] = new Option(InsuranceEnums[2].Name,InsuranceEnums[2].Value,true)
				intInsurance = 2;
				document.getElementById('fieldsetInsurence').style.display = 'none';
			break;
			case 'NOR':
				//objSelect.options[objSelect.options.length] = new Option(InsuranceEnums[2].Name,InsuranceEnums[2].Value,true)
				intInsurance = 2;
				document.getElementById('fieldsetInsurence').style.display = 'none';
			break;
			case 'ITA':
				//objSelect.options[objSelect.options.length] = new Option(InsuranceEnums[2].Name,InsuranceEnums[2].Value,true)
				intInsurance = 2;
				document.getElementById('fieldsetInsurence').style.display = 'none';
			break;
			case 'BEL':
				//objSelect.options[objSelect.options.length] = new Option(InsuranceEnums[2].Name,InsuranceEnums[2].Value,true)
				intInsurance = 2;
				document.getElementById('fieldsetInsurence').style.display = 'none';
			break;
			case 'SWI':
				//objSelect.options[objSelect.options.length] = new Option(InsuranceEnums[2].Name,InsuranceEnums[2].Value,true)
				intInsurance = 2;
				document.getElementById('fieldsetInsurence').style.display = 'none';
			break;
			case 'UK':
				//objSelect.options[objSelect.options.length] = new Option(InsuranceEnums[2].Name,InsuranceEnums[2].Value,true)
				intInsurance = 2;
				document.getElementById('fieldsetInsurence').style.display = 'none';
			break;
			case 'MEX':
				//objSelect.options[objSelect.options.length] = new Option(InsuranceEnums[2].Name,InsuranceEnums[2].Value,true)
				intInsurance = 2;
				document.getElementById('fieldsetInsurence').style.display = 'none';
			break;
			case 'CHI':
				//objSelect.options[objSelect.options.length] = new Option(InsuranceEnums[2].Name,InsuranceEnums[2].Value,true)
				intInsurance = 2;
				document.getElementById('fieldsetInsurence').style.display = 'none';
			break;
			case 'USA':
				// create a default "select here" option
				objSelect.options[objSelect.options.length] = new Option(InsuranceEnums[0].Name,InsuranceEnums[0].Value,true)
				for(var i = 3;i<=5;i++){
					objSelect.options[objSelect.options.length] = new Option(InsuranceEnums[i].Name,InsuranceEnums[i].Value)
				}
				document.getElementById('fieldsetInsurence').style.display = 'block';
				document.getElementById('trRowDentalInsuranceValue').style.display = 'block';
				intInsurance = 0;
			break;
	
			
			default:
				//objSelect.options[objSelect.options.length] = new Option(InsuranceEnums[1].Name,InsuranceEnums[1].Value,true)
				intInsurance = 1;
				document.getElementById('fieldsetInsurence').style.display = 'none';
		}
	}
}

function setTextInsuranceSpans(){
//spanInsurenceText
//spanInsurenceType
//spanInsurenceNoOfCovered
//strInsurenceGroupTxt_4
	if(intInsurance > 0){
		document.getElementById('spanInsurenceType').innerHTML = '(' + InsuranceEnums[intInsurance].Name.toString() + ')'
		if(intNumberOfDependents == 0){
			document.getElementById('spanInsurenceNoOfCovered').innerHTML = '&nbsp;- ' + strInsurenceGroupTxt_1
		}else if(intNumberOfDependents == 1){
			if(intDependentSpouse == 1 && intDependentChild == 0){
				document.getElementById('spanInsurenceNoOfCovered').innerHTML = '&nbsp;- ' + strInsurenceGroupTxt_3
			}
			else{
				document.getElementById('spanInsurenceNoOfCovered').innerHTML = '&nbsp;- ' + strInsurenceGroupTxt_2
			}
	
		}else if(intNumberOfDependents >= 2){
			document.getElementById('spanInsurenceNoOfCovered').innerHTML = '&nbsp;- ' + strInsurenceGroupTxt_4
		}
		else{
			document.getElementById('spanInsurenceNoOfCovered').innerHTML = '&nbsp;- ' + strInsurenceGroupTxt_1
		}
		
	}
	else{
		document.getElementById('spanInsurenceType').innerHTML = '';
		document.getElementById('spanInsurenceNoOfCovered').innerHTML = '';
	}
	
	if(strDutyStationCountryCode != 'USA'){
		document.getElementById('spanInsurenceText').innerHTML = strMedicalAndDental;
	}
	else{
		document.getElementById('spanInsurenceText').innerHTML = strMedicalNoDental;
	}

}

function setAssignmentGrantSpans(){
	document.getElementById('spanAssignmentGrant2').innerHTML = document.forms[0].fmSpecialLivingAllowanceFirst.value;
	document.getElementById('spanAssignmentGrant3').innerHTML = document.forms[0].fmSpecialLivingAllowanceFirst.value/2;
}

function setHeader1(){
// id="divHeader1"
strHeader1Gs
strHeader1Single
strHeader1Dependant
	var regEx = /G\d{1}/
	if(regEx.test(strGrade) && !blnIsDepandent){
		document.getElementById('divHeader1').innerHTML = strHeader1Gs;
	}
	if(!regEx.test(strGrade) && blnIsDepandent){
		document.getElementById('divHeader1').innerHTML = strHeader1Dependant;
	}
	if(!regEx.test(strGrade) && !blnIsDepandent){
		document.getElementById('divHeader1').innerHTML = strHeader1Single;
	}
	if(strGrade == '' && !blnIsDepandent){
		document.getElementById('divHeader1').innerHTML = strHeader1Gs;
	}
}

function setIsDepandent(){
	if(intDependentSpouse == 1 || new Number(intDependentChild) > 0){
		blnIsDepandent = true;
	}
	else{
		blnIsDepandent = false;
	}
}

	function get2DigetRounded(fltNbr){
		var tmp = Math.round(fltNbr*100)/100;
		switch(tmp.toString().indexOf('.')){
			case -1:
				return tmp + '.00'
			break;
			case tmp.toString().length - 2:
				return tmp + '0'
			break;
			default:
				return tmp
			break;
		}
	}
	
//http://icsc.un.org/resources/html/cold/pac/pac_frm.htm
//http://icsc.un.org/resources/html/cold/pac/pac_tab.htm#A
function getExternalRates(){
	var winRates
	if(strDutyStation != 0){
		var tmpHref = strDutyStation.substring(0,1)
		tmpHref = 'http://icsc.un.org/resources/html/cold/pac/pac_tab.htm#' + tmpHref
		winRates = window.open(tmpHref,'externelRates');
		winRates.focus();
	}
	else{
		winRates = window.open('http://icsc.un.org/resources/html/cold/pac/pac_frm.htm','externelRates');
		winRates.focus();
	}
}

//############################### helpers  end  ################################################
//##############################################################################################

//############################### Calculations  end  ###########################################
//##############################################################################################