/*
  Scrub the Search
*/
  function checkSearch(anId) {
    ok = false;
    term = document.getElementById(anId);
    if (term != null && term.value.length > 0) {
      var stuff = new RegExp("[^a-zA-Z0-9_ .*~-]","g");
      term.value = term.value.replace(stuff,"");
      term.value = term.value + "*";
      ok = true;
    }
    return ok;
  }


/*
  Get Id

  Parameters: anId

  Returns the DOM object associated to the Id passed into the function.
*/
  function getById(aString) {
    return document.getElementById(aString);
  }


/*
  Get Names

  Parameters: names

  Returns the DOM objects associated to a partial match of the name string
  passed into the function.
*/
  function getByNames(aString) {
    return document.getElementsByName(aString);
  }

/*
  ----------------------------------------------------------------------------
    Check for Valid Email

    checks for a period and the at symbol

    anId is the ID of the input field

    return true if passed, false if failed

    Ex: <form action="#" onsubmit="return checkEmail('emailA')">
          <input name="emailA" id="emailA" type="text">
  ----------------------------------------------------------------------------
*/

function checkEmail(anId) {
  var e = document.getElementById(anId);
  var ok = false;
  if (e != null) {
    if (e.value.indexOf(".") != -1 && e.value.indexOf("@") != -1) {
      ok =  true;
    }
  }
  return ok;
}

function alignColumns() {
  var lb = document.getElementById("left_block");
  var rb = document.getElementById("right_block");
  if (lb != null && rb != null) {
    if (lb.offsetHeight < rb.offsetHeight) {
      lb.style.height = rb.offsetHeight + "px";
    } else {
      rb.style.height = lb.offsetHeight + "px";
    }
  }
//  if (window.attachEvent && document.title != "UWantSavings: Your Account Update") {
//    window.attachEvent('onresize',function(){document.location.reload();});
  /*
    window.attachEvent('onresize',function(){
      document.location.reload();
    });
  */
//  }
}


function changeDiv(theDiv, divChange) {
	var theStyle = getStyleObject(theDiv);
	if (theStyle != false) {
		theStyle.display = divChange;
	}
}

function getStyleObject(objectId) {
	if (document.getElementById && document.getElementById(objectId)) {
		return document.getElementById(objectId).style;
	} else if (document.all && document.all(objectId)) {
		return document.all(objectId).style;
	} else {
		return false;
	}
}

window.addEvent('domready', function() {
  var topdeals = $$('.dealsMenu')[0];
  if (topdeals != null) {
    var plusses = topdeals.getElements('.plus'); 
    plusses.addEvent('click', function() {
      var thisPlus = this;
      var dm = thisPlus.getParent().getElement('.dealsMenuClick');
  
      thisPlus.getParent().getParent().getParent().getElements('.plus').each(function(item) {
        if (!item.getParent().hasChild(dm)) {
          var pDiv = item.getParent(); 
          pDiv.getElements('.dealsMenuClick').setStyle('display', 'none');
          item.set('html',' [+] ');
        }
      });
      
      if (thisPlus.get('html').contains('-')) {
        dm.setStyle('display', 'none');
        thisPlus.set('html',' [+] ');
      } else {
        dm.setStyle('display', 'block');
        thisPlus.set('html',' [-] ');
      }
    });
  }
});
