   var http_request_A = false;
   var http_request_B = false;
   var http_request_C = false;
   var http_request_D = false;
   var http_request_E = false;
   var http_request_F = false;

   var pmcontrol;
   var cmpnycontrol;
   var lcncontrol;
   var depcontrol;
   var companyid;
   var oc_control;
   
   companyid=0;
   
var strFlagPE = "N";

document.onkeypress=function(e){
  var isIE=(document.all);
  userKeyPress=(isIE) ? event.keyCode : e.which;
  if( userKeyPress == 13 ){
    if( companyEmailFlag == "Y" ) {
      companyEmailFlag = "N"; 
    } else {
      return false;
  }
  }
}

function last_choice(selection) {
  return selection.selectedIndex==selection.length - 1; }
  
function check_choice() {
  if(!last_choice(document.frmForm.company)) {
    document.frmForm.othercompany.blur();
    alert('Please check your menu selection first');
    document.frmForm.company.focus(); }}
    
function activate(field) {
  field.disabled=false;
  if(document.styleSheets)field.style.visibility  = 'visible';
  field.focus(); }
    
  function process_choice(){
       if(document.getElementById('company').value == -99){
            document.getElementById('divothercompany').style.display = 'block';
            document.getElementById('dep_label').style.display = 'block';
            document.getElementById('spu_label').style.display = 'none';
            document.getElementById('disc_label').style.display = 'none';
            document.getElementById('seg_label').style.display = 'none';
            document.getElementById('contractortable').style.display = 'none';
            document.getElementById('locationrow').style.display = '';
            document.getElementById('operatingcompanyrow').style.display = 'none';
            document.getElementById('businessunitrow').style.display = 'none';

       } else {
            document.getElementById('divothercompany').style.display = 'none';
            if (document.getElementById('company').value == 104) {
                document.getElementById('dep_label').style.display = 'none';
                document.getElementById('spu_label').style.display = 'block';
                document.getElementById('disc_label').style.display = 'none';
                document.getElementById('seg_label').style.display = 'none';

            } else if (document.getElementById('company').value == 243) {
                document.getElementById('dep_label').style.display = 'none';
                document.getElementById('disc_label').style.display = 'block';
                document.getElementById('dep_label').style.display = 'none';
                document.getElementById('seg_label').style.display = 'none';
            } else if (document.getElementById('company').value == 10) {
                document.getElementById('dep_label').style.display = 'none';
                document.getElementById('disc_label').style.display = 'none';
                document.getElementById('dep_label').style.display = 'none';
                document.getElementById('seg_label').style.display = 'block';                            
            } else {
                document.getElementById('dep_label').style.display = 'block';
                document.getElementById('spu_label').style.display = 'none';
                document.getElementById('disc_label').style.display = 'none';
                document.getElementById('seg_label').style.display = 'none';
            }
            
            if ((document.getElementById('company').value == 104) || (document.getElementById('company').value == 243)) { 
                document.getElementById('contractortable').style.display = 'block';
            
            } else {
                document.getElementById('contractortable').style.display = 'none';
            
            }
            
            if ((document.getElementById('company').value == 10) || (document.getElementById('company').value == 243)) {
                document.getElementById('locationrow').style.display = 'none';
                
            } else {
                document.getElementById('locationrow').style.display = '';
                
            }
            
            if (document.getElementById('company').value == 243) {
                document.getElementById('operatingcompanyrow').style.display = '';
                document.getElementById('businessunitrow').style.display = '';
            } else { 
                document.getElementById('operatingcompanyrow').style.display = 'none';
                document.getElementById('businessunitrow').style.display = 'none';
            }
            if (document.getElementById('company').value == 113) {
                document.getElementById('departmentrow').style.display = 'none';
            }
          }
  }                    
  
    function process_department_choice(){
       if(document.getElementById('department').value == -99){
            document.getElementById('otherdepartment').style.display = 'block';
       } else {
            document.getElementById('otherdepartment').style.display = 'none';
       }
  }                   
  
    function process_location_choice(){
       if(document.getElementById('location').value == -99){
            document.getElementById('otherlocation').style.display = 'block';
       } else {
            document.getElementById('otherlocation').style.display = 'none';
       }
  }                    
  
     

