// *** 
// WalySoft Sistemas - www.walysoft.com.ar
// *** 

var nIdStatus = null;
var nTop = 5;
var nLeft = 0;
var bHintOn = false;
var nHintWidth = 50;
var nXOffSet = 0;
var nYOffSet = 0;
var cDiv = 'helpwin';
var hwSkn = MWJ_findObj( cDiv );

var bWH_NS = (document.layers)? true:false;
var bWH_IE = (document.all)? true:false;

MWJ_changeZIndex( cDiv, 5 );
	
MWJ_monitorMouse( 
	function () {
		if( bHintOn )
			MWJ_changePosition( cDiv, 
								MWJ_getMouse[0] + nXOffSet, 
								MWJ_getMouse[1] + nYOffSet,
								true
			);
	}
);

function ScrollR()
{ 
	nLeft = nLeft + 20;
	MWJ_changePosition( cDiv, nLeft, nTop, true );
	if( nLeft < 5 ) 
   		nIdStatus = window.setTimeout( 'ScrollR()', 50 );
}

function ScrollL()
{ 
	nLeft = nLeft - 20;
	MWJ_changePosition( cDiv, nLeft, nTop, true );
	if( nLeft > -120 ) 
   		nIdStatus = window.setTimeout( 'ScrollL()', 50 )
   	else
  		MWJ_changeVisibility( cDiv, false );
}

function hintOn(msg,nWidth)
{
  MWJ_changeVisibility( cDiv, false );
  if( nIdStatus != null ) window.clearTimeout( nIdStatus );  

  cEffect = "z-index: 5; progid:DXImageTransform.Microsoft.Fade(duration=0.6)";

  if( nWidth != null ) 
  	nXOffSet = nWidth / 2 * (-1); // ( nWidth * (-1) ) + 15;
  else
	nXOffSet = nHintWidth / 2 * (-1);

  if( document.body.scrollLeft &&  ( nXOffSet < ( document.body.scrollLeft + 5 ) ) ) 
	nXOffSet = 5;

  nYOffSet = 18;
  
  var content = "<table class='wsTableHint'";
  
  if( nWidth != null ) 
  	content += " style='width:"+ nWidth +"px'";  
  
  content += " style=' filter: progid:DXImageTransform.Microsoft.DropShadow(OffX=5, OffY=5, color=gray, Positive=true) Alpha(style=0,opacity=88)'";
  content += "><tr><td align='center'>";
  content += "&nbsp;"+msg+"&nbsp;"
  content += "</td></tr></table>"	

  if( hwSkn.style.filter ) {
  	hwSkn.style.filter = cEffect;
  	hwSkn.filters[0].Apply();
  }

  if ( bWH_IE ) 
	hwSkn.innerHTML = content
  else
  if ( bWH_NS ) 
  { 
	hwSkn.document.write(content); 
	hwSkn.document.close();
  }
  else
	hwSkn.innerHTML = content;
  
  MWJ_changeVisibility( cDiv, true );
  if( hwSkn.style.filter ) hwSkn.filters[0].Play();
  
  bHintOn = true;
}

function pop(msg) {
	popext( msg, null, null );
}

function popext(msg, cTitle, cWidth )
{

// progid:DXImageTransform.Microsoft.

// RandomDissolve(duration=0.6)
// RandomBars(duration=0.6,orientation=horizontal)
// Fade(duration=0.6)
// Pixelate(duration=0.6,maxSquare=10)
// GradientWipe(duration=0.6,motion=reverse)

// Shadow(color=gray,direction=135,strenght=3)
// Glow(Color=red,Strength=8)
// Alpha(style=0,opacity=90)
// Shadow(color=gray,direction=135,strenght=3)
// DropShadow(OffX=5, OffY=5, Color='gray', Positive='true')

MWJ_changeVisibility( cDiv, false );
if( nIdStatus != null ) window.clearTimeout( nIdStatus );  

if( document.body.scrollTop ) 
	nTop = document.body.scrollTop + 5
else
	nTop = 5;

nLeft = -115;
MWJ_changePosition( cDiv, nLeft, nTop, true );

if( cTitle == null ) cTitle = 'Ayuda';

cEffect = "z-index: 5; progid:DXImageTransform.Microsoft.Fade(duration=0.6)";

var content = "<table class='wsTableWinHelp'";
cStyle = "";
if( cWidth !== null ) 
	cStyle += "width:" + cWidth + " !important;";
if( bIE )
	cStyle += "filter: progid:DXImageTransform.Microsoft.DropShadow(OffX=5, OffY=5, color=gray, Positive=true) Alpha(style=0,opacity=88)";
if( cStyle !== '' )
	content += ' style="' + cStyle + '"';
content += "><tr><th>" + cTitle + "</th></tr>"
content += "<tr><td>"+msg+"</td></tr></table>";

  if( hwSkn.style.filter ) {
	hwSkn.style.filter = cEffect;
  	hwSkn.filters[0].Apply();
  }

  if ( bWH_IE ) 
	document.all(cDiv).innerHTML = content
  else
  if ( bWH_NS ) 
  { 
	hwSkn.document.write(content); 
	hwSkn.document.close();
  }
  else
	hwSkn.innerHTML = content;

  MWJ_changeVisibility( cDiv, true );
  if( hwSkn.style.filter ) hwSkn.filters[0].Play();

  if( nIdStatus != null ) window.clearTimeout( nIdStatus );  

  ScrollR();
}

