var hat_switcher_switched = false;
var hat_switcher_switched_index = 1;

function hideIf(id) {
  if (document.getElementById(id)) {
    document.getElementById(id).style.display = 'none';
    return true;
  } else {
    return false;
  }
}

function showIf(id) {
  if (document.getElementById(id)) {
    document.getElementById(id).style.display = '';
    return true;
  } else {
    return false;
  }
}


initProjArr = new Array();
function initProjections() {
  for (i=0;i<initProjArr.length;i++) {
    var id = initProjArr[i];
    //	getProjections(id,document.getElementById(id).value);
  }
}
function validatePassw(id1,id2) {
  if (document.getElementById(id1) && document.getElementById(id2)) {
    var pass1 = document.getElementById(id1).value;
    var pass2 = document.getElementById(id2).value;

    if (pass1 != '' && pass2 != '') {
      if (pass1 == pass2) {
	return true;
      }
      else {
	alert('The desired password and confirm password are not the same. Please re-enter the same desired password in both fields.');
	document.getElementById(id1).focus();
	return false;
      }
    }
  }
}

brows = new Brows();
if (brows.nav6up) {
  document.writeln('<link rel="stylesheet" type="text/css" href="/css/mozilla.css">');
}

var processedRadio = '';
function dispYesNo(radio,useprocessed) {

  if ((useprocessed==true && radio.name != processedRadio) || useprocessed==false){
    pass = true;
  }else if (useprocessed==true){
    pass = false;
  }

  if (document.getElementById('children_'+radio.name) && pass==true) {    

    if ((radio.value == 'Increase' || radio.value == 'Decrease') && radio.checked) {
      dsp = 'block';
      processedRadio = radio.name;	 					
      document.getElementById('children_'+radio.name).style.display = dsp;
      
    }       
    else if (radio.value == 'No Change' && radio.checked) {
      dsp = 'none';
      processedRadio = radio.name;
      document.getElementById('children_'+radio.name).style.display = dsp;
    }
    else {
      
    }
  }
}

function initYesNo() {

  var inputs = new Array();
  inputs = document.getElementsByTagName('input');
  	
  for (i = 0; i < inputs.length; i++) {
    if (inputs[i].type == 'radio') {
      dispYesNo(inputs[i],true);
    }
  }
  processedRadio = '';
  
}

function toggleDisplay(id,dt) {
  dsp = document.getElementById(id).style.display;
  document.getElementById(id).style.display = (dsp == dt) ? 'none' : dt;
}

function showHideOtherContractingOffice(inField){
  var sname = inField.name;
  var stemp = new Array();
  var snumber;
  var sstyle; 
  var in_class = 'agency_registration';
  temp = sname.split('[');
  temp[3].replace(/]/,'');
  snumber = temp[3].substr(0,temp[3].length-1);
  var ourstyle = inField.value == '__send_alert' ? '' : 'none';
  var notfounddiv = document.getElementById('so_formfield_dnf_class_values_'+in_class+'__offices__'+snumber+'__contracting_office_nf_');
  if (!notfounddiv){
    notfounddiv = document.getElementById('so_formfield_dnf_class_values_'+in_class+'__offices__dynamicadd'+snumber+'__contracting_office_nf_');
  }   
  if (notfounddiv){
    notfounddiv.style.display = ourstyle;
  }
}

