// Utility functions

/*
function SetOpacity(object, alpha)
{
	//figure out what browser we're using
	var br=new Array(4);
	br=getBrowser();
	
	if (br[2] == "msie")
	{
		object.style.filter = "alpha(opacity=" + (alpha) + ")";
		//object.filters.alpha.opacity = alpha;
	}
	else if (br[2] == "gecko")
	{
		object.style.MozOpacity = alpha/100;
	}
	else
	{	
		object.style.opacity = alpha/100;
	}
	
}*/
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}


function createDiv(id, img)
{
	var divTag = document.createElement("div");
	divTag.id = id;
	divTag.className ="dynamicDiv";
	if (img != null)
		divTag.style.backgroundImage = "url(" + img + ")";
	document.body.appendChild(divTag);
	return divTag;
}

function killDiv(divObject)
{
	document.body.removeChild(divObject);	
}

function moveDiv(div, Left, Top, Width, Height)
{
	div.style.left = Left + "px";
	div.style.width = Width + "px";
	div.style.top = Top + "px";
	div.style.height = Height + "px";
}


function MultiDimensionalArray(iRows,iCols)
{
var i;
var j;
   var a = new Array(iRows);
   for (i=0; i < iRows; i++)
   {
       a[i] = new Array(iCols);
       for (j=0; j < iCols; j++)
       {
           a[i][j] = "";
       }
   }
   return(a);
} 


function findPosX(obj)
{
	var curleft = 0;

	if(obj.offsetParent)
		while(1) 
		{
		  curleft += obj.offsetLeft;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;

	
}

function findPosY(obj)
{
	var curtop = 0;
	if(obj.offsetParent)
		while(1)
		{
		  curtop += obj.offsetTop;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
}


function getViewportWidth ()
{
	/*
	 var viewportwidth;
	 
	 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	 
	 if (typeof window.innerWidth != 'undefined')
	 {
		  viewportwidth = window.innerWidth;
	 }
	 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	
	 else if (typeof document.documentElement != 'undefined'
		 && typeof document.documentElement.clientWidth !=
		 'undefined' && document.documentElement.clientWidth != 0)
	 {
		   viewportwidth = document.documentElement.clientWidth;
	 }
	 
	 // older versions of IE
	 
	 else
	 {
		   viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
	 }
	 
	 return viewportwidth;
	 */
	 return $(window).width();
}
	
function getViewportHeight ()
{
	/*
	 var viewportheight;
	 
	 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	 
	 if (typeof window.innerWidth != 'undefined')
	 {
		  viewportheight = window.innerHeight;
	 }
	 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	
	 else if (typeof document.documentElement != 'undefined'
		 && typeof document.documentElement.clientWidth !=
		 'undefined' && document.documentElement.clientWidth != 0)
	 {
		   viewportheight = document.documentElement.clientHeight;
	 }
	 
	 // older versions of IE
	 
	 else
	 {
		   viewportheight = document.getElementsByTagName('body')[0].clientHeight;
	 }
	 
	 return viewportheight;
	 */
	 return $(window).height();
}
	
function changeStyleOverflow(oName,newValue)
{
	var o = document.getElementById(oName);
	if (o) o.style.overflow = newValue;
}


function WrapNumber (number, wrapsize)
{
	var result = number % wrapsize ;
	if (result <0)
			result += wrapsize;
			
	return result;
}
	
/*
function getURLVar(urlVarName) 
{
	//divide the URL in half at the '?'
	var urlHalves = String(document.location).split('?');
	var urlVarValue = '';
	
	if(urlHalves[1])
	{
		//load all the name/value pairs into an array
		var urlVars = urlHalves[1].split('&');
		//loop over the list, and find the specified url variable
		for(i=0; i<=(urlVars.length); i++)
		{
			if(urlVars[i])
			{
				//load the name/value pair into an array
				var urlVarPair = urlVars[i].split('=');
				if (urlVarPair[0] && urlVarPair[0] == urlVarName) 
				{
					//I found a variable that matches, load it's value into the return variable
					urlVarValue = urlVarPair[1];
				}
			}
		}
	}
	return urlVarValue;   
}*/
function getURLPage() 
{
	//divide the URL in half at the '#'
	var urlHalves = String(document.location).split('#');
	if(urlHalves[1])
		return urlHalves[1];
	else
		return;

}
function getURLBase() 
{
	//divide the URL in half at the '#'
	var urlHalves = String(document.location).split('#');
	
	return urlHalves[0];
	

}

function trim(s)
{
	var l=0; var r=s.length -1;
	while(l < s.length && s[l] == ' ')
	{	l++; }
	while(r > l && s[r] == ' ')
	{	r-=1;	}
	return s.substring(l, r+1);
}


