
$(document).ready(function(){
	
	// desplegar menu superior
	var menu_sup_autoesconder;
	$('#menu_sup a').mouseover( function(){
		if(menu_sup_autoesconder) clearTimeout(menu_sup_autoesconder);
		$('#menu_sup a').each(function(i){
			$(this).css('backgroundPosition', (0 - parseInt($(this).css('left'))) + 'px 0px');
		})
		var bgpos = (0 - parseInt($(this).css('left'))) + 'px -28px';
		$(this).css('backgroundPosition', bgpos);
		$('#pag_menu_sup div.menu_sup_tabs').stop(true,true).hide();
		var tabid = $(this).attr('id').toString().replace(/\D/g,'');
		var h = $('#menu_sup_tab'+tabid).height();
		$('#menu_sup_tab'+tabid).css('opacity',0).animate({opacity: 1, height: '+='+h, height: 'toggle'}, 'fast');
	});
	
	// autoesconder menu superior
	$('#pag_menu_sup div.menu_sup_tabs').hover(function(){
		if(menu_sup_autoesconder) clearTimeout(menu_sup_autoesconder);
	},function(){
		menu_sup_autoesconder = setTimeout( "$('#"+ $(this).attr('id') +"').hide(); $('#menu_sup a').each(function(i){ $(this).css('backgroundPosition', (0 - parseInt($(this).css('left'))) + 'px 0px'); })", 1000);
	});

	// botones con rollover
	$('a.rolleableBackground').css('backgroundPosition','0px 0px').hover( function(){
		$(this).css('backgroundPosition','0px -'+$(this).height()+'px');
	}, function(){
		$(this).css('backgroundPosition','0px 0px');
	});

	// desplegar menu al pie de pagina
	var menu_pie_autoesconder;
	$('#menu_pie a').mouseover( function(){
		if(menu_pie_autoesconder) clearTimeout(menu_sup_autoesconder);
		$('#menu_pie a').each(function(i){
			$(this).css('backgroundPosition', '0px -'+ $(this).css('top') );
		})
		var bgpos = '-127px -'+ $(this).css('top');
		$(this).css('backgroundPosition', bgpos);
		$('#pag_cuerpo_cierre div.menu_pie_tabs').stop(true,true).hide().css('left', '166px' );
		var tabid = $(this).attr('id').toString().replace(/\D/g,'');
		$('#menu_pie_tab'+tabid).animate({opacity: 'toggle', left: '+=15px'}, 'slow');
	});
	
	// autoesconder menu al pie
	$('#pag_cuerpo_cierre div.menu_pie_tabs').hover(function(){
		if(menu_pie_autoesconder) clearTimeout(menu_pie_autoesconder);
	},function(){
		menu_pie_autoesconder = setTimeout( "$('#"+ $(this).attr('id') +"').hide(); $('#menu_pie a').each(function(i){ $(this).css('backgroundPosition', '0px -'+ $(this).css('top') ); })", 1000);
	});

});

function querystring(variable) {
	var fullqs = window.location.search.substring(1);
	var args = fullqs.split("&");
	var var_val = '';
	for (var i=0; i<args.length; i++) {
		var_val = args[i].split("=");
		if (var_val[0] == variable) return var_val[1];
	}
	return '';
}

function completo(obj,nombre,tipo){	if(tipo=='int'){ if ((obj.value=='')||(isNaN(obj.value))){ return "\n* "+nombre+" debe ser completado con números."; }else{ return ""; }}else if(obj.value==''){ return "\n* "+nombre+' debe ser completado.'; }else{ return ""; }}

function emailvalido(obj,nombre) {msg=""; if(obj.value!=""){var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;if (reg1.test(obj.value) || !reg2.test(obj.value)){msg= "\n* "+nombre+' es inválido (formato correcto: nombre@servidor)'}} return msg}

function fechavalida(obj,nombre){val=obj.value; dr=/^[ ]*[0]?(\d{1,2})\D(\d{1,2})\D(\d{2,4})[ ]*$/; mc=val.match(dr);if (mc){ mc[3]=(mc[3]<999 ? mc[3]+1000 : mc[3]); var td=new Date( mc[3],parseInt(mc[2])-1,mc[1]); if (td.getDate()==parseInt(mc[1]) && td.getFullYear()==parseInt(mc[3]) && (td.getMonth()+1)==parseInt(mc[2])) return"";} return "\n* "+nombre+' es inválido (formato correcto: DD/MM/AAAA)'}

function scrollPageTo(id){
	$('html,body').animate({scrollTop: $("#"+id).offset().top},'slow');
}