function handleAdditionalOfficesUserLevel(inField){
  var fname = inField.name;
  var ftemp = new Array();
  var fnumber;
  var fstyle; 
  var in_class = 'agency_registration';
  temp = fname.split('[');
  temp[3].replace(/]/,'');
  fnumber = temp[3].substr(0,temp[3].length-1);
  if (inField.value == 'contracting office'){
    fstyle = '';
  } else {
    fstyle = 'none'; 
  }
  var curtype = '';  
  var curcodiv = document.getElementById('so_formfield_dnf_class_values_'+in_class+'__offices__'+fnumber+'__contracting_office_');
  
  if (!curcodiv) { 
     curcodiv = document.getElementById('so_formfield_dnf_class_values_'+in_class+'__offices__dynamicadd'+fnumber+'__contracting_office_');
     curtype ='dynamicadd';
  }
  if (curcodiv){
     curcodiv.style.display = fstyle;
  } 
  var covalinputvalue = fstyle;
  if (fstyle == ''){
    var covalinput = document.getElementById('dnf_class_values_'+in_class+'__offices__'+curtype+fnumber+'__contracting_office_');
    if (covalinput){
      covalinputvalue = covalinput.value == '__send_alert' ? '': 'none';
    }  
  }

  var notfounddiv = document.getElementById('so_formfield_dnf_class_values_'+in_class+'__offices__'+fnumber+'__contracting_office_nf_');
  if (!notfounddiv){
     var notfounddiv = document.getElementById('so_formfield_dnf_class_values_'+in_class+'__offices__dynamicadd'+fnumber+'__contracting_office_nf_');
  }
  if (notfounddiv){
     notfounddiv.style.display = covalinputvalue;
  }
}

function handleRequestNewRoleUserLevel(inField){
  var fstyle; 
  var in_class = 'agency_contact_reg_role';
  if (inField.value == 'contracting office'){
    fstyle = '';
  } else {
    fstyle = 'none'; 
  }
  var curtype = '';  
  var curcodiv = document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office_');
  if (curcodiv){
     curcodiv.style.display = fstyle;
  }
  var covalinputvalue = fstyle;
  if (fstyle == ''){
    var covalinput = document.getElementById('dnf_class_values_'+in_class+'__contracting_office_');
   if (covalinput && covalinput.type!='hidden'){
      covalinputvalue = covalinput.value == '__send_alert' ? '': 'none';
    } else if (!curcodiv){
      covalinputvalue = '';
    }
  }

  var notfounddiv = document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office_nf_');
  if (notfounddiv){
     notfounddiv.style.display = covalinputvalue;
  }
}

function handleUserLevel(inField,form,in_class){
  var inValue = inField.value;
  if ( inValue == 'region'){
    //show region picker
    if (typeof(ffs) != 'undefined') {
       wizSkip('agency_registration','so_formfield_dnf_class_values_'+in_class+'__region_',false);
       wizSkip('agency_registration','so_formfield_dnf_class_values_'+in_class+'__region_nf_',false);
       wizSkip('agency_registration','so_formfield_dnf_class_values_'+in_class+'__contracting_office_',true);	
       wizSkip('agency_registration','so_formfield_dnf_class_values_'+in_class+'__contracting_office_nf_',true);
    }
   else {
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region_')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region_').style.display = "";
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region__blurb')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region__blurb').style.display='';
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region__divider')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region__divider').style.display='';
    
    //hide office picker
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office_')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office_').style.display = "none";
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office__blurb')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office__blurb').style.display='none';
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office__divider')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office__divider').style.display='none';
  
    //hide office not found field
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office_nf_')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office_nf_').style.display = "none";
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office_nf__blurb')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office_nf__blurb').style.display='none';
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office_nf__divider')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office_nf__divider').style.display='none';
 
    //show region not found field
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region_nf_')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region_nf_').style.display = "";
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region_nf__blurb')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region_nf__blurb').style.display='';
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region_nf__divider')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region_nf__divider').style.display='';
  }
  } else if ( inValue == 'contracting office') {
     if (typeof(ffs) != 'undefined') {
       wizSkip('agency_registration','so_formfield_dnf_class_values_'+in_class+'__region_',true);
       wizSkip('agency_registration','so_formfield_dnf_class_values_'+in_class+'__region_nf_',true);
       wizSkip('agency_registration','so_formfield_dnf_class_values_'+in_class+'__contracting_office_',false);	
       wizSkip('agency_registration','so_formfield_dnf_class_values_'+in_class+'__contracting_office_nf_',false);
    } else { 
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region_')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region_').style.display = "none";
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region__blurb')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region__blurb').style.display='none';
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region__divider')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region__divider').style.display='none';
    
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office_')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office_').style.display = "";
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office__blurb')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office__blurb').style.display='';
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office__divider')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office__divider').style.display='';
    
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region_nf_')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region_nf_').style.display = "none";
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region_nf__blurb')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region_nf__blurb').style.display='none';
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region_nf__divider')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region_nf__divider').style.display='none';
  
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office_nf_')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office_nf_').style.display = "";
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office_nf__blurb')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office_nf__blurb').style.display='';
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office_nf__divider')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office_nf__divider').style.display='';
}
  } else {
    if (typeof(ffs) != 'undefined') {
       wizSkip('agency_registration','so_formfield_dnf_class_values_'+in_class+'__region_',true);
       wizSkip('agency_registration','so_formfield_dnf_class_values_'+in_class+'__region_nf_',true);
       wizSkip('agency_registration','so_formfield_dnf_class_values_'+in_class+'__contracting_office_',true);
       wizSkip('agency_registration','so_formfield_dnf_class_values_'+in_class+'__contracting_office_nf_',true);
  } else {
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region_')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region_').style.display = "none";
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region__blurb')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region__blurb').style.display='none';
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region__divider')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region__divider').style.display='none';
    
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office_')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office_').style.display = "none";
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office__blurb')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office__blurb').style.display='none';
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office__divider')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office__divider').style.display='none';
  
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region_nf_')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region_nf_').style.display = "none";
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region_nf__blurb')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region_nf__blurb').style.display='none';
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region_nf__divider')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__region_nf__divider').style.display='none';

    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office_nf_')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office_nf_').style.display = "none";
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office_nf__blurb')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office_nf__blurb').style.display='none';
    if (document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office_nf__divider')) document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contracting_office_nf__divider').style.display='none';
  }
 }
}

