String.prototype.trim = function(){ return this.replace(/^\s+|\s+$/g,'') };

function fadeRow(target) { 
		new Effect.Highlight(target, {endcolor:'#BBD2DD'});
}

function showHideEl(elId){
	if (document.getElementById(elId).style.display == 'none'){
		new Effect.BlindDown(elId);
	} else {
		new Effect.BlindUp(elId);
	}
	}

	function showHideEl_fade(elId){
	if (document.getElementById(elId).style.display == 'none'){
		new Effect.Appear(elId);
	} else {
		new Effect.Fade(elId);
	}
	}

function toggleHiddenBlock(blockId){
		var block = document.getElementById(blockId);
		
		if (block.style.display == 'none'){
			block.style.display = 'block';
		}else{
			block.style.display = 'none';
		}
	}
	
	
function hideId(elID) {
	
	if (document.getElementById(elID).style.display != 'none'){
//		document.getElementById(elID).style.display = 'none';
//	new Effect.BlindUp(elID);
	new Effect.Fade(elID);		
	}
}
function showId(elID) {

	if (document.getElementById(elID).style.display == 'none'){
	//document.getElementById(elID).style.display = 'block';
//	new Effect.BlindDown(elID);
	new Effect.Appear(elID);	
	}
}

// Generic function to change display state to none
//
// Arguments are:
// div: the id of the div to be checked.
//

function closeSection(div) {
	document.getElementById(div).style.display = 'none';
}

function hideAllClasses(tagName, className) {
//	alert(document.getElementsByTagName(tagName).item(10).className.indexOf(className));
//	 myString.indexOf("com")
	for (i=0;i<document.getElementsByTagName(tagName).length; i++) {
		if (document.getElementsByTagName(tagName).item(i).className.indexOf(className) != -1){
			//alert(document.getElementsByTagName(tagName).item(i).className.indexOf(className));
			document.getElementsByTagName(tagName).item(i).style.display = 'none';
		}
	}
}

function getWindowHeight(){
winH = 1200;

if (parseInt(navigator.appVersion)>3) {
 if (navigator.appName=="Netscape") {
  winH = document.documentElement.scrollHeight ;
 }
 if (navigator.appName.indexOf("Microsoft")!=-1) {
//having trouble getting the correct height for total scroll to hard code the height;
//winH = document.body.scrollHeight;
  winH=3000;
 }
}
return winH;
}


function getWindowWidth(){
winW = 1200;

if (parseInt(navigator.appVersion)>3) {
 if (navigator.appName=="Netscape") {
  winW = document.documentElement.scrollWidth ;
 }
 if (navigator.appName.indexOf("Microsoft")!=-1) {
  //winW = document.body.offsetWidth;
  winW = document.body.scrollWidth;
  
 }
}
return winW;
}

// Bunch of fly-fu to set up the floaters, thanks J!


function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
		return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
		return curtop;
}

function getCoords(obj, offsetX, offsetY) {
	var xPos = (findPosX(obj) - offsetX) + "px";
	var yPos = (findPosY(obj) - offsetY) + "px";
	return {xPos : xPos, yPos : yPos};
}


function hideSelects(action) {
//documentation for this script at http://www.shawnolson.net/a/1198/
//possible values for action are 'hidden' and 'visible'
if (action!='visible'){action='hidden';}
if (navigator.appName.indexOf("MSIE")) {
for (var S = 0; S < document.forms.length; S++){
for (var R = 0; R < document.forms[S].length; R++) {
if (document.forms[S].elements[R].options) {
document.forms[S].elements[R].style.visibility = action;
}
}
}
}
}

// used for labeling quick invite fields
// inspired by aaron boodman's labels.js
var fancyLabels = {
  init: function(id) {
    if(!document.getElementById || !document.getElementById(id)) return;

    var div = document.getElementById(id);
    var lbls = div.getElementsByTagName('span');
    for(var i = 0; i < lbls.length; i++) {
      fancyLabels.initLabel(lbls[i]);
    }
    
    var form = div.getElementsByTagName('form')[0];
    addEvent(form, 'submit', function() { fancyLabels.wipeLabels(div) });
  },
  
  initLabel: function(span) {
    span.style.display = 'none';
    var lbl = span.getElementsByTagName('label')[0];
    var input = document.getElementById(lbl.htmlFor);
    input._label = lbl.firstChild.nodeValue;
    addEvent(input, 'focus', fancyLabels.focusedLabel);
    addEvent(input, 'blur', fancyLabels.blurredLabel);
    if(input.value == '') fancyLabels.showLabel(input);
  },
  
  wipeLabels: function(div) {
    var inputs = div.getElementsByTagName('input');
    for(var i = 0; i < inputs.length; i++) {
      if(inputs[i].value == inputs[i]._label) fancyLabels.hideLabel(inputs[i]);
    }
  },
  
  focusedLabel: function(e) {
    var input = window.event ? window.event.srcElement : e ? e.target : null;
    if(input.value == input._label) fancyLabels.hideLabel(input);
  },
  
  blurredLabel: function(e) {
    var input = window.event ? window.event.srcElement : e ? e.target : null;
    if(input.value == '') fancyLabels.showLabel(input);
  },
  
  hideLabel: function(input) {
    input.value = '';
    input.style.color = '#000';
  },
  
  showLabel: function(input) {
    input.value = input._label;
    input.style.color = '#999';
  }
}

function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  }
}


function splitValue(){
	var bilAmount = document.getElementById('biiamount').value;
	var conCount = document.getElementsByName('bismemfk');
	for (i=0; i <= conCount.length-1; i++){
		var bilSplit = bilAmount / conCount.length;
		var el = "splitvalue_" + conCount[i].value.toString();
		document.getElementById(el).value = bilSplit.toFixed(2)
		
	}
}

function showFormBasedOnCombo(el, Id1, value){
	var intValue = el.value;
	if (intValue != value) {
		//show add new section
		showId(Id1);
		//hideId(Id2);
	}else {
		//hide it
		hideId(Id1);
		//showId(Id2);
	}
}