/*
//	© 2008 InWise Internet Company do Brasil S.A. - Todos os direitos reservados
//	www.inwise.com.br
*/

// Carrega Rollovers
aPageRollovers[ aPageRollovers.length ] = "/sources/images/floatingFrame/closeButton-over.gif";
aPageRollovers[ aPageRollovers.length ] = "/sources/images/floatingFrame/closeButton-down.gif";
aPageRollovers[ aPageRollovers.length ] = "/sources/images/buttons/close-over.gif";
aPageRollovers[ aPageRollovers.length ] = "/sources/images/buttons/close-down.gif";

var aPageFrames = [ "DownloadSoftphoneFrame", "DownloadPenphoneFrame", "OrderSoftphoneFrame", "OrderPenphoneFrame", "OrderCustomizationFrame", "OrderPrivateLabelCustomizationFrame", "OrderSharedCustomizationFrame", "OrderCoBrandedCustomizationFrame" ];
window.onscroll = AdjustFramePositionOnScroll;

function ToggleShowFloatingFrame( sFrameName, hElement ) {

	if ( hElement == null ) {

		sFrameName = "Download" + sFrameName + "Frame";
		hElement = document.getElementById( sFrameName );

	} else
		sFrameName = hElement.id

	var sVisibility = "visible";
	if ( hElement != null ) {

		sVisibility = ( hElement.style.visibility == "visible" )? "hidden" : "visible";
		SetLayerVisibility( hElement.id, sVisibility );

		if ( sVisibility == "visible" )
			CentralizeLayer( document.body, hElement.id );

		var hIFrame = hElement.getElementsByTagName( "iFrame" );
		if (( hIFrame != null ) && ( hIFrame.length > 0 )) {

			for ( var i = 0; i < frames.length; i++ ) {

				if (( frames[i].frameElement == hIFrame[0] ) && ( frames[i].OnShowForm != null )) {

					frames[i].OnShowForm( sFrameName, sVisibility );
					break;

				}
			}
		}
	}

	AdjustFrameBackground( sVisibility );
	return true;

}

function AdjustFrameOnPageResize() {

	for ( var i = 0, hElement; i < aPageFrames.length; i++ ) {

		hElement = document.getElementById( aPageFrames[i] )
		if (( hElement != null ) && ( hElement.style.visibility == "visible" )) {

			CentralizeLayer( document.body, hElement.id );
			AdjustFrameBackground( "visible" );

		}
	}
	
	return true;

}

function AdjustFramePositionOnScroll() {

	if ( AdjustFramePositionOnScroll.LastScroll == null )
		AdjustFramePositionOnScroll.LastScroll = [ 0, 0 ];

	for ( var i = 0, hElement; i < aPageFrames.length; i++ ) {

		hElement = document.getElementById( aPageFrames[i] )
		if (( hElement != null ) && ( hElement.style.visibility == "visible" )) {

			if ( document.body.clientWidth > hElement.offsetWidth )
				hElement.style.left = parseInt( hElement.style.left ) + ( document.body.scrollLeft - AdjustFramePositionOnScroll.LastScroll[0] );

			if ( document.body.clientHeight > hElement.offsetHeight )
				hElement.style.top = parseInt( hElement.style.top ) + ( document.body.scrollTop - AdjustFramePositionOnScroll.LastScroll[1] );

		}
	}

	AdjustFramePositionOnScroll.LastScroll = [ document.body.scrollLeft, document.body.scrollTop ];
	return true;

}

function AdjustFrameBackground( sVisibility ) {

	var hDownloadFrameBackground = document.getElementById( "DownloadFrameBackground" );
	if ( hDownloadFrameBackground != null ) {

		SetLayerVisibility( hDownloadFrameBackground.id, sVisibility );

		if ( isIE()) {

			hDownloadFrameBackground.style.width = document.body.scrollWidth;
			hDownloadFrameBackground.style.height = document.body.scrollHeight;

		} else {

			hDownloadFrameBackground.style.width = document.body.parentNode.clientWidth;
			hDownloadFrameBackground.style.height = document.body.parentNode.clientHeight
		
		}
	}

	return true;

}

function isIE() {

	return navigator.appName == 'Microsoft Internet Explorer';

}