function handleCodes(inField,form,in_name){
  in_name = in_name + '_nf';
  if (inField.value=='__send_alert'){
    if (document.getElementById('so_formfield_dnf_class_values_agency_registration__'+in_name+'_')) document.getElementById('so_formfield_dnf_class_values_agency_registration__'+in_name+'_').style.display = "";
    if (document.getElementById('so_formfield_dnf_class_values_agency_registration__'+in_name+'__blurb')) document.getElementById('so_formfield_dnf_class_values_agency_registration__'+in_name+'__blurb').style.display='';
    if (document.getElementById('so_formfield_dnf_class_values_agency_registration__'+in_name+'__divider')) document.getElementById('so_formfield_dnf_class_values_agency_registration__'+in_name+'__divider').style.display='';
  } else {
    if (document.getElementById('so_formfield_dnf_class_values_agency_registration__'+in_name+'_')) document.getElementById('so_formfield_dnf_class_values_agency_registration__'+in_name+'_').style.display = "none";
    if (document.getElementById('so_formfield_dnf_class_values_agency_registration__'+in_name+'__blurb')) document.getElementById('so_formfield_dnf_class_values_agency_registration__'+in_name+'__blurb').style.display='none';
    if (document.getElementById('so_formfield_dnf_class_values_agency_registration__'+in_name+'__divider')) document.getElementById('so_formfield_dnf_class_values_agency_registration__'+in_name+'__divider').style.display='none';
  }  
}

function checkIfSub(inField,form,in_class)
{
  val = inField.value;
  if (val == 'sub'){
    display = "";
  }else{
    display = "none";
  }
  
  document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contract_amount_').style.display = display;
  if(document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contract_amount__blurb')) {
    document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contract_amount__blurb').style.display = display;
  }
  if(document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contract_amount__divider')) {
    document.getElementById('so_formfield_dnf_class_values_'+in_class+'__contract_amount__divider').style.display = display;
  }
  document.getElementById('so_formfield_dnf_class_values_'+in_class+'__awardor_duns_').style.display = display;
  if(document.getElementById('so_formfield_dnf_class_values_'+in_class+'__awardor_duns__blurb')) {
    document.getElementById('so_formfield_dnf_class_values_'+in_class+'__awardor_duns__blurb').style.display = display;
  }
  if(document.getElementById('so_formfield_dnf_class_values_'+in_class+'__awardor_duns__divider')) {
    document.getElementById('so_formfield_dnf_class_values_'+in_class+'__awardor_duns__divider').style.display = display;
  }
  document.getElementById('so_formfield_dnf_class_values_'+in_class+'__awardor_email_').style.display = display;
  if(document.getElementById('so_formfield_dnf_class_values_'+in_class+'__awardor_email__blurb')) {
    document.getElementById('so_formfield_dnf_class_values_'+in_class+'__awardor_email__blurb').style.display = display;
  }
  if(document.getElementById('so_formfield_dnf_class_values_'+in_class+'__awardor_email__divider')) {
    document.getElementById('so_formfield_dnf_class_values_'+in_class+'__awardor_email__divider').style.display = display;
  }
}

