var popUpWin=0;
function OpenWindow(URLStr, left, top, width, height) {
	if(popUpWin) {
		if(!popUpWin.closed) popUpWin.close();
	}
	popUpWin = open(URLStr, 'popUpWin');
}

function OpenPopUp(URLStr, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+'');
}
function OpenFull(URLStr)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=yes,location=yes,status=yes,menubar=yes,scrollbar=yes,resizable=yes,copyhistory=yes,width='+screen.availWidth+',height='+screen.availHeight+'');
}


function getObj() {
	var thingy = arguments[0];
	if ( typeof thingy == 'object' ) {
		return thingy;
	} else if ( typeof thingy == 'string' ) {
		return document.getElementById(thingy);
	}
}

function toggleDisplay() {
	var toggleDiv = getObj(arguments[0]);
	with (toggleDiv.style) { display = (display=='none'||display==''?'block':'none'); }
}

function showDisplay() {
	var showDiv = getObj(arguments[0]);
	with (showDiv.style) { display = 'block'; }
}

function hideDisplay() {
	var hideDiv = getObj(arguments[0]);
	with (hideDiv.style) { display = 'none'; }
}

function toggleVisibility() {
	var toggleDiv = getObj(arguments[0]);
	with (toggleDiv.style) { visibility = (visibility=='hidden'?'visible':'hidden'); }
}

function showVisibility() {
	var showDiv = getObj(arguments[0]);
	with (showDiv.style) { visibility = 'visible'; }
}

function hideVisibility() {
	var hideDiv = getObj(arguments[0]);
	with (hideDiv.style) { visibility = 'hidden'; }
}


function getAwimJsSelectOptions(callbackFunction, params) { 
   var requestURL = "/jsp/jsps/awimSite/awimJsSelectOptions.jsp" + params;   
   var loadInvoke = new AjaxNet.LinkLoader(requestURL, callbackFunction);
}


function initCompanyDivisions(companyDivisionSelectObject, selectedCompanyDivision, orgCustNum) {
         
   var onCompanyDivisionDataRefresh = function() {
       if(companyDivisionSelectObject != null && companyDivisionSelectObject != '') {
          var companyDivisionsArray = eval(this.httpObjResponseText);  // Get the response and convert to an array
          
          // Clear any existing values...
          for(j = (companyDivisionSelectObject.options.length - 1); j >= 0; j--) {
             companyDivisionSelectObject.options[j] = null;
          }          

          // If this country array does not contain anything, simply make it non-applicable and return
          if(companyDivisionsArray == null || companyDivisionsArray.length == 0) {
             companyDivisionSelectObject.options[0] = new Option('<N/A>','<N/A>',true,true);
             return;
          }

          // By doing this we make them select a Division from the list because this is the first value in the list...
          var offset = 1;
          companyDivisionSelectObject.options[0] = new Option('<Select>','',true,true);

          // Populate the options with the array
          for(j = 0; j < companyDivisionsArray.length; j++) {
             companyDivisionSelectObject.options[j + offset] = eval(companyDivisionsArray[j]);
          }

          // If there is a division passed in, make sure that one is selected...
          var foundit = false;
          for(j = 0; j < companyDivisionsArray.length; j++) {
             division = companyDivisionSelectObject.options[j + offset];
             if(!foundit && selectedCompanyDivision != null && selectedCompanyDivision != '' && selectedCompanyDivision == division.value) {
                division.selected = true;
                foundit = true;
                break;
             } else { division.selected = false; }
          }
          if(!foundit) { companyDivisionSelectObject.options[0].selected = true; }
       }
    }
    
    var params = "?REQUEST_METHOD=getCompanyDivisions&ORG_CUST_NUM=" + orgCustNum;
    
    getAwimJsSelectOptions(onCompanyDivisionDataRefresh, params);
 }
 
function initCompanyVolunteerRoles(companyVolunteerRolesSelectObject, selectedCompanyVolunteerRoles, orgCustNum) {
         
   var onCompanyVolunteerRolesDataRefresh = function() {
       if(companyVolunteerRolesSelectObject != null && companyVolunteerRolesSelectObject != '') {
          var companyVolunteerRolesArray = eval(this.httpObjResponseText);  // Get the response and convert to an array
          
          // Clear any existing values...
          for(j = (companyVolunteerRolesSelectObject.options.length - 1); j >= 0; j--) {
             companyVolunteerRolesSelectObject.options[j] = null;
          }          

          // If this role array does not contain anything, simply make it non-applicable and return
          if(companyVolunteerRolesArray == null || companyVolunteerRolesArray.length == 0) {
             companyVolunteerRolesSelectObject.options[0] = new Option('<N/A>','<N/A>',true,true);
             return;
          }

          // By doing this we make them select a Role from the list because this is the first value in the list...
          var offset = 1;
          companyVolunteerRolesSelectObject.options[0] = new Option('<Select>','',true,true);

          // Populate the options with the array
          for(j = 0; j < companyVolunteerRolesArray.length; j++) {
             companyVolunteerRolesSelectObject.options[j + offset] = eval(companyVolunteerRolesArray[j]);
          }

          // If there is a role passed in, make sure that one is selected...
          var foundit = false;
          for(j = 0; j < companyVolunteerRolesArray.length; j++) {
             volRole = companyVolunteerRolesSelectObject.options[j + offset];
             if(!foundit && selectedCompanyVolunteerRoles != null && selectedCompanyVolunteerRoles != '' && selectedCompanyVolunteerRoles == volRole.value) {
                volRole.selected = true;
                foundit = true;
                break;
             } else { volRole.selected = false; }
          }
          if(!foundit) { companyVolunteerRolesSelectObject.options[0].selected = true; }
       }
    }
    
    var params = "?REQUEST_METHOD=getCompanyVolunteerRoles&ORG_CUST_NUM=" + orgCustNum;
    
    getAwimJsSelectOptions(onCompanyVolunteerRolesDataRefresh, params);
 }