/*

Jose G Kurszewski - [ sargento ]
062011 - Requiere jQuery

*/

$( function(){
		fFormatearTablasMaterias();
		fIrAArriba();
	} );

/* ------------------------------------------------------- */

function fAjax( obj ){
	
	if( window.XMLHttpRequest ){
		obj.xhr = new XMLHttpRequest();
	} else
	if( window.ActiveXObject ){
		obj.xhr = new ActiveXObject( "Microsoft.XMLHTTP" );
	} else {
		// alert( "Error" );
	}
	
	if( obj.xhr ){
		obj.xhr.onreadystatechange = obj.func;
		obj.xhr.open( "GET", String( obj.doc ), true );
		obj.xhr.send( null );
	}
}

// Función para leer valores del URI
function fLeerURI( v ){
	
	var sRE = "[&?]" + v + "=([^&]+)";
	var oRE = new RegExp( sRE );
	
	if( oRE.test( location.search ) ){ return RegExp.$1; } else { return null; }
}

// ------------------------------------------------------------------------------------ FUNCIONES

function fFormatearForm ( idForm, activarPrimero ){
	$( '#' + idForm + ' :text, #' + idForm + ' textarea' )
		.each( function(){
							$( this ).addClass( 'texto' )
									 .focus( function(){ $( this ).addClass( 'txtFocus' );
														 // $( this ).parent().css( 'font-weight', 'bold' );
														} )
									 .blur( function(){ $( this ).removeClass( 'txtFocus' );
														// $( this ).parent().css( 'font-weight', 'normal' );
														} )
						} );
	if( activarPrimero ){
		$( '#' + idForm + ' :text:first' ).focus();
	}
	
}

function fIrAArriba(){
	$( 'p.ir_arriba' )
		.each( function(){
						$( this ).html( '<a href="#aTop">volver a arriba</a>' );
						} );
}

function fFormatearTablasMaterias(){
	$( 'table.tblFormateada' ).each( function(){
													$( this )
														.attr( 'cellspacing', 1 )
														.attr( 'border', 0 )
														.find( 'th' )
															.each( function(){ $( this ).addClass( 'bg_gris_4x fnt_gris_4x' ) } );
													
													var allTRs = $( this ).find( 'tr td:nth-child(1)' ).parent();
													for( var tr = 0; tr < $( allTRs ).length; tr++ ){
														$( allTRs[tr] ).addClass( ( tr % 2 ) ? 'bg_gris_2_3' : 'bg_gris_1_3' );
													}
												} );
}

function fToolTip( posX, posY, msg ){
	$( '#divToolTip' )
		.css( { 'display' : 'block', 'left' : posX + 20, 'top' : posY } )
		.html( msg );
}


// GOOGLE ANALYTICS
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-23224388-2']);
_gaq.push(['_setDomainName', '.3d.com.mx']);
_gaq.push(['_trackPageview']);
(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