function handleAction(inVal,report_id,in_class){
  top.frames[parent.nextFrame()].location.href = '/utils/handleReportAction?action='+inVal+'&report='+report_id+'&class='+in_class;
}

function trythis(stuff){
  return;
  len = stuff.value.length;
  //alert((len - Math.floor(len / 3) * len));
  //if ((len - Math.floor(len / 3) * len) == 0){
  //  stuff.value = stuff.value+',';
  //}
  var return_value = '';
  for (i=(len-1);i--;i>0){
    return_value = stuff.value.charAt(i)+return_value;
  }
  // stuff.value = return_value;
}

function enterSubmit(dunsForm){
  if (document.all){ 
    var key = event.keyCode;
    if (key == 13){ 
      dunsForm.action = '?reg=rstep1&_submit=1';
    }
  }
};	

function calc294(inval,inform,field_name,in_class){
  var current_contract_value;
  var total_awards; 
  var invalue;
  var smallcategories = new Array('sdb','wosb','hbcu_mi','hubzone','vosbc','sd_vosbc','anc','ancn');
  if(in_class == '' || typeof(in_class)=='undefined' || in_class==false) {
     in_class = 'f294';
  }

  //Check that we're left with digits and a dot
  //re=/^-?[0-9]*\.?[0-9]*$/;
  re = /^-?[0-9]+$/;// whole dollar should be integer?
  if (re.test(inval.value)) {
    invalue = parseFloat(inval.value);
    //If in value is null, dont do anything
    if (isNaN(invalue)) invalue = 0;
    
    submitted_by = document.getElementById('dnf_class_values_'+in_class+'__submitted_by_').value;
    if (submitted_by == 'prime contractor'){
      current_contract_value = parseFloat(document.getElementById('dnf_class_values_'+in_class+'__current_contract_value_').value);
    } else {
      current_contract_value = parseFloat(document.getElementById('dnf_class_values_'+in_class+'__subcontract_amount_').value);
    }    
    if (isNaN(current_contract_value)) current_contract_value = 0;
    
    var percent_1_field = field_name.replace('whole','')+'percent';
    var percent_2_field = field_name.replace('whole','')+'percent2';
    
    if (field_name == 'sbc_whole' || field_name == 'lbc_whole'){
      if (field_name == 'sbc_whole'){
				var other_field = 'lbc_whole';
				var other_percent = 'lbc_percent';
      } else if (field_name == 'lbc_whole'){
				var other_field = 'sbc_whole';
				var other_percent = 'sbc_percent';
      }
      
      //When entering in the small, make sure its not less than any socio-economic category first
      var checksmall;
      if (field_name == 'sbc_whole'){
				for(i in smallcategories){
					checksmall = parseFloat(document.getElementById('dnf_class_values_'+in_class+'__'+smallcategories[i]+'_whole_').value);
					if (isNaN(checksmall)) checksmall = 0;
					if (invalue < checksmall){
						alert('The Actual Cumulative Whole Dollar value for Small Business Concerns (2a) cannot be less than any socio-economic category in the Actual Cumulative Whole Dollar Column');
						inval.value = '';
						document.getElementById('dnf_class_values_'+in_class+'__sbc_percent_').value = '';
						document.getElementById('dnf_class_values_'+in_class+'__sbc_percent2_').value = '';
						inval.select();
						inval.focus();
						return false;
					}
				}
      }
			
      //calculate total
      var val1 = parseFloat(document.getElementById('dnf_class_values_'+in_class+'__'+other_field+'_').value);
      if (isNaN(val1)) val1 = 0;
      total_awards = Math.round((val1 + invalue)*100)/100;
      document.getElementById('dnf_class_values_'+in_class+'__total_whole_').value = total_awards;
      
      if (total_awards != 0){
				//calculate Other (either small or large) percent against subcontract awards
				var other_percent_value = ((val1 / total_awards)*100);
				other_percent_value = Math.round(other_percent_value*10)/10;
				document.getElementById('dnf_class_values_'+in_class+'__'+other_percent+'_').value = other_percent_value;
				
				//calculate total percent against current contract value
				if (current_contract_value > 0){
					var total_percent_value = ((total_awards / current_contract_value)*100); 
					total_percent_value = Math.round(total_percent_value*10)/10;
					document.getElementById('dnf_class_values_'+in_class+'__total_percent2_').value = total_percent_value;
				} else {
					//no current contract value, set 0 in case of copied report
					document.getElementById('dnf_class_values_'+in_class+'__total_percent2_').value = 0;
				}
      }
			
      //Update each socio-economic category
      var category_field;
      var category_percent;
      var category_val;
      for(i in smallcategories){
				category_field = smallcategories[i]+'_percent';
				if (total_awards != 0){
					category_val = parseFloat(document.getElementById('dnf_class_values_'+in_class+'__'+smallcategories[i]+'_whole_').value);
					if (isNaN(category_val)) category_val = 0;
					category_percent = ((category_val / total_awards)*100);
					category_percent = Math.round(category_percent*10)/10;
					if (isNaN(category_percent)) category_percent = 0;
					document.getElementById('dnf_class_values_'+in_class+'__'+category_field+'_').value = category_percent;
				} else {
					document.getElementById('dnf_class_values_'+in_class+'__'+category_field+'_').value = '';
				}
      }
    } else {
      total_awards = parseFloat(document.getElementById('dnf_class_values_'+in_class+'__total_whole_').value);
      if (isNaN(total_awards)) total_awards = 0;
      
      small_awards = parseFloat(document.getElementById('dnf_class_values_'+in_class+'__sbc_whole_').value);
      if (!isNaN(small_awards) && invalue > small_awards){
				alert('The Actual Cumulative Whole Dollar value cannot be greater than than the Actual Cumulative Whole Dollar amount for Small Business Concerns (2a)');
				inval.value = '';
				document.getElementById('dnf_class_values_'+in_class+'__'+percent_1_field+'_').value = '';
				document.getElementById('dnf_class_values_'+in_class+'__'+percent_2_field+'_').value = '';
				inval.select();
				inval.focus();
				return false;
      }
    }
		
		
    //Calculate Current Percent Against Subcontracting Awards
    if (total_awards != 0){
      var percent_1_value = ((invalue / total_awards)*100); 
      percent_1_value = Math.round(percent_1_value*10)/10;
      document.getElementById('dnf_class_values_'+in_class+'__'+percent_1_field+'_').value = percent_1_value;
    } else if (invalue == 0){
      document.getElementById('dnf_class_values_'+in_class+'__'+percent_1_field+'_').value = 0;
    }
    //Calculate Percent Against Current Contract Value
    if (current_contract_value > 0){
      var percent_2_value = ((invalue / current_contract_value)*100);
      percent_2_value = Math.round(percent_2_value*10)/10;
      document.getElementById('dnf_class_values_'+in_class+'__'+percent_2_field+'_').value = percent_2_value;
    } else {
			document.getElementById('dnf_class_values_'+in_class+'__'+percent_2_field+'_').value = 0;
		}
  } else {
    //alert("Please provide a valid number using only digits and at most one decimal point.");
    alert('Please provide a valid number using only digits');
    inval.value='';
    inval.select();
    inval.focus();
    return false;
  }
  inform.onsubmit=Function('return true');
}

