var now = new Date();

function Obj(sID) 
{
	return document.getElementById(sID);
}

String.prototype.trim = function() 
{ 
	return this.replace(/^\s+|\s+$/g, ''); 
}

String.prototype.toInitialCap = function()
{
	return this.substring(0, 1).toUpperCase() + this.substring(1, this.length).toLowerCase();
}

function Write(sID, sValue)
{
	Obj(sID).innerHTML = sValue;
}

function Go(sURL)
{
	this.location.href = sURL;
}

function Hide(sID) 
{
	Obj(sID).style.display = "none";
}

function Show(sID, sType) 
{
	Obj(sID).style.display = sType;
}

function MoveTop(sID, iValue)
{
	Obj(sID).style.top = iValue + "px";
}

function MoveBottom(sID, iValue) 
{
	Obj(sID).style.bottom = iValue + "px";
}

function Resize(sID, iWidth, iHeight)
{
	if ( iWidth > 0 )
	{
		Obj(sID).style.width = iWidth + "px";
	}
	
	if ( iHeight > 0 )
	{
		Obj(sID).style.height = iHeight + "px";
	}
}

function ChangeZIndex(sID, z)
{
	Obj(sID).style.zIndex = z;
}

function ChangeImage(sID, sSrc)
{
	document.images[sID].src = sSrc;
}

function ChangeClass(sID, sClass)
{	
	Obj(sID).setAttribute("class", sClass);
	Obj(sID).setAttribute("className", sClass); // IE 6.0
}

function ChangeAttribute(sID, sAttribute, sValue)
{
	Obj(sID).setAttribute(sAttribute, sValue);
}

function OpenPopup(sURL, iWidth, iHeight)
{
	var popup = window.open(sURL, null,"location=0, status=0, scrollbars=1, resizable=1, width=" + iWidth + ", height=" + iHeight);
	popup.focus();	
}

function GetRandomNumber(iLower, iUpper)
{
	return Math.floor((Math.random() * iUpper) + iLower);
}

function GetWindowHeight()
{
	var i = 0;
	if ( typeof( window.innerHeight ) == "number" ) 
	{
		i = window.innerHeight;
	} 
	else if ( document.documentElement && document.documentElement.clientHeight ) 
	{
		i = document.documentElement.clientHeight;
	} 
	else if ( document.body && document.body.clientHeight  ) 
	{
		i = document.body.clientHeight;
	}
	return i;
}

function GetWindowWidth()
{
	var i = 0;
	if ( typeof( window.innerWidth ) == "number" ) 
	{
		i = window.innerWidth;
	} 
	else if ( document.documentElement && document.documentElement.clientWidth ) 
	{
		i = document.documentElement.clientWidth;
	} 
	else if ( document.body && document.body.clientWidth ) 
	{
		i = document.body.clientWidth;
	}
	return i;
}

function GetObjectHeight(sID)
{
	return Obj(sID).offsetHeight;
}

function GetObjectWidth(sID)
{
	return Obj(sID).offsetWidth;
}

function CreateCookie(sName, sValue, iDays) 
{
	if (iDays) 
	{
		now.setTime(now.getTime() + (iDays * 24 * 60 * 60 * 1000));
		var expires = "; expires=" + now.toGMTString();
	}
	else var expires = "";
	document.cookie = sName + "=" + sValue + "" + expires + "; path=/";
}

function ReadCookie(name) 
{
	var nameEQ = name + "=";
	var namevaluepairs = document.cookie.split(';');
	for(var i = 0; i < namevaluepairs.length; i++) 
	{
		var value = namevaluepairs[i];
		while (value.charAt(0)==' ') 
		{
			value = value.substring(1, value.length);
		}
		if (value.indexOf(nameEQ) == 0) 
		{
			return value.substring(nameEQ.length, value.length);
		}
	}
	return null;
}

function DeleteCookie(name) 
{
	CreateCookie(name, "", -1);
}

function Querystring()
{
	// get the query string, ignore the ? at the front.
	var queryString = location.search.substring(1, location.search.length);

	// parse out name/value pairs separated via &
	var args = queryString.split('&');

	// split out each name = value pair
	for (var i = 0; i < args.length; i++)
	{
		var pair = args[i].split('=');

		// Fix broken unescaping
		temp = unescape(pair[0]).split('+');
		temp0 = temp.join(' ');
		
		temp = unescape(pair[1]).split('+');
		temp1 = temp.join(' ');
		
		this[temp0]=temp1;
	}

	this.get=GetQuerystring;
}

function GetQuerystring(sKey, sDefault)
{
	var value = this[sKey];
	if (value==null)
	{
		value = sDefault;
	}
	return value;
}