//---------------- START OF RELOAD ONE PM BOX --------------

   function makePMBoxRequest(url, parameters) {
      http_request_B = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request_B = new XMLHttpRequest();
         if (http_request_B.overrideMimeType) {
            http_request_B.overrideMimeType('text/xml');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request_B = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request_B = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request_B) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      http_request_B.onreadystatechange = alertOC;
      http_request_B.open('GET', url + parameters, true);
	  //alert(url + parameters);
      http_request_B.send(null);

   }

function makePMBoxRequest2(url, parameters) {
  http_request_D = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
     http_request_D = new XMLHttpRequest();
     if (http_request_D.overrideMimeType) {
        http_request_D.overrideMimeType('text/xml');
     }
  } else if (window.ActiveXObject) { // IE
     try {
        http_request_D = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) {
        try {
           http_request_D = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
     }
  }
  if (!http_request_D) {
     alert('Cannot create XMLHTTP instance');
     return false;
  }
  http_request_D.onreadystatechange = alertCompany;
  http_request_D.open('GET', url + parameters, true);
//alert(url + parameters);
  http_request_D.send(null);
}

function makePMBoxRequest3(url, parameters) {
  http_request_E = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
     http_request_E = new XMLHttpRequest();
     if (http_request_E.overrideMimeType) {
        http_request_E.overrideMimeType('text/xml');
     }
  } else if (window.ActiveXObject) { // IE
     try {
        http_request_E = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) {
        try {
           http_request_E = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
     }
  }
  if (!http_request_E) {
     alert('Cannot create XMLHTTP instance');
     return false;
  }
  http_request_E.onreadystatechange = alertDepartment;
  http_request_E.open('GET', url + parameters, true);
//alert(url + parameters);
  http_request_E.send(null);
}
   
function makePMBoxRequest4(url, parameters) {
  http_request_F = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
     http_request_F = new XMLHttpRequest();
     if (http_request_F.overrideMimeType) {
        http_request_F.overrideMimeType('text/xml');
     }
  } else if (window.ActiveXObject) { // IE
     try {
        http_request_F = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) {
        try {
           http_request_F = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
     }
  }
  if (!http_request_F) {
     alert('Cannot create XMLHTTP instance');
     return false;
  }
  http_request_F.onreadystatechange = alertLocation;
  http_request_F.open('GET', url + parameters, true);
//alert(url + parameters);
  http_request_F.send(null);
}
   
   function makeBUBoxRequest(url, parameters) {
      http_request_A = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request_A = new XMLHttpRequest();
         if (http_request_A.overrideMimeType) {
            http_request_A.overrideMimeType('text/xml');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request_A = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request_A = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request_A) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      http_request_A.onreadystatechange = alertBU;
      http_request_A.open('GET', url + parameters, true);
	  //alert(url + parameters);
      http_request_A.send(null);

   }
   
   
   function alertPM() {
      if (http_request_B.readyState == 4) {
         if (http_request_B.status == 200) {

   //         alert(http_request_B.responseText);
            result = http_request_B.responseText;
 	    var parts = result.split("|");
            var currentValue = document.getElementById(pmcontrol).value;
            changePMList(document.getElementById(pmcontrol), parts, currentValue);

         } else {
            result = 'There was a problem with the request.' + http_request_B.status + '';
            alert(result);
         }

      }
   }


   function alertCompany() {
      if (http_request_D.readyState == 4) {
         if (http_request_D.status == 200) {

   //         alert(http_request_B.responseText);
            result = http_request_D.responseText;
 	    var parts = result.split("|");
         
            var currentValue = document.getElementById('company').value;
              changePMList(document.getElementById('company'), parts, currentValue);
            
            process_choice();
            getDepartments();
            
            if (document.getElementById('company').value == 243) {
                getOperatingCompanies();
            }
            
            //process_department_choice();

         } else {
            result = 'There was a problem with the request.' + http_request_D.status + '';
            alert(result);
         }

      }
   }

   function alertDepartment() {
      if (http_request_E.readyState == 4) {
         if (http_request_E.status == 200) {

   //         alert(http_request_B.responseText);
            result = http_request_E.responseText;
 	    var parts = result.split("|");
            var currentValue = document.getElementById('department').value;
            changePMList(document.getElementById('department'), parts, currentValue);
            process_department_choice();
            getLocations();
         } else {
            result = 'There was a problem with the request.' + http_request_E.status + '';
            alert(result);
         }

      }
   }

   function alertLocation() {
      if (http_request_F.readyState == 4) {
         if (http_request_F.status == 200) {

   //         alert(http_request_B.responseText);
            result = http_request_F.responseText;
 	    var parts = result.split("|");
            var currentValue = document.getElementById('location').value;
              changePMList(document.getElementById('location'), parts, currentValue);

            if (companyid != 10) {
            //alert(companyid);
            process_location_choice();
            }

         } else {
            result = 'There was a problem with the request.' + http_request_F.status + '';
            alert(result);
         }

      }
   }
   function alertOC() {
      if (http_request_B.readyState == 4) {
         if (http_request_B.status == 200) {

   //         alert(http_request_B.responseText);
            result = http_request_B.responseText;
 	    var parts = result.split("|");
            var currentValue = document.getElementById('operatingcompany').value;
            changePMList(document.getElementById('operatingcompany'), parts, currentValue);
            
            getBusinessUnits();
          
         } else {
            result = 'There was a problem with the request.' + http_request_B.status + '';
            alert(result);
         }

      }
   }
   
   
  function alertBU() {
      if (http_request_A.readyState == 4) {
         if (http_request_A.status == 200) {

   //         alert(http_request_B.responseText);
            result = http_request_A.responseText;
 	    var parts = result.split("|");
            var currentValue = document.getElementById('businessunit').value;
            changePMList(document.getElementById('businessunit'), parts, currentValue);
            //process_oc_choice();
          
         } else {
            result = 'There was a problem with the request.' + http_request_A.status + '';
            alert(result);
         }

      }
   }