function fixNonNumbers(str) {
  re=/^[^\-\d]/g;
  re2=/[^\d.]*/g;
  str=str.replace(re, "");
  str=str.replace(re2, "");
  return str;
}

function calc295(inval,inform,field_name,subclass){
  var total_awards; 
  var invalue;
  var incomingid = inval.id;
  if (incomingid.indexOf('ctp')!= '-1'){
    var smallcategories = new Array('sdb','wosb','hbcu_mi','hubzone','vosbc','sd_vosbc','anc');
  } else {
    var smallcategories = new Array('sdb','wosb','hbcu_mi','hubzone','vosbc','sd_vosbc','anc','ancn');
  }
  var incomingprefix = field_name.replace('_whole','');
  var percent_field = field_name.replace('whole','')+'percent';
  var percent_id = '';
  field_name.replace('whole','')+'percent';
  percent_id = incomingid.replace('whole','percent');
  
  var othercatid = '';
  var othercatpercentid = '';
  var totalid = '';
  var smallid = '';
  //Check that we're left with digits and a dot
  //re=/^-?[0-9]*\.?[0-9]*$/;
  re = /^-?[0-9]+$/;
  if (re.test(inval.value)) {
    
    invalue = parseFloat(inval.value);
    if (isNaN(invalue)) invalue = 0;

    if (field_name == 'sbc_whole' || field_name == 'lbc_whole'){
      if (field_name == 'sbc_whole'){
	var other_field = 'lbc_whole';
	var other_percent = 'lbc_percent';
      } else if (field_name == 'lbc_whole'){
	var other_field = 'sbc_whole';
	var other_percent = 'sbc_percent';
      }
      
      //When entering in the small, make sure its not less than any socio-economic category first
      var checksmall;
      if (field_name == 'sbc_whole'){
	for(i in smallcategories){
	  smallid = incomingid.replace(incomingprefix,smallcategories[i]);
	  checksmall = parseFloat(document.getElementById(smallid).value);
	  if (isNaN(checksmall)) checksmall = 0;
	  if (invalue < checksmall){
	    alert('The Whole Dollar value for Small Business Concerns (1a) cannot be less than any socio-economic category in the Whole Dollar Column');
	    inval.value = '';
	    smallid = incomingid.replace(field_name,'sbc_percent');
	    document.getElementById(smallid).value = '';
	    inval.select();
	    inval.focus();
	    return false;
	  }
	}
      }
      
      othercatid = incomingid.replace(field_name,other_field);
      totalid = incomingid.replace(field_name,'total_whole');
      //calculate total
      var val1 = parseFloat(document.getElementById(othercatid).value);
      if (isNaN(val1)) val1 = 0;
      total_awards = Math.round((val1 + invalue)*100)/100;
      document.getElementById(totalid).value = total_awards;
      
      if (total_awards != 0){
	//calculate Other (either small or large) percent against subcontract awards
	var other_percent_value = ((val1 / total_awards)*100);
	other_percent_value = Math.round(other_percent_value*10)/10;
	othercatpercentid = percent_id.replace(percent_field,other_percent);
	document.getElementById(othercatpercentid).value = other_percent_value;
      } else if (invalue == 0){
	document.getElementById(percent_id).value = 0;
      }
      var category_field;
      var category_percent;
      var category_val;
      for(i in smallcategories){
	category_field = smallcategories[i]+'_percent';
	if (total_awards != 0){
	  smallid = incomingid.replace(incomingprefix,smallcategories[i]);
	  category_val = parseFloat(document.getElementById(smallid).value);
	  if (isNaN(category_val)) category_val = 0;
	  category_percent = ((category_val / total_awards)*100);
	  category_percent = Math.round(category_percent*10)/10;
	  if (isNaN(category_percent)) category_percent = 0;
	  smallid = percent_id.replace(incomingprefix,smallcategories[i]);
	  document.getElementById(smallid).value = category_percent;
	} else {
	  smallid = percent_id.replace(incomingprefix,smallcategories[i]);
	  document.getElementById(smallid).value = '';
	}
      }
    } else {
      totalid = incomingid.replace(field_name,'total_whole');
      total_awards = parseFloat(document.getElementById(totalid).value);
      if (isNaN(total_awards)) total_awards = 0;
      smallid = incomingid.replace(field_name,'sbc_whole');
      small_awards = parseFloat(document.getElementById(smallid).value);
      if (!isNaN(small_awards) && invalue > small_awards){
	alert('The Whole Dollar value cannot be greater than than the Whole Dollar amount for Small Business Concerns (2a)');
	inval.value = '';
	document.getElementById(percent_id).value = '';
	inval.select();
	inval.focus();
	return false;
      }
    }
    //anc whole cannot be greater than sdb
    if(field_name == 'anc_whole' ){
       sdb_id = incomingid.replace(field_name,'sdb_whole');
       sdb_awards = parseFloat(document.getElementById(sdb_id).value);
       if (!isNaN(sdb_awards) && (invalue > sdb_awards)){
        alert('The Whole Dollar value cannot be greater than the Whole Dollar amount for Small Disadvantaged Business Concerns (2)');
        inval.value = '';
        document.getElementById(percent_id).value = '';
        inval.select();
        inval.focus();
        return false;
       }
    }
    //Calculate Current Percent Against Subcontracting Awards
    if (total_awards != 0){

      if(field_name == 'anc_whole' || field_name == 'ancn_whole'){
         document.getElementById(percent_id).value = '';
      }else{
        var percent_value = ((invalue / total_awards)*100);
        percent_value = Math.round(percent_value*10)/10;
        document.getElementById(percent_id).value = percent_value;
      }
    }
  } else {
    //alert("Please provide a valid number using only digits and at most one decimal point.");
    alert('Please provide a valid number using only digits');
    inval.value='';
    inval.select();
    inval.focus();
    return false;
  }
  inform.onsubmit=Function('return true');
}

