/* Window Popup */
function aPopup(strWindowName, strURL, intWidth, intHeight,boolResizable, boolScrollbars) {
  var strOptions = "";
  strOptions = _aAddOptionStr(strOptions, "width",intWidth);
  strOptions = _aAddOptionStr(strOptions, "height",intHeight);
  
  if (boolResizable) {
    boolResizable = 'yes';
  }
  else {
    boolResizable = 'no';
  }
  strOptions = _aAddOptionStr(strOptions, "resizable",boolResizable);
  
  if (boolScrollbars) {
    boolScrollbars = 'yes';
  }
  else {
    boolScrollbars = 'no';
  }
  strOptions = _aAddOptionStr(strOptions, "scrollbars",boolScrollbars);    
  var resWnd = window.open(strURL,strWindowName, strOptions);
  resWnd.focus();
  return resWnd;
}

function aClose(resWnd) {
  if (resWnd) {
    resWnd.close();
  }
  else {
    window.close();
  }
}


function aToggleDisplay(_strLayerId, _boolShow) {
  var objLayer = document.getElementById(_strLayerId);
  if (objLayer) {
    if (_boolShow) {
      objLayer.style.display = 'block';
    }
    else {
      objLayer.style.display = 'none';
    }
  }
}



/* Window Resize */
function aResizeWindow(_intWidth, _intHeight) {
  if (window.outerWidth != _intWidth
        || window.outerHeight != _intHeight) {
    window.resizeTo(_intWidth, _intHeight);
  }
}


/* Checkboxes */
function aToggleCheckboxes(strName, objCB) {
  if (objCB && strName) { 
    for (var intKey = 0; intKey < objCB.form.elements[strName].length; intKey++) {
      objCB.form.elements[strName][intKey].checked = objCB.checked;
    }
  }
  return true;
}



/* FadeIn/FadeOut */
var arrFadedLayers = new Object();

function aFadeIn (_strLayerId) {  
  new Effect.Appear(_strLayerId);
  arrFadedLayers[_strLayerId] = true;
}

function aFadeOut (_strLayerId) {
  new Effect.Fade(_strLayerId);
  arrFadedLayers[_strLayerId] = false;
}

function aFadeToggle (_strLayerId) {
  if (arrFadedLayers[_strLayerId]) {
    aFadeOut(_strLayerId);
  }
  else {
    aFadeIn(_strLayerId);
  }
}


/* SlideIn/SlideOut */
var arrSlidedLayers = new Object();

function aSlideDown (_strLayerId) {  
  new Effect.SlideDown(_strLayerId);
  arrSlidedLayers[_strLayerId] = true;
}

function aSlideUp (_strLayerId) {
  new Effect.SlideUp(_strLayerId);
  arrSlidedLayers[_strLayerId] = false;
}

function aSlideToggle (_strLayerId) {
  if (arrSlidedLayers[_strLayerId]) {
    aSlideUp(_strLayerId);
  }
  else {
    aSlideDown(_strLayerId);
  }
}



/* Misc functions */

function _aAddOptionStr(strOptions, strProperty, mixVal) {
  if (mixVal && ((isNaN(mixVal) && String(mixVal).length > 0) || mixVal > 0)) {
    if (strOptions.length > 0) {
      strOptions = strOptions + ",";
    }
    strOptions = strOptions + strProperty+"="+mixVal;
  }
  return strOptions;
}


/* OnLoad Event */
function aAddOnLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}