$(document).ready(function() {
	
	$("a.description").click(function(){
		$("a.description").attr("href", "javascript:switch1('about');switch2('about1')");
	});

	//
	//								BLUEBOXES - INSTITUTII
	//initiere tooltip-uri
	$("#productList_tooltips li").hoverIntent( {
			sensitivity: 3,
			interval: 500,
			timeout: 500,
			over: function(){
					var pos = $(this).offset();
					idLi = $(this).attr("id");
					blueBoxId = "#bluebox_extern_" + idLi;
					if($(blueBoxId).is(":hidden")) {
						$(".bluebox").hide();
						$(blueBoxId).css('top' , pos.top - 165);
						$(blueBoxId).fadeIn('slow');
						if (blueBoxId == '#bluebox_extern_sfaturi_online') {
							$('.hideOnSubmit').show();
							$('.infoFormSfaturi').hide();
						}
					}
				  },
			out: function(){} 
	});
	$("#productList_tooltips li").click ( function () { //functie identica cu cea de mai sus
		var pos = $(this).offset();
		idLi = $(this).attr("id");
		blueBoxId = "#bluebox_extern_" + idLi;
		if($(blueBoxId).is(":hidden")) {
			$(".bluebox").hide();
			$(blueBoxId).css('top' , pos.top - 165);
			$(blueBoxId).fadeIn('slow');
			if (blueBoxId == '#bluebox_extern_sfaturi_online') {
				$('.hideOnSubmit').show();
				$('.infoFormSfaturi').hide();
			}
		}
		
	});
	//buton de close pentru fiecare fereastra
	$(".btn_close").click( function() {
		//aflu id-ul div-ului de pe al doilea nivel (tooltip-ul)
		idBox = $(this).parents('div:eq(1)').attr("id");
		$("#" + idBox).hide();
	});

	$('.bluebox').hover( function(){ 
       inside_bluebox = true; 
   }, function(){ 
	   inside_bluebox = false; 
   });

	//la click in inputul de search se golesc valorile predefinite ('suma, moneda, perioada...')
	$(".inputbox").click( function () {
		var inputId =  $(this).attr('id');
		
		if($(this).val() != '') {
			if( $(this).hasClass('sfaturiInputNume') && $(this).val() == 'nume') {
				$(this).val('');
			} else if ( $(this).hasClass('sfaturiInputEmail') && $(this).val() == 'email'){
				$(this).val('');
			}
		}	});
	
	$(".inputbox").blur( function () {
		if($(this).val() == '') {
			if($(this).hasClass('sfaturiInputNume')) {
				$(this).val('nume');
			} else {
				$(this).val('email');
			}
		}
	});	

	//submit form sfaturi
	$("#submitFormSfaturi").click( function () {
		var intrebare = $(".sfaturiInputIntrebare").val();
		var nume = $(".sfaturiInputNume").val();
		var email = $(".sfaturiInputEmail").val();
		var emailFilter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;

		if(intrebare.length < 1 || nume.length < 1 || email.length < 1) {
			$('.infoFormSfaturi').show();
			$('.infoFormSfaturi').html('Unul din campuri a ramas necompletat!');
		} else if (!emailFilter.test(email)) {
			$('.infoFormSfaturi').show();
			$('.infoFormSfaturi').html('Adresa de email invalida!');
		} else {
			$('.infoFormSfaturi').show();
			$.ajax({
				type: 'POST',
				dataType: "html",
				data: 'intrebare=' + intrebare + '&nume=' + nume + '&email=' + email,
				url: '/index/sfatulExpertuluiForm',
				success: function(msg){
						if(msg == 'ok') {
							$('.infoFormSfaturi').html('Mesajul a fost trimis cu succes!');
							$('.hideOnSubmit').hide();
							return false;
						} else {
							$('.infoFormSfaturi').html('A intervenit o eroare la trimitere! Va rugam incercati inca odata.');
							return false;
						}						
			   	}
			});
		}
	});
	//
	//								END BLUEBOXES - INSTITUTII
	//
});


function showSucursale(id_inst, id_parent, city, slug)
{
	if (city==undefined) city='toate';
	$('#hartaIfr').html('<iframe src="/institutii/IframeSucursale/?inst='+id_inst+'&parent='+id_parent+'&city='+city+'&slug='+slug+'" FRAMEBORDER="0" width="680" height="500" style="overflow:hidden;"></iframe>');
}

