var $ = jQuery.noConflict();
$(document).ready(function(){
	//-----------------------------------------------//
	// SCRIPT search
	//-----------------------------------------------//	
	$(':text','.search').focus(function(){
		if($(this).attr('value') == $(this).attr('title'))
			$(this).attr('value','');
	});
	$(':text','.search').blur(function(){
		if($(this).attr('value')=='')
			$(this).attr('value',$(this).attr('title'));
	});
				
	//-----------------------------------------------//
	// SCRIPT select
	//-----------------------------------------------//	
	$('.select').hover(
		function(){ $('.border',this).hide(); },
		function(){ $('.border',this).show(); }
	);

	jQuery("#loading").hide();
	
	//Exibe o Load quando um AJAX é executado
	jQuery("#loading").ajaxStart(function(){
		jQuery(this).show();
		jQuery("input[type=submit]").hide();
	});
		
	//Oculta o Load quando um AJAX é finalizado
	jQuery("#loading").ajaxStop(function(){
		jQuery(this).hide();
		jQuery("input[type=submit]").show();
	});
	
	$('#olvideContrasena').click(function() {
		$('#login').fadeOut();
		$('#olvide-contrasena').fadeIn();
	});
	
	$('#volverLogin').click(function() {
		$('#olvide-contrasena').fadeOut();
		$('#login').fadeIn();
	});

})

function sendForm(form) {
	var options = {
		success: completeSucess,
		type:'post'
	}
	jQuery(form).ajaxSubmit(options);
	return false;
}

function completeSucess(responseText, statusText, myForm) {
	if (responseText) {
		if ($.trim(responseText).substr(0,8) == 'return:o') {
			$('.question'+myForm.attr('id')).fadeOut();
			$('.content'+myForm.attr('id')).html(responseText.replace('return:o',''));
			$('.estatus'+myForm.attr('id')).html('right');
			$('.estatus'+myForm.attr('id').replace('form','')).removeClass('wrong');
			$('.estatus'+myForm.attr('id').replace('form','')).removeClass('yellow');
			$('.estatus'+myForm.attr('id').replace('form','')).addClass('right');
		} else if ($.trim(responseText).substr(0,8) == 'return:v') {
			window.location.href=window.location.href;
		} else if ($.trim(responseText).substr(0,8) == 'return:e') {
			$('.error'+myForm.attr('id')).html(responseText.replace('return:e',''));
			$('.estatus'+myForm.attr('id').replace('form','')).removeClass('yellow');
			$('.estatus'+myForm.attr('id').replace('form','')).removeClass('wrong');
			$('.estatus'+myForm.attr('id').replace('form','')).addClass('wrong');
		} else {
			$('.error'+myForm.attr('id')).html(responseText);
		}
	} else {
		alert('Error');
	}
}
