function rowOverEffect(object) {
  if (Element.Methods.hasClassName(object, 'deactivatedRow')) {
    Element.Methods.removeClassName(object, 'deactivatedRow');
    Element.Methods.addClassName(object, 'mouseOverDeactivatedRow');
  }
  else if (Element.Methods.hasClassName(object, 'newRow')) {
    Element.Methods.removeClassName(object, 'newRow');
    Element.Methods.addClassName(object, 'mouseOverNewRow');
  } else if (Element.Methods.hasClassName(object, "dataSpecialTable"))  {
    Element.Methods.removeClassName(object, 'dataSpecialTable');
    Element.Methods.addClassName(object, "mouseOverDataSpecialTable");
  } else {
    Element.Methods.addClassName(object, 'mouseOver');
  }
}

function rowOutEffect(object) {
  if (Element.Methods.hasClassName(object, 'mouseOverDeactivatedRow')) {
    Element.Methods.removeClassName(object, 'mouseOverDeactivatedRow');
    Element.Methods.addClassName(object, 'deactivatedRow');
  }
  else if (Element.Methods.hasClassName(object, 'mouseOverNewRow')) {
    Element.Methods.removeClassName(object, 'mouseOverNewRow');
    Element.Methods.addClassName(object, 'newRow');
  }
  else if (Element.Methods.hasClassName(object, "mouseOverDataSpecialTable")) {
    Element.Methods.removeClassName(object, 'mouseOverDataSpecialTable');
    Element.Methods.addClassName(object, "dataSpecialTable");
  } else {
    Element.Methods.removeClassName(object, 'mouseOver');
  }
}

function updateDatePullDownMenu(objForm, fieldName) {
  var pdmDays = fieldName + "_days";
  var pdmMonths = fieldName + "_months";
  var pdmYears = fieldName + "_years";

  time = new Date(objForm[pdmYears].options[objForm[pdmYears].selectedIndex].text, objForm[pdmMonths].options[objForm[pdmMonths].selectedIndex].value, 1);

  time = new Date(time - 86400000);

  var selectedDay = objForm[pdmDays].options[objForm[pdmDays].selectedIndex].text;
  var daysInMonth = time.getDate();

  for (var i=0; i<objForm[pdmDays].length; i++) {
    objForm[pdmDays].options[0] = null;
  }

  for (var i=0; i<daysInMonth; i++) {
    objForm[pdmDays].options[i] = new Option(i+1);
  }

  if (selectedDay <= daysInMonth) {
    objForm[pdmDays].options[selectedDay-1].selected = true;
  } else {
    objForm[pdmDays].options[daysInMonth-1].selected = true;
  }
}

function toggleDivBlocks(group, exempt) {
  if (!document.getElementsByTagName) return null;

  if (!exempt) exempt = "";

  var divs = document.getElementsByTagName("div");

  for(var i=0; i < divs.length; i++) {
    var div = divs[i];
    var id = div.id;

    if ((id != exempt) && (id.indexOf(group) == 0)) {
      hideBlock(id);
    }
  }

  showBlock(exempt);
}

function toggleInfoBox(exempt) {
  if (!exempt || !document.getElementsByTagName) return null;

  var infoBox = "infoBox_" + exempt;

  var divs = document.getElementsByTagName("div");

  for(var i=0; i < divs.length; i++) {
    var div = divs[i];
    var id = div.id;

    if (id.indexOf("infoBox_") == 0) {
      var infoBoxForm = id.substring(8);

      if (document.forms[infoBoxForm]) {
        document.forms[infoBoxForm].reset();
      }

      if (id != infoBox) {
        hideBlock(id);
      }
    }
  }

  showBlock(infoBox);
}

function showBlock(id) {
  if (document.getElementById) {
    itm = document.getElementById(id);
  } else if (document.all){
    itm = document.all[id];
  } else if (document.layers){
    itm = document.layers[id];
  }

  if (itm) {
    itm.style.display = "block";
  }
}

function hideBlock(id) {
  if (document.getElementById) {
    itm = document.getElementById(id);
  } else if (document.all){
    itm = document.all[id];
  } else if (document.layers){
    itm = document.layers[id];
  }

  if (itm) {
    itm.style.display = "none";
  }
}

function toggleClass(removeClass, addClass, cssClass, tagName) {
  if (!document.getElementsByTagName) return null;

  if (!tagName) tagName = "div";

  var tags = document.getElementsByTagName(tagName);

  for(var i=0; i < tags.length; i++) {
    var tag = tags[i];
    var id = tag.id;

    if ((id != addClass) && (id.indexOf(removeClass) == 0)) {
      tag.className = "";
    }
  }

  document.getElementById(addClass).className = cssClass;
}

function selectAllFromPullDownMenu(field) {
  var field = document.getElementById(field);

  for (i=0; i < field.length; i++) {
    field.options[i].selected = true;
  }
}

function resetPullDownMenuSelection(field) {
  var field = document.getElementById(field);

  for (i=0; i < field.length; i++) {
    field.options[i].selected = false;
  }
}

function flagCheckboxes(element) {
  var elementForm = element.form;
  var i = 0;

  for (i = 0; i < elementForm.length; i++) {
    if (elementForm[i].type == 'checkbox') {
      elementForm[i].checked = element.checked;
    }
  }
}

// Returns array with x,y page scroll values
// Core code from - quirksmode.org
function getPageScroll() {
  var yScroll;

  if (self.pageYOffset) {
    yScroll = self.pageYOffset;
  } else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
    yScroll = document.documentElement.scrollTop;
  } else if (document.body) { // all other Explorers
    yScroll = document.body.scrollTop;
  }

  arrayPageScroll = new Array('', yScroll);

  return arrayPageScroll;
}

