
function MM_openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}
function makeWindow1(){
	var  win = window.open("", "newWindow1","HEIGHT=350,WIDTH=250,scrollbars=yes");
	document.maillist1.target = "newWindow1";
}
  function showElem(id) {
    var el = getElemRef(id);
    showElemObj(el);
  }
  function showElemObj(el) {
    if (el && el.css) el.css.display = "block";
  }
  function hideElem(id) {
    var el = getElemRef(id);
    hideElemObj(el);
  }
  function hideElemObj(el) {
    if (el && el.css) el.css.display = "none";
  }
  function getElemRef(id) {
    var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
    if (el) el.css = (el.style)? el.style: el;
    return el;
  }
  function toggleElem(id){
    var el = getElemRef(id);
    if(el.style.display == 'none'){
      showElem(id);
    } else{
      hideElem(id);
    }
  }
  function toggleDiv(id){
    toggleElem(id);
  }
  function isNumeric(testValue){
    var numericExpression = /^[0-9]+$/;
    if(testValue.match(numericExpression)){
      return true;
    } else{
      return false;
    }
  }
  function getElemRefs (theClass,container) {
    var allTags = new Array();
    container = container||document;
    var allTags=(container.getElementsByTagName)?container.getElementsByTagName("*"): (container.all)? container.all: (container.layers)? container.layers: null;
    //Cycle through the tags using a for loop
    var arr = []
    for (var i=0; i<allTags.length; i++) {
      //Pick out the tags with our class name
      if (allTags[i].className==theClass) {
        arr[arr.length] = allTags[i];
      }
    }
    return arr;
  }
  function toggleAll(theClass,container) {
    var arr = getElemRefs(theClass,container);
    if (arr != null) {
      for (var i=0; i<arr.length; i++) {
        var el = arr[i];
        if (el) el.css = (el.style)? el.style: el;
        if (el && el.css) {
          if (el.css.display == "none") {
            el.css.display = "block";
          } else {
            el.css.display = "none";
          }
        }

      }
    }
  }
  function setAndShow(content,id) {
    var obj = getElemRef(id);
    obj.innerHTML = content;
    showElemObj(obj);
  }
  function set(content,id) {
    var obj = getElemRef(id);
    obj.innerHTML = content;
  }
  function showElemAndHideOthersInClass(elemToShowId,elemsToHideClass) {
    showElemAndHideOthers(elemToShowId,getElemRefs(elemsToHideClass));
  }
  function showElemAndHideOthers(elemToShowId,elemsToHideArray) {
    var elemToShow = getElemRef(elemToShowId);
    if (elemToShow !=  null) showElem(elemToShowId);
    for(i = 0; i < elemsToHideArray.length; i++) {
      hideElemIfNotSelected(elemsToHideArray[i],elemToShow);
    }
  }
  function hideElemIfNotSelected(elemToHide,elemToShow) {
  	if (elemToHide != null) {
      if (elemToShow == null || elemToShow != elemToHide) {
        hideElemObj(elemToHide);
      }
  	}
  }
  function getValueFromSelectOrHidden(theObject) {
    var selectValObj = getSelectedObject(theObject);  
    var value = theObject.value;
    if (selectValObj != null) {
      value = selectValObj.value;
    }
    return value;
  }
  // return the index of the selected object
  function getSelectedIndex(selectObj) {
    if(!selectObj)
      return -1;
    var selectLength = selectObj.length;
    for(var i = 0; i < selectLength; i++) {
      if(selectObj[i].selected) {
        return i;
      }
    }
    return -1;
  }
  // return the selected object
  function getSelectedObject(selectObj) {
    return selectObj[getSelectedIndex(selectObj)];
  }
  // return the value of the radio button that is checked
  // return an empty string if none are checked, or
  // there are no radio buttons
  function getCheckedValue(radioObj) {
    if(!radioObj)
      return "";
    var radioLength = radioObj.length;
    if(radioLength == undefined)
      if(radioObj.checked)
        return radioObj.value;
      else
        return "";
    for(var i = 0; i < radioLength; i++) {
      if(radioObj[i].checked) {
        return radioObj[i].value;
      }
    }
    return "";
  }
  
  // set the radio button with the given value as being checked
  // do nothing if there are no radio buttons
  // if the given value does not exist, all the radio buttons
  // are reset to unchecked
  function setCheckedValue(radioObj, newValue) {
    if(!radioObj) {
      return;
    }  
    var radioLength = radioObj.length;
    if(radioLength == undefined) {
      radioObj.checked = (radioObj.value == newValue.toString());
      return;
    }
    for(var i = 0; i < radioLength; i++) {
      radioObj[i].checked = false;
      if(radioObj[i].value == newValue.toString()) {
        radioObj[i].checked = true;
      }
    }
  }
  function getFormObjByName(form, objName) {
    for(var i=0; i<form.elements.length; i++) {
      if (form.elements[i].name == objName) {
        return form.elements[i];
      }
    }
  }  
  function clearDefaultText(formfield){
    if(formfield.defaultValue==formfield.value)
      formfield.value = ""
  }
  function returnDefaultText(formfield) {
    if(formfield.value=="")
      formfield.value = formfield.defaultValue
  }
  window.addEvent('domready', function() {
    var customTips = $$('.tooltip');
    
    var toolTips = new Tips(customTips, {    
      showDelay: 100,    //default is 100
      hideDelay: 100,   //default is 100
      offsets: {
      'x': 16,       //default is 16
      'y': 16        //default is 16
    },
    fixed: false,      //default is false
    
    onShow: function(toolTip){
        toolTip.fade('in');
    },
    onHide: function(toolTip){
        toolTip.fade('out');
    }
    });
  });
  function setDivWithHtmlContent(div,content) {
    if (content != null) {
      $(div).set("html",content);
    } else {
      $(div).set("html","");
    }
  }

