String.prototype.trim = function() {
   return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
   return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
   return this.replace(/\s+$/,"");
}


function getElementsByClass( searchClass, domNode, tagName) {
  if (domNode == null) domNode = document;
  if (tagName == null) tagName = '*';
  var el = new Array();
  var tags = domNode.getElementsByTagName(tagName);
  var tcl = " "+searchClass+" ";
  for(i=0,j=0; i<tags.length; i++) {
    var test = " " + tags[i].className + " ";
    if (test.indexOf(tcl) != -1)
      el[j++] = tags[i];
  }
  return el;
}



function showCreditRequestForm()
{
   document.getElementById('creditRequestForm').style.display = 'block';
   document.getElementById('creditLink').style.display = 'none';
}

function hideCreditRequestForm()
{
   document.getElementById('creditRequestForm').style.display = 'none';
   document.getElementById('creditLink').style.display = 'block';
}

function checkReason()
{
   comments = document.getElementById('comments');

   if (comments.value.trim().length < 2) {
      alert('You must enter a problem description.');
      return false;
   } else {
      return true;
   }
}

function toggle_specific(id)
{
	div = document.getElementById(id);
	arrow = document.getElementById('arrow-' + id);
	
	if (div.style.display == 'block') {
		div.style.display = 'none';
		arrow.src = '/images/arrow-closed.gif';
	} else {
		div.style.display = 'block';
		arrow.src = '/images/arrow-open.gif';
	}
}

function toggle_specific_table(id)
{
	// I apologize for the user-agent detection here
	
	div = document.getElementById(id);
	arrow = document.getElementById('arrow-' + id);
	
	if (navigator.userAgent.indexOf('Firefox') != -1) {
		// we're running firefox
		mode = 'table-cell';
	} else {
		// we're running not firefox
		// this works in IE6 and is untested elsewhere (IE7, Opera, Safari/Konq)
		mode = 'block';
	}
	
	if (div.style.display == 'none') {
		div.style.display = mode;
		arrow.src = '/images/arrow-open.gif';
	} else {
		div.style.display = 'none';
		arrow.src = '/images/arrow-closed.gif';
	}
}



function toggle_rows(classname)
{
  rows = getElementsByClass(classname);
  arrow = document.getElementById('arrow-' + classname);
  
  for (i=0; i<rows.length; i++)
  {
    if (rows[i].style.display == 'none') 
    {
      // show rows
      rows[i].style.display = '';
      arrow.src = '/images/arrow-open.gif';
    }
    else
    {
      // hide rows
      rows[i].style.display = 'none';
      arrow.src = '/images/arrow-closed.gif';
    }
  }
}


function checkAuditParameters()
{
	company_sel = document.getElementById('company_id');
	percept_sel = document.getElementById('perceptionist_id');
	
	comp_id = company_sel.options[company_sel.selectedIndex].value;
	percept_id = percept_sel.options[percept_sel.selectedIndex].value;
	
	if (comp_id == '' && percept_id == '') {
		alert('You cannot select "any perceptionist" and "any company" at the same time.  Please select one or the other.');
		return false;
	}
	
	return true;
}

function popupCreditHelp()
{
	window.open('/credithelp.html', 'credithelp', 'status=0,resizable=1,scrollbars=1,location=0,width=584,height=417');
}


function popupBlackoutHelp()
{
	window.open('/blackouthelp.html', 'credithelp', 'status=0,resizable=1,scrollbars=1,location=0,width=584,height=417');
}
