/* toggleDisabled(oForm, bDisabled, sElement1 [, sElementn ...]) */

if(self != top)
  top.location.replace(self.location.href);

/* newWindow.js */

function newWindow(href, target, width, height)
{
  var returnValue = false;
  var features = (arguments.length == 4) ? 'scrollbars,status,width=' + width + ',height=' + height : ((arguments[4]) ? arguments[4] + ',width=' + width + ',height=' + height : 'width=' + width + ',height=' + height);
  if (window.screen)
  {
    var pxLeft = ((screen.availWidth - width - 10) * .5);
    var pxTop = ((screen.availHeight - height - 30) * .5);
    features += ',left=' + pxLeft + ',top=' + pxTop + ',x=' + pxLeft + ',y=' + pxTop;
  }
  if(!window.open)
    returnValue = true;
  else
  {
    self[target + 'Win'] = window.open(href, target, features);
    if(self[target + 'Win'].focus)
      self[target + 'Win'].focus();
  }
  return returnValue;
}

function sentenceList(list, concatenator)
{
  var returnValue = list;
  var delimiter = ',';
  var _tempArray = new Array();
  if(sentenceList.arguments.length == 3) delimiter = sentenceList.arguments[2];
  _tempArray = list.split(delimiter);
  if(_tempArray.length)
    returnValue = _tempArray[0];
  for(var i = 1; i < _tempArray.length - 1; i++)
    returnValue += ', ' + _tempArray[i];
  if(_tempArray.length > 2)
    returnValue += ',';
  if(_tempArray.length > 1)
    returnValue += ' ' + concatenator + ' ' + _tempArray[_tempArray.length - 1];
  return returnValue;
};

function addError(oElement, sError)
{
  var oError = (oElement.parentNode.firstChild.tagName.toLowerCase() == 'p') ? oElement.parentNode.firstChild : null;
  if(!oError)
  {
    oError = document.createElement('P');
    oError.className = 'error';
    oElement.parentNode.insertBefore(oError, oElement.parentNode.firstChild);
  }
  oError.innerHTML = sError;
  if(!Element.hasClassName(oElement.parentNode, 'error'))
    Element.addClassName(oElement.parentNode, 'error');
}

function removeError(oElement)
{
  var oError = (oElement.parentNode.firstChild.tagName.toLowerCase() == 'p') ? oElement.parentNode.firstChild : null;
  if(oError)
  {
    oError.removeNode(true);
    Element.removeClassName(oElement.parentNode, 'error');
  }        
}

var acceptTypes = ['jpg', 'jpeg'];

function validateInput(oElement)
{
	var returnValue = true;
	var filePath, fileName, fileExt;
	if(oElement.value)
	{
		filePath = (oElement.value.indexOf('/')) ? oElement.value.split('/') : oElement.value.split('\\');
		fileName = filePath[filePath.length - 1].split('.');
		fileExt = fileName[fileName.length - 1].toLowerCase();
		if(acceptTypes.indexOf(fileExt) == -1)
		{
			addError(oElement, 'Files may only be of type: ' + sentenceList(acceptTypes.join(','), ' or '));
			returnValue = false;
		}
		else
			removeError(oElement);
	}
	else
		removeError(oElement);
	return returnValue;
}
