/*	
    RICOH Brasil
    ricoh.com.br
    
    Modificações feitas pela M2
    
    por: M2BRNET (http://www.m2brnet.com)
\* ......................................................................................................................................... */

/*
	Namespace
\* ......................................................................................................................................... */

var M2 = function() {

	function Tabs() {
		var tabContainers = $('#tabs-produtos .tabs'),
			tabNav        = $('.snavListTxt a, .lineList a');
				
			$(tabNav).click(function () {
				if (!$(this).parents('ul').hasClass('notabs') || $(this).parents('ul').attr('id') === 'qqmerda' ) {
					tabContainers.hide().filter(this.hash).show();
					$(tabNav).removeClass('active');
					$('.snavListTxt a[href='+this.hash+'], .lineList a[href='+this.hash+']').addClass('active');
					if ($(this).parents('ul').hasClass('lineList')) {
						$('html,body').animate({scrollTop: $(this.hash).offset().top},'fast');
					};
					return false;
				}
			}).filter(':first').click();
	}

	return {
		Init: function(){

			Tabs();

		}
	};

}();

var validaEmail = function(s) {
	var regexpEmail = /\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/;
	return regexpEmail.test(s);
}

$.fn.clearForm = function() {
	return this.each(function() {
		var type = this.type, 
			tag = this.tagName.toLowerCase();
		if (tag == 'form')
			return $(':input',this).clearForm();
		if (type == 'text' || type == 'password' || tag == 'textarea')
			this.value = '';
		else if (type == 'checkbox' || type == 'radio')
			this.checked = false;
		else if (tag == 'select')
			this.selectedIndex = -1;
	});
};

/*
	DOM Loaded
\* ......................................................................................................................................... */

$(function(){ 

	M2.Init();

	/*
	// Select Estados 
	$('#estado').change(function(){
		var estado = $(this).val();
		if (estado == 0) {
			alert('Escolha um estado válido.')
		} else {
			window.location.href = raiz_site + 'suporte/revendas/?estado=' + estado;
		}
	});
	*/
	// Selects Comprar
	$('#form-empresa #sel-estado').hide();
	$('#form-empresa #more-info').hide();
	$('#form-empresa #tipo').change(function(){
		var valor = $(this).val();

		$('#form-empresa #sel-estado').hide();
		$('#form-empresa #more-info').hide();
		$('#form-empresa-submit').show();

		if((valor != '4') && (valor != '3') && (valor != '')) {
			$('#form-empresa #sel-estado').show();
		}
		if ((valor == '3') || (valor == '4')) {
			$('#form-empresa #more-info').show();
			$('#form-empresa-submit').hide();
		};
	});
	$('#form-empresa').submit(function(){
		var erro       = false;
		var tipo       = $('#tipo',this);
		var estado     = $('#estados',this);
		var sel_estado = $('#sel-estado',this).is(':visible');

		$('small.req').remove();

		if (!tipo.val()) {
			$('<small class="req">Escolha um tipo de empresa.</small>').insertAfter(tipo);
			erro = true;
		}
		if (sel_estado) {
			if (!estado.val()) {
				$('<small class="req">Escolha um estado.</small>').insertAfter(estado);
				erro = true;
			}
		};

		if (erro) 
        {
			return false;
		} 
        else 
        {
			window.location.href = raiz_site + 'suporte/revendas/?estado=' + $(estado).val();
			return false;
		}
	});

});