function getCompanyBPArray() {
  strFlagPE = "N";
      //regular expression to test for valid email address
      var emailRegxp = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
      
      
      var eml = document.getElementById('Email').value;
      eml = eml.toLowerCase();
      //alert(emailRegxp.test(eml));
      var d;
      if (emailRegxp.test(eml) == true) {
        var u;
        if (eml.indexOf("tom@ihrdc.com") != -1) {
            u=243;
        }
        else if (eml.indexOf("\@bp\.com") != -1) {
            u = 104;
      	} else if (eml.indexOf("\@pan\-energy\.com") != -1) {
      	  u = 104;
          strFlagPE = "Y";
        } else if (eml.indexOf("\@ihrdc\.com") != -1) {
            u = 6;
        } else if ((eml.indexOf("slb\.") != -1) || (eml.indexOf("westerngeco\.") != -1) || (eml.indexOf("waii\.") != -1) || (eml.indexOf("westgeo\.") != -1)) {
          u = 10;
        } else if (eml.indexOf("\@chevron\.com") != -1) {
            u = 243;
        } else if (eml.indexOf("\@petro-canada\.ca") != -1) {
            u = 349;
        } else if( eml.indexOf("\@talisman-energy.com") != -1 || eml.indexOf("\@fortunaenergy.com") != -1 ){
            u = 113;
        } else {
            u = -1;
        }
        companyid = u;
      cmpnycontrol = 'company';
	  var myRand = Math.random()*49999999; // cache buster
	
	var getstr = "?dom="+u+"&flag="+strFlagPE+"&cb="+myRand;
	makePMBoxRequest2('getCompanyList3.asp', getstr);
    } else {
        makePMBoxRequest2('getCompanyList3.asp', '?dom=-1&flag=N&cb='+myRand);
   }
   
    process_choice();
}

    function getCompanyArray() {
      
      //regular expression to validate proper email format  
      var emailRegxp = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
      
      
      var eml = document.getElementById('Email').value;
      //alert(emailRegxp.test(eml));
      var d;
      if (emailRegxp.test(eml) == true){
          var a = eml.indexOf("@")+1;
          var b = eml.length;      
          d = eml.substring(a, b);
          //alert(d);

      
     
      
      pmcontrol = 'company';
	 var myRand = Math.random()*19999999; // cache buster
	
	var getstr = "?dom=" + d+"&cb="+myRand;
	//alert(escape(d); 
	makePMBoxRequest('getCompanyList.asp', getstr);
    } else {
        emptyPMList(document.getElementById('company'));
   }
}

   function getOperatingCompanies() {
    var cid = document.getElementById('company').value;
    
    oc_control = 'operatingcompany';
    var myRand = Math.random()*9999799; // cache buster
    var getstr = "?cid=" + cid+"&cb="+myRand;
    makePMBoxRequest('getOperatingCompanies.asp', getstr);
    
   
   }
 
   function getBusinessUnits() {
    var cid = document.getElementById('company').value;
    var oid = document.getElementById('operatingcompany').value;
    
    bu_control = 'businessunit';
      var myRand = Math.random()*99922999; // cache buster
    var getstr = "?cid=" + cid + "&oid=" + oid+"&cb="+myRand;
    makeBUBoxRequest('getBusinessUnits.asp', getstr);
    }
   


   
   function getDepartments() {
    var cid = document.getElementById('company').value;
    
    depcontrol = 'department';
    var myRand = Math.random()*99949999; // cache buster
    var getstr = "?cid=" + cid + "&flag=" + strFlagPE + "&cb=" + myRand;
    makePMBoxRequest3('getDepartmentList3.asp', getstr);
    
   
   }
   
