
function ButtonOn(TheButton){
	TheButton.style.backgroundColor='#FFee00';
	}
	
function ButtonOff(TheButton){
	TheButton.style.backgroundColor='#ffcc00';
	}
	
function TextClear(TheItem, TheString){
		if(TheItem.value==TheString){
			TheItem.value='';
		}
		TheItem.style.color='black';
	}
	
	
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : "";
            var imgClass = (img.className) ? "class='" + img.className + "' " : "";
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
            var imgStyle = "display:inline-block;" + img.style.cssText ;
            if (img.align == "left") imgStyle = "float:left;" + imgStyle;
            if (img.align == "right") imgStyle = "float:right;" + imgStyle;
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"; 
            img.outerHTML = strNewHTML;
            i = i-1;
         }
      }
   }    
}	
	
	
//Removes all whitespaces in 2 steps... left and right trims
function TrimLeft( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}
// remove right spaces
function TrimRight( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

// Removes left spaces
function trim( value ) {
	return TrimLeft(TrimRight(value));
}


//nice center popup function
function CenterPopup(link,name,height,width,type){
			
	var winl,wint;
	if(screen.width)
	{
		winl = (screen.width-width)/2;
		wint = (screen.height-height)/2;
	}

	if (winl < 1) winl = 0;
	if (wint < 1) wint = 0;
					
	var settings = 'height=' + height + ',';
	settings += 'width=' + width + ',';
	settings += 'top=' + wint + ',';
	settings += 'left=' + winl + ',';
	
	switch (type){
		case 1:
			settings += 'menubar=yes,toolbar=yes,location=yes,scrollbars=yes';
			break;
		case 2:
			settings += 'menubar=no,toolbar=no,location=no,scrollbars=yes';
			break;
		default:
			settings += 'menubar=no,toolbar=no,location=no,scrollbars=no';
		}

	var newWindow = window.open(link, name , settings);
	if(!newWindow) 
		alert("new window appears to have been blocked.");
	else
		newWindow.focus();
	
	//return(newWindow);
}

	
function GetPopup(sPopoverThis, sPopoverID, sPage, sString, iHeightOffset, iHorizOffset){

	//sPopoverId="HelpPopup";
	var newX,newY
	if (sPopoverThis != null)
	{
		newX = $(sPopoverThis.id).getLeft()+iHorizOffset;
		newY = $(sPopoverThis.id).getTop()+iHeightOffset;
	}
	else
	{
		newX = 400;
		newY = 300;
	}
	
	ThePopup=$(sPopoverID);
	ThePopup.style.left=newX+'px';
	ThePopup.style.top=newY+'px';
	ThePopup.style.display='block';
	ThePopup.innerHTML='<div id=\'RSM_LOADING\' >Loading...</div>';

//	document.location = sPage+ '?' +sString;

	new Ajax(sPage, {method: "get",update: $(sPopoverID)}).request(sString);
}
	
	
////  8-10-07    I think we should move all the stuff below this point to other JS files	
	
//*************************
//These functions make the popup dynamically page smaller...
//************************

function PopupHilight(div){div.style.backgroundColor='#bbbbff';}
function PopupUnHilight(div){div.style.backgroundColor='#ffffff';}

function PopupClick(sTheObject, name){
		$(sTheObject).value=name;
		$(sTheObject).focus();
		hide_div();
	}
//***********************
//EXPANDER
//constant step size... how much to expand the div each time
	var stepsize=10;
	//holder variables
	var ExpandObject;
	var speed;
	var MaxHeight;
	var MaxWidth;
	var CurrentHeight;
	var CurrentWidth;
	var EXP_in_progress=false;
	
	function OpenObject(object, height, TheSpeed, TheStep){
		if(!EXP_in_progress){//if another process isn't running
			stepsize=TheStep;
			EXP_in_progress=true; //lets everyone know that a function is running
			ExpandObject=$(object);
			MaxHeight=height;
			speed=TheSpeed;
			if(ExpandObject.style.height.replace('px','')){
				eval('CurrentHeight='+ExpandObject.style.height.replace('px','')+';'); //sets the numeric variable current height to the value of the height
			}else{
				CurrentHeight=0;
			}
			if(CurrentHeight>=MaxHeight){
				CurrentHeight=MaxHeight;
				ContractIt();
			}else{
				CurrentHeight=0;
				ExpandObject.style.display='block'; 
				ExpandIt(); }
		}
	}
	
	function ExpandIt(){
		if(CurrentHeight<=MaxHeight){
			CurrentHeight=CurrentHeight+stepsize;
			ExpandObject.style.height=CurrentHeight+'px';
			setTimeout("ExpandIt()",speed);
		}else{
			EXP_in_progress=false;
		}
	}
	function ContractIt(){
		if(CurrentHeight>0){
			CurrentHeight=CurrentHeight-stepsize;
			ExpandObject.style.height=CurrentHeight+'px';
			setTimeout("ContractIt()",speed);
		}else{
			ExpandObject.style.display='none';
			EXP_in_progress=false;
		}
	}
	
	function OpenObjectW(object, width, TheSpeed, TheStep){
		if(!EXP_in_progress){
			stepsize=TheStep;
			EXP_in_progress=true; //lets everyone know that a function is running
			ExpandObject=$(object);
			MaxWidth=width;
			speed=TheSpeed;
			if(ExpandObject.style.width.replace('px','')){
				eval('CurrentWidth='+ExpandObject.style.width.replace('px','')+';') //sets the numeric variable current height to the value of the div width
			}else{
				CurrentWidth=0;
			}
			if(CurrentWidth>=MaxWidth){
				CurrentWidth=MaxWidth;
				ContractItW();
			}else{
				CurrentHeight=0;
				ExpandObject.style.display='block'; 
				ExpandItW(); }
		}
	}
	function ExpandItW(){
		if(CurrentWidth<=MaxWidth){
			CurrentWidth=CurrentWidth+stepsize;
			ExpandObject.style.width=CurrentWidth+'px';
			setTimeout("ExpandItW()",speed);
		}else{
			EXP_in_progress=false;
		}
	}
	function ContractItW(){
		if(CurrentWidth>0){
			CurrentWidth=CurrentWidth-stepsize;
			ExpandObject.style.width=CurrentWidth+'px';
			setTimeout("ContractItW()",speed);
		}else{
			ExpandObject.style.display='none'
			EXP_in_progress=false;
		}
	}
/************************************************************************
POPUP HELP DIV brings up a HELP article
Be sure to include the following items in a page that calls this function
<div style="display:none; position:absolute; z-index:15000;" id="HelpPopup"></div> after body
drag.js
rsm.css
/************************************************************************/
function GetHelp(sPopoverThis, help_article){ //brings up an article.
	GetPopup(sPopoverThis, "HelpPopup", "AJAX/GetHelp.asp", "article="+help_article, -100, 50);
	}
function QuickHelp(sPopoverThis, help_article, quickWidth, quickHeight){ //brings up an article.
	GetPopup(sPopoverThis, "HelpPopup", "AJAX/GetHelp.asp", "quickhelp=true&article="+help_article+"&quickWidth="+quickWidth+"&quickHeight="+quickHeight, 0, 50);
	//UnknownIngredient(345);//test
	}
function ChangeArea(){ //brings up the set search area div.
	GetPopup($('Currently_Searching'), "HelpPopup", "AJAX/SetSearchArea_Ajax.asp", 'change=true', 25,-100);
	}