function freeWin( cTitle, cHTML, nX, nY, bIsHintOn )
{
  MWJ_changeVisibility( cDiv, false );
  if( nIdStatus != null ) window.clearTimeout( nIdStatus );  
  
  cEffect = "z-index: 5; progid:DXImageTransform.Microsoft.Fade(duration=0.6)";
  
  if( hwSkn.style.filter ) {
  	hwSkn.style.filter = cEffect;
  	hwSkn.filters[0].Apply();
  }

var content = "<table class='wsTableWinHelp'";
content += " style=' filter: progid:DXImageTransform.Microsoft.DropShadow(OffX=5, OffY=5, color=gray, Positive=true)'>";
content += "<tr><th>"+cTitle+"</th></tr>"
content += "<tr><td>"+cHTML+"</td></tr></table>";

  if ( bWH_IE ) 
	hwSkn.innerHTML = content
  else
  if ( bWH_NS ) 
  { 
	hwSkn.document.write(content); 
	hwSkn.document.close();
  }
  else
	hwSkn.innerHTML = content;

  var nLeft = MWJ_getMouse[0] + nX; 
  var nTop = MWJ_getMouse[1] + nY;

  if( document.body.scrollTop ) 
	nYOffSet = document.body.scrollTop + 5
  else
	nYOffSet = 5;

  if( document.body.scrollLeft ) 
	nXOffSet = document.body.scrollLeft + 5
  else
	nXOffSet = 5;
  
  if( nTop < ( nYOffSet + 5 ) )
	nYOffSet =  nY + nYOffSet + 5 - nTop
  else
  	nYOffSet = nY;

  if( nLeft < ( nXOffSet + 5 ) )
	nXOffSet =  nX + nXOffSet + 5 - nLeft
  else
  	nXOffSet = nX;
   
  MWJ_changeVisibility( cDiv, true );
  if( hwSkn.style.filter ) hwSkn.filters[0].Play();
  
  if( bIsHintOn == null ) bIsHintOn = true;
  
  if( ! bIsHintOn ) {
		if( document.body.scrollTop ) 
			nTop = document.body.scrollTop + 5
		else
			nTop = 5;

		nLeft = 5;
		MWJ_changePosition( cDiv, nLeft, nTop, true );
  }
  
  bHintOn = bIsHintOn;
  
}

function kill() 
{ 
  if( nIdStatus != null ) window.clearTimeout( nIdStatus );  
  ScrollL();
}

function hintOff() 
{
  bHintOn = false;
  if( nIdStatus != null ) window.clearTimeout( nIdStatus );  
  MWJ_changeVisibility( cDiv, false );
}

function MWJ_findObj( oName, oFrame, oDoc ) {
	if( !oDoc ) { if( oFrame ) { oDoc = oFrame.document; } else { oDoc = window.document; } }
	if( oDoc[oName] ) { return oDoc[oName]; } if( oDoc.all && oDoc.all[oName] ) { return oDoc.all[oName]; }
	if( oDoc.getElementById && oDoc.getElementById(oName) ) { return oDoc.getElementById(oName); }
	for( var x = 0; x < oDoc.forms.length; x++ ) { if( oDoc.forms[x][oName] ) { return oDoc.forms[x][oName]; } }
	for( var x = 0; x < oDoc.anchors.length; x++ ) { if( oDoc.anchors[x].name == oName ) { return oDoc.anchors[x]; } }
	for( var x = 0; document.layers && x < oDoc.layers.length; x++ ) {
		var theOb = MWJ_findObj( oName, null, oDoc.layers[x].document ); if( theOb ) { return theOb; } }
	if( !oFrame && window[oName] ) { return window[oName]; } if( oFrame && oFrame[oName] ) { return oFrame[oName]; }
	for( var x = 0; oFrame && oFrame.frames && x < oFrame.frames.length; x++ ) {
		var theOb = MWJ_findObj( oName, oFrame.frames[x], oFrame.frames[x].document ); if( theOb ) { return theOb; } }
	return null;
}

