// JavaScript Document
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

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 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;
	var printstring = '';
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			printstring += ' element ' + obj.tagName + ' has ' + obj.offsetTop;
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	window.status = printstring;
	return curtop;
}

function GetLeft(elem)
{
	xPos = elem.offsetLeft;
	tempEl = elem.offsetParent;
  	while (tempEl != null) {
  		xPos += tempEl.offsetLeft;
	  	tempEl = tempEl.offsetParent;
  	}
	return xPos;
}

function GetRight(elem)
{
	xPos = elem.offsetLeft;
	tempEl = elem.offsetParent;
  	while (tempEl != null) {
  		xPos += tempEl.offsetLeft;
	  	tempEl = tempEl.offsetParent;
  	}
	return xPos+elem.offsetWidth;
}


function GetTop(elem)
{
	yPos = elem.offsetTop;
	tempEl = elem.offsetParent;
	while (tempEl != null) {
  		yPos += tempEl.offsetTop;
	  	tempEl = tempEl.offsetParent;
  	}
	return yPos;
}
	
	
	
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 MakePopover(sPopoverId, sPopoverThis, page, string, followup, Xoff, Yoff ){	
	/*
	sPopoverId, The id of the element that will containt he popover information
	sPopoverThis, The element that the popover will appear above
	page, the AJAX page to get the popover information
	string, the url string to send to the ajax page
	followup, the followup function (optional)
	Xoff, X offset
	Yoff, Y offset
	*/
			var newX = findPosX(sPopoverThis)-Xoff;
			var newY = findPosY(sPopoverThis)-Yoff;
			
		ThePopup=document.getElementById(sPopoverId);
		ThePopup.style.left=newX+'px';
		ThePopup.style.top=newY+'px';
		ThePopup.style.display='block';
		ThePopup.innerHTML='<div style=\'background-color:#eeeeee; padding:10px;\'>Loading</div>';
	
	GetAjax("page", string, sPopoverId, followup);
}
	
function GetPopup(sPopoverThis, sPopoverID, sPage, sString, iHeightOffset, iHorizOffset){

	//sPopoverId="HelpPopup";
	var newX,newY
	if (sPopoverThis != null)
	{
		newX = findPosX(sPopoverThis)+iHorizOffset;
		newY = findPosY(sPopoverThis)+iHeightOffset;
	}
	else
	{
		newX = 400;
		newY = 300;
	}
		//alert(newX+' - '+newY)//test
	ThePopup=document.getElementById(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;

	GetAjax(sPage, sString, sPopoverID, "");
}
	
	
////  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){
		document.getElementById(sTheObject).value=name;
		document.getElementById(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=document.getElementById(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=document.getElementById(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(document.getElementById('Currently_Searching'), "HelpPopup", "AJAX/SetSearchArea_Ajax.asp", 'change=true', 25,-100);
	}

		

