/*	tell server that javascript is enabled. */
document.cookie = 'javascript=Y';



/*
	Get browser
*/

var browser_ie = (navigator.userAgent.indexOf('MSIE') >= 0);
var browser_opera = (navigator.userAgent.indexOf('Opera') >= 0);













/*
	Debug
*/

function debug(strInMessage)
{	
	objMessage = document.createElement('div');
	objMessage.setAttribute('style','padding:10px 5px;');
	objMessage.innerHTML = strInMessage;
	
	objDebug = document.getElementById('divDebug');
	if (objDebug) objDebug.appendChild(objMessage);
}















/*
	Get page parameters from query string.
*/

var rayPageParameters = null;
function getPageParameters()
{	
	rayOutParameters = new Array();
	strQueryString = location.search.replace(/\?/,'&');
	rayQueryString = strQueryString.split('&');
	for (i=1; i < rayQueryString.length; i++)
	{	strParameter = rayQueryString[i];
		rayParameter = strParameter.split('=');
		rayOutParameters[rayParameter[0]] = rayParameter[1];
	}
	return rayOutParameters;
}
function getPageParameter(strInParam)
{	
	if (!rayPageParameters) rayPageParameters = getPageParameters();
	return rayPageParameters[strInParam];
}









/*
	Cookies
*/

function writeCookie(cname, cvalue, cexpire)
{
	document.cookie = cname + '=' + escape(cvalue) +
	(typeof cexpire == 'date' ? 'expires=' + cexpire.toGMTString() : '') +
		',path=/;domain=about.com';
}


































































/*
	DOM object handling
*/

var httpObj = false;

function getHttpObj()
{	
	if (!httpObj) httpObj = getHTTPObject();
	return httpObj;
}
function getHTTPObject()
{	
	if (window.XMLHttpRequest)
	{	// first choice.
		return new XMLHttpRequest();
	}
	else
	if (window.ActiveXObject)
	{	// LAST choice.
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return false;
}



function removeNodeChildren(objInNode)
{	
	if (objInNode && objInNode.childNodes)
	{	
		for (n=0; n < objInNode.childNodes.length; n++)
		{	
			objInNode.removeChild( objInNode.childNodes[n] );
		}
	}
}



function getObjPosition(objInput)
{
	intOutLeft = 0;
	intOutTop = 0;
	intOutRight = objInput.offsetRight ? objInput.offsetRight : null;
	intOutBottom = objInput.offsetBottom ? objInput.offsetBottom : null;
	intOutWidth = objInput.offsetWidth ? objInput.offsetWidth : null;
	intOutHeight = objInput.offsetHeight ? objInput.offsetHeight : null;
	if (objInput.offsetParent)
	{	while (objInput.offsetParent)
		{	intOutLeft += objInput.offsetLeft;
			intOutTop += objInput.offsetTop;
			objInput = objInput.offsetParent;
		}
	}
	else
	if (objInput.x || objInput.y)
	{	intOutLeft += objInput.x;
		intOutTop += objInput.y;
		intOutWidth = objInput.width ? objInput.width : null;
		intOutHeight = objInput.height ? objInput.height : null;
	}
	if ((intOutRight == null) && intOutWidth) intOutRight = intOutLeft+intOutWidth;
	if ((intOutBottom == null) && intOutHeight) intOutBottom = intOutTop+intOutHeight;
	rayOutput = new Array();
	rayOutput['left'] = intOutLeft;
	rayOutput['right'] = intOutRight;
	rayOutput['top'] = intOutTop;
	rayOutput['bottom'] = intOutBottom;
	rayOutput['width'] = intOutWidth;
	rayOutput['height'] = intOutHeight;
	return rayOutput;
}



function addToClassName(objInput, strInClassName)
{	
	rayCurrentClassName = new Array();
	if (strCurrentClassName = objInput.className)
		rayCurrentClassName = strCurrentClassName.split(' ');
	rayCurrentClassName.push(strInClassName);
	
	return (objInput.className = rayCurrentClassName.join(' '));
}

function removeFromClassName(objInput, strInClassName)
{	
	rayCurrentClassName = new Array();
	if (strCurrentClassName = objInput.className)
		rayCurrentClassName = strCurrentClassName.split(' ');
	rayOutClassName = new Array();
	for (i in rayCurrentClassName)
		if (rayCurrentClassName[i] != strInClassName)
			rayOutClassName.push(rayCurrentClassName[i]);
	
	return (objInput.className = rayOutClassName.join(' '));
}













/*
	Sorting
*/

function sortNumber(a,b)
{
	return a - b;
}































































/*
	
	Formatting functions...
	
*/

function padDecimal(dblNumber, intDigits)
{	
	strInput = new String(dblNumber);
	rayInput = strInput.split(".");
	strLeft = rayInput[0];
	strRight = rayInput[1];
	while (strRight.length < intDigits) strRight += "0";
	
	return strLeft+"."+strRight;
}

function padNumber(intNumber, intDigits)
{	strOutput = new String(intNumber);
	intL = intDigits - strOutput.length;
	for (i=0; i< intL; i++)
	{	strOutput = "0"+strOutput; }
	return strOutput;
}

function formatCurrency(intInAmount)
{
	strDecimal = '.';
	strDelim = ',';
	strOutAmount = "";
	
	intInAmount = new Number(intInAmount);
	if (isNaN(intInAmount)) return false;
	
	booNegative = (intInAmount < 0);
	strInAmount = Math.abs(intInAmount).toFixed(2);
	rayInAmount = strInAmount.split('.');
	strLeftAmount = rayInAmount[0];
	
	rayLeftAmount = new Array();
	while(strLeftAmount.length > 3)
	{	
		strThisNumber = strLeftAmount.substr(strLeftAmount.length-3);
		
		rayLeftAmount.unshift(strThisNumber);
		strLeftAmount = strLeftAmount.substr(0,strLeftAmount.length-3);
	}
	if (strLeftAmount.length > 0) rayLeftAmount.unshift(strLeftAmount);
	
	strOutAmount = (booNegative?'-':'')+
		rayLeftAmount.join(strDelim)+strDecimal+rayInAmount[1];
	
	return strOutAmount;
}

































































/*
	
	Parsing functions...
	
*/

/*
	Parse standard data string. "key1:value1;key2:value2"
	return as keyed array [key1]="value1", [key2]="value2"
*/
function DataStrToRay(strInput)
{
	rayOutput = new Array();
	rayInput = strInput.split(';');
	for (dstri=0; dstri< rayInput.length; dstri++)
	{
		rayThisPair = rayInput[dstri].split(':');
		rayOutput[rayThisPair[0]] = rayThisPair[1];
	}
	return rayOutput;
}
function DataRayToStr(rayInput)
{
	strOutput = '';
	for (drtsi in rayInput)
	{
		if (typeof(rayInput[drtsi]) != 'function')
		{
			if (strOutput) strOutput += ';';
			strOutput += drtsi+':'+rayInput[drtsi];
		}
	}
	return strOutput;
}

function summarize(rayInput)
{	
	strOutput = '';
	for (smrzi in rayInput)
	{
		if (typeof(rayInput[smrzi]) != 'function')
		{
			if (strOutput) strOutput += ', ';
			strOutput += smrzi+':'+rayInput[smrzi];
		}
	}
	return strOutput;
}

































































/*
	
	Common validation functions
	
*/



function validateZip(inZipCode) 
{	/*
		test passed zipcode for format validity.
	*/
	regZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
	return regZip.test(inZipCode);
}


