function Genie(URL) {
   if (URL.indexOf(".htm") >= 0) {
     var NewWin = window.open(URL,"","width=500,height=500,top=0,left=0,scrollbars");
   } else {
     var NewWin = window.open(URL,"","width=500,height=500,top=0,left=0");
   }
   return false;
}

function setWidth(strURL) {

  var intWidth;
  if (navigator.appVersion.indexOf("MSIE") > 0) {
    intWidth = document.body.offsetWidth
  } else if (navigator.appName == "Netscape") {
    intWidth = window.innerWidth
  } else {
    intWidth = 750
  }

  var intCols;
  if (intWidth > 800 ) {
    intCols = 3
  } else if (intWidth > 600 ) {
    intCols = 2 
  } else {
    intCols = 1
  }

  if (strURL.indexOf("?") > 0) {
    location = strURL + "&cols=" + intCols;
  } else {
    location = strURL + "?cols=" + intCols;
  }
  return false;
}

function CheckForm(objForm) {
  var arrReq = objForm.Required.value.split(",");
  var objField;
  var strErrors = "";
  var strType = "";

  for (var i=0;i<arrReq.length;i++) {
    objField = eval("objForm." + arrReq[i]);
    strType = objField.type?objField.type:objField[0].type;

  CheckFields:
    switch (strType) {
      // Text boxes and Textareas
      case "textarea":
	strType = "text";

      case "text":
        if(objField.value=="") strErrors += "* " + (objField.title?objField.title:objField.name) + "\n";
	break;

      // Radio Buttons
      case "radio":
        if (objField.length) {
	  for (var j=0;j<objField.length;j++) {
	    if (objField[j].checked) break CheckFields;
          }
	  strErrors += "* " + (objField[0].title?objField[0].title:objField[0].name) + "\n";
 	} else {
	  if (!objField.checked) strErrors += "* " + (objField.title?objField.title:objField.name) + "\n";
        }
	break;

      // Check Boxes
      case "checkbox":
        if (objField.length) {
	  for (var j=0;j<objField.length;j++) {
	    if (objField[j].checked) break CheckFields;
          }
	  strErrors += "* " + (objField[0].title?objField[0].title:objField[0].name) + "\n";
 	} else {
	  if (!objField.checked) strErrors += "* " + (objField.title?objField.title:objField.name) + "\n";
        }
	break;

      // Select Boxes
      case "select-multiple":
        if (objField.selectedIndex < 0 ) {
	  strErrors += "* " + (objField.title?objField.title:objField.name) + "\n";
	  break;
        }

      case "select-one":
        if (objField.selectedIndex == 0 && !objField.options[objField.selectedIndex].value) {
	  strErrors += "* " + (objField.title?objField.title:objField.name) + "\n";
	  break;
        }
    }
  }

  if (strErrors) {
    alert("You must complete the fields marked with an asterisk (*):\n\n" + strErrors);
    return false;
  } else {
    return true;
  }
}

// Directory listings should include a width
function checkLink(objEvt) {
  var ThisDomain = location.hostname
  
  // Netscape and IE/Opera handle events differently
  objElement=objEvt?objEvt.target:event.srcElement

  // Netscape treats text nodes as elements.  Find the link...
  while (objElement.tagName != "A" && objElement.tagName != "BODY") objElement=objElement.parentNode;

  // Not a link? Proceed as normal
  if (objElement.tagName != "A") return true;

  // Is it an external link other than Americart?
  if ( (objElement.href.indexOf(ThisDomain) < 0 ) && (objElement.href.indexOf("cartserver") < 0 ) ) {
    window.open(objElement.href,"","");
    return false
  }

  // Is it a link to a directory?
  if (objElement.href.indexOf("directory.asp") > 0 ) {
    return setWidth(objElement.href);
  }

  // Is it a link to the Genie popup?
  if(objElement.href.indexOf("Genie.asp") > 0 || objElement.href.indexOf("MIBDetail") > 0 ) {
    return Genie(objElement.href);
  }

  // None of the above? 
  return true;
} 

function CheckOptions(objForm) {
  if (!document.getElementById) return true;

  var strReq = "";
  if (document.getElementById("req")) strReq = document.getElementById("req").value;

  if (strReq == "" ) return true;
  var strMsg = "";
  var arrPairs,objField,strType; 

  arrPairs = strReq.split("^");
  for (var I=0;I<arrPairs.length;I++) {
    objField = document.getElementById(arrPairs[I].substr(0,3)) 

    strType = objField.type?objField.type:objField[0].type;
    CheckFields:
      switch (strType) {
	case "select-one":
	  if (objField.selectedIndex == 0) strMsg += arrPairs[I].substr(4) + "\n"
	  break;
	case "textarea":
	  if (objField.value == "") strMsg += arrPairs[I].substr(4) + "\n"
	  break;
	case "text":
	  if (objField.value == "") strMsg += arrPairs[I].substr(4) + "\n"
	  break;
      }
  } 

  if (strMsg == "") return true;

  strMsg = "Please choose option(s) shown below\nbefore pressing \"Add to Cart\"\n\n" + strMsg
  alert(strMsg);
  return false;
}

function ShowHide(strType,numIndex) {
  if (numIndex > 0) {
    document.getElementById("Edit-" + strType).disabled=""
  } else {
    document.getElementById("Edit-" + strType).disabled="disabled"
  }
}

document.onclick=checkLink