/*
 * Returns a new XMLHttpRequest object, or false if this browser
 * doesn't support it
 */
function newXMLHttpRequest() {
  var xmlreq = false;
  if (window.XMLHttpRequest) {
    // Create XMLHttpRequest object in non-Microsoft browsers
    xmlreq = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    // Create XMLHttpRequest via MS ActiveX
    try {
      // Try to create XMLHttpRequest in later versions
      // of Internet Explorer
      xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e1) {
      // Failed to create required ActiveXObject
      try {
        // Try version supported by older versions
        // of Internet Explorer
        xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e2) {
        // Unable to create an XMLHttpRequest with ActiveX
      }
    }
  }
  return xmlreq;
}
/*
 * Returns a function that waits for the specified XMLHttpRequest
 * to complete, then passes its XML response
 * to the given handler function.
 * req - The XMLHttpRequest whose state is changing
 * responseXmlHandler - Function to pass the XML response to
 */
function getReadyStateHandler(req, responseXmlHandler) {
  // Return an anonymous function that listens to the 
  // XMLHttpRequest instance
  return function () {
    // If the request's status is "complete"
    if (req.readyState == 4) {      
      // Check that a successful server response was received
      if (req.status == 200) {
        // Pass the XML payload of the response to the 
        // handler function
        responseXmlHandler(req.responseXML);
      } else {
        // An HTTP problem has occurred - this commonly happens when client clicks off the page before
        // the response is returned
      }
    }
  }
}

/*
 * Helper function to make it easy to call our Server
 */
function callServer(callBackMethod, params, modelName) {
  // Obtain an XMLHttpRequest instance
  var req = newXMLHttpRequest();

  // Set the handler function to receive callback notifications
  // from the request object
  var handlerFunction = getReadyStateHandler(req, callBackMethod);
  req.onreadystatechange = handlerFunction;
  
  // Open an HTTP GET connection to the shopping cart servlet.
  // Third parameter specifies request is asynchronous.
  if (!modelName || modelName == '') {
    modelName = "Checkout";
  }
  req.open("POST", "/Shop/Control/"+modelName+"/fp/SFV/32727" , true);

  // Specify that the body of the request contains form data 
  // Send vendorId as URL as it gets cut off from path (I think because there is no trailing /)
  req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

  // Send form encoded data stating that I want to add the 
  // specified item to the cart.
  req.send("SFV=32727&isAjax=true"+params);  
  
}
