var bUseV2CSS 
// useV2CSS() is defined in common.js, which isn't included everywhere iframe.js is.
try { bUseV2CSS = useV2CSS() }
catch (ex) { bUseV2CSS = false }

function ResizeIFrame(oFrame) {
	var innerBody;
	var height;

	// sometimes, the window name is passed, not the frame object
	if (typeof(oFrame) == 'string') {
		oFrame = window.parent.document.getElementsByName(oFrame)[0];
	}
	//alert(typeof oFrame);

	try
	{
		if (oFrame) {
			if (oFrame.contentDocument || oFrame.Document) {
				try {
					innerBody = (oFrame.contentDocument) ? oFrame.contentDocument.body : oFrame.Document.body; //oFrame.contentWindow.document;
				}
				catch (err) {
					//window.status = "There was an error in (iframe.js;ResizeIFrame()): " + err.description;
				}
				if (innerBody) {
					// Sometimes the offsetHeight has what we want, sometimes the scrollHeight. 
					//	Just taking the largest value seems to do the trick!
					//var height = (innerBody.offsetHeight > innerBody.scrollHeight) ? innerBody.offsetHeight : innerBody.scrollHeight;
					height = innerBody.offsetHeight;
					//var width = (innerBody.offsetWidth > innerBody.scrollWidth) ? innerBody.offsetWidth : innerBody.scrollWidth;
					//oFrame.width = width;  //+ 10;
				} else { // can't access the iframe contents to determine the height
					height = 1500;
				}
			} else { //what to do if the oFrame is eCommerce, which is in a different domain? (and therefore no cross-domail javascript?)
				height = 1500;
			}
			oFrame.height = height; 
			oFrame.style.height = height.toString() + 'px';
		}
		

		//if (bUseV2CSS) return;
		////alert(oFrame.height + ' ' + oFrame.id);
		//parent.setTallFrames(parseInt(oFrame.height) + 10, oFrame.id);
		//var Height2 = oFrame.height;
	}
	catch(err)
	{
		//window.status = "There was an error in (iframe.js;ResizeIFrame()): " + err.description;
	}
	parent.setTall();
}

function UpdateIFrameSize(sFrameName) {	
	var oFrame;

	try {
		oFrame = window.parent.document.getElementById(window.parent.frames[sFrameName].thisFrameID);
		//oFrame = window.parent.document.getElementsByName(sFrameName)[0];
	}
	catch (e){/* If the frame content is from another My-PTA site, access is denied. */}
	if (oFrame) {
		window.parent.ResizeIFrame(oFrame);
	}
}

function ParentURL(sURL) {
	window.parent.location.href = sURL;
}

var thisFrameID;

function saveFrameID() {
	// Function to retrieve the frame id if applicable
	if (window.frameElement) {
		thisFrameID = window.frameElement.id;
	} else {
		thisFrameID = "LeftNav";  //"Content";
	}
}

function getPageArea() {
	if (thisFrameID) {
		if (thisFrameID.indexOf('LeftNav') == 0)
			return 'Left';
		if (thisFrameID.indexOf('Content') == 0)
			return 'Middle';
		if (thisFrameID.indexOf('RightNav') == 0)
			return 'Right';
	} else
	{ return 'Unknown'; }
}

function pageArea(sArea) {
	var sColumn
	if (thisFrameID) {
		sColumn = thisFrameID;
		if (thisFrameID.indexOf('LeftNav') == 0)
			sColumn = 'Left';
		if (thisFrameID.indexOf('Content') == 0)
			sColumn = 'Middle';
		if (thisFrameID.indexOf('RightNav') == 0)
			sColumn = 'Right';
	} else
	{ sColumn = 'Unknown'; }
	
	if (sArea) {
		return sColumn.indexOf(sArea) > -1
	} else {
		return sColumn;
	}
}

try {
	$(function() {
		UpdateIFrameSize(window.name);
		saveFrameID();
	});
} catch (ex) {
	//alert("uh-oh");
}

