//  function checkValue()
//  this function checks for the selected value from the
//  company type question and then calls getCompanyType.
//
function checkValue()
{
  hideAll();
  for (i = 0; i < 16; i++)
  {
    if (document.myForm.ctype[i].selected == true)
    {
      getCompanyType(document.myForm.ctype[i].value);
    }
  }
}

//  function getCompanyType(cval)
//  this function determines the company type from
//  the company type question and then calls switchDiv.
//
function getCompanyType(cval) 
{
  var companytype;
  if (cval == 'Business/Corporation') {companytype = 'GP1';}
  if (cval == 'Cable operator/MSO') {companytype = 'GP3';}
  if (cval == 'Education - Higher Ed') {companytype = 'GP2';}
  if (cval == 'Education - K-12') {companytype = 'GP2';}
  if (cval == 'Finance') {companytype = 'GP1';}
  if (cval == 'Government - Federal') {companytype = 'GP2';}
  if (cval == 'Government - Local') {companytype = 'GP2';}
  if (cval == 'Government - Other') {companytype = 'GP2';}
  if (cval == 'Government - State') {companytype = 'GP2';}
  if (cval == 'Healthcare') {companytype = 'GP1';}
  if (cval == 'Networking Equip Reseller/Dist') {companytype = '';}
  if (cval == 'Research & Education') {companytype = 'GP2';}
  if (cval == 'Retail') {companytype = 'GP1';}
  if (cval == 'Telecom Service Provider') {companytype = 'GP3';}
  if (cval == 'Other') {companytype = 'GP1';}
  switchDiv(companytype);
}

// function switchDiv(ctype)
//  this function first hides all the divs and then 
//  takes the id of a div and calls the other 
//  functions required to show that div
//
function switchDiv(ctype)
{
  hideAll();
  if (ctype == 'GP1')
  { 
    var style_sheet1 = getStyleObject("revenue");
    var style_sheet2 = getStyleObject("impsecproj");
    var style_sheet3 = getStyleObject("timeframe");
    var style_sheet4 = getStyleObject("reseller");
    if (style_sheet1) {changeObjectVisibility("revenue","visible","block");}
    if (style_sheet2) {changeObjectVisibility("impsecproj","visible","block");}
    if (style_sheet3) {changeObjectVisibility("timeframe","visible","block");}
    if (style_sheet4) {changeObjectVisibility("reseller","visible","block");}
  }  
  if (ctype == 'GP2')
  { 
    var style_sheet1 = getStyleObject("employees");
    var style_sheet2 = getStyleObject("impsecproj");
    var style_sheet3 = getStyleObject("timeframe");
    var style_sheet4 = getStyleObject("reseller");
    if (style_sheet1) {changeObjectVisibility("employees","visible","block");}
    if (style_sheet2) {changeObjectVisibility("impsecproj","visible","block");}
    if (style_sheet3) {changeObjectVisibility("timeframe","visible","block");}
    if (style_sheet4) {changeObjectVisibility("reseller","visible","block");}
  }  
  if (ctype == 'GP3')
  { 
    var style_sheet2 = getStyleObject("impsecproj");
    var style_sheet3 = getStyleObject("timeframe");
    if (style_sheet2) {changeObjectVisibility("impsecproj","visible","block");}
    if (style_sheet3) {changeObjectVisibility("timeframe","visible","block");}
  }
}

// function hideAll()
//  this function hides the divs
//
function hideAll()
{
   changeObjectVisibility("revenue","hidden","none");
   changeObjectVisibility("employees","hidden","none");
   changeObjectVisibility("impsecproj","hidden","none");
   changeObjectVisibility("timeframe","hidden","none");
   changeObjectVisibility("reseller","hidden","none");
}

// function getStyleObject(string) 
//  this function returns the style object
//  given a string containing the id of an object
//  the function returns the stylesheet of that object
//  or false if it can't find a stylesheet.  Handles
//  cross-browser compatibility issues.
//
function getStyleObject(objectId) {
  // checkW3C DOM, then MSIE 4, then NN 4.
  //
  if(document.getElementById && document.getElementById(objectId)) {
  return document.getElementById(objectId).style;
   }
   else if (document.all && document.all(objectId)) {  
   return document.all(objectId).style;
   } 
   else if (document.layers && document.layers[objectId]) { 
   return document.layers[objectId];
   } else {
   return false;
   }
}

// function changeObjectVisibility(objectId, newVisibility, newDisplay)
//  this function first get a reference to the 
//  cross-browser style object and make sure 
//  the object exists
//
function changeObjectVisibility(objectId, newVisibility, newDisplay) {
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
    styleObject.visibility = newVisibility;
    styleObject.display = newDisplay;
    return true;
    } else {
    // we couldn't find the object, so we can't change its visibility
    return false;
    }
}
