/*******************************************
This code use functions from:
Generic DHTML do everything script
By Mark 'Tarquin' Wilton-Jones .
You can see  the full original and complete script file dhtmlapi.js.
The script was provided for free by http://www.howtocreate.co.uk/
*******************************************/

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;
var bInitialized = false;

var aDivs = [];
var aSkins = [];

var bWH_NS = (document.layers)? true:false;
var bWH_IE = (document.all)? true:false;

function myWinsInitialized() {
	if( ! bInitialized )  {
		hwSkn = MWJ_findObj( cDiv );
		if( typeof hwSkn !== 'undefined' ) {
			MWJ_changeZIndex( cDiv, 5 );
			
			MWJ_monitorMouse( 
				function () {
					if( bHintOn )
						MWJ_changePosition( cDiv, 
							MWJ_getMouse[0] + nXOffSet, 
							MWJ_getMouse[1] + nYOffSet,
							true
						);
				}
			);
			
			bInitialized = true;			
		}
	}

	return bInitialized;
}

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) {

	if( ! myWinsInitialized() ) return false;
	
	MWJ_changeVisibility( cDiv, false );
	if( nIdStatus != null ) window.clearTimeout( nIdStatus );  

	cEffect = "z-index:5";

	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=' ' ";
	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 ) {

	if( ! myWinsInitialized() ) return false;

	MWJ_changeVisibility( cDiv, false );
	if( nIdStatus != null ) window.clearTimeout( nIdStatus );  

	if (document.documentElement && document.documentElement.scrollTop)
		nTop = document.documentElement.scrollTop + 5;
	else if (document.body)
		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( 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 ) {
	if( ! myWinsInitialized() ) return false;
	
	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.documentElement && document.documentElement.scrollTop)
		nYOffSet = document.documentElement.scrollTop + 5;
	else if (document.body)
		nYOffSet = document.body.scrollTop + 5;
	else
		nYOffSet = 5;

	if (document.documentElement && document.documentElement.scrollLeft)
		nXOffSet = document.documentElement.scrollLeft + 5;
	else if (document.body)
		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( ! myWinsInitialized() ) return false;
	
	if( nIdStatus != null ) window.clearTimeout( nIdStatus );  
	ScrollL();
}

function hintOff() {
	if( ! myWinsInitialized() ) return false;
	
	bHintOn = false;
	if( nIdStatus != null ) window.clearTimeout( nIdStatus );  
	MWJ_changeVisibility( cDiv, false );
}

// Waly Windows Functions

function IsDiv( cId ) {
	nPos = -1;
	for( i=0; i<aDivs.length; i++ ) 
		if( aDivs[i] == cId ) {
			nPos = i;
			break;
		};
	return nPos;
}

function DoModalDiv( cId ) {
	nPos = IsDiv( cId );
	if(  nPos < 0 ) {
		nPos = aDivs.length;
		document.write( '<div id="' + cId + '" class="wsHelpWin"></div>' );
		aDivs[nPos] = cId;
		aSkins[nPos] = MWJ_findObj( aDivs[nPos] );
	}
}

function ShowModal( cId, cTitle, cClass, cHTML, nWidth, nX, nY ) {
	nPos = IsDiv(cId);
	if( nPos < 0 ) return;
	
	hwSknMW = aSkins[nPos];
	cModalWin = aDivs[nPos];

	C = "'";	
	cHTML = '<table class="'+cClass+'" style="width:'+nWidth+'"><tr><th style="text-align:left"><a href="javascript:CloseModal(' +C+ cId +C+ ')"><span title="Cerrar Ventana" style="background:black;color:white;border:1px solid red">X</span></a>&nbsp;'+cTitle+'</th><tr><td>' + cHTML + '</td></tr></table>';
	
	CloseModal( cId );
	
	if ( bWH_IE ) 
		hwSknMW.innerHTML = cHTML
  	else
  	if ( bWH_NS ) 
  	{ 
		hwSknMW.document.write(cHTML); 
		hwSknMW.document.close();
  	}
  	else
		hwSknMW.innerHTML = cHTML;
	
	if( ( nX != null ) && ( nY != null ) ) {
		aPos = MWJ_getMouseCoords();
		MWJ_changePosition( cModalWin, 
							MWJ_getMouse[0] + nX, 
							MWJ_getMouse[1] + nY,
							true
		);
	}
	MWJ_changeVisibility( cModalWin, true );
}

function CloseModal( cId ) {
	nPos = IsDiv(cId);
	if( nPos >= 0 )
		MWJ_changeVisibility( aDivs[nPos], false );
}	

/*******************************************
    Generic DHTML do everything script
By Mark 'Tarquin' Wilton-Jones 28-29/9/2002
Updated 19/10/2004 for event handler bug fix
********************************************/

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_changePosition( oName, oXPos, oYPos, oRel, oFrame ) {
	var theDiv = MWJ_findObj( oName, oFrame ); if( !theDiv ) { return; }
	if( theDiv.style ) { theDiv = theDiv.style; } var oPix = document.childNodes ? 'px' : 0;
	if( typeof( oXPos ) == 'number' ) { theDiv.left = ( oXPos + ( oRel ? 0 : parseInt( theDiv.left ) ) ) + oPix; }
	if( typeof( oYPos ) == 'number' ) { theDiv.top = ( oYPos + ( oRel ? 0 : parseInt( theDiv.top ) ) ) + oPix; }
}
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_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' : ( oDisp == 'inline' ) ? 'inline' : '';
}
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];
}
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_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];
}
