// JavaScript Document
//
// Copyright 2006 Nelson Daza. nelson.daza@gmail.com. All rights reserved.
// DOM HTML 
// ----------------------------------------------------
//
// Functions.js
//
//	version 2.1.8.4 major.minor[.revision[.build]]
//
	
	/* START Pop-up Windows Script */

	function popup ( url, name, width, height, posx, posy, features )	{
		if ( typeof( posx ) == 'undefined' )
			posx = 'center';
		if ( typeof( posy ) == 'undefined' )
			posy = 'middle';
		if ( typeof( features ) == 'undefined' )
			features = '';

		if ( posx.toLowerCase ( ) == 'center' )
			posx = ( screen.width - width ) / 2;
		else if ( posx.toLowerCase ( ) == 'right' )
			posx = (screen.width - width - 30);
		else if ( posx < 0 )
			posx = screen.width - width + posx;
		else 
			posx = 0;
	
		if ( posy.toLowerCase ( ) == 'middle' )
			posy = ( screen.height - height ) / 2;
		else if ( posy.toLowerCase ( ) == 'bottom' )
			posy = ( screen.height - height - 60 );
		else if ( posy < 0 )
			posx = screen.height - height - posy - 30;
		else 
			posy = 0;
	
		if ( typeof( name ) == 'undefined' || typeof( width ) == 'undefined' || typeof( height ) == 'undefined' )
			return open( url );
		else
			return open( url, name, 'width=' + width + ',height=' + height + ',screenX=' + posx + ',left=' + posx + ',screenY=' + posy + ',top=' + posy + ',' + features );
	}
	
	/* END Pop-up Windows Script */

	function validateEmail ( email )	{
		var pos = 0;
		if ( email.length > 7 && email.indexOf ( ' ', 0 ) == -1 )	{
			pos = email.indexOf ( '@', 0 );
			if ( pos > 2 && email.indexOf ( '@', pos ) && email.indexOf ( '.', pos ) > ( pos + 2 ) )	{
				pos = email.indexOf ( '.', pos );
				if ( pos > -1 && pos < email.length - 2 )
					return true;
			}
		}			
		return false;
	}

	var font_size = 9;
	var MAX = 17;
	var MIN = 11;
	
	function changeFont( num )	{
		font_size += num;
		if( font_size > MAX )
			font_size = MAX;
		if( font_size < MIN )
			font_size = MIN;
		 document.getElementsByTagName( 'body' )[0].style.fontSize = font_size + 'px';
	}

	function toObject ( something )	{
		if ( typeof( something ) == 'string' )
			return document.getElementById ( something );
		if ( typeof( something.nodeName ) != 'undefined' )
			return something;
		return null;
	}
	
	function jumpTo ( url )	{
		document.location.href = url;
	}
	
	function hideElement ( something )	{
		something = toObject ( something );
		if ( something )	{
			something.style.visibility = 'hidden';
			something.style.display = 'none';
		}
	}
	
	function showElement ( something )	{
		something = toObject ( something );
		if ( something )	{
			something.style.visibility = 'visible';
			something.style.display = 'block';
		}
	}
	
	function changeVisibility ( something )	{
		something = toObject ( something );
		if ( something )	{
			if ( something.style.visibility == 'visible' )
				hideElement ( something );
			else
				showElement ( something );
		}
	}
	
	function setElementPosition( something, posx, posy )	{
		something = toObject( something );
		something.style.position = 'absolute';
		something.style.left = posx + 'px';
		something.style.top = posy + 'px';
	}
	
	function isDate ( year, month, day )	{
		if ( year.toString().length == 0 )
			return false;
		if ( day == null )	{
			month = ( month == null ) ? '-' : month;
			if ( year.toString().indexOf( month ) == -1 )
				return false;
			
			var arr = year.toString().split( month );
			if ( arr.length != 3 )
				return false;
			year = arr[0];
			month = arr[1];
			day = arr[2];
		}
		month = month - 1;  // javascript month range : 0- 11
		var tempDate = new Date ( year, month, day );
		var nyear = ( tempDate.getYear ( ) < 1000 ) ? tempDate.getYear ( ) + 1900 : tempDate.getYear ( )
		
		return ( ( nyear == year ) && ( month == tempDate.getMonth ( ) ) && ( day == tempDate.getDate ( ) ) );
	}
	
	function imagenChange ( image, source )	{
		image = toObject ( image );
		if ( image )
			image.src = source;
	}
	
	function checkMaxChars( something, maxChars ){
		something = toObject ( something );
		if ( something && something.value.length > maxChars )
			something.value = something.value.substring( 0, maxChars );
	}
	
	function innerChange ( something, child )	{
		something = toObject ( something );
		if ( something )	{
			while ( something.hasChildNodes( ) )
				something.removeChild( something.firstChild );
			if ( typeof ( text ) == 'string' )
				something.appendChild( document.createTextNode( child ) )
			else
				something.appendChild( child )
		}
	}
	
	function bookMark ( value )	{
		var bookData = new Array ( );
		bookData = value.split ( '|' );
		if ( document.all )
			window.external.AddFavorite ( bookData[0], bookData[1] );
		else
			alert( 'Lo Sentimos, los usuarios de Netscape o Mozilla deben agregar a \nfavoritos manualmente desde el menu o haciendo uso de <Ctrl-D>' );
	}

	function setElementOpacity ( something, opacity )	{
		var old = something;
		something = toObject( something );
		if( !something )
			return;

		if( opacity < 0 )
			opacity = 0;
		else if( opacity > 1 )
			opacity /= 100;

		if( document.all )
			something.style.filter = 'alpha(opacity=' + ( opacity * 100 ) + ')';
		else
			something.style.MozOpacity = opacity;
		something.style.opacity = opacity;
	}
	
	function moveElement ( elem, nX, nY, nXStepIn, nYStepIn, bPercent, nInterval, onCallBack )	{
		elem = toObject( elem );
		var style = elem.style;
		var nDirX = 0;
		var nDirY = 0;
		var nXStep = nXStepIn;
		var nYStep = nYStepIn;
		
		if ( nXStep <= 0 )
			nXStep = 1;
	
		if ( nYStep <= 0 )
			nYStep = 1;
			
		var left = Number ( style.left.replace( 'px', '' ) );
		var top = Number ( style.top.replace( 'px', '' ) );
		
		if ( Math.abs( nX - left ) > 0 )	{
			if ( bPercent )
				nXStep = Math.ceil ( ( nXStepIn ) * Math.abs ( nX - left ) / 100 );
			
			if ( Math.abs( nX - left ) < Math.abs( nXStep ) + 1 )
				nXStep = Math.abs( nX - left );
			
			nDirX = ( nX - left ) >= 0 ? 1 : -1;
			
			left += nXStep * nDirX;
			style.left = left + 'px';
		}

		if ( Math.abs( nY - top ) > 0 )	{
			if ( bPercent )
				nYStep = Math.ceil ( ( nYStep ) * Math.abs( nY - top ) / 100 );

			if ( Math.abs( nY - top ) < Math.abs( nYStep ) + 1 )
				nYStep = Math.abs( nY - top );
			
			nDirY = ( nY - top ) >= 0 ? 1 : -1;
			
			top += nYStep * nDirY;
			style.top = top + 'px';
		}
		
		if ( nDirX == 0 && nDirY == 0 )	{
			if ( onCallBack != undefined )	{
				var func = new Function( onCallBack );
				func( );
			}
		}
		else
			elem.timeout = setTimeout( "moveElement ( '" + elem.id + "', " + nX + ", " + nY + ", " + nXStepIn + ", " + nYStepIn + ", " + bPercent + ", " + nInterval + ", \"" + onCallBack + "\" )", nInterval );
	}

	/* START SortTable Script */

	function compare ( obj1, obj2 )	{
		var str1 = obj1.toString( ).toLowerCase( );
		var str2 = obj2.toString( ).toLowerCase( );
		if ( str1 == str2 )
			return 0;
		if ( isNaN ( str1 ) && isNaN ( str2 ) )	{
			return ( str1 > str2 ) ? 1 : -1;
		}
		
		return Number( str1 ) - Number ( str2 );
	}

	function sortTable ( column )	{
		column = toObject ( column );
		if ( column )	{
			var table = column;
			while ( table && table.parentNode && table.parentNode.nodeName.toLowerCase( ) != 'table' )
				table = table.parentNode;
			if ( table )	{
				var groups = table.getElementsByTagName ( 'tbody' );
				alert( groups.length )
				for( var c = 0; c < groups.length; c++ )
					sortTableRows ( groups[c], column.parentNode.cellIndex );
			}
		}
	}
	
	function sortTableRows ( group, col )	{
		var oRows = new Array ( );	//set the rows to be removed as an array of cloneNodes
		var iRows = new Array ( );	//set those rows' indexes as array

		for ( var c = 0; c < group.rows.length; c++ )	{
			oRows[c] = group.rows[c].cloneNode ( true );
			iRows[c] = group.rows[c].sectionRowIndex;
		}
		var oCol = new Array ( );			//set the string content of column cells as array
		var vCol = new Array ( );			//set the "compare" array for a future sort/reverse

		for ( c = 0; c < iRows.length; c++ )	{
			if ( group.rows[c].cells[col] )
				vCol[c] = oCol[c] = [group.rows[c].cells[col].firstChild.nodeValue,iRows[c]];
			else
				vCol[c] = oCol[c] = ['',iRows[c]];
		}

		oCol.sort ( compare );	//sorts the content array

		if ( vCol.toString ( ) == oCol.toString ( ) )
			oCol.reverse ( );	//if the content was already sorted, reverse

		for ( c = 0; c < group.rows.length; c++ )	{
			group.replaceChild ( oRows[oCol[c][1]], group.rows[c] );	//writes the rows in a sorted/reversed order
		}
	}
	
	String.prototype.trim = function ( )	{
		return this.replace( /^\s+|\s+$/g,'' );
	}


	/* END SortTable Script */

	/**********************************/
	/* BEGIN General Functions Script */
	/**********************************/

	function inputFocus ( obj, def )	{
		if( obj && obj.value.trim( ) == def )
			obj.value = '';
	}
	
	function inputBlur ( obj, def )	{
		if( obj && obj.value.trim( ) == '' )
			obj.value = def;
	}
	
	function validateSearchForm ( )	{
		var sInput = toObject( 'searchKey' );
		if ( !sInput || sInput.value.trim( ) == 'Buscar' || sInput.value.trim( ).length < 3 )	{
			sInput.focus( );
			alert( unescape( 'La b%FAsqueda debe contener 3 caracteres como m%EDnimo' ) );
			return false;
		}
		return true;
	}
	
	function validateNewsForm ( )	{
		var sInput = toObject( 'newsName' );
		if ( !sInput || sInput.value.trim( ) == 'Nombre' || sInput.value.trim( ).length <= 3 )	{
			sInput.focus( );
			alert( unescape( 'No ha ingresado un nombre correcto.' ) );
			return false;
		}
		sInput = toObject( 'newsEmail' );
		if ( !sInput || sInput.value.trim( ) == 'E-mail' || sInput.value.trim( ).length <= 3 || !validateEmail( sInput.value ) )	{
			sInput.focus( );
			alert( unescape( 'No ha ingresado un e-mail correcto.' ) );
			return false;
		}
		
		requestInto( 'newsForm', 'Scripts/newsletter.php', 'newsHolder', null, true );
		
		return false;
	}
	
	function validateLoginForm( )	{
		return true;
	}
	
	var lastMenu = null;
	var menuInterval = null;
	function menuOver ( id )	{
		clearTimeout( menuInterval );
		if( lastMenu != id )
			hideLastMenu( );
		lastMenu = id;
		var opt = toObject( 'menuOpt_' + lastMenu );
		if( opt.className != 'menuOptionSel' )
			opt.className = 'menuOptionOver';
		var list = toObject( 'menu_' + lastMenu );
		if( list )
			showElement( list );
	}
	
	function hideLastMenu ( )	{
		if( lastMenu )	{
			var opt = toObject( 'menuOpt_' + lastMenu );
			if (opt) {
				if( opt.className != 'menuOptionSel' )
					opt.className = 'menuOption';
				var list = toObject( 'menu_' + lastMenu );
				if( list )
					hideElement( list );
			}
		}
	}
	
	function menuOut( id )	{
		menuInterval = setTimeout( 'menuOutTimeOut( \'' + id + '\' )', 500 );
	}
	
	function menuOutTimeOut( id )	{
		if( lastMenu == id )
			hideLastMenu( );
	}
	
	function getElementDimensions( something )	{
		return {'height': getElementHeight( something ), 'width': getElementWidth( something ) };
	}
	
	function getElementWidth ( something, includePadding, includeBorder )	{
		var width = 0;
		something = toObject( something );
		
		if ( window.getComputedStyle )	{ // FF, Safari, Opera
			var style = document.defaultView.getComputedStyle( something , null );
			if ( style.getPropertyValue( "display" ) === "none" )
				return 0;
			width = parseInt( style.getPropertyValue( "width" ) );
			
			if ( /opera/i.test( navigator.userAgent ) )	{
				// opera includes the padding and border when reporting the width/height - subtract that out
				width -= parseInt( style.getPropertyValue( "padding-left" ) );
				width -= parseInt( style.getPropertyValue( "padding-right" ) );
				width -= parseInt( style.getPropertyValue( "border-left-width" ) );
				width -= parseInt( style.getPropertyValue( "border-right-width" ) );
			}
			
			if ( includePadding ) {
				width += parseInt( style.getPropertyValue( "padding-left" ) );
				width += parseInt( style.getPropertyValue( "padding-right") );
			}
			
			if ( includeBorder ) {
				width += parseInt( style.getPropertyValue( "border-left-width" ) );
				width += parseInt( style.getPropertyValue( "border-right-width" ) );
			}
		}
		else	{ // IE
			if ( something.currentStyle["display"] === "none" )
				return 0;
			var bRegex = /thin|medium|thick/; // regex for css border width keywords
			width = something.offsetWidth; // currently the width including padding + border
			
			if ( !includeBorder )	{
				var borderLeftCSS = something.currentStyle["borderLeftWidth"];
				var borderRightCSS = something.currentStyle["borderRightWidth"];
				var temp = document.createElement( "div" );
				if ( something.offsetWidth > something.clientWidth && something.currentStyle["borderLeftStyle"] !== "none" )	{
					if ( !bRegex.test( borderLeftCSS ) )	{
						temp.style.width = borderLeftCSS;
						something.parentNode.appendChild( temp );
						width -= Math.round( temp.offsetWidth );
						something.parentNode.removeChild( temp );
					}
					else	{
						temp.style.width = "10px";
						temp.style.border = borderLeftCSS + " " + something.currentStyle["borderLeftStyle"] + " #000000";
						something.parentNode.appendChild( temp );
						width -= Math.round( ( temp.offsetWidth - 10 ) / 2 );
						something.parentNode.removeChild( temp );
					}
	
					if ( !bRegex.test( borderRightCSS ) )	{
						temp.style.width = borderRightCSS;
						something.parentNode.appendChild( temp );
						width -= Math.round( temp.offsetWidth );
						something.parentNode.removeChild( temp );
					}
					else	{
						temp.style.width = "10px";
						temp.style.border = borderRightCSS + " " + something.currentStyle["borderRightStyle"] + " #000000";
						something.parentNode.appendChild(temp);
						width -= Math.round( ( temp.offsetWidth - 10 ) / 2 );
						something.parentNode.removeChild( temp );
					}
				}
			}
			
			if ( !includePadding )	{
				var paddingLeftCSS = something.currentStyle["paddingLeft"];
				var paddingRightCSS = something.currentStyle["paddingRight"];
				var temp = document.createElement("div");
				temp.style.width = paddingLeftCSS;
				something.parentNode.appendChild( temp );
				width -= Math.round( temp.offsetWidth );
				temp.style.width = paddingRightCSS;
				width -= Math.round( temp.offsetWidth );
				something.parentNode.removeChild( temp );
			}
		}
		
		return width;
	}
	
	var getElementHeight = function ( something, includePadding, includeBorder )	{
		var height = 0;
		something = toObject( something );
		if ( window.getComputedStyle )	{ // FF, Safari, Opera
			var style = document.defaultView.getComputedStyle( something, null );
			if ( style.getPropertyValue( "display" ) === "none" )
				return 0;
			height = parseInt( style.getPropertyValue( "height" ) );
			
			if ( /opera/i.test( navigator.userAgent ) )	{
				// opera includes the padding and border when reporting the width/height - subtract that out
				height -= parseInt( style.getPropertyValue( "padding-top" ) );
				height -= parseInt( style.getPropertyValue( "padding-bottom" ) );
				height -= parseInt( style.getPropertyValue( "border-top-width" ) );
				height -= parseInt( style.getPropertyValue( "border-bottom-width" ) );
			}
			
			if ( includePadding ) {
				height += parseInt( style.getPropertyValue( "padding-top" ) );
				height += parseInt( style.getPropertyValue( "padding-bottom" ) );
			}
			
			if ( includeBorder )	{
				height += parseInt( style.getPropertyValue( "border-top-width" ) );
				height += parseInt( style.getPropertyValue( "border-bottom-width" ) );
			}
		}
		else	{ // IE
			if ( something.currentStyle["display"] === "none" )
				return 0;
			var bRegex = /thin|medium|thick/; // regex for css border width keywords
			height = something.offsetHeight; // currently the height including padding + border
		
			if ( !includeBorder )	{
				var borderTopCSS = something.currentStyle["borderTopWidth"];
				var borderBottomCSS = something.currentStyle["borderBottomWidth"];
				var temp = document.createElement( "div" );
				if ( something.offsetHeight > something.clientHeight && something.currentStyle["borderTopStyle"] !== "none" )	{
					if ( !bRegex.test( borderTopCSS ) )	{
						temp.style.width = borderTopCSS;
						something.parentNode.appendChild( temp );
						height -= Math.round( temp.offsetWidth );
						something.parentNode.removeChild( temp );
					}
					else	{
						temp.style.width = "10px";
						temp.style.border = borderTopCSS + " " + something.currentStyle["borderTopStyle"] + " #000000";
						something.parentNode.appendChild( temp );
						height -= Math.round( ( temp.offsetWidth - 10 ) / 2 );
						something.parentNode.removeChild( temp );
					}
				}
				if ( something.offsetHeight > something.clientHeight && something.currentStyle["borderBottomStyle"] !== "none" )	{
					if ( !bRegex.test( borderBottomCSS ) )	{
						temp.style.width = borderBottomCSS;
						something.parentNode.appendChild( temp );
						height -= Math.round( temp.offsetWidth );
						something.parentNode.removeChild( temp );
					}
					else	{
						temp.style.width = "10px";
						temp.style.border = borderBottomCSS + " " + something.currentStyle["borderBottomStyle"] + " #000000";
						something.parentNode.appendChild( temp );
						height -= Math.round( ( temp.offsetWidth - 10 ) / 2 );
						something.parentNode.removeChild( temp );
					}
				}
			}
		
			if ( !includePadding )	{
				var paddingTopCSS = something.currentStyle["paddingTop"];
				var paddingBottomCSS = something.currentStyle["paddingBottom"];
				var temp = document.createElement("div");
				temp.style.width = paddingTopCSS;
				something.parentNode.appendChild( temp );
				height -= Math.round( temp.offsetWidth );
				temp.style.width = paddingBottomCSS;
				height -= Math.round( temp.offsetWidth );
				something.parentNode.removeChild( temp );
			}
		}
		
		return height;
	}
	
	function toObject ( something )	{
		if ( typeof( something ) == 'string' )
			return document.getElementById ( something );
		if ( typeof( something.nodeName ) != 'undefined' )
			return something;
		return null;
	}
	
	function findPos(obj) {
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			curleft = obj.offsetLeft
			curtop = obj.offsetTop
			while (obj = obj.offsetParent) {
				curleft += obj.offsetLeft
				curtop += obj.offsetTop
			}
		}
		return [curleft,curtop];
	}