/*********************************************************
* JS Constants shared across the site
*********************************************************/


/********************************************
* Takes a JSON string and returns an 
* object.  
*
*********************************************/
function JSONtoObj(jsonStr)
{
	//alert(jsonStr);
	// for now just use 'eval' 
	// convert the json string to an object
	var jsonObj = eval('(' + jsonStr + ')');
	
	return jsonObj;
	
}


/********************************************
*  Calculates the x,y coordinates to be used
*  to center an element based on the width and height
*  in pixels.
*
*  Returns an array with the following elements:
*
*		0 = x coordinate of center of screen
*		1 = y coordinate of center of screen
*
**********************************************/

function getCenterOfScreen()
{
	// find the center of the screen using the javascript window fields
	//var centeredLayoutCoords = getCenteredLayoutLocation(displayDivWidth,displayDivHeight);
	var screenAvailWidth = screen.availWidth;
	var screenAvailHeight = screen.availHeight;
	//alert("avail width x height:  " + screenAvailWidth + " x " + screenAvailHeight);
	
	// find the center of the screen
	var centerX = Math.abs(screenAvailWidth/2);
	var centerY = Math.abs(screenAvailHeight/2);
	//alert("center x,y:  " + centerX + ", " + centerY);

	var centerPoint = new Array();
	centerPoint[0] = centerX;
	centerPoint[1] = centerY;
	
	// return the array
	return centerPoint;
}

/********************************************
*  Calculates the x,y coordinates to be used
*  to center an element based on the width and height
*  in pixels.
*
*  Returns an array with the following elements:
*
*		0 = x coordinate of center of screen
*		1 = y coordinate of center of screen
*		2 = x coordinate of element to be centered
*		3 = y coordinate of element to be centered
*
**********************************************/
function getCenteredLayoutPoint(elementWidth, elementHeight)
{
	
	// get the center of the screen
	var centeredLayoutLocation = getCenterOfScreen();
	
	var centerX = centeredLayoutLocation[0];
	var centerY = centeredLayoutLocation[1];
	//alert("center x,y: " + centerX + ", " + centerY);

	// calculate the middle of the width and height, subtract them from center and 
	// add the result to the array
	// strip units
	var elementWidthNum = elementWidth.replace(/px/gi, "");
	var elementHeightNum = elementHeight.replace(/px/gi, "");
	
	//alert("element size width, height: " + elementWidthNum + ", " + elementHeightNum);
	
	var layoutX = centerX - Math.round( Math.abs(elementWidthNum/2));
	var layoutY = centerY - Math.round( Math.abs(elementHeightNum/2));
	//alert("layout x,y:  " + layoutX + ", " + layoutY);
	
	centeredLayoutLocation[2] = layoutX;
	centeredLayoutLocation[3] = layoutY;
			
	// return the array
	return centeredLayoutLocation;
		
}

/**********************************************************
* Gets the scroll amount of the scroll bars
*
*  Returns an array with the following elements:
*
*		0 = offset of x axis scroll bars
*		1 = offset of y axis scroll bars
************************************************************/
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 ];
  	
}
/*****************************************
* formats a time from 24 hr to 12 hour with AM/PM
*******************************************/
function formatTime24To12(time24Str)
{
	// for now just spit out the unformated string
	return time24Str;
	
}


/**************************************************************
*  Helper to pop a download window and make it show the brochure or form
**************************************************************/
function popDownloadWindow(targetUrl)
{
	var newWin = window.open(targetUrl);
	// newWin.location = targetUrl;
	
}


/**********************************************************
* Pops a new browser window and targets the provide URL
***********************************************************/
function linkToExternalSite(targetUrl)
{
	var newWin = window.open(targetUrl);
	//newWin.location = targetUrl;
	
	
}

/**********************************************************8
* toggles a div to expand/contract with an icon change
***********************************************************/

/*************************************
* functions for toggling the section hide/show with an Image
*
* ORIGINAL:
//	var divToToggle = dojo.byId(blockId);
//	var imgToUpdate = dojo.byId(blockImgId);
//	
//	
//	if (divToToggle.style.display == "")
//	{
//		divToToggle.style.display = "none";
//		imgToUpdate.src = BLOCK_STATUS_COLLAPSED_IMG;
//	}
//	else
//	{
//		divToToggle.style.display = "";
//		imgToUpdate.src = BLOCK_STATUS_EXPANDED_IMG;
//	}
***************************************/
function toggleExpandCollapseBlock(blockId,blockImgId)
{
	
	var curDisplay = jQuery("#" + blockId).css("display");
	
	if (curDisplay !="none")
	{
		// hiding
		jQuery("#" + blockId).hide();
		jQuery("#" + blockImgId).attr("src",BLOCK_STATUS_COLLAPSED_IMG);
	} else
	{
		// showing
		jQuery("#" + blockId).slideDown('fast');
		jQuery("#" + blockImgId).attr("src",BLOCK_STATUS_EXPANDED_IMG);
	}
}