function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "; path=/") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function setPermCookie(name, value, path, domain, secure) {
	var expires = new Date();
	expires.setFullYear(expires.getFullYear()+1000);
	setCookie(name, value, expires, domain, secure);
}

function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "; path=/") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function disableUploadButton(dis){
  var range = document.getElementsByTagName('input');
  for (i=0; i<range.length; i++) {
    if (range[i].name == 'import_submit'){
      range[i].disabled = dis;
    }
  }
}


function switchHatSwitcher() {
  document.getElementById('hat_switcher_user_name').style.display = (hat_switcher_switched ? 'inline' : 'none');
  document.getElementById('hat_switcher_menu').style.display = (hat_switcher_switched ?  'none' : 'inline');
  hat_switcher_switched = !hat_switcher_switched;
}

function handleAddRoleCO(form,inField,current_value,in_wizard){
     var fname = inField.name;
     var ftemp = new Array();
     var fnumber;
     var fstyle; 
     var in_class = 'agency_registration';
     temp = fname.split('[');
     temp[3].replace(/]/,'');
     fnumber = temp[3].substr(0,temp[3].length-1);
     if (inField.value == '__send_alert'){
       fstyle = '';
     } else {
       fstyle = 'none'; 
     }
     var notfounddiv = document.getElementById('so_formfield_dnf_class_values_'+in_class+'__offices__'+fnumber+'__contracting_office_nf_');
     if (!notfounddiv){
       var notfounddiv = document.getElementById('so_formfield_dnf_class_values_'+in_class+'__offices__dynamicadd'+fnumber+'__contracting_office_nf_');
     }

     if (notfounddiv){
       notfounddiv.style.display = fstyle;
     }

   return;
  if (in_wizard){
    wizWaitForRefresh(form);
    document.forms[form].action = wizFormActions[form];
    document.forms[form].onsubmit = wizFormOnSubmits[form];
  }
  var formObj = document.forms[form];
  if (document.forms[form].onsubmit == 'void(0)'){
    document.forms[form].onsubmit = null;
  }
  if (form == 'agency_registration'){
    sympFormSubmit(formObj,inField);
  } else {
    formObj.submit();
  }
}