/**
 * Selector of products on the page for batch actions
 *
 * This function makes selection of checkboxes elements on the listing of products page for batch actions
 *
 * @param object javascript select object that represents user wishes of selection
 *                          possible value are:
 *                            [empty] - no action is required
 *                            select_all - select all products (including not visible on the page)
 *                            select_visible - select visible on the page products
 *                            unselect_all - unselect all products
 *                            unselect_visible - unselect visible products
 *
 * @access public
 * @static
 */
function flagCheckboxesAdvanced(element) {
  var elementForm = element.form;
  if (element.value=='') {
    return;
  }

  var i = 0;
  for (i = 0; i < elementForm.length; i++) {
    if (elementForm[i].type == 'checkbox') {
      if (element.value=='select_all') {
        elementForm[i].checked = true;
        //disable possibility to change selection to user if select_all is selected
        elementForm[i].disabled = true;
      } else if (element.value=='select_visible') {
        elementForm[i].checked = true;
        elementForm[i].disabled = false;
      // in case of unselect action unselect_all or unselect_visible are really the same actions
      } else if (element.value=='unselect_all' || element.value=='unselect_visible') {
        elementForm[i].checked = false;
        elementForm[i].disabled = false;
      }
    }
  }
}

// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
function getPageSize() {
  var xScroll, yScroll;

  if (window.innerHeight && window.scrollMaxY) {
    xScroll = document.body.scrollWidth;
    yScroll = window.innerHeight + window.scrollMaxY;
  } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
    xScroll = document.body.scrollWidth;
    yScroll = document.body.scrollHeight;
  } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
    xScroll = document.body.offsetWidth;
    yScroll = document.body.offsetHeight;
  }

  var windowWidth, windowHeight;

  if (self.innerHeight) { // all except Explorer
    windowWidth = self.innerWidth;
    windowHeight = self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
  } else if (document.body) { // other Explorers
    windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
  }

// for small pages with total height less then height of the viewport
  if (yScroll < windowHeight) {
    pageHeight = windowHeight;
  } else {
    pageHeight = yScroll;
  }

// for small pages with total width less then width of the viewport
  if (xScroll < windowWidth) {
    pageWidth = windowWidth;
  } else {
    pageWidth = xScroll;
  }

  arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);

  return arrayPageSize;
}


/**
 * Show tab function
 *
 * This function displays the right content with each tab
 *
 * @param tabArray this array contains all tab names of the tab listing
 * @param currentTab contains the current tab element
 * @param currentPanel contains the current panel element corresponding with the tab
 *
 * @access public
 * @static
 */
function showTab(tabArray, currentTab, currentPanel) {

  /**
   * Reset all tab element id's
   */
  for(i = 0; i < currentTab.parentNode.parentNode.childNodes.length; i++) {
    if(currentTab.parentNode.parentNode.childNodes[i].nodeName == 'LI') {
      currentTab.parentNode.parentNode.childNodes[i].firstChild.id = '';
    }
  }

  /**
   * Set the current tab id to the id btv_tabs_active
   */
  currentTab.id = 'btv_tabs_active';

  /**
   * Set all panel display values to none except the current panel
   */
  for(i = 0; i < tabArray.length; i++) {
    document.getElementById(tabArray[i]).style.display = (currentPanel == tabArray[i]) ? 'block':'none';
  }

  return false;
}

function showMessages(messages)
  {
    var messagesDiv = document.getElementById('divMessages');
    if (messagesDiv == undefined) {
      if (addMessagesDiv()) {
        messagesDiv = document.getElementById('divMessages');
      } else {
        return false;
      }
    }
    messagesDiv.innerHTML = messages;
  }

  function addMessagesDiv(){
    var container = document.getElementById('divMessagesContainer');
    if (container == undefined) {
      return false;
    }
    var div1 = document.createElement('div');
    div1.setAttribute('id','content');
    div1.setAttribute('style','margin-bottom: 20px;');
    div1.style.marginBottom = '20px';
    container.appendChild(div1);
    var div2 = document.createElement('div');
    div1.appendChild(div2);
    var div3 = document.createElement('div');
    div2.appendChild(div3);
    var div4 = document.createElement('div');
    div3.appendChild(div4);
    var div5 = document.createElement('div');
    div4.appendChild(div5);
    var div6 = document.createElement('div');
    div5.appendChild(div6);
    var div7 = document.createElement('div');
    div7.setAttribute('id','mainTable');
    div6.appendChild(div7);
    var div8 = document.createElement('div');
    div7.appendChild(div8);
    var div9 = document.createElement('div');
    div8.appendChild(div9);
    var div10 = document.createElement('div');
    div9.appendChild(div10);
    var div11 = document.createElement('div');
    div10.appendChild(div11);
    var div12 = document.createElement('div');
    div11.appendChild(div12);
    var div13 = document.createElement('div');
    div13.setAttribute('id','divMessages');
    div13.setAttribute('style','color: #dd0000; font-weight: bold;');
    div13.style.color = '#dd0000';
    div13.style.fontWeight = 'bold';
    div12.appendChild(div13);
    return true;
  }

  function setCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  }

function getCookie(name) {
  var cookie = " " + document.cookie;
  var search = " " + name + "=";
  var setStr = null;
  var offset = 0;
  var end = 0;
  if (cookie.length > 0) {
    offset = cookie.indexOf(search);
    if (offset != -1) {
      offset += search.length;
      end = cookie.indexOf(";", offset)
      if (end == -1) {
        end = cookie.length;
      }
      setStr = unescape(cookie.substring(offset, end));
    }
  }
  return(setStr);
}
