﻿	
	// FUNCTIONS
	//------------------------------------------------------------
	// AddLoadEvent( func )						Add onLoad events
	// PrintDiv( oDiv )							Print send div content
	// GetStyle( oDiv , sAtr )					Returns the final style value aplied
	// Random( nMin , nMax )					Retunrs random value between two nuumbers
	// InterpolateAB( fA , fB , fPonderado )	Retunrs interpolated value between two nuumbers
	//------------------------------------------------------------

	// AddLoadEvent()
	// Adds event to window.onload without overwriting currently assigned onload functions.
	// Function found at Simon Willison's weblog - http://simon.incutio.com/
	//------------------------------------------------------------
	function AddLoadEvent( func )
	{
		var oldonload = window.onload ;
		if ( typeof window.onload != 'function' )
		{
			window.onload = func ;
		}
		else
		{
			window.onload = function()
			{
				oldonload() ;
				func() ;
			}
		}
	}

	// INTERPOLATE AB
	// Retunrs interpolated value between two nuumbers
	//-------------------------------------------------	
	function InterpolateAB( fA , fB , fPonderado )
	{
		var increment ;
		if ( fA == fB )
		{
			return fA ;
		}
		else if( fA > fB )
		{
			fA *= 100 ;
			fB *= 100 ;
			increment = ( fA - fB ) * fPonderado ;
			if( increment < 1 ) increment = 1 ;
			return( Math.floor( ( fA - increment ) * 0.01 ) ) ;
		}
		else
		{
			fA *= 100 ;
			fB *= 100 ;
			increment = ( fB - fA ) * fPonderado ;
			if( increment < 1 ) increment = 1 ;
			return ( Math.ceil( ( fA + increment ) * 0.01 ) ) ;
		}
	}
	
	// RANDOM
	// Retunrs random value between two nuumbers
	//-------------------------------------------------		
	function Random( fMin , fMax )
	{
		return ( parseInt( fMin ) + ( Math.round( Math.random() * ( fMax - fMin ) ) ) ) ;
	}

	// GET STYLE
	// Returns the final style value aplied
	//-------------------------------------------------	
	function GetStyle( oDiv , sAtr )
	{ 
		if ( document.defaultView && document.defaultView.getComputedStyle && document.body )
		{ 
			 sAtr = sAtr.replace(/([A-Z])/g,"-$1").toLowerCase() ; 
			 return document.defaultView.getComputedStyle( oDiv , null ).getPropertyValue( sAtr ) ; 
		}
		else if ( document.body && document.body.currentStyle )
		{ 
			return oDiv.currentStyle[sAtr] ; 
		} 
	}
	
	// PRINT DIV
	// Print send div content
	//-------------------------------------------------		
	function PrintDiv( oDiv )
	{
		var Print = window.open( ' ' , 'popimpr' ) ;
		Print.document.write( oDiv.innerHTML  );
		Print.document.close() ;
	  	Print.print() ;
		Print.close() ;
	}
