var mcSCDemo;

//MasterCard SecureCode Window Popup
function launchDemo (theURL){
	if (mcSCDemo==null){
		mcSCDemo = window.open(theURL, 'mcSCDemo', getSizeCentered(780,440,100,100,true) + ',titlebar=yes');
	}
	else if (mcSCDemo.closed){
		mcSCDemo = window.open(theURL, 'mcSCDemo', getSizeCentered(780,440,100,100,true) + ',titlebar=yes');
	}
	else {
		mcSCDemo.location.href = theURL;
	}
	mcSCDemo.focus();
}

// Sizes and Centers Popup
// Returns width, height, left, top, screenX, and screenY parameters in popup-friendly string
// Will use larger width and height of either actual or percentage, but never exceeds actual
function getSizeCentered(popupWidth, popupHeight, percentWidth, percentHeight, percentage){
	var tempWidth;
	var tempHeight;
	if (percentage){
		tempWidth = parseInt(screen.availWidth * percentWidth / 100);
		tempHeight = parseInt(screen.availHeight * percentHeight / 100);
		if (tempWidth < popupWidth){
			popupWidth = tempWidth;
		} 
		if (tempHeight < popupHeight){
			popupHeight = tempHeight;
		} 
	}
	var winWidth = 'width=' + popupWidth;
	var winHeight = 'height=' + popupHeight;
	var indentNetscapeWidth = 'screenX=' + getIndent(popupWidth, false);
	var indentNetscapeHeight = 'screenY=' + getIndent(popupHeight, true);
	var indentMSIEWidth = 'left=' + getIndent(popupWidth, false);
	var indentMSIEHeight = 'top=' + getIndent(popupHeight, true);
	var dimensions = winWidth + ',' + winHeight + ',' + indentNetscapeWidth + ',' + indentNetscapeHeight + ',' + indentMSIEWidth + ',' + indentMSIEHeight;
//	alert(dimensions + ' ' + screen.availWidth + ' ' + screen.availHeight);
	return dimensions;
}

// Calculates indented pixel width to get a centered window
function getIndent (popupDimension, isHeight){
	if (isHeight){
		return ((screen.availHeight - popupDimension) / 2);
	} else {
		return ((screen.availWidth - popupDimension) / 2);
	}
}

function autofitIfram(id){
   var obj = parent.document.getElementById(id);
   if (obj != null) {
    parent.document.getElementById(id).style.height="0px";
    parent.document.getElementById(id).style.height=this.document.body.scrollHeight+"px";
   }
}