function toggleChildFieldDisplay(inField,inForm,inID){
  var children_container_id = inID;
  var ccel;
  if (ccel = document.getElementById(children_container_id)){
    if(inField.value==true){
      children_style = '';
    } else {
      children_style = 'none';
    }
    ccel.style.display = children_style;
  }
}

function showHideCO(inField){
   var fstyle= '';
   if (inField.value =='__send_alert'){
    fstyle = '';
   } else {
    fstyle = 'none'; 
   }
   var notfounddiv = document.getElementById('so_formfield_dnf_class_values_agency_contact_reg_role__contracting_office_nf_');
   if (notfounddiv){
     notfounddiv.style.display = fstyle;
   }
}

function tabToNextTAS(inel,goto){
  var re=/[^a-z0-9()\/\.]/g;
  inel.value=inel.value.replace(re,'');
  if (goto==3){
    return;
  }
  var newid = inel.id.substr(0,inel.id.length-3);
  newid += '['+goto+']';
  var charsallowed = inel.getAttribute('maxLength');
  if (inel.value.length == charsallowed){
    inel.form[newid].focus();
  }
}

function disableInputButtonOnClick(inElement,label){
  if (!label){
    label = 'Loading... Please Wait';
  }
  inElement.setAttribute('disabled',true);
  inElement.value= label;
}
function checkFFATAReportPeriod(inElement){
  alert(inElement.name);
}