function getLocations() {
  var did = document.getElementById('department').value;
  
  lcncontrol = 'location';
  var myRand = Math.random()*9994929; // cache buster
  var getstr = "?did=" + did + "&flag=" + strFlagPE + "&cb=" + myRand;
  if( companyid == 113 ){
    makePMBoxRequest4('getLocationList.asp', "?companyID=" + companyid + "&cb=" + myRand );
  } else {
    makePMBoxRequest4('getBPLocationList3.asp', getstr);
  }
  
}


//------------------- END OF UPDATE ONE PM LIST --------------------



//------------------- PM BOX MANAGER ------------------------

function emptyPMList( box ) {

	// Set each option to null thus removing it
	while ( box.options.length ) box.options[0] = null;
}

// This function assigns new drop down options to the given
// drop down box from the list of lists specified

function fillPMList( box, arr , currentValue ) {

	//option = new Option("","");
	//box.options[box.length] = option;

	var idx;

	for ( i = 0; i < arr.length; i++ ) {

		var opts = arr[i].split("=");

		// Create a new drop down option with the
		// display text and value from arr
		option = new Option( opts[1], opts[0] );
		idx = box.length;

		// Add to the end of the existing options
		box.options[idx] = option;

		//if (currentValue.toUpperCase() == opts[1].toUpperCase()) {
		//  box.selectedIndex=idx;
		//}
	}

	// Preselect option 0
	//box.selectedIndex=0;

}

// This function performs a drop down list option change by first
// emptying the existing option list and then assigning a new set

function changePMList( box, list, currentValue ) {

	// Next empty the slave list
	emptyPMList( box );

	// Then assign the new list values
	fillPMList( box, list, currentValue );
}

//----------------- END PM BOX MANAGER ---------------------
function setSuperName() {

  var idx = document.getElementById('contractsuperid').selectedIndex;
  var txt = document.getElementById('contractsuperid').options[idx].text;
  if (txt != 'undefined') {
    document.getElementById('consultsupervisor').value = txt;
  }
  else {
    document.getElementById('consultsupervisor').value = '';
  }
}

//---------------- START OF RELOAD ONE PM BOX --------------

var phonectl;

   function makePhoneRequest(url, parameters) {
      http_request_C = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request_C = new XMLHttpRequest();
         if (http_request_C.overrideMimeType) {
            http_request_C.overrideMimeType('text/xml');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request_C = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request_C = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request_C) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      http_request_C.onreadystatechange = alertPhone;
      http_request_C.open('GET', url + parameters, true);
//      alert(url + parameters);
      http_request_C.send(null);

   }



   function alertPhone() {
      if (http_request_C.readyState == 4) {
         if (http_request_C.status == 200) {

   //         alert(http_request_C.responseText);
            result = http_request_C.responseText;

            phonectl.value = result;

         } else {
            result = 'There was a problem with the request.' + http_request_C.status + '';
            alert(result);
         }

      }
   }


   function getPMPhone(idx) {

    var getstr = "";
    if (idx ==1) {
        phonectl = document.getElementById('emprojmanagerphone');
	    getstr = "?id=" + document.getElementById('emprojmanager').value + "&idx=1";
	    makePhoneRequest('getmgrphone.asp', getstr);
    }
    if (idx ==2) {
        phonectl = document.getElementById('consultsupervisorphone');
	    getstr = "?id=" + document.getElementById('contractsuperid').value + "&idx=2";
	    makePhoneRequest('getmgrphone.asp', getstr);
    }
       
   }
