Array.prototype.contains = function (element) {
	for (var i = 0; i < this.length; i++) {
		if (this[i] == element) {
			return true;
        }
    }
	return false;
};

function switchDivVisibility(strDivName,bolVisible){
	if(!document.getElementById(strDivName)) return;
	var objElement = document.getElementById(strDivName).style;
	
	if(!bolVisible){
		objElement.display = "none";
	} else {
		objElement.display = "";
	}
}

function testOnKeyPress(e) {
	var keynum;
	var keychar;
	var numcheck;
	
	if(window.event) { // IE
		keynum = e.keyCode;
	}
	else if(e.which) {// Netscape/Firefox/Opera
  		keynum = e.which;
  	}
	alert(keynum);
}

function taLimit2(taObj, maxLength, e) {
	var keynum;
	var keychar;
	var numcheck;
	
	if(window.event) { // IE
		keynum = e.keyCode;
	}
	else if(e.which) {// Netscape/Firefox/Opera
  		keynum = e.which;
  	}
	
  	if (keynum == 8 || keynum == undefined)
  		return true;
	
	if (taObj.value.length==maxLength) return false;
}

function taCount2(taObj, span_id, maxLength) {
	if (taObj.value.length>maxLength) taObj.value=taObj.value.substring(0,maxLength);

	var visCnt = document.getElementById(span_id);
	//alert(maxLength-taObj.value.length);
	visCnt.innerHTML=maxLength-taObj.value.length;
}

function OpenVariableWindow(link, winName, intWidth, intHeight){
	var newWindow;
	var screenWidth = screen.width;
	var displayPos = ((screenWidth/2) - (intWidth/2));
	newWindow = window.open( link, winName, "toolbar,width=" + intWidth + ",height=" + intHeight + ",left=" + displayPos + ",scrollbars,resizable");
	newWindow.focus();
}

var processingDivs = new Array();
function processingTextDiv(div, num) {
	var txt = processingDivs[div];
	
	if (!txt) {
		stopProcessingTextDiv(div);
	}
	else {
		num++;
		
		if (num > 4)
			num = 0;
		
		// display new text
		for(var i=1; i <= num; i++) {
			txt += '.';
		}
		
		var elem = document.getElementById(div);
		elem.innerHTML = txt;
			
		setTimeout('processingTextDiv(\'' + div + '\', ' + num + ');', 500);
	}
}

function startProcessingTextDiv(div) {
	// get the html text in the div
	var elem = document.getElementById(div);	
	elem.style.display = '';
	processingDivs[div] = elem.innerHTML;
	
	setTimeout('processingTextDiv(\'' + div + '\', 0);', 500);
}

function stopProcessingTextDiv(div) {
	processingDivs[div] = '';
	
	// hide div
	var elem = document.getElementById(div);
	elem.style.display = 'none';
}

function displayJavaLayerUrl(url, width, height) {
	if (!width)
		width = 750;
	if (!height)
		height = 600;
	
	javaLayer.setSource(url);
	javaLayer.setCssClassMessageBox(false);
	javaLayer.setSize(width, height);
	javaLayer.setShadowDivVisible(true);	// Enable shadow for these boxes
	javaLayer.display();
}

function displayJavaLayer(messageContent, width, height) {
	if (!width)
		width = 300;
	if (!height)
		height = 150;
	
	javaLayer.setHtmlContent(messageContent);
	javaLayer.setSize(width, height);
	javaLayer.setCssClassMessageBox(cssClass);
	javaLayer.setSource(false);	// no html source since we want to use a static message here.
	javaLayer.setShadowDivVisible(false);	// Disable shadow for these boxes	
	javaLayer.display();
}

function closeJavaLayer() {
	javaLayer.close();	
}

function getFloat(strIn){
   //strip all non numeric digits out of string and parse the resulting float
   strIn = strIn + "";
   if(strIn.length == 0) return 0
   var digit
   var strFloat = ""
   for(var i=0; i<strIn.length; i++){
      digit = strIn.charAt(i)
      if(digit == "-" || digit == "." || (digit >= "0" && digit <= "9")) strFloat += digit
   }
   if(strFloat == "") return 0
   var flt = parseFloat(strFloat)
   if(isNaN(flt)) return 0
   return flt
}

function formatNumber(strNum, dec){
	//num = the number to format, dec = # of decimal places
	//convert str to float
	var num = getFloat(strNum + "")
	//if negative number, capture sign and convert to positive number
	var negSign = "";
	if(num < 0){
		negSign = "-";
		num = -num;
	}
	//round to appropriate spot
	num = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec)
	//convert num to string
	var strOut = num + ""
	//add 0's if required
	var i //index of decimal
	var d //number of decimal places already in number
	if(dec > 0){
	   i = strOut.indexOf(".")
	   if(i == -1){
	      strOut += "."
	      d = 0
	   }else{
	      d = strOut.length - i - 1
	   }
	   for(var j=0; j<dec-d; j++) strOut += "0"
	}
	//add commas by building string backwards
	var strTemp = strOut
	//grab decimal portion of number
	strOut = (dec > 0) ? strTemp.substr(strTemp.length-dec-1,dec+1) : ""
	i = 0
	for(var j=strTemp.length-strOut.length-1; j >= 0; j--){
	   if(i==3){
	      strOut = "," + strOut
	      i = 0
	   }
	   strOut = strTemp.charAt(j) + strOut
	   i = i + 1
	}
	return negSign + strOut;
}

function validateRange(ctl, rLow, rHigh){
	var val = getFloat(ctl.value);
	if(val < rLow){
		ctl.value = rLow;
		alert("The minimum value for this field is " + rLow + ".");
		return;
	}
	if(val > rHigh){
		ctl.value = rHigh;
		alert("The maximum value for this field is " + rHigh + ".");
		return;
	}
}

function updateImages(strIDs){
	var strIDs = "," + strIDs + ",";
	var img;
	var arImages = document.getElementsByTagName("img");
	for(var j=0; j<arImages.length; j++){
		if(arImages[j].name.substr(0,3) == "img"){
			var id = "," + arImages[j].name.substr(3,50) + ",";
			if(strIDs.indexOf(id) != -1){
				arImages[j].src = "../images/shopping_cart.gif";
			}else{
				arImages[j].src = "../images/give.gif";
			}
		}
	}
}

function validateLength(ctl, intLen){
	if(ctl.value.length > intLen){
		alert("The maximum number of characters for this field is " + intLen + "." + 
			" Any additional characters will not be saved.");
		ctl.value = ctl.value.substr(0,intLen);
	}
}