function handleFFATAZipChange(inField){
	if (0 && inField.value.length > 0 && inField.value.length < 9){
		alert('Please provide the full 9 digit Zip+4.  Do not include any dashes.');
		inField.select();
		inField.focus();
		return false;
	} else {

		var yuiparams = 'field_id='+inField.id+'&field_name='+inField.name+'&zip='+inField.value;
		var yuicallback = {};
		yuicallback.success = function(o){eval(o.responseText)};
		yuicallback.failure = function(o){};
		
		var district_field_name = inField.name.replace('zip','district');
		var state_field_name = inField.name.replace('zip','state');
		var district_field = inField.form[district_field_name];
		var state_field = inField.form[state_field_name];
		if (district_field.options){
			yuiparams += '&curval='+district_field.options[district_field.selectedIndex].value;
		} else {
			yuiparams += '&curval='+district_field.value;
		} 
		if (state_field){
			yuiparams += '&state_val='+state_field.value;
		}
		if ((!state_field || state_field.value!='ZZ') && inField.value.length!=9){
			alert('Please provide the full 9 digit Zip+4.  Do not include any dashes.');
			inField.select();
			inField.focus();
		}
		var yuirequest = YAHOO.util.Connect.asyncRequest('POST', '/utils/handleCongressionalDistrict',yuicallback,yuiparams);
		
	}
}


function handleAwardTypeToggle(inField){
	var local_lookup = document.getElementById('dnf_class_values_contract__contract_');
	if (local_lookup){
		local_lookup.value = '';
	}
  inField.form.submit();
}

function dunsplus4OnBlur(inField){
	if (inField && inField.value.length > 0 && inField.value.length!=4){
		alert('If providing DUNS Number +4, you must provide exactly 4 digits.');
		inField.select();
		inField.focus();
	}
	
}

function checkNumberLocal(inField,min,max,just_warn,max_decimal_places) {
        if (inField.value == '') return;
        var error = false;
        var error_msg = 'Please provide a valid number using only digits and at most one decimal point.';

        //Get rid of whitespace
        var re = /\s+/g;
        inField.value = inField.value.replace(re, '');

        //Check that we are left with digits and a dot
        re = /^-?[0-9]*\.?[0-9]*$/;

        if (re.test(inField.value)) {
                if (inField.value != '') {
                        if (( min != null && inField.value < min) || ( max != null && inField.value > max)) {
                                please = (just_warn ? 'Expected' : 'Please enter');
                                if (min == null) {
                                        alert(please + ' a number smaller or equal to '+max);
                                } else if (max == null) {
                                        alert(please + ' a number greater or equal to '+min);
                                } else if (max == min) {
                                        alert(min + ' is the ' + (just_warn ? 'expected' : 'only allowed') + ' value.')
                                } else {
                                        alert(please + ' a number between '+min+' and '+max);
                                }
                                if (!just_warn) {
                                        inField.value = (inField.value < min ? min : max);
                                }
                                error = true;
                        }

                        if (max_decimal_places != null) {
                                var decimal_place = inField.value.lastIndexOf('.');
                                if (decimal_place != '-1') {
                                        var length_of_decimals = inField.value.length-decimal_place-1;
                                        if (length_of_decimals > max_decimal_places) {
                                                alert('Please enter less than or equal to ' + max_decimal_places + ' decimal places.');
                                                inField.value = inField.value.substring(0,(decimal_place+max_decimal_places+1));
                                        }
                                }
                        }
                }
        } else {
                alert(error_msg);
                error = true;
        }

        if (error) {
                inField.value = '';
                if (!just_warn) {
                        inField.select();
                        inField.focus();
                        return false;
                }
        }
}