function MWJ_changeVisibility( oName, oVis, oFrame ) {
	var theDiv = MWJ_findObj( oName, oFrame ); if( !theDiv ) { return; }
	if( theDiv.style ) { theDiv.style.visibility = oVis ? 'visible' : 'hidden'; } else { theDiv.visibility = oVis ? 'show' : 'hide'; }
}

function MWJ_changeDisplay( oName, oDisp, oFrame ) {
	var theDiv = MWJ_findObj( oName, oFrame ); if( !theDiv ) { return; }
	if( theDiv.style ) { theDiv = theDiv.style; } if( typeof( oDisp ) == 'string' ) { oDisp = oDisp.toLowerCase(); }
	theDiv.display = ( oDisp == 'none' ) ? 'none' : ( oDisp == 'block' ) ? 'block' : '';
}

function MWJ_changePosition( oName, oXPos, oYPos, oRel, oFrame ) {
	var theDiv = MWJ_findObj( oName, oFrame ); if( !theDiv ) { return; }
	if( theDiv.style ) { theDiv = theDiv.style; }
	if( typeof( oXPos ) == 'number' ) { theDiv.left = oXPos + ( oRel ? 0 : parseInt( theDiv.left ) ); }
	if( typeof( oYPos ) == 'number' ) { theDiv.top = oYPos + ( oRel ? 0 : parseInt( theDiv.top ) ); }
}

function MWJ_monitorMouse(oFunc) {
	if( document.captureEvents && Event.MOUSEMOVE ) { document.captureEvents( Event.MOUSEMOVE ); }
	window.MWJ_getMouse = [0,0]; window.MWJstoreFunc = oFunc;
	document.onmousemove = function (e) { window.MWJ_getMouse = MWJ_getMouseCoords(e); if( window.MWJstoreFunc ) { window.MWJstoreFunc(); } };
}

function MWJ_getMouseCoords(e) {
	if( !e ) { e = window.event; } if( !e || ( typeof( e.pageX ) != 'number' && typeof( e.clientX ) != 'number' ) ) { return[0,0]; }
	if( typeof( e.pageX ) == 'number' ) { var xcoord = e.pageX; var ycoord = e.pageY; } else {
		var xcoord = e.clientX; var ycoord = e.clientY;
		if( !( ( window.navigator.userAgent.indexOf( 'Opera' ) + 1 ) || ( window.ScriptEngine && ScriptEngine().indexOf( 'InScript' ) + 1 ) || window.navigator.vendor == 'KDE' ) ) {
			if( document.documentElement && ( document.documentElement.scrollTop || document.documentElement.scrollLeft ) ) {
				xcoord += document.documentElement.scrollLeft; ycoord += document.documentElement.scrollTop;
			} else if( document.body && ( document.body.scrollTop || document.body.scrollLeft ) ) {
				xcoord += document.body.scrollLeft; ycoord += document.body.scrollTop;
			} } } return [xcoord,ycoord];
}

function MWJ_getScroll( oFrame ) {
	if( !oFrame ) { oFrame = window; } var scrOfX = 0, scrOfY = 0;
	if( typeof( oFrame.pageYOffset ) == 'number' ) { scrOfY = oFrame.pageYOffset; scrOfX = oFrame.pageXOffset; }
	else if( oFrame.document.documentElement && ( oFrame.document.documentElement.scrollLeft || oFrame.document.documentElement.scrollTop ) ) {
		scrOfY = oFrame.document.documentElement.scrollTop; scrOfX = oFrame.document.documentElement.scrollLeft; }
	else if( oFrame.document.body && ( oFrame.document.body.scrollLeft || oFrame.document.body.scrollTop ) ) {
		scrOfY = oFrame.document.body.scrollTop; scrOfX = oFrame.document.body.scrollLeft; }
	return [scrOfX,scrOfY];
}

function MWJ_changeZIndex( oName, ozInd, oFrame ) {
	var theDiv = MWJ_findObj( oName, oFrame ); if( !theDiv ) { return; }
	if( theDiv.style ) { theDiv = theDiv.style; } theDiv.zIndex = ozInd;
}

function MWJ_getSize( oFrame ) {
	if( !oFrame ) { oFrame = window; } var myWidth = 0, myHeight = 0;
	if( typeof( oFrame.innerWidth ) == 'number' ) { myWidth = oFrame.innerWidth; myHeight = oFrame.innerHeight; }
	else if( oFrame.document.documentElement && ( oFrame.document.documentElement.clientWidth || oFrame.document.documentElement.clientHeight ) ) {
		myWidth = oFrame.document.documentElement.clientWidth; myHeight = oFrame.document.documentElement.clientHeight; }
	else if( oFrame.document.body && ( oFrame.document.body.clientWidth || oFrame.document.body.clientHeight ) ) {
		myWidth = oFrame.document.body.clientWidth; myHeight = oFrame.document.body.clientHeight; }
	return [myWidth,myHeight];
}